<?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>Rob Searles &#187; Open Source</title>
	<atom:link href="http://www.robsearles.com/category/open-source/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.robsearles.com</link>
	<description>Musing on the business of and development for "The Web"</description>
	<lastBuildDate>Thu, 02 Feb 2012 15:36:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>My Perfect Desktop &#8211; Day 0</title>
		<link>http://www.robsearles.com/2010/03/16/my-perfect-desktop-day-0/</link>
		<comments>http://www.robsearles.com/2010/03/16/my-perfect-desktop-day-0/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 11:21:34 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=270</guid>
		<description><![CDATA[Join me as I build my perfect desktop, ideal for a Linux based web developer.]]></description>
			<content:encoded><![CDATA[<p>Today is an exciting day. I have in my possession a brand new custom built computer to use exclusively at the office. I currently use the laptop for both home and office work, but since the laptop is getting a bit old and computer components are so cheap these days I decided to build a work station just for me to use at the office. The best thing is that as it is custom built I can put whatever I damn well want on it – no pre-installed Windows or anything else. I can make it absolutely perfect for me.</p>
<p>I&#8217;ll be documenting here in my blog exactly the steps needed to take it from a <a href="http://en.wikipedia.org/wiki/Tabula_rasa">tabula rasa</a> to my perfect desktop system.  Apart from the system being obviously Linux based, there will be a number of things to consider before I get started. If I want it to be perfect, I need to think about what it is that I really need and want from a work only system. So, after a brainstorm this is the breakdown of what I require:</p>
<ol>
<li>
<h4>Keyboard Friendly</h4>
<p>I am becoming less interested in using the mouse. This is for a number of reasons, firstly it is quicker to keep your hands on the keyboard rather than always having to find the mouse and point and click. Secondly, using the mouse greatly exacerbates <a href="http://www.ccohs.ca/oshanswers/ergonomics/office/mouse/mouse_problems.html">RSI and all that jazz</a>. As such a system designed for maximum keyboard usage is important.</li>
<li>
<h4>Great Web Development Tools</h4>
<p>As a web developer this is a no brainer. I need to be able to have the tools for developing websites, testing (at code, server and client level) deployment and client side version control.</li>
<li>
<h4>Base system should be small, quick and light</h4>
<p>Due to point 2, I can see the need for being able to have virtualised instances of Windows running, each running a different version of IE. As such, the base system should be as small, quick and light as possible so it doesn&#8217;t get bogged down when I have one (or more) windows running for testing purposes.</li>
<li>
<h4>Communications</h4>
<p>I have to be able to email, chat, and talk with people via my computer</li>
<li>
<h4>Music and sound</h4>
<p>I need to listen to music at work!</li>
<li>
<h4>Must get on with others</h4>
<p>Some strange people out there still use propriety software. My system needs to be able to read Word and Powerpoint and all that stuff.</li>
<li>
<h4>Not be rude</h4>
<p>This is a strange request, but over the weekend I had a friend staying who is an IT administrator for a large international company. He had to do some work on their Windows based infrastructure, so he powered up Vista on my laptop (which I never use*) to log into their systems via the Remote Desktop. Half way through he had to make a couple of calls. When he came back Vista had rebooted and he had lost everything. We narrowed it down to the fact that Vista had updates, installed them and rebooted without even asking for permission. IMO, that is really fucking rude.</li>
<li>
<h4>Stable</h4>
<p>Last, but by no means least, the system has to be solid. I can&#8217;t have it crashing on me every hour.</li>
</ol>
<p>And that is pretty much it. Follow me over the next week or so whilst I sort out my ideal perfect work station.</p>
<p><em>* I just had to make that point</em></p>
<h4>Building My Perfect Desktop</h4>
<ul>
<li><a href="http://www.robsearles.com/2010/03/18/my-perfect-desktop-day-1-the-base-system/">Day 1 &#8211; The Base System</a><strong><br />
</strong></li>
</ul>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=270&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2010/03/16/my-perfect-desktop-day-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Emacs CSS-Mode Fix (adding to the chain!)</title>
		<link>http://www.robsearles.com/2009/10/29/emacs-css-mode-fix/</link>
		<comments>http://www.robsearles.com/2009/10/29/emacs-css-mode-fix/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 13:52:25 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Emacs]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=202</guid>
		<description><![CDATA[After my week with Emacs I&#8217;m still struggling along. One of my main annoyances is the default way some of the modes indent the code. I think the worst offender of this is the default CSS-mode. After frustration when, yet again, I hit the tab key and the cursor rockets about 80 places to the [...]]]></description>
			<content:encoded><![CDATA[<p>After my <a href="http://www.robsearles.com/2009/10/19/a-week-with-emacs/" target="_blank">week with Emacs</a> I&#8217;m still struggling along. One of my main annoyances is the default way some of the modes indent the code. I think the worst offender of this is the default <a href="http://www.emacswiki.org/emacs/css-mode.el" target="_blank">CSS-mode</a>. After frustration when, yet again, I hit the tab key and the cursor rockets about 80 places to the right I decided to Google for a fix.</p>
<p><em>The internet is great!</em> Clearly it wasn&#8217;t just me having a problem, <a href="http://transcyberia.info/archives/50-fixing-emacs-css-mode.html" target="_blank">Guido Stevens</a> was also suffering and posted a fix, which he himself found on another <a href="http://www.chrisamiller.com/blog/2009/01/20/fix-css-mode-indention-in-emacs/" target="_blank">blog post by Chris Miller</a>, which Chris in turn <a href="http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/" target="_blank">found on StokeBloke.com</a> which had been found originally on a now dead post.</p>
<p>Not bad! Four people all having problems with the same thing and posting a fix for others to share. So I thought I&#8217;d join the chain, and write this blog post.</p>
<p>Oh yes, and the fix itself:</p>
<pre>;; fix css mode
(require 'css-mode)
(setq cssm-indent-level 2)
(setq cssm-newline-before-closing-bracket t)
(setq cssm-indent-function #'cssm-c-style-indenter)
(setq cssm-mirror-mode t)</pre>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=202&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/10/29/emacs-css-mode-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A week with Emacs: one week later</title>
		<link>http://www.robsearles.com/2009/10/25/a-week-with-emacs-one-week-later/</link>
		<comments>http://www.robsearles.com/2009/10/25/a-week-with-emacs-one-week-later/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 22:05:59 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Emacs]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=196</guid>
		<description><![CDATA[I spent a week using Emacs. I wasn't easy but I survived. Read more to find out how I did.]]></description>
			<content:encoded><![CDATA[<p>As promised in <a href="http://www.robsearles.com/2009/10/19/a-week-with-emacs/" target="_blank">my last post</a>, I have spent a whole week using <a href="http://www.gnu.org/software/emacs/" target="_blank">Emacs</a>.   Apart from the odd foray with <a href="http://www.nano-editor.org/" target="_blank">Nano</a> and <a href="http://www.xfce.org/projects/mousepad/" target="_blank">Mousepad</a> I  haven&#8217;t touched <a href="http://www.eclipse.org/" target="_blank">Eclipse</a> or <a href="http://www.netbeans.org/" target="_blank">Netbeans</a> or any other IDE and  managed to stick to Emacs for the full week.</p>
<p><strong>How did it go?</strong></p>
<p>To start off it was slow. Emacs has a <a href="http://xahlee.org/emacs/emacs_fun.html" target="_blank">notoriously high learning curve</a>, and I pretty much started at the bottom. One of the reasons for doing this was so I could move away from the mouse and it turns out that the mouse is an extremely hard habit to break. So to are the keyboard arrow keys. I kept on finding my hands would instinctively  jump off the keyboard and try to double click on something, or try to navigate around the page with the arrows. This is clearly <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Moving-Point.html#Moving-Point" target="_blank">not the way it is done</a> in Emacs!</p>
<p>The next thing I found is that Emacs doesn&#8217;t let you indent code files as you want. It seems to have a preferred method and forces it on you. This is very annoying and being a n00b I still haven&#8217;t found a way around this.</p>
<p>However, after a couple of days I began to get the hang of it. Still painfully slow, but navigating around the page, buffers and windows was becoming gradually quicker. I began to enjoy using Emacs, even though my right hand kept on unceremoniously lurching to the right from time to time.</p>
<p>By a complete coincidence, on Wednesday I was invited to <a href="http://www.c-base.org/" target="_blank">C-Base here in Berlin</a> for a beginners&#8217; introduction to Emacs. Even though it was all in German, and my Deutsch ist nicht so gut I was blown away by not only the speed but also the huge amount of functionality within Emacs. To see someone who actually knew Emacs inside out was a revelation. I made a huge amount of notes (within Emacs before you ask!) ready to test out for myself. This insight into the &#8220;how the pros use Emacs&#8221; has really been an eye-opener and I am determined to learn just a fraction of what was on display at the tutorial.</p>
<p><strong>Summing up my week with Emacs.</strong></p>
<p>It was hard work, there was much and is even more left to learn. It is a vast landscape to negotiate, with many nooks and crannies. But once it is mastered I have no doubt that my productivity will be greatly increased.</p>
<p><strong>Other people diving into Emacs</strong></p>
<ul>
<li><a href="http://sodonnell.wordpress.com/2007/06/12/choosing-an-editor/" target="_blank">Stephen O’Donnell &#8211; Choosing an Editor</a></li>
<li><big><a href="http://johnbokma.com/mexit/2008/04/16/" target="_blank">John Bokma &#8211; Emacs it is</a><br />
</big></li>
</ul>
<p><strong>Some useful sites</strong></p>
<ul>
<li><a href="http://www.gnu.org/software/emacs/manual/" target="_blank">http://www.gnu.org/software/emacs/manual/</a></li>
<li><a href="http://www.emacswiki.org/" target="_blank">http://www.emacswiki.org/</a></li>
<li><a href="http://emacsblog.org/" target="_blank">http://emacsblog.org/</a></li>
</ul>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=196&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/10/25/a-week-with-emacs-one-week-later/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Thinking About Database Revision Control</title>
		<link>http://www.robsearles.com/2009/10/11/thinking-about-database-revision-control/</link>
		<comments>http://www.robsearles.com/2009/10/11/thinking-about-database-revision-control/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 17:24:19 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=180</guid>
		<description><![CDATA[In a current database driven project that has multiple developers the single biggest issue we have is version control for the database.
For us at ibrow, the number one practise that we engage in is Version Control/Revision Control. I personally use version control for almost everything and not using it when having multiple developers working on [...]]]></description>
			<content:encoded><![CDATA[<p>In a current database driven project that has multiple developers the single biggest issue we have is version control for the database.</p>
<p>For us at <a href="http://www.ibrow.com">ibrow</a>, the number one practise that we engage in is <a href="http://en.wikipedia.org/wiki/Revision_control" target="_blank">Version Control/Revision Control</a>. I personally use version control for almost everything and not using it when having multiple developers working on a project sends shivers down my spine.We currently use <a href="http://subversion.tigris.org/" target="_blank">Subversion</a>, however I&#8217;m thinking of moving over to <a href="http://git-scm.com/" target="_blank">Git</a>, but there is also <a href="http://bazaar-vcs.org/en/" target="_blank">Bazaar</a> and <a href="http://mercurial.selenic.com/wiki/" target="_blank">Mercurial</a> plus <a href="http://en.wikipedia.org/wiki/List_of_revision_control_software" target="_blank">many, many others</a>.</p>
<p>Whilst there is this vast array of version control system for code, there doesn&#8217;t seem to be the focus on version control for database schemes. Jeff Atwood has a <a href="http://www.codinghorror.com/blog/archives/001050.html" target="_blank">couple</a> of <a href="http://www.codinghorror.com/blog/archives/000743.html" target="_blank">posts</a> espousing the virtues of version control for databases. There is <a href="http://guides.rubyonrails.org/migrations.html" target="_blank">Rail&#8217;s Migrations</a> which seems to be the most advanced version control for databases to date and there is a project to make a <a href="http://code.google.com/p/mysql-php-migrations/" target="_blank">PHP version of Migrations</a>. However, Migrations still has it&#8217;s flaws, which are discussed in <a href="http://adamblog.heroku.com/past/2009/3/2/database_versioning/" target="_blank">Adam Wiggins&#8217;s blog post about this very subject</a>. Adam offers some good insights into the problem and has a brain storm about possible solutions. But I think I&#8217;m coming to the problem from a slightly different angle to him.</p>
<p>As most of our projects are in constant development we do not, as such, have versions, but instead <strong>revisions</strong>. This is a key difference here. If we check in a database change to the version control, we don&#8217;t yet know it&#8217;s revision, especially if we have multiple developers working on the same project and possibly changing the scheme of the database at the same time.</p>
<p>The ideal solution would use the following steps:</p>
<ol>
<li>Developer finishes their chunk of code with any database changes, and are ready to commit. The database changes include UP and DOWN changes.</li>
<li>Developer commits their code changes, a revision number is assigned</li>
<li>Based on this revision number, the database changes are committed.</li>
</ol>
<p>Obviously the developer should update their working copy before committing, just to see if there are any conflicts and to make sure they have the latest copy of the code.</p>
<p>On the updating side, the following steps should occur when the developer updates their  code:</p>
<ol>
<li>The update process makes a note of their current revision number</li>
<li>Downloads all code changes via the SVN update command</li>
<li>Downloads all the database changes since their last revision</li>
<li>Update process applies all database changes to developer&#8217;s local database</li>
</ol>
<p>This process can be reversed for reverting or merging backwards.</p>
<p>Currently I can&#8217;t find anything out there that does this &#8211; which probably means one of 2 things:</p>
<ol>
<li>My Google-fu isn&#8217;t up to scratch</li>
<li>It is actually a lot harder than I think!</li>
</ol>
<p>I really need to get this right, as this is possibly the most important thing to get right for us at the moment. It would be great to hear any possible solutions or existing implementations out there.</p>
<p>Maybe this will be an interesting sub project for me over the next few weeks?</p>
<p><em>(And obviously I haven&#8217;t even considered trying to keep the data up to date &#8211; but I guess that will be for another day.)</em></p>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=180&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/10/11/thinking-about-database-revision-control/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sup Mail Client is Saving my life</title>
		<link>http://www.robsearles.com/2009/09/28/sup-mail-client-is-saving-my-life/</link>
		<comments>http://www.robsearles.com/2009/09/28/sup-mail-client-is-saving-my-life/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 20:02:34 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[sup]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=173</guid>
		<description><![CDATA[About a month ago I decided to get very geeky and installed a command line emailing program: Sup. I started off by moving my main work account over to test it out and after a month of heavy testing I have now just moved my other accounts across.
So why?
Well, let me first state that Sup [...]]]></description>
			<content:encoded><![CDATA[<p>About a month ago I decided to get very geeky and <a href="http://www.robsearles.com/2009/08/30/ubuntu-jaunty-command-line-email-sup-offlineimap-and-msmtp/">installed a command line emailing program</a>: <a href="http://sup.rubyforge.org/" target="_blank">Sup</a>. I started off by moving my main work account over to test it out and after a month of heavy testing I have now just moved my other accounts across.</p>
<p>So why?</p>
<p>Well, let me first state that Sup is no where near perfect. Crazy people out there still send me HTML email which obviously doesn&#8217;t display too well in a command line interface, but I can open those up in my browser. I still haven&#8217;t found a way to easily search and add multiple names from the address book to an email I&#8217;m composing. And there is that irritating thing that means if I&#8217;m writing an email, I can go back and view my inbox (note: this is probably my fault, I&#8217;m using a popup window&#8217;d emacs).</p>
<p>But the thing is these are all fixable. It is open source, so if these things really pissed me off then I should learn Ruby and have a crack at fixing them myself. And the thing is I like Sup so much I just might.</p>
<p>Also Sup is being <a href="http://rubyforge.org/projects/sup/" target="_blank">actively developed</a>. If you have a look on the <a href="http://gitorious.org/sup" target="_blank">Gitorius page</a> you can see that Sup&#8217;s maintainer <a href="http://masanjin.net/" target="_blank">William Morgan</a> seems to spend every weekend hacking away! Plus there is a large list of active developers.</p>
<p>Yet I didn&#8217;t move all my mail accounts over to Sup just because I can fix things and if I can&#8217;t then hopefully someone else will!</p>
<p>No, I moved them all over because Sup appears to be slowly, email by email, saving my life.</p>
<p>I currently have 1893 emails index, but of these 1893 email, only 12 of them are in my inbox. For me this is unheard of.</p>
<p>Sup has provided me with such an easy system of filing and organising my mail that I can deal with it pretty much instantly, clearing my inbox. And over the last month I have found that keeping a clean inbox keeps my head pretty focused. I&#8217;m not worrying about all the emails I have to deal with. I am finding I can handle more stuff, get more stuff done and still have a tidy head.</p>
<p>This is great news!</p>
<p>Having this confidence of being able to handle more stuff, I&#8217;m wanting to handle more stuff. I want to do more things, I want to push projects forward. I am now no longer wallowing in an unorganised mess! So thank you William and thank you Sup &#8211; you are saving my life <img src='http://www.robsearles.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>More stuff? Bring it on!</p>
<p><strong>More Sup posts</strong></p>
<ul>
<li><a href="http://www.robsearles.com/2009/08/30/ubuntu-jaunty-command-line-email-sup-offlineimap-and-msmtp/">Sup, OfflineIMAP, MSMTP on Jaunty</a></li>
<li><a href="http://www.robsearles.com/2010/05/26/sup-crash-index-locked-then-terminates-easy-fix/">Fixing a Sup Crash</a></li>
</ul>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=173&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/09/28/sup-mail-client-is-saving-my-life/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple tools produce powerful results</title>
		<link>http://www.robsearles.com/2009/09/14/simple-tools-produce-powerful-results/</link>
		<comments>http://www.robsearles.com/2009/09/14/simple-tools-produce-powerful-results/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 21:07:05 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=169</guid>
		<description><![CDATA[
Sometimes I really love the Linux world. Sometimes it all fits so neatly together and lets you just get stuff done. Sure it might take a bit of digging around, but when it all comes together it really is beautiful!
I&#8217;m waxing lyrical today because I have just managed to fit all the pieces together for [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-170" title="Tools" src="http://www.robsearles.com/wp-content/uploads/2009/09/tools.png" alt="Tools" width="300" height="300" /></p>
<p>Sometimes I really love the Linux world. Sometimes it all fits so neatly together and lets you just get stuff done. Sure it might take a bit of digging around, but when it all comes together it really is beautiful!</p>
<p>I&#8217;m waxing lyrical today because I have just managed to fit all the pieces together for a certain aspect of a large project we&#8217;re working here at <a href="http://www.ibrow.com" target="_blank">ibrow towers</a>. This particular problem was a three parter:</p>
<ol>
<li>Users can FTP into a server into their own directory.</li>
<li>These users should be created automatically (i.e. sign up on site, get details, ftp) and have the same login credentials as the rest of the site</li>
<li>Uploads to the FTP server should be monitored and each file processed</li>
</ol>
<p>To solve this three part problem, I utilised the following:</p>
<ul>
<li>VSFTPD FTP Server using MySQL as the credentials database</li>
<li>incron as the directory monitoring</li>
<li>bash as the glue</li>
</ul>
<p><span id="more-169"></span></p>
<p>My server is running Debian, and I found the on <a href="http://www.howtoforge.com/vsftpd_mysql_debian_etch" target="_blank">Falko Timme tutorial for VSFTPD and MySQL at How To Forge</a> incredibly easy to follow and it worked pretty much &#8220;out of the box&#8221;. It did take a bit of tweaking, but I was able to use my existing data structure to be used for the FTP login credentials.</p>
<p>The next task was directory monitoring. After some searching around I found <a href="http://incron.aiken.cz/" target="_blank">incron</a>. On a Debian system installation was a breeze:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> incron</pre></div></div>

<p>Now, for my VSFTP user I had to create an incrontab. First I had to add the user into the incron.conf file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>incron.allow</pre></div></div>

<p>This was blank, so I just added the line:</p>

<div class="wp_syntax"><div class="code"><pre class="text text" style="font-family:monospace;">vsftpd</pre></div></div>

<p>No to test this was working I created a small bash script that esentially appends to a text file. I created this in /home/vsftpd/bin/incron.sh</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">!/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;start: $1 || $2&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vsftpd<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>log.txt</pre></div></div>

<p>The $1 and $2 variable are to store command line arguments which I&#8217;ll pass via the incrontab. Make this executable and quickly test this is working:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> 0755 <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vsftpd<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>incron.sh
$ <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vsftpd<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>incron.sh <span style="color: #7a0874; font-weight: bold;">test</span> hello
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vsftpd<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>log.txt
start: <span style="color: #7a0874; font-weight: bold;">test</span> || hello</pre></div></div>

<p>The test script is all working so now we need to call it whenever a file is uploaded. You need to edit the incrontab passing it the directory to monitor, which actions to look out for and then what script to call, passing any arguments.</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ incrontab <span style="color: #660033;">-e</span></pre></div></div>

<p>You&#8217;ll be taken to an editor where you should enter something like:</p>

<div class="wp_syntax"><div class="code"><pre class="text text" style="font-family:monospace;">/home/vsftpd/cam1/ IN_CLOSE_WRITE /home/vsftpd/bin/incron.sh 123 $@$#</pre></div></div>

<p>The IN_CLOSE_WRITE basically means, &#8220;once finished uploading&#8221;. &#8220;123&#8243; is the user id, as I didn&#8217;t want the directory name to reflect the user id. Finally the $@$# is translated into the full path of the directory (as typed by you, so keep an eye on trailing slashes) and the file name that was caught by the incron, e.g: /home/vsftpd/cam1/my-file.txt</p>
<p>Now simply test this by FTPing and uploading something to the user&#8217;s directory. It&#8217;s always fun to do:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vsftpd<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>log.txt</pre></div></div>

<p>to watch the log being updated in real time. Now that&#8217;s working you can change the incron.sh script to do anything you want!</p>
<p>The final thing to do is to automate the creation of the users&#8217; FTP directories. When adding the directories we also want to ensure that they are correctly monitored. To solve this I wrote a small bash script that is saved on the FTP server, /home/vsftpd/bin/add-user.sh:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># user id = $1</span>
<span style="color: #666666; font-style: italic;"># user directory = $2</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create the directory</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vsftpd<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #000000;">2</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Add monitoring</span>
incrontab <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>$1.in
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;/home/vsftpd/$2/ IN_CLOSE_WRITE /home/vsftpd/bin/incron.sh $1 <span style="color: #000099; font-weight: bold;">\$</span>@<span style="color: #000099; font-weight: bold;">\$</span>#&quot;</span> <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>$1.in
incrontab <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>$1.in
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>$1.in</pre></div></div>

<p>The important part of this is that we keep monitoring intact. And this is one of the reasons why I love Linux so much. By using incrontab -l to send the output to a tmp file, then echoing the new incrontab line to append that tmp file, then finally calling incrontab again, this time passing the tmp file we have just added a new directory to monitor, whilst keeping all the existing ones! Simple, elegant and it just works. One thing to not here is to make sure you escape the $@ and $# variables in the echo.</p>
<p>Make this executable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> 0755 <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vsftpd<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>add-user.sh</pre></div></div>

<p>Test this on the server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>vsftpd<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>add-user.sh <span style="color: #000000;">456</span> testdir</pre></div></div>

<p>and you should see that the testdir has been created and monitored, associating with the user id 456. This script should be invoked during the user creation phase in your web app.</p>
<p>That&#8217;s it!</p>
<p>Through using bash, VSFTPD with MySQL credentials and the incrontab program I can now automatically create a new user, keeping it linked in with my website database, create the user&#8217;s FTP directory and monitor it for any uploads.</p>
<p>Using some faily simple tools together (here ftp, bash and incron) you can create some very powerful solutions.</p>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=169&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/09/14/simple-tools-produce-powerful-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress: Multiple Content Columns</title>
		<link>http://www.robsearles.com/2009/07/05/wordpress-multiple-content-columns/</link>
		<comments>http://www.robsearles.com/2009/07/05/wordpress-multiple-content-columns/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 14:32:47 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.robsearles.com/?p=126</guid>
		<description><![CDATA[Wordpress template hack to split page content into multiple columns using the more tag]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a <a href="http://wordpress.org" target="_blank">Wordpress</a> site for a client with one of our developers <a href="http://www.thomashartnell.com/" target="_blank">Tom Hartnell</a>. The design of this particular site was that some pages would need content displayed over multiple columns. This content had to be updatable by the client, as such it could not be hard coded into the template files.</p>
<p>We had a look around and we found a potential solution on <a href="http://www.kriesi.at/archives/wordpress-display-content-in-multiple-columns" target="_blank">this blog pos</a>t.</p>
<p>We played around with this for a while but found that, whilst it was a good solution, it wasn&#8217;t quite suitable for our needs.  What we needed was a solution which allowed us to have any number of columns and for each column to contain completely different content. The solution in the post demanded that each column start with the same HTML tag (H2 in the example). We decided to rewrite the function described above, based on the same principals, but updated and improved so it would fit our needs.</p>
<p>To see what the end result is, you can see a <a href="/multiple-columns-page/" target="_blank">demo page</a>.</p>
<p><span id="more-126"></span></p>
<p>The first thing the new function had to do was to split the content into the different columns using the <strong>more</strong> tag. In our tests, we found that Wordpress replaced the more tag with a span, but only in the first instance, all the rest were kept as a comment tag. The regular expression we used had to take this into account.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// the first &quot;more&quot; is converted to a span with ID</span>
<span style="color: #000088;">$columns</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="">'/(&lt;span id=&quot;more-\d+&quot;&gt;&lt;\/span&gt;)|(&lt;!--more--&gt;)&lt;\/p&gt;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>This regular expression is not bullet proof, but it does the job for us. Specifically, if you are using a plugin like &#8220;Sociable&#8221; or something that appends stuff to the end of the content then this stuff will end up in the third column and not nicely across the bottom of the page. Also, it hasn&#8217;t been tested when adding images. These two issues weren&#8217;t going to be a problem for us, so the regular expression above is perfectly adequate for our needs.</p>
<p>Next we need to loop through each column, removing any stray &lt;p&gt; tags that may have been orphaned by the regular expression and putting the content into separate divs.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$col_count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color:#800080;">0</span>; <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$col_count</span>; <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// check to see if there is a final, if not add it</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="">'/&lt;\/p&gt;\s?$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="">'&lt;/p&gt;'</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// check to see if there is an appending, if there is, remove</span>
	<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="">'/^\s?&lt;\/p&gt;/'</span><span style="color: #339933;">,</span> <span style="">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #666666; font-style: italic;">// now add the div wrapper</span>
	<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="">'&lt;div class=&quot;dynamic-col-'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="">'&lt;/div&gt;'</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally we can join the columns back together to produce the final content.</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;'</span>;</pre></div></div>

<p>Notice that we have added a clearing div here. This is basically so you can clear the floats with CSS so any content displayed below the page content will be correctly positioned.</p>
<p>What if there isn&#8217;t a more tag? We will only have one column. As such there is no need to modify the content, so the code above should go into an if statement</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$col_count</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #339933;">...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The last job to do in this function is to clear out any blank &lt;p&gt; tags caused by the regular expression and return the content</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// remove any left over empty tags</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="">'&lt;p&gt;&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span>;</pre></div></div>

<p>This would normally all be contained in a function (we called my_multi_col_v2) that would be called as a filter function, however, we found that this was causing problems with the Wordpress excerpts, so instead we are overriding the default content display function in the <strong>page.php</strong> file.<br />
In your page.php file, replace the line that calls the the_content() function</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//the_content('Read the rest of this entry &amp;raquo;');</span></pre></div></div>

<p>Now we collect the content into a variable, then pass this variable to the new function, outputting the result. The function that gets the content instead of directly outputting it is <a href="http://codex.wordpress.org/Function_Reference/get_the_content" target="_blank">get_the_content()</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> get_the_content<span style="color: #009900;">&#40;</span><span style="">''</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">FALSE</span><span style="color: #339933;">,</span><span style="">''</span><span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">//arguments remove 'more' text</span>
<span style="color: #990000;">echo</span> my_multi_col_v2<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>As we are using get_the_content() the default filtering that is normally done on the content is not being run. So at the top of our new function, we must manually run these</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// run through a couple of essential tasks to prepare the content</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="">']]&gt;'</span><span style="color: #339933;">,</span> <span style="">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>This also caused a problem with line breaks when only displaying one column, so we needed to include an else statement that ran <a href="http://codex.wordpress.org/Function_Reference/wpautop" target="_blank">wpautop() </a></p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// this page does not have dynamic columns</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> wpautop<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>So the final function looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> my_multi_col_v2<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// run through a couple of essential tasks to prepare the content</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="">']]&gt;'</span><span style="color: #339933;">,</span> <span style="">']]&amp;gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// the first &quot;more&quot; is converted to a span with ID</span>
	<span style="color: #000088;">$columns</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_split</span><span style="color: #009900;">&#40;</span><span style="">'/(&lt;span id=&quot;more-\d+&quot;&gt;&lt;\/span&gt;)|(&lt;!--more--&gt;)&lt;\/p&gt;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000088;">$col_count</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$col_count</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color:#800080;">0</span>; <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$col_count</span>; <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// check to see if there is a final &lt;/p&gt;, if not add it</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="">'/&lt;\/p&gt;\s?$/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="">'&lt;/p&gt;'</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #666666; font-style: italic;">// check to see if there is an appending &lt;/p&gt;, if there is, remove</span>
			<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="">'/^\s?&lt;\/p&gt;/'</span><span style="color: #339933;">,</span> <span style="">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #666666; font-style: italic;">// now add the div wrapper</span>
			<span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="">'&lt;div class=&quot;dynamic-col-'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="">'&lt;/div&gt;'</span>;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="">'&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;'</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// this page does not have dynamic columns</span>
		<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> wpautop<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// remove any left over empty &lt;p&gt; tags</span>
	<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="">'&lt;p&gt;&lt;/p&gt;'</span><span style="color: #339933;">,</span> <span style="">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The next thing to do is to update your CSS so it lays out the columns correctly. In the demo I have used three columns, and the CSS for it looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* dynamic columns */</span>
div<span style="color: #6666ff;">.dynamic-col-1</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">38</span>%</span>; <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">2</span>%</span>;<span style="color: #00AA00;">&#125;</span>
div<span style="color: #6666ff;">.dynamic-col-2</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">38</span>%</span>;padding-<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">2</span>%</span>;<span style="color: #00AA00;">&#125;</span>
div<span style="color: #6666ff;">.dynamic-col-3</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">20</span>%</span>;<span style="color: #00AA00;">&#125;</span>
div<span style="color: #6666ff;">.clear</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">both</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>And that&#8217;s pretty much it.  Have a look at <a href="/multiple-columns-page/" target="_blank">the demo</a>, below is a screenshot of the Wordpress editor screen so you can see that it really is controlled by the user, you should see the two more tags that are used to split the content into the three columns.</p>
<div id="attachment_128" class="wp-caption alignnone" style="width: 510px"><a href="http://www.robsearles.com/wp-content/uploads/2009/07/wordpress-multiple-cols.png"><img class="size-full wp-image-128" title="wordpress-multiple-cols" src="http://www.robsearles.com/wp-content/uploads/2009/07/wordpress-multiple-cols.png" alt="Wordpress multiple content columns, editor input" width="500" height="440" /></a><p class="wp-caption-text">Wordpress multiple content columns, editor input</p></div>
<p>Please feel free to take this, improve it, update it, completely rewrite it. If you do please can you drop me a comment and let me know. And a big thanks to <a href="http://www.kriesi.at/" target="_blank">Kriesi</a> for his initial work and for providing inspiration for this blog post.</pre>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=126&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2009/07/05/wordpress-multiple-content-columns/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Timesheet NG: Experimental Web Installer</title>
		<link>http://www.robsearles.com/2008/12/14/timesheet-ng-experimental-web-installer/</link>
		<comments>http://www.robsearles.com/2008/12/14/timesheet-ng-experimental-web-installer/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 01:09:25 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://www.robsearles.co.uk/?p=43</guid>
		<description><![CDATA[I&#8217;ve just committed a new very basic web installer for Timesheet Next Gen which is the Timesheet and job tracking open source web app that I&#8217;m trying to contribute to when I have a spare moment.
Only in the SVN repository at the moment, but if you have a chance you can get check it out [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just committed a new <strong>very basic</strong> web installer for <a href="https://sourceforge.net/projects/tsheetx/" target="_blank">Timesheet Next Gen</a> which is the Timesheet and job tracking open source web app that I&#8217;m <em>trying</em> to contribute to when I have a spare moment.</p>
<p>Only in the SVN repository at the moment, but if you have a chance you can get check it out anonymously from SourceForge using your favourite SVN app here:</p>
<p>https://tsheetx.svn.sourceforge.net/svnroot/tsheetx/branches/exp_installer</p>
<p>More details in the <a href="https://sourceforge.net/forum/forum.php?forum_id=897584" target="_blank">news page</a></p>
<p>Warning &#8211; in no way is this stable yet and should not be used for mission critical situations!</p>
<img src="http://www.robsearles.com/?ak_action=api_record_view&id=43&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2008/12/14/timesheet-ng-experimental-web-installer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress Plugin &#8211; Registered Only &#8211; Fix</title>
		<link>http://www.robsearles.com/2008/12/12/wordpress-plugin-registered-only-fix/</link>
		<comments>http://www.robsearles.com/2008/12/12/wordpress-plugin-registered-only-fix/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 13:08:39 +0000</pubDate>
		<dc:creator>Rob Searles</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.robsearles.co.uk/?p=41</guid>
		<description><![CDATA[In my &#8220;real life&#8221; I manage a number of blogs for both clients and friends, mostly Wordpress. One of the blogs had a requirement that was to completely password protect the entire site &#8211; i.e. only registered users could view any page/post.
For this I initially set up .htaccess password protection &#8211; quick and simple.
However, we [...]]]></description>
			<content:encoded><![CDATA[<p>In my &#8220;real life&#8221; I manage a number of blogs for both clients and friends, mostly <a href="http://wordpress.org/" target="_blank">Wordpress</a>. One of the blogs had a requirement that was to completely password protect the entire site &#8211; i.e. only registered users could view any page/post.</p>
<p>For this I initially set up .htaccess password protection &#8211; quick and simple.</p>
<p>However, we found out that this prevented the <a href="http://iphone.wordpress.org/" target="_blank">Wordpress iPhone App</a> from login in and doing it&#8217;s stuff. So we had to look for another solution.</p>
<p>After doing some Googling I found <a href="http://www.cre8d-design.com/2006/08/password-protecting-your-wordpress-blog/" target="_blank">a post all about password protecting wordpress</a> on the <a href="http://www.cre8d-design.com/2006/08/password-protecting-your-wordpress-blog/" target="_blank">Cre8d Design</a> blog. This pointed me to the <a href="http://plugins.trac.wordpress.org/browser/registered-only/" target="_blank">&#8220;Registered Only&#8221; plugin</a>. Whilst it is quite old (4 years since last commit) it should have been just what I was looking for, so I downloaded it, installed and activated (taking care to follow the readme and remove the RSS feeds)</p>
<p>When testing it out it displayed the login box on first visit to the site &#8211; prefect. However, I logged in, but it still showed the login box. I assumed I typed in the wrong password, so I tried again. Same result.</p>
<p><strong>Argh, a bug! </strong></p>
<p>Probably because it was meant for a much older version of Wordpress (this blog was using 2.6.3 &#8211; now upgraded to2.7)</p>
<p>There was only one thing for it, I had to <strong>view the source</strong>! Which turned out to be relatively simple:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> carthik_bouncer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;wp-login.php&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        auth_redirect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="">'init'</span><span style="color: #339933;">,</span> <span style="">'carthik_bouncer'</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>The problem was clearly the <strong>auth_redirect() </strong>function<strong>. </strong>After some searching, I found <a href="http://wordpress.org/support/topic/192605" target="_blank">this thread</a><strong> </strong>in the Wordpress Support forums, after which I dutifully modified the code to this:</p>

<div class="wp_syntax"><div class="code"><pre class="php php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> carthik_bouncer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">12</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;wp-login.php&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_user_logged_in<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> auth_redirect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="">'init'</span><span style="color: #339933;">,</span> <span style="">'carthik_bouncer'</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Success! It works prefectly.</p>
<p>If you need to know, here is a patch:</p>

<div class="wp_syntax"><div class="code"><pre class="diff diff" style="font-family:monospace;">--- registered-only-old.php	<span style="">2008</span>-<span style="">12</span>-<span style="">12</span> <span style="">14</span>:00:<span style="">09.000000000</span> +0100
<span style="color: #888822;">+++ registered-only-new.php	<span style="">2008</span>-<span style="">12</span>-<span style="">12</span> <span style="">14</span>:01:<span style="">21.000000000</span> +0100</span>
<span style="color: #440088;">@@ -<span style="">26</span>,<span style="">7</span> +<span style="">26</span>,<span style="">7</span> @@</span>
&nbsp;
 function carthik_bouncer<span style="">&#40;</span><span style="">&#41;</span> <span style="">&#123;</span>
     if <span style="">&#40;</span>substr<span style="">&#40;</span>$_SERVER<span style="">&#91;</span>'SCRIPT_NAME'<span style="">&#93;</span>, -<span style="">12</span><span style="">&#41;</span> != &quot;wp-login.php&quot;<span style="">&#41;</span> <span style="">&#123;</span>
<span style="color: #991111;">-        auth_redirect<span style="">&#40;</span><span style="">&#41;</span>;</span>
<span style="color: #00b000;">+	    if <span style="">&#40;</span>!is_user_logged_in<span style="">&#40;</span><span style="">&#41;</span><span style="">&#41;</span> <span style="">&#123;</span> auth_redirect<span style="">&#40;</span><span style="">&#41;</span>; <span style="">&#125;</span></span>
     <span style="">&#125;</span>
 <span style="">&#125;</span></pre></div></div>

<img src="http://www.robsearles.com/?ak_action=api_record_view&id=41&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.robsearles.com/2008/12/12/wordpress-plugin-registered-only-fix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

