<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Erich Beyrent :: Beyrent.net</title>
	<link>http://beyrent.net</link>
	<description>Drupal and PHP Web Development</description>
	<pubDate>Mon, 07 Jul 2008 12:28:09 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>
	<language>en</language>
			<item>
		<title>Drupal and Sane Flash Remoting</title>
		<link>http://beyrent.net/2008/07/07/drupal-and-sane-flash-remoting/</link>
		<comments>http://beyrent.net/2008/07/07/drupal-and-sane-flash-remoting/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 12:28:09 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Web]]></category>

		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://beyrent.net/2008/07/07/drupal-and-sane-flash-remoting/</guid>
		<description><![CDATA[

On my latest project, I was faced with a challenge: build Flash widgets that displayed dynamic data and could be embedded on any web page.  Phase two of the widgets called for user interaction with the widget, as opposed to simply displaying content.  It seemed that Flex would be the most logical technology [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>On my <a href="http://greenopolis.com" target="_blank">latest project</a>, I was faced with a challenge: build Flash widgets that displayed dynamic data and could be embedded on any web page.  Phase two of the widgets called for user interaction with the widget, as opposed to simply displaying content.  It seemed that Flex would be the most logical technology to use for this project.</p>
<p>I used the <a href="http://drupal.org/project/services" target="_blank">Services</a> and <a href="http://drupal.org/project/amfphp" target="_blank">AMFPHP</a> modules for Drupal to expose content via web services for my Flex widget to consume.  However, I ran into a problem with the critical piece that Flex needs in order to get remote data.  As a workaround to the browser security settings that prevent cross-site scripting, Adobe chose to implement an opt-in solution in the form of a file called crossdomain.xml.  With crossdomain.xml, a site owner may allow a list of domains to read its data and the client, Flash in this case, is responsible for enforcement.  As the business case for the project called for the widget to be embedded on any domain, I needed to use a promiscuous crossdomain policy, allowing access from all domains:</p>
<div class="igBar"><span id="lxml-3"><a href="#" onclick="javascript:showPlainTxt('xml-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-3">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;cross</span>-domain-policy<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;allow</span>-access-from <span style="color: #000066;">domain</span>=<span style="color: #ff0000;">"*"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/cross</span>-domain-policy<span style="font-weight: bold; color: black;">&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Because of this policy, the widget was allowed to read all data on the site that the user has access to, including any (authenticated) content and (session) cookies. This could easily lead to privacy violations, account takeovers, theft of sensitive data, and bypassing of CSRF protections.</p>
<p>Other domains in a similar predicament have simply hosted their APIs on a different domain, thus preventing access to user data on the root domain.  Unfortunately, the nature of Drupal doesn't allow for splitting the Services functionality out from the rest of the platform. </p>
<p>My solution was to write a forwarder, which is just a really simple PHP script, that is hosted on a subdomain.  This subdomain hosts the promiscuous crossdomain policy, and the policy file on the root domain is configured to only accept requests from the subdomain.  The forwarder does two things: it first makes sure that only requests to /services/amfphp are allowed; if allowed, the $HTTP_RAW_POST_DATA is sent to the root domain via cURL.</p>
<div class="igBar"><span id="lphp-4"><a href="#" onclick="javascript:showPlainTxt('php-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-4">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Configuration variables</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$server</span> = <span style="color:#FF0000;">'http://mydomain.com/services/amfphp'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$request_uri</span> = <a href="http://www.php.net/trim"><span style="color:#000066;">trim</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$_SERVER</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'REQUEST_URI'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$request_uri</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> === <span style="color:#FF0000;">'/'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$request_uri</span> = <a href="http://www.php.net/substr"><span style="color:#000066;">substr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$request_uri</span>, <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Split the uri into components</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/list"><span style="color:#000066;">list</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$handler</span>, <span style="color:#0000FF;">$protocol</span><span style="color:#006600; font-weight:bold;">&#41;</span> = <a href="http://www.php.net/split"><span style="color:#000066;">split</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/'</span>, <span style="color:#0000FF;">$request_uri</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Filter out unwanted requests</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$handler</span> != <span style="color:#FF0000;">'services'</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$protocol</span> != <span style="color:#FF0000;">'amfphp'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/exit"><span style="color:#000066;">exit</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Handle the post from the flash/flex client</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$xml</span> = <span style="color:#0000FF;">$HTTP_RAW_POST_DATA</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$xml</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/exit"><span style="color:#000066;">exit</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Set the headers</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$header</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">"Content-type: text/xml"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$header</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">"Content-length: "</span>.<a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$xml</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$ch</span> = curl_init<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$server</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_RETURNTRANSFER, <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_TIMEOUT, <span style="color:#CC66CC;color:#800000;">30</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_HTTPHEADER, <span style="color:#0000FF;">$header</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">curl_setopt<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span>, CURLOPT_POSTFIELDS, <span style="color:#0000FF;">$xml</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$response</span> = curl_exec<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>curl_errno<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/exit"><span style="color:#000066;">exit</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; curl_close<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$ch</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/strlen"><span style="color:#000066;">strlen</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$response</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/exit"><span style="color:#000066;">exit</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/print"><span style="color:#000066;">print</span></a> <span style="color:#0000FF;">$response</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/exit"><span style="color:#000066;">exit</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Because the subdomain doesn't host any data at all, the security risk has been removed.  If you are working with Drupal and Flash remoting, you'll need to consider the risks associated with promiscuous crossdomain policy files.  While my solution certainly isn't the only solution, it is pretty effective and simple.</p>
<p>
<div class="bsuggestive_footer">
<h3>Related:</h3>
<p><!-- start bsuite_speedcache object bsuggestive/66 on 2008-07-22 09:07:05-->
<ul>
<li><a href="http://beyrent.net/2008/04/03/drupal-and-cross-domain-javascript-widgets/" title="">Drupal: Cross-domain Widgets</a></li>
<li><a href="http://beyrent.net/2007/02/13/apple-movie-trailer-wordpress-widget/" title="">Apple Movie Trailer Wordpress Widget</a></li>
<li><a href="http://beyrent.net/2007/04/18/ie7-rss-auto-discovery/" title="">IE7 RSS Auto-discovery</a></li>
<li><a href="http://beyrent.net/2007/02/13/astronomy-picture-of-the-day-widget-for-wordpress/" title="">Astronomy Picture of the Day Widget for Wordpress</a></li>
<li><a href="http://beyrent.net/2005/11/03/php-and-soap-authentication/" title="">PHP and SOAP Authentication</a></li>
</ul>
<p><!-- end bsuite_speedcache object --></div>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2008/07/07/drupal-and-sane-flash-remoting/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Introduction to Young Talent</title>
		<link>http://beyrent.net/2008/06/15/introduction-to-young-talent/</link>
		<comments>http://beyrent.net/2008/06/15/introduction-to-young-talent/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 22:56:10 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://beyrent.net/2008/06/15/introduction-to-young-talent/</guid>
		<description><![CDATA[

My niece, Brynn Doughty, played a wonderful piano piece for a recital on June 12, 2008.






          
        

]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>My niece, Brynn Doughty, played a wonderful piano piece for a recital on June 12, 2008.</p>
<div class="flvPlayer">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="490" height="416">
<param name="movie" value="http://www.beyrent.net/wordpress/wp-content/plugins/mediaplayer.swf?file=http://www.beyrent.net/wordpress/wp-content/uploads/2008/06/Brynn_June122008.flv" />
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<param name="allowfullscreen" value="true" />
          <embed src="http://www.beyrent.net/wordpress/wp-content/plugins/mediaplayer.swf?file=http://www.beyrent.net/wordpress/wp-content/uploads/2008/06/Brynn_June122008.flv" quality="high" wmode="transparent" allowfullscreen="true" width="490" height="416" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /><br />
        </object>
</div>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2008/06/15/introduction-to-young-talent/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Drupal: Cross-domain Widgets</title>
		<link>http://beyrent.net/2008/04/03/drupal-and-cross-domain-javascript-widgets/</link>
		<comments>http://beyrent.net/2008/04/03/drupal-and-cross-domain-javascript-widgets/#comments</comments>
		<pubDate>Thu, 03 Apr 2008 12:00:59 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Web]]></category>

		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://beyrent.net/2008/04/03/drupal-and-cross-domain-javascript-widgets/</guid>
		<description><![CDATA[

Drupal is incredibly flexible, but in current versions, lacks the ability to export content easily in the form of widgets.  However, the Services module gives you that flexibility in a very easy to use manner.
Services allows you to expose pieces of your Drupal site, such as user, node, and views methods.  Combine this [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p><a href="http://drupal.org" target="_blank"><img src='http://beyrent.net/wordpress/wp-content/uploads/2008/04/drupal1.thumbnail.png' alt='drupal1.png' align="left" border=0 hspace=8 vspace=4 /></a>Drupal is incredibly flexible, but in current versions, lacks the ability to export content easily in the form of widgets.  However, the <a href="http://drupal.org/project/services" target="_blank">Services module</a> gives you that flexibility in a very easy to use manner.</p>
<p>Services allows you to expose pieces of your Drupal site, such as user, node, and views methods.  Combine this with the integration of <a href="http://drupal.org/project/amfphp" target="_blank">AMFPHP</a>, you can build some extremely fast Flash and Flex widgets that display dynamic data and can be embedded on any website.</p>
<p>However, there is a catch.  </p>
<p>I was working with another developer on a Facebook application that displayed my Flex widget, and it seems that in Facebook, you have to provide a static image for the user to click on in order to active the flash.  This is clunky, and not the ideal solution for me.</p>
<p>Another option was to attempt to create cross-domain javascript widgets.  I looked at <a href="http://drupal.org/project/json_server" target="_blank">JSON Server</a>, which is a Services wrapper that returns data in JSON.  This module worked great on the same domain, but failed on cross-domain calls.  The reason why is that the module only accepts POST requests.</p>
<p>I ended up <a href="http://drupal.org/node/242159" target="_blank">patching the module</a> to accept GET requests structured in the following manner:</p>
<div style="width:495px;overflow:auto;">
<div class="igBar"><span id="ljavascript-7"><a href="#" onclick="javascript:showPlainTxt('javascript-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-7">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> get<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; headElement = document.<span style="color: #006600;">getElementsByTagName</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"head"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #000066; font-weight: bold;">item</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> script = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"script"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; script.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"type"</span>, <span style="color: #3366CC;">"text/javascript"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900; font-style: italic;">// The callback parameter is needed so that the JSON gets returned correctly in order to be handled by the output function</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; script.<span style="color: #006600;">setAttribute</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"src"</span>,<span style="color: #3366CC;">"http://server.com/services/json?method=views.getView&amp;view_name=some_view&amp;callback=display"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; headElement.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>script<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> display<span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> theDiv = document.<span style="color: #006600;">createElement</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"div"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; theDiv.<span style="color: #006600;">innerHTML</span> = obj.<span style="color: #006600;">data</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; document.<span style="color: #006600;">body</span>.<span style="color: #006600;">appendChild</span><span style="color: #66cc66;">&#40;</span>theDiv<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</div>
<p>You'll note that I am doing script tag inserts into the head of the calling website.  The script source is set to the path of my JSON server, with the services method as a parameter.  The services method takes arguments, which differ depending on the service you are calling.  In the case of the Views.getView service, you have to supply the name of the view to call.  </p>
<p>The last parameter specifies the name of your output function.  My patch takes this callback and wraps the JSON-formatted data returned by the service with the name of the callback.  The callback is extremely important, as the JSON sent back by the server acts as a call to your defined callback function.  From there, your callback function can display the data however it chooses.</p>
<p>Implementation of this method on a remote site is very easy:</p>
<div class="igBar"><span id="ljavascript-8"><a href="#" onclick="javascript:showPlainTxt('javascript-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-8">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script type=<span style="color: #3366CC;">"text/javascript"</span> src=<span style="color: #3366CC;">"http://server.com/path/to/javascript.js"</span>&gt;&lt;/script&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;script type=<span style="color: #3366CC;">"text/javascript"</span>&gt;get<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;&lt;/script&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>For my widget, I created a custom service that returned the output of a theme() function to render the widget template.  This html output was then displayed by my JSON callback function.</p>
<p>Using the Services and (patched) JSON Server modules for Drupal, you can quite easily set up cross-domain javascript/html widgets that can be embedded anywhere.</p>
<p>
<div class="bsuggestive_footer">
<h3>Related:</h3>
<p><!-- start bsuite_speedcache object bsuggestive/63 on 2008-07-22 12:17:39-->
<ul>
<li><a href="http://beyrent.net/2008/07/07/drupal-and-sane-flash-remoting/" title="">Drupal and Sane Flash Remoting</a></li>
<li><a href="http://beyrent.net/2007/01/25/ajax-extended/" title="">Ajax Extended</a></li>
<li><a href="http://beyrent.net/2007/01/25/ajax-extended-read-me/" title="">AJAX Extended - Read Me</a></li>
<li><a href="http://beyrent.net/2006/02/06/troubleshooting-profiles/" title="">Troubleshooting Profiles</a></li>
<li><a href="http://beyrent.net/2007/10/19/drupal-releasing-custom-modules/" title="">Drupal: Releasing Custom Modules</a></li>
</ul>
<p><!-- end bsuite_speedcache object --></div>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2008/04/03/drupal-and-cross-domain-javascript-widgets/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Debugging Goodness</title>
		<link>http://beyrent.net/2008/03/04/php-debugging-goodness/</link>
		<comments>http://beyrent.net/2008/03/04/php-debugging-goodness/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 15:59:52 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://beyrent.net/2008/03/04/php-debugging-goodness/</guid>
		<description><![CDATA[

I have found PHP nirvana in a box.
I was trying to debug the lastest dev version of the userpoints module for Drupal, and was getting nowhere.  The process of debugging PHP is tedious to begin with, but the practice of putting print statements into your code in places you think are likely the problem [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p><img src='http://beyrent.net/wordpress/wp-content/uploads/2008/03/zend_studio_box_gif.gif' alt='Zend Studio For Eclipse' align="right" hspace=8 vspace=4/>I have found PHP nirvana in a box.</p>
<p>I was trying to debug the lastest dev version of the userpoints module for Drupal, and was getting nowhere.  The process of debugging PHP is tedious to begin with, but the practice of putting print statements into your code in places you think are likely the problem is a nightmare, and a huge black hole for productivity.  Understanding what hooks are getting called and when they execute via print statements is a good way to waste an entire afternoon.</p>
<p>Enter Zend Studio.  Their newest version is based on Eclipse, the open-source IDE that ties development in many languages into a single common UI.  Zend Studio supports interactive debugging sessions with the server version of its debugger, and the client-server communication allows you to step into, over, and return from bits of code.  It tells you what variables are currently in the stack, what the chain of functions is that is being called, and many other useful things.  </p>
<p>I have to admit, I didn't come to this point of nirvana without trial.  In trying to configure the Eclipse PDT to communicate effectively with the server debugger running on a remote server, I failed spectacularly.  I tried a few other IDEs, and found them all to be unacceptable.  I even tried Zend Studio 5.5.  I was at the end of my patience when I found the newest version of Zend Studio, which. just. worked.  Yes, I said it.  It just worked, with the exception of changing the default port setting for the remote debugger.</p>
<p>My frustration is gone, I am at one with the code, and I can finally explain exactly what is going on in Drupal - how things get called, where and when they get called, and what the results of each call are.</p>
<p>And that bug with the userpoints module?  The problem existed between keyboard and chair.</p>
<p>
<div class="bsuggestive_footer">
<h3>Related:</h3>
<p><!-- start bsuite_speedcache object bsuggestive/58 on 2008-07-22 17:35:38-->
<ul>
<li><a href="http://beyrent.net/2007/10/19/drupal-releasing-custom-modules/" title="">Drupal: Releasing Custom Modules</a></li>
<li><a href="http://beyrent.net/2007/10/15/drupal-loading-custom-userprofile-data/" title="">Drupal:  Loading custom userprofile data</a></li>
<li><a href="http://beyrent.net/2007/10/11/calling-views-in-code/" title="">Drupal: Calling Views In Code</a></li>
<li><a href="http://beyrent.net/2008/04/03/drupal-and-cross-domain-javascript-widgets/" title="">Drupal: Cross-domain Widgets</a></li>
<li><a href="http://beyrent.net/2008/07/07/drupal-and-sane-flash-remoting/" title="">Drupal and Sane Flash Remoting</a></li>
</ul>
<p><!-- end bsuite_speedcache object --></div>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2008/03/04/php-debugging-goodness/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DrupalCon Boston 2008: Day1</title>
		<link>http://beyrent.net/2008/03/03/drupalcon-boston-2008-day1/</link>
		<comments>http://beyrent.net/2008/03/03/drupalcon-boston-2008-day1/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 21:41:54 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Drupal]]></category>

		<category><![CDATA[DrupalCon]]></category>

		<guid isPermaLink="false">http://beyrent.net/2008/03/03/drupalcon-boston-2008-day1/</guid>
		<description><![CDATA[

I have the distinct pleasure of attending DrupalCon 2008, which is being held in Boston, MA this year.  This year's attendance has blown out the attendance levels of previous DrupalCons, and it is a testament to the growing popularity of Drupal as a content management system.
The sessions I attended today were:
Design on the Edge [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p><img src="http://boston2008.drupalcon.org/sites/all/themes/bluebeach/logo.gif" hspace=8 vspace=4 align="left">I have the distinct pleasure of attending DrupalCon 2008, which is being held in Boston, MA this year.  This year's attendance has blown out the attendance levels of previous DrupalCons, and it is a testament to the growing popularity of Drupal as a content management system.</p>
<p>The sessions I attended today were:</p>
<p><b>Design on the Edge of Drupal</b><br />
This session was principally for designers, and talked about taking inspiration from architecture to build Drupal websites that are anything but standard.  The point of the presentation was that a Drupal site does not have to look like a Drupal site, as long as users of the site have an expectation of how to navigate and get around.</p>
<p><b>Enterprise Theming in Drupal</b><br />
As the engineering manager for <a href="http://www.greenopolis.com">Greenopolis</a>, an environmentally-themed social networking site built 100% in Drupal, this session was very informative.  We have thousands of nodes and users, and the purpose of this session was how to take a very large site and segment it thematically for the purposes of monetizing your audience.</p>
<p><b>Mapping Business Requirements to Drupal Modules</b><br />
This session covered the basic problem of taking what the customer has asked you to build, and applying a development planning process for meeting those business goals.</p>
<p><b>Drupal Multimedia</b><br />
As I continue to work on Greenopolis, one of the challenges I face is how to implement multimedia, especially in user-generated content.  Performance and security are always major concerns, and this session provided a wealth of information regarding the options available to Drupal developers, as well as techniques for accomplishing some of this kind of functionality.</p>
<p>I will be attending DrupalCon on Tuesday and Wednesday, and post more information as the conference progresses.</p>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2008/03/03/drupalcon-boston-2008-day1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cell Phone Aggravation</title>
		<link>http://beyrent.net/2008/02/14/cell-phone-aggravation/</link>
		<comments>http://beyrent.net/2008/02/14/cell-phone-aggravation/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 12:57:05 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://beyrent.net/2008/02/14/cell-phone-aggravation/</guid>
		<description><![CDATA[Much to my dismay, the manager did not know the product he sold me, or else he would have known that the software does not support my phone.  After searching the internet for a few hours, it became clear that a lot of people did not know how to connect their computer to the SCP-3200.]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p><img src='http://beyrent.net/wordpress/wp-content/uploads/2008/02/scp3200atlantic_blue.thumbnail.jpg' alt='scp3200atlantic_blue.jpg' align="right" hspace=8 vspace=4/>I finally broke down and bought a cellphone.  </p>
<p>Nothing fancy, just a Sanyo SCP-3200 with Sprint as the carrier.  There is nothing spectacular about this phone; it's got basic functionality, it's small and lightweight, and is a good solution for someone who doesn't like to talk on the phone in the first place.</p>
<p>Sadly, this phone had an unfortunate interaction with the inside of a toilet bowl, resulting in the white screen of death.  Despite having been submerged in water for less than two seconds, the screen was completely shot, a victim of "massive water damage."</p>
<p>Fortunately, the screen was the only part of the phone that was damaged, but it could not be repaired, so I purchased a new phone of the same model.  My new problem was how to get my contacts and other data off the old phone.  Stupidly, I went to <a href="http://www.radioshack.com" target="_blank">Radio Shack</a> to purchase a <a href="http://global.mobileaction.com/product/product_USB_new.jsp" target="_blank">data cable</a> for $9.99.  The data cable came with the HandsetManager software, which the manager at RadioShack said would help me retrieve my data from the broken cell phone.</p>
<p>Much to my dismay, the manager did not know the product he sold me, or else he would have known that the software does not support my phone.  After searching the internet for a few hours, it became clear that a lot of people did not know how to connect their computer to the SCP-3200.</p>
<p>One tip led me to <a href="http://www.datapilot.com" target="_blank">DataPilot</a>, which is not free.  Despite paying for a data cable and software, I had to shell out another $39.95 for the DataPilot software, which was risky considering the fact that I had no idea if it would work or not.  Out of the box, this software did not support my phone.  I had to update the software several times and from several different places before I could finally connect to my phone.  Once I was able to do that, the software did a good job of reading the data from the phone, allowing me to edit the data and save it to my computer, and then send the data to the new cell phone.</p>
<p><img src='http://beyrent.net/wordpress/wp-content/uploads/2008/02/lg_dp200-134.gif' alt='lg_dp200-134.gif' align="left" hspace=8 vspace=4/>The user interface is not the best, being neither intuitive nor visually appealing.  However, it is very functional software, except it does not support ringtone editing on my phone, or photo editing.  These pieces of missing functionality don't bother me though, as I use neither function on my phone.</p>
<p>So the bottom line is, if you need to connect to a Sanyo SCP-3200 cell phone, one solution is to purchase a data cable and DataPilot, and make sure you update the software after purchasing it.</p>
<p class="bsuite_tagblock" style="text-align:right;font-size:10px;">tags: <a href="http://technorati.com/tag/datapilot" rel="tag">datapilot</a>, <a href="http://technorati.com/tag/handsetmanager" rel="tag">handsetmanager</a>, <a href="http://technorati.com/tag/radioshack" rel="tag">radioshack</a>, <a href="http://technorati.com/tag/scp-3200" rel="tag">scp-3200</a>, <a href="http://technorati.com/tag/sanyo" rel="tag">sanyo</a>, <a href="http://technorati.com/tag/sprint" rel="tag">sprint</a>, <a href="http://technorati.com/tag/cell%2Bphone" rel="tag">cell+phone</a>, <a href="http://technorati.com/tag/water%2Bdamage" rel="tag">water+damage</a></p>
<p>
<div class="bsuggestive_footer">
<h3>Related:</h3>
<p><!-- start bsuite_speedcache object bsuggestive/53 on 2008-07-23 18:05:20-->
<ul>
<li><a href="http://beyrent.net/2006/03/01/configuring-vonage/" title="">Configuring Vonage</a></li>
<li><a href="http://beyrent.net/2005/05/20/voice-your-opinion-judicial-filibusters/" title="">Voice Your Opinion:: Judicial Filibusters</a></li>
<li><a href="http://beyrent.net/2005/09/02/al-qaeda-develops-new-weapons-of-mass-destruction/" title="">Al Qaeda Develops New Weapons of Mass Destruction</a></li>
<li><a href="http://beyrent.net/2006/03/09/configuring-vonage-redux/" title="">Configuring Vonage Redux</a></li>
<li><a href="http://beyrent.net/2005/06/23/the-death-of-property-rights/" title="">The Death of Property Rights</a></li>
</ul>
<p><!-- end bsuite_speedcache object --></div>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2008/02/14/cell-phone-aggravation/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Drupal: Incorrect Pager Results</title>
		<link>http://beyrent.net/2007/12/13/drupal-incorrect-pager-results/</link>
		<comments>http://beyrent.net/2007/12/13/drupal-incorrect-pager-results/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 12:48:47 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[SQL]]></category>

		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://beyrent.net/2007/12/13/drupal-incorrect-pager-results/</guid>
		<description><![CDATA[

I've been working on a Drupal module that generates a search form and presents the results below the form.  However, I ran into a strange issue where the database query returned 3 records, and yet, the pager was displaying 9 pagination links.
The code that builds and handles the query looks like this:
PLAIN TEXT
PHP:




&#60;?php


$query = [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>I've been working on a Drupal module that generates a search form and presents the results below the form.  However, I ran into a strange issue where the database query returned 3 records, and yet, the pager was displaying 9 pagination links.</p>
<p>The code that builds and handles the query looks like this:</p>
<div class="igBar"><span id="lphp-11"><a href="#" onclick="javascript:showPlainTxt('php-11'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-11">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$query</span> = <span style="color:#FF0000;">'select</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; n.nid,</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; n.title,</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; DATE_FORMAT(FROM_UNIXTIME(n.created), <span style="color:#000099; font-weight:bold;">\'</span>%c/%e/%Y<span style="color:#000099; font-weight:bold;">\'</span>) as created,</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; c.field_product_price_value as price,</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; d.name,</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; t.tid</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">from</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; {node} n</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; left join {node_revisions} r on r.vid = n.vid</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; left join {content_type_galleria_product} c on c.nid = n.nid</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; left join {term_node} t on t.nid = n.nid</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">&nbsp; left join {term_data} d on d.tid = t.tid '</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$groupby</span> = <span style="color:#FF0000;">' group by n.nid'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$clauses</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'n.type = <span style="color:#000099; font-weight:bold;">\'</span>galleria_product<span style="color:#000099; font-weight:bold;">\'</span>'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">foreach</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$form_values</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$key</span> =&gt; <span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$key</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span> != <span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#616100;">switch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$key</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">case</span> <span style="color:#FF0000;">'name'</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'n.title like <span style="color:#000099; font-weight:bold;">\'</span>%%'</span>.db_escape_string<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#FF0000;">'%%<span style="color:#000099; font-weight:bold;">\'</span>'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">case</span> <span style="color:#FF0000;">'price_range'</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'c.field_product_price_value &lt;= '</span>.db_escape_string<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">case</span> <span style="color:#FF0000;">'category'</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'t.tid = '</span>.db_escape_string<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#616100;">case</span> <span style="color:#FF0000;">'created'</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">switch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$value</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span>&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">case</span> <span style="color:#FF0000;">'today'</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'DATE(FROM_UNIXTIME(n.created)) = CURDATE()'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">case</span> <span style="color:#FF0000;">'current_week'</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'WEEK(FROM_UNIXTIME(n.created)) = WEEK(NOW())'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#616100;">case</span> <span style="color:#FF0000;">'current_month'</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'MONTH(FROM_UNIXTIME(n.created)) = MONTH(NOW())'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#616100;">break</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#616100;">case</span> <span style="color:#FF0000;">'current_year'</span>:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#FF0000;">'YEAR(FROM_UNIXTIME(n.created)) = YEAR(NOW())'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#000000; font-weight:bold;">default</span>:</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#616100;">break</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$limit</span> = <span style="color:#CC66CC;color:#800000;">30</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$header</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'data'</span> =&gt; t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Name'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#FF0000;">'field'</span> =&gt; <span style="color:#FF0000;">'n.title'</span>, <span style="color:#FF0000;">'sort'</span> =&gt; <span style="color:#FF0000;">'asc'</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'data'</span> =&gt; t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Rating'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'data'</span> =&gt; t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Price'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#FF0000;">'field'</span> =&gt; <span style="color:#FF0000;">'c.field_product_price_value'</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'data'</span> =&gt; t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Category'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#FF0000;">'field'</span> =&gt; <span style="color:#FF0000;">'d.name'</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'data'</span> =&gt; t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Created'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#FF0000;">'field'</span> =&gt; <span style="color:#FF0000;">'n.created'</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$query</span> .= <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/count"><span style="color:#000066;">count</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#FF0000;">'WHERE '</span> . <a href="http://www.php.net/implode"><span style="color:#000066;">implode</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">' AND '</span>, <span style="color:#0000FF;">$clauses</span><span style="color:#006600; font-weight:bold;">&#41;</span> : <span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$tablesort</span> = tablesort_sql<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$header</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$result</span> = pager_query<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$query</span>.<span style="color:#0000FF;">$groupby</span>.<span style="color:#0000FF;">$tablesort</span>, <span style="color:#0000FF;">$limit</span>, <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$rows</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Retrieve all the data found by the query</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">while</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span> = db_fetch_array<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$result</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$current_avg</span> = votingapi_get_voting_results<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'node'</span>, <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'nid'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#FF0000;">'percent'</span>, <span style="color:#FF0000;">'vote'</span>, <span style="color:#FF0000;">'average'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$stars</span> = variable_get<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'fivestar_stars_'</span>. <span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$node</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? <span style="color:#FF0000;">'default'</span> : <span style="color:#0000FF;">$node</span>-&gt;<span style="color:#006600;">type</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#CC66CC;color:#800000;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$rows</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; l<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'title'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#FF0000;">'node/'</span>.<span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'nid'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; theme<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'fivestar_static'</span>, <span style="color:#0000FF;">$current_avg</span><span style="color:#006600; font-weight:bold;">&#91;</span><a href="http://www.php.net/count"><span style="color:#000066;">count</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$current_avg</span><span style="color:#006600; font-weight:bold;">&#41;</span>-<span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>-&gt;<span style="color:#006600;">value</span>, <span style="color:#0000FF;">$stars</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF0000;">'$'</span>.<span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'price'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; l<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'name'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#FF0000;">'taxonomy/term/'</span>.<span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'tid'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'created'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/empty"><span style="color:#000066;">empty</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$rows</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#0000FF;">$rows</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'data'</span> =&gt; t<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Your search failed to find any products.'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#FF0000;">'colspan'</span> =&gt; <span style="color:#CC66CC;color:#800000;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$output</span> = theme<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'table'</span>, <span style="color:#0000FF;">$header</span>, <span style="color:#0000FF;">$rows</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$output</span> .= theme<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'pager'</span>, <span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#0000FF;">$limit</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>After banging my head against the wall for a few hours, I came across <a href="http://www.krisbuytaert.be/blog/?q=node/522" target="_blank">a post by Kris Buytaert</a> which explained why I was seeing this problem.</p>
<p>To summarize, the code that produces the pagination links is in pager.inc.  Within this code is this bit:</p>
<div class="igBar"><span id="lphp-12"><a href="#" onclick="javascript:showPlainTxt('php-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-12">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$count_query</span> = <a href="http://www.php.net/preg_replace"><span style="color:#000066;">preg_replace</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'/SELECT.*?FROM /As'</span>, <span style="color:#FF0000;">'/ORDER BY .*/'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'SELECT COUNT(*) FROM '</span>, <span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span>,<span style="color:#0000FF;">$query</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>You'll note that the pattern matching is <b>case insensitive</b>.  As my query was written all in lowercase, the pagination code was not matching anything.  All I had to do was rewrite the query such that the MySQL keywords were in uppercase.</p>
<p>A bug, to be sure, considering that the SQL Standard does not call for specific case.  As pager.inc is part of the Drupal core, hopefully it will get patched and fixed soon.</p>
<p>
<div class="bsuggestive_footer">
<h3>Related:</h3>
<p><!-- start bsuite_speedcache object bsuggestive/52 on 2008-07-21 18:16:54-->
<ul>
<li><a href="http://beyrent.net/2007/10/19/drupal-releasing-custom-modules/" title="">Drupal: Releasing Custom Modules</a></li>
<li><a href="http://beyrent.net/2007/10/15/drupal-loading-custom-userprofile-data/" title="">Drupal:  Loading custom userprofile data</a></li>
<li><a href="http://beyrent.net/2008/03/04/php-debugging-goodness/" title="">PHP Debugging Goodness</a></li>
<li><a href="http://beyrent.net/2007/10/11/calling-views-in-code/" title="">Drupal: Calling Views In Code</a></li>
<li><a href="http://beyrent.net/2008/04/03/drupal-and-cross-domain-javascript-widgets/" title="">Drupal: Cross-domain Widgets</a></li>
</ul>
<p><!-- end bsuite_speedcache object --></div>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2007/12/13/drupal-incorrect-pager-results/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Drupal: Releasing Custom Modules</title>
		<link>http://beyrent.net/2007/10/19/drupal-releasing-custom-modules/</link>
		<comments>http://beyrent.net/2007/10/19/drupal-releasing-custom-modules/#comments</comments>
		<pubDate>Fri, 19 Oct 2007 12:37:08 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://beyrent.net/2007/10/19/drupal-releasing-custom-modules/</guid>
		<description><![CDATA[

I recently built my first module for Drupal, which exposes data from the Userpoints module to Views.  There was some talk with the CEO of my company about releasing the module to the community as a contributed module, and some hedging about whether to release it or not.
Releasing modules shouldn't even be a topic [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>I recently built my first module for Drupal, which exposes data from the Userpoints module to Views.  There was some talk with the CEO of my company about releasing the module to the community as a contributed module, and some hedging about whether to release it or not.</p>
<p>Releasing modules shouldn't even be a topic of discussion within a company.  The work I did on this module was built off the many, many, many hours others have spent on Userpoints and Views.  In addition, thousands of developers contributed to, and continue to contribute to Drupal.  For a company to even consider taking an Open Source project, developing a feature on top of it and then not releasing it, is rude and insulting to all the developers that have work on this OSS project.</p>
<p>Companies who use Drupal and other open source software have directly benefited from the work of thousands.  These companies have saved gobs and gobs of cash by stating with Drupal as a base and then building on top. That base was built by ordinary people, and that base depends upon people contributing their code.</p>
<p>Credit should be given where it is due and if your company has sponsored the development of Drupal modules by paying your salary, that should be mentioned.  At the very least, your company's name can be in the module itself with the README file and within the code.</p>
<p>Again, this should not even be a topic of discussion.  If you work with Drupal and extend its functionality, release the code to the community.</p>
<p>
<div class="bsuggestive_footer">
<h3>Related:</h3>
<p><!-- start bsuite_speedcache object bsuggestive/49 on 2008-07-22 04:46:06-->
<ul>
<li><a href="http://beyrent.net/2007/10/15/drupal-loading-custom-userprofile-data/" title="">Drupal:  Loading custom userprofile data</a></li>
<li><a href="http://beyrent.net/about/" title="">Profile</a></li>
<li><a href="http://beyrent.net/2008/03/04/php-debugging-goodness/" title="">PHP Debugging Goodness</a></li>
<li><a href="http://beyrent.net/2008/03/03/drupalcon-boston-2008-day1/" title="">DrupalCon Boston 2008: Day1</a></li>
<li><a href="http://beyrent.net/2005/05/12/upgrading-to-freebsd-54/" title="">Upgrading to FreeBSD 5.4</a></li>
</ul>
<p><!-- end bsuite_speedcache object --></div>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2007/10/19/drupal-releasing-custom-modules/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Drupal:  Loading custom userprofile data</title>
		<link>http://beyrent.net/2007/10/15/drupal-loading-custom-userprofile-data/</link>
		<comments>http://beyrent.net/2007/10/15/drupal-loading-custom-userprofile-data/#comments</comments>
		<pubDate>Mon, 15 Oct 2007 15:51:21 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://beyrent.net/2007/10/15/drupal-loading-custom-userprofile-data/</guid>
		<description><![CDATA[

I have found that the core Drupal profile module provides very limited customization possibilities.  However, the Usernode and Nodeprofile modules help out immensely with this.
If you want access to custom user profile fields, such as CCK fields, you simply load the profile:
PLAIN TEXT
PHP:




&#60;?php


$usernode = nodeprofile_load&#40;'uprofile', $node-&#62;uid&#41;;


?&#62; 






tags: drupal, image, nodeprofile, php, user+profile, usernode


Related:


Troubleshooting Profiles
Profile
Tyrants [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>I have found that the core Drupal profile module provides very limited customization possibilities.  However, the Usernode and Nodeprofile modules help out immensely with this.</p>
<p>If you want access to custom user profile fields, such as CCK fields, you simply load the profile:</p>
<div class="igBar"><span id="lphp-14"><a href="#" onclick="javascript:showPlainTxt('php-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-14">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$usernode</span> = nodeprofile_load<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'uprofile'</span>, <span style="color:#0000FF;">$node</span>-&gt;<span style="color:#006600;">uid</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<div class="bsuggestive_footer">
<h3>Related:</h3>
<p><!-- start bsuite_speedcache object bsuggestive/48 on 2008-07-23 06:19:34-->
<ul>
<li><a href="http://beyrent.net/2006/02/06/troubleshooting-profiles/" title="">Troubleshooting Profiles</a></li>
<li><a href="http://beyrent.net/about/" title="">Profile</a></li>
<li><a href="http://beyrent.net/2005/05/20/tyrants-in-skivvies/" title="">Tyrants In Skivvies</a></li>
<li><a href="http://beyrent.net/2008/03/03/drupalcon-boston-2008-day1/" title="">DrupalCon Boston 2008: Day1</a></li>
<li><a href="http://beyrent.net/2008/04/03/drupal-and-cross-domain-javascript-widgets/" title="">Drupal: Cross-domain Widgets</a></li>
</ul>
<p><!-- end bsuite_speedcache object --></div>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2007/10/15/drupal-loading-custom-userprofile-data/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Drupal: Calling Views In Code</title>
		<link>http://beyrent.net/2007/10/11/calling-views-in-code/</link>
		<comments>http://beyrent.net/2007/10/11/calling-views-in-code/#comments</comments>
		<pubDate>Thu, 11 Oct 2007 11:34:52 +0000</pubDate>
		<dc:creator>erich</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://beyrent.net/2007/10/11/calling-views-in-code/</guid>
		<description><![CDATA[

Drupal is a fairly flexible system as far as CMS applications go, and is even more flexible as a development platform.  The Views module gives developers ways to dynamically build queries of data, and display that data in many different ways.  Sometimes, however, you want to display views in ways not supported through [...]]]></description>
			<content:encoded><![CDATA[
<!-- ALL ADSENSE ADS DISABLED -->
<p>Drupal is a fairly flexible system as far as CMS applications go, and is even more flexible as a development platform.  The Views module gives developers ways to dynamically build queries of data, and display that data in many different ways.  Sometimes, however, you want to display views in ways not supported through the admin interface.  Fortunately, there are other ways to get the job done.</p>
<p>For example, I have a block in my sidebar where I want to display a list of the latest blog post, latest forum topic, and latest user poll.  Each of these lists can be created as separate views.  However, there doesn't seem to be any functionality, either in the Views module or another third-party module, that allows you to display multiple unrelated views in a single block.  So, we turn to the code.  The Views API provides a mechanism for building and displaying  your views anywhere in your templates:</p>
<div class="igBar"><span id="lphp-18"><a href="#" onclick="javascript:showPlainTxt('php-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-18">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> views_get_view<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$name_of_view</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
and</p>
<div class="igBar"><span id="lphp-19"><a href="#" onclick="javascript:showPlainTxt('php-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-19">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> views_build_view<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$type</span>, <span style="color:#0000FF;">$view</span>, <span style="color:#0000FF;">$view_args</span>, <span style="color:#0000FF;">$use_pager</span>, <span style="color:#0000FF;">$node_limit</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Clearly, the views_get_view() function retrieves the view definition from the database, while the views_build_view() function renders it.  </p>
<p>Back to my example - I simply created a new block, and set the input format to PHP.  Then, I used the following code to populate the block with the views:</p>
<div class="igBar"><span id="lphp-20"><a href="#" onclick="javascript:showPlainTxt('php-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;h2&gt;Latest Blog Post:&lt;/h2&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span>&nbsp; <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> views_build_view<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'embed'</span>, views_get_view<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'latest_blogpost'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#000000; font-weight:bold;">false</span>, <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;h2&gt;Latest Forum Topic:&lt;/h2&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> views_build_view<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'embed'</span>, views_get_view<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'latest_forumtopic'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#000000; font-weight:bold;">false</span>, <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;h2&gt;Latest Poll:&lt;/h2&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> views_build_view<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'embed'</span>, views_get_view<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'latest_userpoll'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#000000; font-weight:bold;">false</span>, <span style="color:#CC66CC;color:#800000;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The above code shows the rendered view.  However, there are times where you want or need to do some additional processing on the values returned by the view.  Fortunately, the Views module is incredibly powerful, and has a ton of options for retrieving the views.</p>
<p>In the above example, the first argument to the views_build_view() function is 'embed'.  There are several other options:</p>
<ul>
<li>page - Produces output as a page, sent through the theme.  The only real difference between this and block is that a page uses drupal_set_title to change the page title.</li>
<li>block - Produces output as a block, sent through the theme</li>
<li>embed - Use this if you want to embed a view onto another page, and don't want any block or page specific things to happen to it.</li>
<li>result - Returns an array of information, including a database object that  you can use db_fetch_object() on</li>
<li>items - Returns an array like resul, however, it contains an array of objects found by the queries, so you don't have to fetch the objects yourself.</li>
<li>queries - returns an array, summarizing the queries, but does not run them</li>
</ul>
<p>This information comes directly from the code, and hopefully, it will be of some assistance to people who are looking for this kind of functionality.</p>
<p>
<div class="bsuggestive_footer">
<h3>Related:</h3>
<p><!-- start bsuite_speedcache object bsuggestive/47 on 2008-07-19 08:52:33-->
<ul>
<li><a href="http://beyrent.net/2006/05/31/press-announcement/" title="">Press Announcement</a></li>
<li><a href="http://beyrent.net/2007/01/25/ajax-extended-read-me/" title="">AJAX Extended - Read Me</a></li>
<li><a href="http://beyrent.net/2007/03/26/pagination-helper-for-cakephp/" title="">Pagination Helper for CakePHP</a></li>
<li><a href="http://beyrent.net/2007/10/19/drupal-releasing-custom-modules/" title="">Drupal: Releasing Custom Modules</a></li>
<li><a href="http://beyrent.net/2006/04/28/database-migration/" title="">Database Migration</a></li>
</ul>
<p><!-- end bsuite_speedcache object --></div>
]]></content:encoded>
			<wfw:commentRss>http://beyrent.net/2007/10/11/calling-views-in-code/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
