<?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; extend</title>
	<atom:link href="http://www.marcus-povey.co.uk/tag/extend/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>Loosely coupled Elgg extensions (Captcha example)</title>
		<link>http://www.marcus-povey.co.uk/2009/06/15/loosely-coupled-elgg-extensions-captcha-example/</link>
		<comments>http://www.marcus-povey.co.uk/2009/06/15/loosely-coupled-elgg-extensions-captcha-example/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 16:41:07 +0000</pubDate>
		<dc:creator>Marcus Povey</dc:creator>
				<category><![CDATA[elgg]]></category>
		<category><![CDATA[#ue]]></category>
		<category><![CDATA[actions]]></category>
		<category><![CDATA[captcha]]></category>
		<category><![CDATA[extend]]></category>
		<category><![CDATA[hooks]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://www.marcus-povey.co.uk/?p=206</guid>
		<description><![CDATA[One thing we try and do when working on a new Elgg feature is &#8211; where we can &#8211; couple things together as loosely as possible and provide hooks for third party developers to extend Elgg and fill in any blanks. A good example of where this has been done is the newly introduced Captcha [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://xkcd.com/233/"><img src="http://www.marcus-povey.co.uk/wp-content/a_new_captcha_approach.png" border="0" alt="A new CAPTCHA approach" width="300" align="right" /></a>One thing we try and do when working on a new Elgg feature is &#8211; where we can &#8211; <a href="http://en.wikipedia.org/wiki/Coupling_(computer_science)">couple things together as loosely as possible</a> and provide hooks for third party developers to extend Elgg and fill in any blanks.</p>
<p>A good example of where this has been done is the newly introduced <a href="http://en.wikipedia.org/wiki/Captcha">Captcha</a> functionality available in the latest <a href="http://www.elgg.org/download/nightly/">nightly testing builds of Elgg</a>.</p>
<p>The Captcha functionality is provided by a module which extends a view called &#8220;<a href="https://code.elgg.org/elgg/trunk/views/default/input/captcha.php">input/captcha</a>&#8220;. This view is blank by default but is used in several places such as user registration and the lost password form.</p>
<p>This means two things; firstly that if a Captcha module isn&#8217;t installed or enabled then forms behave normally, and secondly it becomes a trivial matter for third party modules to provide their own Captcha functionality.</p>
<p>This same mechanism is how the <a href="http://community.elgg.org/pg/plugins/marcus/read/142964/example-url-shortening-service-using-3lacc">URL shortener module</a> works by the way.</p>
<p>Next, the Captcha module <a href="http://www.marcus-povey.co.uk/2009/05/08/extendin-actions-in-elgg/">extends a number of actions</a> to require a correctly validated Captcha code. This list itself is the product of a <a href="http://docs.elgg.org/wiki/PluginHooks">plugin hook</a> which returns an array of actions which require Captcha validation:</p>
<blockquote><p><code>$actions = array();<br />
$actions = trigger_plugin_hook('actionlist', 'captcha', null, $actions);</code></p></blockquote>
<blockquote><p><code>...</code></p></blockquote>
<blockquote><p><code>function captcha_actionlist_hook($hook, $entity_type, $returnvalue, $params)<br />
{<br />
if (!is_array($returnvalue))<br />
$returnvalue = array();</code></p>
<p><code>$returnvalue[] = 'register';<br />
$returnvalue[] = 'user/requestnewpassword';</code></p>
<p><code>return $returnvalue;<br />
}</code></p></blockquote>
<p>The reason why the list of actions is provided this way is twofold, firstly it lets modules use Captcha functionality in their own code through a generic interface, and secondly it is harder to spoof than looking for some marker in the form code.</p>
<p>The Captcha itself injects a server generated token into the form, which together with the user&#8217;s response to the characters generated in an image are used to validate that the user is indeed human.</p>
<p>As we can see, Elgg asks to be provided with a Captcha if one is available by including a specific view, but is agnostic as to where (or indeed if) this functionality is supplied.</p>
<p>By using the techniques available to an Elgg programmer I was able to loosely couple the Captcha system to Elgg in such a way that a third party can easily use the same techniques to provide a more advanced module.</p>
<p>Happy coding!</p>
<p><small>Image &#8220;<a href="http://xkcd.com/233/">A new Captcha approach</a>&#8221; by <a href="http://www.xkcd.com">XKCD</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcus-povey.co.uk/2009/06/15/loosely-coupled-elgg-extensions-captcha-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
