<?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>jakobloekkemadsen.com &#187; Code</title>
	<atom:link href="http://www.jakobloekkemadsen.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jakobloekkemadsen.com</link>
	<description>Usability. Design. Code.</description>
	<lastBuildDate>Thu, 02 Feb 2012 15:06:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How to use Knockout.js with XSLT</title>
		<link>http://www.jakobloekkemadsen.com/2011/11/how-to-use-knockout-js-with-xslt/</link>
		<comments>http://www.jakobloekkemadsen.com/2011/11/how-to-use-knockout-js-with-xslt/#comments</comments>
		<pubDate>Tue, 22 Nov 2011 15:37:37 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[knockout.js]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://www.jakobloekkemadsen.com/?p=246</guid>
		<description><![CDATA[<p>As you may know, <a href="http://knockoutjs.com/">Knockout.js</a> uses inline Javascript for it&#8217;s elegant, declarative bindings:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&#60;</span>li data<span style="color: #339933;">-</span>bind<span style="color: #339933;">=</span><span style="color: #3366CC;">&#34;css: {'active': visible()}&#34;</span><span style="color: #339933;">&#62;&#60;/</span>li<span style="color: #339933;">&#62;</span></pre></div></div>

<p>But if you use XSLT to render your HTML, it may fail because the curly-braces may not be supported&#8230; <a href="http://www.jakobloekkemadsen.com/2011/11/how-to-use-knockout-js-with-xslt/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p>As you may know, <a href="http://knockoutjs.com/">Knockout.js</a> uses inline Javascript for it&#8217;s elegant, declarative bindings:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>li data<span style="color: #339933;">-</span>bind<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;css: {'active': visible()}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span></pre></div></div>

<p>But if you use XSLT to render your HTML, it may fail because the curly-braces may not be supported in attributes.</p>
<p>To make this work, you need to do two things:</p>
<ol>
<li>
Convert the attribute:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">data<span style="color: #339933;">-</span>bind<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;...&quot;</span></pre></div></div>

<p> into an</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>xsl<span style="color: #339933;">:</span>attribute <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;data-bind&quot;</span><span style="color: #339933;">&gt;</span></pre></div></div>

<p>Like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>xsl<span style="color: #339933;">:</span>attribute <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;data-bind&quot;</span><span style="color: #339933;">&gt;</span>
  css<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'active'</span><span style="color: #339933;">:</span> visible<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>
 <span style="color: #339933;">&lt;/</span>xsl<span style="color: #339933;">:</span>attribute<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span></pre></div></div>

</li>
<li>Do a search and replace exchanging the curly braces with XML-safe entities:

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">	<span style="color: #3366CC;">&quot;{&quot;</span> to <span style="color: #3366CC;">&quot;&amp;#123;&quot;</span>
	<span style="color: #3366CC;">&quot;}&quot;</span> to <span style="color: #3366CC;">&quot;&amp;#125&quot;</span></pre></div></div>

<p>	So the final XSLT should look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>xsl<span style="color: #339933;">:</span>attribute <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;data-bind&quot;</span><span style="color: #339933;">&gt;</span>
  css<span style="color: #339933;">:</span> <span style="color: #339933;">&amp;</span>#<span style="color: #CC0000;">125</span><span style="color: #3366CC;">'active'</span><span style="color: #339933;">:</span> visible<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;</span>#<span style="color: #CC0000;">125</span>
 <span style="color: #339933;">&lt;/</span>xsl<span style="color: #339933;">:</span>attribute<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span></pre></div></div>

<p>&nbsp;</li>
</ol>
<p>Ugly, I know! But now it will work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakobloekkemadsen.com/2011/11/how-to-use-knockout-js-with-xslt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharepoint error message of the day</title>
		<link>http://www.jakobloekkemadsen.com/2011/10/sharepoint-error-message-of-the-day/</link>
		<comments>http://www.jakobloekkemadsen.com/2011/10/sharepoint-error-message-of-the-day/#comments</comments>
		<pubDate>Mon, 24 Oct 2011 12:48:09 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[fail]]></category>

		<guid isPermaLink="false">http://www.jakobloekkemadsen.com/?p=241</guid>
		<description><![CDATA[<p>Trusty ol&#8217; Microsoft Sharepoint &#8230;<br />
King of sensical error messages:</p>
<p><a href="http://www.jakobloekkemadsen.com/wp-content/uploads/2011/10/error.jpg"><img class="alignnone size-full wp-image-242" title="error" src="http://www.jakobloekkemadsen.com/wp-content/uploads/2011/10/error.jpg" alt="" width="616" height="295" /></a></p>
]]></description>
			<content:encoded><![CDATA[<p>Trusty ol&#8217; Microsoft Sharepoint &#8230;<br />
King of sensical error messages:</p>
<p><a href="http://www.jakobloekkemadsen.com/wp-content/uploads/2011/10/error.jpg"><img class="alignnone size-full wp-image-242" title="error" src="http://www.jakobloekkemadsen.com/wp-content/uploads/2011/10/error.jpg" alt="" width="616" height="295" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakobloekkemadsen.com/2011/10/sharepoint-error-message-of-the-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to empty a Javascript array</title>
		<link>http://www.jakobloekkemadsen.com/2011/02/how-to-empty-a-javascript-array/</link>
		<comments>http://www.jakobloekkemadsen.com/2011/02/how-to-empty-a-javascript-array/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 15:11:59 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.jakobloekkemadsen.com/?p=197</guid>
		<description><![CDATA[<p>It&#8217;s easy:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">MyArray.length = 0;</pre></div></div>

<p>(Just a reminder to myself, since I&#8217;ve forgotten about this a few times &#8230;)</p>
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s easy:</p>

<div class="wp_syntax"><div class="code"><pre class="js" style="font-family:monospace;">MyArray.length = 0;</pre></div></div>

<p>(Just a reminder to myself, since I&#8217;ve forgotten about this a few times &#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakobloekkemadsen.com/2011/02/how-to-empty-a-javascript-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to make CSS3PIE work</title>
		<link>http://www.jakobloekkemadsen.com/2010/10/how-to-make-css3pie-work/</link>
		<comments>http://www.jakobloekkemadsen.com/2010/10/how-to-make-css3pie-work/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 19:16:45 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[Frontend development]]></category>
		<category><![CDATA[htc]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[IE7]]></category>
		<category><![CDATA[IE8]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.jakobloekkemadsen.com/?p=172</guid>
		<description><![CDATA[<p><a href="http://css3pie.com" target="_blank"><img class="alignnone" title="CSS3pie" src="http://css3pie.com/wp/wp-content/themes/pie-wp-theme/img/logo.png" alt="CSS3pie" width="194" height="127" /></a></p>
<p>Countless hours have been lost creating rounded corners, dropshadows and gradient backgrounds for the web.<br />
With Internet Explorer still lacking support for CSS3, until recently it seemed like we would have to keep doing tiny graphic sprites (or&#8230; <a href="http://www.jakobloekkemadsen.com/2010/10/how-to-make-css3pie-work/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://css3pie.com" target="_blank"><img class="alignnone" title="CSS3pie" src="http://css3pie.com/wp/wp-content/themes/pie-wp-theme/img/logo.png" alt="CSS3pie" width="194" height="127" /></a></p>
<p>Countless hours have been lost creating rounded corners, dropshadows and gradient backgrounds for the web.<br />
With Internet Explorer still lacking support for CSS3, until recently it seemed like we would have to keep doing tiny graphic sprites (or implementing dirty javascripts) in order to accomodate the demand for such UI niceness.</p>
<p>Enter: <a href="http://css3pie.com/" target="_blank">http://css3pie.com/</a><br />
PIE is a .htc CSS behaviour script that enables support for dropshadows, rounded corners and background gradient CSS3 properties in Internet Explorer &#8211; all the way back to IE6!</p>
<p>Of course, I couldn&#8217;t wait to try it out.<br />
And it didn&#8217;t work.<br />
Bummer &#8230;</p>
<p>Fortunately, I found out why:<br />
It only works on positioned elements.</p>
<p><strong>You must specify &#8220;position: relative;&#8221; or &#8220;position: absolute;&#8221; on the element that calls the .htc behaviour, and then it works!</strong></p>
<p>Amazing script!<br />
CSS3 future is here now.<br />
Thank you so much, Jason Johnston of <a href="http://327creative.com/" target="_blank">327 Creative LLC</a>, for sharing this little goodie with the world!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakobloekkemadsen.com/2010/10/how-to-make-css3pie-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful PHP libraries, part 2 &#8211; Scaffold CSS</title>
		<link>http://www.jakobloekkemadsen.com/2010/02/useful-php-libraries-part-2-scaffold-css/</link>
		<comments>http://www.jakobloekkemadsen.com/2010/02/useful-php-libraries-part-2-scaffold-css/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 16:52:24 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[productivity]]></category>

		<guid isPermaLink="false">http://www.jakobloekkemadsen.com/?p=150</guid>
		<description><![CDATA[<p><a href="http://wiki.github.com/anthonyshort/csscaffold/" target="_blank">Scaffold CSS</a> was developed by <a href="http://anthonyshort.com.au/" target="_blank">Anthony Short</a> and it is &#8211; basically &#8211; every CSS-coder’s dream come true:</p>
<p>Variables, nested selectors, abstractions from vendor-specific properties etc. etc. etc. Good stuff!</p>
<p>Installation and usage couldn’t be simpler! (Really. I&#8230; <a href="http://www.jakobloekkemadsen.com/2010/02/useful-php-libraries-part-2-scaffold-css/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://wiki.github.com/anthonyshort/csscaffold/" target="_blank">Scaffold CSS</a> was developed by <a href="http://anthonyshort.com.au/" target="_blank">Anthony Short</a> and it is &#8211; basically &#8211; every CSS-coder’s dream come true:</p>
<p>Variables, nested selectors, abstractions from vendor-specific properties etc. etc. etc. Good stuff!</p>
<p>Installation and usage couldn’t be simpler! (Really. I don’t see how it could!)<br />
You place the library folder in whatever folder holds you CSS-files. Then you copy-paste the .htaccess-file that redirects every request for your CSS-files to the library. Scaffold then reads through your CSS and interprets whatever tricks you’ve written and serves up nicely formatted (or minifed, if you prefer) W3C-compliant CSS.</p>
<p>”What’s this good for?”, you say?</p>
<p>Well. Consider this piece of regular CSS:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#arrival_date</span><span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#departure_date</span><span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#persons</span><span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#location</span>
<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">18px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">white</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#arrival_date</span> label<span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#departure_date</span> label<span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#persons</span> label<span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#location</span> label
<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#arrival_date</span> input<span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#departure_date</span> input<span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#persons</span> input<span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#location</span> input
<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">18px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">180px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">40px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
-moz-box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span>
-webkit-box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span>
-ms-box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span>
box-sizing<span style="color: #00AA00;">:</span> border-box<span style="color: #00AA00;">;</span>
behavior<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">&quot;boxsizing.htc&quot;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #cc00cc;">#arrival_date</span> .popupcalendar_icon<span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span>  <span style="color: #cc00cc;">#departure_date</span> .popupcalendar_icon<span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span>  <span style="color: #cc00cc;">#persons</span> .popupcalendar_icon<span style="color: #00AA00;">,</span>
form<span style="color: #cc00cc;">#searchbox</span>  <span style="color: #cc00cc;">#location</span> <span style="color: #6666ff;">.popupcalendar_icon</span>
<span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">./graphics/images/sprites.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</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;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">295px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">314px</span><span style="color: #00AA00;">;</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;">text-indent</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-9999px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-271px</span> <span style="color: #933;">-20px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">39px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">31px</span><span style="color: #00AA00;">;</span>
zoom<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> -moz-inline-box<span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Even though it’s nicely ordered and very readable, this code is still quite hard to understand at first look. You can&#8217;t just read what&#8217;s going on. What&#8217;s related to what? You need to look back and forth a few times to see this.<br />
This makes it bad code!<br />
<a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882" target="_blank" title="Clean Code - book on amazon">Good code is always easy to read and understand.</a></p>
<p>Now look at the same code in Scaffold syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@constants {</span>
   labelTextColor<span style="color: #00AA00;">:</span> <span style="color: #993333;">white</span><span style="color: #00AA00;">;</span>
   gutter<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
form<span style="color: #cc00cc;">#searchbox</span> <span style="color: #00AA00;">&#123;</span>
&nbsp;
   <span style="color: #cc00cc;">#arrival_date</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#departure_date</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#persons</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#location</span>  <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">18px</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> !labelTextColor<span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> #<span style="color: #00AA00;">&#91;</span><span style="color: #cc66cc;">2</span> <span style="color: #00AA00;">*</span> !gutter<span style="color: #00AA00;">&#93;</span><span style="color: #993333;">px</span><span style="color: #00AA00;">;</span>
&nbsp;
      label <span style="color: #00AA00;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> #<span style="color: #00AA00;">&#91;</span><span style="color: #cc66cc;">10</span> <span style="color: #00AA00;">*</span> !gutter<span style="color: #00AA00;">&#93;</span><span style="color: #993333;">px</span><span style="color: #00AA00;">;</span>
         <span style="color: #00AA00;">+</span>inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
      <span style="color: #00AA00;">&#125;</span>
&nbsp;
      input <span style="color: #00AA00;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">18px</span><span style="color: #00AA00;">;</span>
         <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">180px</span><span style="color: #00AA00;">;</span>
         <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> #<span style="color: #00AA00;">&#91;</span><span style="color: #cc66cc;">4</span> <span style="color: #00AA00;">*</span> !gutter<span style="color: #00AA00;">&#93;</span><span style="color: #993333;">px</span><span style="color: #00AA00;">;</span>
         <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> #<span style="color: #00AA00;">&#91;</span><span style="color: #cc66cc;">1</span> <span style="color: #00AA00;">*</span> !gutter<span style="color: #00AA00;">&#93;</span><span style="color: #993333;">px</span><span style="color: #00AA00;">;</span>
         <span style="color: #00AA00;">+</span>border-box<span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
      <span style="color: #00AA00;">&#125;</span>
&nbsp;
      <span style="color: #6666ff;">.popupcalendar_icon</span> <span style="color: #00AA00;">&#123;</span>
         image-replace<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'./graphics/images/sprites.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
         <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-271px</span> <span style="color: #933;">-20px</span><span style="color: #00AA00;">;</span>
         <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">39px</span><span style="color: #00AA00;">;</span>
         <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">31px</span><span style="color: #00AA00;">;</span>
         <span style="color: #00AA00;">+</span>inline-<span style="color: #993333;">block</span><span style="color: #00AA00;">&#40;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
         <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #933;">0px</span> <span style="color: #933;">0px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
      <span style="color: #00AA00;">&#125;</span>
   <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The nesting immedietaly makes the code easy to read!<br />
The selectors come in a logical order. The code is scannable, and in my opinion this is quite a revolution as far as CSS goes!</p>
<p>And it gets even better!</p>
<p>As you may have noticed, my second code example is full of non-CSS properties.<br />
These are Scaffold-specific functions, constants and ”mixins”.</p>
<p>For example: A standard gutter width of 10px is defined as a constant, then used throughout the style declarations by reference.<br />
No more search-and-replace for simple color changes!<br />
This feature alone will save me countless hours.</p>
<p>Then there’s stuff like ”+inline-block();” or ”+border-box();”. These are ”mixins” that basically call a set of CSS properties that take care of crossbrowser compatibility. Scaffold serves up vendor-specific properties and even a selection of IE-behaviors, filters and expressions to get the desired effect working all around. Now we have a one line trick that’ll fix box model-quirks or get inline-blocks behave like expected. (Or rotation, shadows and other CSS3-goodies for that matter). This means more time for coffee, which is nice!</p>
<p>Finally we have functions like ”image-replace: url(&#8216;./graphics/images/sprites.png&#8217;);”<br />
This line takes care of everything regarding CSS image replacement. It even automatically sets the correct height and width fitting the specified image file.</p>
<p>The library has tons of useful features and some pretty advanced ones too. Everything is cached, so it&#8217;s just as fast as regular CSS. </p>
<p>So if you’re lucky enough to have your CSS-files served from an Apache server with PHP enabled, then by all means, do not miss out on Scaffold CSS!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakobloekkemadsen.com/2010/02/useful-php-libraries-part-2-scaffold-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful PHP libraries, part 1 &#8211; SLIR</title>
		<link>http://www.jakobloekkemadsen.com/2010/02/useful-php-libraries-part-1-slir/</link>
		<comments>http://www.jakobloekkemadsen.com/2010/02/useful-php-libraries-part-1-slir/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 19:20:05 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.jakobloekkemadsen.com/?p=115</guid>
		<description><![CDATA[<p><em>In this series of blog posts I introduce my favourite PHP libraries.</em></p>
<p>Today&#8217;s library is:<br />
<strong><a href="http://code.google.com/p/smart-lencioni-image-resizer/">SLIR</a></strong></p>
<p>SLIR – or ”Smart Lencioni Image Resizer” – was developed by <a href="http://shiftingpixel.com/">Joe Lencioni</a>.<br />
It does on-the-fly scaling and cropping of images.</p>
<p>The&#8230; <a href="http://www.jakobloekkemadsen.com/2010/02/useful-php-libraries-part-1-slir/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<p><em>In this series of blog posts I introduce my favourite PHP libraries.</em></p>
<p>Today&#8217;s library is:<br />
<strong><a href="http://code.google.com/p/smart-lencioni-image-resizer/">SLIR</a></strong></p>
<p>SLIR – or ”Smart Lencioni Image Resizer” – was developed by <a href="http://shiftingpixel.com/">Joe Lencioni</a>.<br />
It does on-the-fly scaling and cropping of images.</p>
<p>The benefit is that you can change your image sizes dynamically on request-time.<br />
If your page layout changes, you can just request images with new sizes that fit.</p>
<p>Under the hood it&#8217;s a clever PHP script that returns the content of an image file. Requests are handled by a .htaccess-file that disguises the underlying PHP and presents it to the public as an actual image file.</p>
<p>This means you activate the resizer just by requesting a url with some resize parameters plus the path to the original image file.</p>
<p>Example:</p>
<p>Original image:</p>

<div class="wp_syntax"><div class="code"><pre class="htm" style="font-family:monospace;">&lt;img src=&quot;http://www.jakobloekkemadsen.com/wp-content/uploads/2010/02/DSC_1225_maj-30-2009.jpg&quot; alt=&quot;&quot; /&gt;</pre></div></div>

<p><img src="http://www.jakobloekkemadsen.com/wp-content/uploads/2010/02/DSC_1225_maj-30-2009.jpg" alt="" /></p>
<p>Scaled to fit 100px width:</p>

<div class="wp_syntax"><div class="code"><pre class="htm" style="font-family:monospace;">&lt;img src=&quot;http://www.jakobloekkemadsen.com/slir/w100/wp-content/uploads/2010/02/DSC_1225_maj-30-2009.jpg&quot; alt=&quot;&quot; /&gt;</pre></div></div>

<p><img src="http://www.jakobloekkemadsen.com/slir/w100/wp-content/uploads/2010/02/DSC_1225_maj-30-2009.jpg" alt="" /></p>
<p>Scaled to fit 25px width and cropped to square:</p>

<div class="wp_syntax"><div class="code"><pre class="htm" style="font-family:monospace;">&lt;img src=&quot;http://www.jakobloekkemadsen.com/slir/w25-c1:1/wp-content/uploads/2010/02/DSC_1225_maj-30-2009.jpg&quot; alt=&quot;&quot; /&gt;</pre></div></div>

<p><img src="http://www.jakobloekkemadsen.com/slir/w25-c1:1/wp-content/uploads/2010/02/DSC_1225_maj-30-2009.jpg" alt="" /></p>
<p>”What about performance?”, I hear you ask. &#8220;Won&#8217;t the server choke on having to process all image requests?&#8221;</p>
<p>No, it won&#8217;t. (-:<br />
SLIR caches the image the first time it’s requested, so all subsequent requests are served just as fast as any other image file on the server. The redirect is handled by an alias to the cachefile. Only if no matching cache file exists, or if it’s too old, or if the original has changed, then SLIR is invoked and a new image is generated and cached.</p>
<p>”Ok. But what about security, then?”</p>
<p>In theory this script enables a hacker to flood your server with files just by changing the url and requesting all imaginable combinations of width and height. This issue has been discussed in the comments on <a href="http://shiftingpixel.com/2008/03/03/smart-image-resizer/">http://shiftingpixel.com/2008/03/03/smart-image-resizer/</a> and the current version of the script can be made to restrict access to any other combinations than the ones you specify.</p>
<p>Personally I haven’t found an easier, more futureproof and flexible solution for handling image scaling.<br />
And it&#8217;s free!</p>
<p>Simply put: I love this script!</p>
<p><strong>Stay tuned for part two of &#8220;Useful PHP libraries&#8221;. Coming soon &#8230;</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakobloekkemadsen.com/2010/02/useful-php-libraries-part-1-slir/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to inject dynamic content from PHP into an old and closed source cms.</title>
		<link>http://www.jakobloekkemadsen.com/2009/12/how-to-inject-dynamic-content-from-php-into-an-old-and-closed-source-cms/</link>
		<comments>http://www.jakobloekkemadsen.com/2009/12/how-to-inject-dynamic-content-from-php-into-an-old-and-closed-source-cms/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 10:43:31 +0000</pubDate>
		<dc:creator>Jakob</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[e-commerce]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.jakobloekkemadsen.com/blog/?p=49</guid>
		<description><![CDATA[<h3>The problem</h3>
<p>Recently I was asked by an e-commerce client if I could create a banner on his website that would let visitors know whether the phone hotline of the store is currently open or closed based on store opening&#8230; <a href="http://www.jakobloekkemadsen.com/2009/12/how-to-inject-dynamic-content-from-php-into-an-old-and-closed-source-cms/" class="read_more">Read the rest</a></p>]]></description>
			<content:encoded><![CDATA[<h3>The problem</h3>
<p>Recently I was asked by an e-commerce client if I could create a banner on his website that would let visitors know whether the phone hotline of the store is currently open or closed based on store opening hours.</p>
<p>In a PHP-based CMS the only task involved would have been writing a function outputting some HTML for use in the banner. So this should have been a no-brainer, had it not been for the fact that my client&#8217;s website is run in a proprietary, hosted (and heavily outdated) CMS with no server-side access what so ever!</p>
<p>My first thought was then to make a solution entirely in Javascript. This would be very possible in theory, but since Javascript is a client-side language, it can only know the time and date from the client&#8217;s local settings.</p>
<p>This fact rendered the client-side solution very impractical. What about time-zone differences? What if the clients clock is set wrong? How about daylight savings time? In reality, the client-side solution was not an option.</p>
<p>So what to do?</p>
<h3>The solution</h3>
<p>The only way to go about this problem was then to write a server-side script, run it on a different domain accessing one single source of time and date information (ie. this server&#8217;s own clock) and then inject the output into the client&#8217;s website using the front-end methods available to me.</p>
<p>That way, the information posted would appear correctly across all visitors regardless of their settings and time zone.</p>
<p>Using AJAX was not an option because of the <a href="http://en.wikipedia.org/wiki/Same_origin_policy">Same Origin Policy</a> preventing me to use something like <a href="http://docs.jquery.com/Ajax/load">jQuery&#8217;s load()-function</a>. Also, the fact that the server running the client&#8217;s CMS itself was inaccessible to me ment that no <a href="http://developer.yahoo.com/javascript/howto-proxy.html">proxy-script</a> could be set up to circumvent the restriction.</p>
<p>What struck me, then, was that I had missed the most obvious solution, which was really lo-tech and simple. Embarrasingly simple, actually &#8211; as I had already spent so much time scratching my head and searching the web for a workaround to get this fancy AJAX-thing working &#8230;</p>
<p>First, here&#8217;s the PHP-script to generate the HTML string telling the visitor whether the hotline is open or closed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Content-type: application/x-javascript; charset=UTF-8&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Name of variable to output:</span>
<span style="color: #000088;">$nameOfVariable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;hotline_status&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Strings to output:</span>
<span style="color: #000088;">$open</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;p class='<span style="color: #006699; font-weight: bold;">$nameOfVariable</span>'&gt;The hotline is open!&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$closed</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;p class='<span style="color: #006699; font-weight: bold;">$nameOfVariable</span>'&gt;The hotline is closed!&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Opening hours (in 24-hour clock):</span>
<span style="color: #000088;">$weekday</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
 <span style="color: #0000ff;">'open'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span>
 <span style="color: #0000ff;">'close'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">17</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$saturday</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
 <span style="color: #0000ff;">'open'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span>
 <span style="color: #0000ff;">'close'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">14</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Time zone adjustment. (If the server is in a different time zone than the hours configured above refer to):</span>
<span style="color: #000088;">$timeZoneAdjust</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Don't change these:</span>
<span style="color: #000088;">$now</span> <span style="color: #339933;">=</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$daylightSavingsTime</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;I&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$now</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$minutes</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$now</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$minuteOfDay</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$minutes</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">1440</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$hourOfDay</span> <span style="color: #339933;">=</span> <span style="color: #990000;">abs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$minuteOfDay</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #000088;">$timeZoneAdjust</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$daylightSavingsTime</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dayOfWeek</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;D&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$now</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Make the string:</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;var <span style="color: #006699; font-weight: bold;">$nameOfVariable</span> = <span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$dayOfWeek</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;Sun&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #666666; font-style: italic;">//Sunday is hardcoded.</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$closed</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$dayOfWeek</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;Sat&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hourOfDay</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$saturday</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'open'</span><span style="color: #009900;">&#93;</span> or <span style="color: #000088;">$hourOfDay</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$saturday</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'close'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$closed</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$open</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: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hourOfDay</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$weekday</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'open'</span><span style="color: #009900;">&#93;</span> or <span style="color: #000088;">$hourOfDay</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$weekday</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'close'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$closed</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$open</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Did you catch the trick?</p>
<p>The trick is to specify a php header like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;Content-type: application/x-javascript; charset=UTF-8&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That way the script returns a javascript file.<br />
This file contains a single variable holding the string that I want to inject into the DOM of my client&#8217;s website.</p>
<h3>The result</h3>
<p>On a normal weekday within hotline opening hours the output of the PHP file will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> hotline_status <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;p class='hotline_status'&gt;The hotline is open!&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I can then reference the PHP-file somewhere in the HTML of my client&#8217;s website (preferebly near the bottom for load speed reasons) like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://path/to/php/file/&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;;</span></pre></div></div>

<p>Then I inject the content of the variable in the right place using jQuery:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;div#hotline_status&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>append<span style="color: #009900;">&#40;</span>hotline_status<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Voila!</p>
<p>Visitors now see if the hotline is open at the time of visiting the site.</p>
<p>(-:</p>
<p><strong>Possibilities</strong></p>
<p>And this is only a simple script.</p>
<p>You can use this method to apply all the bells and wistles of PHP (or your server-side language of choice) to your client&#8217;s ancient and closed source website &#8211; including database access, file reads, curls, etc.</p>
<p>Want to feed variables to your PHP script to condition an SQL-call?<br />
No problem! Just append your variables to the filename of the referenced script (like scriptname.php?key=value) and use $_GET['key'] in the script to access them.</p>
<p>I guess you could even inject the script-tag itself on an event rather than on load, thus making user input possible, for instance on submitting a form. I haven&#8217;t tried this yet, though.</p>
<p>Of course, all of this wouldn&#8217;t be necessary at all in a perfect world where all clients have an open mind and understand the benefits of using non-proprietary, open-source CMS and e-commerce platforms.</p>
<p>But until that happens (which is never), little hacks like this are sometimes necessary to get the job done.</p>
<p>Hope you find it useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jakobloekkemadsen.com/2009/12/how-to-inject-dynamic-content-from-php-into-an-old-and-closed-source-cms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

