<?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>Notes Log &#187; Enzymes</title>
	<atom:link href="http://noteslog.com/category/enzymes/feed/" rel="self" type="application/rss+xml" />
	<link>http://noteslog.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 15:11:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to Add a Digg Button to a WordPress Post</title>
		<link>http://noteslog.com/post/how-to-add-a-digg-button/</link>
		<comments>http://noteslog.com/post/how-to-add-a-digg-button/#comments</comments>
		<pubDate>Wed, 01 Oct 2008 21:36:07 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Enzymes]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=282</guid>
		<description><![CDATA[See the Digg button? </p><div class="diggthis"><script type="text/javascript">
digg_url = 'http://noteslog.com/post/how-to-add-a-digg-button/';
digg_title = 'How to Add a Digg Button to a WordPress Post';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p> is the enzyme I wrote for displaying it. I think it&#8217;s useful to have a means for adding a Digg button to a post only when and where you need it. Of course you can put the same enzyme in a template (using the metabolize function), and you&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p></p><div class="diggthis"><script type="text/javascript">
digg_url = 'http://noteslog.com/post/how-to-add-a-digg-button/';
digg_title = 'How to Add a Digg Button to a WordPress Post';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p> See the Digg button? <span style="color: #333399;">{[  1.diggthis()  ]}</span> is the enzyme I wrote for displaying it. I think it&#8217;s useful to have a means for adding a Digg button to a post only when and where you need it.</p>
<p><span id="more-282"></span></p>
<p>Of course you can put the same enzyme in a template (using the <span style="color: #333399;">metabolize</span> function), and you&#8217;ll see a Digg button into each and every post, but I prefer the on-demand way.</p>
<p>Now I&#8217;ll show you my setup.</p>
<h4>1. Add a &#8216;diggthis-code&#8217; custom field</h4>
<p>As usual, I add the enzymes I&#8217;m going to use over and over, into the post number 1, the one that WordPress gives you by default.</p>
<p>This custom field is for the code that <a href="http://digg.com/tools/integrate" target="_blank">Digg tells you to use</a>. I prefer to isolate external codes into their own custom fields, so this one is just for that:</p>
<p><pre><code class="html">&lt;script type=&quot;text/javascript&quot;&gt;
digg_url = 'WEBSITE_URL';
digg_title = 'TITLE';
&lt;/script&gt;
&lt;script src=&quot;http://digg.com/tools/diggthis.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</code></pre></p>
<h4>2. Add a &#8216;diggthis&#8217; custom field</h4>
<p>This custom field is for the enzyme:</p>
<p><pre class="ln-"><code class="php">$post = $this-&gt;post;
$url = post_permalink( $post-&gt;ID );
if( false !== strpos( $url, '://localhost/' ) ) {
  return '[no digg for localhost]';
}
$title = $post-&gt;post_title;
$code = $this-&gt;elaborate( &quot;1.diggthis-code&quot; );
$code = $code[0];
$code = str_replace( 'WEBSITE_URL', $url, $code );
$code = str_replace( 'TITLE', $title, $code );
$style = $this-&gt;substrate;
if( '' != $style ) {
  $style = ' style=&quot;' . $style . '&quot;';
}
$code = '&lt;/p&gt;&lt;div class=&quot;diggthis&quot;' . $style . '&gt;' . $code . '&lt;/div&gt;&lt;p&gt;';
//return htmlspecialchars( $code );
return $code;</code></pre></p>
<ul>
<li>Line 1: get the current post object</li>
<li>Lines 2-6: get values for the variables of the widget<br />
the localhost shortcircuit is a Digg requirement; if you don&#8217;t return, you&#8217;ll see an error</li>
<li>Lines 7-10: get the widget and set its variables</li>
<li>Lines 11-14: get custom style from the enzyme&#8217;s substrate, if any</li>
<li>Line 15: decorate the widget<br />
reverse P-wrap is needed because WordPress automatically applies a P-wrap and a DIV into a P is not allowed</li>
<li>Line 16: useful for debugging</li>
<li>Line 17: return the widget</li>
</ul>
<h4>3. Use it</h4>
<p>That&#8217;s it. For displaying a new Digg button now, right here </p><div class="diggthis" style="float: right; margin-left: 1em;"><script type="text/javascript">
digg_url = 'http://noteslog.com/post/how-to-add-a-digg-button/';
digg_title = 'How to Add a Digg Button to a WordPress Post';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></div><p> I wrote <span style="color: #333399;">{[ 1.diggthis( =float: right; margin-left: 1em;= ) ]}</span>. This time I overwrite the CSS for the class <span style="color: #333399;">diggthis</span> that I put into my theme:</p>
<p><pre><code class="css">.diggthis {
	float: left;
	margin-right: 1em;
}</code></pre></p>
<h4>Prior art</h4>
<ul>
<li><a href="http://www.aviransplace.com/digg-this-wordpress-plugin/" target="_blank">digg-this-wordpress-plugin</a></li>
<li><a href="http://cybernetnews.com/digg-button/" target="_blank">digg-button</a></li>
<li><a href="http://en.blog.wordpress.com/2007/02/22/digg-this/" target="_blank">digg-this</a></li>
<li><a href="http://www.ashbaughonline.com/2007/05/05/manually-adding-digg-button-to-wordpress-posts/">manually-adding-digg-button-to-wordpress-posts</a></li>
<li>&#8230; and many others</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/how-to-add-a-digg-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to highlight code in WordPress</title>
		<link>http://noteslog.com/post/how-to-highlight-code-in-wordpress/</link>
		<comments>http://noteslog.com/post/how-to-highlight-code-in-wordpress/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 00:48:47 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Chili]]></category>
		<category><![CDATA[Enzymes]]></category>

		<guid isPermaLink="false">http://noteslog.com/post/how-to-highlight-code-in-wordpress/</guid>
		<description><![CDATA[Although it&#8217;s easy to use WP Chili out of the box, WordPress does have some limitations, like the following: you need to change to the Code editor before adding a snippet to your post you need to make your snippet postable yourself, escaping all HTML entities even if snippets are very short, they are intermingled [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://noteslog.com/blog/wp-content/uploads/2008/03/visual-code.png" alt="WordPress Editing Tabs" /></p>
<p>Although it&#8217;s easy to use <a href="http://noteslog.com/chili/wp-chili/">WP Chili</a> out of the box, WordPress does have some limitations, like the following:</p>
<ul>
<li>you need to change to the <u>Code</u> editor before adding a snippet to your post</li>
<li>you need to make your snippet <a href="http://noteslog.com/personal/projects/postable/">postable</a> yourself, escaping all HTML entities</li>
<li>even if snippets are very short, they are intermingled with their explanations and it&#8217;s tricky to concentrate on writing the best post with so many distractions in between</li>
</ul>
<h4>Using WP Chili &amp; Enzymes</h4>
<p>Now I&#8217;ll show you a better approach by using together <a href="http://wordpress.org/extend/plugins/wp-chili/" target="_blank">WP Chili</a> 1.0 and <a href="http://wordpress.org/extend/plugins/enzymes/" target="_blank">Enzymes</a> 2.2.<br />
All you need to be up and running is the classical roundtrip: download, unzip, upload, and activate.</p>
<h5>How to highlight code snippets</h5>
<p>You can start by writing a simple enzyme for automating things, like the following <u>hilite</u> custom field: <pre><code class="php">return 
'&lt;pre&gt;&lt;code class=&quot;' . $this-&gt;substrate . '&quot;&gt;'
. htmlspecialchars( $this-&gt;pathway ) 
. '&lt;/code&gt;&lt;/pre&gt;';</code></pre></p>
<p><u>hilite</u> can be used with the following patterns:</p>
<ol>
<li><u>{[ =snippet= | .hilite( =language= ) ]}</u></li>
<li><u>{[ .snippet | .hilite( =language= ) ]}</u></li>
</ol>
<p>The first pattern comes in handy when you want to highlight some very short and naive snippet<br />
<u>{[ =echo htmlentities( $name );= | .hilite( =php= ) ]}</u> renders <pre><code class="php">echo htmlentities( $name );</code></pre></p>
<p>So far, so good, but if the snippet has a character that WP texturizes, then <u>hilite</u> seems to fail. In fact<br />
<u>{[ =$welcome \= "Hello ".$name;= | .hilite( =php= ) ]}</u> renders <pre><code class="php">$welcome = &quot;Hello &quot;.$name;</code></pre></p>
<p>The above issue is not a <u>hilite</u>&#8216;s bug but it could be fixed by adding new code to it, or with new enzymes along the pathway, like the following <u>requote</u> custom field: <pre><code class="php">$from = array( '&amp;#8216;', '&amp;#8217;', '&amp;#8220;', '&amp;#8221;' );
$to = array( &quot;'&quot;, &quot;'&quot;, '&quot;', '&quot;' );
return str_replace( $from, $to, $this-&gt;pathway );</code></pre></p>
<p>which makes that <u><br />
{[ =$welcome \= "Hello ".$name;= | .requote() | .hilite( =php= ) ]}</u> renders <pre><code class="php">$welcome = &quot;Hello &quot;.$name;</code></pre></p>
<p><strong>The best option</strong> is to add another custom field for hosting your snippet and use the second pattern: in fact <u>hilite</u>&#8216;s snippet has been rendered by <u>{[ .hilite | .hilite( =php= ) ]}</u> and <u>requote</u>&#8216;s one by <u>{[ .requote | .hilite( =php= ) ]}</u>.</p>
<h5>How to highlight code files</h5>
<p>Sometimes you have a file that you want to show in its entirety, and having to copy it into a custom field is annoying or maybe not an option, if the file is <em>alive</em>, for example.</p>
<p>In such cases you can use an enzyme like the following <u>file</u> custom field: <pre><code class="php">return file_get_contents( $this-&gt;substrate );</code></pre></p>
<p>It&#8217;s use is again very simple and very similar to the above patterns:<br />
<u>{[ .file( =blog/wp-content/plugins/hello.php= ) | .hilite( =php= ) ]}</u> renders <pre><code class="php"></code></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/how-to-highlight-code-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enzymes 2.2 Released Today</title>
		<link>http://noteslog.com/post/enzymes-22-released-today/</link>
		<comments>http://noteslog.com/post/enzymes-22-released-today/#comments</comments>
		<pubDate>Sat, 01 Mar 2008 14:59:46 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Enzymes]]></category>

		<guid isPermaLink="false">http://noteslog.com/post/enzymes-22-released-today/</guid>
		<description><![CDATA[Changes Added the new feature for transcluding a value, rather than a post/key reference to it (which is still available). This comes in handy when you have a &#8220;normal&#8221; value and it&#8217;s a bit annoying to define a custom field just for that. For example, let&#8217;s say that you have a template called mark-template.php with [...]]]></description>
			<content:encoded><![CDATA[<h5>Changes</h5>
<ul>
<li>Added the new feature for transcluding a value, rather than a post/key reference to it (which is still available). This comes in handy when you have a &#8220;normal&#8221; value and it&#8217;s a bit annoying to define a custom field just for that.</li>
</ul>
<p>For example, let&#8217;s say that you have a template called <u>mark-template.php</u> with the following code:</p>
<p><pre class="chili-all"><code class="html">&lt;span style=&quot;background-color:&lt;?php </code><code class="php">echo $this-&gt;enzyme; </code><code class="html">?&gt;;&quot;&gt;
	&lt;?php </code><code class="php">
		echo $this-&gt;pathway; 
		$this-&gt;pathway = ''; 
	</code><code class="html">?&gt;
&lt;/span&gt;</code></pre>


</p>
<p>Then you could use it <u>{[ =like this= | =cyan= \mark-template.php ]}</u> to get something 
<span style="background-color:cyan;">
	like this</span>
</p>
<h5>Download</h5>
<p>This version is available for <a href="http://wordpress.org/extend/plugins/enzymes/">download</a> from wordpress.org</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/enzymes-22-released-today/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enzymes 2.1 Released Today</title>
		<link>http://noteslog.com/post/enzymes-21-released-today/</link>
		<comments>http://noteslog.com/post/enzymes-21-released-today/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 17:51:27 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Enzymes]]></category>

		<guid isPermaLink="false">http://noteslog.com/post/enzymes-21-released-today/</guid>
		<description><![CDATA[Changes Added the new feature for passing a value as an argument to an evaluation enzyme, rather than a post/key reference to it (which is still available). This comes in handy when you have a &#8220;normal&#8221; value and it&#8217;s a bit annoying to define a custom field just for that. For example, let&#8217;s say that [...]]]></description>
			<content:encoded><![CDATA[<h5>Changes</h5>
<ul>
<li>Added the new feature for passing a value as an argument to an evaluation enzyme, rather than a post/key reference to it (which is still available). This comes in handy when you have a &#8220;normal&#8221; value and it&#8217;s a bit annoying to define a custom field just for that.</li>
</ul>
<p>For example, let&#8217;s say that you have a custom field with the key <u>mark</u> and the following value:</p>
<p><pre class="chili-all"><code class="php">return 
	'&lt;span style=&quot;background-color:yellow;&quot;&gt;' 
		. $this-&gt;substrate 
	. '&lt;/span&gt;';</code></pre></p>
<p>Then you could use it <u>{[ .mark( =like this= ) ]}</u> to get something <span style="background-color:yellow;">like this</span></p>
<h5>Download</h5>
<p>This version is available for <a href="http://wordpress.org/extend/plugins/enzymes/">download</a> from wordpress.org</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/enzymes-21-released-today/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enzymes 2.0 Released Today</title>
		<link>http://noteslog.com/post/enzymes-20-released-today/</link>
		<comments>http://noteslog.com/post/enzymes-20-released-today/#comments</comments>
		<pubDate>Sat, 10 Nov 2007 22:55:43 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Enzymes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://noteslog.com/post/enzymes-20-released-today/</guid>
		<description><![CDATA[Enzymes is a WordPress Plugin for retrieving properties and custom fields of posts, pages, and authors, right into the visual editor of posts and pages, and everywhere else. I&#8217;m releasing now Enzymes 2.0 which is quite a step forward. The features are a new syntax for retrieving properties of posts, pages, and authors; as well [...]]]></description>
			<content:encoded><![CDATA[<p>Enzymes is a WordPress Plugin for retrieving properties and custom fields of posts, pages, and authors, right into the visual editor of posts and pages, and everywhere else.</p>
<p>I&#8217;m releasing now Enzymes 2.0 which is quite a step forward. The features are</p>
<ul>
<li>a new syntax for retrieving properties of posts, pages, and authors; as well as the old syntax for custom fields</li>
<li>a new syntax for identifying posts and pages by means of their slugs; as well as the old syntax with their numbers</li>
<li>a new <u>elaborate</u> method allowing for an easier processing of indirect arguments</li>
<li>a new <u>merging</u> method helping at crafting how the pathway is built by evaluation enzymes</li>
<li>slash and backslash templating uniformly supported by transclusion and evaluation enzymes</li>
<li>a cleaner code</li>
<li><a href="http://noteslog.com/enzymes/">a new manual</a></li>
<li>new examples</li>
</ul>
<h5>A WordPress Plugin</h5>
<p>This version is available for <a href="http://wordpress.org/extend/plugins/enzymes/">download</a> from wordpress.org</p>
<h5>The previous version</h5>
<p>I released Enzymes 1.2 one year ago from mondotondo.com, and re-released it as version 1.3 one month ago from wordpress.org. Both were almost the same thing. Here are the only differences:</p>
<ul>
<li>updated the description header, accounting for the new address (notelog.com)</li>
<li>removed the signals to my server for activation / deactivation of the plugin</li>
<li>packaged as a wordpress plugin, available for download from wordpress.org</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/enzymes-20-released-today/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add semantics to WordPress posts</title>
		<link>http://noteslog.com/post/how-to-add-semantics-to-wordpress-posts/</link>
		<comments>http://noteslog.com/post/how-to-add-semantics-to-wordpress-posts/#comments</comments>
		<pubDate>Fri, 02 Mar 2007 09:49:35 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Enzymes]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=151</guid>
		<description><![CDATA[Browsing the WordPress&#8217; ideas repository I&#8217;ve found one that could make WordPress fill the gap between a blog tool and a knowledge base: Structured Blogging. The fact that it got 60 votes but only 50% stars means two things: voting people are lazy thinkers it&#8217;s a difficult task at many levels Nonetheless it&#8217;s a good [...]]]></description>
			<content:encoded><![CDATA[<p>Browsing the WordPress&#8217; <a href="http://wordpress.org/extend/ideas/" target="_blank">ideas repository</a> I&#8217;ve found one that could make <a href="http://wordpress.org/" target="_blank">WordPress</a> fill the gap between a blog tool and a knowledge base: <a href="http://wordpress.org/extend/ideas/topic.php?id=217" target="_blank">Structured Blogging</a>.</p>
<p>The fact that it got 60 votes but only 50% stars means two things:</p>
<ol>
<li>voting people are lazy thinkers</li>
<li>it&#8217;s a difficult task at many levels</li>
</ol>
<p>Nonetheless it&#8217;s a good idea because this is and will be for many years to come the blogging era, where millions of authors <strong>post</strong> content to the Internet. There is no good reason for that content to be unstructured except lazyness and complexity.</p>
<p>Nothing can be done about lazyness but complexity can be substantially reduced. The solution needs:</p>
<ul>
<li>a mechanism for adding XML tags from some dictionary</li>
<li>a template system for showing XML content appropiately</li>
</ul>
<p>On the path to something readily usable (I hope Matt will provide it in WordPress 3.0), a mechanism could be a <a href="http://docs.jquery.com/Plugins" target="_blank">jQuery plugin</a> for the visual editor, and a template system could be based on <a href="/?page_id=77" target="_blank">Enzymes</a>.</p>
<h4>Autocompletion</h4>
<p>I think that <a href="http://tinymce.moxiecode.com/" target="_blank">tinyMCE</a> can be extended by plugins, but I don&#8217;t know how to. <a href="http://jquery.com/" target="_blank">jQuery</a> itself has an <a href="http://www.dyve.net/jquery/?autocomplete" target="_blank">autocompletion plugin</a> that could be used this way. When an author presses a &lt; key, the <a href="http://en.wikipedia.org/wiki/Autocompletion" target="_blank">autocompletion</a> gets triggered and the popup &#8230; pops up :-)</p>
<p>If you have ever used <a href="http://www.microsoft.com/windows/ie/ie6/downloads/recommended/ime/default.mspx" target="_blank">IME</a> (for Japanese for example), you should know what I mean. Options are organized in a hierarchy and you get the most relevant at the top, depending on the few characters already typed. XML dictionaries could be ajaxed and locally cached; they could be plugins that you install into your blog, or be web services too; they could be <a href="http://dublincore.org/" target="_blank">international standards</a> compliant or be completely custom.</p>
<p>The most-relevant-first feature of the autocompletion popup would be a big help for authors. If I already opened a Tag, then the most relevant options after pressing &lt; could be:</p>
<ol>
<li>the closing tag for that Tag</li>
<li>any tag that could be inside that Tag (properly sorted if needed)</li>
<li>any root of the cached dictionaries (if possible in Tag)</li>
<li>an option for accessing additional dictionaries (if possible in Tag)</li>
</ol>
<h4>Templates</h4>
<p>A PHP template for properly rendering XML content is very easy to write, and Enzymes could be used in the clockwork. In fact an Enzymes feature is the possibility of easily transcluding all the content of a post or a page by means of the special char *</p>
<p>The XML to HTML template can be transformed in an Enzymes template with a couple of PHP instructions, thus allowing you to almost copy and paste already available templates. Then you could apply a solution like this:</p>
<ol>
<li>write a private post or page with the XML content, using the autocompletion feature described above (say this post is #123)</li>
<li>write a public post or page with the Enzymes statement {[123.* /template.php]} in its content</li>
</ol>
<p>The post in 1. needs to be private because you don&#8217;t want it to appear on the blog as is, and 2. makes the transformation happen. As an added benefit, you can display that semantic content inside of a greater context, and you can transclude it wherever you want in your WordPress blog (as many times as you like).</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/how-to-add-semantics-to-wordpress-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Highlight Mixed Language Source Code</title>
		<link>http://noteslog.com/post/mixed-language-snippets/</link>
		<comments>http://noteslog.com/post/mixed-language-snippets/#comments</comments>
		<pubDate>Fri, 16 Feb 2007 15:35:29 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Chili]]></category>
		<category><![CDATA[Enzymes]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=143</guid>
		<description><![CDATA[Web pages contain many snippets from different languages, like HTML, PHP, CSS, and JavaScript. Chili 1.x cannot highlight mixed language source code automatically, but the forthcoming released Chili 2.0 will be is able to do that. Meanwhile, if you are using a Chili + Enzymes setup, then it&#8217;s possible to write an Enzymes template capable [...]]]></description>
			<content:encoded><![CDATA[<p>Web pages contain many snippets from different languages, like HTML, PHP, CSS, and JavaScript. Chili 1.x cannot highlight mixed language source code automatically, but the <span style="text-decoration: line-through;">forthcoming</span> released <a href="http://noteslog.com/post/chili-20-released-today/">Chili 2.0</a> <span style="text-decoration: line-through;">will be</span> is able to do that.</p>
<p>Meanwhile, if you are using a Chili + Enzymes setup, then it&#8217;s possible to write an Enzymes template capable of making Chili 1.x highlight a web page perfectly (expanding on my previous php template).</p>
<p>Here is the <span style="text-decoration: line-through;">new</span> updated (2007/02/19) <span style="text-decoration: underline;">chili-web.php</span> Enzymes template. At the moment it supports XHTML, and embedded CSS, JavaScript, and PHP snippets.</p>
<p><?php 
if( ! function_exists( 'format_code' ) ) {

	function snippet_wrap( $class, $code ) {
		return '' == $code ? '' : '<code class="'.$class.'">'.htmlentities( $code ).'</code>';
	}

	function snippet_php( $open, $code, $close ) {
		return snippet_wrap( 'html', $open ).snippet_wrap( 'php', $code ).snippet_wrap( 'html', $close );
	}

	function php_inside_html( $matches ) {
		list( $all, $before, $open, $code, $close ) = $matches;

		if( '' == $open ) 
			return snippet_wrap( 'html', $all );
		else 
			return snippet_wrap( 'html', $before ).snippet_php( $open, $code, $close );
	}

	function php_inside_css( $matches ) {
		list( $all, $before, $open, $code, $close ) = $matches;

		if( '' == $open ) 
			return snippet_wrap( 'css', $all );
		else 
			return snippet_wrap( 'css', $before ).snippet_php( $open, $code, $close );
	}

	function php_inside_javascript( $matches ) {
		list( $all, $before, $open, $code, $close ) = $matches;

		if( '' == $open ) 
			return snippet_wrap( 'javascript', $all );
		else 
			return snippet_wrap( 'javascript', $before ).snippet_php( $open, $code, $close );
	}

	function php_inside( $class, $code ) {
		return preg_replace_callback( '/(?:(.*?)(\<\?php\s)(.*?)(\?\>))|(?:.+)/si', "php_inside_$class", $code );
	}

	function snippet_web( $class, $open, $code, $close ) {
		return snippet_wrap( 'html', $open ).php_inside( $class, $code ).snippet_wrap( 'html', $close );
	}

	function format_code( $matches ) {
		list( $all, $before, $open, $tag, $code, $close ) = $matches;

		if( '' == $open ) {
			return php_inside( 'html', $all );
		}
		else {
			switch( $tag ) {
				case 'script': $class = 'javascript'; break;
				case 'style' : $class = 'css';        break;
				default      : $class = 'html';
			}
			return php_inside( 'html', $before ).snippet_web( $class, $open, $code, $close );
		}
	}

	function format_clean( $out ) {
		do {
			$len = strlen( $out );
			$out = preg_replace( '/(\<code class="(\w+)"\>[^<]*)\<\/code\>\<code class="\2"\>/is', '$1', $out );
		} while( $len != strlen( $out ) );
		return $out;
	}
}

?>
<pre class="chili-<?php 
	$tmp = preg_split( '/(?:\r?\n)+/', $this->result );
	if( count( $tmp ) > 28 ) echo 'clip';
	else echo 'all'; 
?>"><?php
	$out = preg_replace_callback( '/(?:(.*?)(\<(script|style)\b.*?\>)(.*?)(\<\/\3\>))|(?:.+)/is', 'format_code', $this->result );
	echo format_clean( $out );
?></pre></p>
<p>The WordPress file <span style="text-decoration: underline;">/wp-content /themes /default /comments-popup.php</span> is a page that uses all the supported languages, so it&#8217;s a good test for the previous template:</p>
<p><?php
/* Don't remove these lines. */
add_filter('comment_text', 'popuplinks');
while ( have_posts()) : the_post();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <title><?php echo get_option('blogname'); ?> - Comments on <?php the_title(); ?></title>

	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
	<style type="text/css" media="screen">
		@import url( <?php bloginfo('stylesheet_url'); ?> );
		body { margin: 3px; }
	</style>

</head>
<body id="commentspopup">

<h1 id="header"><a href="" title="<?php echo get_option('blogname'); ?>"><?php echo get_option('blogname'); ?></a></h1>

<h2 id="comments">Comments</h2>

<p><a href="<?php echo get_option('siteurl'); ?>/wp-commentsrss2.php?p=<?php echo $post->ID; ?>"><abbr title="Really Simple Syndication">RSS</abbr> feed for comments on this post.</a></p>

<?php if ('open' == $post->ping_status) { ?>
<p>The <abbr title="Universal Resource Locator">URL</abbr> to TrackBack this entry is: <em><?php trackback_url() ?></em></p>
<?php } ?>

<?php
// this line is WordPress' motor, do not delete it.
$commenter = wp_get_current_commenter();
extract($commenter);
$comments = get_approved_comments($id);
$post = get_post($id);
if (!empty($post->post_password) && $_COOKIE['wp-postpass_'. COOKIEHASH] != $post->post_password) {  // and it doesn't match the cookie
	echo(get_the_password_form());
} else { ?>

<?php if ($comments) { ?>
<ol id="commentlist">
<?php foreach ($comments as $comment) { ?>
	<li id="comment-<?php comment_ID() ?>">
	<?php comment_text() ?>
	<p><cite><?php comment_type('Comment', 'Trackback', 'Pingback'); ?> by <?php comment_author_link() ?> â€” <?php comment_date() ?> @ <a href="#comment-<?php comment_ID() ?>"><?php comment_time() ?></a></cite></p>
	</li>

<?php } // end for each comment ?>
</ol>
<?php } else { // this is displayed if there are no comments so far ?>
	<p>No comments yet.</p>
<?php } ?>

<?php if ('open' == $post->comment_status) { ?>
<h2>Leave a comment</h2>
<p>Line and paragraph breaks automatic, e-mail address never displayed, <acronym title="Hypertext Markup Language">HTML</acronym> allowed: <code><?php echo allowed_tags(); ?></code></p>

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
	<p>
	  <input type="text" name="author" id="author" class="textarea" value="<?php echo $comment_author; ?>" size="28" tabindex="1" />
	   <label for="author">Name</label>
	<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
	<input type="hidden" name="redirect_to" value="<?php echo attribute_escape($_SERVER["REQUEST_URI"]); ?>" />
	</p>

	<p>
	  <input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="28" tabindex="2" />
	   <label for="email">E-mail</label>
	</p>

	<p>
	  <input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="28" tabindex="3" />
	   <label for="url"><abbr title="Universal Resource Locator">URL</abbr></label>
	</p>

	<p>
	  <label for="comment">Your Comment</label>
	<br />
	  <textarea name="comment" id="comment" cols="70" rows="4" tabindex="4"></textarea>
	</p>

	<p>
	  <input name="submit" type="submit" tabindex="5" value="Say It!" />
	</p>
	<?php do_action('comment_form', $post->ID); ?>
</form>
<?php } else { // comments are closed ?>
<p>Sorry, the comment form is closed at this time.</p>
<?php }
} // end password check
?>

<div><strong><a href="javascript:window.close()">Close this window.</a></strong></div>

<?php // if you delete this the sky will fall on your head
endwhile;
?>

<!-- // this is just the end of the motor - don't touch that line either :) -->
<?php //} ?>
<p class="credit"><?php timer_stop(1); ?> <cite>Powered by <a href="http://wordpress.org/" title="Powered by WordPress, state-of-the-art semantic personal publishing platform"><strong>WordPress</strong></a></cite></p>
<?php // Seen at http://www.mijnkopthee.nl/log2/archive/2003/05/28/esc(18) ?>
<script type="text/javascript">
<!--
document.onkeypress = function esc(e) {
	if(typeof(e) == "undefined") { e=event; }
	if (e.keyCode == 27) { self.close(); }
}
// -->
</script>
</body>
</html></p>
<p>Chili &amp; Enzymes confirm to be a perfect match.</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/mixed-language-snippets/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>An enzyme for transcluding a web page</title>
		<link>http://noteslog.com/post/an-enzyme-for-transcluding-a-web-page/</link>
		<comments>http://noteslog.com/post/an-enzyme-for-transcluding-a-web-page/#comments</comments>
		<pubDate>Sat, 10 Feb 2007 16:35:33 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Enzymes]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=129</guid>
		<description><![CDATA[Enzymes can be complex PHP scripts, but basic enzymes are also very useful. This one is a oneliner, and it allows to transclude aÂ web page inside a post. Really all the magic is played by an IFRAME element, but Enzymes makes it easy to use the method over and over, without any need to remember: [...]]]></description>
			<content:encoded><![CDATA[<p>Enzymes can be complex PHP scripts, but basic enzymes are also very useful. This one is a oneliner, and it allows to transclude aÂ web page inside a post. Really all the magic is played by an IFRAME element, but Enzymes makes it easy to use the method over and over, without any need to remember: &#8220;how did I do it?&#8221;</p>
<p> this is got by the statement <u>{[.page(.google)]}</u></p>
<p> this is got by the statement <u>{[.page(.yahoo)]}</u></p>
<p>Here is the code for the <u>page</u> field:</p>
<blockquote><p>echo "<iframe width='450' height='200' src='" . $this->substrate . "'></iframe>";</p></blockquote>
<p>Here is the code for the <u>google</u> and <u>yahoo</u> fields respectively:</p>
<blockquote><p>http://www.google.com/<br />
http://www.yahoo.com/</p></blockquote>
<p>Easy, isn&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/an-enzyme-for-transcluding-a-web-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enzymes 1.2 Released Today</title>
		<link>http://noteslog.com/post/enzymes-12-released-today/</link>
		<comments>http://noteslog.com/post/enzymes-12-released-today/#comments</comments>
		<pubDate>Mon, 25 Dec 2006 14:48:01 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Enzymes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=96</guid>
		<description><![CDATA[Changes Fixed a bug inÂ the metabolism outside a post. For example,Â a title transcluding a custom fieldÂ by means of anÂ implicit reference rendered correctly when viewing the post but not when the title appeared in a list of post titles. Files download all in a zip read the manual]]></description>
			<content:encoded><![CDATA[<p><strong>Changes</strong></p>
<ul>
<li>Fixed a bug inÂ the metabolism outside a post. For example,Â a title transcluding a custom fieldÂ by means of anÂ implicit reference rendered correctly when viewing the post but not when the title appeared in a list of post titles.</li>
</ul>
<p><strong>Files</strong></p>
<ul>
<li><a href="/personal/projects/enzymes/1.2/enzymes-1.2-all.zip" onclick="javascript:urchinTracker('/downloads/enzymes-1.2');">download all in a zip</a></li>
<li><a href="/enzymes/">read the manual</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/enzymes-12-released-today/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>AdSense Enzymes</title>
		<link>http://noteslog.com/post/adsense-enzymes/</link>
		<comments>http://noteslog.com/post/adsense-enzymes/#comments</comments>
		<pubDate>Wed, 06 Dec 2006 08:26:39 +0000</pubDate>
		<dc:creator>Andrea Ercolino</dc:creator>
				<category><![CDATA[Enzymes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://noteslog.com/?p=93</guid>
		<description><![CDATA[AdSense Enzymes areÂ very simple. At the simplest level of abstraction, I can directly trascludeÂ the custom fieldÂ whichÂ I&#8217;ve stored the ad code into. AndÂ I can doÂ itÂ either byÂ means ofÂ a statement into the content of a post or a page, or byÂ means of a call to the metabolize function (available in Enzymes 1.1)Â into the php code of a WordPress [...]]]></description>
			<content:encoded><![CDATA[<p>AdSense Enzymes areÂ very simple.</p>
<p>At the simplest level of abstraction, I can directly trascludeÂ the custom fieldÂ whichÂ I&#8217;ve stored the ad code into. AndÂ I can doÂ itÂ either byÂ means ofÂ a statement into the content of a post or a page, or byÂ means of a call to the metabolize function (available in Enzymes 1.1)Â into the php code of a WordPress template file.</p>
<p>The former methodÂ isÂ useful when I want to place an ad unit in a particular/variable position inside the content of a post or a page; the latter method is useful when I want to place an ad unit in a general/constant position inside the blog.</p>
<p>For example, if I put the statement <u>{[1.ad001]}</u> here,Â itÂ would reproduce by itselfÂ the ad unit right here, becauseÂ in the firstÂ postÂ I&#8217;ve storedÂ the ad codeÂ inÂ a custom field called <u>ad001</u>. But toÂ makeÂ the ad unitÂ appear before any post, IÂ need toÂ find the line in the <u>index.php</u> file of my default theme that reads</p>
<p><?php if (have_posts()) : ?></p>
<p>and replace it with this line</p>
<p><?php metabolize( "{[1.ad001]}" ); if (have_posts()) : ?></p>
<p>Taking theÂ abstraction one step further,Â I&#8217;d like to storeÂ the string <u>1.ad001</u> in a new <u>home</u> field, so that I can provide a separation layer that makes it possible for me to replace the ad code simply by changing the content ofÂ a field, rather than having to change the phpÂ file again.</p>
<p>Indirect transclusion is not directly available inÂ Enzymes, but it can be easily achieved by means of a simple enzyme like this</p>
<p>preg_match( '/'.$this->e['substrate'].'/', $this->substrate, $matches );
return $this->item( $matches['sub_id'], $matches['sub_key'] );</p>
<p>I&#8217;ve called this enzyme <u>get</u>, and I&#8217;ve put it intoÂ the first post.Â So the Enzymes statement becomes <u>{[1.get(1.home)]}</u> and theÂ edited line for the <u>index.php</u> file becomes</p>
<p><?php metabolize( "{[1.get(1.home)]}" ); if (have_posts()) : ?></p>
<p>I&#8217;m currently using the latter for my blog home, so I don&#8217;t have to worry about placing ads every time I post a new log, andÂ the former for my pages, so that I can place the ads insdide the content, in a position that I hope will fit better.</p>
<p>Why does Google <a href="https://www.google.com/adsense/support/bin/answer.py?answer=10541&#038;topic=8437" target="_blank">limit to three</a> the number of ad units per page? Is it a technical reason?</p>
<p>Â </p>
]]></content:encoded>
			<wfw:commentRss>http://noteslog.com/post/adsense-enzymes/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

