<?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>Fireside Media Development Blog &#187; Code</title>
	<atom:link href="http://www.firesidemedia.net/dev/topic/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.firesidemedia.net/dev</link>
	<description></description>
	<lastBuildDate>Mon, 24 Aug 2009 23:23:41 +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>IIS Fails with Multiple Referers, but not Referrers</title>
		<link>http://www.firesidemedia.net/dev/iis-fails-with-multiple-referers-but-not-referrers/</link>
		<comments>http://www.firesidemedia.net/dev/iis-fails-with-multiple-referers-but-not-referrers/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 23:09:46 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.firesidemedia.net/dev/?p=121</guid>
		<description><![CDATA[This is something I came across today when we launched a new section for a website. It&#8217;s something I&#8217;ve never encountered before, and I ended up spending most of my afternoon debugging what was causing our issue. Let me begin by saying the correct spelling of Referrer does have two r&#8217;s, however it is misspelled [...]]]></description>
			<content:encoded><![CDATA[<p>This is something I came across today when we launched a new section for a website. It&#8217;s something I&#8217;ve never encountered before, and I ended up spending most of my afternoon debugging what was causing our issue. Let me begin by saying the correct spelling of Referrer <strong>does</strong> have two r&#8217;s, however it is misspelled in the <a href="http://tools.ietf.org/html/rfc2616#section-14.36">HTTP Specification</a>. To the end user, this should mean nothing as most software that uses the HTTP Spec uses the incorrect spelling, as it&#8217;s what was defined in the spec.</p>
<p>When we launched the site, we checked it out in all our normal browsers and everything was good. Then we fired up IE 6 (unfortunately the client in question needs IE 6 support), navigated to the new secti-OH CRAP! The page itself would load, but <strong>none </strong>of the external assets (images, stylesheets and scripts) were loading. Refresh the page and bingo! it works fine! What the heck is going on?!</p>
<p>It turns out IE 6 was sending not one, but two referers to the web server. While it&#8217;s odd to have 2 referers, it shouldn&#8217;t cause 4xx Errors when sending a request. From this, we were able to find out a few things:</p>
<ol>
<li>IIS accepts both Referer <em>and</em> Refer<strong>r</strong>er as valid HTTP headers.</li>
<li>IIS <em>will not</em> accept more than one Referer.</li>
<li>IIS <em>will</em> accept more than one Referrer (note this is the dictionary spelling of referrer, not the spec spelling).</li>
<li>IE 6 will add 2 referrers if the link you clicked is located inside of a Flash element for all external assets: the URI to the Flash file and the URI of the page you are on.</li>
</ol>
<p><span id="more-121"></span><br />
I&#8217;m not quite sure why IE 6 behaves the way it does, but the fact is that it does and it was causing IIS to give us 400 Bad Request responses. Think I&#8217;m crazy (and maybe I am, please prove me wrong)? Try sending this request to www.microsoft.com:</p>
<pre>HEAD / HTTP/1.1
Host: www.microsoft.com
Referer: http://google.com
Referer: http://yahoo.com
Connection: Close</pre>
<p>In response you should get something similar to:</p>
<pre>HTTP/1.1 400 Bad Request
Content-Length: 339
Content-Type: text/html; charset=us-ascii
Server: Microsoft-HTTPAPI/2.0
Date: Mon, 24 Aug 2009 22:53:04 GMT
Connection: close</pre>
<p>Now send the <em>exact same request</em> to, say, www.apple.com:</p>
<pre>HEAD / HTTP/1.1
Host: www.apple.com
Referer: http://google.com
Referer: http://yahoo.com
Connection: Close</pre>
<p>and you get:</p>
<pre>HTTP/1.1 200 OK
Age: 255
X-Cache-TTL: 345
Accept-Ranges: bytes
Date: Mon, 24 Aug 2009 22:48:41 GMT
Content-Length: 9542
Content-Type: text/html; charset=utf-8
Expires: Mon, 24 Aug 2009 22:58:41 GMT
Cache-Control: max-age=600
Server: Apache/2.2.8 (Unix)
X-Cached-Time: Mon, 24 Aug 2009 22:50:56 GMT</pre>
<p>And now, to prove point #3, send the following request to www.microsoft.com (note the change in spellings):</p>
<pre>HEAD / HTTP/1.1
Host: www.microsoft.com
Referrer: http://google.com
Referrer: http://yahoo.com
Connection: Close</pre>
<p>and you get</p>
<pre>HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 1020
Content-Type: text/html
Last-Modified: Mon, 16 Mar 2009 20:35:26 GMT
Accept-Ranges: bytes
ETag: "67991fbd76a6c91:0"
Server: Microsoft-IIS/7.0
P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
X-Powered-By: ASP.NET
Date: Mon, 24 Aug 2009 23:09:03 GMT</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.firesidemedia.net/dev/iis-fails-with-multiple-referers-but-not-referrers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Show Only Children Pages on Parent Page</title>
		<link>http://www.firesidemedia.net/dev/show-only-children-pages-on-parent-page/</link>
		<comments>http://www.firesidemedia.net/dev/show-only-children-pages-on-parent-page/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 22:54:32 +0000</pubDate>
		<dc:creator>Jonathan Dingman</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.firesidemedia.net/dev/?p=113</guid>
		<description><![CDATA[There is still much to be desired within WordPress when it comes to dealing with parent and children pages. The core code is there, and it&#8217;s usable, but there&#8217;s not a lot &#8220;out of the box&#8221; to play with. We&#8217;ve developed a bit of code to help make your life a little easier. Adding the [...]]]></description>
			<content:encoded><![CDATA[<p>There is still much to be desired within WordPress when it comes to dealing with parent and children pages.  The core code is there, and it&#8217;s usable, but there&#8217;s not a lot &#8220;out of the box&#8221; to play with.</p>
<p><strong>We&#8217;ve developed a bit of code to help make your life a little easier.</strong></p>
<p>Adding the code below to your functions.php file will let you remove the other children pages while on the parent page.</p>
<pre class="brush: php;">add_filter('wp_list_pages_excludes', 'remove_others_children');
function remove_others_children($excludes = array()) {
  $all_pages = get_pages();
  $all_children = (array) get_page_children(true, $all_pages);
  foreach ( $all_children as $child )
    $excludes[] = $child-&gt;ID;

  if ( ! is_page() )
    return $excludes;

  global $post;

  $this_heirarchy = (array) $post-&gt;ancestors;
  $this_children = (array) get_page_children($post-&gt;ID, $all_pages);
  foreach ( $this_heirarchy as $ancestor )
    $this_children = array_merge($this_children, (array) get_page_children($ancestor, $all_pages));

  foreach ($this_children as $child)
    $this_heirarchy[] = $child-&gt;ID;

  return array_diff($excludes, $this_heirarchy);
}</pre>
<p>Here are some examples of what it would like without the code, then with the code.</p>
<p><img src="http://www.firesidemedia.net/dev/files/wordpress-remove-children-from-parents-pages.jpg" alt="WordPress:  Remove Children Pages from Parent Pages" title="WordPress:  Remove Children Pages from Parent Pages" width="491" height="474" class="size-full wp-image-115" /></p>
<p>A huge thanks goes out to <a href="http://sivel.net/">Matt Martz</a> for working with us on helping get this code ready.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firesidemedia.net/dev/show-only-children-pages-on-parent-page/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The Power of XSL</title>
		<link>http://www.firesidemedia.net/dev/the-power-of-xsl/</link>
		<comments>http://www.firesidemedia.net/dev/the-power-of-xsl/#comments</comments>
		<pubDate>Fri, 22 Feb 2008 20:47:53 +0000</pubDate>
		<dc:creator>James</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.firesidemedia.net/dev/the-power-of-xsl/</guid>
		<description><![CDATA[When we did the last rewrite of Christian Lyrics I spent a good bit of time working on the template system. I loathe Smarty due to how bloated it is, but almost went with it because needed modular caching (guests all see the same static files, logged in users see their user info, etc&#8230;). We [...]]]></description>
			<content:encoded><![CDATA[<p>When we did the last rewrite of <a href="http://www.christian-lyrics.net/" rel="external" title="Christian Music Lyrics">Christian Lyrics</a> I spent a good bit of time working on the template system. I loathe <a href="http://smarty.php.net" title="Smarty Templating Engine" rel="external">Smarty</a> due to how bloated it is, but almost went with it because needed modular caching (guests all see the same static files, logged in users see their user info, etc&#8230;). We ended up using a <a href="http://phpsavant.com" title="PHP Savant" rel="external">Savant</a> style system (no stupid custom tags, no parsing, just PHP) that works pretty well, but has some short comings still. After we finished the rewrite, I spent some time exploring other options. Only one caught my eye: <a href="http://www.w3.org/TR/xsl" title="Extensible Stylesheet Language" rel="external">XSL</a>.</p>
<blockquote><p>The eXtensible Stylesheet Language (XSL) is a family of transformation languages which allows one to describe how files encoded in the XML standard are to be formatted or transformed. XSL is designed to be data driven and strongly encourages the Inversion of control design pattern. There are three languages in the family:</p>
<ol>
<li>XSL Transformations (XSLT): an XML language for transforming XML documents</li>
<li>XSL Formatting Objects (XSL-FO): an XML language for specifying the visual formatting of an XML document</li>
<li>the XML Path Language (XPath): a non-XML language used by XSLT, and also available for use in non-XSLT contexts, for addressing the parts of an XML document.</li>
</ol>
<p><cite>Source: <a href="http://en.wikipedia.org/wiki/Extensible_Stylesheet_Language" rel="external nofollow">Wikipedia</a></cite></p></blockquote>
<p>In a nutshell, XSL can be used to transform a plain XML document into a full-fledged HTML document. One thing I really like about XSL is that the processing can be done either server-side or client-side. Most modern browsers understand XSL and do all the dirty work for you, leaving your server to do other, more important, things. Not only that, but if you send the XML to the client for processing, then you have the base of your API already done.</p>
<p>But the best part is how modular you can make the caching. Here&#8217;s how I do it:</p>
<ol>
<li>If the data is cacheable it gets saved to disk in an XML file. Queries are only done to the SQL server for this data if the cache file doesn&#8217;t exist or has expired.</li>
<li>If it&#8217;s not cacheable, insert it into the cached XML document on the fly.</li>
</ol>
<p>Then the XSL document handles the rest. I can&#8217;t think of any simpler way to do it.</p>
<p>However, there are downsides (when aren&#8217;t there?):</p>
<ul>
<li>IE has notoriously bad support for XSL (of course).</li>
<li>PHP has <a href="http://www.php.net/xsl" title="PHP:XSL" rel="external">XSL support natively in PHP5</a>, but PHP4 requires a <a href="http://www.php.net/xslt">PECL library</a> (I can&#8217;t find the extension on PECL for some reason).</li>
<li>More syntax to remember</li>
<li>The only good documentation I&#8217;ve come across is the specification itself. <a href="http://www.w3schools.com/xsl/" title="W3 Schools XSLT Tutorial" rel="external">W3Schools</a>, which usually has a pretty decent overview, I found lacking.</li>
<li><span style="font-weight: bold; font-style: italic">Most</span> variable processing has to be done before you transform the XML. It is possible to use variables in the XSL itself, but it is very limited.</li>
<li>Javascript does not work on the XML document itself, just the generated source. This means if you use AJAX to grab eg. a list of languages, you have to either do the transformation server-side or in the Javascript itself. Thankfully, Google has an excellent <a href="http://code.google.com/p/ajaxslt/" rel="external" title="AJAXSLT">Javascript library to do XSL transformations</a>! Some browsers (Mozilla is one I believe) also have built-in XSLT support in Javascript.</li>
<li>Unless you do the transformation on the server-side <span style="font-weight: bold">search engine crawlers will not be able to index your site</span>. Of course you could set it up to only transform server-side if a crawler comes.</li>
</ul>
<p>Now I ask: why don&#8217;t more sites use XSL? I know I&#8217;ll be building most of my sites in the future with XSL, the benefits far outweigh the downsides in my opinion.</p>
<p><span style="font-weight: bold">Update:</span> I completely forgot to mention a <span style="font-style: italic">very important</span> downside. I bolded it in the list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firesidemedia.net/dev/the-power-of-xsl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
