<?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; extending</title>
	<atom:link href="http://www.marcus-povey.co.uk/tag/extending/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>Mon, 06 Feb 2012 19:13:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<atom:link rel='hub' href='http://www.marcus-povey.co.uk/?pushpress=hub'/>
		<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>
<div class="wsbuttons">
	<div class="shareblob facebook">
		<div class="fb-like" data-href="http://www.marcus-povey.co.uk/2009/05/08/extendin-actions-in-elgg/" data-send="false" data-layout="box_count" data-width="60" data-show-faces="false" data-colorscheme="light"></div>
	</div>

	<div class="shareblob google">
		<div class="g-plusone" data-size="tall" data-href="http://www.marcus-povey.co.uk/2009/05/08/extendin-actions-in-elgg/"></div>
	</div>

	<div class="shareblob twitter">
		<div class="twitter">
			<a href="https://twitter.com/share?url=http%3A%2F%2Fwww.marcus-povey.co.uk%2F2009%2F05%2F08%2Fextendin-actions-in-elgg%2F&count=vertical" class="twitter-share-button" data-lang="en">Tweet</a>
			<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
		</div>
	</div>

</div>
	]]></content:encoded>
			<wfw:commentRss>http://www.marcus-povey.co.uk/2009/05/08/extendin-actions-in-elgg/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

