<?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>JamieRF &#187; fluxbb</title>
	<atom:link href="http://www.jamierf.co.uk/tag/fluxbb/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jamierf.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 04 Jun 2010 11:20:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Extensible PHP software: Hooks &amp; patches</title>
		<link>http://www.jamierf.co.uk/2010/02/08/extensible-php-software-hooks-patches/</link>
		<comments>http://www.jamierf.co.uk/2010/02/08/extensible-php-software-hooks-patches/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 18:32:41 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fluxbb]]></category>
		<category><![CDATA[open-source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.jamierf.co.uk/?p=321</guid>
		<description><![CDATA[In thinking about FluxBB 2.0, one of the important goals is to come up with a well designed and easy to use extension system. The days of manually digging into the code are past, people now expect to be able to install an extension with one click. In PunBB 1.3 (which we forked into FluxBB [...]]]></description>
			<content:encoded><![CDATA[<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> <p>In thinking about FluxBB 2.0, one of the important goals is to come up with a well designed and easy to use extension system. The days of manually digging into the code are past, people now expect to be able to install an extension with one click.</p>
<p>In PunBB 1.3 (which we forked into FluxBB 1.3 Legacy), Rickard introduced the use of hooks and eval, to allow extensions to insert code and extend the core software. Originally this system was designed to allow small changes, but by the time the software was finished it had mutated into a full blown extension system.</p>
<p>Along with the disadvantages inherent from a hook system (see below), FluxBB 1.3 Legacy used a rather horrible system of PHP code within XML code, which was parsed and inserted into the database on install. The aim was that then the install files could be deleted or overwritten and the extension wouldn&#8217;t be affected until it was uninstalled/updated. However due to the fact that most extensions referenced external files (be it included php files, or css and images) this theory did not work very well.</p>
<p>So, going back to the beginning, what are the different solutions available for writing extensible PHP software?</p>
<p><span id="more-321"></span></p>
<h3>Hooks</h3>
<p>Hooks are probably the most common way used to make PHP software extensible. The idea is fairly simple; throughout the code there are &#8220;hooks&#8221;, where extensions can insert code. Below is an example hook taken from FluxBB 1.3 Legacy:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;color: #FCFFBA;color: black;"><span style="color: #b1b100;color: #B83A24;">if</span> <span style="color: #009900;color: #000;">&#40;</span><span style="color: #990000;color: #B83A24;">isset</span><span style="color: #009900;color: #000;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;color: #000;">&#91;</span><span style="color: #0000ff;">'form_sent'</span><span style="color: #009900;color: #000;">&#93;</span><span style="color: #009900;color: #000;">&#41;</span><span style="color: #009900;color: #000;">&#41;</span>
<span style="color: #009900;color: #000;">&#123;</span>
	<span style="color: #009900;color: #000;">&#40;</span><span style="color: #000088;">$hook</span> <span style="color: #339933;color: #000;">=</span> get_hook<span style="color: #009900;color: #000;">&#40;</span><span style="color: #0000ff;">'po_form_submitted'</span><span style="color: #009900;color: #000;">&#41;</span><span style="color: #009900;color: #000;">&#41;</span> ? <span style="color: #990000;color: #B83A24;">eval</span><span style="color: #009900;color: #000;">&#40;</span><span style="color: #000088;">$hook</span><span style="color: #009900;color: #000;">&#41;</span> <span style="color: #339933;color: #000;">:</span> <span style="color: #009900; font-weight: bold;color: #343832;">null</span><span style="color: #339933;color: #000;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;color: green;">// Make sure form_user is correct</span></pre></div></div>

<p>In the above example the get_hook method will look for all the code which has been registered with the hook &#8220;po_form_submitted&#8221;, combine it and return it. The code will then be executed using the <a href="http://uk2.php.net/manual/en/function.eval.php">eval</a> function.</p>
<p>The disadvantages of the hook system should be fairly obvious&#8230;</p>
<ul>
<li><span style="background-color: #ffffff;">Blocks of code can be inserted, but only at pre defined locations within the software. This means extra thought has to be given during development as to where hooks may be required. If someone writing an extension needs a hook in a place where there isn&#8217;t one, then they are out of luck.</span></li>
<li><span style="background-color: #ffffff;">Insertion of code is all very well, but what if we want to change or remove some existing code? There is no way to do this using hooks. This leads to extensions with rather &#8220;interesting&#8221; algorithms to attempt to undo or block code in the core, which can be both messy and inefficient.</span></li>
</ul>
<p>Despite these rather major sounding disadvantages, I would argue hooks are good! At least much better than requiring users to change code by hand&#8230;</p>
<p>In the example code given above the eval function was used to execute the inserted code, but where is the code actually stored, and is this the best way to execute it? There are a few options:</p>
<ul>
<li>Store the code in a database or XML etc. then load and eval it when required. This probably isn&#8217;t the best solution as it involves storing code in the database or other storage that isn&#8217;t designed for code. Caching would probably also be required, loading and parsing a large XML file on every page load would not be efficient.</li>
<li>Keep the code for each hook in an individual PHP file and include it when required. This option seems reasonable, but could result in having a huge amount of tiny files being included, which could be hard to organize and may not be ideal if the server isn&#8217;t running any form of opcode cache.</li>
<li>Keep the code all in one PHP file and register specific functions with each hook, then call these when required. This seems like the best solution, but introducing functions introduces problems of variable scope. The underlying code would need to be written carefully in a way that appropriate variables can be passed to each hook.</li>
</ul>
<h3>Patches</h3>
<p>A totally different approach to extending PHP software is patching it. In a similar way to how a <a href="http://en.wikipedia.org/wiki/Patch_(Unix)">patch file</a> is used, the software could read instructions from an extension and physically modify the appropriate code.</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;color: #FCFFBA;color: black;">@@ -<span style="color: black;">58</span>,<span style="color: black;">7</span> +<span style="color: black;">58</span>,<span style="color: black;">9</span> @@
 // Did someone just hit &quot;Submit&quot; or &quot;Preview&quot;?
 if <span style="color: #000;">&#40;</span>isset<span style="color: #000;">&#40;</span>$_POST<span style="color: #000;">&#91;</span>'form_sent'<span style="color: #000;">&#93;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>
 <span style="color: #000;">&#123;</span>
<span style="color: #991111;">-	// Make sure form_user is correct</span>
<span style="color: #00b000;">+	// This is some new code</span>
<span style="color: #00b000;">+	$username = isset<span style="color: #000;">&#40;</span>$_POST<span style="color: #000;">&#91;</span>'username'<span style="color: #000;">&#93;</span><span style="color: #000;">&#41;</span> ? $_POST<span style="color: #000;">&#91;</span>'username'<span style="color: #000;">&#93;</span> : null;</span>
<span style="color: #00b000;">+</span></pre></div></div>

<p>This means that once the extension has been installed, there is no extension code left to worry about; the physical files have been changed and the extension installation files can be removed.</p>
<p>At first this may seem like a much better solution than hooks; code can be inserted/changed/deleted anywhere in any files, there is no need to litter hooks all over the place. However it has three major disadvantages:</p>
<ul>
<li>Often in shared hosting environments PHP will be configured to run as a certain unix user (usually &#8220;www-data&#8221; or &#8220;nobody&#8221;). For the software to be able to patch itself, all files would require to be writeable by that user. This could prove to be a major security flaw as it would allow other users on the server to modify your files. A work around for this could be to modify the files over (S)FTP instead, but then the user would need to provide their hosting login details.</li>
<li>Updating the core software becomes harder. Since the files have been physically modified it is no longer a simple task to replace them with updated files. In theory core updates could be applied the same way extensions are installed (i.e. as patches), but with a modified board conflicts are fairly likely, and code that been removed by extensions is likely to just be replaced when the core is updated.</li>
<li>An extension with a bug, or even a malicious extension, could render the whole software unusable by deleting sections of code or inserting invalid code. Since the actual files would have physically been overwritten there would be no way to recover from this, other than the user manually uploading a backup (if they were organized enough to have one!).</li>
</ul>
<p>To me this seems like a rather show stopping problem, what&#8217;s the point in a one-click install system if uninstallation can require manually removing the changes. The idea of a buggy extension being able to totally destroy a working install is not acceptable!</p>
<h3>Conclusions</h3>
<p>What will be use in FluxBB 2.0? Only time will tell, but I&#8217;m currently leaning towards making use of hooks again, but attaching functions loaded from native PHP scripts, rather than chunks of code to be evaled.</p>
<p>Have any suggestions or better ideas? Please leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamierf.co.uk/2010/02/08/extensible-php-software-hooks-patches/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>FluxBB: Changes, updates and on-going progress&#8230;</title>
		<link>http://www.jamierf.co.uk/2009/10/21/fluxbb-changes-updates-and-on-going-progress/</link>
		<comments>http://www.jamierf.co.uk/2009/10/21/fluxbb-changes-updates-and-on-going-progress/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 13:01:32 +0000</pubDate>
		<dc:creator>Jamie</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fluxbb]]></category>

		<guid isPermaLink="false">http://www.jamierf.co.uk/?p=252</guid>
		<description><![CDATA[After various ups and downs for FluxBB I feel things are finally starting to look up. I am proud to have recently taken over leadership of the project, and am looking forward to a more organized and structured future. We have also recently announced our plans to unveil a brand new website, on a new [...]]]></description>
			<content:encoded><![CDATA[<!-- wp-jquery-lightbox, a WordPress plugin by ulfben --> <p>After various ups and downs for FluxBB I feel things are finally starting to look up. I am proud to have recently taken over leadership of the project, and am looking forward to a more organized and structured future.</p>
<p>We have also recently announced our plans to unveil a brand new website, on a new server which I have ordered from <a href="http://www.gandi.net">Gandi</a> (where I also happen to rent the VPS for this website from). On the new server I have decided to give <a href="http://www.lighttpd.net">lighttpd</a> a try as an alternative to <a href="http://httpd.apache.org">Apache2</a>, I guess time will tell if this was a good idea or not.</p>
<p>The new website, along with looking much cleaner and professional, has much more information and many more useful features than the old (and slightly out-of-date) one.</p>
<p><span id="more-252"></span></p>
<ul>
<li>Some important information that was missing from the old site, such as a a full feature list and information about; FluxBB&#8217;s history, future development and the development team.</li>
<li>Localization support &#8211; Every page of the new site can now be easily translated into various different languages. Once the text has been finalized we hope some members of the international communities will provide us with some translations.</li>
<li>Information about upgrading between releases, and converting from other software; including a list of other software which conversion from is supported.</li>
<li>A page of recommended web hosts to get people started.</li>
<li>A modification repository to host modifications, plugins, styles and language packs. This will allow mod developers to host their modifications in a central location where they can easily be found. It also gives us some control over which modifications are published, allowing us to reject any with obvious security vulnerabilities for example, which will hopefully improve the quality of the modifications.</li>
<li>An updated IRC web chat, using the webchat.freenode.net script.</li>
<li>A brand new user oriented wiki, providing guides on installing, setting up, using, moderating and administering FluxBB.</li>
</ul>
<p>For anyone interested, a sneak preview of the new site:<br />
<img class="aligncenter size-full wp-image-254" style="border: 1px solid black;" title="FluxBB site preview" src="http://www.jamierf.co.uk/wp-content/uploads/2009/10/fluxbb_site_preview.png" alt="FluxBB site preview" width="890" height="376" /><br />
For more information, <a href="http://fluxbb.org/forums/topic/3343/changes-updates-and-ongoing-progress/">Changes, updates and on-going progress&#8230;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jamierf.co.uk/2009/10/21/fluxbb-changes-updates-and-on-going-progress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
