<?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>BigSmoke &#187; HTTP</title>
	<atom:link href="http://blog.bigsmoke.us/tag/http/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.bigsmoke.us</link>
	<description>Smokes your problems, coughs fresh air.</description>
	<lastBuildDate>Tue, 07 Sep 2010 08:43:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Atom and REST</title>
		<link>http://blog.bigsmoke.us/2009/10/09/atom-rest</link>
		<comments>http://blog.bigsmoke.us/2009/10/09/atom-rest#comments</comments>
		<pubDate>Fri, 09 Oct 2009 21:07:17 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Atom]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=841</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s is an interesting discussion about <a href="http://bill.burkecentral.com/2008/10/06/atom-too-soapy-for-me/">when (not) to use the Atom protocol for your REST API</a>.</p>

<p>While looking at the trackbacks of that post, I came across a very nice post by Subbu detailing the <a href="http://www.subbu.org/blog/2008/10/location-vs-content-location">differences between and uses of the <tt>Location</tt> and <tt>Content-Location</tt> HTTP headers</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2009/10/09/atom-rest/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XMLHttpRequest caching behaviour</title>
		<link>http://blog.bigsmoke.us/2009/10/09/ajax-caching</link>
		<comments>http://blog.bigsmoke.us/2009/10/09/ajax-caching#comments</comments>
		<pubDate>Fri, 09 Oct 2009 20:45:41 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[HTTP]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=837</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>I was suprised to <a href="http://www.mnot.net/blog/2006/05/11/browser_caching">learn</a> that the caching mechanism in the web browser often behaves differently for AJAX requests than it does for regular HTTP requests. Someone has created a <a href="http://www.mnot.net/javascript/xmlhttprequest/cache.html">set of functional tests</a> to analyze differences in browser behaviour.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2009/10/09/ajax-caching/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>www.stichting-ecosafe.org</title>
		<link>http://blog.bigsmoke.us/2009/09/16/www.stichting-ecosafe.org</link>
		<comments>http://blog.bigsmoke.us/2009/09/16/www.stichting-ecosafe.org#comments</comments>
		<pubDate>Wed, 16 Sep 2009 10:19:56 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[406]]></category>
		<category><![CDATA[AHAH]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[mod_include]]></category>
		<category><![CDATA[mod_negotiation]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[SSI]]></category>
		<category><![CDATA[WWW]]></category>
		<category><![CDATA[www.stichting-ecosafe.org]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=683</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Stichting EcoSafe is a Dutch foundation for the safe-keeping of the funds that are necessary for the maintenance of hardwood plantations. In July of 2006, together with Johan Ockels, I created a website for the Foundation. Johan was responsible for the organization of the whole process. This went very smooth and the website ended up being an emblem of simplicity and clarity. That&#8217;s why I wanted to blog a bit about it now, even though there are a few things that I&#8217;d probably end up doing different if I were to start from scratch. [There's actually a disturbing number of things for which this is true, I'm coming to notice.]</p>

<table class="invisible" style="border: none;"><tr><td valign="top">
<div id="attachment_708" class="wp-caption alignnone" style="width: 310px"><a rel="lightbox-screen" href="http://blog.bigsmoke.us/uploads/2009/07/ecosafe-index-en.png"><img src="http://blog.bigsmoke.us/uploads/2009/07/ecosafe-index-en-300x206.png" alt="The Welcome page of the EcoSafe website" title="www.stichting-ecosafe.org/index.en" width="300" height="206" class="size-medium wp-image-708" /></a><p class="wp-caption-text">The Welcome page of the EcoSafe website</p></div>
</td><td valign="top">
<div id="attachment_794" class="wp-caption alignnone" style="width: 310px"><a rel="lightbox-screen" href="http://blog.bigsmoke.us/uploads/2009/09/ecosafe-plantations-en.png"><img src="http://blog.bigsmoke.us/uploads/2009/09/ecosafe-plantations-en-300x206.png" alt="EcoSafe page for plantations" title="www.stichting-ecosafe.org/plantations.en" width="300" height="206" class="size-medium wp-image-794" /></a><p class="wp-caption-text">EcoSafe page for plantations</p></div>
</td><td valign="top">
<div id="attachment_810" class="wp-caption alignnone" style="width: 310px"><a href="http://blog.bigsmoke.us/uploads/2009/09/ecosafe-cost-structure-en.png"><img src="http://blog.bigsmoke.us/wp-factory/../uploads/2009/09/ecosafe-cost-structure-en-300x205.png" alt="EcoSafe cost structure" title="www.stichting-ecosafe.org/cost-structure.en" width="300" height="205" class="size-medium wp-image-810" /></a><p class="wp-caption-text">EcoSafe cost structure</p></div>
</td></tr></table>

<h2 id="file-structure">File structure</h2>

<p>Like with most websites, I started with creating an SVN repo so that I wouldn&#8217;t have to be afraid of ever losing anything.</p>

<p>The file structure was pretty standard:</p>

<ul>
<li>a <tt>css</tt> dir for stylesheets;</li>
<li><tt>img</tt> for images;</li>
<li><tt>inc</tt> for shared PHP and mod_include stuff and for AJAX partials;</li>
<li><tt>jot</tt> for to-do&#8217;s and other notes;</li>
<li>and <tt>js</tt> for JavaScript files and libraries.</li>
</ul>

<h3>Possible file structure improvements</h3>

<p>If I were to redesign this file structure, I&#8217;d collapse <tt>css</tt>, <tt>img</tt> and <tt>js</tt> into one directory called <tt>layout</tt>, because these are typically things that require the same <tt>robots.txt</tt> and caching policy. Also, it is meaningless to organize things by file extension. If you want to sort something by file extension, use <q><tt>ls -X</tt></q> (or <q><tt>ls --sort=extension</tt></q> if you&#8217;re on GNU).</p>


<h2 id="ssi">Server-side includes</h2>

<p>The site would be so simple that I felt that any type of CMS or content transformation would be completely unnecessary. Instead, I decided to rely on Apache&#8217;s <a href="http://httpd.apache.org/docs/1.3/mod/mod_include.html">mod_include</a> and just use a few partials for repeating page elements such as the left sidebar containing the logo and the menu.</p>

<p>Also, because I didn&#8217;t need to transform the HTML files, I decided I could use good ol&#8217; HTML 4 instead of XHTML 1 (which I&#8217;d have to send to the browser with the wrong mime-type anyway).</p>

<p>This is the HTML for <tt>contact.nl.shtml</tt>:</p>

<pre class="php">&lt;!DOCTYPE html PUBLIC <span style="color: #ff0000;">&quot;-//W3C//DTD HTML 4.01//EN&quot;</span> <span style="color: #ff0000;">&quot;http://www.w3.org/TR/html4/loose.dtd&quot;</span>&gt;
&nbsp;
&lt;html lang=<span style="color: #ff0000;">&quot;en&quot;</span>&gt;
  &lt;head&gt;
    &lt;title&gt;Contact EcoSafe&lt;/title&gt;
&nbsp;
    &lt;meta http-equiv=<span style="color: #ff0000;">&quot;Content-Type&quot;</span> content=<span style="color: #ff0000;">&quot;text/html; charset=UTF-8&quot;</span> /&gt;
&nbsp;
    &lt;link rel=<span style="color: #ff0000;">&quot;stylesheet&quot;</span> type=<span style="color: #ff0000;">&quot;text/css&quot;</span> href=<span style="color: #ff0000;">&quot;/css/style.css&quot;</span>&gt;&lt;/link&gt;
  &lt;/head&gt;
&nbsp;
  &lt;body&gt;
    &lt;!--<span style="color: #808080; font-style: italic;">#include virtual=&quot;/inc/left-side.en.html&quot;--&gt;</span>
&nbsp;
    &lt;!--<span style="color: #808080; font-style: italic;">#include virtual=&quot;/inc/alt-lang.phtml&quot;--&gt;</span>
&nbsp;
    &lt;div id=<span style="color: #ff0000;">&quot;content&quot;</span>&gt;
      &lt;h1&gt;Contact&lt;/h1&gt;
&nbsp;
      &lt;p&gt;Your email to EcoSafe kan be sent to the following address:
      &lt;a href=<span style="color: #ff0000;">&quot;mailto:service@stichting-ecosafe.org&quot;</span>&gt;service@stichting-ecosafe.org&lt;/a&gt;.
      Or, alternatively, you can fax us at <span style="color: #cc66cc;">+31</span> <span style="color: #cc66cc;">50</span> - <span style="color: #cc66cc;">309</span> <span style="color: #cc66cc;">66</span> <span style="color: #cc66cc;">58</span>.&lt;/p&gt;
&nbsp;
      &lt;h2&gt;About this website&lt;/h2&gt;
&nbsp;
      &lt;p&gt;For comments and/or suggestions concerning this website,
      you can direct an email message at:
      &lt;a href=<span style="color: #ff0000;">&quot;mailto:webmaster@stichting-ecosafe.org&quot;</span>&gt;webmaster@stichting-ecosafe.org&lt;/a&gt;.&lt;/p&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre>

<div id="attachment_788" class="wp-caption alignright" style="width: 197px"><img src="http://blog.bigsmoke.us/uploads/2009/09/ecosafe-alt-language.png" alt="Alternative language selection" title="www.stichting-ecosafe.org alternative language selection" width="187" height="38" class="size-full wp-image-788" /><p class="wp-caption-text">Alternative language selection</p></div>

<p>I use <tt>&lt;!--#include virtual--&gt;</tt> to include the repeating parts. <tt>&lt;!--#include virtual--&gt;</tt> has several advantages over <tt>&lt;!--#include file--&gt;</tt> in that it allows for content-negotiation, execution of dynamic content etc., but here the only place were it holds an advantage is in the inclusion of <tt>/inc/alt-lang.phtml</tt>. <tt>alt-lang.phtml</tt> is a messy PHP script that figures out which language variants of a page are available and displays a selection of alternative language versions (variants with a language different from the current).</p>

<h3>SSI and caching</h3>

<p>Without the <A href="http://httpd.apache.org/docs/1.3/mod/mod_include.html#xbithack">XBitHack directive</a> set to <tt>full</tt>, all content handled by <tt>mod_include</tt> is sent without a <tt>Last-Modified</tt> header. However, I don&#8217;t want to use <tt>XBitHack</tt> at all, because I don&#8217;t want just any executable file to be handled by <tt>mod_include</tt>; that just too much of a … hack.</p>

<p>If I were to do something similar now, I&#8217;d use some kind of (sed) substitution to pre-process the includes locally so that more of what I end up uploading is simple static content. The dynamic part of the included PHP script, I would simply replace with JavaScript.</p>

<h2 id="visual">Visual design</h2>

<p>As you can see in the HTML example, there&#8217;s hardly anything layout oriented in the HTML source. This is good, and means that I have to touch only the CSS for most minor and major lay-out modifications. (It is a pipe-dream to think that you only need to change the CSS to make the same HTML page look however you want as long as that HTML is rich enough in meaning, but for a site with pages of such simple structure, it&#8217;s a dream that comes pretty close to reality.)</p>

<p>I&#8217;m not much of a designer, but I think design is overrated anyway. Actually, I think that most website suffer from too much design.</p>

<div id="attachment_692" class="wp-caption alignright" style="width: 275px"><img src="http://blog.bigsmoke.us/uploads/2009/07/ecosafe-logo.jpg" alt="The EcoSafe logo" title="EcoSafe logo" width="265" height="217" class="size-full wp-image-692" /><p class="wp-caption-text">The EcoSafe logo</p></div>

<p>To start the design, I got a logo made by <a href="http://wiki.hardwood-investments.net/Huite_Zijlstra">Huite Zijlstra</a>. Because the logo was pretty big and didn&#8217;t look good scaled down, I decided to put it at the left of the content area instead of at the top. This would still leave enough room for the menu (which actually takes less space horizontally than the logo).</p>

<h3 id="colors">Colors</h3>

<p>For the color scheme, I just picked a few colors from the logo. As always, the base of the scheme would be black text on a white background for maximum readability. The print version hardly uses any colors.</p>

<pre class="css"><span style="color: #a1a100;">@media screen {</span>
body            <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span>: <span style="color: #993333;">white</span>;  <span style="color: #66cc66;">&#125;</span>
*               <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span>: <span style="color: #000000; font-weight: bold;">black</span>;             <span style="color: #66cc66;">&#125;</span>
a<span style="color: #3333ff;">:link </span>         <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span>: #<span style="color: #cc66cc;">585</span>;              <span style="color: #66cc66;">&#125;</span>
h1              <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span>: #<span style="color: #cc66cc;">880</span>;              <span style="color: #66cc66;">&#125;</span>
h2              <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span>: #<span style="color: #cc66cc;">888</span>;              <span style="color: #66cc66;">&#125;</span>
strong          <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span>: #a62;              <span style="color: #66cc66;">&#125;</span>
#menu li a      <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span>: #<span style="color: #cc66cc;">660</span>;              <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>

<h3 id="underlines">Underlines</h3>

<p>I wanted an underline below the level 1 and 2 headings. Because I didn&#8217;t like the effect of <tt>text-decoration:underline</tt> (too thick for <tt>&lt;h2&gt;</tt>s, too dark for <tt>&lt;h1&gt;</tt>s and different from browser to browser) and because <tt>border-bottom</tt> was set too far from the text, I made two simple PNG images that I could <tt>repeat-x</tt> along the bottom edge.</p>

<pre class="css"><span style="color: #a1a100;">@media screen {</span>
h1 <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #993333;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/img/h1-border-bottom.png'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">bottom</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">repeat-x</span>; <span style="color: #66cc66;">&#125;</span>
h2 <span style="color: #66cc66;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span>: <span style="color: #993333;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/img/hx-border-bottom.png'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">bottom</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #993333;">repeat-x</span>; <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>

<h3 id="menu">Menu</h3>

<p>The menu is very simple. The markup is part of <tt>inc/left-side.en.html</tt> for the English version and <tt>inc/left-side.nl.html</tt> for the Dutch version:</p>

<pre class="bash">cat inc/left-side.en.html</pre>
<pre class="php">&lt;div id=<span style="color: #ff0000;">&quot;left&quot;</span> lang=<span style="color: #ff0000;">&quot;en&quot;</span>&gt;
  &lt;a <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">&quot;logo&quot;</span> href=<span style="color: #ff0000;">&quot;/index.en&quot;</span>&gt;&lt;img <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">&quot;logo&quot;</span> alt=<span style="color: #ff0000;">&quot;[Logo]&quot;</span> src=<span style="color: #ff0000;">&quot;/img/logo.jpg&quot;</span>&gt;&lt;/img&gt;&lt;/a&gt;
&nbsp;
  &lt;ul id=<span style="color: #ff0000;">&quot;menu&quot;</span> <span style="color: #000000; font-weight: bold;">class</span>=<span style="color: #ff0000;">&quot;menu&quot;</span>&gt;
    &lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/index.en&quot;</span> rel=<span style="color: #ff0000;">&quot;start&quot;</span>&gt;Start page&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/plantations.en&quot;</span>&gt;For plantations&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/investors.en&quot;</span>&gt;For investors&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/history.en&quot;</span>&gt;History&lt;/a&gt;&lt;/li&gt;
    &lt;!--&lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/goals&quot;</span>&gt;Goals&lt;/a&gt;&lt;/li&gt;--&gt;
    &lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/methods.en&quot;</span>&gt;How it works&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/cost-structure.en&quot;</span>&gt;Cost structure&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/cost-calculator.en&quot;</span>&gt;Cost calculator&lt;/a&gt;&lt;/li&gt;
    &lt;!--&lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/clients.en&quot;</span>&gt;Clients&lt;/a&gt;&lt;/li&gt;--&gt;
    &lt;li&gt;&lt;a href=<span style="color: #ff0000;">&quot;/contact.en&quot;</span>&gt;Contact&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
&nbsp;
&lt;script type=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> src=<span style="color: #ff0000;">&quot;/js/menu.js&quot;</span>&gt;&lt;/script&gt;</pre>

<div id="attachment_710" class="wp-caption alignright" style="width: 270px"><img src="http://blog.bigsmoke.us/uploads/2009/07/ecosafe-menu-en.png" alt="The EcoSafe menu (in English)" title="EcoSafe menu EN" width="260" height="438" class="size-full wp-image-710" /><p class="wp-caption-text">The EcoSafe menu (in English)</p></div>

<p>As is customary, I started by removing all the default list styles and made the anchors behave as block-level elements. I used the big O from the logo for bullets in the list (using <tt>background-image</tt> instead of <tt>list-style-image</tt> because the latter gives unpredictable cross-browser results and doesn&#8217;t make the bullet clickable).</p>

<pre class="css"><span style="color: #cc00cc;">#menu <span style="color: #66cc66;">&#123;</span></span>
  <span style="color: #000000; font-weight: bold;">margin-top</span>: 2em;
  <span style="color: #000000; font-weight: bold;">margin-left</span>: 2em;
  <span style="color: #000000; font-weight: bold;">list-style-type</span>: <span style="color: #993333;">none</span>;
  <span style="color: #000000; font-weight: bold;">padding</span>: <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
#menu li <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin</span>: <span style="color: #cc66cc;">0</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
#menu li a <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">display</span>: <span style="color: #993333;">block</span>;
  <span style="color: #000000; font-weight: bold;">background-image</span>: <span style="color: #993333;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/img/o-21x16.png'</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #000000; font-weight: bold;">background-position</span>: <span style="color: #000000; font-weight: bold;">top</span> <span style="color: #000000; font-weight: bold;">left</span>;
  <span style="color: #000000; font-weight: bold;">background-repeat</span>: <span style="color: #993333;">no-repeat</span>;
  <span style="color: #000000; font-weight: bold;">padding-left</span>: 30px;
  <span style="color: #000000; font-weight: bold;">text-decoration</span>: <span style="color: #993333;">none</span>;
  <span style="color: #000000; font-weight: bold;">font-family</span>: <span style="color: #993333;">sans-serif</span>;
  <span style="color: #000000; font-weight: bold;">font-weight</span>: <span style="color: #993333;">bold</span>;
  <span style="color: #000000; font-weight: bold;">color</span>: #<span style="color: #cc66cc;">660</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
#menu li a:hover,
#menu li<span style="color: #6666ff;">.active </span>a <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-image</span>: <span style="color: #993333;">url</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/img/oSafe-21x16.png'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
#menu a<span style="color: #3333ff;">:hover </span><span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">color</span>: #<span style="color: #cc66cc;">787800</span>;
<span style="color: #66cc66;">&#125;</span></pre>

<h4>JavaScript menu item activation</h4>

<p>To add the <tt>active</tt> class to the currently active list item (<tt>&lt;li&gt;</tt>), I used a client-side solution using JavaScript. After all, it&#8217;s proper use of JavaScript to enhance your user interface with it (as long as, as many would say, it isn&#8217;t <em>required</em> for the UI to function (as it is in the Cost Calculator)).</p>

<pre class="javascript"><span style="color: #009900; font-style: italic;">// menu.js</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> menu = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'menu'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #003366; font-weight: bold;">var</span> anchors = menu.<span style="color: #006600;">getElementsByTagName</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #003366; font-weight: bold;">var</span> locationHref = window.<span style="color: #006600;">location</span>.<span style="color: #006600;">pathname</span>.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span>i = anchors.<span style="color: #006600;">length</span> - <span style="color: #CC0000;">1</span>; i &gt;= <span style="color: #CC0000;">0</span>; i--<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  a = anchors<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>;
  aHref = a.<span style="color: #006600;">href</span>;
    
  <span style="color: #009900; font-style: italic;">// Does this menu item link to the current page?</span>
  <span style="color: #009900; font-style: italic;">// We find out by looking if the window location contains the URL in the anchor</span>
  <span style="color: #009900; font-style: italic;">// or the other way arround. The reason to look at both is content-negotiation.</span>
  <span style="color: #009900; font-style: italic;">// It's also true if the location is just '/' and we're looking at the anchor of</span>
  <span style="color: #009900; font-style: italic;">// the 'start' page.</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">&#40;</span>locationHref === <span style="color: #3366CC;">'/'</span> &amp;&amp; a.<span style="color: #006600;">rel</span> === <span style="color: #3366CC;">'start'</span><span style="color: #66cc66;">&#41;</span> ||
       <span style="color: #66cc66;">&#40;</span>locationHref !== <span style="color: #3366CC;">'/'</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span> locationHref.<span style="color: #006600;">indexOf</span><span style="color: #66cc66;">&#40;</span>aHref<span style="color: #66cc66;">&#41;</span> !== <span style="color: #CC0000;">-1</span> ||
                                  aHref.<span style="color: #006600;">indexOf</span><span style="color: #66cc66;">&#40;</span>locationHref<span style="color: #66cc66;">&#41;</span> !== <span style="color: #CC0000;">-1</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    a.<span style="color: #006600;">parentNode</span>.<span style="color: #006600;">className</span> = <span style="color: #3366CC;">'active'</span>;
    <span style="color: #000066; font-weight: bold;">break</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>

<p>I actually just fixed a long-standing bug that was caused by me not being able to fully rely on HTTP language negotiation for the selection of the appropriate language variant, which made me change all links from being language-neutral to including the language in the link target (e.g.: <tt>http:///history</tt> became <tt>http:///history.en</tt> and <tt>http:///history.nl</tt>), the problem with this being that, instead of being able to link to link to <tt>http:///</tt> (<tt>http://www.stichting-ecosafe.org/</tt>), I had to link to <tt>http:///index.en</tt> or <tt>http:///index.nl</tt>, making it more difficult to detect the active anchor if we&#8217;re requesting the home page through <tt>http:///</tt> instead of on of its language-specific URLs.</p>

<p>The JavaScript rested on the assumption that by reverse iterating through all the anchors in the menu and thus processing the link to <tt>http:///</tt> as last, I&#8217;d know that I had struck the home page and wouldn&#8217;t need to worry that <em>any of the links</em> contain a slash. (I don&#8217;t know if I intended it to work this way, but it sure seems to me now that the only way this could ever have worked was as an apparent side-effect of the looping order; the SVN logs seem to agree.)</p>

<p>I could have solved this by redirecting all requests for <tt>http:///</tt> to the appropriate variant. Maybe I should have (to avoid duplicate content). Instead I chose to add a <tt>rel="start"</tt> attribute to the links to the home page, as can be deduced from the JavaScript above. (To resolve the duplicate content issue, I could also add a <a href="http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html">canonical link</a> to the header of the two language variants.)</p>

<p>Anyway, all this brings me to the messy subject of content negotiation.</p>

<h2 id="content-negotiation">Content and language negotiation</h2>

<p>The EcoSafe website would be bi-lingual (English and Dutch) from the onset. Initially, I wanted to use language negotiation to the extend of having completely language-neutral URLs. For example: <q><tt>http:///cost-calculator</tt></q> instead of <q><tt>http:///cost-calculator.en</tt></q> and <q><tt>http:///cost-calculator.nl</tt></q>. In the end, you can make this work properly in the browser with the help of a cookie, but it&#8217;s still a pipe-dream because nothing else will work if you do not also offer another navigational path to the different variants. Maybe, we&#8217;ll revisit this topic for a later experiment.</p>

<p>Content-type negotiation is almost effortless with Apache thanks to <tt><a href="http://httpd.apache.org/docs/1.3/mod/mod_negotiation.html">mod_negotiation</a></tt>. If, like me, you despise to have <tt>.html</tt>, <tt>.htm</tt>, <tt>.xhtml</tt>, <tt>.phtml</tt>, <tt>.pxhtml</tt>. <tt>.sxhtml</tt>, <tt>.php</tt>, <tt>.xml</tt> in your URL (I actually used all of these at some time or other), you only have to make sure that <tt>MultiViews</tt> is in your options.</p>

<p>I&#8217;ve configured SSI by means of the following instead of a “magic mime-type”:</p>

<pre class="apache"><span style="color: #00007f;">AddType</span>         text/html       .shtml
<span style="color: #00007f;">AddHandler</span>      server-parsed   .shtml
<span style="color: #00007f;">AddCharset</span>      UTF<span style="color: #ff0000;">-8</span>           .shtml
AddOutputFilter <span style="color: #0000ff;">Includes</span>        .shtml</pre>

<p>For PHP I couldn&#8217;t do the same because my web host was still at Apache 1.3. Otherwise, the following should have worked equally well for PHP:</p>

<pre class="apache"><span style="color: #adadad; font-style: italic;"># This doesn't work with Apache 1.3</span>
<span style="color: #00007f;">AddType</span>        text/html       .phtml
<span style="color: #00007f;">AddHandler</span>     php-<span style="color: #00007f;">script</span>      .phtml
<span style="color: #00007f;">AddCharset</span>     UTF<span style="color: #ff0000;">-8</span>           .phtml</pre>

<p>Configuring language priority is easy with Apache:</p>

<h3>Integrating PHP and SSI</h3>

<p>The integration of PHP with all the weirdness that I had configured and created around SSI took some figuring out. Luckily, PHP offers a <a href="http://www.php.net/virtual"><tt>virtual()</tt></a> function that works roughly the same as <tt>mod_include's</tt> <tt>&lt;!--#include virtual--&gt;</tt>. Here&#8217;s an example:</p>

<pre class="php">&lt;body&gt;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/virtual"><span style="color: #000066;">virtual</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'/inc/left-side.en.html'</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #0000ff;">$uri</span> = <span style="color: #ff0000;">'/cost-calculator.en.phtml'</span>; <span style="color: #b1b100;">include</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'inc/alt-lang.phtml'</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span></pre>

<p>In retrospect, it&#8217;s pretty much bullshit to use it. I could have just as well <tt>require()</tt>d the partials (which I actually did for the alternate language selection), but I probably started out using virtual on a more generic URL without language and content-type selection in it.</p>

<h3>406 handling</h3>

<p>Because I deployed on Apache 1.3 and the <tt><a href="http://httpd.apache.org/docs/2.0/mod/mod_negotiation.html#forcelanguagepriority">ForceLanguagePriority</a></tt> directive was only introduced with Apache 2.0.30, I had to write an ugly hack to avoid visitors getting 406 errors. To that end, I added a 406 handler to my <tt>.htaccess</tt> file:</p>

<pre class="apache"><span style="color: #00007f;">LanguagePriority</span> en nl
ForceLanguagePriority Prefer Fallback <span style="color: #adadad; font-style: italic;"># This doesn't work with 1.3</span>
&nbsp;
<span style="color: #00007f;">ErrorDocument</span> <span style="color: #ff0000;">406</span> /error<span style="color: #ff0000;">-406</span>.php <span style="color: #adadad; font-style: italic;"># Luckily, this does </span></pre>

<p><tt>error-406.php</tt> is a PHP file that figures out the available variants based on <tt>$_SERVER['REQUEST_URI']</tt>. Then, it simply picks the first one (which works because, accidentally, that&#8217;s the one I&#8217;ve given priority using the <tt><a href="http://httpd.apache.org/docs/1.3/mod/mod_negotiation.html#languagepriority">LanguagePriority</a></tt> directive as well), outputs a 200 OK header instead of the 406, and <tt>virtual()</tt>s the file of the variant. The code looks somewhat like this:</p>

<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<a href="http://www.php.net/chdir"><span style="color: #000066;">chdir</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'DOCUMENT_ROOT'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$filenames</span> = <a href="http://www.php.net/glob"><span style="color: #000066;">glob</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/basename"><span style="color: #000066;">basename</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$_SERVER</span><span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'REQUEST_URI'</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span> . <span style="color: #ff0000;">&quot;.*&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0000ff;">$filename</span> = <span style="color: #0000ff;">$filenames</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
<a href="http://www.php.net/apache_setenv"><span style="color: #000066;">apache_setenv</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'DOCUMENT_URI'</span>, <span style="color: #ff0000;">&quot;/$filename&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<a href="http://www.php.net/header"><span style="color: #000066;">header</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'HTTP/1.1 200 OK'</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://www.php.net/virtual"><span style="color: #000066;">virtual</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$filename&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre>

<div id="attachment_807" class="wp-caption alignright" style="width: 310px"><a rel="lightbox-ecosafe" href="http://blog.bigsmoke.us/uploads/2009/09/ecosafe-cost-calculator.png"><img src="http://blog.bigsmoke.us/uploads/2009/09/ecosafe-cost-calculator-300x137.png" alt="EcoSafe Cost Calculator" title="www.stichting-ecosafe.org/cost-calculator" width="300" height="137" class="size-medium wp-image-807" /></a><p class="wp-caption-text">EcoSafe Cost Calculator</p></div>

<div id="attachment_808" class="wp-caption alignright" style="width: 194px"><a href="http://blog.bigsmoke.us/uploads/2009/09/ecosafe-cost-calculation.png"><img src="http://blog.bigsmoke.us/uploads/2009/09/ecosafe-cost-calculation-184x300.png" alt="EcoSafe Cost Calculator results" title="EcoSafe cost calculation" width="184" height="300" class="size-medium wp-image-808" /></a><p class="wp-caption-text">EcoSafe Cost Calculator results</p></div>

<h2>The Cost Calculator</h2>

<p>The EcoSafe Cost Calculator is some of the least neatly contained and most procedurally oriented PHP code I&#8217;ve ever produced while knowing full well what I was doing. It does almost everything it does in global scope. Yet, it does it well.</p>

<p>The thing is designed as a dynamic web page rather than a web application. What I mean by this is that it&#8217;s simply two pages (one for English and one for Dutch) using PHP among a number of pages using SSI. In an application, it&#8217;s usual to have just one ‘view’ that is the same for all languages, but here I chose to put the different language versions in different language pages and then include everything reusable (and language-neutral) from within these files.</p>

<p>Most of the actual processing and calculating is done in <tt>inc/costs-functions.php</tt>.  (The part about gotos is a joke. (Labeled blocks would have been quite sufficient. <img src='http://blog.bigsmoke.us/wp-factory/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ))</p>

<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #808080; font-style: italic;"># costs-functions.php - Stuff that's includes by cost-calculator.{nl,en}.phtml</span>
<span style="color: #808080; font-style: italic;">/**
 * Just remember that this code was never meant to be general purpose or anything.
 * So, relaxeeee and keep your OO-axe burried where it belongs.
 * Oh, if only PHP would support GOTO's ... Sigh ...
 */</span></pre>

<p>The rest of the file is just a whole lot of processing of form data and turning it into something that can be easily traversed for display to the user. There are even the function calls without arguments doing all their work on globals. These are actually only added to make it clearer <em>em</em> a piece of code is doing. And—I must say—after a few years it&#8217;s still remarkably clear to me what each part of the code is doing. There&#8217;s no deep, confusing nesting structures or anything. There&#8217;s just a whole lot of very simple code.</p>

<h3>Some simple AHAH increases form interactivity</h3>

<p>Users of the calculator can add any number of plantings and locations. When the user decides to add a planting or a location, the <tt>onClick</tt> event triggers the execution of <tt>addExtraPlanting()</tt> or <tt>addExtraLocation()</tt>. Here&#8217;s how <tt>addExtraPlanting()</tt> looks:</p>

<pre class="javascript"><span style="color: #003366; font-weight: bold;">function</span> addExtraPlanting<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  lang = document.<span style="color: #006600;">documentElement</span>.<span style="color: #006600;">lang</span>;
&nbsp;
  <span style="color: #003366; font-weight: bold;">new</span> Ajax.<span style="color: #006600;">Updater</span><span style="color: #66cc66;">&#40;</span>
    <span style="color: #3366CC;">'plantings'</span>, <span style="color: #3366CC;">'/inc/planting.'</span> + lang, <span style="color: #66cc66;">&#123;</span>
      method: <span style="color: #3366CC;">'get'</span>,
      insertion: Insertion.<span style="color: #006600;">Bottom</span>
    <span style="color: #66cc66;">&#125;</span>
  <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre>

<p><a href="http://api.prototypejs.org/ajax/ajax/updater.html"><tt>Ajax.Updater</tt></a> comes from the <a href="http://www.prototypejs.org/">Prototype JavaScript framework</a>.</p>

<p>Here&#8217;s what <tt>inc/planting.en.phtml</tt> looks like. The same file is also included in a loop to rebuild the form&#8217;s state after submitting.</p>

<pre class="php">&lt;li&gt;
  &lt;input name=<span style="color: #ff0000;">&quot;num_hectares[]&quot;</span> type=<span style="color: #ff0000;">&quot;text&quot;</span> size=<span style="color: #ff0000;">&quot;5&quot;</span> value=<span style="color: #ff0000;">&quot;&lt;?php echo $num_hectares ?&gt;&quot;</span> /&gt;
&nbsp;
  hectares have been planted in
&nbsp;
  &lt;select name=<span style="color: #ff0000;">&quot;plant_years[]&quot;</span>&gt;&lt;?php <span style="color: #b1b100;">require</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'planting_options.php'</span><span style="color: #66cc66;">&#41;</span> ?&gt;&lt;/select&gt;
&nbsp;
  <span style="color: #66cc66;">&#40;</span>&lt;a title=<span style="color: #ff0000;">&quot;Remove this planting&quot;</span> href=<span style="color: #ff0000;">&quot;#&quot;</span> onclick=<span style="color: #ff0000;">&quot;removePlanting(this); return false;&quot;</span>&gt;x&lt;/a&gt;<span style="color: #66cc66;">&#41;</span>
&lt;/li&gt;</pre>

<p>I think that I&#8217;ve gone into small enough detail by now to get to the conclusion. Also showing the contents of <tt>planting_options.php</tt> would be pushing it. Ah, well…</p>

<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> !<a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$this_year</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">$this_year</span> = <a href="http://www.php.net/intval"><span style="color: #000066;">intval</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.php.net/date"><span style="color: #000066;">date</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Y'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> !<a href="http://www.php.net/isset"><span style="color: #000066;">isset</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$plant_year</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #0000ff;">$plant_year</span> = <span style="color: #0000ff;">$this_year</span>;
&nbsp;
<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span> = <span style="color: #0000ff;">$this_year</span>; <span style="color: #0000ff;">$i</span> &gt;= <span style="color: #0000ff;">$this_year</span> - <span style="color: #cc66cc;">20</span>; <span style="color: #0000ff;">$i</span>--<span style="color: #66cc66;">&#41;</span>
  <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;&lt;option&quot;</span> . <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$i</span> == <span style="color: #0000ff;">$plant_year</span> ? <span style="color: #ff0000;">&quot; selected='1'&quot;</span> : <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span> . <span style="color: #ff0000;">&quot;&gt;$i&lt;/option&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;</pre>

<p>(Yesterday, I couldn&#8217;t resist the temptation of turning this into a simple file to <tt>require()</tt> instead of the function definition it was. I think it&#8217;s funny to refactor something to <em>remove</em> encapsulation.)</p>

<h2>Conclusion</h2>

<p>As is usual when looking at old code, I see many things that I&#8217;d do (even just a little) different today, but I saw a surprising number of solutions that I actually still like now that I see them back after three years. Removing some of the remaining warts probably won&#8217;t do much good besides the masturbatory satisfaction it could give me. (It&#8217;s likely that the website won&#8217;t live much longer, making such extra attention very undeserved.) But, nevertheless, I&#8217;ve enjoyed blogging about it now to recoup the whole experience and to at least <em>look</em> at what I&#8217;d do different now and what I learned in the meantime.</p>

<h2>Some links</h2>

<ul>
  <li><a href="http://www.w3.org/TR/html401/types.html#type-links">The HTML spec. on <cite>Link types</cite></a></li>
  <li><a href="http://www.stichting-ecosafe.org/">The EcoSafe website</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2009/09/16/www.stichting-ecosafe.org/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Separate development/production environments for WordPress</title>
		<link>http://blog.bigsmoke.us/2008/07/12/separate-development-environment-for-wordpress</link>
		<comments>http://blog.bigsmoke.us/2008/07/12/separate-development-environment-for-wordpress#comments</comments>
		<pubDate>Sat, 12 Jul 2008 00:10:32 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/?p=94</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re out Googling on how to maintain a separate development environment for a WordPress installation, you will only stumble across information about how to install all kinds of WAMPP packages. Well, I don&#8217;t care about WAMP (or WAMPP). I want to be able to edit my theme, change my plugins, mess with my database locally and then deploy my changes when they&#8217;re ready and well-tested (as if I ever&#8230;)</p>

<p>Rails was the obvious inspiration for how to do this properly. In Rails, the whole development and deployment process is very intuitive and powerful. In WordPress documentation I never even see the awareness of the need for this separation. They usually tell you to download stuff, upload it and muck about with it on the <em>life</em> production server. But, I&#8217;m not the <em>mucking-about-in-live-configurations</em> type. I&#8217;m the <em>I-fucked-this-up-so-often-I-want-a-staging-area</em> type. This post is about how I managed to fulfill this wish with WordPress.</p>

<h2>Changing the environment</h2>

<p>The first thing I had to do was to find some way to decide which environment to go into. For some reason I decided to use Apache&#8217;s mod_rewrite to set an environment variable based on the HTTP <tt>Host</tt> header. This is in fact very illogical, but we&#8217;ll get to that later.</p>

<pre class="apache">&lt;IfModule mod_rewrite.c&gt;
<span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteCond</span> %<span style="color: #66cc66;">&#123;</span>HTTP_HOST<span style="color: #66cc66;">&#125;</span> =bsblog <span style="color: #66cc66;">&#91;</span>OR<span style="color: #66cc66;">&#93;</span>
<span style="color: #00007f;">RewriteCond</span> %<span style="color: #66cc66;">&#123;</span>HTTP_HOST<span style="color: #66cc66;">&#125;</span> =bsblog.molensteen
<span style="color: #00007f;">RewriteRule</span> . - <span style="color: #66cc66;">&#91;</span>env=WP_ENV:development<span style="color: #66cc66;">&#93;</span>
<span style="color: #00007f;">RewriteCond</span> %<span style="color: #66cc66;">&#123;</span>HTTP_HOST<span style="color: #66cc66;">&#125;</span> =blog.bigsmoke.us
<span style="color: #00007f;">RewriteRule</span> . - <span style="color: #66cc66;">&#91;</span>env=WP_ENV:production<span style="color: #66cc66;">&#93;</span>
&lt;/IfModule&gt;
&nbsp;
<span style="color: #adadad; font-style: italic;"># Keep out of WP's own block of rewrite rules below</span>
<span style="color: #adadad; font-style: italic;"># BEGIN WordPress </span></pre>

<p><q><tt>. -</tt></q> looks like a needle because it&#8217;s voodoo. The dot says I match anything and the dash says I change nothing of what I match. I do set an environment variable to whether I want to be in development or in production.</p>

<p>So I now have an Apache environment variable available for querying from within PHP (as if PHP doesn&#8217;t have a <tt>$_SERVER['HTTP_HOST']</tt> variable:-? ) and I can make use of that in my <tt>wp-config.php</tt>.</p>

<h2>Multiple configurations in one file</h2>

<p>I love configuration files that share the program&#8217;s language; <tt>wp-config.php</tt> being simple PHP code is what make this whole thing so easy:</p>

<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <a href="http://www.php.net/getenv"><span style="color: #000066;">getenv</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'WP_ENV'</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">'production'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #808080; font-style: italic;">// ** MySQL settings ** //</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'DB_NAME'</span>, <span style="color: #ff0000;">'blog'</span><span style="color: #66cc66;">&#41;</span>;             <span style="color: #808080; font-style: italic;">// The name of the database</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'DB_USER'</span>, <span style="color: #ff0000;">'wordpress'</span><span style="color: #66cc66;">&#41;</span>;        <span style="color: #808080; font-style: italic;">// Your MySQL username</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'DB_PASSWORD'</span>, <span style="color: #ff0000;">'[my password]'</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// ...and password</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'DB_HOST'</span>, <span style="color: #ff0000;">'bigsmoke.db'</span><span style="color: #66cc66;">&#41;</span>;        <span style="color: #808080; font-style: italic;">// 99% chance you won't need to change this value</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'WP_SITEURL'</span>, <span style="color: #ff0000;">'http://blog.bigsmoke.us'</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">elseif</span> <span style="color: #66cc66;">&#40;</span> <a href="http://www.php.net/getenv"><span style="color: #000066;">getenv</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'WP_ENV'</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #ff0000;">'development'</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #808080; font-style: italic;">// ** MySQL settings ** //</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'DB_NAME'</span>, <span style="color: #ff0000;">'bsblog'</span><span style="color: #66cc66;">&#41;</span>;          <span style="color: #808080; font-style: italic;">// The name of the database</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'DB_USER'</span>, <span style="color: #ff0000;">'root'</span><span style="color: #66cc66;">&#41;</span>;            <span style="color: #808080; font-style: italic;">// Your MySQL username</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'DB_PASSWORD'</span>, <span style="color: #ff0000;">'[my password]'</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// ...and password</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'DB_HOST'</span>, <span style="color: #ff0000;">'127.0.0.1'</span><span style="color: #66cc66;">&#41;</span>;       <span style="color: #808080; font-style: italic;">// 99% chance you won't need to change this value</span>
  <a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'WP_SITEURL'</span>, <span style="color: #ff0000;">'http://bsblog'</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #808080; font-style: italic;">//define('WP_DEBUG', true);</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<a href="http://www.php.net/define"><span style="color: #000066;">define</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'WP_HOME'</span>, WP_SITEURL<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// You can have multiple installations in one database if you give each a unique prefix</span>
<span style="color: #0000ff;">$table_prefix</span>  = <span style="color: #ff0000;">'wp_'</span>;   <span style="color: #808080; font-style: italic;">// Only numbers, letters, and underscores please!</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// The rest of the stuff in this config file just isn't interesting</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre>

<p>There&#8217;s a few things to note here. You have to use <tt>getenv()</tt> or <tt>$_SERVER</tt> instead of <tt>$_ENV</tt> because variables set by Apache end up in the former two. Another thing to note is that I should have just checked <tt>$_SERVER['HTTP_HOST']</tt> instead of resorting to mod_rewrite voodoo. For the rest it&#8217;s all very straight-forward: I make some database settings depend on which environment I&#8217;m in and I set the URL accordingly.</p>

<h2>Development URLs</h2>

<p>I had some trouble putting the pieces back together when newer WordPress versions started doing automatic redirects for URL that didn&#8217;t match <tt>siteurl</tt> in the <tt>wp_options</tt>. This change meant that when going to <tt>http://bsblog/</tt> (the development URL for this weblog) for example, I&#8217;d inevitably end up at <tt>http://blog.bigsmoke.us/</tt>.</p>

<p>Links had always been constructed according to this setting, so I had already been planning a plug-in to transform production URLs to development URLs. But, I learned (a little late) that this is completely unnecessary since <a href="http://codex.wordpress.org/Editing_wp-config.php"><tt>wp-config.php</tt> supports the configuration of a base URL</a>. I had wrongly assumed that settings that weren&#8217;t in the sample config file, simply didn&#8217;t exist.</p>

<p>Thus, after adding <tt>WP_SITEURL</tt> and <tt>WP_SITEHOME</tt> to <tt>wp-config.php</tt>, everything was working.</p>

<h2>Ideas to further enhance your configuration</h2>

<ul>
  <li>Don&#8217;t limit yourself to one development environment if you have more than one development server.</li>
  <li>Automate your deployment process. I use rsync for this.</li>
  <li>Write a script to clone your production database to your development database. There&#8217;s no substitute for actual data.</li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2008/07/12/separate-development-environment-for-wordpress/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Native PostgreSQL authentication in Rails with rails-psql-auth</title>
		<link>http://blog.bigsmoke.us/2007/07/16/rails-psql-auth</link>
		<comments>http://blog.bigsmoke.us/2007/07/16/rails-psql-auth#comments</comments>
		<pubDate>Mon, 16 Jul 2007 13:58:13 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/2007/07/16/rails-psql-auth</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>A while ago, I wrote a <a href="http://rubyforge.org/projects/rails-psql-auth/">PostgreSQL auth</a> plugin for <a href="http://www.rubyonrails.org/">Rails</a>. The plugin basically defers all authentication and authorization worries to the database layer where they are supposed to be taken care of anyway.</p>

<p>Using this plugin, the user is asked for his or her credentials using a HTTP Basic authentication challenge. (The code for this is adapted from <a href="http://www.codahale.com/">Coda Hale</a>&#8216;s <a href="http://blog.codahale.com/2006/05/11/basic-http-authentication-with-rails-simple_http_auth/">Basic HTTP authentication plugin</a>.) It&#8217;s possible to specify a <tt>guest_username</tt> in the <tt>database.yml</tt> which will be used as a fall-back if no credentials are supplied. After successful login or if a guest user is found, the plugin will make sure that all database operations run as that user. If any operation fails due to insufficient user rights, the user will be prompted for a username/password pair again.</p>

<p>Detailed and up-to-date documentation for the plugin can always be found at the plugin&#8217;s <a href="http://rails-psql-auth.rubyforge.org/">homepage</a>. Go to the plugin&#8217;s <a href="http://rubyforge.org/projects/rails-psql-auth/">project page</a> for getting help or for reporting issues with the plugin.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2007/07/16/rails-psql-auth/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache&#8217;s ForceType directive overrides AddCharset directives</title>
		<link>http://blog.bigsmoke.us/2007/02/26/apache-forcetype-overrides-addcharset</link>
		<comments>http://blog.bigsmoke.us/2007/02/26/apache-forcetype-overrides-addcharset#comments</comments>
		<pubDate>Mon, 26 Feb 2007 22:30:01 +0000</pubDate>
		<dc:creator>Rowan Rodrik</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[406]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[iso-8859-1]]></category>
		<category><![CDATA[latin1]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Sicirec]]></category>
		<category><![CDATA[utf-8]]></category>
		<category><![CDATA[www.sicirec.org]]></category>

		<guid isPermaLink="false">http://blog.bigsmoke.us/2007/02/26/apache-forcetype-overrides-addcharset</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Yesterday, after uploading a refreshed <a href="http://www.sicirec.org/">www.sicirec.org</a>, some character encoding issues popped up because I had converted the website&#8217;s content from ISO-8859-1 (Latin 1) to UTF-8. (I wanted to be able to type and paste special characters from PuTTY into VIM without worrying about the particular encoding of each file.)</p>

<p>The Apache HTTPD at <a href="http://www.initfour.nl/">InitFour</a>, our webhosting provider, is configured to send ISO-8859-1 by default, while the one on our test server is configured for UTF-8. This caused a little bit of a surprise when I uploaded the refreshed website and saw all characters outside the ASCII range mangled on the life website!</p>

<p>I quickly dug into my <tt>.htaccess</tt> file to add the <tt><a href="http://httpd.apache.org/docs/1.3/mod/mod_mime.html#addcharset">AddCharset</a> utf-8 .xhtml</tt> directive. To my surprise, this didn&#8217;t do squat. A lot of fiddling, reloading and researching later, I realized that the following section in my <tt>.htaccess</tt> file rendered the <tt><a href="http://httpd.apache.org/docs/1.3/mod/mod_mime.html#addcharset">AddCharset</a></tt> directive irrelevant:</p>

<pre class="php">&lt;Files *.xhtml&gt;
ForceType text/html
&lt;/Files&gt;</pre>

<p>I had to change the <tt><a href="http://httpd.apache.org/docs/1.3/mod/mod_mime.html#forcetype">ForceType</a></tt> directive to include the charset as a MIME parameter:</p>

<pre class="php">&lt;Files *.xhtml&gt;
ForceType <span style="color: #ff0000;">'text/html; charset=UTF-8'</span>
&lt;/Files&gt;</pre>

<p>Now, it all <em>seemed</em> to work. (Except that it didn&#8217;t really because I do some ridiculously complex content negotiation stuff involving a 406 handler in PHP that <a href="http://www.php.net/virtual"><tt>virtual</tt></a>s the most appropriate variant when no match is found. This script didn&#8217;t send a useful <tt>Content-Type</tt> header. After first adding it to the script, I noticed that the <tt><a href="http://httpd.apache.org/docs/1.3/mod/core.html#adddefaultcharset">AddDefaultCharset</a></tt> is actually allowed in <tt>.htaccess</tt> context&#8212;a discovery which luckily rendered the other hacks useless.)</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bigsmoke.us/2007/02/26/apache-forcetype-overrides-addcharset/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
