<?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>Marcus Povey &#187; processing</title>
	<atom:link href="http://www.marcus-povey.co.uk/tag/processing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marcus-povey.co.uk</link>
	<description>Making the world a better place, one byte at a time...</description>
	<lastBuildDate>Fri, 16 Jul 2010 09:00:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<atom:link rel='hub' href='http://www.marcus-povey.co.uk/?pushpress=hub'/>
		<item>
		<title>Post processing Elgg views &#8211; Trac tags example</title>
		<link>http://www.marcus-povey.co.uk/2009/07/06/post-processing-elgg-views-trac-tags-example/</link>
		<comments>http://www.marcus-povey.co.uk/2009/07/06/post-processing-elgg-views-trac-tags-example/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 09:43:29 +0000</pubDate>
		<dc:creator>Marcus Povey</dc:creator>
				<category><![CDATA[elgg]]></category>
		<category><![CDATA[#ue]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugin hook]]></category>
		<category><![CDATA[post processing]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[trac]]></category>
		<category><![CDATA[views]]></category>

		<guid isPermaLink="false">http://www.marcus-povey.co.uk/?p=232</guid>
		<description><![CDATA[There are a number of ways that an Elgg plugin developer can manipulate views via the powerful Elgg views system. Most Elgg programmers are by now familiar with extending or replacing existing views, or providing new views for new objects etc. But what if you just wanted to make a simple tweak to an existing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://trac.edgewall.org"><img title="Trac_Logo_512x512" src="http://www.marcus-povey.co.uk/wp-content/Trac_Logo_512x512-150x150.png" alt="Trac_Logo_512x512" width="150" height="150" align="right" /></a>There are a number of ways that an Elgg plugin developer can manipulate views via the powerful <a href="http://docs.elgg.org/wiki/Views">Elgg views system</a>.</p>
<p>Most Elgg programmers are by now familiar with <a href="http://docs.elgg.org/wiki/Views#Extending_views">extending</a> or replacing existing views, or providing new views for new objects etc.</p>
<p>But what if you just wanted to make a simple tweak to an existing view &#8211; for example to replace all instances of rude words in a feed article, or to turn passive links into active ones?</p>
<p>Well, fortunately Elgg provides a post processing hook for views which can do just that.</p>
<p>After every view has been generated, the framework will trigger a <a href="http://docs.elgg.org/wiki/PluginHooks">plugin hook</a> called &#8220;&#8216;display&#8217;, &#8216;view&#8217;&#8221;. This hook is passed a parameter &#8216;view&#8217; which contains the name of the view being processed (eg. object/blog).</p>
<p>The contents of the view are passed in the <code>$returnvalue</code> variable which you can perform any processing on before returning it from the hook.</p>
<p>I have just uploaded a <a href="http://community.elgg.org/pg/plugins/marcus/read/168854/trac-tags">Trac tags plugin</a> to the <a href="http://community.elgg.org">Elgg community</a> site which provides a good example of this.</p>
<p>The Trac tags plugin is a tiny plugin which uses the views post processing hook to turn <a href="http://trac.edgewall.org">Trac</a> links (e.g. #xxxxx for tickets and [xxxxx] for changesets) into active links into your repository, and here&#8217;s how &#8211; first we register the hook:</p>
<blockquote><p><code>function tractags_init()<br />
{<br />
....<br />
// Register our post processing hook<br />
register_plugin_hook('display', 'view', 'tractags_rewrite');</code></p>
<p><code><br />
// define views we want to rewrite codes on (means we don't have to process *everything*)<br />
$CONFIG-&gt;tractags_views = array(<br />
'object/thewire',<br />
'object/blog'<br />
);</code></p>
<p><code> ....<br />
}</code></p></blockquote>
<p>Then in our handler looks something like this:</p>
<blockquote><p><code>function tractags_rewrite($hook, $entity_type, $returnvalue, $params)<br />
{<br />
global $CONFIG;</code></p>
<p><code>$view = $params['view'];</code></p>
<p><code>if (($view) &amp;&amp; (in_array($view, $CONFIG-&gt;tractags_views)))<br />
{<br />
// Search and replace ticket numbers<br />
$returnvalue =  preg_replace_callback('/(#)([0-9]+)/i',<br />
create_function(<br />
'$matches',<br />
'<br />
global $CONFIG;</code></p>
<p><code>return "&lt;a href=\"{$CONFIG-&gt;trac_baseurl}ticket/{$matches[2]}\"&gt;{$matches[0]}&lt;/a&gt;";<br />
'<br />
), $returnvalue);</code></p>
<p><code>// Search and replace changesets<br />
$returnvalue =  preg_replace_callback('/(\[)([0-9]+)(\])/i',<br />
create_function(<br />
'$matches',<br />
'<br />
global $CONFIG;</code></p>
<p><code>return "&lt;a href=\"{$CONFIG-&gt;trac_baseurl}changeset/{$matches[2]}\"&gt;{$matches[0]}&lt;/a&gt;";<br />
'<br />
), $returnvalue);</code></p>
<p><code>return $returnvalue;<br />
}<br />
}</code></p></blockquote>
<p>I&#8217;m sure you will be able to come up with some much more interesting uses!</p>
<p><small>Image from the <a href="http://trac.edgewall.org">Trac project</a>.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcus-povey.co.uk/2009/07/06/post-processing-elgg-views-trac-tags-example/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
