<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Christoph Dorn - All around PHP</title>
	
	<link>http://www.christophdorn.com/Blog</link>
	<description>... All around PHP ...</description>
	<pubDate>Tue, 16 Dec 2008 19:42:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/AllAroundPHP" type="application/rss+xml" /><item>
		<title>FirePHP column in November php|architect</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/469608027/</link>
		<comments>http://www.christophdorn.com/Blog/2008/11/29/firephp-column-in-november-phparchitect/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 20:12:49 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[FirePHP]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[ajax]]></category>

		<category><![CDATA[article]]></category>

		<category><![CDATA[column]]></category>

		<category><![CDATA[php|architect]]></category>

		<category><![CDATA[selective logging]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=170</guid>
		<description><![CDATA[The November issue of php&#124;architect is finally out. Why is this exiting for me? Because I had something to do with it:
/etc: FirePHP for Ajax Development
Firebug is without doubt the most popular development tool among Firefox plugins. Christoph Dorn thought it would be nice to have PHP integration for it.
by Christoph Dorn

The column describes why [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" title="Magazine" src="http://www.firephp.org/images/PHPArchitect_Cover_0086.jpg" alt="" width="150" height="195" />The <a href="http://www.phparch.com/c/magazine/issue/86" target="_blank">November</a> issue of <a href="http://www.phparch.com/" target="_blank">php|architect</a> is finally out. Why is this exiting for me? Because I had something to do with it:</p>
<blockquote><p><strong>/etc: FirePHP for Ajax Development</strong></p>
<p>Firebug is without doubt the most popular development tool among Firefox plugins. Christoph Dorn thought it would be nice to have PHP integration for it.</p>
<p><em>by Christoph Dorn</em></p></blockquote>
<p><span id="more-170"></span></p>
<p>The column describes why FirePHP is perfectly suited for Ajax Development and how to implement a selective logging system allowing the developer to switch on and off specific logging items on the fly. A complete working demo you can take and make your own is also included.</p>
<p>If you do not already have a php|architect subscription head on over to their <a href="http://www.phparch.com/c/magazine/issue/86" target="_blank">site</a> and purchase the November issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/11/29/firephp-column-in-november-phparchitect/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/11/29/firephp-column-in-november-phparchitect/</feedburner:origLink></item>
		<item>
		<title>Powerpoint on Steroids</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/444023084/</link>
		<comments>http://www.christophdorn.com/Blog/2008/11/05/powerpoint-on-steroids/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 05:24:44 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[Observations]]></category>

		<category><![CDATA[interactive]]></category>

		<category><![CDATA[presentation]]></category>

		<category><![CDATA[touch screen]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=166</guid>
		<description><![CDATA[The days of static Powerpoint Presentations are numbered. By static I mean stale content and primarily sequential presentation.
If you watched CNN&#8217;s coverage of the 2008 US Presidential Elections you will have seen their &#8220;New Toy&#8221;. An interactive touch display that takes presenting data to the next level. It is developed by Jeff Han of Perceptive [...]]]></description>
			<content:encoded><![CDATA[<p>The days of static Powerpoint Presentations are numbered. By static I mean stale content and primarily sequential presentation.</p>
<p>If you watched CNN&#8217;s coverage of the 2008 US Presidential Elections you will have seen their &#8220;New Toy&#8221;. An interactive touch display that takes presenting data to the next level. It is developed by <a href="http://www.ted.com/index.php/talks/jeff_han_demos_his_breakthrough_touchscreen.html" target="_blank">Jeff Han</a> of <a href="http://www.perceptivepixel.com/" target="_blank">Perceptive Pixel</a>.</p>
<p><span id="more-166"></span></p>
<p>It is great to see this technology appear in different mediums and not restricted to <a href="http://www.apple.com/iphone/" target="_blank">iPhones</a> or <a href="http://www.microsoft.com/surface/index.html" target="_blank">Table Tops</a>.</p>
<p>These days most computers have internet access. There is no reason why the content in presentations needs to be so static any more.</p>
<p>I think modern &#8220;presentations&#8221; will be much more fluid. There will be a primary sequence of points for the presentation but the presenter will be able to explore arguments by bringing up data, graphs, charts, photos, websites, screenshots, etc&#8230; completely interactively while staying completely engaged with the audience.</p>
<p>More importantly, you will be able to download the presentation later and view it again. You will be able to stop it at any point in time and interactively dig deeper into the data presented or look at the sources of the data to follow your own ideas.</p>
<p>When I went to the CNN website to check out the election section I was disappointed to see the data presented with basic flash objects on separate pages. It would have been nice to see the same &#8220;presentation&#8221; as was on the touch screen on TV.</p>
<p>There is still some technology missing to make interactive presentations the norm, like hand gesture capturing to control projected screens in lecture theaters but it won&#8217;t be long. In fact, there is probably already stuff out there that can already do all this. Let&#8217;s see it!</p>
<p>I am looking forward to the day when presentations are not controlled by powerpoint slides but rather follow the presenter&#8217;s experienced judgement of where the audience needs to be taken.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/11/05/powerpoint-on-steroids/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/11/05/powerpoint-on-steroids/</feedburner:origLink></item>
		<item>
		<title>FirePHP 0.2 Released</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/429039461/</link>
		<comments>http://www.christophdorn.com/Blog/2008/10/22/firephp-02-released/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 23:09:05 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[FirePHP]]></category>

		<category><![CDATA[Firebug]]></category>

		<category><![CDATA[Mozilla]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=154</guid>
		<description><![CDATA[I have released a new version of FirePHP. You can download it here. It will also be available on the Mozilla Add-ons site in a few days.
The release includes 27 bug fixes and feature enhancements. The scope of this release was primarily focused on improving the current feature set in terms of usability, reliability and [...]]]></description>
			<content:encoded><![CDATA[<p>I have released a new version of FirePHP. You can download it <a href="http://www.firephp.org/" target="_blank">here</a>. It will also be available on the <a href="https://addons.mozilla.org/en-US/firefox/addon/6149" target="_blank">Mozilla Add-ons site</a> in a few days.</p>
<p>The release includes <a href="http://code.google.com/p/firephp/issues/list?can=1&amp;q=label%3Arelease-0.2" target="_blank">27 bug fixes and feature enhancements</a>. The scope of this release was primarily focused on improving the current feature set in terms of usability, reliability and support for logging complex objects. You can find the changelog <a href="http://www.firephp.org/Wiki/Development/Release02" target="_blank">here</a>.</p>
<p><span id="more-154"></span></p>
<p>After installing the FirePHP 0.2 extension you will be directed to the <a href="http://www.firephp.org/HQ/Install.htm" target="_blank">Install</a> page after your next Firefox restart. On this page you need to download the updated FirePHPCore library. Next you can visit the <a href="http://www.firephp.org/HQ/Learn.htm" target="_blank">Learn</a> page for information on how to get started with FirePHP. Finally refer to the <a href="http://www.firephp.org/HQ/Use.htm" target="_blank">Usage</a> page as a reference for all supported features.</p>
<p>I want to thank everyone who has participated in the <a href="http://forum.firephp.org/" target="_blank">Community Forum</a> and <a href="http://code.google.com/p/firephp/issues/list" target="_blank">Issue Tracker</a> to report, test and resolve issues. Your help has been invaluable to make this release possible.</p>
<p>Finally, I have a new <a href="http://www.firephp.org/HQ/Contribute.htm" target="_blank">Contribution</a> page that includes a Donation button. If FirePHP saves you time I encourage you to donate what you believe is reasonable. It will allow me to spend more time maintaining FirePHP and make improvements that are suggested.</p>
<p>The 0.2 release includes the following improvements. See the <a href="http://www.firephp.org/HQ/Use.htm" target="_blank">Usage</a> page for more information.</p>
<h3>Enhanced object logging</h3>
<p>FirePHP will now log and display non-static private and protected object members. If they are declared static they can be logged with PHP 5.3. The variable viewer will indicate the visibility with a little icon. Red is private, orange is protected and green is public. Grey means undeclared (you have assigned a value but not declared the variable in the class) and the square means it is static.</p>
<p>Logging complex objects containing cyclical references to many other objects is no longer a problem. By using options you can now specify the mximum depth to traverse objects and arrays. You can also exclude specific object members from being logged in order to remove infomation that is not required and will only slow down your debugging.</p>
<h3>File and Line Information</h3>
<p>By default you can see the source file name and line number where each message was triggered when you hover over the message in the Firebug Console.</p>
<h3>Full UTF-8 and Latin-1 Support</h3>
<p>FirePHP now supports UTF-8 and Latin-1 (ISO-8859-1) encoded files and strings. All other encodings should work as well as all data gets converted to UTF-8.</p>
<h3>Enhanced Variable display in Console</h3>
<p>The variable display in the Console has been completely overhauled. Different types of variables including objects and labels are now properly displayed, abbreviated and highlighted.</p>
<h3>Other Improvements</h3>
<ul>
<li>The Variable Viewer can be resized</li>
<li>FirePHP will tell you when you need to upgrade your server library</li>
<li>Built-in error and exception handlers</li>
<li>Message grouping</li>
<li>New object oriented API to access FirePHP via static methods</li>
<li>Support for Firebug 1.3</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/10/22/firephp-02-released/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/10/22/firephp-02-released/</feedburner:origLink></item>
		<item>
		<title>Profiling queries with Zend_Db_Profiler_Firebug</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/421160846/</link>
		<comments>http://www.christophdorn.com/Blog/2008/10/14/profiling-queries-with-zend_db_profiler_firebug/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 03:25:18 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[FirePHP]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<category><![CDATA[db]]></category>

		<category><![CDATA[mysql]]></category>

		<category><![CDATA[profiler]]></category>

		<category><![CDATA[profiling]]></category>

		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=145</guid>
		<description><![CDATA[Eran Galperin has written a great post on profiling MySQL queries with Zend_Db and optimizing them by hand.
He explains how to use  Zend_Db_Profiler to analyze all SQL queries on a page and how to improve the performance of the queries by adding indexes.
Here is a quick modification to his example that will send the [...]]]></description>
			<content:encoded><![CDATA[<p>Eran Galperin has written a <a href="http://www.techfounder.net/2008/10/12/profiling-queries-with-zend_db-and-optimizing-them-by-hand/" target="_blank">great post</a> on profiling MySQL queries with Zend_Db and optimizing them by hand.</p>
<p>He explains how to use  <a href="http://framework.zend.com/manual/en/zend.db.profiler.html" target="_blank">Zend_Db_Profiler</a> to analyze all SQL queries on a page and how to improve the performance of the queries by adding indexes.</p>
<p>Here is a quick modification to his example that will send the profiling information to firebug instead of printing it to the page.</p>
<p><span id="more-145"></span></p>
<p>To use Firebug all you need to do is use <a target="_blank" href="http://framework.zend.com/manual/en/zend.db.profiler.html#zend.db.profiler.profilers.firebug">Zend_Db_Profiler_Firebug</a> as the profiler instead of the default one.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$profiler</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Db_Profiler_Firebug<span style="color: #009900;">&#40;</span><span style="">'All DB Queries'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$profiler</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="">'host'</span> <span style="color: #339933;">=&gt;</span> <span style="">'localhost'</span><span style="color: #339933;">,</span>
    <span style="">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="">'dbusername'</span><span style="color: #339933;">,</span>
    <span style="">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="">'dbpassword'</span><span style="color: #339933;">,</span>
    <span style="">'dbname'</span> <span style="color: #339933;">=&gt;</span> <span style="">'dbname'</span><span style="color: #339933;">,</span>
    <span style="">'profiler'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$profiler</span>
<span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> Zend_Db<span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="">'PDO_MYSQL'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>You can skip the whole second step of printing the profiling information to the page.</p>
<p>This code is assuming you are using Zend_Controller_Front and executing your queries in your model, view or controller files. For other use-cases see <a target="_blank" href="http://framework.zend.com/manual/en/zend.db.profiler.html#zend.db.profiler.profilers.firebug">here</a>.</p>
<p>Now open your Firefox web browser with <a href="http://www.getfirebug.com/" target="_blank">Firebug</a> and <a href="http://www.firephp.org/" target="_blank">FirePHP</a> installed and open the page you want to profile.</p>
<p>When you view the Firebug console you should see something like this:</p>
<p><a href="http://www.christophdorn.com/wordpress/wp-content/uploads/2008/10/zf_profilerscreenshot1.png"><img src="http://www.christophdorn.com/wordpress/wp-content/uploads/2008/10/zf_profilerscreenshot1.png" alt="" title="ZF Profiler Screenshot" width="300" height="77" class="alignnone size-medium wp-image-149" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/10/14/profiling-queries-with-zend_db_profiler_firebug/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/10/14/profiling-queries-with-zend_db_profiler_firebug/</feedburner:origLink></item>
		<item>
		<title>Your Mac can talk FeedBurner stats via PHP!</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/393935524/</link>
		<comments>http://www.christophdorn.com/Blog/2008/09/15/your-mac-can-talk-feedburner-stats/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 06:39:10 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[Mac]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[FeedBurner]]></category>

		<category><![CDATA[speech]]></category>

		<category><![CDATA[speech recognition]]></category>

		<category><![CDATA[speech synthesis]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=102</guid>
		<description><![CDATA[You have a blog and you are proud of it. Your sense of self-worth depends on how many people are following it. Making a detour to FeedBurner every day (the feed stats only update once a day) to check on your vitals is simple and does not take long (with a bookmark) but there has [...]]]></description>
			<content:encoded><![CDATA[<p>You have a blog and you are proud of it. Your sense of self-worth depends on how many people are following it. Making a detour to <a href="http://www.feedburner.com/" target="_blank">FeedBurner</a> every day (the feed stats only update once a day) to check on your vitals is simple and does not take long (with a bookmark) but there has to be a more automated way.</p>
<p>What if you could just think <em>&#8220;I wonder what my stats are today?&#8221;</em> and your Mac would tap into your mind and give you the answer. It&#8217;s probably a good thing it has not advanced that far yet.</p>
<p><strong>But what if you could ask your Mac and it would answer?</strong></p>
<p>Well &#8230;<span style="color: #ff0000;"> It can!</span> The needed <a href="http://en.wikipedia.org/wiki/PlainTalk" target="_blank">speech tools</a> are built right into Mac OS X.</p>
<p><img class="alignnone size-full wp-image-116" title="Preferences" src="http://www.christophdorn.com/wordpress/wp-content/uploads/2008/09/preferencesscreenshot2.png" alt="" width="349" height="79" /></p>
<p><span id="more-102"></span></p>
<p>By default, once enabled, you can voice-control some common features of most applications. You can also open <a href="http://en.wikipedia.org/wiki/Apple_Terminal" target="_blank"><em>Terminal</em></a> and type:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">say You look good today</pre></div></div>

<p>These are two separate systems (<a href="http://en.wikipedia.org/wiki/Speech_recognition" target="_blank">speech recognition</a> and <a href="http://en.wikipedia.org/wiki/Speech_synthesis" target="_blank">speech synthesis</a>). To have your Mac <em>listen</em> for some keyword and then <em>answer</em> with some intelligent information you need some plumbing code. Luckily it&#8217;s not hard to do at all and there are only a few steps. I&#8217;ll walk you through the setup.</p>
<h2>Requirements</h2>
<ul>
<li>Mac OS X Tiger but it should work just as well on Leopard</li>
<li><a href="http://php.net/" target="_blank">PHP5</a></li>
<li>A text editor</li>
<li>I am also assuming you have <a href="http://growl.info/" target="_blank">Growl</a> installed</li>
</ul>
<h2>Step 1:  Save and configure PHP script</h2>
<p>Save the PHP script below in a file somewhere on your hard drive. You will need to know the absolute path to it. Lets say you save it as <em>FeedBurnerStats.php</em> in your <em>user home directory</em>. My path would be <em>/Users/cadorn/FeedBurnerStats.php</em></p>
<p>Once saved you need to edit it to change the <em>&lt;username&gt;</em>, <em>&lt;password&gt;</em> and <em>&lt;feeduri&gt;</em> configuration options. That is your FeedBurner <em>username</em> and <em>password</em> as well as the unique URI of your feed that FeedBurner gives you. Your login information will be encrypted before it is sent so don&#8217;t worry about that.</p>
<p>If you have <a href="http://growl.info/" target="_blank">Growl</a> installed this script will also show your stats in Growl. If you don&#8217;t, just set <em>$growlnotify</em> to <em>false</em>.</p>
<p>I am not going to run you through the code. It should be simple enough to follow. If you don&#8217;t know PHP don&#8217;t worry. This will still work for you.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*******************************/</span>
<span style="color: #666666; font-style: italic;">// Your account username</span>
<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="">'&lt;username&gt;'</span>;
<span style="color: #666666; font-style: italic;">// Your account password</span>
<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="">'&lt;password&gt;'</span>;
<span style="color: #666666; font-style: italic;">// The URI of your feed (http://feeds.feedburner.com/&lt;feeduri&gt;)</span>
<span style="color: #000088;">$feedUri</span> <span style="color: #339933;">=</span> <span style="">'&lt;feeduri&gt;'</span>;
<span style="color: #666666; font-style: italic;">// Path to growlnotify if you want growl notifications</span>
<span style="color: #000088;">$growlnotify</span> <span style="color: #339933;">=</span> <span style="">'/usr/local/bin/growlnotify'</span>;
<span style="color: #666666; font-style: italic;">/*******************************/</span>
&nbsp;
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="">'https://api.feedburner.com/awareness/1.0/GetFeedData?uri='</span>
       <span style="color: #339933;">.</span> <span style="color: #000088;">$feedUri</span>;
&nbsp;
<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="">'http'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span>
        <span style="">'method'</span><span style="color: #339933;">=&gt;</span><span style="">'GET'</span><span style="color: #339933;">,</span>
        <span style="">'header'</span><span style="color: #339933;">=&gt;</span><span style="">'Authorization: Basic '</span>
                  <span style="color: #339933;">.</span> <span style="color: #990000;">base64_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span> <span style="color: #339933;">.</span> <span style="">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="">'say Fetching'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000088;">$tree</span> <span style="color: #339933;">=</span> simplexml_load_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tree</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entry</span><span style="color: #009900;">&#91;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'circulation'</span><span style="color: #009900;">&#93;</span>
       <span style="color: #339933;">.</span> <span style="">' Subscribers and '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$tree</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">feed</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entry</span><span style="color: #009900;">&#91;</span><span style="color:#800080;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="">'hits'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="">' Hits'</span>;
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$growlnotify</span><span style="color: #009900;">&#41;</span> <span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$growlnotify</span> <span style="color: #339933;">.</span> <span style="">' -m &quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$msg</span> <span style="color: #339933;">.</span> <span style="">'&quot;'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #990000;">exec</span><span style="color: #009900;">&#40;</span><span style="">'say '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Step 2: Choose your speech synthesis voice</h2>
<table border="0">
<tbody>
<tr>
<td valign="top"><img class="size-full wp-image-110" title="Speech 2" src="http://www.christophdorn.com/wordpress/wp-content/uploads/2008/09/speechscreenshot2.png" alt="" width="297" height="243" /></td>
<td style="padding-left: 20px;" valign="top">Go to your <em>System Preferences</em> and click on <em>Speech</em> under the <em>System</em> group.</p>
<p>Select the <em>Text to Speech</em> tab and choose a voice in the <em>System Voice</em> dropdown.</p>
<p>I like <em>Vicki</em>. She seems to be the clearest.</td>
</tr>
</tbody>
</table>
<h2>Step 3: Enable speech recognition</h2>
<table border="0">
<tbody>
<tr>
<td valign="top"><img class="size-full wp-image-109" title="Speech 1" src="http://www.christophdorn.com/wordpress/wp-content/uploads/2008/09/speechscreenshot1.png" alt="" width="298" height="243" /></td>
<td style="padding-left: 20px;" valign="top"><img class="size-full wp-image-107" title="Speech Indicator" src="http://www.christophdorn.com/wordpress/wp-content/uploads/2008/09/speechindicatorscreenshot.png" alt="" width="98" height="99" align="right" /><br />
Click on the <em>Speech Recognition</em> tab. Ensure <em>Speakable Items</em> is set to <em>On</em>. You should now see this little tool:</p>
<p>Now check your <em>Settings</em>. I am using my internal microphone and have it set to continuously listen without needing a keyword before a command is spoken. Turn the command acknowledgement off as it will interfere.</p>
<p>Before we continue, ensure that the system is actually listening. Toggle your <em>Listen Key</em> until the bars (blue and green) in the speech tool move as you speak.</td>
</tr>
</tbody>
</table>
<h2>Step 4: Install your &#8220;statts&#8221; voice command</h2>
<table border="0">
<tbody>
<tr>
<td valign="top"><img class="size-full wp-image-111" title="Speech 3" src="http://www.christophdorn.com/wordpress/wp-content/uploads/2008/09/speechscreenshot3.png" alt="" width="297" height="243" /></td>
<td style="padding-left: 20px;" valign="top">Click on the <em>Commands</em> tab and ensure <em>Application Specific Items</em> is checked.</p>
<p>Click on <em>Open Speakable Items Folder</em>.</p>
<p>In the <em>Finder</em> select the <em>Application Speakable Items</em> folder and select an application to enable the command for. It has to be attached to an application for it to work. I have mine in <em>firefox-bin</em> as I use Firefox all day.</p>
<p>Leave this folder open in your Finder and proceed below.
</td>
</tr>
</tbody>
</table>
<p>Save the following script into a file called <em>statts.scpt</em> on your desktop. Double-click the file you just created. It should launch the <em>Script Editor</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">tell application &quot;Terminal&quot;
	do shell script &quot;/usr/bin/php /Users/cadorn/FeedBurnerStats.php&quot;
end tell</pre></div></div>

<p>Edit the path to PHP if it is different and update the path to your PHP script file we saved above. To find the absolute path to your PHP binary you can type <em>which php</em> in your <em>Terminal</em> window. Remember that this needs to be the PHP5 binary.</p>
<p>Go to the <em>File</em> menu and select <em>Save As &#8230;</em></p>
<p>Now drag the folder you have selected in the <em>Finder</em> (see above) onto the <em>Where</em> dropdown in the <em>Save As</em> dialog. Save the script. It will be automatically compiled.</p>
<p>My file would now be at <em>/Users/cadorn/Library/Speech/Speakable Items/Application Speakable Items/firefox-bin/statts.scpt</em>.</p>
<p><strong>NOTE:</strong> The name of the file is important. It will be your voice command. The double <em>tt</em> is not a mistake. The command needs to be written as it sounds.</p>
<h2>At your command</h2>
<p>Open the application you have enabled the command for and <strong>speak it out aloud</strong>. When the system recognizes your command it will show briefly above the speech tool and execute your script.</p>
<p>The script will say <em>fetching</em>, then get your stats via the <a href="http://code.google.com/apis/feedburner/awareness_api.html" target="_blank">FeedBurner Awareness API</a> and tell you the number of subscribers and hits for the past 24 hours.</p>
<p>The <em>statts</em> word is pretty forgiving so you should not have too much of a problem having the system recognize you. If it is not working you can go to the <em>Speech Recognition</em> tab and under <em>Settings</em> try and <em>calibrate</em> your system. If it is recognizing other commands then you probably have an error in your <em>Speakable Item Script</em> or the PHP script.</p>
<p>While playing with this I noticed that the system does not recognize changes to the <em>Speakable Item Script</em> right away. It seems to index it every 10 seconds or so.</p>
<h2>Now Innovate</h2>
<p>This example may not be the most useful to you. The point is you now know how to trigger a PHP script via a voice command as well as have a PHP script talk to you.</p>
<p>Change the code, make it more useful. Have some fun with it. Who knows what you can come up with.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/09/15/your-mac-can-talk-feedburner-stats/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/09/15/your-mac-can-talk-feedburner-stats/</feedburner:origLink></item>
		<item>
		<title>Recursiveness: CakePHP Set::extract() and JSONPath</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/391299457/</link>
		<comments>http://www.christophdorn.com/Blog/2008/09/12/recursiveness-cakephp-setextract-and-jsonpath/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 05:32:55 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[benchmark]]></category>

		<category><![CDATA[CakePHP]]></category>

		<category><![CDATA[comparison]]></category>

		<category><![CDATA[jsonPath]]></category>

		<category><![CDATA[recursiveness]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=71</guid>
		<description><![CDATA[Just ran across this post where Felix shares some wisdom he gained while re-writing CakePHP&#8217;s Set::extract() (code) method to make it faster and add some XPath 2.0 support.
If you need a function to have the highest performance, try to express it non-recursively. It can make a 500% difference.
Now I thought the 500% speed gain (and [...]]]></description>
			<content:encoded><![CDATA[<p>Just ran across <a href="http://debuggable.com/posts/xpath-on-php-arrays-set-extract:48ca6265-258c-4032-b3ff-55b84834cda3" target="_blank">this post</a> where Felix shares some wisdom he gained while re-writing <a href="http://cakephp.org/" target="_blank">CakePHP</a>&#8217;s <em><a href="http://api.cakephp.org/class_set.html#b2d88d1df853685f5b8bc96b967ef6c3" target="_blank">Set::extract()</a></em> (<a href="https://trac.cakephp.org/browser/branches/1.2.x.x/cake/libs/set.php" target="_blank">code</a>) method to make it faster and add some <a href="http://en.wikipedia.org/wiki/XPath" target="_blank">XPath 2.0</a> support.</p>
<blockquote><p>If you need a function to have the highest performance, try to express it non-recursively. It can make a 500% difference.</p></blockquote>
<p>Now I thought the 500% speed gain (and associated fewer CPU cycles) was a number he grabbed out of the air or it was based on comparisons with the previous <em>Set::extract()</em> method and very specific to that case. It surely would not apply to any algorithm in general as some are much more complex than others.</p>
<p><span id="more-71"></span></p>
<p>While it <em>may not</em> apply to any algorithm in general it <em>may</em> apply to similar algorithms. So I benchmarked the new <em>Set::extract()</em> against a library I remembered called <em><a href="http://goessner.net/articles/JsonPath/" target="_blank">JSONPath</a></em> (<a href="http://code.google.com/p/jsonpath/source/browse/trunk/src/php/jsonpath.php" target="_blank">code</a>) which also allows you to extract data from nested arrays using a string selector. <em>JSONPath</em> uses recursion just like the old <em>Set::extract()</em> method.</p>
<p>I used the second <em>$users</em> array from <a href="http://debuggable.com/posts/cake-12s-set-class-eats-arrays-for-breakfast:480f4dd6-d084-4fb7-bacc-49fdcbdd56cb" target="_blank">here</a> and ran the following two tests:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Simple</span>
Set<span style="color: #339933;">::</span><span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="">'/User/name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$users</span><span style="color: #009900;">&#41;</span>;
jsonPath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$users</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;$..User.name&quot;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #666666; font-style: italic;">// Complex</span>
Set<span style="color: #339933;">::</span><span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="">'/User/Item[id&gt;2]/name'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$users</span><span style="color: #009900;">&#41;</span>;
jsonPath<span style="color: #009900;">&#40;</span><span style="color: #000088;">$users</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;$..User.Item.[?(@['id']&gt;2)].name&quot;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Both of these tests generate the same output so they are a pretty good comparison for the underlying algorithms. Running them 100 times each gives the following result:</p>
<p></p>
<table class="wptable rowstyle-alt" id="wptable-1" >
	<thead>
	<tr>
		<th class="sortable" style="width:100px" align="left">Library</th>
		<th class="sortable" style="width:80px" align="center">Complexity</th>
		<th class="sortable" style="width:80px" align="right">Time (sec)</th>
		<th class="sortable" style="width:80px" align="right">Comparison</th>
	</tr>
	</thead>
	<tr>
		<td style="width:100px" align="left">Set::extract()</td>
		<td style="width:80px" align="center">Simple</td>
		<td style="width:80px" align="right">0.013</td>
		<td style="width:80px" >&nbsp;</td>
	</tr>
	<tr class="alt">
		<td style="width:100px" align="left">jsonPath</td>
		<td style="width:80px" align="center">Simple</td>
		<td style="width:80px" align="right">0.068</td>
		<td style="width:80px" align="right">498%</td>
	</tr>
	<tr>
		<td style="width:100px" align="left">Set::extract()</td>
		<td style="width:80px" align="center">Complex</td>
		<td style="width:80px" align="right">0.034</td>
		<td style="width:80px" >&nbsp;</td>
	</tr>
	<tr class="alt">
		<td style="width:100px" align="left">jsonPath</td>
		<td style="width:80px" align="center">Complex</td>
		<td style="width:80px" align="right">0.172</td>
		<td style="width:80px" align="right">500%</td>
	</tr>
</table><p>
</p>
<p><strong>Lo and behold! The speed difference is ~500%!</strong></p>
<p><span style="color: #ff0000;">Now that is a funny answer to my question!</span> NOTE: The two libraries (and old <em>Set::extract()</em>) have different features and cannot be compared like this. The <em>500%</em> is only applicable for this specific example but take it to show that recursion should definitely be evaluated when looking for speed gain. The cost for less recursion may be less modularity and extensibility, but that is a tradeoff you always need to make.</p>
<p>Now don&#8217;t use these figures to choose between <em>Set::extract()</em> and <em>JSONPath</em>. They work very differently internally. <em>JSONPath</em> uses a lot of recursion and jumping around but it also uses a lot of regular expression matching which is notoriously slow in PHP.</p>
<p><em>JSONPath</em> has a very academic background and illustrates some neat concepts. If someone was to take it and put a practical spin on it with some performance improvements (reducing recursiveness!?) and new features, it could make for an even better library to extract data from arrays.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/09/12/recursiveness-cakephp-setextract-and-jsonpath/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/09/12/recursiveness-cakephp-setextract-and-jsonpath/</feedburner:origLink></item>
		<item>
		<title>Domplate variables and variable formatters</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/389180095/</link>
		<comments>http://www.christophdorn.com/Blog/2008/09/10/domplate-variables-and-variable-formatters/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 01:15:41 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[Domplate]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[callback]]></category>

		<category><![CDATA[formatter]]></category>

		<category><![CDATA[function]]></category>

		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=55</guid>
		<description><![CDATA[I have more domplate goodness for you. First of all keep in mind that domplate only works in Firefox right now. I will be making it cross-browser soon! Also, it requires some plumbing code if used outside of Firebug that I will be removing as well.
This post is about the variable substitution and variable formatter [...]]]></description>
			<content:encoded><![CDATA[<p>I have more domplate goodness for you. First of all keep in mind that domplate <strong>only works in Firefox</strong> right now. I will be making it cross-browser soon! Also, it requires some plumbing code if used outside of Firebug that I will be removing as well.</p>
<p>This post is about the variable substitution and variable formatter functionality in domplate. I will start by showing you what you can do with the domplate implementation that is shipped with Firebug and then tell you about a little enhancement I made on my own copy.</p>
<p><span id="more-55"></span></p>
<p>Lets take a look at the following template taken from <a href="http://code.google.com/p/domplate/source/browse/trunk/apache/MultipleFunctionArguments/index.php" target="_blank">here</a>. To run this locally you will also need <a href="http://code.google.com/p/domplate/source/browse/trunk/libraries/domplate/domplate-debug.js" target="_blank">this</a> copy of domplate.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">TABLE<span style="color: #009900;">&#40;</span>
  TBODY<span style="color: #009900;">&#40;</span>
    TR<span style="color: #009900;">&#40;</span>
      TH<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'style'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'background-color: gray;'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
         <span style="color: #3366CC;">'Names'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #000066; font-weight: bold;">FOR</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'row'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'$people|getRows'</span><span style="color: #339933;">,</span>
      TR<span style="color: #009900;">&#40;</span>
        TD<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'style'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'background-color: $row.color'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
           <span style="color: #3366CC;">'Hello $row.name|formatName'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>As you can see, a domplate template is simply a <em>set of nested function calls</em> where the function name represents the HTML tag except for some special functions like <em>FOR</em>. The first argument contains any HTML attributes you want to add and the remaining arguments further tags or the actual content that is to reside within the tag.</p>
<h2>Variables</h2>
<p>You will notice that there are a number of variables in the basic form of <em>$var</em>. Variables in domplate work just like they do in javascript although only printing of <em>object variables</em> is supported. Arrays are supported for passing data to formatters <span style="color: #999999;">(more on that later)</span>, but they cannot be printed as the array items cannot be accessed directly.</p>
<p>Variables have scope. When a template executes all variables passed to domplate from your calling code will be present by default<em> throughout the entire template</em>. In the example above the <em>FOR</em> loop will create its own sub-scope with its <em>own variables</em>. These variables are only accessible from within the <em>FOR</em> loop and are not available after the for loop as exited.</p>
<p>You can access properties of objects stored in the variables via the dot syntax. The <em>$row.name</em> variable accesses the <em>name</em> property of the <em>row</em> object.</p>
<p>A variable is recognized as such if it begins with a <em>$</em> and ends with a <em>space</em>, <em>comma</em> or <em>pipe</em> <span style="color: #999999;">(more on the <em>comma</em> and <em>pipe</em> later)</span>. The first character after the <em>$</em> may not be <em>numeric</em> (just like in javascript) and any alphanumeric characters including <em>underscore</em> and <em>period</em> and valid thereafter.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$var1
$var1.<span style="color: #660066;">prop1</span>
$var1 Hello
Hello$var1</pre></div></div>

<p>You can print any number of variables embedded into the tag content.</p>
<h2>Variable Formatters</h2>
<p>Variables are great and essential in a template system, but domplate really shines in its support for variable formatters. A variable formatter is a function callback that allows you to call a function defined within your template object and pass along a template variable. The task of the function is to <em>format</em> the variable and return it to be printed, used in special functions like <em>FOR</em> or piped to another formatter.</p>
<p>To define a formatter simply append <em>|func</em> to the end of a variable. This will <em>pipe</em> the variable to the function called <em>func</em> which means that it will pass the variable to the function as the first and only argument.</p>
<p>In the above example <em>$row.name|formatName</em> will pass the <em>$row.name</em> variable to the <em>formatName</em> function and the result will be printed inline. Similarly <em>$people|getRows</em> will pass the <em>$people</em> variable to the <em>getRows</em> function and the result will be used to iterate over in the <em>FOR</em> loop.</p>
<p>You can chain multiple formatters to a variable by appending more than one <em>|func</em> to it. It will pass the specified variable to the first function and the result to the second function and so on. Think of it like unix pipes. Hence the use of the <em>|</em> character. You can pipe the result of one formatter to another.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$var|func
$var|func1|func2</pre></div></div>

<h2>The FOR loop</h2>
<p>While we are at it lets examine the <em>FOR</em> loop a bit closer. I will have further posts about other built-in functions in future.</p>
<p>The <em>FOR</em> function is a <em>built-in template function</em> that iterates over a list of values by repeating its sub-template for every entry in an <em>indexed array</em>. Each <em>array value</em> can be a simple <em>string</em>, <em>integer</em> or an <em>object</em> containing one or more properties where a property can contain further nested objects.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">FOR</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'row'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'$people|getRows'</span><span style="color: #339933;">,</span>
  ...
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>This <em>FOR</em> loop will iterate over the array returned by the <em>getRows</em> formatter. The formatter in turn is taking in the <em>$people</em> variable as its source of data. This setup allows you to iterate over any variable as long as the formatter knows how to interpret it in order to return a list of values to the FOR loop.</p>
<p>As the loop steps through the array, each value is assigned to a variable called <em>row</em>. You can access it via <em>$row</em> and if your array values are objects you can use the dot syntax to get the object properties such as <em>$row.name</em>. As mentioned above the <em>$row</em> variable has limited scope and is only available from within the loop.</p>
<p>You can nest <em>FOR</em> loops and supply a variable without a formatter as the data for the loop as long as it is already an indexed array of values.</p>
<h2>Passing multiple variables to a formatter</h2>
<p>If you use formatters in their basic form which is to format variables for display you will usually only need to pass one variable to it. Even if you need to be able to customize a formatter dynamically you can register a variable on the template object which the formatter can access.</p>
<p>There are cases however where you don&#8217;t want to pollute the template object with such variables or you need more flexibility in your templates especially if they are nested and/or inherit and customize other templates. It is also useful if you need to combine two variables in a formatter that will be used to feed a <em>FOR</em> loop.</p>
<p>This is where my little enhancement comes in handy.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$var1<span style="color: #339933;">,</span>$var2|func
$var1<span style="color: #339933;">,</span>$var2<span style="color: #339933;">,</span>$var3|func1|func2</pre></div></div>

<p>It allows you to pass two or more variables to a formatter while still being able to chain formatters. Simply separate each variable with a <em>comma</em> to assemble a list of variables to be piped to the first formatter as function arguments in corresponding order.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> func<span style="color: #009900;">&#40;</span>var1<span style="color: #339933;">,</span>var2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Do not include any spaces in this list or the variables will be treated separately. The second formatter will simply receive the result of the first as its only argument.</p>
<p>Note that this feature is only available in <a href="http://code.google.com/p/domplate/source/browse/trunk/libraries/domplate/domplate-debug.js" target="_blank">my copy</a> of domplate and not supported by Firebug at this point. You can see an example of it <a href="http://code.google.com/p/domplate/source/browse/trunk/apache/MultipleFunctionArguments/index.php" target="_blank">here</a>. You need to download it along with the domplate code to run it.</p>
<p>Enjoy! If you have any questions post them here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/09/10/domplate-variables-and-variable-formatters/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/09/10/domplate-variables-and-variable-formatters/</feedburner:origLink></item>
		<item>
		<title>Domplate debug logging</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/386325377/</link>
		<comments>http://www.christophdorn.com/Blog/2008/09/07/domplate-debug-logging/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 04:03:11 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[Domplate]]></category>

		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[debug]]></category>

		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=51</guid>
		<description><![CDATA[I have been working on trying to understand the magic behind domplate, the template system that is shipped with Firebug. Apparently nobody knows much about it and there is no documentation.
As part of my domplate project that is aimed at making the template system available for general use in the browser (and yes there will [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working on trying to understand the magic behind <a href="http://code.google.com/p/fbug/source/browse/branches/firebug1.3/content/firebug/domplate.js" target="_blank">domplate</a>, the template system that is shipped with Firebug. Apparently nobody knows much about it and there is no documentation.</p>
<p>As part of my <a href="http://code.google.com/p/domplate/" target="_blank">domplate project</a> that is aimed at making the template system available for general use in the browser (and yes there will be documentation) I have begun by adding some debug logging capabilities.</p>
<p><span id="more-51"></span></p>
<p>I find <em>logging</em> more useful for understanding intircate and highly nested code as opposed to <em>interactive debugging</em> as you can see the entire execution path on one page. Turns out that firebug is ideally suited for this task thanks to its <a href="http://getfirebug.com/logging.html" target="_blank">logging console</a> that supports nested groups.</p>
<p><strong>If you work with domplate you will want to try out <a href="http://code.google.com/p/domplate/source/browse/trunk/libraries/domplate/domplate-debug.js" target="_blank">this modified version</a> with the added logging capabilities. </strong>There is no logging levels yet and it spits out <strong>A LOT</strong> of information so it can be a bit slow but it will give you a great overview of what happens behind the scenes including the generated dynamic code.</p>
<p>To use it simply enable <em>DomplateDebug</em> logging and make sure your Firebug console is enabled:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">DomplateDebug.<span style="color: #660066;">enabled</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span>;</pre></div></div>

<p>There is a page with a simple demo <a href="http://code.google.com/p/domplate/source/browse/trunk/apache/SimpleFormatter/index.php?r=10" target="_blank">here</a>. You will need to download it. At the moment domplate only works on Firefox.</p>
<p>While I was building the logging system I was on the hunt for a <a href="http://groups.google.com/group/firebug/browse_thread/thread/5bd5d142d5e41c67" target="_blank">problem reported by Nathan</a>. (The demo page above is a slightly modified version of his testing code that showed the problem). The logger allowed me to narrow it down and solve it.</p>
<p>It turns out to be so trivial, yet it was so hard to track down and figure out. Are you ready?</p>
<p>When you define tables in your templates <span style="color: #ff0000;">you must include a <strong>TBODY</strong> tag</span>!</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">TABLE<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>border<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  TBODY<span style="color: #009900;">&#40;</span>
    TR<span style="color: #009900;">&#40;</span>
      TH<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>colspan<span style="color: #339933;">:</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'array'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #000066; font-weight: bold;">FOR</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'x'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'$value'</span><span style="color: #339933;">,</span>
      TR<span style="color: #009900;">&#40;</span>
        TD<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'$x.name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        TD<span style="color: #009900;">&#40;</span>
          TAG<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'$x.val|format'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>value<span style="color: #339933;">:</span><span style="color: #3366CC;">'$x.val|parseParts'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

<p>Now don&#8217;t feel too bad if you have made this mistake yourself. The tbody tag after all is optional when coding websites, but evidently it is <strong>NOT</strong> optional in domplate.</p>
<p>Stay tuned for more domplate magic on my blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/09/07/domplate-debug-logging/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/09/07/domplate-debug-logging/</feedburner:origLink></item>
		<item>
		<title>FirePHP and Zend Framework 1.6</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/381938313/</link>
		<comments>http://www.christophdorn.com/Blog/2008/09/02/firephp-and-zend-framework-16/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 03:00:10 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[FirePHP]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Zend Framework]]></category>

		<category><![CDATA[debugging]]></category>

		<category><![CDATA[logging]]></category>

		<category><![CDATA[profiling]]></category>

		<category><![CDATA[Zend_Db_Profiler_Firebug]]></category>

		<category><![CDATA[Zend_Log_Writer_Firebug]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=17</guid>
		<description><![CDATA[The long awaited day has arrived. Zend Framework 1.6 just shipped and with it native support for FirePHP!
This means that if you use Zend Framework (ZF) you can now log to your Firebug Console via FirePHP without needing to download any other PHP files such as the FirePHPCore library.
There are two primary components available at [...]]]></description>
			<content:encoded><![CDATA[<p>The long awaited day has arrived. <a href="http://framework.zend.com/" target="_blank">Zend Framework 1.6</a> just shipped and with it native support for <a href="http://www.firephp.org/" target="_blank">FirePHP</a>!</p>
<p>This means that if you use Zend Framework (ZF) you can now log to your <a href="http://www.getfirebug.com/" target="_blank">Firebug</a> <a href="http://getfirebug.com/logging.html" target="_blank">Console</a> via FirePHP without needing to download any other PHP files such as the <a href="http://www.firephp.org/Wiki/Libraries/FirePHPCore" target="_blank">FirePHPCore</a> library.</p>
<p>There are two primary components available at this time. One is the <a href="http://framework.zend.com/manual/en/zend.log.writers.html#zend.log.writers.firebug" target="_blank"><code>Zend_Log_Writer_Firebug</code></a> and the other the <a href="http://framework.zend.com/manual/en/zend.db.profiler.html#zend.db.profiler.profilers.firebug" target="_blank"><code>Zend_Db_Profiler_Firebug</code></a>.<br />
<span id="more-17"></span><br />
Lets check out how to use these new components. I would think that most ZF applications use <a href="http://framework.zend.com/manual/en/zend.controller.front.html" target="_blank"><code>Zend_Controller_Front</code></a> so the following examples assume you have a <a href="http://framework.zend.com/docs/quickstart" target="_blank">basic MVC application</a>.</p>
<h2>Install Firebug and FirePHP</h2>
<p>You first need to install the Firebug and FirePHP Firefox extensions. You can install them from here:</p>
<ul>
<li>Firebug: <a href="https://addons.mozilla.org/en-US/firefox/addon/1843" target="_blank">https://addons.mozilla.org/en-US/firefox/addon/1843</a></li>
<li>FirePHP: <a href="https://addons.mozilla.org/en-US/firefox/addon/6149" target="_blank">https://addons.mozilla.org/en-US/firefox/addon/6149</a></li>
</ul>
<h2>Logging to FirePHP with Zend_Log</h2>
<p>All logging in ZF is done via <a href="http://framework.zend.com/manual/en/zend.log.html" target="_blank"><code>Zend_Log</code></a> which delegates the actual logging to registered <a href="http://framework.zend.com/manual/en/zend.log.writers.html" target="_blank">log writers</a>. The <code>Zend_Log_Writer_Firebug</code> component is such a writer and as the name indicates it sends your log data to Firebug.</p>
<p>Place the following code in your <a href="http://framework.zend.com/docs/quickstart/create-a-bootstrap-file" target="_blank">bootstrap</a> file somewhere before dispatching your front controller:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$logger</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Log<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$writer</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Log_Writer_Firebug<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$logger</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addWriter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$writer</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>To keep an instance of your logger you can use:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">set</span><span style="color: #009900;">&#40;</span><span style="">'logger'</span><span style="color: #339933;">,</span><span style="color: #000088;">$logger</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>The Firebug log writer is all setup and ready to go. You can now dispatch your front controller and log data from within any of your model, view and controller files with the following:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$logger</span> <span style="color: #339933;">=</span> Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="">'logger'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$logger</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">log</span><span style="color: #009900;">&#40;</span><span style="">'This is a log message!'</span><span style="color: #339933;">,</span> Zend_Log<span style="color: #339933;">::</span><span style="color: #004000;">INFO</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>If you have done everything correctly you should see <em>&#8220;This is a log message!</em>&#8221; in your Firebug Console. If it is not showing up, make sure you have the <em>Net</em> and <em>Console</em> Firebug panels enabled.</p>
<p>The <code>Zend_Log::INFO</code> constant passed to <code>log()</code> determines the priority of the logging message. To increase the priority you can use <code>Zend_Log::WARN</code> or <code>Zend_Log::ALERT</code> for example which will produce a log message with a warning and error style respectively.</p>
<p>To log a plain message without any icon in Firebug you can use <code>Zend_Log::DEBUG</code>.</p>
<p>While logging simple strings is fun, FirePHP really comes into its own when logging complex data structures such as multi-dimensional arrays and objects. All you need to do is pass the object you want to log to the <code>log()</code> method, specify the logging priority and FirePHP will render the data appropriately.</p>
<p>For example you can log your exceptions with a complete expandable stack trace with the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">try <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Code that may throw an exception</span>
<span style="color: #009900;">&#125;</span> catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="">'logger'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">err</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Note the above code also uses the <code>err()</code> shortcut instead of passing the <code>Zend_Log::Err</code> constant to <code>log()</code>.</p>
<p>For extensive documentation on how to use the Firebug log writer including information on how to create tables in the Firebug Console please see the <a href="http://framework.zend.com/manual/en/zend.log.writers.html#zend.log.writers.firebug" target="_blank">online documentation</a>.</p>
<h2>Profiling Database Queries</h2>
<p>There are numerous reasons for wanting to see a list of database queries executed during a page request. The <code>Zend_Db_Profiler_Firebug</code> component makes this possible and displays the result in an expandable table in the Firebug Console.</p>
<p>Place the following code in your <a href="http://framework.zend.com/docs/quickstart/create-a-bootstrap-file" target="_blank">bootstrap</a> file somewhere after your database adapter (<em>$db</em>) is initialized and before dispatching your front controller:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$profiler</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Db_Profiler_Firebug<span style="color: #009900;">&#40;</span><span style="">'All DB Queries'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$profiler</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setProfiler</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$profiler</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>That&#8217;s it! Any database queries executed in your model, view and controller files will now be sent to Firebug along with the time it took to execute each, the query that was executed and any parameters bound to the query.</p>
<p>For a more detailed tutorial on how to use <code>Zend_Db_Proflier_Firebug</code> see <a href="http://peacocksuit.com/blog/2008/09/02/zend-framework-logging-database-queries-to-firebug/" target="_blank">here</a>.</p>
<h2>Try it Out!</h2>
<p>You may be used to debugging your ZF code using <code>Zend_Debug::dump()</code> or even <code>var_dump()</code>. What do you have to loose trying these new components? They offer the big advantage of not dumping your debug data to the page. They allow you to debug applications with intricate designs as well as AJAX request that require clean JSON or XML responses.</p>
<p>Even if you are used to <a href="http://www.xdebug.org/" target="_blank">xDebug</a>, FirePHP may prove to be a faster debugging solution in some cases than starting a debug session every time you need to ge some quick feedback as to what your variables are doing.</p>
<p>If you get tired of typing <em>Zend_Registry::get(&#8217;logger&#8217;)->debug();</em> every time you need to print some debug data you can place the following wrapper function in your bootstrap file:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> fb<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$label</span><span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$label</span><span style="color: #339933;">!=</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$label</span><span style="color: #339933;">,</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
    Zend_Registry<span style="color: #339933;">::</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="">'logger'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now you can simply use:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;">fb<span style="color: #009900;">&#40;</span><span style="">'This is a log message!'</span><span style="color: #009900;">&#41;</span>;
fb<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #339933;">,</span> <span style="">'Server Variables'</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>One last note of caution. <span style="color: #ff0000;"><strong>Do not log your debug data for everyone to see!</strong></span> Make sure you disable all logging when your application runs in production. Instead of removing your logging code every time you upload your application, you can disable the log writer and database profiler in your bootstrap file with:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$writer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$profiler</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<h2>More Information/Help</h2>
<p>For detailed information on these two components please refer to the <a href="http://framework.zend.com/manual/en/" target="_blank">Zend Framework Manual</a>. Specifically the <a href="http://framework.zend.com/manual/en/zend.log.writers.html#zend.log.writers.firebug" target="_blank"><code>Zend_Log_Writer_Firebug</code></a> and <a href="http://framework.zend.com/manual/en/zend.db.profiler.html#zend.db.profiler.profilers.firebug" target="_blank"><code>Zend_Db_Profiler_Firebug</code></a> chapters.</p>
<p>If you need help use one of the following forums:</p>
<ul>
<li><a href="http://framework.zend.com/wiki/display/ZFDEV/Contributing+to+Zend+Framework#ContributingtoZendFramework-Subscribetotheappropriatemailinglists" target="_blank">Zend Framework Mailing Lists</a> (Use the <em>General</em> List)</li>
<li><a href="http://forum.firephp.org/" target="_blank">FirePHP Community Forum</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/09/02/firephp-and-zend-framework-16/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/09/02/firephp-and-zend-framework-16/</feedburner:origLink></item>
		<item>
		<title>FirePHP for legacy code</title>
		<link>http://feeds.feedburner.com/~r/AllAroundPHP/~3/379051793/</link>
		<comments>http://www.christophdorn.com/Blog/2008/08/30/firephp-for-legacy-code/#comments</comments>
		<pubDate>Sat, 30 Aug 2008 17:26:49 +0000</pubDate>
		<dc:creator>Christoph Dorn</dc:creator>
		
		<category><![CDATA[FirePHP]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[debugging]]></category>

		<category><![CDATA[inherited websites]]></category>

		<category><![CDATA[legacy code]]></category>

		<guid isPermaLink="false">http://www.christophdorn.com/Blog/?p=12</guid>
		<description><![CDATA[I stumbled across this post during one of my &#8220;firephp&#8221; google searches.
I find it great for inherited websites where I need to troubleshoot problems on live servers, as I can have all the debug/variable dump/etc crap dump to the FirePHP console so it doesn&#8217;t show up on the website while I&#8217;m trying to track down [...]]]></description>
			<content:encoded><![CDATA[<p>I stumbled across <a href="http://lists.nyphp.org/pipermail/talk/2008-August/026487.html" target="_blank">this post</a> during one of my &#8220;firephp&#8221; google searches.</p>
<blockquote><p>I find it great for inherited websites where I need to troubleshoot problems on live servers, as I can have all the debug/variable dump/etc crap dump to the FirePHP console so it doesn&#8217;t show up on the website while I&#8217;m trying to track down a problem and the budget is not there to make a dev copy of the system[they need an in and out fix, 4 hours tops]</p></blockquote>
<p>It illustrates a great use case. Many times you need to maintain legacy code that you don&#8217;t have a development environment for. FirePHP enables you to do ad-hock debugging on a live site without affecting site visitors as long as you are careful not to cause any parser errors. Maybe not a great idea on a high-traffic site, but chances are if the site runs on more than one server or has a lot of traffic the owners will be able to afford a development environment for you.</p>
<p>It may also be a great tool for helping you convert PHP4 applications to PHP5.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christophdorn.com/Blog/2008/08/30/firephp-for-legacy-code/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.christophdorn.com/Blog/2008/08/30/firephp-for-legacy-code/</feedburner:origLink></item>
	</channel>
</rss>
