<?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; actions</title>
	<atom:link href="http://www.marcus-povey.co.uk/tag/actions/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>
		<item>
		<title>Extending actions in Elgg</title>
		<link>http://www.marcus-povey.co.uk/2009/05/08/extendin-actions-in-elgg/</link>
		<comments>http://www.marcus-povey.co.uk/2009/05/08/extendin-actions-in-elgg/#comments</comments>
		<pubDate>Fri, 08 May 2009 17:01:22 +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[extending]]></category>
		<category><![CDATA[overriding]]></category>

		<guid isPermaLink="false">http://www.marcus-povey.co.uk/?p=188</guid>
		<description><![CDATA[Those eagle-eyed developers who have been tracking the Elgg core SVN may have noticed that I have recently committed a bunch of captcha related changes, including a simple captcha module. I just thought I&#8217;d write a quick post about it as this module makes use of a bit of Elgg functionality which has been around [...]]]></description>
			<content:encoded><![CDATA[<p>Those eagle-eyed developers who have been tracking the Elgg core SVN may have noticed that I have recently committed a bunch of <a href="http://en.wikipedia.org/wiki/Captcha">captcha</a> related changes, including a simple captcha module.</p>
<p>I just thought I&#8217;d write a quick post about it as this module makes use of a bit of Elgg functionality which has been around for a while, but that I know a number of plugin developers have missed.</p>
<p>Namely, the ability to extend actions.</p>
<p>When the Elgg framework calls an <a href="http://docs.elgg.org/wiki/Actions">action</a> the Action handler triggers a <a href="http://docs.elgg.org/wiki/PluginHooks">plugin hook</a> called &#8220;action&#8221; before executing the action itself. This hook looks like this:</p>
<blockquote><p><code>$event_result = true;<br />
$event_result = trigger_plugin_hook('action', $action, null, $event_result);</code></p></blockquote>
<p>Where <code>$action</code> is the action being called. If the hook returns false then the main action will not be executed.</p>
<p>The captcha module uses this to intercept the <code>register</code> and <code>user/requestnewpassword</code> actions and redirect them to a function which checks the captcha code. This check returns true if valid or false if not (which prevents the associated action from executing).</p>
<p>This is done as follows:</p>
<blockquote><p><code>register_plugin_hook("action", "register", "captcha_verify_action_hook");<br />
register_plugin_hook("action", "user/requestnewpassword", "captcha_verify_action_hook");</code></p>
<p><code>.<br />
.<br />
.</code></p>
<p><code>function captcha_verify_action_hook($hook, $entity_type, $returnvalue, $params)<br />
{<br />
$token = get_input('captcha_token');<br />
$input = get_input('captcha_input');</code></p>
<p><code> if (($token) &amp;&amp; (captcha_verify_captcha($input, $token)))<br />
return true;</code></p>
<p><code> register_error(elgg_echo('captcha:captchafail'));</code></p>
<p><code> return false;<br />
}<br />
</code></p></blockquote>
<p>As you can see, this lets a plugin extend an existing action without the need to replace the action itself. In the case of the captcha plugin it allows the plugin to provide captcha support in a very loosely coupled way.</p>
<p>Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcus-povey.co.uk/2009/05/08/extendin-actions-in-elgg/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
