<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dan Polant :: Web Interaction Designer &#187; drupal</title>
	<atom:link href="http://danpolant.com/category/drupal/feed/" rel="self" type="application/rss+xml" />
	<link>http://danpolant.com</link>
	<description></description>
	<lastBuildDate>Tue, 01 Nov 2011 03:55:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Dynamically creating views in Drupal</title>
		<link>http://danpolant.com/dynamically-creating-views-in-drupal/</link>
		<comments>http://danpolant.com/dynamically-creating-views-in-drupal/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 00:09:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[how to]]></category>

		<guid isPermaLink="false">http://danpolant.com/?p=547</guid>
		<description><![CDATA[The Views module can be broken down into three main parts: the query builder, the display builder and the user interface. Usually, we use the interface to control the other two parts, but sometimes situations call for query and display logic that the interface cannot provide.
A good introduction to dynamic views is the function views_embed_view(). [...]]]></description>
			<content:encoded><![CDATA[<p>The Views module can be broken down into three main parts: the query builder, the display builder and the user interface. Usually, we use the interface to control the other two parts, but sometimes situations call for query and display logic that the interface cannot provide.</p>
<p>A good introduction to dynamic views is the function <code><a href="http://drupalcontrib.org/api/drupal/contributions--views--views.module/function/views_embed_view/6">views_embed_view()</a></code>. Using this, one can render the finished display of a view stored in the database or in code. It returns rendered HTML:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$display</span> = views_embed_view<span class="br0">&#40;</span><span class="st0">&quot;name_of_view&quot;</span>, <span class="st0">&quot;display_id&quot;</span>, <span class="re0">$arg1</span>, <span class="re0">$arg2</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Often this function is a good alternative to using views blocks, for situations where the view display should be more tightly integrated in a certain area. By using <code>func_get_args()</code>, <code>views_embed_view</code> lets you pass arguments into the view that would normally have to be in the URL. </p>
<p>However, there are situations where views_embed_view just won&#8217;t cut it. Here are some examples:</p>
<p>1) The user needs be able to choose what filters/fields exist in the view.<br />
2) Groupings need to be dynamically generated based on user input</p>
<p>The functionality listed above cannot be achieved merely by passing arguments into the view. Rather, one must employ methods of the View object ([views module]/includes/view.inc) in order to build up elements of the view from the foundation.</p>
<p>This approach starts with the function <code><a href="http://drupalcontrib.org/api/drupal/contributions--views--views.module/function/views_get_view/6">views_get_view()</a></code>. This function loads a view from any storage, but does not execute or render it. </p>
<p>Now comes the most important function to master, <code>View::add_item()</code>. The code is in views/includes/view.inc. The following snippet demonstrates how to add a node id filter to a view named &#8220;example.&#8221;</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$view</span> = views_get_view<span class="br0">&#40;</span><span class="st0">&#8216;example&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$options</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&#8216;value&#8217;</span> =&gt; <span class="nu0">5</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$view</span>-&gt;<span class="me1">add_item</span><span class="br0">&#40;</span><span class="st0">&#8216;default&#8217;</span>, <span class="st0">&#8216;filter&#8217;</span>, <span class="st0">&#8216;node&#8217;</span>, <span class="st0">&#8216;nid&#8217;</span>, <span class="re0">$options</span>, <span class="st0">&#8216;nid_identifier&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Here is a breakdown of arguments found in <code>View::add_item</code>:</p>
<p>1) display id<br />
2) type &#8211; can be filter, relationship, field, sort<br />
3) table &#8211; can also be table alias<br />
4) options &#8211; see below<br />
5) identifier &#8211; an internal reference to this filter, useful for establishing predictable dynamic keys for fields/filters/relationships that may get added twice. If you don&#8217;t pass anything for this argument, Views will create a unique id using an incremental variable if necessary.</p>
<p>Here is a breakdown of the <code>$options</code> argument, at least that of it which I have used:</p>
<p>1) value &#8211; meaningful only to filters. Specifies the conditions that will pass the filter. This can be an array in order to imply the IN operator<br />
2) operator &#8211; may assume any of the standard db operators. It is not necessary to specify IN if you provide an array as value.<br />
3) relationship &#8211; specifies a relationship for this item to use. Remember that doing this will require that you change the table alias to reflect the relationship table alias.<br />
4) group &#8211; filters only. Specifies a group for this filter to be a part of. Numeric or string values will work.</p>
<p>The majority of the work can be done with the <code>add_item</code> function. If I were to choose one more important method to learn within this subject it would be <code>set_option()</code>. Suppose you have defined several filters as being part of groups 0 and 1. Here is how you would use <code>set_option</code> to tell Views what to do with those groupings:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$groups</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="nu0">0</span> =&gt; <span class="st0">&#8216;OR&#8217;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="nu0">1</span> =&gt; <span class="st0">&#8216;AND&#8217;</span></div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re0">$view</span>-&gt;<span class="me1">display_handler</span>-&gt;<span class="me1">set_option</span><span class="br0">&#40;</span><span class="st0">&#8216;filter_groups&#8217;</span>, <span class="re0">$groups</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>This snippet would create two conditional groups, 0 conjoined by OR and 1 conjoined by AND.</p>
<p>Set_option is a method of the views handler, not the view. It can be used to set any of the other characteristics defined the in the options element of the handler. It can do the same things as <code>add_item</code> but <code>add_item</code> performs additional procedures that help things come out the way you want (in most cases) and is definitely more useful for adding filters, relationships, fields and sorts.</p>
<p>Once you have your view prepared the way you want it, you need to execute and probably render it. The following code will do just that:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$view</span>-&gt;<span class="me1">init_display</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$view</span>-&gt;<span class="me1">pre_execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$view</span>-&gt;<span class="me1">execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// at this point, your view will have results added</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$view</span>-&gt;<span class="me1">post_execute</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; </div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="co1">// this is the final output &nbsp;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re0">$output</span> = <span class="re0">$view</span>-&gt;<span class="me1">display_handler</span>-&gt;<span class="me1">preview</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>There is a lot more you can do with dynamic views than I have outlined here. Generally, the best way to learn more about this is to first use the UI to build a view that contains the elements and characteristics that you want to dynamically add in your function. Then look at the export of that view. You will gain a good understanding of what the $view object and its display handler need to look like in code. Having a PHP debugger is also immensely helpful, but short of that, just use <code>dpm</code> liberally.</p>
]]></content:encoded>
			<wfw:commentRss>http://danpolant.com/dynamically-creating-views-in-drupal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Should I use Drupal 7?</title>
		<link>http://danpolant.com/should-i-use-drupal-7/</link>
		<comments>http://danpolant.com/should-i-use-drupal-7/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 18:24:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Information Industry]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Drupal 7]]></category>

		<guid isPermaLink="false">http://danpolant.com/?p=531</guid>
		<description><![CDATA[There are a lot of things to consider when making the decision to go with Drupal 7 or Drupal 6. I will provide some general advice, but many factors will be specific to your project. So my first piece of advice is to do a lot of research on what modules are available. This means [...]]]></description>
			<content:encoded><![CDATA[<p>There are a lot of things to consider when making the decision to go with Drupal 7 or Drupal 6. I will provide some general advice, but many factors will be specific to your project. So my first piece of advice is to do a lot of research on what modules are available. This means not only looking to see if there is a 7.x code branch, but also downloading and testing each module. Very few modules are out of the development state right now. This doesn&#8217;t mean they won&#8217;t work, but it does mean they probably have quirks/bugs/missing features.</p>
<p>The bottom line is that at this time, Drupal 7 development takes a lot longer than Drupal 6 development. There are benefits of course. To me, Drupal 6 is already starting to seem cumbersome and antiquated at the architectural and UI levels. Many of the Drupal 7 features and modules are way ahead of their Drupal 6 counterparts: Commerce versus Ubercart, Field api versus CCK, Entity API versus, well, nothing &#8230; and et cetera. Soon Drupal 7 will be better supported than Drupal 6, but right now, it is not.</p>
<p>Module update lag now overshadows the benefits of using Drupal 7. I would recommend that the novice PHP/Drupal API developer not use Drupal 7 at this point in time, because the likelihood of having to debug/patch complex modules or implement functionality with little or no documentation, is high. Also, module interactions are fluid and brittle. In order to get a D7 site working that uses Views, Entity API and Date, you have to install and maintain a changing cocktail of dev, beta and RC versions. Using the wrong combination will earn you a site full of undefined function errors. Suffice it to say you had better know how to <a href="http://drupal.org/node/157632">disable modules in the database</a> before attempting to use these modules.</p>
<p>These issues should not daunt skilled developers doing work for clients with large budgets. Drupal 7 development is fun and challenging. A little bit of code goes a long way, especially when working with the entity and field API. Also, at this stage in the game, you may get a chance to write some code for the big modules or for Drupal core, because it is likely that a bug in one of these large codebases will block your way at some point and you will have to either fix it or wait for someone else to do so. One word of warning, if you are a Drupal developer who has hitherto avoided learning about Object Oriented programming (I mean beyond insofar as objects are the same as arrays in PHP), now is the time to put aside your trepidation and <a href="http://www.php.net/manual/en/language.oop5.php">learn at least a little bit</a> about class inheritance, interfaces, abstract classes, protected properties and other structural conventions for OO. Many of the big modules (Views, Rules, Entity API and others) make heavy use of OO now.</p>
<p>On the user interface side, there are two modules that are important to learn for Drupal 7: Rules and Features. Spearheaded mainly by Drupal Commerce, there seems to be an initiative for making rules events where there were once hooks, with rules action instances taking the place of hook implementations. Indeed, Commerce appears somewhat inert until you realize that most of its more advanced features are configurable as rules. If you want to write a module that adds functionality to cart events for example, you will find rules event invocations rather than module hook invocations. Fortunately, rules and hooks function similarly; the difference being that while rules are are more complex to configure in code, they, unlike hook implementations, can be customized and created in the UI and exported as Features.</p>
<p>As Rules becomes more central to the average Drupal consumer, the Features module gains significance too. Rules are beginning to describe increasingly complex procedures and business logic previously defined in module hooks, and only through Features can this functionality be packaged and reused abstractly. Features documentation is abundant and mostly good due to the fact that Features hasn&#8217;t changed much since Drupal 6. My only advice is to get to know the <a href="http://drupal.org/node/960926">drush Features commands</a>: drush fr (feature revert), drush fu (feature update), et cetera.</p>
<p>Bear in mind that as the timestamp on this post slips further into the past, Drupal 7 will have gotten better and the things written here will be less true. Until then, heed this advice: 1) introduce a healthy time/budget buffer in your Drupal 7 estimates, 2) be prepared for programming challenges, 3) do not expect everything to &#8220;just work&#8221; like it did in Drupal 6 and 4) use forums, issue queues and IRC to your advantage. The good thing is once you get into developing with Drupal 7, you will realize how much better it is as a framework compared to Drupal 6. My guess is we have about a year to wait before the old, important Drupal 6 modules are fully upgraded, and the community can return to relying on a large canon of feature-rich and largely bug-free modules.</p>
]]></content:encoded>
			<wfw:commentRss>http://danpolant.com/should-i-use-drupal-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Want to run xDebug? MAMP is the easiest way &#8230;</title>
		<link>http://danpolant.com/want-to-run-xdebug-mamp-is-the-easiest-way/</link>
		<comments>http://danpolant.com/want-to-run-xdebug-mamp-is-the-easiest-way/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 02:40:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[drupal]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[xdebug]]></category>

		<guid isPermaLink="false">http://danpolant.com/?p=477</guid>
		<description><![CDATA[Just got through an epic struggle with Xdebug. It ended in victory! Some one had demonstrated this software at the last Ann Arbor Drupal Users Group meeting and it looked sweet. Xdebug provides a standard set of debugging features, like breakpoints, watch expressions, step into/through/over/out, etc. It integrates well with Netbeans and one of my co-workers [...]]]></description>
			<content:encoded><![CDATA[<p>Just got through an epic struggle with <a title="xDebug" href="http://www.xdebug.org/">Xdebug</a>. It ended in victory! Some one had demonstrated this software at the last <a title="Ann Arbor Drupal Users Group" href="http://groups.drupal.org/ann-arbor">Ann Arbor Drupal Users Group</a> meeting and it looked sweet. Xdebug provides a standard set of debugging features, like breakpoints, watch expressions, step into/through/over/out, etc. It integrates well with Netbeans and one of my co-workers runs it with Eclipse.</p>
<p>Really my struggle should have been less epic. Quite simply, if you have MAMP, don&#8217;t try to install xDebug in your MAMP Apache instance. Why? It&#8217;s already there! Just put this in your php.ini (the one in the MAMP instance, probably something like /Applications/MAMP/conf/php5.x/php.ini):</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>xdebug<span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">zend_extension=<span class="st0">&quot;/Applications/MAMP/bin/php5.2/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so&quot;</span></div>
</li>
<li class="li1">
<div class="de1">xdebug.remote_enable=<span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">xdebug.remote_host=localhost</div>
</li>
<li class="li2">
<div class="de2">xdebug.remote_port=<span class="nu0">9000</span></div>
</li>
<li class="li1">
<div class="de1">xdebug.remote_handler=dbgp</div>
</li>
</ol>
</div>
<p>If you are trying to install xDebug on a linux machine, or Windows, there are tons of instructions accessible via easy googling, or on the Xdebug site.</p>
<p>If you are special like me, and managed to overwrite your original MAMP copy of xdebug.so, don&#8217;t try to re-compile it. Instead, if you find yourself down this path, simply find your original MAMP download, grab its xDebug.so and throw it where it needs to be (somewhere relatively close to the url after &#8220;zend_extension&#8221; up above). I tried to compile my own xDebug.so, but the MAMP instance of phpize would not run correctly on the Xdebug files.</p>
<p>Xdebug is great. I have no complaints, but bear in mind I am ecstatic about simply getting any PHP debugger to work. So far, Netbeans is my favorite text-editor/IDE. It has better usability than Eclipse and is faster and more reliable than Aptana. The only annoying thing is that it opens too many browser tabs while debugging. It makes a new tab for every session, as well as a whole tab for a &#8220;session ending&#8221; message. Integration with Growl or some other ambient notifier would have been better.</p>
]]></content:encoded>
			<wfw:commentRss>http://danpolant.com/want-to-run-xdebug-mamp-is-the-easiest-way/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTML playground for drupal</title>
		<link>http://danpolant.com/html-playground-for-drupal/</link>
		<comments>http://danpolant.com/html-playground-for-drupal/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 19:52:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[drupal]]></category>

		<guid isPermaLink="false">http://danpolant.com/?p=430</guid>
		<description><![CDATA[Recently I had to build this. It&#8217;s a simple little app that uses the forms API. Think w3schools.com &#8220;try it yourself.&#8221;



function sg_games_menu&#40;&#41;&#123;


&#160;


&#160; &#160; &#160; &#160; $items&#91;&#8216;html-sandbox&#8217;&#93; = array&#40;


&#160; &#160; &#160; &#160; &#160; &#160; &#160;&#8216;title&#8217; =&#62; t&#40;&#8216;HTML sandbox&#8217;&#41;,


&#160; &#160; &#160; &#160; &#160; &#160; &#160;&#8216;page callback&#8217; =&#62; &#8216;sg_games_html&#8217;,


&#160; &#160; &#160; &#160; &#160; &#160; &#160;&#8216;access arguments&#8217; =&#62; array&#40;&#8216;access [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I had to build this. It&#8217;s a simple little app that uses the forms API. Think <a href="w3schools.com">w3schools.com</a> &#8220;try it yourself.&#8221;</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> sg_games_menu<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$items</span><span class="br0">&#91;</span><span class="st0">&#8216;html-sandbox&#8217;</span><span class="br0">&#93;</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&#8216;title&#8217;</span> =&gt; t<span class="br0">&#40;</span><span class="st0">&#8216;HTML sandbox&#8217;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&#8216;page callback&#8217;</span> =&gt; <span class="st0">&#8216;sg_games_html&#8217;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&#8216;access arguments&#8217;</span> =&gt; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&#8216;access content&#8217;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="st0">&#8216;type&#8217;</span> =&gt; PAGE_CALLBACK,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$items</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> sg_games_html<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$output</span> = drupal_get_form<span class="br0">&#40;</span><span class="st0">&#8216;sg_games_html_form&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$output</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> sg_games_html_form<span class="br0">&#40;</span> <span class="re0">$form_state</span> <span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span> !<span class="re0">$output</span> = <span class="re0">$form_state</span><span class="br0">&#91;</span><span class="st0">&#8216;storage&#8217;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;values&#8217;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;editor&#8217;</span><span class="br0">&#93;</span> <span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$output</span> = <span class="st0">&#8216;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0">&lt;h1&gt;Try entering some html!&lt;/h1&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0">&#8216;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$form</span><span class="br0">&#91;</span><span class="st0">&#8216;editor&#8217;</span><span class="br0">&#93;</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;#type&#8217;</span> =&gt; <span class="st0">&#8216;textarea&#8217;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;#title&#8217;</span> =&gt; t<span class="br0">&#40;</span><span class="st0">&#8216;Enter your HTML code here&#8217;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;#default_value&#8217;</span> =&gt; <span class="re0">$output</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$form</span><span class="br0">&#91;</span><span class="st0">&#8216;submit&#8217;</span><span class="br0">&#93;</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;#type&#8217;</span> =&gt; <span class="st0">&#8216;submit&#8217;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;#value&#8217;</span> =&gt; <span class="st0">&#8216;Try it!&#8217;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$form</span><span class="br0">&#91;</span><span class="st0">&#8216;output&#8217;</span><span class="br0">&#93;</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;#value&#8217;</span> =&gt; <span class="re0">$output</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;#prefix&#8217;</span> =&gt; <span class="st0">&#8216;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0">&lt;div id=&quot;sg-games-output&quot;&gt;&#8217;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;#suffix&#8217;</span> =&gt; <span class="st0">&#8216;&lt;/div&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0">&#8216;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$form</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">function</span> sg_games_html_form_submit<span class="br0">&#40;</span><span class="re0">$form</span>, &amp;amp;<span class="re0">$form_state</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$form_state</span><span class="br0">&#91;</span><span class="st0">&#8216;storage&#8217;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;values&#8217;</span><span class="br0">&#93;</span> = <span class="re0">$form_state</span><span class="br0">&#91;</span><span class="st0">&#8216;values&#8217;</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$form_state</span><span class="br0">&#91;</span><span class="st0">&#8216;rebuild&#8217;</span><span class="br0">&#93;</span> = <span class="kw2">TRUE</span>;</div>
</li>
<li class="li2">
<div class="de2"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>All it really needs to do is hand off the form_state back into storage, rebuild the same form, and use part of the storage array as the default value of the editor field. </p>
<p>This one is really going to send shockwaves through the Drupal community <img src='http://danpolant.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://danpolant.com/html-playground-for-drupal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>R integration with PHP</title>
		<link>http://danpolant.com/r-integration-with-php/</link>
		<comments>http://danpolant.com/r-integration-with-php/#comments</comments>
		<pubDate>Mon, 17 May 2010 18:10:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[R]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://danpolant.com/?p=329</guid>
		<description><![CDATA[Recently, I needed to do some statistical tests on data from within a Drupal Module. Having found no PHP libraries suitable for the task, I decided to try and run code in R from within PHP. This post helped out a great deal.
As far as I can tell, the only way to do this is [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I needed to do some statistical tests on data from within a Drupal Module. Having found no PHP libraries suitable for the task, I decided to try and run code in R from within PHP. <a href="http://http://www.stanford.edu/~mjockers/cgi-bin/drupal/node/25">This post</a> helped out a great deal.</p>
<p>As far as I can tell, the only way to do this is to write the R output to a temporary file. So to start off, I create a new temp file with:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$path</span> = <a href="http://www.php.net/tempnam"><span class="kw3">tempnam</span></a><span class="br0">&#40;</span><span class="st0">&#8216;/tmp&#8217;</span>, <span class="st0">&#8216;tmp&#8217;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>This function, in case you&#8217;ve never seen it, creates a file with a random name in the directory specified by the first argument, with the extension specified by the second argument.</p>
<p>Next, I loaded up some R. Here&#8217;s what I did:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="re0">$rcode</span> = &lt;&lt;&lt;EOD</div>
</li>
<li class="li1">
<div class="de1">library<span class="br0">&#40;</span>RMySQL<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">con &lt;- dbConnect<span class="br0">&#40;</span>dbDriver<span class="br0">&#40;</span><span class="st0">&#8216;MySQL&#8217;</span><span class="br0">&#41;</span>, dbname = <span class="st0">&#8216;sg_drupal&#8217;</span>,</div>
</li>
<li class="li2">
<div class="de2">username=<span class="st0">&#8216;xxxx&#8217;</span>, password=<span class="st0">&#8216;xxxxxx&#8217;</span>,host=<span class="st0">&#8216;localhost&#8217;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">data &lt;- dbGetQuery<span class="br0">&#40;</span>con,statement=<span class="st0">&#8216;$sql&#8217;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">x = data<span class="br0">&#91;</span>,<span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#91;</span>data<span class="br0">&#91;</span><span class="st0">&#8216;x&#8217;</span><span class="br0">&#93;</span>==<span class="re0">$a</span><span class="br0">&#93;</span></div>
</li>
<li class="li2">
<div class="de2">y = data<span class="br0">&#91;</span>,<span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#91;</span>data<span class="br0">&#91;</span><span class="st0">&#8216;x&#8217;</span><span class="br0">&#93;</span>==<span class="re0">$b</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">x = <span class="kw1">as</span>.numeric<span class="br0">&#40;</span>x<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">y = <span class="kw1">as</span>.numeric<span class="br0">&#40;</span>y<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li2">
<div class="de2">ttest = t.test<span class="br0">&#40;</span>x,y<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">library<span class="br0">&#40;</span>rjson<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">ttest = toJSON<span class="br0">&#40;</span>ttest<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">cat<span class="br0">&#40;</span>ttest, <a href="http://www.php.net/file"><span class="kw3">file</span></a>=<span class="st0">&#8216;$path&#8217;</span><span class="br0">&#41;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">EOD;</div>
</li>
</ol>
</div>
<p>First, you connect to your database in R. This is a lot easier than trying to pass in a result set &#8211; you could use JSON to do this if you really needed to. But R runs MySQL queries just fine, and puts them into neatly accessible vectors. Don&#8217;t forget to load the RMySQL library before doing your queries. I believe this comes with the standard package of R. </p>
<p>One word of warning &#8211; be careful of using the $ sign in your R code string. There may be a way to escape it, but I couldn&#8217;t (quickly) find a way to use this character without PHP trying to parse it as a variable. Fortunately, R has substitute ways to access vectors of a dataset.</p>
<p>Here I&#8217;d like to point out that R has a unique functionality that makes it better than PHP for manipulating and traversing raw data. Without having to write a loop, R has functions that can create new vectors out of the matching values of existing vectors, like this:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">x = data<span class="br0">&#91;</span>,<span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#91;</span>data<span class="br0">&#91;</span><span class="st0">&#8216;x&#8217;</span><span class="br0">&#93;</span>==<span class="re0">$a</span><span class="br0">&#93;</span></div>
</li>
</ol>
</div>
<p>This command means &#8220;assign the second vector of dataset &#8216;data&#8217; where the &#8216;x&#8217; vector equals $a, to variable x.&#8221;</p>
<p>After loading the rjson library, you can turn your output, in this case a T-test, into JSON notation. JSON is a special format that makes data readable by PHP and Javascript as an object or array. Finally, </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">cat<span class="br0">&#40;</span>ttest, <a href="http://www.php.net/file"><span class="kw3">file</span></a>=<span class="st0">&#8216;$path&#8217;</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>writes the JSON output to the temp file we created. But none of this has been executed yet. So let&#8217;s say:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><a href="http://www.php.net/exec"><span class="kw3">exec</span></a><span class="br0">&#40;</span><span class="st0">&quot;echo <span class="es0">\&quot;</span>$rcode<span class="es0">\&quot;</span> | /usr/bin/R &#8211;vanilla&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$back</span> = <a href="http://www.php.net/file_get_contents"><span class="kw3">file_get_contents</span></a><span class="br0">&#40;</span><span class="re0">$path</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$back</span> = json_decode<span class="br0">&#40;</span><span class="re0">$back</span>, <span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>First, this runs the R code as a UNIX command on your server. Then, it reads the contents of the temp file and JSON decodes them. The second &#8220;true&#8221; argument of json_decode returns the data as an array rather than an object. This is important because R will often name its properties with spaces and other illegal characters for object properties in PHP. There is probably a way to escape or change these characters, but I couldn&#8217;t find it. The array will work just as well as the object though.</p>
<p>I thought this was pretty cool. Using this method, you could run statistics on anything in your database and display it on a web page. This seems like a clever way to display usage statistics to site admins, and actually give them an idea of whether the results are statistically significant. </p>
]]></content:encoded>
			<wfw:commentRss>http://danpolant.com/r-integration-with-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Drupal vs. WordPress</title>
		<link>http://danpolant.com/drupal-vs-wordpress/</link>
		<comments>http://danpolant.com/drupal-vs-wordpress/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 01:03:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Critical Writing]]></category>
		<category><![CDATA[drupal]]></category>

		<guid isPermaLink="false">http://danpolant.com/?p=193</guid>
		<description><![CDATA[User interface:
Drupal’s user interface has a steeper learning curve than that of WordPress. Users of WordPress are mostly bloggers, so the interface emphasizes a small set of the things bloggers need to do most frequently, like writing new posts, editing/deleting old posts and viewing statistics. The dashboard aggregates these high-use panels as a default landing [...]]]></description>
			<content:encoded><![CDATA[<h4>User interface:</h4>
<p>Drupal’s user interface has a steeper learning curve than that of WordPress. Users of WordPress are mostly bloggers, so the interface emphasizes a small set of the things bloggers need to do most frequently, like writing new posts, editing/deleting old posts and viewing statistics. The dashboard aggregates these high-use panels as a default landing page after authentication. </p>
<h4>Users:</h4>
<p>Drupal users have more diverse needs than just blogging support. Drupal provides more flexible layouts (panels) and information displays (views) than anything in the WordPress framework currently has to offer. An inexperienced, non-technical user would probably give up long before they got Drupal to do anything like what they wanted, whereas the default post-management behavior of WordPress caters to the goals of users who want to spend more time creating content than managing it.<br />
I believe the fundamental difference between Drupal and WordPress is that Drupal fulfills the needs of developers while WordPress fulfills the needs of end-users. This means if you are developing WordPress plugins, you’re developing software for normal people, and if you’re building Drupal modules, you’re developing software to help people build websites for normal people. Not to say that people don’t hire WordPress developers to build custom sites, but if you want a site that features a non-blog-like information architecture or layout, a Drupal developer will be able to build your site cheaper by spending less time.</p>
<h4>Extendability:</h4>
<p>Drupal’s information architecture is more abstracted and more extendable than that of WordPress. In WordPress the post is analogous to a node, but no one has gone as far as to create a data-structure in WordPress that is as infinitely extendable as Drupal CCK. The closest WordPress has is a post metadata table, which really doesn’t come very close.</p>
]]></content:encoded>
			<wfw:commentRss>http://danpolant.com/drupal-vs-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

