<?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>Blog: Raised Eyebrow Web Studio, Inc. &#187; Drupal</title>
	<atom:link href="http://blog.raisedeyebrow.com/category/cms/drupal/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.raisedeyebrow.com</link>
	<description>What's turning heads at Raised Eyebrow</description>
	<lastBuildDate>Thu, 15 Jul 2010 15:19:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Datadotgc.ca &#8211; A Drupal case study: Part 2</title>
		<link>http://blog.raisedeyebrow.com/2010/06/datadotgc-ca-a-drupal-case-study-part-2/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=datadotgc-ca-a-drupal-case-study-part-2</link>
		<comments>http://blog.raisedeyebrow.com/2010/06/datadotgc-ca-a-drupal-case-study-part-2/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 19:23:41 +0000</pubDate>
		<dc:creator>Colin Calnan</dc:creator>
				<category><![CDATA[Code and Coding]]></category>
		<category><![CDATA[Content Management Systems]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[CKAN]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=880</guid>
		<description><![CDATA[This is the second part of Drupal Case Study on integrating the CKAN data repository with Drupal 6. Part 1 covered the following:

What is CKAN?
CKAN’s API
The Foundation
The Build
Theming
Homepage Chart

Caching
API calls are expensive. There&#8217;s no doubt about that. Particularly when you&#8217;re returning large amounts of data. To avoid any issues of the CKAN API being exhausted [...]]]></description>
			<content:encoded><![CDATA[<p>This is the second part of Drupal Case Study on integrating the CKAN data repository with Drupal 6. <a href="/2010/04/datadotgc-ca-a-drupal-case-study/">Part 1 covered the following</a>:</p>
<ul>
<li>What is CKAN?</li>
<li>CKAN’s API</li>
<li>The Foundation</li>
<li>The Build</li>
<li>Theming</li>
<li>Homepage Chart</li>
</ul>
<h3>Caching</h3>
<p>API calls are expensive. There&#8217;s no doubt about that. Particularly when you&#8217;re returning large amounts of data. To avoid any issues of the CKAN API being exhausted from requests and to ensure that the site remained responsive, I decided to leverage Drupals caching mechanisms and pretty much cached everything I could, within reason. <a href="http://www.datadotgc.ca">The Chart</a>, Tag Cloud, <a href="http://www.datadotgc.ca/data/tag">Tag lists</a>, <a href="http://www.datadotgc.ca/data/ministry">Ministry lists</a>, <a href="http://www.datadotgc.ca/data/all">All Packages</a> list and all individual packages are cached. The issue with caching on this site is that if a package gets updated on the CKAN instance, we need to know about that on our Drupal site immediately and then clear the appropriate caches so that the most recent data can be retrieved. </p>
<p>For caching I created a table called &#8216;cache_ckan&#8217;, that stores everything I need. To create this table I used the schema of the existing cache table and put that in my .install file in my module directory.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p880code8'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8808"><td class="code" id="p880code8"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Implementation of hook_install().
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> ckan_install<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  drupal_install_schema<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Implementation of hook_uninstall().
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> ckan_uninstall<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  drupal_uninstall_schema<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Implementation of hook_schema().
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> ckan_schema<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$schema</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$schema</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> drupal_get_schema_unprocessed<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'system'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$schema</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Whenever this module is enabled this schema will be run and the table will be created.</p>
<h4>What is stored in the ckan_cache table?</h4>
<p>There are various items stored in the cache table.</p>
<ol>
<li>The Homepage chart data</li>
<li>Tag lists</li>
<li>Ministry lists</li>
<li>List of all datasets</li>
</ol>
<p>Let&#8217;s take the <a href="http://www.datadotgc.ca/data/all">list of all packages</a> as an example. I covered how I implemented the paging in <a href="/2010/04/datadotgc-ca-a-drupal-case-study/">my previous post</a>. As this list is paginated it&#8217;s important that every page be cached to improve the speed of the site. As the paging mechanism is already implemented it&#8217;s just a case of creating a cache table entry (<strong>ckan:all{page-number}</strong>) for each page, and then checking for it&#8217;s existence when loading the page.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p880code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8809"><td class="code" id="p880code9"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> cache_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan:all'</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// If cached data exists for this page...</span>
	<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$ckan</span> <span style="color: #339933;">=</span> ckan_ckan<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$items_per_page</span> <span style="color: #339933;">=</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_items_per_page'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// If we're in a page, we need to set where to start the list</span>
		<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$items_per_page</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Set the offset to the number of records in</span>
	<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Limit to the number of items per page </span>
	<span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$items_per_page</span><span style="color: #339933;">;</span>
&nbsp;
	try <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">advancedSearch</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'groups'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'canadagov'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all_fields'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'offset'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'limit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// If the API call worked</span>
	watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Called CKAN API for list of all packages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	cache_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan:all'</span><span style="color: #339933;">.</span><span style="color: #000088;">$page</span><span style="color: #339933;">,</span> <span style="color: #000088;">$results</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This method is very simple and very effective. It means the pages load lightning fast and only one page of data at a time is retrieved.</p>
<h4>How does the cache get cleared/updated</h4>
<p>Datasets/Packages change all the time on the CKAN instance, so how do you make sure that the Drupal site has the most current data. This module has two ways of managing that.</p>
<h4>1. Using <a href="http://api.drupal.org/api/function/hook_form/6">hook_form</a> to redirect to CKAN</h4>
<p>As the CKAN nodes on Drupal are created on the fly and hold very little information, there is really no need to access the EDIT form for these nodes. Whenever an admin user clicks the edit tab on the node, they are automatically redirected to the appropriate CKAN package editing screen. hook_form is called to retrieve the form that is displayed when one attempts to &#8220;create/edit&#8221; an item. For CKAN content types, the user is redirect to the CKAN instance.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p880code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p88010"><td class="code" id="p880code10"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Implementation of hook_form
 *
 * Redirect the user to ca.ckan.net package edit screen on edit
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> ckan_form<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$node</span><span style="color: #339933;">,</span> <span style="color: #000088;">$form_state</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">type</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'ckan'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  	drupal_goto<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://ca.ckan.net/package/edit/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When the CKAN form is submitted, CKAN then redirects back to the Drupal site and calls a specific URL that tells Drupal to call CKAN again to get the package information and populate the node. To clarify, the process is</p>
<ol>
<li>Redirect http://www.datadotgc.ca/node/X/edit to http://ca.ckan.net/package/edit/{name of X}</li>
<li>On save of CKAN Package, redirect to http://www.datadotgc.ca/{special_url}/{name_of_X}</li>
<li>Load the node with {name_of_X}</li>
<li>Call CKAN to get the (updated) data for Package {name_of_X}</li>
<li>Save the node with updated data</li>
</ol>
<h4>Using Cron and an Atom Feed</h4>
<p>CKAN provides an Atom feed of recent updates to the Packages. Cron checks this feed every time it runs. If the feed has changed since the last cron run, then we know there have been updates and we clear all of the caches.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p880code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p88011"><td class="code" id="p880code11"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Implementation of hook_cron()
 *
 **/</span>
<span style="color: #000000; font-weight: bold;">function</span> ckan_cron<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Get the md5sum of the current atom feed</span>
	<span style="color: #000088;">$current_feed</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/md5_file"><span style="color: #990000;">md5_file</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://ca.ckan.net/revision/list?format=atom'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Current feed md5: '</span><span style="color: #339933;">.</span> <span style="color: #000088;">$current_feed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Retrieve the previously stored md5sum</span>
	<span style="color: #000088;">$previous_feed</span> <span style="color: #339933;">=</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_atom_feed_md5'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current_feed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Previous feed md5: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$previous_feed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// If there have been changes</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_feed</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$previous_feed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ATOM feed has updated, clearing caches and deleting nodes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Flush all the caches</span>
		cache_clear_all<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	        <span style="color: #666666; font-style: italic;">// Set the previous feed md5</span>
		variable_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_atom_feed_md5'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$current_feed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Tag cloud creation</h3>
<p>I borrowed some code from the <a href="http://drupal.org/project/tagadelic">Tagadelic</a> module to achieve the tag cloud</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p880code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p88012"><td class="code" id="p880code12"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Build a tag cloud based on the settings provided
 *
 * @return	String	A themed list of weighted tags
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> ckan_tag_cloud<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// If there is cached data</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> cache_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan:tags'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/unserialize"><span style="color: #990000;">unserialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$ckan</span> <span style="color: #339933;">=</span> ckan_ckan<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTagCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Called CKAN API for tag cloud'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		cache_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan:tags'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Let's sort them by weight first off</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$tag</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span>  <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$weight</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<a href="http://www.php.net/array_multisort"><span style="color: #990000;">array_multisort</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$weight</span><span style="color: #339933;">,</span> SORT_DESC<span style="color: #339933;">,</span> <span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Now let's get the top X number of tags</span>
	<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_slice"><span style="color: #990000;">array_slice</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_tagcloud_total'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Now build the tags</span>
	<span style="color: #000088;">$tags</span> <span style="color: #339933;">=</span> ckan_tag_build_weighted<span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Sort them</span>
	<span style="color: #000088;">$tags</span> <span style="color: #339933;">=</span> ckan_tag_sort<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Theme them</span>
	<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> theme<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_weighted_tags'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Theme function that renders the HTML for the tags
 * @ingroup themable
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> theme_ckan_weighted_tags<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tag</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> l<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'data/tag/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$tag</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attributes'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;tagcloud level&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$tag</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'weight'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rel'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tag'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Using the CKAN Search API for all lists</h3>
<p>Ok, so what&#8217;s this all about? CKAN has some <a href="http://knowledgeforge.net/ckan/doc/ckan/api.html">nice API calls</a> like <em>/api/rest/package/PACKAGE-REF</em> that return a list of Packages. However these return the name/id of the Package ONLY. In our case, for our listings, we wanted other data, such as the tags attached to the Package as well as a brief description.</p>
<p>The only way to get this data was to do a search API call <em>/api/search/package</em> and pass some extra parameters, in this case <em><strong>all_fields=1</strong></em> and <em><strong>department={name of Ministry}</strong></em>. </p>
<p><em><strong>all_fields=1</strong></em> tells the search to return all Package fields, not just the name/id; just as is if you called  <em>/api/rest/package/PACKAGE-REF</em>.</p>
<p><em><strong>department={name of Ministry}</strong></em> tells the search to return all packages that have a department of {name of Ministry}. <strong>The lovely folks at CKAN added this functionality for us on request</strong>.</p>
<p>What does this look like, well it&#8217;s pretty simple really. Call the <em>advancedSearch()</em> function. Pass it a few parameters and it returns you all the data you need. Here&#8217;s the function itself:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p880code13'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p88013"><td class="code" id="p880code13"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> advancedSearch<span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parameters</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$querystring</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'='</span><span style="color: #339933;">.</span> <a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">transfer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'api/search/package?'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$querystring</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$results</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> CkanException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Search Error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$results</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>And here is that function being called for the list of Ministry Packages. The offset and limit are for the paging mechanism:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p880code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p88014"><td class="code" id="p880code14"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Call the function</span>
<span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">advancedSearch</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'department'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ministry</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all_fields'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'offset'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'limit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>There&#8217;s a lot more functionality in this module, more than I can go through in a blog post, even 5 posts. If you&#8217;re trying to integrate Drupal with a CKAN instance and are not sure where to start then please leave a comment and I&#8217;ll get back in touch.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2010/06/datadotgc-ca-a-drupal-case-study-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hey, Web Geeks With Hearts of Gold: We&#8217;re Hiring.</title>
		<link>http://blog.raisedeyebrow.com/2010/05/hey-web-geeks-with-hearts-of-gold-were-hiring/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=hey-web-geeks-with-hearts-of-gold-were-hiring</link>
		<comments>http://blog.raisedeyebrow.com/2010/05/hey-web-geeks-with-hearts-of-gold-were-hiring/#comments</comments>
		<pubDate>Fri, 28 May 2010 16:31:08 +0000</pubDate>
		<dc:creator>Lauren Bacon</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Nonprofit Tech]]></category>
		<category><![CDATA[Raised Eyebrow]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=915</guid>
		<description><![CDATA[We&#8217;re excited to announce a new opportunity at Raised Eyebrow. Our little-web-studio-that-could is growing again, and we&#8217;ve got an opening for a Front-End Developer/Themer to help us build awesome websites for fabulous, mission-driven clients.
This is a position for someone with solid technical skills &#8212; someone who can rock HTML and CSS, who prides themselves on [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re excited to announce a new opportunity at Raised Eyebrow. Our little-web-studio-that-could is growing again, and we&#8217;ve got an opening for a <a href="http://raisedeyebrow.com/jobs/">Front-End Developer/Themer</a> to help us build awesome websites for fabulous, mission-driven clients.</p>
<p>This is a position for someone with solid technical skills &#8212; someone who can rock HTML and CSS, who prides themselves on attention to detail and clean, elegant code. You&#8217;ll be turning design comps into themes for Drupal and WordPress sites, so experience with one (or both) of those CMS&#8217;s is preferred, but if you&#8217;re confident in your coding skills and are new to Drupal &amp; WordPress, don&#8217;t let that stop you.</p>
<p>Because we&#8217;re a small shop, everyone here tends to wear a few hats, so we&#8217;re looking for someone with smarts, adaptability and a serious appetite for learning. We pride ourselves on the quality of our work, our efficiency, and our passion for our clients &#8212; and we&#8217;re looking for someone whose shares those values.</p>
<p>In our beautiful, heritage Gastown office, you&#8217;ll find a friendly team of experts, a ridiculously well-stocked tea cabinet, and abundant opportunities to work on projects that allow you to flex your technical muscles and bring your heart and ideals to work.</p>
<p>Sound like a fit for you (or someone you know)? <a href="http://raisedeyebrow.com/jobs/">The job description, with details on how to apply, is right here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2010/05/hey-web-geeks-with-hearts-of-gold-were-hiring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Datadotgc.ca &#8211; A Drupal case study</title>
		<link>http://blog.raisedeyebrow.com/2010/04/datadotgc-ca-a-drupal-case-study/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=datadotgc-ca-a-drupal-case-study</link>
		<comments>http://blog.raisedeyebrow.com/2010/04/datadotgc-ca-a-drupal-case-study/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 17:56:20 +0000</pubDate>
		<dc:creator>Colin Calnan</dc:creator>
				<category><![CDATA[Code and Coding]]></category>
		<category><![CDATA[Content Management Systems]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Nonprofit Tech]]></category>
		<category><![CDATA[CKAN]]></category>
		<category><![CDATA[Open data]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=863</guid>
		<description><![CDATA[We recently launched http://www.datadotgc.ca, an open data collection portal for Canada, built to help poke the Canadian government in the right direction, towards something like similar sites in the UK (data.gov.uk) and the US (data.gov). Read David Eaves&#8217; explanation of its purpose. For the benefit of the programming and Drupal community, I&#8217;m going to run [...]]]></description>
			<content:encoded><![CDATA[<p>We recently launched <a href="http://www.datadotgc.ca">http://www.datadotgc.ca</a>, an open data collection portal for Canada, built to help poke the Canadian government in the right direction, towards something like similar sites in the UK (<a href="http://data.gov.uk">data.gov.uk</a>) and the US (<a href="http://data.gov">data.gov</a>). <a href="http://eaves.ca/2010/04/15/datadotgc-ca-launched-the-opportunity-and-challenge/">Read David Eaves&#8217; explanation of its purpose</a>. For the benefit of the programming and Drupal community, I&#8217;m going to run through, with the aid of code samples, the development of the Drupal module to communicate with the CKAN API (which is where the data is stored). I&#8217;ll also walk through Theming, integration with Google Charts, Tag Clouds and most importantly, caching.</p>
<h3>What is CKAN?</h3>
<blockquote><p>CKAN is a registry or catalogue system for datasets or other &#8220;knowledge&#8221; resources. CKAN aims to make it easy to find, share and reuse open content and data, especially in ways that are machine automatable.</p></blockquote>
<p>CKAN is a nice big database that is built to accept user input of the type of data we&#8217;re trying to collect for datadotgc.ca. It has a slick front and back end that allows administrative access to the collected data.<br />
You can find out more on <a href="http://www.okfn.org/ckan/">their website</a>. </p>
<h3>CKAN&#8217;s API</h3>
<p>In order to utilize the power of CKAN I needed to link it up to Drupal. CKAN has a <a href="http://knowledgeforge.net/ckan/doc/ckan/api.html">powerful and flexible API</a> that I used extensively in the module.</p>
<h3>The Foundation</h3>
<p>Early on in the project I got in touch with the wonderful team at CKAN and they then put me in touch with Sean Burlington from the <a href="http://data.gov.uk">data.gov.uk</a> development team. They had also built their site in Drupal and Seán had lots of information on how they tweaked their CKAN site to work with Drupal. He worked hard to open source some of the work that they had done, and <a href="http://www.practicalweb.co.uk/blog/10/02/24/drupal-module-ckan-integration">released it</a> just in time for us to get started. Seáns module provided the basic API connectivity we needed to get started and was the foundation for our module.</p>
<h3>The Build</h3>
<p>How do you integrate Drupal with the CKAN API? Let&#8217;s start with the basics:</p>
<p>CKAN stores the <a href="http://www.datadotgc.ca/dataset/geogratisnat_hydrography_v100">individual datasets that you see on Datadotgc.ca</a> as &#8216;<em>Packages</em>&#8216;. It became clear that these &#8216;Packages&#8217; could be directly mapped to the standard node architecture in Drupal. To achieve this I created a content type in the module that stored all the data I needed.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code25'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86325"><td class="code" id="p863code25"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Define module-provided node types.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> ckan_node_info<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'ckan'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'name'</span>           <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CKAN Package'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'module'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ckan'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'description'</span>    <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'A package of Open Data.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'has_title'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'title_label'</span>    <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'has_body'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'body_label'</span>     <span style="color: #339933;">=&gt;</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Package Description'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'min_word_count'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'locked'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span>
    <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ckan_create_node<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ckan_data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'title'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ckan_data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'uid'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'body'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ckan_data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'promote'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'path'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dataset/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ckan_data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'type'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ckan'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'comment'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>As you can see from the code, the only data elements to be set when a node is created are <em>Title</em>, <em>Body</em> and <em>Path</em>. The body of the node is set to be the name of the CKAN package, which is in fact a simple string: <em>geogratisnat_hydrography_v100</em>.</p>
<p>The more complex CKAN data was not mapped to any CCK fields as you might think, but instead it is pulled from CKAN when the node is loaded. This simplifies the Drupal side of things by ensuring that we don&#8217;t have to keep track of any changes to the structure or contents of the dataset that may happen on the CKAN side.</p>
<p>Here is an example of some package data:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code26'); return false;">View Code</a> INI</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86326"><td class="code" id="p863code26"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>maintainer<span style="">&#93;</span></span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Government of Canada, Natural Resources Canada, Centre for Topographic Information <span style="">&#40;</span>Sherbrooke<span style="">&#41;</span></span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>name<span style="">&#93;</span></span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; 1996_population_census_data_canada</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>author<span style="">&#93;</span></span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Government of Canada, Natural Resources Canada, Canada Centre for Remote Sensing, GeoAccess Division, The Atlas of Canada</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>url<span style="">&#93;</span></span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; ftp://ftp.geogratis.gc.ca/atlas/Population_Ecumene_Census/1996/</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>notes<span style="">&#93;</span></span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; The parts of Canada making up the 1996 Settled Area, <span style="">&#40;</span>or Population Ecumene<span style="">&#41;</span>, represents a selection of the 5984 Census Subdivisions <span style="">&#40;</span>CSD<span style="">&#41;</span> as defined by Statistics Canada for the 1996 Census. The selection process essentially removes those CSDs with very large areas and/or very low populations. Some of British Columbia's CSD boundaries have been further modified to better conform to the distinctive settlement patterns in the Cordilleran regions. The 1996 Settled Area is an attempt to balance the needs of national scale choropleth mapping with the spatial reality that the majority of Canada's land area contains very few people. The Settled Area represents more than 98% of the Canadian population captured in the 1996 Census of Canada.</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>title<span style="">&#93;</span></span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; 1996 Population <span style="">&#40;</span>Ecumene<span style="">&#41;</span> Census Data, Canada</span>
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>download_url<span style="">&#93;</span></span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; ftp://ftp.geogratis.gc.ca/atlas/Population_Ecumene_Census/1996/1996.zip</span></pre></td></tr></table></div>

<p>When a node is loaded, the package data is pulled from CKAN and then cached for later use.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code27'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86327"><td class="code" id="p863code27"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Load node-type-specific information
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> ckan_load<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$ckan</span> <span style="color: #339933;">=</span> ckan_ckan<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> cache_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan:'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Get the cached data</span>
    <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ckan</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    try <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// Call the API to get the package data</span>
      <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ckan</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPackage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      drupal_set_message<span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// Cache this package data for later use</span>
    cache_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan:'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span><span style="color: #339933;">,</span> <span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ckan</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
    watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Called CKAN API for '</span><span style="color: #339933;">.</span><span style="color: #000088;">$node</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">body</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' package - ckan_load()'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$node</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Once the CKAN data has been added to the node object it&#8217;s relatively easy to output this data in a node template. I created a template file in my theme called node_ckan.tpl.php and here&#8217;s an example of how I displayed some of the CKAN package data in there:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code28'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86328"><td class="code" id="p863code28"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 <span style="color: #339933;">&lt;</span>h1 id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;page-title&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;title tk-museo-slab&quot;</span><span style="color: #339933;">&gt;&lt;</span> ?php <span style="color: #b1b100;">print</span> <span style="color: #000088;">$title</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>h1<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;package-name&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">print</span> <span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
 <span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;package-link&quot;</span><span style="color: #339933;">&gt;&lt;</span> ?php <span style="color: #b1b100;">print</span> l<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attributes'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'link'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>You can see from all of the above examples I&#8217;m using a class object called &#8220;<em>ckan</em>&#8221; to store our data. This came from Sean&#8217;s module and is a simple class that provides the connectivity to the CKAN API. Here&#8217;s a brief synopsis of how it works:</p>
<ol>
<li>First I need a way to connect to the API. That&#8217;s relatively straightforward using the <a href="http://php.net/manual/en/book.curl.php">curl libraries in php</a>.

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code29'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86329"><td class="code" id="p863code29"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_init"><span style="color: #990000;">curl_init</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">url</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/curl_setopt"><span style="color: #990000;">curl_setopt</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_TIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_exec"><span style="color: #990000;">curl_exec</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$info</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/curl_getinfo"><span style="color: #990000;">curl_getinfo</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<a href="http://www.php.net/curl_close"><span style="color: #990000;">curl_close</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li>Now create some functions that allow various parts of the API to be called. Below is an example of two class functions which call the API.

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code30'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86330"><td class="code" id="p863code30"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Get an individual package</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPackage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$package</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$package</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">transfer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'api/rest/package/'</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$package</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$package</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> CkanException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Package Load Error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$package</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get a list of all packages</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getPackageList<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$list</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">transfer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'api/rest/package/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$list</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> CkanException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Package List Error&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$list</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
</ol>
<p>All of these API calls return a JSON object which is then decoded into an object using the PHP function:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code31'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86331"><td class="code" id="p863code31"><pre class="php" style="font-family:monospace;"><a href="http://www.php.net/json_decode"><span style="color: #990000;">json_decode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Theming</h3>
<p>Once that data has been successfully retrieved and decoded from JSON into something that&#8217;s easier to handle, it needs to be themed. For this I created two theming functions; one for creating an individual list item, the other to create a formatted list of these individual items. I call the theme function whenever I get results from the API, and pass it the results, along with the title I want to appear on the listings page.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code32'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86332"><td class="code" id="p863code32"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Theme the results retrieved from API call</span>
theme<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_results'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$results</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'All Packages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Theme search results
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> theme_ckan_results<span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #339933;">,</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Two global variables needed by the pager.</span>
  <span style="color: #666666; font-style: italic;">// Taken from pager_query() in pager.inc</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$pager_page_array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pager_total</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Grab the 'page' query parameter.</span>
  <span style="color: #666666; font-style: italic;">// Taken from pager_query() in pager.inc</span>
  <span style="color: #000088;">$page</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Convert comma-separated $page to an array, used by other functions.</span>
  <span style="color: #666666; font-style: italic;">// Taken from pager_query() in pager.inc</span>
  <span style="color: #000088;">$pager_page_array</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Generate the data for page the requested and add it to the output.</span>
  <span style="color: #000088;">$items_per_page</span> <span style="color: #339933;">=</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_items_per_page'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// If there are less results than the specified number of items per page, reset the number of items per page</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$results</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$items_per_page</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$items_per_page</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$results</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Initialize pager</span>
  <span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// If it's not the first page</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Set the data to start displaying on the correct page</span>
    <span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$items_per_page</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;h1 id=&quot;page-title&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/h1&gt;'</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;h3 class=&quot;resultscount&quot;&gt;Your search returned '</span><span style="color: #339933;">.</span><span style="color: #000088;">$results</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">' records&lt;/h3&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Theme the individual results</span>
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$items_per_page</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span>  theme<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_item'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$results</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">results</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Put some magic in the two global variables</span>
  <span style="color: #666666; font-style: italic;">// Based on code in pager_query() in pager.inc</span>
  <span style="color: #000088;">$total_results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$results</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$pager_total</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ceil"><span style="color: #990000;">ceil</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$total_results</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$items_per_page</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//ckan_number_of_pages();</span>
  <span style="color: #000088;">$pager_page_array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>
    <a href="http://www.php.net/max"><span style="color: #990000;">max</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <a href="http://www.php.net/min"><span style="color: #990000;">min</span></a><span style="color: #009900;">&#40;</span>
      <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$pager_page_array</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span><span style="color: #000088;">$pager_total</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Add the pager to the output.</span>
  <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> theme<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pager'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span> <span style="color: #000088;">$items_per_page</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Theme individual search items
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> theme_ckan_item<span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Link the title to the dataset</span>
  <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;h2&gt;'</span> <span style="color: #339933;">.</span> l<span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'dataset/'</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span>check_plain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// Truncate the notes field</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">notes</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;p&gt;'</span> <span style="color: #339933;">.</span> truncate_utf8<span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">notes</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">250</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wordsafe</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dots</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">// Output any tags	</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/count"><span style="color: #990000;">count</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tags</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$items</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> l<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'data/tag/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$seperated</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$items</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;p&gt;&lt;strong&gt;Tags:&lt;/strong&gt; '</span> <span style="color: #339933;">.</span><span style="color: #000088;">$seperated</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/p&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>	
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>One thing you need to consider when displaying a list of results is having a pager built in so that you can break the list into bite-sized chunks. This took quite a while to figure out how to do. The problem was that the API call resulted in a lot of data and that resulted in a significant delay loading the page, due to the amount of time to complete the round trip to the API, along with the time taken to render all of that in a pager. CKAN however is very clever. When you call the API and ask for a list of packages, it returns the packages, but it also returns, as a variable, the count of the records your query generated. As well as that you can use the parameters &#8216;<em>offset</em>&#8216; and &#8216;<em>limit</em>&#8216; just like in SQL. What&#8217;s even more clever here is that it still returns the variable that holds the count of the records the query generated, but it also only returns the number of packages determined by the &#8216;<em>offset</em>&#8216; and &#8216;<em>limit</em>&#8216; parameters. </p>
<p>So if an API call to list all packages for a certain tag would normally return 200 records, and you specify a limit of 10 and an offset of 10, the data returned will contain a count of the number of records normally generated by that call, 200, but will <strong>only return 10 packages</strong> in the data, as specified by the offset and limit. This came in extremely useful for the pager as I just passed an offset and limit each time a page was loaded and then cached the returned data.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code33'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86333"><td class="code" id="p863code33"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ckan</span> <span style="color: #339933;">=</span> ckan_ckan<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$items_per_page</span> <span style="color: #339933;">=</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_items_per_page'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// If we're in a page, we need to set where to start the list</span>
  <span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$page</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$items_per_page</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Set the offset</span>
<span style="color: #000088;">$offset</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$start</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Limit to the number of items per page </span>
<span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$items_per_page</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Get the list of tags with their count</span>
try <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">advancedSearch</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'department'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ministry</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all_fields'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'offset'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$offset</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'limit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  drupal_goto<span style="color: #009900;">&#40;</span>variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_no_results_page'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'sorry'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Homepage Chart</h3>
<p>There was a requirement for a graph on the homepage the displayed the number of packages attributed to each Government Ministry. The quickest way to do this was using <a href="http://code.google.com/apis/charttools/">Google Chart Tools</a>. It was relatively straightforward to get the data we needed. I did however have to do some funky sorting to get the data in the correct order. I also <a href="http://psychopyko.com/tutorial/how-to-use-google-charts/">found a wonderful tutorial</a> that really helped to clear up some of the label/legend issues I was having.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p863code34'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p86334"><td class="code" id="p863code34"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Function to build a Google Chart
 *
 * @return	  string	HTML code with img tag
 *
 **/</span>
<span style="color: #000000; font-weight: bold;">function</span> ckan_chart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// If there is a cached version of the chart</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span> <span style="color: #339933;">=</span> cache_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan:chart'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$cache</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    watchdog<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Called Google API to build chart'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Get the list of ministries</span>
    <span style="color: #000088;">$ministries</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> filter_xss<span style="color: #009900;">&#40;</span>variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan_ministry_list'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Set up our data array</span>
    <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ministries</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$ministry</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$ckan</span> <span style="color: #339933;">=</span> ckan_ckan<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">// Get the list of tags with their count</span>
      try <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ckan</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">advancedSearch</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'department'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$ministry</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'all_fields'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'offset'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'0'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'limit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$results</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #666666; font-style: italic;">// Cache the count to use on the Ministry list page '/ministry'</span>
      cache_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan:ministry_'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$ministry</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'_count'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$ministry</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">' ('</span><span style="color: #339933;">.</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">')'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$count</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #666666; font-style: italic;">// Sort the array in reverse order - most packages first and maintain index association</span>
    <a href="http://www.php.net/arsort"><span style="color: #990000;">arsort</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Return all the keys of the data array - the names of the ministries</span>
    <span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">legend</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array_keys"><span style="color: #990000;">array_keys</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Get the range of the chart - highest + a quarter</span>
    <span style="color: #000088;">$range</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/round"><span style="color: #990000;">round</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/current"><span style="color: #990000;">current</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color:#800080;">1.25</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Grid spacing  100/MaxRange*IntervalAmount</span>
    <span style="color: #000088;">$grid</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">/</span><span style="color: #000088;">$range</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Chart size, must be less than 30k pixels</span>
    <span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">size</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'590'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">'380'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Create query</span>
    <span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span> <span style="color: #339933;">=</span>
      <span style="color: #0000ff;">'cht=bhg&amp;'</span><span style="color: #339933;">.</span>	<span style="color: #666666; font-style: italic;">// Type</span>
      <span style="color: #0000ff;">'chd=t:'</span><span style="color: #339933;">.</span><a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">.</span>	<span style="color: #666666; font-style: italic;">// Data</span>
      <span style="color: #0000ff;">'chs='</span><span style="color: #339933;">.</span><span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'x'</span><span style="color: #339933;">.</span> <span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">.</span>	<span style="color: #666666; font-style: italic;">// Size</span>
      <span style="color: #0000ff;">'chco=cc0000&amp;'</span><span style="color: #339933;">.</span>	<span style="color: #666666; font-style: italic;">// Color ( Remove # from string )</span>
      <span style="color: #0000ff;">'chxt=x,y&amp;'</span><span style="color: #339933;">.</span>	<span style="color: #666666; font-style: italic;">// X,Y axis labels</span>
      <span style="color: #0000ff;">'chxr=0,0,'</span><span style="color: #339933;">.</span><span style="color: #000088;">$range</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">.</span> <span style="color: #666666; font-style: italic;">// Range</span>
      <span style="color: #0000ff;">'chxs=1,000000,13|0,000000,13&amp;'</span><span style="color: #339933;">.</span> 	<span style="color: #666666; font-style: italic;">// Axis colors and font size</span>
      <span style="color: #0000ff;">'chg='</span><span style="color: #339933;">.</span><span style="color: #000088;">$grid</span><span style="color: #339933;">.</span><span style="color: #0000ff;">',0,5,5&amp;'</span><span style="color: #339933;">.</span> <span style="color: #666666; font-style: italic;">// Grid verticalgridlines, horizontalgridlines, linesize, gapsize</span>
      <span style="color: #0000ff;">'chds=0,'</span><span style="color: #339933;">.</span><span style="color: #000088;">$range</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">.</span>	<span style="color: #666666; font-style: italic;">// Scale</span>
      <span style="color: #0000ff;">'chma=0,0,0,0&amp;'</span><span style="color: #339933;">.</span> <span style="color: #666666; font-style: italic;">//left_margin, right_margin, top_margin, bottom_margin| legend_width, legend_height</span>
      <span style="color: #0000ff;">'chbh=13,0,2&amp;'</span><span style="color: #339933;">.</span>	<span style="color: #666666; font-style: italic;">// bar_width_or_scale, space_between_bars, space_between_groups</span>
      <span style="color: #0000ff;">'chxl=1:|'</span><span style="color: #339933;">.</span><a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array_reverse"><span style="color: #990000;">array_reverse</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">legend</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//|Jan|Feb|Mar|Apr|May'</span>
&nbsp;
    <span style="color: #000088;">$api_path</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://chart.apis.google.com/chart?'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/sprintf"><span style="color: #990000;">sprintf</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;img src=&quot;%s&quot; alt=&quot;%s&quot; style=&quot;width:%spx;height:%spx;&quot; /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$api_path</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Who\'s Sharing'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$chart</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">size</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      cache_set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ckan:chart'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$image</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'cache_ckan'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>	
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$image</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>So that&#8217;s a brief(not-so) overview of some of the fundamentals of how I integrated Drupal with CKAN and was able to create nodes and listings directly from API calls. </p>
<p><a href="/2010/06/datadotgc-ca-a-drupal-case-study-part-2/">In my next post I&#8217;ll cover some very important areas</a> of the module development such as:</p>
<ul>
<li>Caching</li>
<li>Tag cloud creation</li>
<li>Using the CKAN Search API for all lists</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2010/04/datadotgc-ca-a-drupal-case-study/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Passing a querystring to FormAPI redirect</title>
		<link>http://blog.raisedeyebrow.com/2010/03/passing-a-querystring-to-formapi-redirect/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=passing-a-querystring-to-formapi-redirect</link>
		<comments>http://blog.raisedeyebrow.com/2010/03/passing-a-querystring-to-formapi-redirect/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 21:36:10 +0000</pubDate>
		<dc:creator>Colin Calnan</dc:creator>
				<category><![CDATA[Code and Coding]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[FormAPI]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=840</guid>
		<description><![CDATA[Here&#8217;s a really quick and useful trick to know.
Sometimes you might want your form to redirect to somewhere and pass a few bits of information in the querystring, so that you can do something when you get there.
For example, I needed a recent form to redirect depending on which checkboxes were checked to build a [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a really quick and useful trick to know.</p>
<p>Sometimes you might want your form to redirect to somewhere and pass a few bits of information in the querystring, so that you can do something when you get there.</p>
<p>For example, I needed a recent form to redirect depending on which checkboxes were checked to build a certain URL:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p840code36'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p84036"><td class="code" id="p840code36"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form_state</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'values'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filters'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'open'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #000088;">$query</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'o=1'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> 
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$form_state</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'values'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filters'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'down'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #000088;">$query</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'d=1'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$form_state</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'redirect'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'data/search/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$keyword</span><span style="color: #339933;">,</span> <a href="http://www.php.net/implode"><span style="color: #990000;">implode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If &#8220;open&#8221; checkbox is checked, it will redirect to &#8220;data/search/keyword?o=1&#8243;. I then get the value of this using $_GET['o']. Simple eh?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2010/03/passing-a-querystring-to-formapi-redirect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DrupalCon Sessions to help you manage your business</title>
		<link>http://blog.raisedeyebrow.com/2010/02/drupalcon-sessions-to-help-you-manage-your-business/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=drupalcon-sessions-to-help-you-manage-your-business</link>
		<comments>http://blog.raisedeyebrow.com/2010/02/drupalcon-sessions-to-help-you-manage-your-business/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 21:36:59 +0000</pubDate>
		<dc:creator>Colin Calnan</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Project Management]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=826</guid>
		<description><![CDATA[DrupalCon San Francisco 2010 is just around the corner and Raised Eyebrow hopes to &#8220;own the podium&#8221;, sorry I couldn&#8217;t resist. Chris and I have been to 2 Drupalcon&#8217;s so far in our Drupal lifetime, and have decided it is time to give something back. We&#8217;ve come up with 2 Session Proposals that are overviews [...]]]></description>
			<content:encoded><![CDATA[<p>DrupalCon San Francisco 2010 is just around the corner and Raised Eyebrow hopes to &#8220;own the podium&#8221;, sorry I couldn&#8217;t resist. Chris and I have been to 2 Drupalcon&#8217;s so far in our Drupal lifetime, and have decided it is time to give something back. We&#8217;ve come up with 2 Session Proposals that are overviews about how we used Drupal to create two killer applications for managing a small Web Business.</p>
<p>One <strong>stores all kinds of client information</strong>; FTP connection info., Drupal logins, client contact info., newsletter provider and vendor info. The other is an <strong>online training manual</strong> for our clients, enabling us to train them remotely, give them access to it wherever they can find a browser and reduces the need to print large binders that end up getting lost or in the landfill/recycling.</p>
<p>So if you&#8217;re interested in hearing more about these the please go cast your vote by following the links below:</p>
<p><a href="http://sf2010.drupal.org/conference/sessions/manage-your-web-studio-using-drupal">Manage your Web Studio using Drupal </a><br />
<a href="http://sf2010.drupal.org/conference/sessions/using-drupal-train-clients-how-use-drupal">Using Drupal to train clients on how to use Drupal</a></p>
<p>The closing date for voting for Voting is March 1st, so get voting. See you in San Fran.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2010/02/drupalcon-sessions-to-help-you-manage-your-business/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Drupal to deliver video</title>
		<link>http://blog.raisedeyebrow.com/2009/12/using-drupal-to-deliver-video/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-drupal-to-deliver-video</link>
		<comments>http://blog.raisedeyebrow.com/2009/12/using-drupal-to-deliver-video/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 17:11:51 +0000</pubDate>
		<dc:creator>Colin Calnan</dc:creator>
				<category><![CDATA[Code and Coding]]></category>
		<category><![CDATA[Content Management Systems]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Nonprofit Tech]]></category>
		<category><![CDATA[Our Clients]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=103</guid>
		<description><![CDATA[There are many ways to skin the cat when it comes to putting video on a Drupal site. I&#8217;ve tried and tested quite a few methods since my first introduction to Drupal 2 years ago. I&#8217;ve used Embedded Media Field as well as Video Filter but finally settled on the combination of FileField with JWPlayer [...]]]></description>
			<content:encoded><![CDATA[<p>There are many ways to skin the cat when it comes to putting video on a Drupal site. I&#8217;ve tried and tested quite a few methods since my first introduction to Drupal 2 years ago. I&#8217;ve used <a href="http://drupal.org/project/emfield">Embedded Media Field </a>as well as <a href="http://drupal.org/project/video_filter">Video Filter</a> but finally settled on the combination of <a href="http://drupal.org/project/filefield">FileField</a> with <a href="http://www.longtailvideo.com/players/jw-flv-player/">JWPlayer</a> or <a href="http://flowplayer.org/">Flowplayer</a> and in some cases the <a href="http://drupal.org/project/media_mover">Media Mover Module</a> for moving files to <a href="http://aws.amazon.com/s3/">Amazon S3</a> storage. I&#8217;m going to use our recent launch of the <a href="http://www.policyalternatives.ca">CCPA website</a> as a case study for how we currently handle video delivery. So let&#8217;s dissect this a little.</p>
<h3>Uploading files</h3>
<p>The video files need to be uploaded before we display them. This is best achieved using the wonderful <a href="http://drupal.org/project/filefield">Filefield</a> Module. This is quite a simple yet powerful module developed/maintained by <a href="http://www.lullabot.com/">Lullabot</a>, <a href="http://quicksketch.org/">Nate Haug</a> (<a href="http://drupal.org/user/35821">quicksketch</a>), whom I&#8217;ve had the pleasure of being trained by at one of their excellent Drupal Theming workshops. Once you install and enable the module you then add a new CCK field, of type &#8220;filefield&#8221;. In our case we have a content type called &#8220;Multimedia&#8221;. We add the field to this content type. You then need to configure the following:</p>
<h4>1. Permitted upload file extensions</h4>
<p style="padding-left: 30px;">In most cases this is relatively straightforward, it&#8217;s just one file type. If you&#8217;re using JWPlayer or Flowplayer it will be FLV. Both these players are built to play Flash Video files (FLV). If you have Quicktime MOV&#8217;s or AVI&#8217;s that you want to upload then you&#8217;ll need to consider different options for playing video. For the purpose of this case study we&#8217;re just uploading FLV files.</p>
<p style="padding-left: 30px;">
<h4>2. File size restrictions</h4>
<p style="padding-left: 30px;">It&#8217;s very important that you set these, otherwise you may end up with users trying to upload 200MB videos, not a very good idea. I set this low as a learning feature for clients. Any reasonably long FLV file that is over 40MB is probably not optimized as well as it should be.</p>
<p style="padding-left: 30px;">
<h4>3. Path Settings</h4>
<p style="padding-left: 30px;">I like to keep all files that admin/editor users upload in a folder called <strong>uploads</strong> so that it&#8217;s easy to manage them later if they need to be exported etc.</p>
<p style="padding-left: 30px;">
<div id="attachment_729" class="wp-caption aligncenter" style="width: 398px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/12/ccpa-video-admin.gif"><img class="size-full wp-image-729" title="File Field" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/12/ccpa-video-admin.gif" alt="File Field" width="388" height="576" /></a><p class="wp-caption-text">Multimedia File Field Settings</p></div>
<p style="padding-left: 30px; text-align: center;">
<h3>Create a placeholder image</h3>
<p>Most video players require some sort of poster/placeholder image to display before the video plays. In this case I created another FileField for the placeholder image. We&#8217;ll use that later on in conjunction with the <a href="http://ftp.drupal.org/files/projects/imagecache-6.x-2.0-beta9.tar.gz">ImageCache module</a> to achieve our desired results.</p>
<h3>Moving Files to Amazon S3</h3>
<p>We&#8217;ve been using Amazon S3 for storing video files on quite a number of sites recently. One reason is that we were looking for a location off the webserver that could deliver the video, without impacting the performance of the server, so that in the event of a traffic spike the webserver wouldn&#8217;t fall over. We could also have used Amazon EC2 or another CDN service for this, however as most of our clients have a very regional (BC) audience. Most CDN&#8217;s have nodes in various locations across the US and Europe and this would have served no real improvement as the nearest cached version will always be in the same place for everyone.</p>
<p>So if they&#8217;re uploading the files directly to the Drupal site, how to the files get delivered from Amazon S3. That&#8217;s where the <a href="http://drupal.org/project/media_mover">Media Mover module</a> comes in. This module has many purposes, but for our needs it simply harvests all the files uploaded via the &#8220;Multimedia&#8221; content type and moves those files to Amazon S3 so that we can deliver them from there.</p>
<p>Download, install and enable the Media Mover module. You&#8217;ll also need an S3 account and will need to set that up via the module setting page. You then need to add a Configuration via https://www.yoursite.ca/admin/build/media_mover/add.</p>
<p>Media Mover has 4 actions which it performs on your files:</p>
<ul>
<li>Harvest &#8211; Define/collect the files you want to perform actions on</li>
<li>Process &#8211; Perform certain actions on the files</li>
<li>Storage &#8211; Where to store files once the actions have been carried out</li>
<li>Complete &#8211; Final actions to perform on the files</li>
</ul>
<p>So in this case we just want to <strong>harvest</strong> all Multimedia files and <strong>store</strong> them on Amazon S3.</p>
<p>So for clarification here Media Mover does <strong>NOT MOVE</strong> the files to Amazon S3, it simply <strong>COPIES</strong> them over to S3 and the original files remain on your server.</p>
<div id="attachment_730" class="wp-caption aligncenter" style="width: 399px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/12/ccpa-media-mover-settings.gif"><img class="size-full wp-image-730" title="Media Mover Settings" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/12/ccpa-media-mover-settings.gif" alt="Media Mover Settings" width="389" height="572" /></a><p class="wp-caption-text">Media Mover Settings</p></div>
<p style="text-align: center;">
<h3>Delivering the moved Video files</h3>
<p>So this is where the Drupal theming trickery comes in. Flowplayer and JWPlayer are both Flash based FLV video players than can be called using Javascript and that&#8217;s exactly what I do on this site. In plain english this is what happens:</p>
<ol>
<li>Output the placeholder image to screen as a link.</li>
<li>Use Javascript so that when the user clicks on the image the video plays.</li>
<li>Deliver the video from the file on Amazon S3 rather than the file on the webserver (Drupal site).</li>
</ol>
<p>We need to modify three files to achive the above:</p>
<ul>
<li>template.php</li>
<li>multimedia.js (a newly created JS file)</li>
<li>node-multimedia.tpl.php (a custom template file for all multimedia types)</li>
</ul>
<h4>template.php file</h4>
<p>Setting up all the variables we&#8217;re going to need to use as well as making the javascript available</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p103code43'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10343"><td class="code" id="p103code43"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'view'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//If there is a file and there is something to display...</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_aspect_ratio'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//Aspect ratio handling</span>
    <span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'aspect_ratio'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_aspect_ratio'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'aspect_ratio'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'normal'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'multimedia_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'video'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Set the type of multimedia - we also have audio and interactive...</span>
  custom_theme_get_media_mover_files<span style="color: #009900;">&#40;</span><span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_file'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'media_mover'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Set the filepath to the media moved filepath...</span>
  drupal_add_js<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'videoplayerpath'</span> <span style="color: #339933;">=&gt;</span> path_to_theme<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'/scripts/plugins/flowplayer/flowplayer-3.1.1.swf'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'setting'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Set a JS variable to retrieve later...</span>
  drupal_add_js<span style="color: #009900;">&#40;</span>path_to_theme<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'/scripts/plugins/flowplayer/example/flowplayer-3.1.1.min.js'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'theme'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Call the player...</span>
  drupal_add_js<span style="color: #009900;">&#40;</span>path_to_theme<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'/scripts/multimedia.js'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'theme'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//Call the custom JQuery to handle creating the player...</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * A function that takes a file object and a media_mover element array and set the file path to
 * its media moved path on Amazon S3 or wherever it moved to.
 *
 * It uses the unique file_id identifier to match file with media_mover file.
 *
 * $file = $variables['file_image'][0];
 * $media_mover = $variables['media_mover'][{id of media mover configuration}];
 *
 * @param 		&amp;$file A Drupal file array (by reference)
 * @param 		$media_mover A media_mover file/element array
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> custom_theme_get_media_mover_files<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$media_mover</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>module_exists<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'media_mover_api'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$media_mover</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// If media mover is installed...</span>
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$media_mover</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$media</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// Loop through each media_moved file...</span>
      <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$media</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fid'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// If they match (file id is a unique identifier...</span>
        <span style="color: #000088;">$file</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filepath'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$media</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'complete_file'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Replace the attached file path with the media moved file path...</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// custom_theme_get_media_mover_files()</span></pre></td></tr></table></div>

<p>Let me explain one thing in regards to line 9. I&#8217;ve created a custom function and I&#8217;m passing</p>
<pre>$variables['media_mover'][3]</pre>
<p>to my custom function. When you create a Media Mover configuration and map it to a CCK field, it creates an array in $variables to keep track of the Media Mover object. The array is called <strong>&#8216;media_mover&#8217;</strong> and the number <strong>3</strong> in this case is the ID of the Media Mover configuration.</p>
<h4>node-multimedia.tpl.php</h4>
<p>Set up the template. Create a wrapper div with the placeholder image as the background image (this is run through imagecache) and display the play button as a link with the path set to the path of the Amazon S3 file. This link will also have an id attribute of<strong> &#8216;multimedia&#8217;</strong>. This is necessary as it allows us to attach the player, via Javascript, to this link.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p103code44'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10344"><td class="code" id="p103code44"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;containing-block&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;video-wrapper&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php print <span style="color: #006699; font-weight: bold;">$aspect_ratio</span>;?&gt;&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> ?php <span style="color: #b1b100;">print</span> l<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;img src=&quot;/'</span><span style="color: #339933;">.</span>path_to_theme<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/images/ccpa-button-play-large.png&quot; alt=&quot;Play this video&quot; /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field_file</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filepath'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'attributes'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'multimedia'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$multimedia_type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h4>multimedia.js file</h4>
<p>Hook the Flowplayer to the link, with id  of &#8216;multimedia&#8217;, that we created in the template.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p103code45'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10345"><td class="code" id="p103code45"><pre class="javascript" style="font-family:monospace;">Drupal.<span style="color: #660066;">behaviors</span>.<span style="color: #660066;">showMultimedia</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> interactive_path <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#multimedia'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009966; font-style: italic;">/*Get the path to the video*/</span>
  <span style="color: #003366; font-weight: bold;">var</span> interactive_image <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#multimedia'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'background-image'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #009966; font-style: italic;">/*Get the path to the placeholder image*/</span>
  interactive_image <span style="color: #339933;">=</span> interactive_image.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">4</span><span style="color: #339933;">,</span>interactive_image.<span style="color: #660066;">length</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">/*Tidying up the interactive image path*/</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#multimedia'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'video'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/*If the link has a class of video*/</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#multimedia'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">flowplayer</span><span style="color: #009900;">&#40;</span> <span style="color: #009966; font-style: italic;">/*Initialize the flowplayer and configure the controls*/</span>
    Drupal.<span style="color: #660066;">settings</span>.<span style="color: #660066;">basePath</span> <span style="color: #339933;">+</span> Drupal.<span style="color: #660066;">settings</span>.<span style="color: #660066;">videoplayerpath</span><span style="color: #339933;">,</span> <span style="color: #009966; font-style: italic;">/*Path to the player, gotten from temaplate.php*/</span>
    <span style="color: #009900;">&#123;</span>
      plugins<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
	controls<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
	  <span style="color: #000066;">stop</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	  backgroundColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#efefef'</span><span style="color: #339933;">,</span>
	  backgroundGradient<span style="color: #339933;">:</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">,</span>
	  borderRadius<span style="color: #339933;">:</span> <span style="color: #3366CC;">'0px'</span><span style="color: #339933;">,</span>
	  bufferColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#d2d6ab'</span><span style="color: #339933;">,</span>
	  bufferGradient<span style="color: #339933;">:</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">,</span>
	  buttonColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#777777'</span><span style="color: #339933;">,</span>
	  buttonOverColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#99a134'</span><span style="color: #339933;">,</span>
	  durationColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#cccccc'</span><span style="color: #339933;">,</span>
	  height<span style="color: #339933;">:</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">,</span>
	  opacity<span style="color: #339933;">:</span> <span style="color: #CC0000;">1.0</span><span style="color: #339933;">,</span>
	  progressColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#99a134'</span><span style="color: #339933;">,</span>
	  sliderColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#9999999'</span><span style="color: #339933;">,</span>
	  sliderGradient<span style="color: #339933;">:</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">,</span>
	  timeBgColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#777777'</span><span style="color: #339933;">,</span>
	  timeColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#ffffff'</span><span style="color: #339933;">,</span>
	  tooltipColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#000000'</span><span style="color: #339933;">,</span>
	  tooltipTextColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#ffffff'</span><span style="color: #339933;">,</span>
	  volumeSliderColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#777777'</span><span style="color: #339933;">,</span>
	  volumeSliderGradient<span style="color: #339933;">:</span> <span style="color: #3366CC;">'none'</span>
	<span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I hope that was easy to follow. Now there&#8217;s one more thing to cover and that&#8217;s <strong>Aspect Ratio.</strong></p>
<h3>Aspect Ratio</h3>
<p>The issue of aspect ratio is very important when figuring out how to display video. Not so recently YouTube switched all video display to the 16:9 ratio thus setting the stage for the proliferation of the widescreen aspect ratio across the web. So how do you allow the user to upload a video and choose it&#8217;s aspect ratio. I&#8217;m sure there are other ways to do this via Metadata etc, but for our needs on this site I used a CCK field. This is a simple CCK field set with three options:</p>
<ol>
<li>None (defaults to 4:3)</li>
<li>Normal (4:3)</li>
<li>Widescreen (16:9)</li>
</ol>
<div id="attachment_753" class="wp-caption aligncenter" style="width: 396px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/12/ccpa-aspect-ratio.gif"><img class="size-full wp-image-753" title="ccpa-aspect-ratio" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/12/ccpa-aspect-ratio.gif" alt="ccpa-aspect-ratio" width="386" height="487" /></a><p class="wp-caption-text">Aspect Ratio Field Settings</p></div>
<p style="text-align: center;">
<p>We then check the value of this field in <strong>template.php</strong> above:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p103code46'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10346"><td class="code" id="p103code46"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_aspect_ratio'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">//Aspect ratio handling</span>
    <span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'aspect_ratio'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'field_aspect_ratio'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'aspect_ratio'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'normal'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>and set a variable called &#8216;aspect_ratio&#8221; which we apply as a class to the div wrapping the video in the <strong>node-multimedia.tpl.php</strong>:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p103code47'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10347"><td class="code" id="p103code47"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;containing-block&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;video-wrapper&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php print <span style="color: #006699; font-weight: bold;">$aspect_ratio</span>;?&gt;&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">print</span> l<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;img src=&quot;/'</span><span style="color: #339933;">.</span>path_to_theme<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/images/ccpa-button-play-large.png&quot; alt=&quot;Play this video&quot; /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$field_file</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'filepath'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'attributes'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'multimedia'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$multimedia_type</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>We have also created <strong>image cache presets</strong> for the placeholder images to account for both aspect ratios. These are named &#8216;multimedia_normal&#8217; and &#8216;multimedia_widescreen&#8217; and these have the appropriate dimensions associated with them:</p>
<div id="attachment_760" class="wp-caption aligncenter" style="width: 441px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/12/ccpa-imagecache-presets.gif"><img class="size-full wp-image-760" title="ccpa-imagecache-presets" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/12/ccpa-imagecache-presets.gif" alt="ccpa-imagecache-presets" width="431" height="79" /></a><p class="wp-caption-text">Image Cache Presets</p></div>
<p style="text-align: center;">So using the <a href="http://www.alistapart.com/articles/creating-intrinsic-ratios-for-video/">amazing article on A List Apart for creating intrinsic ratios for video</a> we use CSS to resize the player based on the aspect ratio chosen by the user.</p>
<h4>style.css file</h4>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p103code48'); return false;">View Code</a> CSS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10348"><td class="code" id="p103code48"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* -- Multimedia -- */</span>
<span style="color: #cc00cc;">#containing-</span><span style="color: #993333;">block</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#video-wrapper</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">25px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#video-wrapper</span> div<span style="color: #00AA00;">,</span>
  <span style="color: #cc00cc;">#video-wrapper</span> <span style="color: #993333;">embed</span><span style="color: #00AA00;">,</span>
  <span style="color: #cc00cc;">#video-wrapper</span> object <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#video-wrapper</span>.<span style="color: #993333;">normal</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">75%</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#video-wrapper</span><span style="color: #6666ff;">.widescreen</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">56.25%</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #00AA00;">*</span> html <span style="color: #cc00cc;">#video-wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">45px</span><span style="color: #00AA00;">;</span>
    margin-bot\tom<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#video-wrapper</span> <span style="color: #cc00cc;">#multimedia</span><span style="color: #6666ff;">.audio</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">1em</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#video-wrapper</span> <span style="color: #cc00cc;">#multimedia</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#video-wrapper</span>.<span style="color: #993333;">normal</span> <span style="color: #cc00cc;">#multimedia</span> img <span style="color: #00AA00;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/*margin:118.5px 0 0;*/</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">32%</span> <span style="color: #933;">42%</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span>
&nbsp;
  <span style="color: #cc00cc;">#video-wrapper</span><span style="color: #6666ff;">.widescreen</span> <span style="color: #cc00cc;">#multimedia</span> img <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">22%</span> <span style="color: #933;">41%</span><span style="color: #00AA00;">;</span>
  <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>And the end result looks something like this <a href="http://www.policyalternatives.ca/multimedia/matthew-poverty-and-looking-after-each-other-tough-times">http://www.policyalternatives.ca/multimedia/matthew-poverty-and-looking-after-each-other-tough-times</a>. They haven&#8217;t added any widescreen content yet, just testing content.</p>
<h4>So what are the advantages of doing things this way?</h4>
<ol>
<li>You can easily use any player to play your flash files (all you need to do  is change the path to your player and a few configuration params in multimedia.js)</li>
<li>All your video content is hosted on and delivered from Amazon S3. But there is also a copy on your local server in the event of something going wrong on Amazon S3</li>
<li>You don&#8217;t have to worry about your video looking skewed due to aspect ratio problems</li>
<li>You can add many other apsect ratios pretty quickly</li>
<li>The video file is still downloadable when javascript is not present or disabled</li>
</ol>
<p>I&#8217;d love to get feedback on how other do this, please leave a comment or send me an email and let me know how you deliver Video content on your site.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2009/12/using-drupal-to-deliver-video/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Launched: PolicyAlternatives.ca</title>
		<link>http://blog.raisedeyebrow.com/2009/12/ccpa-launch/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=ccpa-launch</link>
		<comments>http://blog.raisedeyebrow.com/2009/12/ccpa-launch/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 16:58:03 +0000</pubDate>
		<dc:creator>Lauren Bacon</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Nonprofit Tech]]></category>
		<category><![CDATA[Online Strategy]]></category>
		<category><![CDATA[Our Clients]]></category>
		<category><![CDATA[Raised Eyebrow]]></category>
		<category><![CDATA[CCPA]]></category>
		<category><![CDATA[data migration]]></category>
		<category><![CDATA[document library]]></category>
		<category><![CDATA[publications]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=708</guid>
		<description><![CDATA[We are very proud to unveil a project we&#8217;ve been working on for several months now: a redesign of policyalternatives.ca, the online home of the Canadian Centre for Policy Alternatives. Canada&#8217;s leading progressive research institute, the CCPA is a prolific publisher of reports and studies, books, articles, commentary and fact sheets on issues ranging from [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-721" title="Redesigned CCPA home page" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/12/ccpa-home-300x184.jpg" alt="Redesigned CCPA home page" width="300" height="184" />We are very proud to unveil a project we&#8217;ve been working on for several months now: a redesign of <a href="http://www.policyalternatives.ca">policyalternatives.ca</a>, the online home of the Canadian Centre for Policy Alternatives. Canada&#8217;s leading progressive research institute, the CCPA is a prolific publisher of <a href="http://www.policyalternatives.ca/publications/reports">reports and studies</a>, <a href="http://www.policyalternatives.ca/publications/bookstore">books</a>, <a href="http://www.policyalternatives.ca/publications/monitor">articles</a>, <a href="http://www.policyalternatives.ca/publications/commentary">commentary and fact sheets</a> on issues ranging from income equality to environmental policy, privatization of public services, and beyond.</p>
<p>They are highly respected, but like many organizations working towards policy change, they don&#8217;t always reach as broad an audience as they might hope; not many people have the time and inclination to read an in-depth research report, so in recent years they have been creating more bite-sized, easy-to-digest content in both written and <a title="CCPA Multimedia Studio" href="http://www.policyalternatives.ca/multimedia">multimedia</a> formats. As the range of content has grown, though, so has the need to cross-reference related materials &#8212; so the CCPA&#8217;s website needed to both invite visitors to browse through an extensive library in an intuitive and approachable way, but also allow people seeking more in-depth content to locate related materials quickly and easily. (One of our developers describes the complex interrelationships between the CCPA&#8217;s publications as &#8220;like Facebook for documents.&#8221;)</p>
<p>Their five year-old website, although rich in content and highly trafficked, didn&#8217;t offer visitors any way to easily share the CCPA&#8217;s content with their social networks, whether through Facebook or Twitter, or even through their own publications, blogs or presentations. Exchange of ideas is the CCPA&#8217;s raison d&#8217;etre, so it stands to reason that above and beyond extending the website&#8217;s &#8220;share this&#8221; features, the organization would benefit from encouraging online visitors to <a title="CCPA terms of (re)use" href="http://www.policyalternatives.ca/terms">use and share its content</a> &#8212; and they do, using a <a href="http://creativecommons.org/">Creative Commons</a> license.</p>
<p>This project was a complex one on several fronts, as we wrestled with improving navigation through the site (both via menus and site links as well as with improved <a href="http://www.policyalternatives.ca/search">search tools</a>); updating the site&#8217;s look and feel; and migrating the extensive site content (along with the aforementioned relationships between content items) from a commercial CMS platform into Drupal.</p>
<p>Oh, and we also set up a shopping cart (for books, memberships, donations and journal subscriptions).</p>
<p>There&#8217;s a real sense of accomplishment here at Raised Eyebrow when we look at the final result, but of course on the web, there&#8217;s no such thing as a final edit. Our best hope, in fact, is that we&#8217;ve helped to create a solid platform upon which the CCPA can continue to build and extend over the coming years. So while right now we are celebrating the grand opening, the real fun in some ways is still to come. I&#8217;m sure we&#8217;ll see the CCPA continue to play a leadership role when it comes to presenting research online in accessible and innovative ways.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2009/12/ccpa-launch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ubercart &amp; Content Type machine names</title>
		<link>http://blog.raisedeyebrow.com/2009/11/ubercart-content-type-machine-names/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=ubercart-content-type-machine-names</link>
		<comments>http://blog.raisedeyebrow.com/2009/11/ubercart-content-type-machine-names/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 17:08:23 +0000</pubDate>
		<dc:creator>Colin Calnan</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[Geekery]]></category>
		<category><![CDATA[Ubercart]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=665</guid>
		<description><![CDATA[If you use Ubercart on your Drupal website you may be familiar with product classes. Ubercart has, by default, a product content type, however say you have other content types on your site that you want to sell, you can create product classes from those &#8211; http://www.ubercart.org/docs/user/3341/understanding_product_classes.
This works nicely until that moment when you want [...]]]></description>
			<content:encoded><![CDATA[<p>If you use <a href="http://www.ubercart.org/">Ubercart</a> on your <a href="http://drupal.org">Drupal </a>website you may be familiar with product classes. Ubercart has, by default, a product content type, however say you have other content types on your site that you want to sell, you can create product classes from those &#8211; http://www.ubercart.org/docs/user/3341/understanding_product_classes.</p>
<p>This works nicely until that moment when you want to rename your content type machine name.. e.g from &#8220;contenttype&#8221; to &#8220;content_type&#8221;</p>
<p>I did that recently thinking everything would be hunky dory once I made the change, the results were not so nice. So to help prevent this from happening to anyone else, here&#8217;s a simple rule to follow before making changes to your content type machine name.</p>
<blockquote>
<p style="text-align: center;"><strong>Make sure you remove your content type as a product class before changing it&#8217;s machine name.</strong></p>
</blockquote>
<p>It&#8217;s that easy, simply disassociate your content type from Ubercart. The page to do this can be a little scary (www.yoursite.com/admin/store/products/classes), but just click the delete link on the class you want to disassociate and you&#8217;ll get a &#8220;Are you sure you want to do this message&#8221;, go ahead, it won&#8217;t delete your nodes, it just removes a flag that tells Ubercart they&#8217;re products. Also, if you&#8217;re worried about losing your product data, like SKU, Price, Shipping info etc, in my case it retained all product info when I re-instated it. Please backup your data before doing this, I cannot be responsible for any problems this causes on your site. Now, go to your content type, change the machine name.</p>
<p>Oh, and don&#8217;t forget to double check all your views are still working, you may need to edit them to ensure they&#8217;ve picked up the new content type machine name. I guess this is a good lesson to remind you to give your content types a machine name that you will not want change later.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2009/11/ubercart-content-type-machine-names/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Drupal vs WordPress: Which one is right for you?</title>
		<link>http://blog.raisedeyebrow.com/2009/11/drupal-vs-wordpress-which-one-is-right-for-you/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=drupal-vs-wordpress-which-one-is-right-for-you</link>
		<comments>http://blog.raisedeyebrow.com/2009/11/drupal-vs-wordpress-which-one-is-right-for-you/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 15:15:17 +0000</pubDate>
		<dc:creator>Lauren Bacon</dc:creator>
				<category><![CDATA[Content Management Systems]]></category>
		<category><![CDATA[Drupal]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=661</guid>
		<description><![CDATA[Here at Raised Eyebrow, while we have experimented with dozens of Content Management Systems (CMS&#8217;s), these days we mostly build websites using either Drupal or WordPress.
Why these two CMS&#8217;s, of the thousands of content management systems available? Both CMS&#8217;s share several key qualities:

They&#8217;re open-source projects. Over the past few years, Raised Eyebrow has increasingly turned [...]]]></description>
			<content:encoded><![CDATA[<p>Here at Raised Eyebrow, while we have experimented with dozens of <a title="Definition of CMS on Wikipedia" href="http://en.wikipedia.org/wiki/Content_management_system">Content Management Systems</a> (CMS&#8217;s), these days we mostly build websites using either <a href="http://www.drupal.org">Drupal</a> or <a href="http://www.wordpress.org">WordPress</a>.</p>
<p>Why these two CMS&#8217;s, of the thousands of content management systems available? Both CMS&#8217;s share several key qualities:</p>
<ul>
<li><strong>They&#8217;re <a title="definition of open source at Wikipedia" href="http://en.wikipedia.org/wiki/Open_source">open-source</a> projects.</strong> Over the past few years, Raised Eyebrow has increasingly turned to open-source software options because of the flexibility and security they offer.</li>
<li>Both <a href="http://www.wordpress.org/">WordPress</a> and <a href="http://www.drupal.org/">Drupal</a> boast <strong>huge communities</strong> of developers and widespread adoption; those are important things to look at when working with open-source software, because we like to see a critical mass of people who are invested in making the software better, both on the coding side and from the end-user perspective.</li>
<li>They offer a <strong>rich and robust feature set,</strong> both within the core CMS and in terms of the plugins (or in Drupal parlance, modules) that are available &#8212; <a title="WordPress's plugin directory" href="http://wordpress.org/extend/plugins/">plugins</a> and <a title="Drupal's module directory" href="http://drupal.org/project/Modules">modules</a> help us extend the base functionality of your site with features such as photo galleries, event calendars, interactive forms, shopping carts, and so on.</li>
<li>Perhaps the most compelling reason we&#8217;ve chosen these two, though, is that <strong>our clients like using them.</strong> The interfaces are user-friendly; the software is reliable; and the basic functions that our clients need (from uploading a file attachment to creating new pages and blog posts) are available, easy to use, and intuitive. (I won&#8217;t claim that there aren&#8217;t things I wouldn&#8217;t change if I could wave a magic wand &#8212; but of the CMS&#8217;s we&#8217;ve tested, these two are far and away at the top of the heap.)</li>
</ul>
<p>So how do you choose which one is appropriate for your project? Drupal &amp; WordPress are very different systems, with different strengths and weaknesses. Here&#8217;s a quick overview of some of the distinguishing features of each CMS.</p>
<h2>Drupal</h2>
<div id="attachment_689" class="wp-caption alignright" style="width: 160px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Drupal-6-Sandbox.jpg"><img class="size-thumbnail wp-image-689" title="Drupal welcome screen" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Drupal-6-Sandbox-150x150.jpg" alt="Drupal welcome screen" width="150" height="150" /></a><p class="wp-caption-text">Drupal welcome screen</p></div>
<p><strong>Community focus:</strong> Drupal has extensive functionality for allowing people to interact with one another via your website. Creating accounts; logging in to access special content &#8212; or create their own; connecting with one another &#8212; all of these are possible with a Drupal site, so if your short- or long-range plans include turning your website into a social hub for your visitors, Drupal is a better choice.</p>
<div id="attachment_687" class="wp-caption alignleft" style="width: 160px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/A-New-Page-Drupal-6-Sandbox.jpg"><img class="size-thumbnail wp-image-687" title="Editing a page" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/A-New-Page-Drupal-6-Sandbox-150x150.jpg" alt="Editing a page in Drupal" width="150" height="150" /></a><p class="wp-caption-text">Editing a page in Drupal</p></div>
<p><strong>Editing is seamless: </strong>In Drupal, if you have administrative privileges, and you are logged in, you can edit your content simply by navigating to the page you want to update, and clicking an unobtrusive &#8220;Edit&#8221; tab. Many people find this a particularly intuitive approach to site editing. (Not only that, but Drupal is so profoundly customizable that if you want to, you can create custom themes for different areas of your site &#8212; so your back-end could look totally different from your front-end, should you feel so inspired.)</p>
<div id="attachment_688" class="wp-caption alignright" style="width: 160px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Create-Publication-Drupal-6-Sandbox.jpg"><img class="size-thumbnail wp-image-688" title="Create Publication | Drupal 6 Sandbox" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Create-Publication-Drupal-6-Sandbox-150x150.jpg" alt="Specialized content types in Drupal" width="150" height="150" /></a><p class="wp-caption-text">Specialized content types in Drupal</p></div>
<p><strong>Built for dynamic content: </strong>Drupal has some very clever ways of <strong>cross-categorizing content, </strong>so if you have the kind of website where you want content to appear in multiple places based on various categories you assign to it, Drupal may be just right for you. And it&#8217;s often the better choice for managing complex kinds of content, where a simple 2-field &#8220;Title&#8221; and &#8220;Body&#8221; editing screen won&#8217;t suffice.</p>
<p><strong>Highly modular &amp; extensible:</strong> The underlying architecture of Drupal is quite flexible, and the CMS can be adapted for a wide variety of purposes. Drupal is like a Swiss Army knife or a food processor: it is many tools in one, and you can choose to use it for one task or several. WordPress is much more specific in its function: it does a handful of things and does them very well, but it isn&#8217;t the right tool for every job. (On the other hand, if you need a simple site, Drupal may be overkill, and you could spend a lot of time turning off the features you don&#8217;t want.)</p>
<p><strong>Greater investment required up front:</strong> Drupal&#8217;s out-of-the-box configuration is somewhat limiting, and most people prefer to customize it pretty heavily. This requires not only a solid understanding of HTML and CSS, but also of PHP and of Drupal&#8217;s underlying architecture, which has a fairly steep learning curve. As a result, Drupal sites tend to cost more to set up, though the initial investment is well worth it if you plan to extend your site&#8217;s functionality to take advantage of Drupal&#8217;s flexibility.</p>
<h2>WordPress</h2>
<div id="attachment_676" class="wp-caption alignright" style="width: 160px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Edit-Post-‹-Blog_-Raised-Eyebrow-Web-Studio-Inc.-—-WordPress.jpg"><img class="size-thumbnail wp-image-676" title="WordPress Edit Post screen" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Edit-Post-‹-Blog_-Raised-Eyebrow-Web-Studio-Inc.-—-WordPress-150x150.jpg" alt="WordPress's editing screen looks quite different from your site's front-end. This is the screen I see while editing the blog post you're reading." width="150" height="150" /></a><p class="wp-caption-text">WordPress&#39;s editing screen looks quite different from your site&#39;s front-end. This is the screen I see while editing the blog post you&#39;re reading.</p></div>
<p><strong>Built for blogging:</strong> I personally find Drupal&#8217;s blogging capabilities somewhat limited &#8212; for example, creating blog category lists, tag clouds and date-based archives is rather onerous in Drupal, whereas in WordPress they take a matter of minutes to set up. WordPress was first developed as blogging software, and it shows: its blogging features are well thought-through and have been polished by years of improvements.</p>
<div id="attachment_678" class="wp-caption alignleft" style="width: 160px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Media-Library-‹-Blog_-Raised-Eyebrow-Web-Studio-Inc.-—-WordPress1.jpg"><img class="size-thumbnail wp-image-678" title="WordPress Media Library screen" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Media-Library-‹-Blog_-Raised-Eyebrow-Web-Studio-Inc.-—-WordPress1-150x150.jpg" alt="WordPress's Media Library gives you easy access to all the files you've uploaded to your site: images, PDFs, media files, etc." width="150" height="150" /></a><p class="wp-caption-text">WordPress&#39;s Media Library gives you easy access to all the files you&#39;ve uploaded to your site: images, PDFs, media files, etc.</p></div>
<p><strong>Easy-to-use file management: </strong>WordPress&#8217;s &#8220;Media Library&#8221; feature allows you to browse through all the files you&#8217;ve uploaded to your site &#8212; images, PDFs, multimedia files, whatever they might be &#8212; in a clean, attractive &amp; easy-to-use interface. It makes managing your files and inserting them into your blog posts and site pages a much easier task.</p>
<p><strong>Smart spam filtering: </strong>Because of WordPress&#8217;s blogging focus, the developers had to pay close attention to managing spam. (Blogs attract a lot of spam via comments and pingbacks.) WordPress comes bundled with spam-filtering software that does a remarkably good job &#8212; and moreover, its comment-management features are well thought-out and simple to use.</p>
<div id="attachment_675" class="wp-caption alignright" style="width: 160px"><a href="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Dashboard-‹-Blog_-Raised-Eyebrow-Web-Studio-Inc.-—-WordPress.jpg"><img class="size-thumbnail wp-image-675" title="WordPress Dashboard" src="http://blog.raisedeyebrow.com/wp-content/uploads/2009/11/Dashboard-‹-Blog_-Raised-Eyebrow-Web-Studio-Inc.-—-WordPress-150x150.jpg" alt="The WordPress Dashboard gives you an overview of activity on your blog or website." width="150" height="150" /></a><p class="wp-caption-text">The WordPress Dashboard gives you an overview of activity on your blog or website.</p></div>
<p><strong>Quick to install and configure: </strong>WordPress is famous for its <a href="http://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install">5-minute install</a>, and it really does live up to its name. Although that doesn&#8217;t mean you&#8217;ll have a fully-functioning website in 5 minutes, it works well &#8220;out of the box&#8221; for most simple sites &amp; blogs. As a result it is often <strong>less costly</strong> then Drupal to set up.</p>
<p><strong>Easy to theme:</strong> Both Drupal and WordPress have a great deal of flexibility with regard to visual design &#8212; you can make a site built in either CMS look beautiful via either <a title="Drupal's theme directory" href="http://drupal.org/project/Themes">free</a> <a title="WordPress's theme directory" href="http://wordpress.org/extend/themes/">templates</a> or by applying your own custom design. However, theming a Drupal site is a much bigger task than theming a WordPress site, unless you are simply going to download a free theme and slap it on your site. If you want to be able to tweak design details, in our experience, that&#8217;s a much faster job in WordPress.</p>
<p>If you aren&#8217;t planning to use WordPress&#8217;s blogging features, <strong>navigating</strong> through the CMS can be a little confusing, because blog posts are the primary focus in the menus, and page editing is less prominent. In this sense, its focus on blogging can be a weakness as well as a strength.</p>
<p>WordPress keeps your site&#8217;s back-end (that&#8217;s the area where you create &amp; edit content) totally separate from the front-end (the part your visitors see). Some people (like yours truly) prefer this approach, where content is more or less divorced from presentation, whereas others prefer Drupal&#8217;s integrated editing options. In my experience, this is a highly subjective preference, and it&#8217;s worth trying both to see which feels better to you.</p>
<h2>In Summary</h2>
<p>As with most decisions about your website, you are well advised to consider the long-range goals of your site before selecting the CMS you&#8217;re going to use. If you foresee a highly dynamic website with complex content types, and/or community features such as member login areas, multiple blogs, or user-created content, <a href="http://www.drupal.org/">Drupal</a> may be better suited to the job. On the other hand, if your content management needs are relatively straightforward, or if you intend to have a blog-centered website, <a href="http://www.wordpress.org/">WordPress</a> could be just right for you.</p>
<p>Still have questions? Please feel free to leave them in the comments &amp; we&#8217;ll do our best to answer them.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2009/11/drupal-vs-wordpress-which-one-is-right-for-you/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Drupal at Whitehouse.gov</title>
		<link>http://blog.raisedeyebrow.com/2009/10/drupal-at-whitehouse-gov/#utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=drupal-at-whitehouse-gov</link>
		<comments>http://blog.raisedeyebrow.com/2009/10/drupal-at-whitehouse-gov/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 19:43:02 +0000</pubDate>
		<dc:creator>Emira Mears</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://blog.raisedeyebrow.com/?p=670</guid>
		<description><![CDATA[There&#8217;s a great piece on the Drupal and the current White House website in today&#8217;s New York Times. Worth a read for Drupal users/fans or Open Source keeners.
]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a great piece on the Drupal and the current White House website in today&#8217;s <a href="http://bits.blogs.nytimes.com/2009/10/30/drupal-moves-into-the-white-house/" target="_blank">New York Times</a>. Worth a read for Drupal users/fans or Open Source keeners.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.raisedeyebrow.com/2009/10/drupal-at-whitehouse-gov/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
