On Walking to Work

For most of my career as a developer – say, nine of the past twelve years – I have lived within two miles of my workplace. Cybernet, BBK/PeopleDesign and now, Cynergy. On heavy traffic days it is actually faster for me to walk to work than to drive. Even on good days, driving saves me, at best, ten minutes in each direction. When weather permits, I ride my bike.

But I like best to walk. Especially in the morning, when the city is still waking up. The best days are in the cold parts of the year when the sun is just hitting the tops of the highest trees and buildings. Those are also the days when I walk home after dark.

Biking is more efficient, certainly, but – weather aside – I trust the drivers on the road less than during brighter parts of the year. There are fewer bikers from November through March, so drivers are even less aware of them (us) than usual. I can then choose to slalom quickly on the streets, slowly on the sidewalk, or just walk.

Currently I am exactly a mile and a half from work. The walk takes a little less than half an hour each way. Call it a total of fifty minutes a day, for three miles. Fifteen miles a week, and slightly over four hours. Sometimes I will stop for coffee at MadCap or the Grand Central Market. On the way home, I will often swing by the library. Sometimes I will stop back at the Grand Central Market for a sandwich.

The smell of the city changes from block to block and from month to month. In the summer, the city smells green and steamy. In the winter, earth and smoke. Currently, in the morning the scent trail goes something like this: leaves, earth, bread baking, pavement, car exhaust, bus fumes, cigarette smoke, concrete, pancakes, coffee, river, and occasionally hops from one of the local breweries. Each day is unique as a fingerprint.

This is the last work day of the year. Since i started this job on August 22, I have driven to work exactly twice. Call it 18 weeks. Or 17, when holidays are removed. So 17 weeks, five work-days a week, three miles a day. 255 miles. Or in my Subaru, a full tank of gas. Extrapolate it out and it is around 750 miles a year of using alternate transportation.

And the best part is that I feel more connected with Grand Rapids than I have in years. Working in front of a computer for 8+ hours a day, even in an office full of good people, is kind of alienating. Walking brings me back to earth.

Accessing Views From Flash in Drupal Gardens

Wow, life can be whacky.

So I am pretty sold on Drupal Gardens as a base for most of my future development projects. However, there are still a couple of useful pieces missing, that are out-of-the-box available on a full Drupal install. Specifically, the Services module. Services allow alternate means of accessing data stored in the Drupal database. So if I want to, say, use Drupal as a content management system for a Flash game, I can just pull information in as and when I need it, by referencing a URL and passing the appropriate parameters.

Drupal Gardens doesn’t allow that yet. Well, technically they do, but only in very specific ways, none of which are ideal for using Drupal as a straightforward CMS. Having said that, apparently adding this functionality is something they are looking into.

But enough carping! It is possible to use DG as a CMS for a Flash (or AJAX, or Silverlight, etc) application, provided you only need to pull content out of the database, not put it back in. It just takes a bit of a work-around to get everything up and running.

Note: The rest of this post assumes a familiarity with Actionscript, Drupal Views and RSS feeds. If not, take a few minutes to read up on them.

The Views module allows the contents of a view to be published as a Page, as a Block, or as an RSS feed. Say I am making a role-playing game, and I need to populate the world therein with wildlife. To keep things simple, each critter has the following information points:

  • name
  • description
  • terrain (where the creature might be encountered)
  • associated element ( from the classic 5, for combat purposes)

So after entering data for several animals, you would end up with a table which looks something like this:

Name Description Terrain element
squirrel cute, fluffy, voracious forest wood
camel cute, fluffy, spits a lot desert water
walrus truly, nature’s most majestic animal plains earth

…at least, that’s how it looks in the database. To get it into Flash (in Drupal Gardens, at present) requires a little more work. But not a lot more work.

Pulling the RSS feed of a view is quite simple. Just create a “feed” version of an existing view, and set up a URL path for it, and voila! You have a  feed of the contents of a view.

However, note that the actual contents of a view, when delivered in an RSS feed, are all packed into the <description> tag of the view, and include all of the HTML which would normally be rendered in the page. It looks something like this:

 

  http://ecceludum.drupalgardens.com/feeds/monsters/terrain/desert
    
    en
          http://ecceludum.drupalgardens.com/content/camel
    
&lt;div class=&quot;field field-name-body field-type-text-with-summary field-label-hidden&quot;&gt;
&lt;div class=&quot;field-items&quot;&gt;
&lt;div class=&quot;field-item even&quot; property=&quot;content:encoded&quot;&gt; 
&lt;p&gt;camel text&lt;/p&gt; 
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field field-name-field-monster-element field-type-taxonomy-term-reference field-label-above&quot;&gt;
&lt;div class=&quot;field-label&quot;&gt;element:&nbsp;
&lt;/div&gt;
&lt;div class=&quot;field-items&quot;&gt;
&lt;div class=&quot;field-item even&quot;&gt;
&lt;a href=&quot;/elements/water&quot; typeof=&quot;skos:Concept&quot; property=&quot;rdfs:label skos:prefLabel&quot;&gt;Water
&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;field field-name-field-monster-terrain field-type-taxonomy-term-reference field-label-above&quot;&gt;
&lt;div class=&quot;field-label&quot;&gt;terrain:&amp;nbsp;
&lt;/div&gt;
&lt;div class=&quot;field-items&quot;&gt;
&lt;div class=&quot;field-item even&quot;&gt;
&lt;a href=&quot;/terrain/desert&quot; typeof=&quot;skos:Concept&quot; property=&quot;rdfs:label skos:prefLabel&quot;&gt;desert
&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;

     Thu, 15 Dec 2011 18:22:47 +0000
 John Winkelman
 71 at http://ecceludum.drupalgardens.com
 http://ecceludum.drupalgardens.com/content/camel#comments
  
  

All well and good, except boy, are the contents of the DESCRIPTION tag ugly. That is because the  angle brackets, ampersands, quote marks and non-breaking spaces have  been re-written as plain text character entities. In a sense, they have been rendered as a picture of source code, rather than source code. There is a simple fix for this: When Flash pulls in an RSS feed (or any other XML-based document) it pulls this content in as plain text. It is not structured as XML until after it is loaded into the Flash movie. This means that the string can be parsed internally, and all of the character entities turned into their respective text elements. E.g. each instance of “&gt;” can be replaced with a “>”. The simplest way might be the following line of code:

var newString = oldString.split("&lt;").join("<").split("&gt;").join(">").split("&quot;").join("\"").split("&nbsp;").join(" ");
var myXML = new XML(newString);

If that is run on the preceding big ugly bit of RSS feed, then the contents of the DESCRIPTION tags would suddenly look like this:

<div class="field field-name-body field-type-text-with-summary field-label-hidden">
<div class="field-items">
<div class="field-item even" property="content:encoded"> 
<p>camel text</p> 
</div>
</div>
</div>
<div class="field field-name-field-monster-element field-type-taxonomy-term-reference field-label-above">
<div class="field-label">element: 
</div>
<div class="field-items">
<div class="field-item even">
<a href="/elements/water" typeof="skos:Concept" property="rdfs:label skos:prefLabel">Water
</a>
</div>
</div>
</div>
<div class="field field-name-field-monster-terrain field-type-taxonomy-term-reference field-label-above">
<div class="field-label">terrain:&nbsp;
</div>
<div class="field-items">
<div class="field-item even">
<a href="/terrain/desert" typeof="skos:Concept" property="rdfs:label skos:prefLabel">desert
</a>
</div>
</div>
</div>

Now the contents of the DESCRIPTION element of the RSS feed XML are structured and can be parsed using the Flash XML tools. In this instance, you would look for the contents of the elements div.field-name-field-monster-element a, div.field-name-field-monster-terrain a, and div.field-name-body p.

You will note that there are a lot of extra DIV tags, and many of them have huge long class names and/ir IDs. This is not a problem for two reasons: first, the data is well-structured, and second, it is consistent. Unless there are changes to the structure of the View in Drupal Gardens – e.g. changing the “terrain” data field to be called “territory” instead – every time the data is pulled from this RSS feed for this View, it will have exactly the same structure. Having five records or ten thousand won’t change things.

So there it is: An overview of how to access Views information from a Flash movie, via RSS, in Drupal Gardens.