<?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>Flynsarmy</title>
	<atom:link href="http://www.flynsarmy.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flynsarmy.com</link>
	<description>Enter the world of HTML5, CSS3, PHP and all things Web Development</description>
	<lastBuildDate>Mon, 06 May 2013 13:19:26 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Secure WordPress &#8211; Limit Logins to Specified Countries with CloudFlare</title>
		<link>http://www.flynsarmy.com/2013/04/secure-wordpress-limit-logins-to-specified-countries-with-cloudflare/</link>
		<comments>http://www.flynsarmy.com/2013/04/secure-wordpress-limit-logins-to-specified-countries-with-cloudflare/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 00:09:48 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1413</guid>
		<description><![CDATA[As I'm sure is the case with just about every WordPress user, my site is constantly hit with failed login attempts from bots - usually originating from other countries. I had the idea last night to implement country-based login restrictions using CloudFlare's <a href="https://support.cloudflare.com/entries/22268642-What-does-CloudFlare-IP-Geolocation-do-" title="What does CloudFlare IP Geolocation do?" target="_blank">IP Geolocation server variable</a>.

My goal was to redirect redirect all users visiting the login page from countries other than Australia to the home page. This occurs before a login attempt can even be made.

Here's how it's done:
<ul>
	<li>Go into CloudFlare settings and make sure the IP Geolocation option is turned on<a href="http://www.flynsarmy.com/wp-content/uploads/2013/04/cloudflare-ip-geolocation.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2013/04/cloudflare-ip-geolocation.png" alt="Make sure CloudFlare IP Geolocation is turned on" /></a></li>
	<li>Add the following to your active themes <a href="http://codex.wordpress.org/Functions_File_Explained" title="Functions File Explained" target="_blank">functions.php</a> file
<pre lang="php" line="1" escaped="true" highlight="8">// Limit login countries - requires cloudflare
add_action( 'wp_authenticate', 'login_failed', 1);
function login_failed()
{
	if ( !isset($_SERVER["HTTP_CF_IPCOUNTRY"]) )
		return;

	if ( !in_array($_SERVER["HTTP_CF_IPCOUNTRY"], array('AU')) )
	{
		wp_redirect( home_url() );
		exit;
	}
}</pre>
</li>
</ul>
To test simply use a country other than your own. Once it's confirmed working switch to your country and you're good to go!]]></description>
				<content:encoded><![CDATA[<p>As I&#8217;m sure is the case with just about every WordPress user, my site is constantly hit with failed login attempts from bots &#8211; usually originating from other countries. I had the idea last night to implement country-based login restrictions using CloudFlare&#8217;s <a href="https://support.cloudflare.com/entries/22268642-What-does-CloudFlare-IP-Geolocation-do-" title="What does CloudFlare IP Geolocation do?" target="_blank">IP Geolocation server variable</a>.</p>
<p>My goal was to redirect redirect all users visiting the login page from countries other than Australia to the home page. This occurs before a login attempt can even be made.</p>
<p>Here&#8217;s how it&#8217;s done:</p>
<ul>
<li>Go into CloudFlare settings and make sure the IP Geolocation option is turned on<a href="http://www.flynsarmy.com/wp-content/uploads/2013/04/cloudflare-ip-geolocation.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2013/04/cloudflare-ip-geolocation.png" alt="Make sure CloudFlare IP Geolocation is turned on" /></a></li>
<li>Add the following to your active themes <a href="http://codex.wordpress.org/Functions_File_Explained" title="Functions File Explained" target="_blank">functions.php</a> file
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Limit login countries - requires cloudflare</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'wp_authenticate'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'login_failed'</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="color: #000000; font-weight: bold;">function</span> login_failed<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: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_CF_IPCOUNTRY&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
<span style="display:block;background-color: #ffc;">	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;HTTP_CF_IPCOUNTRY&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AU'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span></span>	<span style="color: #009900;">&#123;</span>
		wp_redirect<span style="color: #009900;">&#40;</span> home_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
</li>
</ul>
<p>To test simply use a country other than your own. Once it&#8217;s confirmed working switch to your country and you&#8217;re good to go!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2013/04/secure-wordpress-limit-logins-to-specified-countries-with-cloudflare/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get MySQL Table Sizes</title>
		<link>http://www.flynsarmy.com/2013/03/get-mysql-table-sizes/</link>
		<comments>http://www.flynsarmy.com/2013/03/get-mysql-table-sizes/#comments</comments>
		<pubDate>Tue, 19 Mar 2013 01:10:53 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Database]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1406</guid>
		<description><![CDATA[Here is a super simple SQL query to determine the size of all tables in a given database:
<pre lang="sql" escaped="true">SELECT table_name AS "Table",
	round(((data_length + index_length) / 1024 / 1024), 2) AS Size_in_MB
FROM information_schema.TABLES 
WHERE table_schema = 'my_db_name'
ORDER BY Size_in_MB DESC</pre>
This can be very useful when debugging for instance in figuring out which rogue plugin/module on your site is dumping hundreds of megs of data into your database.]]></description>
				<content:encoded><![CDATA[<p>Here is a super simple SQL query to determine the size of all tables in a given database:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #993333; font-weight: bold;">TABLE_NAME</span> <span style="color: #993333; font-weight: bold;">AS</span> <span style="color: #ff0000;">&quot;Table&quot;</span><span style="color: #66cc66;">,</span>
	round<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>data_length <span style="color: #66cc66;">+</span> index_length<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">1024</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> Size_in_MB
<span style="color: #993333; font-weight: bold;">FROM</span> information_schema<span style="color: #66cc66;">.</span><span style="color: #993333; font-weight: bold;">TABLES</span> 
<span style="color: #993333; font-weight: bold;">WHERE</span> table_schema <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'my_db_name'</span>
<span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> Size_in_MB <span style="color: #993333; font-weight: bold;">DESC</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>This can be very useful when debugging for instance in figuring out which rogue plugin/module on your site is dumping hundreds of megs of data into your database.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2013/03/get-mysql-table-sizes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix Home and End Keys on Mac OS X</title>
		<link>http://www.flynsarmy.com/2013/03/fix-home-and-end-keys-on-mac-os-x/</link>
		<comments>http://www.flynsarmy.com/2013/03/fix-home-and-end-keys-on-mac-os-x/#comments</comments>
		<pubDate>Sun, 17 Mar 2013 23:04:27 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[OSX]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1393</guid>
		<description><![CDATA[<strong>Disclaimer:</strong> The details of this post are shamelessly ripped from <a href="http://phatness.com/2007/08/fix-home-and-end-keys-on-mac-os-x/" title="Fix Home and End Keys on Mac OS X &#38;#8211;  Phatness.com" target="_blank">phatness.com</a>. All credit to those guys, I just wanted a copy for myself for future reference.

<hr />

On every OS ever, Home, End, Pg Up and Pg Down keys work like so:
<pre lang="text" escaped="true">- Home -&#62; move the cursor to the beginning of the line
- End -&#62; move the cursor to the end of the line
- Pg-Up -&#62; move the cursor up the length of the viewport
- Pg-Dn -&#62; move the cursor down the length of the viewport</pre>
But OSX in all its infinate wisdom decided that doesn't make sense. Instead they should work like so:
<pre lang="text" escaped="true">- Home -&#62; move (nothing, not even the cursor, just your view) to the beginning of the DOCUMENT
- End -&#62; move (nothing, not even the cursor, just your view) to the end of the DOCUMENT
- Pg-Up -&#62; move (nothing, not even the cursor, just your view) up the length of the viewport
- Pg-Dn -&#62; move (nothing, not even the cursor, just your view) down the length of the viewport</pre>
Now I'm not one to criticise... but that's stupid and anyone who likes it is stupid ;)

&#160;
<h3>How to Fix</h3>
There's a really useful open source utility out there called <a href="http://doublecommand.sourceforge.net/" title="DoubleCommand" target="_blank">DoubleCommand</a> which is highly recommended and I'm sure broadly used. If you want a non-application solution there are also some config files to edit to get the job done.
<h4>Most Applications</h4>
Create a file
<em>/home/&#60;username&#62;/Library/KeyBindings/DefaultKeyBinding.dict</em> and add the following:
<pre lang="text" escaped="true">{
    "\UF729"  = "moveToBeginningOfLine:";
    "$\UF729" = "moveToBeginningOfLineAndModifySelection:";
    "\UF72B"  = "moveToEndOfLine:";
    "$\UF72B" = "moveToEndOfLineAndModifySelection:";
    "\UF72C"  = "pageUp:";
    "\UF72D"  = "pageDown:";
}</pre>
<h4><span style="font-size: 1em;">Terminal</span></h4>
[caption id="attachment_1400" align="aligncenter" width="300"]<a href="http://www.flynsarmy.com/wp-content/uploads/2013/03/terminal-preferences.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2013/03/terminal-preferences-300x258.png" alt="Terminal preferences" width="300" height="258" class="size-medium wp-image-1400" /></a> Terminal preferences[/caption]

Open Terminal - Preferences - Settings - Keyboard. Edit each of the following setting their action to 'send string to shell'.
<pre lang="text" escaped="true">Key		Escape Sequence

Home		\033[1~
End		\033[4~
Page Up		\033[5~
Page Down	\033[6~</pre>
Now open /home/&#60;username&#62;/.inputrc and add:
<pre lang="text" escaped="true">"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
set completion-ignore-case On</pre>
<h4><span style="font-size: 1em;">Other notes</span></h4>
Restart your machine for changes to take affect. Restarting individual applications also works if you can't restart for whatever reason. I hear Firefox needs its own changes - if you happen to know what those are comment below and I'll add them in.]]></description>
				<content:encoded><![CDATA[<p><strong>Disclaimer:</strong> The details of this post are shamelessly ripped from <a href="http://phatness.com/2007/08/fix-home-and-end-keys-on-mac-os-x/" title="Fix Home and End Keys on Mac OS X &amp;#8211;  Phatness.com" target="_blank">phatness.com</a>. All credit to those guys, I just wanted a copy for myself for future reference.</p>
<hr />
<p>On every OS ever, Home, End, Pg Up and Pg Down keys work like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">- Home -&gt; move the cursor to the beginning of the line
- End -&gt; move the cursor to the end of the line
- Pg-Up -&gt; move the cursor up the length of the viewport
- Pg-Dn -&gt; move the cursor down the length of the viewport</pre></td></tr></table></div>
<!-- end from cahe -->
<p>But OSX in all its infinate wisdom decided that doesn&#8217;t make sense. Instead they should work like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">- Home -&gt; move (nothing, not even the cursor, just your view) to the beginning of the DOCUMENT
- End -&gt; move (nothing, not even the cursor, just your view) to the end of the DOCUMENT
- Pg-Up -&gt; move (nothing, not even the cursor, just your view) up the length of the viewport
- Pg-Dn -&gt; move (nothing, not even the cursor, just your view) down the length of the viewport</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Now I&#8217;m not one to criticise&#8230; but that&#8217;s stupid and anyone who likes it is stupid <img src='http://www.flynsarmy.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<h3>How to Fix</h3>
<p>There&#8217;s a really useful open source utility out there called <a href="http://doublecommand.sourceforge.net/" title="DoubleCommand" target="_blank">DoubleCommand</a> which is highly recommended and I&#8217;m sure broadly used. If you want a non-application solution there are also some config files to edit to get the job done.</p>
<h4>Most Applications</h4>
<p>Create a file<br />
<em>/home/&lt;username&gt;/Library/KeyBindings/DefaultKeyBinding.dict</em> and add the following:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">{
    &quot;UF729&quot;  = &quot;moveToBeginningOfLine:&quot;;
    &quot;$UF729&quot; = &quot;moveToBeginningOfLineAndModifySelection:&quot;;
    &quot;UF72B&quot;  = &quot;moveToEndOfLine:&quot;;
    &quot;$UF72B&quot; = &quot;moveToEndOfLineAndModifySelection:&quot;;
    &quot;UF72C&quot;  = &quot;pageUp:&quot;;
    &quot;UF72D&quot;  = &quot;pageDown:&quot;;
}</pre></td></tr></table></div>
<!-- end from cahe -->
<h4><span style="font-size: 1em;">Terminal</span></h4>
<div id="attachment_1400" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flynsarmy.com/wp-content/uploads/2013/03/terminal-preferences.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2013/03/terminal-preferences-300x258.png" alt="Terminal preferences" width="300" height="258" class="size-medium wp-image-1400" /></a><p class="wp-caption-text">Terminal preferences</p></div>
<p>Open Terminal &#8211; Preferences &#8211; Settings &#8211; Keyboard. Edit each of the following setting their action to &#8216;send string to shell&#8217;.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">Key		Escape Sequence
&nbsp;
Home		 33[1~
End		 33[4~
Page Up		 33[5~
Page Down	 33[6~</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Now open /home/&lt;username&gt;/.inputrc and add:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">&quot;e[1~&quot;: beginning-of-line
&quot;e[4~&quot;: end-of-line
&quot;e[5~&quot;: history-search-backward
&quot;e[6~&quot;: history-search-forward
&quot;e[3~&quot;: delete-char
&quot;e[2~&quot;: quoted-insert
&quot;e[5C&quot;: forward-word
&quot;e[5D&quot;: backward-word
&quot;ee[C&quot;: forward-word
&quot;ee[D&quot;: backward-word
set completion-ignore-case On</pre></td></tr></table></div>
<!-- end from cahe -->
<h4><span style="font-size: 1em;">Other notes</span></h4>
<p>Restart your machine for changes to take affect. Restarting individual applications also works if you can&#8217;t restart for whatever reason. I hear Firefox needs its own changes &#8211; if you happen to know what those are comment below and I&#8217;ll add them in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2013/03/fix-home-and-end-keys-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Drastically Speed Up WordPress with Redis</title>
		<link>http://www.flynsarmy.com/2013/03/how-to-drastically-speed-up-wordpress-with-redis/</link>
		<comments>http://www.flynsarmy.com/2013/03/how-to-drastically-speed-up-wordpress-with-redis/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 22:13:01 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1364</guid>
		<description><![CDATA[I recently came across a <a href="http://www.jimwestergren.com/wordpress-with-redis-as-a-frontend-cache/" title="How to load WordPress in a few milliseconds using Redis" target="_blank">tutorial</a> on sitting Redis infront of WordPress allowing for insanely fast page generation. I gave it a try and it really works, in fact I'm now using it on this very site! The best part however is the fact that the script requires absolutely no modification to your existing WordPress site save for 1 line of htaccess. Truly amazing.

Below I'll detail my slightly modified version of Jim's script along with some metrics.

&#160;
<h3>Firstly, What is Redis and what will it do for me?</h3>
The <a href="http://redis.io/topics/introduction" title="Introduction to Redis – Redis" target="_blank">Redis website</a> describes Redis as
<blockquote>... an open source, BSD licensed, advanced <strong>key-value store</strong>. It is often referred to as a <strong>data structure server</strong> since keys can contain <a href="http://redis.io/topics/data-types#strings">strings</a>, <a href="http://redis.io/topics/data-types#hashes">hashes</a>, <a href="http://redis.io/topics/data-types#lists">lists</a>, <a href="http://redis.io/topics/data-types#sets">sets</a> and <a href="http://redis.io/topics/data-types#sorted-sets">sorted sets</a>.</blockquote>
What does this mean? Essentially it's <a href="http://memcached.org/" title="memcached - a distributed memory object caching system" target="_blank">Memcached</a> but more useful. Redis stores key-value pairs in memory and spits them out when requested. Unlike Memcached it has built in persistence but what's most important to us is that it's fast - very fast.

We'll be using Redis to speed up our site by loading cached pages from it directly without even booting up WordPress. This will save a large amount of page generation time and get out site infront of our users' eyeballs faster.

&#160;
<h3>Exactly how much faster are we talking?</h3>
In my very unscientific tests, loading <a href="http://www.flynsarmy.com" title="Flynsarmy" target="_blank">www.flynsarmy.com</a> a bunch of times resulted in the following:
<table border="0" cellpadding="0" cellspacing="10">
<tbody>
<tr>
<th>Before (Secs)</th>
<th>After (Secs)</th>
</tr>
<tr>
<td width="50%">1.556
0.468
0.494
0.498
0.492
0.514
0.499
0.511
0.499</td>
<td>0.02001
0.00896
0.00883
0.00959
0.01472
0.00916
0.00915
0.00756
0.01989</td>
</tr>
</tbody>
</table>
As you can see from the table above this equates to a <strong>20x to 50x speed increase</strong> and that was WITH <a href="http://wordpress.org/extend/plugins/w3-total-cache/" title="WordPress - W3 Total Cache - WordPress Plugins" target="_blank">W3 Total Cache</a> installed! Results of course may vary but I think you get the picture.]]></description>
				<content:encoded><![CDATA[<p>I recently came across a <a href="http://www.jimwestergren.com/wordpress-with-redis-as-a-frontend-cache/" title="How to load WordPress in a few milliseconds using Redis" target="_blank">tutorial</a> on sitting Redis infront of WordPress allowing for insanely fast page generation. I gave it a try and it really works, in fact I&#8217;m now using it on this very site! The best part however is the fact that the script requires absolutely no modification to your existing WordPress site save for 1 line of htaccess. Truly amazing.</p>
<p>Below I&#8217;ll detail my slightly modified version of Jim&#8217;s script along with some metrics.</p>
<p>&nbsp;</p>
<h3>Firstly, What is Redis and what will it do for me?</h3>
<p>The <a href="http://redis.io/topics/introduction" title="Introduction to Redis – Redis" target="_blank">Redis website</a> describes Redis as</p>
<blockquote><p>&#8230; an open source, BSD licensed, advanced <strong>key-value store</strong>. It is often referred to as a <strong>data structure server</strong> since keys can contain <a href="http://redis.io/topics/data-types#strings">strings</a>, <a href="http://redis.io/topics/data-types#hashes">hashes</a>, <a href="http://redis.io/topics/data-types#lists">lists</a>, <a href="http://redis.io/topics/data-types#sets">sets</a> and <a href="http://redis.io/topics/data-types#sorted-sets">sorted sets</a>.</p></blockquote>
<p>What does this mean? Essentially it&#8217;s <a href="http://memcached.org/" title="memcached - a distributed memory object caching system" target="_blank">Memcached</a> but more useful. Redis stores key-value pairs in memory and spits them out when requested. Unlike Memcached it has built in persistence but what&#8217;s most important to us is that it&#8217;s fast &#8211; very fast.</p>
<p>We&#8217;ll be using Redis to speed up our site by loading cached pages from it directly without even booting up WordPress. This will save a large amount of page generation time and get out site infront of our users&#8217; eyeballs faster.</p>
<p>&nbsp;</p>
<h3>Exactly how much faster are we talking?</h3>
<p>In my very unscientific tests, loading <a href="http://www.flynsarmy.com" title="Flynsarmy" target="_blank">www.flynsarmy.com</a> a bunch of times resulted in the following:</p>
<table border="0" cellpadding="0" cellspacing="10">
<tbody>
<tr>
<th>Before (Secs)</th>
<th>After (Secs)</th>
</tr>
<tr>
<td width="50%">1.556<br />
0.468<br />
0.494<br />
0.498<br />
0.492<br />
0.514<br />
0.499<br />
0.511<br />
0.499</td>
<td>0.02001<br />
0.00896<br />
0.00883<br />
0.00959<br />
0.01472<br />
0.00916<br />
0.00915<br />
0.00756<br />
0.01989</td>
</tr>
</tbody>
</table>
<p>As you can see from the table above this equates to a <strong>20x to 50x speed increase</strong> and that was WITH <a href="http://wordpress.org/extend/plugins/w3-total-cache/" title="WordPress - W3 Total Cache - WordPress Plugins" target="_blank">W3 Total Cache</a> installed! Results of course may vary but I think you get the picture.</p>
<p>&nbsp;</p>
<h3>Installation</h3>
<p>Here&#8217;s how our script will work. When a visitor hits our site, the script will grab the URL the visitor is loading  and check if we have a cached copy in Redis. If we do, serve it. Otherwise generate the page and cache a copy for future serving.</p>
<p>There are a few details here to note:</p>
<ul>
<li>cached pages do not expire not unless explicitly deleted or reset</li>
<li>appending a ?c=y to a url deletes the entire cache of the domain, only works when you are logged in</li>
<li>appending a ?r=y to a url deletes the cache of that url</li>
<li>submitting a comment deletes the cache of that page</li>
<li>refreshing (f5) a page deletes the cache of that page</li>
<li>includes a debug mode, stats are displayed at the bottom most part after &lt;/html&gt;</li>
</ul>
<p>OK with all that out of the way, let&#8217;s get started.</p>
<h4>Install Redis</h4>
<p>On Ubuntu this is very easy. Firstly add a <a href="https://launchpad.net/~rwky/+archive/redis" title="Redis : Rowan" target="_blank">PPA</a> to make sure you can get a recent version of Redis:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-add-repository ppa:rwky<span style="color: #000000; font-weight: bold;">/</span>redis</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Then install:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get update</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get upgrade</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> redis-server</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Note: Older versions of ubuntu may need to install <em>python-software-properties</em> before calling <em>apt-add-repository</em>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> python-software-properties</pre></td></tr></table></div>
<!-- end from cahe -->
<h4>Get the latest copy of Predis</h4>
<p><a href="https://github.com/nrk/predis" title="nrk/predis" target="_blank">Predis</a> is a library that lets PHP communicate with Redis. Drop it into your sites root folder next to <em>index.php.</em></p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>site<span style="color: #000000; font-weight: bold;">/</span>root
<span style="color: #c20cb9; font-weight: bold;">git clone</span> https:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>nrk<span style="color: #000000; font-weight: bold;">/</span>predis.git</pre></td></tr></table></div>
<!-- end from cahe -->
<h4>Add the script</h4>
<p>Our script will communicate to Predis which in turn talks to Redis. Create a file also next to <em>index.php</em> in your sites root folder called <em>index-with-redis.php</em> and drop the following into it:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*</span>
<span style="color: #666666; font-style: italic;">&nbsp;   Author: Jim Westergren, Jeedo Aquino &amp; Flynsarmy</span>
<span style="color: #666666; font-style: italic;">&nbsp;   File: index-with-redis.php</span>
<span style="color: #666666; font-style: italic;">&nbsp;   Updated: 2012-10-25</span>
&nbsp;
<span style="color: #666666; font-style: italic;">&nbsp;   This is a redis caching system for wordpress.</span>
<span style="color: #666666; font-style: italic;">&nbsp;   see more here: www.jimwestergren.com/wordpress-with-redis-as-a-frontend-cache/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">&nbsp;   Originally written by Jim Westergren but improved by Jeedo Aquino.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">&nbsp;   some caching mechanics are different from jim's script which is summarized below:</span>
&nbsp;
<span style="color: #666666; font-style: italic;">&nbsp;   - cached pages do not expire not unless explicitly deleted or reset</span>
<span style="color: #666666; font-style: italic;">&nbsp;   - appending a ?c=y to a url deletes the entire cache of the domain, only works when you are logged in</span>
<span style="color: #666666; font-style: italic;">&nbsp;   - appending a ?r=y to a url deletes the cache of that url</span>
<span style="color: #666666; font-style: italic;">&nbsp;   - submitting a comment deletes the cache of that page</span>
<span style="color: #666666; font-style: italic;">&nbsp;   - refreshing (f5) a page deletes the cache of that page</span>
<span style="color: #666666; font-style: italic;">&nbsp;   - includes a debug mode, stats are displayed at the bottom most part after &lt;/html&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">&nbsp;   for setup and configuration see more here:</span>
&nbsp;
<span style="color: #666666; font-style: italic;">&nbsp;   www.jeedo.net/lightning-fast-wordpress-with-nginx-redis/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">&nbsp;   use this script at your own risk. i currently use this albeit a slightly modified version</span>
<span style="color: #666666; font-style: italic;">&nbsp;   to display a redis badge whenever a cache is displayed.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">*/</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// change vars here</span>
<span style="display:block;background-color: #ffc;"><span style="color: #000088;">$debug</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>			<span style="color: #666666; font-style: italic;">// set to 1 if you wish to see execution time and cache actions</span></span><span style="display:block;background-color: #ffc;"><span style="color: #000088;">$display_powered_by_redis</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// set to 1 if you want to display a powered by redis message with execution time, see below</span></span>&nbsp;
<span style="color: #000088;">$start</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">// start timing page exec</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// if cloudflare is enabled</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_CF_CONNECTING_IP'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_CF_CONNECTING_IP'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// from wp</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'WP_USE_THEMES'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// init predis</span>
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'predis/lib/Predis/Autoloader.php'</span><span style="color: #339933;">;</span>
PredisAutoloader<span style="color: #339933;">::</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$redis</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PredisClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// init vars</span>
<span style="color: #000088;">$cached</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?r=y'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'?c=y'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dkey</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ukey</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// check if page isn't a comment submission</span>
<span style="color: #000088;">$submit</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_CACHE_CONTROL'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_CACHE_CONTROL'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'max-age=0'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// check if logged in to wp</span>
<span style="color: #000088;">$cookie</span> <span style="color: #339933;">=</span> <span style="color: #990000;">var_export</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_COOKIE</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$loggedin</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/wordpress_logged_in/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cookie</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// check if a cache of the page exists</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$loggedin</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$submit</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hexists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/feed/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hget</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$cached</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'this is a cache'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// if a comment was submitted or clear page cache request was made delete cache of page</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$submit</span> <span style="color: #339933;">||</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="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'?r=y'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./wp-blog-header.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hdel</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'cache of page deleted'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// delete entire cache, works only if logged in</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$loggedin</span> <span style="color: #339933;">&amp;&amp;</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="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'?c=y'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./wp-blog-header.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">del</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'domain cache flushed'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'no cache to flush'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// if logged in don't cache anything</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$loggedin</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./wp-blog-header.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'not cached'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// cache the page</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// turn on output buffering</span>
    <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./wp-blog-header.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// get contents of output buffer</span>
    <span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// clean output buffer</span>
    <span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Store to cache only if the page exist and is not a search result.</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_404<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>is_search<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// store html contents to redis cache</span>
        <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$msg</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'cache is set'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$end</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// get end execution time</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// show messages if debug is enabled</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$debug</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;REDIS DEBUG &quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$msg</span><span style="color: #339933;">.</span><span style="color: #0000ff;">': '</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> t_exec<span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #339933;">,</span> <span style="color: #000088;">$end</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cached</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$display_powered_by_redis</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="display:block;background-color: #ffc;">    <span style="color: #666666; font-style: italic;">// You should move this CSS to your CSS file and change the: float:right;margin:20px 0;</span></span><span style="display:block;background-color: #ffc;">    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;style&gt;#redis_powered{float:right;margin:20px 0;background:url(http://images.staticjw.com/jim/3959/redis.png) 10px no-repeat #fff;border:1px solid #D7D8DF;padding:10px;width:190px;}</span></span><span style="display:block;background-color: #ffc;"><span style="color: #0000ff;">#redis_powered div{width:190px;text-align:right;font:10px/11px arial,sans-serif;color:#000;}&lt;/style&gt;&quot;</span><span style="color: #339933;">;</span></span><span style="display:block;background-color: #ffc;">    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;a href='http://www.jimwestergren.com/wordpress-with-redis-as-a-frontend-cache/' style='text-decoration:none;'&gt;&lt;div id='redis_powered'&gt;&lt;div&gt;Page generated in&lt;br/&gt; &quot;</span><span style="color: #339933;">.</span>t_exec<span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #339933;">,</span> <span style="color: #000088;">$end</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; sec&lt;/div&gt;&lt;/div&gt;&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span></span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// time diff</span>
<span style="color: #000000; font-weight: bold;">function</span> t_exec<span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #339933;">,</span> <span style="color: #000088;">$end</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$t</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>getmicrotime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$end</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> getmicrotime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$start</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// get time</span>
<span style="color: #000000; font-weight: bold;">function</span> getmicrotime<span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$usec</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sec</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$t</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$usec</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>float<span style="color: #009900;">&#41;</span><span style="color: #000088;">$sec</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>This is a slightly modified version of <a href="http://www.jimwestergren.com/wordpress-with-redis-as-a-frontend-cache/" title="How to load WordPress in a few milliseconds using Redis" target="_blank">Jim&#8217;s script</a> with support for the newer version of Predis. I&#8217;ve highlighted a few lines that it&#8217;s safe to play around with.</p>
<h4>Turn it on and off</h4>
<p>Everything is now in place. It&#8217;s time to turn it on and off. This is the only change you&#8217;ll need to make to your actual site. Open .htaccess in your sites root folder and add the following line at the top:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">DirectoryIndex</span> index.html index-with-redis.php index.php</pre></td></tr></table></div>
<!-- end from cahe -->
<p>That&#8217;s it! Open an incognito/private browsing window and load your site. Load it a second time and scroll to the very bottom of your page. If all went well you should see an image something like the following:</p>
<div id="attachment_1378" class="wp-caption aligncenter" style="width: 229px"><a href="http://www.flynsarmy.com/wp-content/uploads/2013/03/page-generated-with-redis-2.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2013/03/page-generated-with-redis-2.png" alt="Page generated in 0.0041 seconds" width="219" height="52" class="size-full wp-image-1378" /></a><p class="wp-caption-text">Extremely fast page generation time thanks to Redis Cache</p></div>
<p>&nbsp;</p>
<h3>Cache Invalidation</h3>
<p>This Redis script never invalidates its cache unless you hit F5 of use one of the query strings mentioned above. This can be a problem when creating, editing or deleting posts, making comments etc.</p>
<p>Take creating a new post for example. That will push the last post currently on your homepage onto page 2, the last page on page 2 to page 3 and so on. The cache on those pages aren&#8217;t getting invalidated essentially hiding the overflowing posts.</p>
<p>There are two modifications I came up with to handle this.</p>
<h4>Only cache home, individual post and page pages</h4>
<p>Change line 66 of index-with-redis.php from</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$loggedin</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$submit</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hexists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/feed/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>to</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$loggedin</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$submit</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/feed/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/page/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/category/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hexists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<h4>Invalidate when updating a post, comment or category</h4>
<p>If we&#8217;re updating a post or comment we want that change to reflect instantly to site visitors. Adding or removing a comment or changing your excerpt could also affect the homepage so clear that too.</p>
<p>In your themes <em>functions.php</em> file add the following:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 *  Redis Cache invalidation
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> get_redis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require_once</span> ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'predis/lib/Predis/Autoloader.php'</span><span style="color: #339933;">;</span>
	PredisAutoloader<span style="color: #339933;">::</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> PredisClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Chances are you'll have a list of categories on every page.</span>
<span style="color: #666666; font-style: italic;">// So delete all site cache if categories are messed with</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add_category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_all'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'delete_category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_all'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_all'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Delete all site cache for the current domain</span>
<span style="color: #000000; font-weight: bold;">function</span> redis_invalidate_all<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$redis</span> <span style="color: #339933;">=</span> get_redis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$dkey</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">del</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// When adding/editing/deleting a post, invalidate post and home pages</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'trashed_post'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'save_post'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> redis_invalidate_post<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post_id</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Don't delete cache on auto-save</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'autosave'</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Don't delete cache if we're saving as draft or pending</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'save'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'save'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Save Draft'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Save as Pending'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$redis</span> <span style="color: #339933;">=</span> get_redis<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$dkey</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Invalidate homepage</span>
	<span style="color: #000088;">$ukey</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hexists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hdel</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Invalidate post page</span>
	<span style="color: #000088;">$ukey</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$permalink</span> <span style="color: #339933;">=</span> get_permalink<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post_id</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hexists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$redis</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hdel</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dkey</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ukey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// When adding/editing/deleting a comment, invalidate post and home pages</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comment_closed'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comment_post'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'edit_comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'delete_comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_set_comment_status'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redis_invalidate_comment'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> redis_invalidate_comment<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$comment_id</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$comment</span> <span style="color: #339933;">=</span> get_comment<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$comment_id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	redis_invalidate_post<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_post_ID</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2013/03/how-to-drastically-speed-up-wordpress-with-redis/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Edit WordPress Posts from the Front End</title>
		<link>http://www.flynsarmy.com/2013/03/edit-wordpress-posts-from-the-front-end/</link>
		<comments>http://www.flynsarmy.com/2013/03/edit-wordpress-posts-from-the-front-end/#comments</comments>
		<pubDate>Tue, 05 Mar 2013 00:08:34 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1344</guid>
		<description><![CDATA[I have a project coming up involving editing WordPress posts from the front end of the site. There are a bunch of plugins that let you do this the coolest of which seems to be <a href="http://wordpress.org/extend/plugins/front-end-editor/" title="WordPress - Front-end Editor - WordPress Plugins" target="_blank">Front-end Editor</a> but I wanted to come up with my own solution. Luckily it turned out to be surprisingly quick and painless!

For this tutorial I'll be editing the cafe custom post type from my <a href="http://www.flynsarmy.com/2013/03/adding-custom-post-types-fields-and-taxonomies-in-wordpress/" title="Adding Custom Post Types, Fields and Taxonomies in WordPress &#124; Flynsarmy" target="_blank">last post</a>.]]></description>
				<content:encoded><![CDATA[<p>I have a project coming up involving editing WordPress posts from the front end of the site. There are a bunch of plugins that let you do this the coolest of which seems to be <a href="http://wordpress.org/extend/plugins/front-end-editor/" title="WordPress - Front-end Editor - WordPress Plugins" target="_blank">Front-end Editor</a> but I wanted to come up with my own solution. Luckily it turned out to be surprisingly quick and painless!</p>
<p>For this tutorial I&#8217;ll be editing the cafe custom post type from my <a href="http://www.flynsarmy.com/2013/03/adding-custom-post-types-fields-and-taxonomies-in-wordpress/" title="Adding Custom Post Types, Fields and Taxonomies in WordPress | Flynsarmy" target="_blank">last post</a>.</p>
<p>&nbsp;</p>
<h3>The Frontend</h3>
<p>I want to add a modal to my cafe pages that lets visitors edit the cafe they&#8217;re looking at.  I like <a href="http://twitter.github.com/bootstrap/" title="Bootstrap" target="_blank">Twitter Bootstrap</a> so I&#8217;m using it for theming but you can make it look however you want.</p>
<p>Drop the following code into the bottom of <em>content-cafe.php</em>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;?php</span>
<span style="color: #009900;"><span style="color: #66cc66;">//</span>Admin functions required to show taxonomy lists</span>
<span style="color: #009900;">require_once<span style="color: #66cc66;">&#40;</span>ABSPATH.<span style="color: #ff0000;">'wp-admin/includes/template.php'</span><span style="color: #66cc66;">&#41;</span>;</span>
&nbsp;
<span style="color: #009900;">$custom <span style="color: #66cc66;">=</span> get_post_custom<span style="color: #66cc66;">&#40;</span> get_the_ID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">$address <span style="color: #66cc66;">=</span> @$custom<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;address&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;</span>
<span style="color: #009900;">$website <span style="color: #66cc66;">=</span> @$custom<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;website&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;</span>
<span style="color: #009900;">$phone <span style="color: #66cc66;">=</span> @$custom<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">&quot;phone&quot;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;</span>
<span style="color: #009900;">?&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- Lazily add resources here - this is bad, do it the right way! --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;all&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php bloginfo('template_url'); ?&gt;</span></span>/packages/bootstrap/css/bootstrap.min.css&quot; /&gt;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
	.modal {width:900px;margin-left:-440px;}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php bloginfo('template_url'); ?&gt;</span></span>/packages/bootstrap/js/bootstrap.min.js&quot;&gt;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!-- Modal --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'post'</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multipart/form-data&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;editModal&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">button</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> data-dismiss<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;modal&quot;</span>&gt;</span>×<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">button</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Edit Cafe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'hidden'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'frontend'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'hidden'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'ID'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?= get_the_ID() ?&gt;</span></span>&quot; /&gt;
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'hidden'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'post_type'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?= $post-&gt;</span></span>post_type ?&gt;&quot; /&gt;
&nbsp;
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputTitle&quot;</span>&gt;</span>Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputTitle&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'post_title'</span> placeholder<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Title&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?= get_the_title() ?&gt;</span></span>&quot; /&gt;
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputURL&quot;</span>&gt;</span>URL<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputURL&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'website'</span> placeholder<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://your-cafe.com&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?= $website ?&gt;</span></span>&quot; /&gt;
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputPhone&quot;</span>&gt;</span>Phone<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputPhone&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'phone'</span> placeholder<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;(xx) xxxx xxxx&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?= $phone ?&gt;</span></span>&quot; /&gt;
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputAddress&quot;</span>&gt;</span>Address<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">textarea</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputAddress&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'address'</span> <span style="color: #000066;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;5&quot;</span>&gt;&lt;?<span style="color: #66cc66;">=</span> $address ?&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">textarea</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputCountries&quot;</span>&gt;</span>Countries<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
					<span style="color: #009900;">&lt;?php wp_terms_checklist<span style="color: #66cc66;">&#40;</span>get_the_ID<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, array<span style="color: #66cc66;">&#40;</span></span>
<span style="color: #009900;">						<span style="color: #ff0000;">'taxonomy'</span> <span style="color: #66cc66;">=</span>&gt;</span> 'countries',
					)); ?&gt;
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputContent&quot;</span>&gt;</span>Description<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
					<span style="color: #009900;">&lt;?php wp_editor<span style="color: #66cc66;">&#40;</span> get_the_content<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">'post_content'</span>, array<span style="color: #66cc66;">&#40;</span></span>
<span style="color: #009900;">						<span style="color: #ff0000;">'media_buttons'</span> <span style="color: #66cc66;">=</span>&gt;</span> false,
					)); ?&gt;
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inputImages&quot;</span>&gt;</span>Images<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
					<span style="color: #009900;">&lt;?php</span>
<span style="color: #009900;">						$attachments <span style="color: #66cc66;">=</span> get_posts<span style="color: #66cc66;">&#40;</span>array<span style="color: #66cc66;">&#40;</span></span>
<span style="color: #009900;">							<span style="color: #ff0000;">'post_type'</span> <span style="color: #66cc66;">=</span>&gt;</span> 'attachment',
							'numberposts' =&gt; -1,
							'post_status' =&gt; null,
							'post_parent' =&gt; $post-&gt;ID
						));
						if ( !$attachments )
							echo &quot;No images&quot;;
						else
						{
							?&gt;
							<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
								<span style="color: #009900;">&lt;?php foreach <span style="color: #66cc66;">&#40;</span> $attachments as $attachment <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> ?&gt;</span>
									<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
										<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
											<span style="color: #009900;">&lt;?php the_attachment_link<span style="color: #66cc66;">&#40;</span> $attachment-&gt;</span>ID , false ); ?&gt;
											<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;&lt;?php echo apply_filters<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">'the_title'</span> , $attachment-&gt;</span>post_title ); ?&gt;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
										<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
									<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
								<span style="color: #009900;">&lt;?php <span style="color: #66cc66;">&#125;</span> ?&gt;</span>
							<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
							<span style="color: #009900;">&lt;?php</span>
<span style="color: #009900;">						<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #009900;">					?&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">button</span> data-dismiss<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;modal&quot;</span>&gt;</span>Close<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">button</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">button</span>&gt;</span>Save changes<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">button</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>We also need a button to open the modal. Drop the following code wherever you want that to be:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#editModal&quot;</span> role<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> data-toggle<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;modal&quot;</span>&gt;</span>Edit Cafe<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Saving the Post</h3>
<p>Here&#8217;s the full code I used to handle the frontend form submission (dropped into functions.php):</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Frontend post editing
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> frontend_update_cafe<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;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'frontend'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'cafes'</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// $post global is required so save_cafe_custom_fields() doesn't error out</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> get_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ID'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * Format taxonomies properly for saving.
	 *
	 * Convert from
	 * $_POST[tax_input] =&gt; Array (
	 * 		[countries] =&gt; Array (0, 4, ...)
	 * )
	 * to
	 * $_POST[tax_input] =&gt; Array (
	 * 		[countries] =&gt; Australia,New Zealand
	 * )
	 */</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tax_input'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tax_input'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$taxonomy_slug</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$ids</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tax_input'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$taxonomy_slug</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_col</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
				SELECT name
				FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;terms</span>
				WHERE term_id IN (&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ids</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)
			&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$post_id</span> <span style="color: #339933;">=</span> wp_update_post<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//upload images</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_FILES</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$details</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$wp_filetype</span> <span style="color: #339933;">=</span> wp_check_filetype_and_ext<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$details</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tmp_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$details</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Only accept image uploads</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_filetype</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'ext'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'png'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
&nbsp;
		flynsarmy_add_media<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post_id</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'frontend_update_cafe'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Upload media attachments</span>
<span style="color: #666666; font-style: italic;">// See http://voodoopress.com/including-images-as-attachments-or-featured-image-in-post-from-front-end-form/</span>
<span style="color: #000000; font-weight: bold;">function</span> flynsarmy_add_media<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_handler</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$setthumb</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'false'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// check to make sure its a successful upload</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$file_handler</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!==</span> UPLOAD_ERR_OK <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;wp-admin/includes/image.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;wp-admin/includes/file.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;wp-admin/includes/media.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$attach_id</span> <span style="color: #339933;">=</span> media_handle_upload<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$file_handler</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post_id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$setthumb</span> <span style="color: #009900;">&#41;</span>
		update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_thumbnail_id'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attach_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$attach_id</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Fancy Form Elements</h3>
<p>For the most part on the frontend I just created basic form &lt;input&gt; and &lt;textarea&gt; fields but there are a couple of more advanced form elements that WP provides functions for.</p>
<h4>Adding a WYSIWYG</h4>
<p>For editing large text fields such as the post description WordPress provides a function <a href="http://codex.wordpress.org/Function_Reference/wp_editor" title="Function Reference/wp editor - WordPress Codex" target="_blank">wp_editor()</a> that displays its TinyMCE editor:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_editor<span style="color: #009900;">&#40;</span> get_the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_content'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'media_buttons'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<div id="attachment_1345" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flynsarmy.com/wp-content/uploads/2013/03/frontend-wysiwyg.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2013/03/frontend-wysiwyg-300x192.png" alt="Edit fields on the frontend of your site with WordPress's WYSIWYG editor" width="300" height="192" class="size-medium wp-image-1345" /></a><p class="wp-caption-text">Edit fields on the frontend of your site with WordPress&#8217;s WYSIWYG editor</p></div>
<p>&nbsp;</p>
<h4>Adding a Taxonomy Checkbox List</h4>
<p>I didn&#8217;t have time to figure out how to get the whole AJAX input selection stuff from the backend onto the frontend however I did manage to get a checkbox list that works nicely but it&#8217;ll depend how many taxonomy entries you have.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_terms_checklist<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'taxonomy'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'countries'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<div id="attachment_1346" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flynsarmy.com/wp-content/uploads/2013/03/frontend-taxonomy-checkboxlist.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2013/03/frontend-taxonomy-checkboxlist-300x190.png" alt="Edit taxonomy terms on the frontend of your site with a checkboxlist" width="300" height="190" class="size-medium wp-image-1346" /></a><p class="wp-caption-text">Edit taxonomy terms on the frontend of your site with a checkboxlist</p></div>
<p>&nbsp;</p>
<p>Unfortunately when we submit it&#8217;ll send the data like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">$_POST[tax_input] =&gt; Array (
	[countries] =&gt; Array (0, 4, ...)
)</pre></td></tr></table></div>
<!-- end from cahe -->
<p>but we want</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">$_POST[tax_input] =&gt; Array (
	[countries] =&gt; Australia,New Zealand
)</pre></td></tr></table></div>
<!-- end from cahe -->
<p>so in our form submit function we&#8217;ll have to write a little bit of code to grab the term names from their respective IDs. Here&#8217;s how I did it:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tax_input'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tax_input'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$taxonomy_slug</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$ids</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tax_input'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$taxonomy_slug</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_col</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
			SELECT name
			FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;terms</span>
			WHERE term_id IN (&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ids</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;)
		&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<h4><span style="font-size: 1.17em;">Media Attachments</span></h4>
<p>On the frontend I displayed my gallery of media attachments with:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000088;">$attachments</span> <span style="color: #339933;">=</span> get_posts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'post_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'attachment'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'numberposts'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'post_status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'post_parent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$attachments</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;No images&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;ul class=&quot;thumbnails&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$attachments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$attachment</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
				&lt;li class=&quot;span4&quot;&gt;
					&lt;div class=&quot;thumbnail&quot;&gt;
						<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_attachment_link<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
						&lt;h3&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> apply_filters<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'the_title'</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h3&gt;
					&lt;/div&gt;
				&lt;/li&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/ul&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>And to upload attachments when processing the post I used:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Upload media attachments</span>
<span style="color: #666666; font-style: italic;">// See http://voodoopress.com/including-images-as-attachments-or-featured-image-in-post-from-front-end-form/</span>
<span style="color: #000000; font-weight: bold;">function</span> flynsarmy_add_media<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_handler</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$setthumb</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'false'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// check to make sure its a successful upload</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_FILES</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$file_handler</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'error'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!==</span> UPLOAD_ERR_OK <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;wp-admin/includes/image.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;wp-admin/includes/file.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;wp-admin/includes/media.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$attach_id</span> <span style="color: #339933;">=</span> media_handle_upload<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$file_handler</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post_id</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$setthumb</span> <span style="color: #009900;">&#41;</span>
		update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_thumbnail_id'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attach_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$attach_id</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Call it with</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">flynsarmy_add_media<span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post_id</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Remember to prefix the function with your templatename to avoid function name clashes!</p>
<p>&nbsp;</p>
<h3>Conclusion</h3>
<p>It seems like alot of code but really there&#8217;s not much there. The brunt of the work is in the functions.php code above and everything on the frontend is up to you.</p>
<p>If you spot any issues or find any other cool functions like <a href="http://codex.wordpress.org/Function_Reference/wp_editor" title="Function Reference/wp editor - WordPress Codex" target="_blank">wp_editor()</a> or <a href="http://codex.wordpress.org/Function_Reference/wp_terms_checklist" title="Function Reference/wp terms checklist - WordPress Codex" target="_blank">wp_terms_checklist()</a> that bring alot of functionality to the frontend easily be sure to leave it in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2013/03/edit-wordpress-posts-from-the-front-end/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Custom Post Types, Fields and Taxonomies in WordPress</title>
		<link>http://www.flynsarmy.com/2013/03/adding-custom-post-types-fields-and-taxonomies-in-wordpress/</link>
		<comments>http://www.flynsarmy.com/2013/03/adding-custom-post-types-fields-and-taxonomies-in-wordpress/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 23:11:17 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1334</guid>
		<description><![CDATA[This information is pretty readily available on the internet but I figured I'd make my own post for safe keeping. I'll be adding a custom post type (Cafes) with 3 custom fields (Website, Address and Phone) and a custom taxonomy (Countries).

The following code all goes in your <a href="http://codex.wordpress.org/Functions_File_Explained" title="Functions File Explained &#38;laquo; WordPress Codex" target="_blank">functions.php</a> file.

&#160;
<h3>Custom Post Types</h3>
<pre lang="php" escaped="true" line="1">/**
 * Add Cafe post type
 */
function create_cafe_post_type() {
	register_post_type( 'cafes',
		array(
			'labels' =&#62; array(
				'name' =&#62; 'Cafes',
				'singular_name' =&#62; 'Cafe',
				'add_new' =&#62; 'Add New',
				'add_new_item' =&#62; 'Add New Cafe',
				'edit_item' =&#62; 'Edit Cafe',
				'new_item' =&#62; 'New Cafe',
				'view_item' =&#62; 'View Cafe',
				'search_items' =&#62; 'Search Cafes',
				'not_found' =&#62;  'Nothing Found',
				'not_found_in_trash' =&#62; 'Nothing found in the Trash',
				'parent_item_colon' =&#62; ''
			),
			'public' =&#62; true,
			'publicly_queryable' =&#62; true,
			'show_ui' =&#62; true,
			'query_var' =&#62; true,
			//'menu_icon' =&#62; get_stylesheet_directory_uri() . '/yourimage.png',
			'rewrite' =&#62; true,
			'capability_type' =&#62; 'post',
			'hierarchical' =&#62; false,
			'menu_position' =&#62; null,
			'supports' =&#62; array('title','editor','thumbnail')
		)
	);
}
add_action( 'init', 'create_cafe_post_type' );</pre>
&#160;
<h3>Custom Taxonomies</h3>
<a href="http://codex.wordpress.org/Taxonomies" title="Taxonomies &#38;laquo; WordPress Codex" target="_blank">Taxonomies</a> are basically tags for your post types. Add the following below the <a href="http://codex.wordpress.org/Function_Reference/register_post_type" title="Function Reference/register post type &#38;laquo; WordPress Codex" target="_blank">register_post_type</a> call above:
<pre lang="php" escaped="true" line="1">
//Cafe countries taxonomy
register_taxonomy("countries", array("cafes"), array(
	"hierarchical" =&#62; false,
	"label" =&#62; "Countries",
	"singular_label" =&#62; "Country",
	"rewrite" =&#62; true
));</pre>
&#160;
<h3>Custom Fields</h3>
This is the hardest of the lot. It's not really hard though, just alot of HTML to make the meta boxes. You can put any HTML you like in meta boxes, I just like to keep mine looking like standard WP fields:
<pre lang="php" escaped="true" line="1">&#60;?php
/**
 * Add cafe custom fields
 */
function add_cafe_meta_boxes() {
	add_meta_box("cafe_contact_meta", "Contact Details", "add_contact_details_cafe_meta_box", "cafes", "normal", "low");
}
function add_contact_details_cafe_meta_box()
{
	global $post;
	$custom = get_post_custom( $post-&#62;ID );

	?&#62;
	&#60;style&#62;.width99 {width:99%;}&#60;/style&#62;
	&#60;p&#62;
		&#60;label&#62;Address:&#60;/label&#62;&#60;br /&#62;
		&#60;textarea rows="5" name="address" class="width99"&#62;&#60;?= @$custom["address"][0] ?&#62;&#60;/textarea&#62;
	&#60;/p&#62;
	&#60;p&#62;
		&#60;label&#62;Website:&#60;/label&#62;&#60;br /&#62;
		&#60;input type="text" name="website" value="&#60;?= @$custom["website"][0] ?&#62;" class="width99" /&#62;
	&#60;/p&#62;
	&#60;p&#62;
		&#60;label&#62;Phone:&#60;/label&#62;&#60;br /&#62;
		&#60;input type="text" name="phone" value="&#60;?= @$custom["phone"][0] ?&#62;" class="width99" /&#62;
	&#60;/p&#62;
	&#60;?php
}
/**
 * Save custom field data when creating/updating posts
 */
function save_cafe_custom_fields(){
  global $post;

  update_post_meta($post-&#62;ID, "address", @$_POST["address"]);
  update_post_meta($post-&#62;ID, "website", @$_POST["website"]);
  update_post_meta($post-&#62;ID, "phone", @$_POST["phone"]);
}
add_action( 'admin_init', 'add_cafe_meta_boxes' );
add_action( 'save_post', 'save_cafe_custom_fields' );</pre>
&#160;
<h3>Custom Templates</h3>
You may want your new post type to look different from standard posts. This can be done using custom templates. The WordPress <a href="http://codex.wordpress.org/Post_Type_Templates" title="Post Type Templates - WordPress Codex" target="_blank">codex</a> cover custom post type templates nicely but I'll quickly go over what I did for completeness. I'm using <a href="http://wordpress.org/extend/themes/twentytwelve" title="WordPress - Twenty Twelve - Free WordPress Themes" target="_blank">twentytwelve</a> theme in my demo but this should apply for most themes.
<ol>
	<li>Duplicate <em>single.php</em> into <em>single-&#60;post type&#62;.php</em></li>
	<li>Replace
<pre lang="php" escaped="true">&#60;?php get_template_part( 'content', get_post_format() ); ?&#62;</pre>
with
<pre lang="php" escaped="true">&#60;?php get_template_part( 'content', '&#60;post type&#62;' ); ?&#62;</pre>
</li>
	<li>Duplicate <em>content.php</em> into <em>content-&#60;post type&#62;.php</em> and modify however you like</li>
</ol>
&#160;
<h3>Conclusion</h3>
And we're done! Always remember to check the WordPress documentation for the various functions involved if you want to customize. Lots of useful information in there.]]></description>
				<content:encoded><![CDATA[<p>This information is pretty readily available on the internet but I figured I&#8217;d make my own post for safe keeping. I&#8217;ll be adding a custom post type (Cafes) with 3 custom fields (Website, Address and Phone) and a custom taxonomy (Countries).</p>
<p>The following code all goes in your <a href="http://codex.wordpress.org/Functions_File_Explained" title="Functions File Explained &amp;laquo; WordPress Codex" target="_blank">functions.php</a> file.</p>
<p>&nbsp;</p>
<h3>Custom Post Types</h3>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Add Cafe post type
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> create_cafe_post_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_post_type<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'cafes'</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'labels'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Cafes'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'singular_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Cafe'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'add_new'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Add New'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'add_new_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Add New Cafe'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'edit_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Edit Cafe'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'new_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'New Cafe'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'view_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'View Cafe'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'search_items'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Search Cafes'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'not_found'</span> <span style="color: #339933;">=&gt;</span>  <span style="color: #0000ff;">'Nothing Found'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'not_found_in_trash'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Nothing found in the Trash'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'parent_item_colon'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
			<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'public'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'publicly_queryable'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'show_ui'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #666666; font-style: italic;">//'menu_icon' =&gt; get_stylesheet_directory_uri() . '/yourimage.png',</span>
			<span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'capability_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'menu_position'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'supports'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'editor'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'thumbnail'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'create_cafe_post_type'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Custom Taxonomies</h3>
<p><a href="http://codex.wordpress.org/Taxonomies" title="Taxonomies &amp;laquo; WordPress Codex" target="_blank">Taxonomies</a> are basically tags for your post types. Add the following below the <a href="http://codex.wordpress.org/Function_Reference/register_post_type" title="Function Reference/register post type &amp;laquo; WordPress Codex" target="_blank">register_post_type</a> call above:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Cafe countries taxonomy</span>
register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;countries&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cafes&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">&quot;hierarchical&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">&quot;label&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Countries&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">&quot;singular_label&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Country&quot;</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">&quot;rewrite&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Custom Fields</h3>
<p>This is the hardest of the lot. It&#8217;s not really hard though, just alot of HTML to make the meta boxes. You can put any HTML you like in meta boxes, I just like to keep mine looking like standard WP fields:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Add cafe custom fields
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> add_cafe_meta_boxes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	add_meta_box<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;cafe_contact_meta&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Contact Details&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;add_contact_details_cafe_meta_box&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;cafes&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;normal&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;low&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> add_contact_details_cafe_meta_box<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$custom</span> <span style="color: #339933;">=</span> get_post_custom<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;style&gt;.width99 {width:99%;}&lt;/style&gt;
	&lt;p&gt;
		&lt;label&gt;Address:&lt;/label&gt;&lt;br /&gt;
		&lt;textarea rows=&quot;5&quot; name=&quot;address&quot; class=&quot;width99&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #339933;">@</span><span style="color: #000088;">$custom</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;address&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;
	&lt;/p&gt;
	&lt;p&gt;
		&lt;label&gt;Website:&lt;/label&gt;&lt;br /&gt;
		&lt;input type=&quot;text&quot; name=&quot;website&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #339933;">@</span><span style="color: #000088;">$custom</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;website&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;width99&quot; /&gt;
	&lt;/p&gt;
	&lt;p&gt;
		&lt;label&gt;Phone:&lt;/label&gt;&lt;br /&gt;
		&lt;input type=&quot;text&quot; name=&quot;phone&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #339933;">@</span><span style="color: #000088;">$custom</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;phone&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;width99&quot; /&gt;
	&lt;/p&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009933; font-style: italic;">/**
 * Save custom field data when creating/updating posts
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> save_cafe_custom_fields<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post</span> <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;address&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">@</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;address&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;website&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">@</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;website&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    update_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;phone&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">@</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;phone&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'admin_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_cafe_meta_boxes'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'save_post'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'save_cafe_custom_fields'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Custom Templates</h3>
<p>You may want your new post type to look different from standard posts. This can be done using custom templates. The WordPress <a href="http://codex.wordpress.org/Post_Type_Templates" title="Post Type Templates - WordPress Codex" target="_blank">codex</a> cover custom post type templates nicely but I&#8217;ll quickly go over what I did for completeness. I&#8217;m using <a href="http://wordpress.org/extend/themes/twentytwelve" title="WordPress - Twenty Twelve - Free WordPress Themes" target="_blank">twentytwelve</a> theme in my demo but this should apply for most themes.</p>
<ol>
<li>Duplicate <em>single.php</em> into <em>single-&lt;post type&gt;.php</em></li>
<li>Replace
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> get_template_part<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'content'</span><span style="color: #339933;">,</span> get_post_format<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>with</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> get_template_part<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;post type&gt;'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
</li>
<li>Duplicate <em>content.php</em> into <em>content-&lt;post type&gt;.php</em> and modify however you like</li>
</ol>
<p>&nbsp;</p>
<h3>Conclusion</h3>
<p>And we&#8217;re done! Always remember to check the WordPress documentation for the various functions involved if you want to customize. Lots of useful information in there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2013/03/adding-custom-post-types-fields-and-taxonomies-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Load WordPress Multi-Site in a script</title>
		<link>http://www.flynsarmy.com/2013/02/how-to-load-wordpress-multi-site-in-a-script/</link>
		<comments>http://www.flynsarmy.com/2013/02/how-to-load-wordpress-multi-site-in-a-script/#comments</comments>
		<pubDate>Tue, 12 Feb 2013 05:18:05 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1323</guid>
		<description><![CDATA[This morning I was loading WPMU in a custom script and all <a href="http://codex.wordpress.org/Function_Reference/get_option" title="Function Reference/get option" target="_blank">get_option()</a> lookups were returning the details for the main blog despite being in a <a href="http://codex.wordpress.org/WPMU_Functions/switch_to_blog" title="WPMU Functions/switch to blog" target="_blank">switch_to_blog()</a> block. After a bit of debugging it turns out this was due to <em>get_option()</em> caching its values from the main blog and never expiring its cache when switching. There's a pretty easy action you can use to fix this:
<pre lang="php" escaped="true" line="1">function switch_to_blog_cache_clear( $blog_id, $prev_blog_id = 0 ) {
    if ( $blog_id === $prev_blog_id )
        return;

	wp_cache_delete( 'notoptions', 'options' );
	wp_cache_delete( 'alloptions', 'options' );
}
add_action( 'switch_blog', 'switch_to_blog_cache_clear', 10, 2 );</pre>
Below is a script in its entirety for loading WPMU, switching to blog 31 and grabbing its name:
<pre lang="php" escaped="true" line="1">&#60;?php

$_SERVER['HTTP_HOST'] = 'mypolicedev.com';

ini_set('display_errors', true);

/**
 * BEGIN LOAD WORDPRESS
 */
function find_wordpress_base_path() {
	$dir = dirname(__FILE__);
	do {
		//it is possible to check for other files here
		if( file_exists($dir."/wp-config.php") ) {
			return $dir;
		}
	} while( $dir = realpath("$dir/..") );
	return null;
}

define( 'BASE_PATH', find_wordpress_base_path()."/" );
global $wp, $wp_query, $wp_the_query, $wp_rewrite, $wp_did_header;
require(BASE_PATH . 'wp-load.php');

function switch_to_blog_cache_clear( $blog_id, $prev_blog_id = 0 ) {
	if ( $blog_id === $prev_blog_id )
		return;

	wp_cache_delete( 'notoptions', 'options' );
	wp_cache_delete( 'alloptions', 'options' );
}
add_action( 'switch_blog', 'switch_to_blog_cache_clear', 10, 2 );

/**
 * END LOAD WORDPRESS
 */

switch_to_blog( 31 );
var_dump(get_bloginfo('name'));
restore_current_blog();</pre>]]></description>
				<content:encoded><![CDATA[<p>A task I&#8217;ve been wrestling with lately is to load WPMU in a PHP script which will be accessed regularly via cron using CURL. Getting WPMU to load was simple enough</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'yourdomain.com'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'display_errors'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * BEGIN LOAD WORDPRESS
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> find_wordpress_base_path<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//it is possible to check for other files here</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/wp-config.php&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$dir</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dir</span>/..&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'BASE_PATH'</span><span style="color: #339933;">,</span> find_wordpress_base_path<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_the_query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_did_header</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span>BASE_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'wp-load.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * END LOAD WORDPRESS
 */</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>The above takes care of 90% of the work. All that&#8217;s left is an annoying bug whereby all <a href="http://codex.wordpress.org/Function_Reference/get_option" title="Function Reference/get option" target="_blank">get_option()</a> lookups were returning details for the main blog despite being in a <a href="http://codex.wordpress.org/WPMU_Functions/switch_to_blog" title="WPMU Functions/switch to blog" target="_blank">switch_to_blog()</a> block. After a bit of debugging it turns out this is due to <em>get_option()</em> caching its values from the main blog and never expiring its cache when switching. There&#8217;s a pretty nifty action you can use to fix this:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> switch_to_blog_cache_clear<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$blog_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prev_blog_id</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</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: #000088;">$blog_id</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$prev_blog_id</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
	wp_cache_delete<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'notoptions'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'options'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	wp_cache_delete<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alloptions'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'options'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'switch_blog'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'switch_to_blog_cache_clear'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>There you have it. Below is the script in its entirety for loading WPMU, switching to blog 31 and grabbing its name:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'yourdomain.com'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'display_errors'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * BEGIN LOAD WORDPRESS
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> find_wordpress_base_path<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//it is possible to check for other files here</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/wp-config.php&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$dir</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #990000;">realpath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$dir</span>/..&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'BASE_PATH'</span><span style="color: #339933;">,</span> find_wordpress_base_path<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;/&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_the_query</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_did_header</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span>BASE_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'wp-load.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> switch_to_blog_cache_clear<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$blog_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$prev_blog_id</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</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: #000088;">$blog_id</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$prev_blog_id</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
	wp_cache_delete<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'notoptions'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'options'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	wp_cache_delete<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'alloptions'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'options'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'switch_blog'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'switch_to_blog_cache_clear'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * END LOAD WORDPRESS
 */</span>
&nbsp;
switch_to_blog<span style="color: #009900;">&#40;</span> <span style="color: #cc66cc;">31</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span>get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
restore_current_blog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>For more information see:</p>
<ul>
<li><a href="http://wordpress.stackexchange.com/questions/76465/initialize-wordpress-environment-to-use-in-command-line-script" title="Initialize WordPress environment to use in command line script" target="_blank">Initialize WordPress environment to use in command line script</a></li>
<li><a href="http://scotty-t.com/2012/03/13/switch_to_blog-is-an-unfunny-nightmare/" title="“switch_to_blog( )” is an Unfunny Nightmare" target="_blank">“switch_to_blog( )” is an Unfunny Nightmare</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2013/02/how-to-load-wordpress-multi-site-in-a-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create and Manage a RAID Array in Ubuntu</title>
		<link>http://www.flynsarmy.com/2012/12/create-and-manage-a-raid-array-in-ubuntu/</link>
		<comments>http://www.flynsarmy.com/2012/12/create-and-manage-a-raid-array-in-ubuntu/#comments</comments>
		<pubDate>Sun, 30 Dec 2012 00:40:36 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[RAID]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1301</guid>
		<description><![CDATA[The below is a collaboration of useful information I've found while attempting to build and maintain a RAID5 array consisting of 4 HDDs. This tutorial is a work in progress and I'm learning everything as I go. I've left relevant links in each section for more information and if you spot anything that could be done better or that I'm missing let me know in the comments below!]]></description>
				<content:encoded><![CDATA[<p>The below is a collaboration of useful information I&#8217;ve found while attempting to build and maintain a RAID5 array consisting of 4 HDDs. This tutorial is a work in progress and I&#8217;m learning everything as I go. I&#8217;ve left relevant links in each section for more information and if you spot anything that could be done better or that I&#8217;m missing let me know in the comments below!</p>
<p>A few useful commands to get us started:</p>
<ul>
<li><strong>lsblk</strong> to see mount points</li>
<li><strong>df -T</strong> to see file systems and</li>
<li><strong>sudo fdisk -l</strong> to see partition types</li>
</ul>
<p>&nbsp;</p>
<h3>Format and partition drives</h3>
<p><a href="http://www.flynsarmy.com/2012/11/partitioning-and-formatting-new-disks-in-linux/" target="_blank">http://www.flynsarmy.com/2012/11/partitioning-and-formatting-new-disks-in-linux/</a><br />
<a href="http://www.ehow.com/how_5853059_format-linux-disk.html" target="_blank">http://www.ehow.com/how_5853059_format-linux-disk.html</a><br />
<a href="http://www.allmyit.com.au/mdadm-growing-raid5-array-ubuntu" target="_blank">http://www.allmyit.com.au/mdadm-growing-raid5-array-ubuntu</a></p>
<h4>Make sure all disks are umounted:</h4>
<p>First step is to format and partition our drives to prepare them for the array. I&#8217;m using four 2TB SATA drives.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">lsblk
<span style="color: #666666; font-style: italic;"># Mine are sdb sdc sdd and sde</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>sdb
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>sdc
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>sdd
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>media<span style="color: #000000; font-weight: bold;">/</span>sde</pre></td></tr></table></div>
<!-- end from cahe -->
<h4>Delete all partitions and create new Linux RAID autodetect partitions</h4>
<p>RAID disks require <em>RAID autodetect partitions</em>. These can be made with fdisk:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">fdisk</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb
d <span style="color: #666666; font-style: italic;">#until all deleted</span>
n <span style="color: #666666; font-style: italic;">#use defaults</span>
t <span style="color: #666666; font-style: italic;">#change partition type</span>
fd <span style="color: #666666; font-style: italic;">#Linux RAID autodetect type</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Repeat the above for each drive</p>
<h4>Partition to EXT4</h4>
<p>I&#8217;m using EXT4 for my array.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">	<span style="color: #c20cb9; font-weight: bold;">sudo</span> mkfs.ext4 sdb1
	<span style="color: #c20cb9; font-weight: bold;">sudo</span> mkfs.ext4 sdc1
	<span style="color: #c20cb9; font-weight: bold;">sudo</span> mkfs.ext4 sdd1
	<span style="color: #c20cb9; font-weight: bold;">sudo</span> mkfs.ext4 sde1</pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Create the Array</h3>
<p><a href="http://ubuntuforums.org/showthread.php?t=517282" target="_blank">http://ubuntuforums.org/showthread.php?t=517282</a><br />
<a href="http://blog.mbentley.net/2010/11/creating-a-raid-5-array-in-linux-with-mdadm/" target="_blank">http://blog.mbentley.net/2010/11/creating-a-raid-5-array-in-linux-with-mdadm/</a></p>
<p>As mentioned above I&#8217;m using four drives and making a RAID5 array.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> mdadm <span style="color: #660033;">--create</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md0 <span style="color: #660033;">--level</span>=<span style="color: #000000;">5</span> <span style="color: #660033;">--raid-devices</span>=<span style="color: #000000;">4</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdc1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdd1 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sde1
<span style="color: #c20cb9; font-weight: bold;">watch</span> <span style="color: #660033;">-n3</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>mdstat</pre></td></tr></table></div>
<!-- end from cahe -->
<p>This will take several hours depending on number and size of hdds. When done you should see</p>
<blockquote><p>Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]<br />
md0 : active raid5 sde1[4] sdd1[2] sdc1[1] sdb1[0]<br />
5860145664 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]</p></blockquote>
<p>Reboot and the array will have disappeared. Find the new location:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>mdstat</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Mine had for some reason been replaced with <em>/dev/md127</em>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">Personalities : <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid6<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid5<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid4<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>linear<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>multipath<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid0<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid1<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>raid10<span style="color: #7a0874; font-weight: bold;">&#93;</span>
md127 : active raid5 sde1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdc1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdd1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> sdb1<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
     <span style="color: #000000;">5860145664</span> blocks super <span style="color: #000000;">1.2</span> level <span style="color: #000000;">5</span>, 512k chunk, algorithm <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>UUUU<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Type</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> mdadm <span style="color: #660033;">--assemble</span> <span style="color: #660033;">--scan</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> mdadm <span style="color: #660033;">--detail</span> <span style="color: #660033;">--scan</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>and paste the output at the bottom of /etc/mdadm/mdadm.conf. Mine looked like</p>
<blockquote><p>ARRAY /dev/md/xbmc:0 metadata=1.2 name=xbmc:0 UUID=3dcfe843:c2300a40:75190922:f6caf9c7</p></blockquote>
<p>Add your array from <em>/proc/mdstat</em> (in my case <em>/dev/md127</em>) to fstab like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">/dev/md127        /media/md127    ext4             defaults 0       0</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Reboot.</p>
<p>&nbsp;</p>
<h3>Failed Arrays</h3>
<p>I wanted to test a repair so I pulled a drive and plugged it back in. Alternatively you could use</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">mdadm <span style="color: #660033;">-manage</span> <span style="color: #660033;">-set-faulty</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md127 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Doing a</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> mdadm <span style="color: #660033;">--query</span> <span style="color: #660033;">--detail</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md127</pre></td></tr></table></div>
<!-- end from cahe -->
<p>on the newly failed array showed:</p>
<blockquote><p>/dev/md127:<br />
Version : 1.2<br />
&#8230;<br />
State : clean, degraded<br />
Active Devices : 3<br />
Working Devices : 3<br />
Failed Devices : 0<br />
Spare Devices : 0</p>
<p>Layout : left-symmetric<br />
Chunk Size : 512K</p>
<p>Name : xbmc:0  (local to host xbmc)<br />
UUID : 3dcfe843:c2300a40:75190922:f6caf9c7<br />
Events : 610</p>
<p>Number   Major   Minor   RaidDevice State<br />
0       8       17        0      active sync   /dev/sdb1<br />
1       8       33        1      active sync   /dev/sdc1<br />
2       0        0        2      removed<br />
4       8       49        3      active sync   /dev/sdd1</p></blockquote>
<p>Notice the <em>State</em> is now set to &#8216;clean, degraded&#8217;.</p>
<h4>Email Notifications</h4>
<p>First and foremost you want to be notified by email about failed arrays. Open <em>/etc/mdadm/mdadm.conf</em> and set the <em>MAILADDR</em> line to your email address. When arrays fail you&#8217;ll now receive an email like the following:</p>
<blockquote><p>This is an automatically generated mail message from mdadm<br />
running on xbmc</p>
<p>A DegradedArray event had been detected on md device /dev/md/xbmc:0.</p>
<p>Faithfully yours, etc.</p>
<p>P.S. The /proc/mdstat file currently contains the following:</p>
<p>Personalities : [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid1] [raid10]<br />
md127 : active raid5 sdf1[5] sdd1[4] sdc1[1] sdb1[0]<br />
5860145664 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [UU_U]<br />
[===========&gt;.........]  recovery = 59.5% (1163564104/1953381888) finish=184.5min speed=71313K/sec</p>
<p>unused devices: &lt;none&gt;</p></blockquote>
<h4>Physically Locating the faulty disk</h4>
<p><a href="http://askubuntu.com/questions/11088/how-can-i-physically-identify-a-single-drive-in-a-raid-array" target="_blank">http://askubuntu.com/questions/11088/how-can-i-physically-identify-a-single-drive-in-a-raid-array</a></p>
<p><strong>Always have a diagram written up beforehand showing the location of each drive and their UUID/serial number!</strong> This is the best method.</p>
<p>If you haven&#8217;t done the above a nice way to determine which disk is faulty if you know the /dev/sdx association (using <em>cat /proc/mdstat</em> should do the trick, or  <em>lsscsi -l</em> might help) is by doing a</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdx <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null</pre></td></tr></table></div>
<!-- end from cahe -->
<p>and seeing which LED light blinks madly out front of your machine.</p>
<p>Here&#8217;s a script I whipped up to output /dev location, UUID and model numbers of each drive:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> disk <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">fdisk</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-Eo</span> <span style="color: #ff0000;">'(/dev/[sh]d[a-z]):'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">'s/://'</span><span style="color: #000000; font-weight: bold;">`</span>;
<span style="color: #000000; font-weight: bold;">do</span>
   <span style="color: #007800;">uuid</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> blkid <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1 <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-Eo</span> <span style="color: #ff0000;">'UUID=&quot;([^&quot;]+)&quot;'</span><span style="color: #000000; font-weight: bold;">`</span>
   <span style="color: #007800;">model</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> hdparm <span style="color: #660033;">-i</span> <span style="color: #007800;">$disk</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-Eo</span> <span style="color: #ff0000;">'SerialNo=.*'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">'s/SerialNo=//'</span>;<span style="color: #000000; font-weight: bold;">`</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$disk</span> <span style="color: #007800;">$uuid</span> model='<span style="color: #007800;">$model</span>'&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Output:</p>
<blockquote><p>/dev/sdc UUID=&#8221;3dcfe843-c230-0a40-7519-0922f6caf9c7&#8243; model=&#8217;W -DCWYA00667790&#8242;<br />
/dev/sdb UUID=&#8221;3dcfe843-c230-0a40-7519-0922f6caf9c7&#8243; model=&#8217;W -DCWYA00186517&#8242;<br />
/dev/sdd UUID=&#8221;3dcfe843-c230-0a40-7519-0922f6caf9c7&#8243; model=&#8217;W -DCWYA00677873&#8242;<br />
/dev/sde UUID=&#8221;3dcfe843-c230-0a40-7519-0922f6caf9c7&#8243; model=&#8217;W -DCWYA00879590&#8242;<br />
/dev/sdf UUID=&#8221;3dcfe843-c230-0a40-7519-0922f6caf9c7&#8243; model=&#8217;W -DCWYA00878581&#8242;</p></blockquote>
<h4>Repairing a failed Array</h4>
<p><a href="http://nst.sourceforge.net/nst/docs/user/ch14.html" target="_blank">http://nst.sourceforge.net/nst/docs/user/ch14.html</a><br />
<a href="http://ubuntuforums.org/showthread.php?t=1615374" target="_blank">http://ubuntuforums.org/showthread.php?t=1615374</a><br />
<a href="http://www.techrepublic.com/blog/networking/testing-your-software-raid-be-prepared/387" target="_blank">http://www.techrepublic.com/blog/networking/testing-your-software-raid-be-prepared/387</a></p>
<p>Do an</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">/</span>dev <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> sd</pre></td></tr></table></div>
<!-- end from cahe -->
<p>to find the newly plugged in drive (in my case <em>/dev/sdf</em>) and add the partition on the drive to your raid array (You may have to format/partition as described in the <em>Format and partition drives</em> section above):</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> mdadm <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>md127 <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdf1
<span style="color: #666666; font-style: italic;"># mdadm: added /dev/sdf1</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Monitor your progress with</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">watch</span> <span style="color: #660033;">-n3</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>mdstat</pre></td></tr></table></div>
<!-- end from cahe -->
<p>I made the mistake of reading from the drive before it&#8217;d started repairing. This apparently lowers the repair speed to the bare minimum &#8211; mine was going to take 22 days! To fix this become root and run</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">100000</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>raid<span style="color: #000000; font-weight: bold;">/</span>speed_limit_min
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000;">400000</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>sys<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>raid<span style="color: #000000; font-weight: bold;">/</span>speed_limit_max</pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>GUI Management</h3>
<p><a href="http://michal.karzynski.pl/blog/2009/11/18/mdadm-gui-via-webmin/" target="_blank">http://michal.karzynski.pl/blog/2009/11/18/mdadm-gui-via-webmin/</a></p>
<p>&nbsp;</p>
<p>While researching I came across <a href="http://www.webmin.com/" title="Webmin" target="_blank">webmin</a>. It&#8217;s free, easy to install and offers a fair bit of functionality right from the browser. I haven&#8217;t used it to do any actual modifications yet but it seems to have all the functionality you need and a bunch of other useful stuff such as a web console, apt updates and apache/proftpd administration. I highly recommend checking it out.</p>
<p><a href="http://www.flynsarmy.com/wp-content/uploads/2012/12/mdadm-gui-via-webmin-1.jpg"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/12/mdadm-gui-via-webmin-1-300x168.jpg" alt="WebMin Raid Management 1" width="300" height="168" class="aligncenter size-medium wp-image-1308" /></a></p>
<p><a href="http://www.flynsarmy.com/wp-content/uploads/2012/12/mdadm-gui-via-webmin-2.jpg"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/12/mdadm-gui-via-webmin-2-300x172.jpg" alt="WebMin Raid Management 1" width="300" height="172" class="aligncenter size-medium wp-image-1309" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>Other Useful Links</h3>
<p>udevinfo for Ubuntu<br />
<a href="http://ubuntuforums.org/showthread.php?t=1265469" target="_blank">http://ubuntuforums.org/showthread.php?t=1265469</a></p>
<p>Grow a raid array<br />
<a href="http://www.allmyit.com.au/mdadm-growing-raid5-array-ubuntu" target="_blank">http://www.allmyit.com.au/mdadm-growing-raid5-array-ubuntu</a></p>
<p>Changing /dev locations<br />
<a href="http://unix.stackexchange.com/questions/56267/ubuntu-software-raid5-dev-devices-changed-will-mdadm-raid-break" target="_blank">http://unix.stackexchange.com/questions/56267/ubuntu-software-raid5-dev-devices-changed-will-mdadm-raid-break<br />
</a></p>
<p>Re-adding drives &#8211; Write-Intent Bitmaps<br />
<a href="https://raid.wiki.kernel.org/index.php/Write-intent_bitmap" target="_blank">https://raid.wiki.kernel.org/index.php/Write-intent_bitmap</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/12/create-and-manage-a-raid-array-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get CodeIntel working in Sublime Text on OSX</title>
		<link>http://www.flynsarmy.com/2012/11/how-to-get-codeintel-working-in-sublime-text-on-osx/</link>
		<comments>http://www.flynsarmy.com/2012/11/how-to-get-codeintel-working-in-sublime-text-on-osx/#comments</comments>
		<pubDate>Sat, 24 Nov 2012 08:51:54 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1291</guid>
		<description><![CDATA[<a href="https://github.com/Kronuz/SublimeCodeIntel" title="Kronuz/SublimeCodeIntel · GitHub" target="_blank">SublimeCodeIntel</a> is perhaps the most useful and heavily installed package for <a href="http://www.sublimetext.com/" title="Sublime Text: The text editor you'll fall in love with" target="_blank">Sublime Text</a> but it's also very difficult to get working. The most common issue people run into is the dreaded endless
<blockquote>Info: processing `PHP': Please wait...</blockquote>
This can be fixed by navigating to the SublimeCodeIntel package directory and running <em>build.sh</em>. For <em>build.sh</em> to compile we first need to install two things: <em>pcre</em> and <em>XCode Command Line Tools</em>. Annoyingly this is around 1.6GB of files!

&#160;
<h4>Installing XCode Command Line Tools</h4>
Head <a href="https://developer.apple.com/xcode/" title="Xcode 4 Downloads and Resources - Apple Developer" target="_blank">over here</a> and click <em>View in Mac App Store</em>. Hit install and watch your progress in the <em>Purchases</em> tab.

Once installed open it up and go to <em>XCode - Preferences - Downloads - Components</em> and install <em>Command Line Tools</em>.

&#160;
<h4>Installing pcre</h4>
This little script is required by the <i>scintilla</i> package of SublimeCodeIntel. First install <a href="http://www.macports.org/install.php" title="The MacPorts Project -- Download &#38;amp; Installation" target="_blank">MacPorts</a> then run:
<pre lang="bash" escaped="true">sudo port install autoconf
sudo port install pcre
sudo cp /opt/local/include/pcre.h /usr/include/</pre>
You're done! Navigate to the SublimeCodeIntel <a href="http://stackoverflow.com/questions/7808452/what-is-the-full-path-to-the-packages-folder-for-sublime-text-2-on-mac-os-lion" title="osx - What is the full path to the Packages folder for Sublime text 2 on Mac OS Lion - Stack Overflow" target="_blank">package directory</a> and run <em>sh src/build.sh</em>. If all goes well at the end of compilation you'll see a done! message. Restart Sublime Text and you're good to go.]]></description>
				<content:encoded><![CDATA[<p><a href="https://github.com/Kronuz/SublimeCodeIntel" title="Kronuz/SublimeCodeIntel · GitHub" target="_blank">SublimeCodeIntel</a> is perhaps the most useful and heavily installed package for <a href="http://www.sublimetext.com/" title="Sublime Text: The text editor you'll fall in love with" target="_blank">Sublime Text</a> but it&#8217;s also very difficult to get working. The most common issue people run into is the dreaded endless</p>
<blockquote><p>Info: processing `PHP&#8217;: Please wait&#8230;</p></blockquote>
<p>This can be fixed by navigating to the SublimeCodeIntel package directory and running <em>build.sh</em>. For <em>build.sh</em> to compile we first need to install two things: <em>pcre</em> and <em>XCode Command Line Tools</em>. Annoyingly this is around 1.6GB of files!</p>
<p>&nbsp;</p>
<h4>Installing XCode Command Line Tools</h4>
<p>Head <a href="https://developer.apple.com/xcode/" title="Xcode 4 Downloads and Resources - Apple Developer" target="_blank">over here</a> and click <em>View in Mac App Store</em>. Hit install and watch your progress in the <em>Purchases</em> tab.</p>
<p>Once installed open it up and go to <em>XCode &#8211; Preferences &#8211; Downloads &#8211; Components</em> and install <em>Command Line Tools</em>.</p>
<p>&nbsp;</p>
<h4>Installing pcre</h4>
<p>This little script is required by the <i>scintilla</i> package of SublimeCodeIntel. First install <a href="http://www.macports.org/install.php" title="The MacPorts Project -- Download &amp;amp; Installation" target="_blank">MacPorts</a> then run:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">autoconf</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> pcre
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span>pcre.h <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>include<span style="color: #000000; font-weight: bold;">/</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>You&#8217;re done! Navigate to the SublimeCodeIntel <a href="http://stackoverflow.com/questions/7808452/what-is-the-full-path-to-the-packages-folder-for-sublime-text-2-on-mac-os-lion" title="osx - What is the full path to the Packages folder for Sublime text 2 on Mac OS Lion - Stack Overflow" target="_blank">package directory</a> and run <em>sh src/build.sh</em>. If all goes well at the end of compilation you&#8217;ll see a done! message. Restart Sublime Text and you&#8217;re good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/11/how-to-get-codeintel-working-in-sublime-text-on-osx/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Installing RocketRaid 2760a drivers on Ubuntu 12.10</title>
		<link>http://www.flynsarmy.com/2012/11/installing-rocketraid-2760a-drivers-on-ubuntu-12-10/</link>
		<comments>http://www.flynsarmy.com/2012/11/installing-rocketraid-2760a-drivers-on-ubuntu-12-10/#comments</comments>
		<pubDate>Thu, 08 Nov 2012 11:50:41 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[RAID]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1274</guid>
		<description><![CDATA[So I don't forget, here's a tutorial on installing the RocketRaid 2760a drivers and management utilities on Ubuntu 12.10. I'm using 64-bit but 32-bit should be the same - just substitute where appropriate.
<h4>Installing the Driver</h4>
The installation disc comes with an out of date version of the driver and kernel module. The way the installation works, we need to download and compile the kernel module then download the driver installer, drop the module into place and run the installer. Make sure you have appropriate compiler tools installed - to be safe just run
<pre lang="bash" escaped="true">sudo apt-get install ubuntu-dev-tools</pre>
Download and extract the ones with kernel 3.x support from the <a href="http://www.highpoint-tech.com/USA_new/CS-PCI-E_2_0_x16_Configuration.html" title="HighPoint Global website" target="_blank">HighPoint website</a>:
<pre lang="bash" escaped="true">mkdir ~/driver
cd ~/driver
# driver
wget http://www.highpoint-tech.com/BIOS_Driver/RR276x/linux/Ubuntu/rr276x-ubuntu-11.10-x86_64-v1.1.12.0502.tgz
tar -xvzf rr276x-ubuntu-11.10-x86_64-v1.1.12.0502.tgz
# kernel module
mkdir module
cd module
wget http://www.highpoint-tech.com/BIOS_Driver/RR276x/linux/RR276x-Linux-Src-v1.1-120424-1734.tar.gz
tar -xvzf  RR276x-Linux-Src-v1.1-120424-1734.tar.gz</pre>
Build and compress the kernel module for our driver installer:
<pre lang="bash" escaped="true">cd rr276x-linux-src-v1.1/product/rr276x/linux/
make
# Ignore the warning about not being able to find him_rr2760x.o...doesn't seem to matter
gzip rr276x.ko
mv rr276x.ko.gz ~/driver/boot/rr276x$(uname -r)$(uname -m).ko.gz</pre>
And finally install the driver
<pre lang="bash" escaped="true">cd ~/driver
sudo bash preinst.sh</pre>
<blockquote>This step succeeded! Now you can press ALT+F1 to switch back to the installation screen!</blockquote>
<pre lang="bash" escaped="true">sudo bash install.sh</pre>
<blockquote>Update initrd file /boot/initrd.img-3.5.0-17-generic for 3.5.0-17-generic
Please reboot the system to use the new driver module.</blockquote>
<pre lang="bash" escaped="true">sudo shutdown -r now</pre>
That should be everything! You can now test with
<pre lang="bash" escaped="true">cat /proc/scsi/rr276x/*</pre>
&#160;
<h4>Installing the RAID Management Software</h4>
Annoyingly the RAID management console is difficult to install to say the least. The GUI deb packages error when trying to install and HighPoint don't even provide a deb for the command line version and to top it off the version of the command line utility on the driver CD is newer than the version on their site! For this reason I've provided the newer command line RPMs <a href="http://www.flynsarmy.com/wp-content/uploads/2012/11/LinuxRaidUtilityConsole.tar.gz" target="_blank">here</a>.

Let's get this thing installed.

<strong>Web version:</strong>
<pre lang="bash" escaped="true">mkdir ~/driver/utility
mkdir ~/driver/utility/console
mkdir ~/driver/utility/web
cd ~/driver/utility/web
echo "rr276x" &#124; sudo tee -a /etc/hptcfg &#62; /dev/null
wget http://www.highpoint-tech.com/BIOS_Driver/GUI/linux/WebGui/WebGUI-Linux-v2.1-120419.tgz
tar -xzvf WebGUI-Linux-v2.1-120419.tgz
sudo apt-get -y install alien
sudo alien -d hptsvr-https-2.1-12.0419.$(uname -m).rpm
sudo dpkg -i hptsvr-https_2.1-13.0419_amd64.deb</pre>
&#160;

<strong>Command Line version:</strong>
<pre lang="bash" escaped="true">cd ~/driver/utility/console
wget http://www.flynsarmy.com/wp-content/uploads/2012/11/LinuxRaidUtilityConsole.tar.gz
sudo alien -d hptraidconf-3.5-1.$(uname -m).rpm
sudo alien -d hptsvr-3.13-7.$(uname -m).rpm
sudo dpkg -i hptraidconf_3.5-2_amd64.deb</pre>
Run the web server:
<pre lang="bash" escaped="true">sudo hptsvr</pre>
You should now be able to connect to it from your browser by navigating to http://localhost:7402 with username RAID and password hpt.

&#160;
<h4>Further Reading</h4>
<a href="http://ubuntuforums.org/showthread.php?p=10712667" title="[SOLVED] HOWTO: Get GUI hptsvr &#38;amp; hptraid 3.13 working on Ubuntu - Ubuntu Forums" target="_blank">HOWTO: Get GUI hptsvr &#38; hptraid 3.13 working on Ubuntu
</a><a href="http://www.highpoint-tech.com/USA_new/CS-PCI-E_2_0_x16_Configuration.html" title="HighPoint Global website" target="_blank">HighPoint driver download page for RocketRaid 2760a</a>]]></description>
				<content:encoded><![CDATA[<p>So I don&#8217;t forget, here&#8217;s a tutorial on installing the RocketRaid 2760a drivers and management utilities on Ubuntu 12.10. I&#8217;m using 64-bit but 32-bit should be the same &#8211; just substitute where appropriate.</p>
<h4>Installing the Driver</h4>
<p>The installation disc comes with an out of date version of the driver and kernel module. The way the installation works, we need to download and compile the kernel module then download the driver installer, drop the module into place and run the installer. Make sure you have appropriate compiler tools installed &#8211; to be safe just run</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> ubuntu-dev-tools</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Download and extract the ones with kernel 3.x support from the <a href="http://www.highpoint-tech.com/USA_new/CS-PCI-E_2_0_x16_Configuration.html" title="HighPoint Global website" target="_blank">HighPoint website</a>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>driver
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>driver
<span style="color: #666666; font-style: italic;"># driver</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.highpoint-tech.com<span style="color: #000000; font-weight: bold;">/</span>BIOS_Driver<span style="color: #000000; font-weight: bold;">/</span>RR276x<span style="color: #000000; font-weight: bold;">/</span>linux<span style="color: #000000; font-weight: bold;">/</span>Ubuntu<span style="color: #000000; font-weight: bold;">/</span>rr276x-ubuntu-<span style="color: #000000;">11.10</span>-x86_64-v1.1.12.0502.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> -xvzf rr276x-ubuntu-<span style="color: #000000;">11.10</span>-x86_64-v1.1.12.0502.tgz
<span style="color: #666666; font-style: italic;"># kernel module</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> module
<span style="color: #7a0874; font-weight: bold;">cd</span> module
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.highpoint-tech.com<span style="color: #000000; font-weight: bold;">/</span>BIOS_Driver<span style="color: #000000; font-weight: bold;">/</span>RR276x<span style="color: #000000; font-weight: bold;">/</span>linux<span style="color: #000000; font-weight: bold;">/</span>RR276x-Linux-Src-v1.1-<span style="color: #000000;">120424</span>-<span style="color: #000000;">1734</span>.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span>  RR276x-Linux-Src-v1.1-<span style="color: #000000;">120424</span>-<span style="color: #000000;">1734</span>.tar.gz</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Build and compress the kernel module for our driver installer:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> rr276x-linux-src-v1.1<span style="color: #000000; font-weight: bold;">/</span>product<span style="color: #000000; font-weight: bold;">/</span>rr276x<span style="color: #000000; font-weight: bold;">/</span>linux<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #666666; font-style: italic;"># Ignore the warning about not being able to find him_rr2760x.o...doesn't seem to matter</span>
<span style="color: #c20cb9; font-weight: bold;">gzip</span> rr276x.ko
<span style="color: #c20cb9; font-weight: bold;">mv</span> rr276x.ko.gz ~<span style="color: #000000; font-weight: bold;">/</span>driver<span style="color: #000000; font-weight: bold;">/</span>boot<span style="color: #000000; font-weight: bold;">/</span>rr276x$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">uname</span> -m<span style="color: #7a0874; font-weight: bold;">&#41;</span>.ko.gz</pre></td></tr></table></div>
<!-- end from cahe -->
<p>And finally install the driver</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>driver
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">bash</span> preinst.sh</pre></td></tr></table></div>
<!-- end from cahe -->
<blockquote><p>This step succeeded! Now you can press ALT+F1 to switch back to the installation screen!</p></blockquote>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">bash</span> install.sh</pre></td></tr></table></div>
<!-- end from cahe -->
<blockquote><p>Update initrd file /boot/initrd.img-3.5.0-17-generic for 3.5.0-17-generic<br />
Please reboot the system to use the new driver module.</p></blockquote>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> shutdown <span style="color: #660033;">-r</span> now</pre></td></tr></table></div>
<!-- end from cahe -->
<p>That should be everything! You can now test with</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>scsi<span style="color: #000000; font-weight: bold;">/</span>rr276x<span style="color: #000000; font-weight: bold;">/*</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h4>Installing the RAID Management Software</h4>
<p>Annoyingly the RAID management console is difficult to install to say the least. The GUI deb packages error when trying to install and HighPoint don&#8217;t even provide a deb for the command line version and to top it off the version of the command line utility on the driver CD is newer than the version on their site! For this reason I&#8217;ve provided the newer command line RPMs <a href="http://www.flynsarmy.com/wp-content/uploads/2012/11/LinuxRaidUtilityConsole.tar.gz" target="_blank">here</a>.</p>
<p>Let&#8217;s get this thing installed.</p>
<p><strong>Web version:</strong></p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>driver<span style="color: #000000; font-weight: bold;">/</span>utility
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>driver<span style="color: #000000; font-weight: bold;">/</span>utility<span style="color: #000000; font-weight: bold;">/</span>console
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>driver<span style="color: #000000; font-weight: bold;">/</span>utility<span style="color: #000000; font-weight: bold;">/</span>web
<span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>driver<span style="color: #000000; font-weight: bold;">/</span>utility<span style="color: #000000; font-weight: bold;">/</span>web
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;rr276x&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>hptcfg <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.highpoint-tech.com<span style="color: #000000; font-weight: bold;">/</span>BIOS_Driver<span style="color: #000000; font-weight: bold;">/</span>GUI<span style="color: #000000; font-weight: bold;">/</span>linux<span style="color: #000000; font-weight: bold;">/</span>WebGui<span style="color: #000000; font-weight: bold;">/</span>WebGUI-Linux-v2.1-<span style="color: #000000;">120419</span>.tgz
<span style="color: #c20cb9; font-weight: bold;">tar</span> -xzvf WebGUI-Linux-v2.1-<span style="color: #000000;">120419</span>.tgz
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #660033;">-y</span> <span style="color: #c20cb9; font-weight: bold;">install</span> alien
<span style="color: #c20cb9; font-weight: bold;">sudo</span> alien <span style="color: #660033;">-d</span> hptsvr-https-<span style="color: #000000;">2.1</span>-<span style="color: #000000;">12.0419</span>.$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">uname</span> -m<span style="color: #7a0874; font-weight: bold;">&#41;</span>.rpm
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> hptsvr-https_2.1-<span style="color: #000000;">13.0419</span>_amd64.deb</pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<p><strong>Command Line version:</strong></p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>driver<span style="color: #000000; font-weight: bold;">/</span>utility<span style="color: #000000; font-weight: bold;">/</span>console
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.flynsarmy.com<span style="color: #000000; font-weight: bold;">/</span>wp-content<span style="color: #000000; font-weight: bold;">/</span>uploads<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2012</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">11</span><span style="color: #000000; font-weight: bold;">/</span>LinuxRaidUtilityConsole.tar.gz
<span style="color: #c20cb9; font-weight: bold;">sudo</span> alien <span style="color: #660033;">-d</span> hptraidconf-<span style="color: #000000;">3.5</span>-<span style="color: #000000;">1</span>.$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">uname</span> -m<span style="color: #7a0874; font-weight: bold;">&#41;</span>.rpm
<span style="color: #c20cb9; font-weight: bold;">sudo</span> alien <span style="color: #660033;">-d</span> hptsvr-<span style="color: #000000;">3.13</span>-<span style="color: #000000;">7</span>.$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">uname</span> -m<span style="color: #7a0874; font-weight: bold;">&#41;</span>.rpm
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> hptraidconf_3.5-<span style="color: #000000;">2</span>_amd64.deb</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Run the web server:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> hptsvr</pre></td></tr></table></div>
<!-- end from cahe -->
<p>You should now be able to connect to it from your browser by navigating to http://localhost:7402 with username RAID and password hpt.</p>
<p>&nbsp;</p>
<h4>Further Reading</h4>
<p><a href="http://ubuntuforums.org/showthread.php?p=10712667" title="[SOLVED] HOWTO: Get GUI hptsvr &amp;amp; hptraid 3.13 working on Ubuntu - Ubuntu Forums" target="_blank">HOWTO: Get GUI hptsvr &amp; hptraid 3.13 working on Ubuntu<br />
</a><a href="http://www.highpoint-tech.com/USA_new/CS-PCI-E_2_0_x16_Configuration.html" title="HighPoint Global website" target="_blank">HighPoint driver download page for RocketRaid 2760a</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/11/installing-rocketraid-2760a-drivers-on-ubuntu-12-10/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Partitioning and Formatting New Disks in Linux</title>
		<link>http://www.flynsarmy.com/2012/11/partitioning-and-formatting-new-disks-in-linux/</link>
		<comments>http://www.flynsarmy.com/2012/11/partitioning-and-formatting-new-disks-in-linux/#comments</comments>
		<pubDate>Sun, 04 Nov 2012 11:30:15 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1266</guid>
		<description><![CDATA[The below is a quick guide to creating partitions on a newly purchased, unformatted disk. For this guide I'll be formatting a new WD 2TB Black.

&#160;
<h4>Find the disk you want to partition</h4>
<pre lang="bash" escaped="true"># lsblk</pre>
<blockquote>NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 55.9G 0 disk
├─sda1 8:1 0 53.6G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 2.3G 0 part [SWAP]
sdb 8:16 0 1.8T 0 disk
sdc 8:32 0 1.8T 0 disk</blockquote>
Partitions appear as subitems. Notice sdb and sdc have no partitions - those are the disks I want to format.

&#160;
<h4>Create the partition</h4>
<pre lang="bash" escaped="true"># sudo fdisk /dev/sdb</pre>
<blockquote>Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd3e43840.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help):</blockquote>
Below I'm using the default values to create one large partition for the whole disk.
<pre lang="bash" escaped="true">n</pre>
<blockquote>Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended

Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-3907029167, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-3907029167, default 3907029167):
Using default value 3907029167

Command (m for help):</blockquote>
All done? Write!
<pre lang="bash" escaped="true">w</pre>
<blockquote>The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.</blockquote>
That's all for partitioning! Take a gander at your fancy new partitions:
<pre lang="bash" escaped="true"># lsblk</pre>
<blockquote>NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 55.9G 0 disk
├─sda1 8:1 0 53.6G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 2.3G 0 part [SWAP]
sdb 8:16 0 1.8T 0 disk
└─sdb1 8:17 0 1.8T 0 part
sdc 8:32 0 1.8T 0 disk
└─sdc1 8:33 0 1.8T 0 part</blockquote>
&#160;
<h4>Format to NTFS</h4>
I'm choosing a quick format. You may choose instead to remove the -f argument for a proper one instead.
<pre lang="bash" escaped="true"># sudo mkntfs -f /dev/sdb1</pre>
<blockquote>Cluster size has been automatically set to 4096 bytes.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.</blockquote>
&#160;
<h4>Optional: Name the drives</h4>
Because I'm running NTFS I can give the drives labels. Make sure you have <em>ntfsprogs</em> installed then enter:
<pre lang="bash" escaped="true"># sudo ntfslabel -f /dev/sdb1 YourLabel</pre>
&#160;
<h4>More Information</h4>
For more information on partitioning check out Chris Wakefield's post <a href="http://comtech247.net/2012/07/04/how-to-format-a-hard-drive-on-ubuntu-12-04-using-fdisk/" title="How to format a hard drive on Ubuntu 12.04 using Fdisk" target="_blank">here</a>.
For a short and sweet howto on  formatting as NTFS check <a href="http://www.ehow.com/how_7235886_format-ntfs-partition-linux.html" title="How to Format an NTFS Partition in Linux" target="_blank">here</a>.
Information on NTFS labels <a href="http://tuxecute.blogspot.com.au/2008/09/change-your-ntfs-windows-drive-label.html" title="Change your NTFS / windows drive label via linux" target="_blank">here</a>.]]></description>
				<content:encoded><![CDATA[<p>The below is a quick guide to creating partitions on a newly purchased, unformatted disk. For this guide I&#8217;ll be formatting a new WD 2TB Black.</p>
<p>&nbsp;</p>
<h4>Find the disk you want to partition</h4>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;"># </span>lsblk</pre></td></tr></table></div>
<!-- end from cahe -->
<blockquote><p>NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT<br />
sda 8:0 0 55.9G 0 disk<br />
├─sda1 8:1 0 53.6G 0 part /<br />
├─sda2 8:2 0 1K 0 part<br />
└─sda5 8:5 0 2.3G 0 part [SWAP]<br />
sdb 8:16 0 1.8T 0 disk<br />
sdc 8:32 0 1.8T 0 disk</p></blockquote>
<p>Partitions appear as subitems. Notice sdb and sdc have no partitions &#8211; those are the disks I want to format.</p>
<p>&nbsp;</p>
<h4>Create the partition</h4>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">#</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">fdisk</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb</pre></td></tr></table></div>
<!-- end from cahe -->
<blockquote><p>Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel<br />
Building a new DOS disklabel with disk identifier 0xd3e43840.<br />
Changes will remain in memory only, until you decide to write them.<br />
After that, of course, the previous content won&#8217;t be recoverable.</p>
<p>Warning: invalid flag 0&#215;0000 of partition table 4 will be corrected by w(rite)</p>
<p>Command (m for help):</p></blockquote>
<p>Below I&#8217;m using the default values to create one large partition for the whole disk.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">n</pre></td></tr></table></div>
<!-- end from cahe -->
<blockquote><p>Partition type:<br />
p primary (0 primary, 0 extended, 4 free)<br />
e extended</p>
<p>Select (default p):<br />
Using default response p<br />
Partition number (1-4, default 1):<br />
Using default value 1<br />
First sector (2048-3907029167, default 2048):<br />
Using default value 2048<br />
Last sector, +sectors or +size{K,M,G} (2048-3907029167, default 3907029167):<br />
Using default value 3907029167</p>
<p>Command (m for help):</p></blockquote>
<p>All done? Write!</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">w</span></pre></td></tr></table></div>
<!-- end from cahe -->
<blockquote><p>The partition table has been altered!</p>
<p>Calling ioctl() to re-read partition table.<br />
Syncing disks.</p></blockquote>
<p>That&#8217;s all for partitioning! Take a gander at your fancy new partitions:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;"># </span>lsblk</pre></td></tr></table></div>
<!-- end from cahe -->
<blockquote><p>NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT<br />
sda 8:0 0 55.9G 0 disk<br />
├─sda1 8:1 0 53.6G 0 part /<br />
├─sda2 8:2 0 1K 0 part<br />
└─sda5 8:5 0 2.3G 0 part [SWAP]<br />
sdb 8:16 0 1.8T 0 disk<br />
└─sdb1 8:17 0 1.8T 0 part<br />
sdc 8:32 0 1.8T 0 disk<br />
└─sdc1 8:33 0 1.8T 0 part</p></blockquote>
<p>&nbsp;</p>
<h4>Format to NTFS</h4>
<p>I&#8217;m choosing a quick format. You may choose instead to remove the -f argument for a proper one instead.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;"># </span><span style="color: #c20cb9; font-weight: bold;">sudo</span> mkntfs <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1</pre></td></tr></table></div>
<!-- end from cahe -->
<blockquote><p>Cluster size has been automatically set to 4096 bytes.<br />
Creating NTFS volume structures.<br />
mkntfs completed successfully. Have a nice day.</p></blockquote>
<p>&nbsp;</p>
<h4>Optional: Name the drives</h4>
<p>Because I&#8217;m running NTFS I can give the drives labels. Make sure you have <em>ntfsprogs</em> installed then enter:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;"># </span><span style="color: #c20cb9; font-weight: bold;">sudo</span> ntfslabel <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdb1 YourLabel</pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h4>More Information</h4>
<p>For more information on partitioning check out Chris Wakefield&#8217;s post <a href="http://comtech247.net/2012/07/04/how-to-format-a-hard-drive-on-ubuntu-12-04-using-fdisk/" title="How to format a hard drive on Ubuntu 12.04 using Fdisk" target="_blank">here</a>.<br />
For a short and sweet howto on  formatting as NTFS check <a href="http://www.ehow.com/how_7235886_format-ntfs-partition-linux.html" title="How to Format an NTFS Partition in Linux" target="_blank">here</a>.<br />
Information on NTFS labels <a href="http://tuxecute.blogspot.com.au/2008/09/change-your-ntfs-windows-drive-label.html" title="Change your NTFS / windows drive label via linux" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/11/partitioning-and-formatting-new-disks-in-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Remove Ctrl+L Key Binding from  Pidgin</title>
		<link>http://www.flynsarmy.com/2012/10/how-to-remove-ctrll-key-binding-from-pidgin/</link>
		<comments>http://www.flynsarmy.com/2012/10/how-to-remove-ctrll-key-binding-from-pidgin/#comments</comments>
		<pubDate>Fri, 26 Oct 2012 23:56:17 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1259</guid>
		<description><![CDATA[[caption id="attachment_1263" align="aligncenter" width="300"]<a href="http://www.flynsarmy.com/wp-content/uploads/2012/10/pidgin-clear-scrollback-before-after-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/10/pidgin-clear-scrollback-before-after-web-300x195.png" alt="Removed 'Clear Scrollback' shortcut" title="Removed 'Clear Scrollback' shortcut" width="300" height="195" class="size-medium wp-image-1263" /></a> Removed 'Clear Scrollback' shortcut[/caption]

This would have to be far and away the most annoying 'feature' of Pidgin.

In just about every web browser, Ctrl+L is used to highlight the URL bar allowing easy navigation via the keyboard. In pidgin it's used to clear the scrollback of the active window. As a web developer I'm always hitting Ctrl+L in the browser however every now and then I won't take notice to which window is active on my desktop at the time and use it while Pidgin is active, clearing out the conversation I'm having with my contact at the time. Frustrating!

There was a bug post <a href="https://developer.pidgin.im/ticket/12510" title="#12510 (CTRL + L = Worst Keyboard Shortcut in Pidgin) – Pidgin" target="_blank">here</a> about it but as usual the devs don't particularly care and instead just pointed to their <a href="https://developer.pidgin.im/wiki/Using%20Pidgin#HowdoIbindkeystrokestomenuitems" title="How do I bind keystrokes to menu items?" target="_blank">FAQ</a> page. For convenience here's how you remove the shortcut:

Open <em>~/.purple/accels</em> and change
<pre lang="bash" escaped="true">; (gtk_accel_path "&#60;PurpleMain&#62;/Tools/Preferences" "&#60;Primary&#62;p")</pre>
to
<pre lang="bash" escaped="true">(gtk_accel_path "&#60;main&#62;/Conversation/Clear Scrollback" "")</pre>
Remember to remove the semicolon at the start of the line!

&#160;]]></description>
				<content:encoded><![CDATA[<div id="attachment_1263" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/10/pidgin-clear-scrollback-before-after-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/10/pidgin-clear-scrollback-before-after-web-300x195.png" alt="Removed 'Clear Scrollback' shortcut" title="Removed 'Clear Scrollback' shortcut" width="300" height="195" class="size-medium wp-image-1263" /></a><p class="wp-caption-text">Removed &#8216;Clear Scrollback&#8217; shortcut</p></div>
<p>This would have to be far and away the most annoying &#8216;feature&#8217; of Pidgin.</p>
<p>In just about every web browser, Ctrl+L is used to highlight the URL bar allowing easy navigation via the keyboard. In pidgin it&#8217;s used to clear the scrollback of the active window. As a web developer I&#8217;m always hitting Ctrl+L in the browser however every now and then I won&#8217;t take notice to which window is active on my desktop at the time and use it while Pidgin is active, clearing out the conversation I&#8217;m having with my contact at the time. Frustrating!</p>
<p>There was a bug post <a href="https://developer.pidgin.im/ticket/12510" title="#12510 (CTRL + L = Worst Keyboard Shortcut in Pidgin) – Pidgin" target="_blank">here</a> about it but as usual the devs don&#8217;t particularly care and instead just pointed to their <a href="https://developer.pidgin.im/wiki/Using%20Pidgin#HowdoIbindkeystrokestomenuitems" title="How do I bind keystrokes to menu items?" target="_blank">FAQ</a> page. For convenience here&#8217;s how you remove the shortcut:</p>
<p>Open <em>~/.purple/accels</em> and change</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">; <span style="color: #7a0874; font-weight: bold;">&#40;</span>gtk_accel_path <span style="color: #ff0000;">&quot;&lt;PurpleMain&gt;/Tools/Preferences&quot;</span> <span style="color: #ff0000;">&quot;&lt;Primary&gt;p&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>to</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#40;</span>gtk_accel_path <span style="color: #ff0000;">&quot;&lt;main&gt;/Conversation/Clear Scrollback&quot;</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Remember to remove the semicolon at the start of the line!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/10/how-to-remove-ctrll-key-binding-from-pidgin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating your Banner Slideshows Module</title>
		<link>http://www.flynsarmy.com/2012/09/updating-your-banner-slideshows-module/</link>
		<comments>http://www.flynsarmy.com/2012/09/updating-your-banner-slideshows-module/#comments</comments>
		<pubDate>Mon, 03 Sep 2012 11:13:36 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Lemonstand]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1218</guid>
		<description><![CDATA[One week from this post I will be publishing an update for my <a href="http://lemonstand.com/marketplace/module/flynsarmyslideshow/" title="LemonStand - Banner Slideshows" target="_blank">Banner Slideshows</a> module for LemonStand which upgrades it to use the newly released <a href="http://nivo.dev7studios.com/" title="Nivo Slider - The World's Most Popular jQuery &#38; WordPress Image Slider" target="_blank">Nivoslider 3</a>. This will provide a few nice benefits however the implementation isn't completely backwards compatible so your frontend code may need updating. Details inside.

<h3>What do I need to do?</h3>
Simply press the <em>Update slideshow</em> button on your slideshow page in the Administration:

[caption id="attachment_1219" align="aligncenter" width="300"]<a href="http://www.flynsarmy.com/wp-content/uploads/2012/09/update-slideshow-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/09/update-slideshow-web-300x206.png" alt="Hit the update button indicated above" title="Update slideshow" width="300" height="206" class="size-medium wp-image-1219" /></a> Hit the update button indicated above[/caption]

Then remove your existing slideshow code on your sites frontend and follow the instructions on the <a href="http://lemonstand.com/marketplace/module/flynsarmyslideshow/" title="LemonStand - Banner Slideshows" target="_blank">marketplace page</a> (to be updated when the module update is released) to add the new version.

<h3>How does this benefit me?</h3>
The biggest benefit is its new responsive design which resizes with your browser - making it easier to build sites that scale from a desktop monitor all the way down to a mobile phone. I've whipped up a <a href="http://www.flynsarmy.com/wp-content/uploads/2012/09/nivoslider/index.html" title="Nivo Slider Responsive Demo" target="_blank">live demo</a> to see this feature in action. Open it up and resize your browser window. Notice the slideshow resizes with the window.

Also new in this version of the module is full HTML support for slide descriptions:

[caption id="attachment_1231" align="aligncenter" width="300"]<a href="http://www.flynsarmy.com/wp-content/uploads/2012/09/slide-htmlsupport.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/09/slide-htmlsupport-300x238.png" alt="HTML support for slide descriptions" title="HTML support for slide descriptions" width="300" height="238" class="size-medium wp-image-1231" /></a> HTML support for slide descriptions[/caption]]]></description>
				<content:encoded><![CDATA[<p>One week from this post I will be publishing an update for my <a href="http://lemonstand.com/marketplace/module/flynsarmyslideshow/" title="LemonStand - Banner Slideshows" target="_blank">Banner Slideshows</a> module for LemonStand which upgrades it to use the newly released <a href="http://nivo.dev7studios.com/" title="Nivo Slider - The World's Most Popular jQuery &amp; WordPress Image Slider" target="_blank">Nivoslider 3</a>. This will provide a few nice benefits however the implementation isn&#8217;t completely backwards compatible so your frontend code may need updating. Details below.</p>
<p>&nbsp;</p>
<h3>What do I need to do?</h3>
<p>Existing slideshows need to be &#8216;updated&#8217;. Doing so is quick and easy. Simply press the <em>Update slideshow</em> button on your slideshow page in the Administration:</p>
<div id="attachment_1219" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/09/update-slideshow-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/09/update-slideshow-web-300x206.png" alt="Hit the update button indicated above" title="Update slideshow" width="300" height="206" class="size-medium wp-image-1219" /></a><p class="wp-caption-text">Hit the update button indicated above</p></div>
<p>Then remove your existing slideshow code on your sites frontend and follow the instructions on the <a href="http://lemonstand.com/marketplace/module/flynsarmyslideshow/" title="LemonStand - Banner Slideshows" target="_blank">marketplace page</a> (to be updated when the module update is released) to add the new version. Here&#8217;s a rundown:</p>
<p>Assets for the new nivoslider to be placed in page header:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> root_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modules/flynsarmyslideshow/resources/nivo-slider3.1/themes/default/default.css'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> root_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modules/flynsarmyslideshow/resources/nivo-slider3.1/nivo-slider.css'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;script type='text/javascript' src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> root_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modules/flynsarmyslideshow/resources/nivo-slider3.1/jquery.nivo.slider.js'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>
<!-- end from cahe -->
<p>And to render your slideshow:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">FlynsarmySlideshow_Slideshow<span style="color: #339933;">::</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">find_by_name</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Your slideshow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>I&#8217;ve also added a side pane giving all the information you need:</p>
<div id="attachment_1235" class="wp-caption aligncenter" style="width: 270px"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/09/sidebar-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/09/sidebar-web-260x300.png" alt="" title="New sidebar" width="260" height="300" class="size-medium wp-image-1235" /></a><p class="wp-caption-text">New sidebar shows the code needed to add your slideshow</p></div>
<h3></h3>
<h3>How does this benefit me?</h3>
<p>The <a href="http://nivo.dev7studios.com/2012/05/30/the-nivo-slider-is-responsive/" title="The Nivo Slider is Responsive! | Nivo Slider" target="_blank">official blog post</a> sums up the benefits of the new version of Nivo Slider best.</p>
<p>The biggest benefit is its new responsive design which resizes with your browser &#8211; making it easier to build sites that scale from a desktop monitor all the way down to a mobile phone. I&#8217;ve whipped up a <a href="http://www.flynsarmy.com/wp-content/uploads/2012/09/nivoslider/index.html" title="Nivo Slider Responsive Demo" target="_blank">live demo</a> to see this feature in action. Open it up and resize your browser window. Notice the slideshow resizes with the window.</p>
<p><iframe width="100%" height="300" src="http://www.flynsarmy.com/wp-content/uploads/2012/09/nivoslider/index.html"></iframe></p>
<p>Also new in this version of the module is full HTML support for slide descriptions:</p>
<div id="attachment_1231" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/09/slide-htmlsupport.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/09/slide-htmlsupport-300x238.png" alt="HTML support for slide descriptions" title="HTML support for slide descriptions" width="300" height="238" class="size-medium wp-image-1231" /></a><p class="wp-caption-text">HTML support for slide descriptions</p></div>
<p>&nbsp;</p>
<h3>Needing to update is annoying. Will this be a common thing?</h3>
<p>I certainly hope not.</p>
<p>With the release of version 3 of Nivo Slider, its new responsive layout was something that would clearly benefit users of my module &#8211; however with it came the removal of a few settings and a new HTML markup for rendering the slideshow. These two elements culminated in potentially backwards-incompatible changes which are something I don&#8217;t add to my modules lightly.</p>
<p>I could detail the various ways I considered going about this update along with their benefits and drawbacks, however suffice to say this was the pick of the litter and I believe it&#8217;s the one that will benefit my customers the most in the long run.</p>
<p>I&#8217;ve sent all customers an email a week in advance before publishing this change to make sure they&#8217;re aware of it and (where possible) kept backwards compatibility to hopefully keep sites running while waiting for their respective updates.</p>
<p>As always, good luck with your sites!</p>
<p>&nbsp;</p>
<h3>Any questions?</h3>
<p>As always, if you have any questions or concerns hit me up on my <a href="http://www.flynsarmy.com/contact/" title="Contact | Flynsarmy">contact form</a> and I&#8217;ll get back to you as soon as possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/09/updating-your-banner-slideshows-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating your first LemonStand Widget</title>
		<link>http://www.flynsarmy.com/2012/08/creating-your-first-lemonstand-widget/</link>
		<comments>http://www.flynsarmy.com/2012/08/creating-your-first-lemonstand-widget/#comments</comments>
		<pubDate>Wed, 22 Aug 2012 08:07:03 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Lemonstand]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1206</guid>
		<description><![CDATA[Creating custom widgets with the Widgets module for Lemonstand is a quick and painless process. Below, I'll describe how to build a widget for Lemonstands <a href="http://lemonstand.com/marketplace/module/contact/" title="LemonStand - Contact" target="_blank">Contact</a> module. I'll call this module <strong>Simple Contact Widget</strong>.

Download the completed module from my <a href="https://github.com/Flynsarmy/ls-module-flynsarmycontactwidget" title="Creating your first LemonStand Widget &#124; Flynsarmy" target="_blank">GitHub repo</a>.

While this tutorial will go over everything you need to do to build a complete and working module, it would be very beneficial to also know the basics of module development, naming conventions and so on. Take a look at the documentation <a href="http://lemonstand.com/docs/developing_lemonstand_modules/" title="LemonStand - Developing LemonStand modules" target="_blank">Developing LemonStand Modules</a> if you haven't already done so.]]></description>
				<content:encoded><![CDATA[<p>Creating custom widgets with the Widgets module for Lemonstand is a quick and painless process. Below, I&#8217;ll describe how to build a widget for Lemonstands <a href="http://lemonstand.com/marketplace/module/contact/" title="LemonStand - Contact" target="_blank">Contact</a> module. I&#8217;ll call this module <strong>Simple Contact Widget</strong>.</p>
<p>Download the completed module from my <a href="https://github.com/Flynsarmy/ls-module-flynsarmycontactwidget" title="Creating your first LemonStand Widget | Flynsarmy" target="_blank">GitHub repo</a>.</p>
<p>While this tutorial will go over everything you need to do to build a complete and working module, it would be very beneficial to also know the basics of module development, naming conventions and so on. Take a look at the documentation <a href="http://lemonstand.com/docs/developing_lemonstand_modules/" title="LemonStand - Developing LemonStand modules" target="_blank">Developing LemonStand Modules</a> if you haven&#8217;t already done so.</p>
<h3>Step 1: Create a new module</h3>
<p>First thing to do is create a basic module skeleton. I&#8217;m using the prefix <em>flynsarmycontactwidget</em> for this module. Create the following folders and files in your <em>/modules</em> directory:</p>
<div id="attachment_1207" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/08/new-module-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/08/new-module-web-300x135.png" alt="Skeleton for Simple Contact Widget module" title="Skeleton for Simple Contact Widget module" width="300" height="135" class="size-medium wp-image-1207" /></a><p class="wp-caption-text">Skeleton for Simple Contact Widget module</p></div>
<p>There are two boilerplate files that need to be filled in. Firstly, <em>/classes/flynsarmycontactwidget_module.php</em>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">class</span> FlynsarmyContactWidget_Module <span style="color: #000000; font-weight: bold;">extends</span> Core_ModuleBase
	<span style="color: #009900;">&#123;</span>
		<span style="color: #009933; font-style: italic;">/**
		 * Creates the module information object
		 * @return Core_ModuleInfo
		 */</span>
		<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> createModuleInfo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Core_ModuleInfo<span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">&quot;Simple Contact Widget&quot;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;Provides a widget for LemonStands Contact module&quot;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;Flynsarmy&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>and <em>/updates/version.dat</em>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">#1 Module initialization</pre></td></tr></table></div>
<!-- end from cahe -->
<p>This should be enough to get the module installing. Log out and back into the admin area and you should now see it under <em>System &#8211; Modules &amp; Updates</em>.</p>
<p>&nbsp;</p>
<h3>Step 2: Add the Widget Code</h3>
<p>We have an empty module. Now we need to make it provide a widget.</p>
<p>Each widget has a class that determines how it will load, save and render (on front and backend). The name of the class doesn&#8217;t matter, however following a consistent naming scheme is advised. I&#8217;m naming mine <strong>FlynsarmyContactWidget_Widget_SimpleContact</strong> and placing it in the file <em>/classes/flynsarmycontactwidget_widget_simplecontact.php</em>. This class commonly has the following methods:</p>
<ul>
<li><strong>before_save():</strong> Validates widget settings, moves settings from POST into the widget settings array for later processing by the <em>save()</em> method (which you probably won&#8217;t need to worry about)</li>
<li><strong>render_backend():</strong> Determines how the backend customisation settings will look. The easiest way to handle this is to create a model and render it. Details on how to do that below.</li>
<li><strong>render_frontend($options = array()):</strong> Determines how the widget will look on the frontend. Accepts an optional array of settings that can be used to override the current widget settings.</li>
</ul>
<p>The only other common piece you&#8217;ll see in a widget is the optional <strong>$settings</strong> array. This can be used to provide default settings for your widget.</p>
<p>Let&#8217;s get started. Here&#8217;s the code for the widget class  (<em>/classes/flynsarmycontactwidget_widget_simplecontact.php</em>):</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000000; font-weight: bold;">class</span> FlynsarmyContactWidget_Widget_SimpleContact <span style="color: #000000; font-weight: bold;">extends</span> FlynsarmyWidgets_WidgetBase
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">/*
		 * The settings array isn't required, but it can be used for default settings for options
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$settings</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'show_phone'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'redirect_url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'success_message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Thank you! We will get back to you shortly.'</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">/*
		 * Move any fields I want to save into $this-&gt;settings. Also a good place to do validation
		 */</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</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>post_array_item<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FlynsarmyContactWidget_SimpleContactWidget'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'redirect_url'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
				<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Phpr_ApplicationException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You must enter a redirect URL.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">settings</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">settings</span><span style="color: #339933;">,</span>
				post<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FlynsarmyContactWidget_SimpleContactWidget'</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render_backend<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;form600&quot;&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FlynsarmyContactWidget_SimpleContactWidget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">define_form_fields</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fill_external</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">settings</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			FlynsarmyWidgets_ModelHelper<span style="color: #339933;">::</span><span style="color: #004000;">render_model</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$model</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render_frontend<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			FlynsarmyWidgets_RenderHelper<span style="color: #339933;">::</span><span style="color: #004000;">render_file</span><span style="color: #009900;">&#40;</span>
				<span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/../partials/widgets/frontend/simplecontact.php'</span><span style="color: #339933;">,</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">settings</span>
			<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Our widget needs to be registered to become available in the widget list so open <em>/init/init.php</em> and add the following:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FlynsarmyWidgets'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
		FlynsarmyWidgets<span style="color: #339933;">::</span><span style="color: #004000;">register_widget</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Simple Contact Form'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'description'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Provides a simple contact form. Requires LemonStands 'Contact' module&quot;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'FlynsarmyContactWidget_Widget_SimpleContact'</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>With this file in place you should now see your widget in the <em>Add Widget</em> list:</p>
<div id="attachment_1210" class="wp-caption aligncenter" style="width: 275px"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/08/add-widget-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/08/add-widget-web-265x300.png" alt="Add Widget" title="Add Widget" width="265" height="300" class="size-medium wp-image-1210" /></a><p class="wp-caption-text">Simple Contact Form is now visible in the widget list</p></div>
<h4></h4>
<h4>Backend UI</h4>
<p>We want to provide a backend UI for customisation options for the administrator. The limited contact module doesn&#8217;t provide us many opportunities, but we can decide whether or not to show the phone field, as well as the redirection URL and message.</p>
<p>Take a look at the <em>render_backend()</em> method above. Outside of the styling div I&#8217;m rendering a model <em>FlynsarmyContactWidget_SimpleContactWidget</em>. You&#8217;re able to output any HTML you like here however rendering a model form keeps the look and field of your widget consistent with the rest of LemonStand and provides a bunch of functionality for free.</p>
<p>Here&#8217;s the code for the <em>FlynsarmyContactWidget_SimpleContactWidget</em> model (<em>/models/flynsarmycontactwidget_simplecontactwidget.php</em>).</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">class</span> FlynsarmyContactWidget_SimpleContactWidget <span style="color: #000000; font-weight: bold;">extends</span> Core_Configuration_Model
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> build_form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_field</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'show_phone'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Show Phone field?'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'full'</span><span style="color: #339933;">,</span> db_bool<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_field</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'success_message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Success Message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'full'</span><span style="color: #339933;">,</span> db_varchar<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;A message to display on successful submit.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_field</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'redirect_url'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Redirection URL'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'full'</span><span style="color: #339933;">,</span> db_varchar<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Redirect to given URL on submit. eg http://yoursite.com/contact/success&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">validation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">required</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Very simple stuff &#8211; I&#8217;ve added a checkbox and two text fields. This should render a model form looking like this (Title field is automatically added for you but not as a required field):</p>
<div id="attachment_1209" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/08/contact-modelform-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/08/contact-modelform-web-300x200.png" alt="Contact widget model form" title="Contact widget model form" width="300" height="200" class="size-medium wp-image-1209" /></a><p class="wp-caption-text">How the backend settings UI will look</p></div>
<p>Notice the default <em>Success message</em> value is present thanks to the <em>$settings</em> array added in the widget class. You should now be able to update the settings at will. Try leaving a blank redirection URL and see the validation at work.</p>
<h4>Frontend UI</h4>
<p>The frontend UI is generated with the <em>render_frontend()</em> method of the widget class. We&#8217;re loading the file <em>partials/widgets/frontend/simplecontact.php</em> (as specified in the widget class) so open that up and add the following:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
	<span style="color: #666666; font-style: italic;">/*
	 * Initially taken from http://lemonstand.com/marketplace/module/contact/
	 * A few modifications to make the UI more friendly and support our widget options
	 */</span>
&nbsp;
	<span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> post<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> post<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> post<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$phone</span> <span style="color: #339933;">=</span> post<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'phone'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Phone'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?=</span> open_form<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'onsubmit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;return $(this).sendRequest('contact:on_submit')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;?=</span> flash_message<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$redirect_url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;input type=&quot;hidden&quot; name=&quot;redirect&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$redirect_url</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;input type=&quot;hidden&quot; name=&quot;flash&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> h<span style="color: #009900;">&#40;</span><span style="color: #000088;">$success_message</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&nbsp;
	&lt;ul&gt;
		&lt;li&gt;
			&lt;input type=&quot;text&quot; name=&quot;name&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$name</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; placeholder=&quot;Your name&quot; /&gt;
		&lt;/li&gt;
		&lt;li&gt;
			&lt;input type=&quot;text&quot; name=&quot;email&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$email</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; placeholder=&quot;your@email.com&quot; /&gt;
		&lt;/li&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$show_phone</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;li&gt;
				&lt;input type=&quot;text&quot; name=&quot;phone&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$phone</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; placeholder=&quot;Your mobile number&quot; /&gt;
			&lt;/li&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;li&gt;
			&lt;textarea name=&quot;message&quot; cols=&quot;32&quot; rows=&quot;12&quot; placeholder=&quot;Enter your message here&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?=</span> <span style="color: #000088;">$message</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;
		&lt;/li&gt;
	&lt;/ul&gt;
&nbsp;
	&lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?=</span> close_form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>How you want the frontend UI to look is completely up to you; I took mine from the contact module page and added a few tweaks.</p>
<p>Notice the use of <em>$redirect_url</em>, <em>$success_message</em> and <em>$show_phone</em> variables. Those are the settings made available by the model we created earlier.</p>
<p>&nbsp;</p>
<h3>Conclusion</h3>
<p>Widgets only consist of two main files &#8211; the widget class and a model for rendering the backend settings modal. They can provide alot of functionality and customisability with very little effort and allow developers to rapidly add features to a site.</p>
<p>If you write your own widgets I&#8217;d highly recommend submitting them to the <a href="http://lemonstand.com/marketplace/" title="LemonStand - Marketplace" target="_blank">Lemonstand marketplace</a> &#8211; the more widgets available to everyone, the easier all our jobs become!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/08/creating-your-first-lemonstand-widget/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add Chrome Web Store Style Vertical Scroll Boxes To Your Site</title>
		<link>http://www.flynsarmy.com/2012/07/add-chrome-web-store-style-vertical-scroll-boxes-to-your-site/</link>
		<comments>http://www.flynsarmy.com/2012/07/add-chrome-web-store-style-vertical-scroll-boxes-to-your-site/#comments</comments>
		<pubDate>Mon, 02 Jul 2012 03:00:15 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1184</guid>
		<description><![CDATA[I really like the <a href="https://chrome.google.com/webstore/category/home" title="Chrome Web Store" target="_blank">Chrome web store</a> vertical scroll box functionality so figured I'd write up a tutorial post on how to add them to your site.
<h3>Demo</h3>
Hover over the boxes below.

<iframe width="100%" height="440" src="http://www.flynsarmy.com/wp-content/uploads/2012/07/vert-scroll-boxes.html"></iframe>

Read on for the code!]]></description>
				<content:encoded><![CDATA[<p>I really like the <a href="https://chrome.google.com/webstore/category/home" title="Chrome Web Store" target="_blank">Chrome web store</a> vertical scroll box functionality so figured I&#8217;d write up a tutorial post on how to add them to your site.</p>
<h3>Demo</h3>
<p>Hover over the boxes below.</p>
<p><iframe width="100%" height="440" src="http://www.flynsarmy.com/wp-content/uploads/2012/07/vert-scroll-boxes.html"></iframe></p>
<p><a href="http://www.flynsarmy.com/wp-content/uploads/2012/07/vert-scroll-boxes.html" target="_blank" title="Chrome Web Store style Vertical Scroll Boxes | Flynsarmy">View source</a></p>
<p>&nbsp;</p>
<h3>How-To</h3>
<p>My vertical scroll box is a mashup of the Malsup&#8217;s <a href="http://jquery.malsup.com/cycle/" title="JQuery Cycle Plugin" target="_blank">cycle</a>, George McGinley Smith&#8217;s <a href="http://gsgd.co.uk/sandbox/jquery/easing/" title="jQuery Easing Plugin" target="_blank">easing</a>, and Brian Cherne&#8217;s <a href="http://cherne.net/brian/resources/jquery.hoverIntent.html" title="hoverIntent jQuery Plug-in" target="_blank">hoverintent</a> plugins for <a href="http://jquery.com/" title="jQuery: The Write Less, Do More, JavaScript Library" target="_blank">JQuery</a>.</p>
<p><strong>HTML</strong></p>
<p>Firstly we&#8217;ll add some HTML that&#8217;ll work with cycle:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'vertscrollbox'</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'slide imageslide'</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'slidewrapper'</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'image'</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'slide textslide'</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'slidewrapper'</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Title<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec elit ligula, sollicitudin sit amet tincidunt quis, pharetra eu magna. Integer pellentesque ipsum quis arcu scelerisque et dignissim nunc imperdiet. Mauris blandit felis quis lacus tincidunt sollicitudin...<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Each immediate child of the <em>.verticalscrollbox</em> div is a single slide. I&#8217;ve added some extra classes and a <em>.slidewrapper</em> container div for easier styling.</p>
<p><strong>CSS</strong><br />
You can style the below however you want. I&#8217;ve made mine look relatively close to the chrome web store.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.vertscrollbox</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">240px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #3333ff;">:inline-</span>block<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.vertscrollbox</span> <span style="color: #6666ff;">.slidewrapper</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.vertscrollbox</span> <span style="color: #6666ff;">.slide</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">240px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.vertscrollbox</span> <span style="color: #6666ff;">.imageslide</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.vertscrollbox</span> <span style="color: #6666ff;">.imageslide</span> <span style="color: #6666ff;">.image</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FEFEFE</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">140px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.vertscrollbox</span> <span style="color: #6666ff;">.textslide</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">justify</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.vertscrollbox</span> h3 <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">13px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.vertscrollbox</span> p <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">13px</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p><strong>JS</strong><br />
I could have used cycle on its own, however hoverintent adds a nice feel of professionalism.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.vertscrollbox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">cycle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		fx<span style="color: #339933;">:</span> <span style="color: #3366CC;">'scrollVert'</span><span style="color: #339933;">,</span>
		timeout<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
		containerResize<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
		easing<span style="color: #339933;">:</span> <span style="color: #3366CC;">'easeOutQuint'</span><span style="color: #339933;">,</span>
		speed<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hoverIntent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		timeout<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span>
		over<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">cycle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'prev'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		out<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">cycle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'next'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Conclusion</h3>
<p>Nothing too tricky in this one. It&#8217;s alot of javascript to load for such a simple thing but I think the results are worth it and the tools could be used in other places on your site &#8211; eg cycle as a carousel on your homepage or hoverintent and ease for your main menu.</p>
<p>One last thing to note is that because I&#8217;m using <em>display:inline</em> on my <em>.vertscrollbox</em> divs, they won&#8217;t sit flush up against one another unless you remove the space between <em>&lt;/div&gt;</em> and <em>&lt;div class=&#8217;vertscrollbox&#8217;&gt;</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/07/add-chrome-web-store-style-vertical-scroll-boxes-to-your-site/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to move WPMU domains</title>
		<link>http://www.flynsarmy.com/2012/05/how-to-move-wpmu-domains/</link>
		<comments>http://www.flynsarmy.com/2012/05/how-to-move-wpmu-domains/#comments</comments>
		<pubDate>Wed, 30 May 2012 23:34:26 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[WPMU]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1181</guid>
		<description><![CDATA[Here's a very quick set of SQL snippets for updating a <a href="http://mu.wordpress.org/" title="Blog Tool and Publishing Platform" target="_blank">WPMU</a> domain. This might be useful when building a site on a development domain before moving to a production one later on.

Firstly update the wp_blogs table:
<pre lang="mysql" escaped="true" line="1">UPDATE wp_blogs SET domain='newdomain.com';</pre>
There will be a bunch of <em>wp_options</em> and <em>wp_posts</em> tables - one per site. Find all the tables:
<pre lang="mysql" escaped="true" line="1">SHOW TABLES LIKE "%_options";
SHOW TABLES LIKE "%_posts";</pre>
and for each table, perform the following query:
<pre lang="mysql" escaped="true" line="1">#_options tables
UPDATE &#60;tablename&#62; SET option_value=REPLACE(option_value, 'http://olddomain.com', 'http://newdomain.com');
#_posts tables
UPDATE &#60;tablename&#62; SET post_content=REPLACE(post_content, 'http://olddomain.com', 'http://newdomain.com');</pre>
This was enough to get the sites working for me. Additional tweaks are probably required afterwards - if you find anything let me know in the comments below.]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s a very quick set of SQL snippets for updating a <a href="http://mu.wordpress.org/" title="Blog Tool and Publishing Platform" target="_blank">WPMU</a> domain. This might be useful when building a site on a development domain before moving to a production one later on.</p>
<p>Firstly update the wp_blogs table:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">UPDATE</span> wp_blogs <span style="color: #990099; font-weight: bold;">SET</span> domain<span style="color: #CC0099;">=</span><span style="color: #008000;">'newdomain.com'</span><span style="color: #000033;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>There will be a bunch of <em>wp_options</em> and <em>wp_posts</em> tables &#8211; one per site. Find all the tables:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SHOW</span> <span style="color: #990099; font-weight: bold;">TABLES</span> <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">&quot;<span style="color: #008080; font-weight: bold;">%</span><span style="color: #008080; font-weight: bold;">_</span>options&quot;</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">SHOW</span> <span style="color: #990099; font-weight: bold;">TABLES</span> <span style="color: #CC0099; font-weight: bold;">LIKE</span> <span style="color: #008000;">&quot;<span style="color: #008080; font-weight: bold;">%</span><span style="color: #008080; font-weight: bold;">_</span>posts&quot;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>and for each table, perform the following query:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#_options tables</span>
<span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #CC0099;">&lt;</span>tablename<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">SET</span> option_value<span style="color: #CC0099;">=</span><span style="color: #000099;">REPLACE</span><span style="color: #FF00FF;">&#40;</span>option_value<span style="color: #000033;">,</span> <span style="color: #008000;">'http://olddomain.com'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'http://newdomain.com'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span>
<span style="color: #808080; font-style: italic;">#_posts tables</span>
<span style="color: #990099; font-weight: bold;">UPDATE</span> <span style="color: #CC0099;">&lt;</span>tablename<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">SET</span> post_content<span style="color: #CC0099;">=</span><span style="color: #000099;">REPLACE</span><span style="color: #FF00FF;">&#40;</span>post_content<span style="color: #000033;">,</span> <span style="color: #008000;">'http://olddomain.com'</span><span style="color: #000033;">,</span> <span style="color: #008000;">'http://newdomain.com'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>This was enough to get the sites working for me. Additional tweaks are probably required afterwards &#8211; if you find anything let me know in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/05/how-to-move-wpmu-domains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An Introduction to the HTML5 Pointer Lock and FullScreen APIs</title>
		<link>http://www.flynsarmy.com/2012/05/an-introduction-to-the-html5-pointer-lock-and-fullscreen-apis/</link>
		<comments>http://www.flynsarmy.com/2012/05/an-introduction-to-the-html5-pointer-lock-and-fullscreen-apis/#comments</comments>
		<pubDate>Fri, 11 May 2012 15:40:50 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1168</guid>
		<description><![CDATA[<small>Preface: These APIs are still quite new and subject to change. As of the time of writing, the following tutorial works in Chrome 18.0.1025.168. Firefox 12 supports full screen but not mouse lock.</small>

I've been having a little play with some HTML5 features and worked up an example of <a href="https://developer.mozilla.org/en/API/Mouse_Lock_API" title="Pointer Lock API - MDN" target="_blank">Pointer Lock</a> and <a href="https://developer.mozilla.org/en/DOM/Using_full-screen_mode" title="Using full-screen mode - MDN" target="_blank">Full Screen</a> APIs. As it stands at the moment, pointer lock is tightly coupled with full screen, so you won't be able to use it without first loading up full screen mode.

<span style="color: red;">You'll need to enable <strong>Enable Pointer Lock</strong> in <em>about:flags</em> in Chrome then restart the browser for mouse lock to work.</span>

You may request full screen mode like so:
<pre lang="javascript" escaped="true" line="1">element.requestFullScreen =
	element.requestFullScreen    &#124;&#124;
	element.mozRequestFullScreen &#124;&#124;
	element.webkitRequestFullScreen;

element.requestFullScreen(element.ALLOW_KEYBOARD_INPUT);</pre>
Once in full screen mode, pointer lock should become available:
<pre lang="javascript" escaped="true" line="1">navigator.pointer = navigator.pointer &#124;&#124; navigator.webkitPointer;
navigator.pointer.lock(element,
	function() {
		console.log('Pointer lock');
	},
	function() {
		console.log('No pointer lock');
	}
);</pre>
Note in the above two scripts, <em>element</em> is a DOM element

Check out the working demo <a href="http://www.flynsarmy.com/wp-content/uploads/2012/05/mouselock.html" target="_blank">here</a>. I've also added some JS to determine the direction the locked pointer is travelling and output the data to the screen. View page source for details.]]></description>
				<content:encoded><![CDATA[<p><small>Preface: These APIs are still quite new and subject to change. As of the time of writing, the following tutorial works in Chrome 18.0.1025.168. Firefox 12 supports full screen but not mouse lock.</small></p>
<p>I&#8217;ve been having a little play with some HTML5 features and worked up an example of <a href="https://developer.mozilla.org/en/API/Mouse_Lock_API" title="Pointer Lock API - MDN" target="_blank">Pointer Lock</a> and <a href="https://developer.mozilla.org/en/DOM/Using_full-screen_mode" title="Using full-screen mode - MDN" target="_blank">Full Screen</a> APIs. As it stands at the moment, pointer lock is tightly coupled with full screen, so you won&#8217;t be able to use it without first loading up full screen mode.</p>
<p><span style="color: red;">You&#8217;ll need to enable <strong>Enable Pointer Lock</strong> in <em>about:flags</em> in Chrome then restart the browser for mouse lock to work.</span></p>
<p>You may request full screen mode like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">element.<span style="color: #660066;">requestFullScreen</span> <span style="color: #339933;">=</span>
	element.<span style="color: #660066;">requestFullScreen</span>    <span style="color: #339933;">||</span>
	element.<span style="color: #660066;">mozRequestFullScreen</span> <span style="color: #339933;">||</span>
	element.<span style="color: #660066;">webkitRequestFullScreen</span><span style="color: #339933;">;</span>
&nbsp;
element.<span style="color: #660066;">requestFullScreen</span><span style="color: #009900;">&#40;</span>element.<span style="color: #660066;">ALLOW_KEYBOARD_INPUT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Once in full screen mode, pointer lock should become available:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">navigator.<span style="color: #660066;">pointer</span> <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">pointer</span> <span style="color: #339933;">||</span> navigator.<span style="color: #660066;">webkitPointer</span><span style="color: #339933;">;</span>
navigator.<span style="color: #660066;">pointer</span>.<span style="color: #660066;">lock</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span>
	<span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Pointer lock'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'No pointer lock'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Note in the above two scripts, <em>element</em> is a DOM element</p>
<p>Check out the working demo <a href="http://www.flynsarmy.com/wp-content/uploads/2012/05/mouselock.html" target="_blank">here</a>. I&#8217;ve also added some JS to determine the direction the locked pointer is travelling and output the data to the screen. View page source for details.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/05/an-introduction-to-the-html5-pointer-lock-and-fullscreen-apis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove a PPA and roll back changes in Debian</title>
		<link>http://www.flynsarmy.com/2012/05/remove-a-ppa-and-roll-back-changes-in-debian/</link>
		<comments>http://www.flynsarmy.com/2012/05/remove-a-ppa-and-roll-back-changes-in-debian/#comments</comments>
		<pubDate>Thu, 10 May 2012 03:20:34 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1164</guid>
		<description><![CDATA[If you're a Ubuntu user, you may be familiar with <a href="http://bigbrovar.aoizora.org/index.php/2010/01/10/how-to-safely-remove-ppa-repository-from-ubuntu/" title="How to safely remove PPA Repository from  Ubuntu &#124; bigbrovar" target="_blank">ppa-purge</a>. It's a handy little automated script to remove a PPA and roll back the version of any apps installed from that PPA. Debian doesn't have this nicety by default but there's a relatively simple way to get something close.

Firstly, remove your PPA from <em>/etc/apt/sources.list</em> or from the <em>/etc/apt/sources.list.d/</em> directory.

Do an update:
<pre lang="bash" line="1" escaped="true">sudo apt-get update</pre>
Find any packages that are now obsolete:
<pre lang="bash" line="1" escaped="true">aptitude search '?obsolete'</pre>
For me this returned the following:
<pre lang="text"># aptitude search '?obsolete'
i A libmysqlclient18      - MySQL database client library                                                                           
i A mysql-client-5.5      - MySQL database client binaries                                                                          
i A mysql-server-5.5      - MySQL database server binaries and system database setup                                                
i A mysql-server-core-5.5 - MySQL database server binaries                                                                          
i A ruby-passenger        - Rails and Rack support for Apache2 and Nginx</pre>
Now just remove the listed packages with <em>apt-get remove</em> and reinstall as necessary. It's not quite the automated tool that <em>ppa-purge</em> is, but it's a pretty good start.]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re a Ubuntu user, you may be familiar with <a href="http://bigbrovar.aoizora.org/index.php/2010/01/10/how-to-safely-remove-ppa-repository-from-ubuntu/" title="How to safely remove PPA Repository from  Ubuntu | bigbrovar" target="_blank">ppa-purge</a>. It&#8217;s a handy little automated script to remove a PPA and roll back the version of any apps installed from that PPA. Debian doesn&#8217;t have this nicety by default but there&#8217;s a relatively simple way to get something close.</p>
<p>Firstly, remove your PPA from <em>/etc/apt/sources.list</em> or from the <em>/etc/apt/sources.list.d/</em> directory.</p>
<p>Do an update:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get update</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Find any packages that are now obsolete:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> search <span style="color: #ff0000;">'?obsolete'</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>For me this returned the following:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;"># aptitude search '?obsolete'
i A libmysqlclient18      - MySQL database client library                                                                           
i A mysql-client-5.5      - MySQL database client binaries                                                                          
i A mysql-server-5.5      - MySQL database server binaries and system database setup                                                
i A mysql-server-core-5.5 - MySQL database server binaries                                                                          
i A ruby-passenger        - Rails and Rack support for Apache2 and Nginx</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Now just remove the listed packages with <em>apt-get remove</em> and reinstall as necessary. It&#8217;s not quite the automated tool that <em>ppa-purge</em> is, but it&#8217;s a pretty good start.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/05/remove-a-ppa-and-roll-back-changes-in-debian/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A few handy Exim commands</title>
		<link>http://www.flynsarmy.com/2012/05/a-few-handy-exim-commands/</link>
		<comments>http://www.flynsarmy.com/2012/05/a-few-handy-exim-commands/#comments</comments>
		<pubDate>Tue, 08 May 2012 23:58:45 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1159</guid>
		<description><![CDATA[I've been getting alot of frozen messages with Exim and needed to find out what they were so figured I'd document a few handy commands for doing so:
<h3>List messages in queue:</h3>
<pre lang="bash" line="1" escaped="true">exim -bp</pre>
<h3>Show message header/body:</h3>
<pre lang="bash" line="1" escaped="true">exim -Mvh &#60;id&#62; #For header
exim -Mvb &#60;id&#62; #For body</pre>
<h3>Delete all messages in queue:</h3>
<pre lang="bash" line="1" escaped="true">exim -bp &#124; exiqgrep -i &#124; xargs exim -Mrm</pre>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been getting alot of frozen messages with Exim and needed to find out what they were so figured I&#8217;d document a few handy commands for doing so:</p>
<h3>List messages in queue:</h3>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">exim <span style="color: #660033;">-bp</span></pre></td></tr></table></div>
<!-- end from cahe -->
<h3>Show message header/body:</h3>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">exim <span style="color: #660033;">-Mvh</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #666666; font-style: italic;">#For header</span>
exim <span style="color: #660033;">-Mvb</span> <span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">id</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #666666; font-style: italic;">#For body</span></pre></td></tr></table></div>
<!-- end from cahe -->
<h3>Delete all messages in queue:</h3>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">exim <span style="color: #660033;">-bp</span> <span style="color: #000000; font-weight: bold;">|</span> exiqgrep <span style="color: #660033;">-i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> exim <span style="color: #660033;">-Mrm</span></pre></td></tr></table></div>
<!-- end from cahe -->
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/05/a-few-handy-exim-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add an application to the &#8216;Other Applications&#8217; list in Ubuntu</title>
		<link>http://www.flynsarmy.com/2012/05/how-to-add-an-application-to-the-other-applications-list-in-ubuntu/</link>
		<comments>http://www.flynsarmy.com/2012/05/how-to-add-an-application-to-the-other-applications-list-in-ubuntu/#comments</comments>
		<pubDate>Sun, 06 May 2012 08:04:27 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[gnome 3]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1154</guid>
		<description><![CDATA[It seems Gnome 3 removed the button allowing users to add specified applications into the 'Other Applications' list under 'Open With' in file properties. Until the functionality is restored, you can add applications manually by doing the below:
<pre lang="bash" escaped="true">cp /usr/share/applications/gedit.desktop ~/.local/share/applications/your_app.desktop</pre>
Modify the contents of <em>your_app.deskop</em> to look something like the below:
<pre lang="text" escaped="true">[Desktop Entry]
Name=your_app
GenericName=Your App
Comment=Edit text files
Keywords=Plaintext;Write;
Exec=your_app %U
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
Icon=accessories-text-editor
Categories=GNOME;GTK;Utility;TextEditor;
Actions=Window;Document;
X-Ubuntu-Gettext-Domain=your_app</pre>
You can copy any <em>.desktop</em> file from <em>/usr/share/applications</em> so pick the one that closest resembles the application you're adding. Below you can see <em>komodo</em> added to mine:
<div class="mceTemp mceIEcenter" draggable=""><dl id="attachment_1155" class="wp-caption aligncenter" style="width: 310px;"><dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/05/open_with.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/05/open_with-300x270.png" alt="Komodo has been added to my 'Open With' list" title="Open With" width="300" height="270" class="size-medium wp-image-1155" /></a></dt><dd class="wp-caption-dd">Komodo has been added to my 'Open With' list</dd></dl></div>]]></description>
				<content:encoded><![CDATA[<p>It seems Gnome 3 removed the button allowing users to add specified applications into the &#8216;Other Applications&#8217; list under &#8216;Open With&#8217; in file properties. Until the functionality is restored, you can add applications manually by doing the below:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>applications<span style="color: #000000; font-weight: bold;">/</span>gedit.desktop ~<span style="color: #000000; font-weight: bold;">/</span>.local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>applications<span style="color: #000000; font-weight: bold;">/</span>your_app.desktop</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Modify the contents of <em>your_app.deskop</em> to look something like the below:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">[Desktop Entry]
Name=your_app
GenericName=Your App
Comment=Edit text files
Keywords=Plaintext;Write;
Exec=your_app %U
Terminal=false
Type=Application
StartupNotify=true
MimeType=text/plain;
Icon=/path/to/icon.png
Categories=GNOME;GTK;Utility;TextEditor;
Actions=Window;Document;
X-Ubuntu-Gettext-Domain=your_app</pre></td></tr></table></div>
<!-- end from cahe -->
<p>You can copy any <em>.desktop</em> file from <em>/usr/share/applications</em> so pick the one that closest resembles the application you&#8217;re adding. Below you can see <em>komodo</em> added to mine:</p>
<div class="mceTemp mceIEcenter" draggable="">
<dl id="attachment_1155" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/05/open_with.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/05/open_with-300x270.png" alt="Komodo has been added to my 'Open With' list" title="Open With" width="300" height="270" class="size-medium wp-image-1155" /></a></dt>
<dd class="wp-caption-dd">Komodo has been added to my &#8216;Open With&#8217; list</dd>
</dl>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/05/how-to-add-an-application-to-the-other-applications-list-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change default &#8216;From&#8217; email name from www-data in PHP</title>
		<link>http://www.flynsarmy.com/2012/04/change-default-from-email-name-from-www-data/</link>
		<comments>http://www.flynsarmy.com/2012/04/change-default-from-email-name-from-www-data/#comments</comments>
		<pubDate>Thu, 19 Apr 2012 02:40:02 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1149</guid>
		<description><![CDATA[I've been seeing up an Amazon EC-2 server with Debian Squeeze and used <a href="https://help.ubuntu.com/community/Tasksel" title="Tasksel - Community Ubuntu Documentation" target="_blank">tasksel</a> to install <em>Web Server</em> and <em>Mail Server</em>. Like all things debian, this worked pretty well after the installation completed and everything 'just worked' however I wasn't happy with the default from name and email address assigned to emails sent by PHP - www-data &#60;<em>www-data@my.domain.com&#62;</em>.

I discovered a quick and simple fix to change these defaults for all mail sent with PHP:

Open <em>/etc/php5/apache2/php.ini</em> and set
<pre lang="apache" escaped="true">sendmail_path = '/usr/sbin/sendmail -t -i -fno-reply@my.domain.com -Fno-reply'</pre>
You can see a list of sendmail arguments and what they do <a href="http://www.courier-mta.org/sendmail.html" title="sendmail" target="_blank">here</a>.

Restart apache and you're good to go:
<pre lang="bash" escaped="true">sudo service apache2 restart</pre>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been seeing up an Amazon EC-2 server with Debian Squeeze and used <a href="https://help.ubuntu.com/community/Tasksel" title="Tasksel - Community Ubuntu Documentation" target="_blank">tasksel</a> to install <em>Web Server</em> and <em>Mail Server</em>. Like all things debian, this worked pretty well after the installation completed and everything &#8216;just worked&#8217; however I wasn&#8217;t happy with the default from name and email address assigned to emails sent by PHP &#8211; www-data &lt;<em>www-data@my.domain.com&gt;</em>.</p>
<p>I discovered a quick and simple fix to change these defaults for all mail sent with PHP:</p>
<p>Open <em>/etc/php5/apache2/php.ini</em> and set</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="apache" style="font-family:monospace;">sendmail_path = <span style="color: #7f007f;">'/usr/sbin/sendmail -t -i -fno-reply@my.domain.com -Fno-reply'</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>You can see a list of sendmail arguments and what they do <a href="http://www.courier-mta.org/sendmail.html" title="sendmail" target="_blank">here</a>.</p>
<p>Restart apache and you&#8217;re good to go:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> service apache2 restart</pre></td></tr></table></div>
<!-- end from cahe -->
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/04/change-default-from-email-name-from-www-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cross Domain AJAX with JQuery</title>
		<link>http://www.flynsarmy.com/2012/04/cross-domain-ajax-with-jquery/</link>
		<comments>http://www.flynsarmy.com/2012/04/cross-domain-ajax-with-jquery/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 04:30:41 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1143</guid>
		<description><![CDATA[Anyone attempting to do cross domain AJAX will be familiar with the following message:
<blockquote>XMLHttpRequest cannot load http://domain.com/page.php. Origin http://yoursite.com is not allowed by Access-Control-Allow-Origin.</blockquote>
However if you own the server you're AJAXing data from, there's a simple way to make this possible using a <a href="http://stackoverflow.com/a/761010/1263114" title="javascript - Jquery getJSON cross domain problems - Stack Overflow" target="_blank">callback</a>. Here's an example:

server.php (On a different domain):
<pre lang="php" escaped="true">&#60;?php
	$response = 'your response here'.

	if ( !isset($_GET['callback']) ) $_GET['callback'] = '';

	echo $_GET['callback'] . '('.json_encode(array('response'=&#62;$response)).');';</pre>
client.php (with JQuery):
<pre lang="javascript" escaped="true">$.getJSON('http://yourdomain.com/server.php?callback=?', function(json) {
	alert( json.response );
});</pre>
That's all there is to it. Remember the <em>?callback=?</em> URL segment or it won't work.]]></description>
				<content:encoded><![CDATA[<p>Anyone attempting to do cross domain AJAX will be familiar with the following message:</p>
<blockquote><p>XMLHttpRequest cannot load http://domain.com/page.php. Origin http://yoursite.com is not allowed by Access-Control-Allow-Origin.</p></blockquote>
<p>However if you own the server you&#8217;re AJAXing data from, there&#8217;s a simple way to make this possible using a <a href="http://stackoverflow.com/a/761010/1263114" title="javascript - Jquery getJSON cross domain problems - Stack Overflow" target="_blank">callback</a>. Here&#8217;s an example:</p>
<p>server.php (On a different domain):</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'your response here'</span><span style="color: #339933;">.</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'callback'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'callback'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'callback'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'('</span><span style="color: #339933;">.</span><span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'response'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">');'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>client.php (with JQuery):</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">getJSON</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://yourdomain.com/server.php?callback=?'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	alert<span style="color: #009900;">&#40;</span> json.<span style="color: #660066;">response</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>That&#8217;s all there is to it. Remember the <em>?callback=?</em> URL segment or it won&#8217;t work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/04/cross-domain-ajax-with-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Use Apache Alongside Nginx Without Requiring a Subdomain</title>
		<link>http://www.flynsarmy.com/2012/03/use-apache-alongside-nginx-without-requiring-a-subdomain/</link>
		<comments>http://www.flynsarmy.com/2012/03/use-apache-alongside-nginx-without-requiring-a-subdomain/#comments</comments>
		<pubDate>Sun, 18 Mar 2012 04:09:32 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1126</guid>
		<description><![CDATA[I've been looking for ways to speed up my site recently and came across <a href="http://www.ibualoy.net/blog/itech/linux/167-how-to-configure-nginx-and-apache-on-debian" title="How to configure Nginx and Apache on Debian &#124; Linux" target="_blank">this interesting article</a> on seamlessly integrating <a href="http://nginx.org/" title="nginx news" target="_blank">nginx</a> with Apache to handle asset files without requiring a CDN subdomain. This works by checking the requests file extension for <em>.js, .jpg, .pdf</em> etc and if not found, proxies the request to Apache and serves the results.

<h3>Benefits</h3>
You won't need to modify all your pages/posts updating asset locations to point to a subdomain! Everything will 'just work'.

<h3>Issues/Drawbacks</h3>
There are 2 issues I've found with this setup:
<ul>
	<li>Because Apache is now running on port 8080, your mod_rewrite redirects will now redirect to that port. You won't be able to use <a href="https://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirectmatch" title="RedirectMatch Directive" target="_blank">RedirectMatch</a> anymore, however below is the solution I came up with:
<pre lang="apache" escaped="true">RewriteEngine on
RewriteRule ^foo\.php$ http://%{HTTP_HOST}:80/bar.php [R=301,L]</pre>
</li>
	<li>You can no longer use .htaccess redirects for any asset files nginx is serving. Instead, use nginx redirects. Below is an example:
<pre lang="apache" escaped="true">rewrite ^\/foo\.jpg$ http://173.255.221.210/bar.jpg permanent;</pre>
For more information on nginx redirects, see the <a href="http://wiki.nginx.org/NginxHttpRewriteModule" title="HttpRewriteModule" target="_blank">official documentation</a>.</li>
</ul>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been looking for ways to speed up my site recently and came across <a href="http://www.ibualoy.net/blog/itech/linux/167-how-to-configure-nginx-and-apache-on-debian" title="How to configure Nginx and Apache on Debian | Linux" target="_blank">this interesting article</a> on seamlessly integrating <a href="http://nginx.org/" title="nginx news" target="_blank">nginx</a> with Apache to handle asset files without requiring a CDN subdomain. This works by checking the requests file extension for <em>.js, .jpg, .pdf</em> etc and if not found, proxies the request to Apache and serves the results. Here&#8217;s what you need:</p>
<h3>Install/Configure nginx</h3>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> nginx
<span style="color: #c20cb9; font-weight: bold;">sudo</span> nano<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>sites-available<span style="color: #000000; font-weight: bold;">/</span>default</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Here&#8217;s what my Debian 6 config file looks like (Ubuntu should be the same):</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># You may add here your</span>
<span style="color: #adadad; font-style: italic;"># server {</span>
<span style="color: #adadad; font-style: italic;">#	...</span>
<span style="color: #adadad; font-style: italic;"># }</span>
<span style="color: #adadad; font-style: italic;"># statements for each of your virtual hosts</span>
&nbsp;
server {
&nbsp;
	<span style="color: #00007f;">listen</span>   <span style="color: #ff0000;">80</span>; <span style="color: #adadad; font-style: italic;">## listen for ipv4</span>
	<span style="color: #00007f;">listen</span>   [::]:<span style="color: #ff0000;">80</span> default ipv6only=<span style="color: #0000ff;">on</span>; <span style="color: #adadad; font-style: italic;">## listen for ipv6</span>
&nbsp;
	server_name  localhost;
<span style="display:block;background-color: #ffc;">	root /var/www/;</span>&nbsp;
	access_log  /var/log/nginx/localhost.access.log;
&nbsp;
	<span style="color: #adadad; font-style: italic;"># Static Contents</span>
<span style="display:block;background-color: #ffc;">	location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {</span>		access_log <span style="color: #0000ff;">off</span>;
		expires 30d;
	}
&nbsp;
	<span style="color: #adadad; font-style: italic;"># Dydamic Content forward to Apache</span>
	location / {
        	proxy_set_header X-Real-IP  $remote_addr;
	        proxy_set_header Host $host;
        	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
<span style="display:block;background-color: #ffc;">	        proxy_pass http://127.0.0.1:<span style="color: #ff0000;">8080</span>;</span>	}
}
&nbsp;
<span style="color: #adadad; font-style: italic;">###############################################################################</span>
<span style="color: #adadad; font-style: italic;"># virtualhost</span>
<span style="color: #adadad; font-style: italic;">###############################################################################</span>
&nbsp;
<span style="color: #adadad; font-style: italic;">#server {</span>
<span style="color: #adadad; font-style: italic;">#    server_name www.example.com example.com;</span>
<span style="color: #adadad; font-style: italic;">#    root /var/www/example.com/html/;</span>
<span style="color: #adadad; font-style: italic;">#</span>
<span style="color: #adadad; font-style: italic;">#    # Static Contents</span>
<span style="color: #adadad; font-style: italic;">#    location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {</span>
<span style="color: #adadad; font-style: italic;">#        access_log off;</span>
<span style="color: #adadad; font-style: italic;">#        expires 30d;</span>
<span style="color: #adadad; font-style: italic;">#    }</span>
<span style="color: #adadad; font-style: italic;">#</span>
<span style="color: #adadad; font-style: italic;">#    # Dydamic Content forward to Apache</span>
<span style="color: #adadad; font-style: italic;">#    location / {</span>
<span style="color: #adadad; font-style: italic;">#        proxy_set_header X-Real-IP  $remote_addr;</span>
<span style="color: #adadad; font-style: italic;">#        proxy_set_header Host $host;</span>
<span style="color: #adadad; font-style: italic;">#        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</span>
<span style="color: #adadad; font-style: italic;">#        proxy_pass http://127.0.0.1:8080;</span>
<span style="color: #adadad; font-style: italic;">#    }</span>
<span style="color: #adadad; font-style: italic;">#}</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Above you should tweak the highlighted lines to your liking. You&#8217;ll notice I&#8217;m running apache on port 8080, so let&#8217;s update apache.</p>
<p>&nbsp;</p>
<h3>Apache Configuration</h3>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># log correct IP address for forwarded requests </span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> libapache2-mod-rpaf
&nbsp;
<span style="color: #666666; font-style: italic;"># update the port Apache will be running on. Change the following lines from 80 to 8080:</span>
<span style="color: #666666; font-style: italic;"># NameVirtualHost *:8080</span>
<span style="color: #666666; font-style: italic;"># Listen 8080</span>
<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>apache2<span style="color: #000000; font-weight: bold;">/</span>ports.conf
&nbsp;
<span style="color: #666666; font-style: italic;"># do the same in your desired site. Change 80 to 8080:</span>
<span style="color: #666666; font-style: italic;"># &lt;virtualhost :8080=&quot;&quot;&gt; sudo nano /etc/apache2/sites-enabled/000-default &lt;/virtualhost&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Restart your servers</h3>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> service apache2 restart
<span style="color: #c20cb9; font-weight: bold;">sudo</span> service nginx restart</pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Benefits</h3>
<p>You won&#8217;t need to modify all your pages/posts updating asset locations to point to a subdomain! Everything will &#8216;just work&#8217;.</p>
<p>&nbsp;</p>
<h3>Issues/Drawbacks</h3>
<p>There are 2 issues I&#8217;ve found with this setup:</p>
<ul>
<li>Because Apache is now running on port 8080, your mod_rewrite redirects will now redirect to that port. You won&#8217;t be able to use <a href="https://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirectmatch" title="RedirectMatch Directive" target="_blank">RedirectMatch</a> anymore, however below is the solution I came up with:
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">on</span>
<span style="color: #00007f;">RewriteRule</span> ^foo.php$ http://%{HTTP_HOST}:<span style="color: #ff0000;">80</span>/bar.php [R=<span style="color: #ff0000;">301</span>,L]</pre></td></tr></table></div>
<!-- end from cahe -->
</li>
<li>You can no longer use .htaccess redirects for any asset files nginx is serving. Instead, use nginx redirects. Below is an example:
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="apache" style="font-family:monospace;">rewrite ^/foo.jpg$ http://173.255.221.210/bar.jpg permanent;</pre></td></tr></table></div>
<!-- end from cahe -->
<p>For more information on nginx redirects, see the <a href="http://wiki.nginx.org/NginxHttpRewriteModule" title="HttpRewriteModule" target="_blank">official documentation</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/03/use-apache-alongside-nginx-without-requiring-a-subdomain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Forward Email from a Specified Address</title>
		<link>http://www.flynsarmy.com/2012/03/forward-email-from-a-specified-address/</link>
		<comments>http://www.flynsarmy.com/2012/03/forward-email-from-a-specified-address/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 05:02:30 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[email]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1120</guid>
		<description><![CDATA[A couple of times now we've needed to forward <em>foo@oursite.com</em> to <em>my@gmail.com</em>. If you're running postfix here's how to do that.
<pre lang="bash">nano /etc/postvix/virtual</pre>
Add
<pre lang="text">from@email.com to@email.com</pre>
then run
<pre lang="bash">postmap /etc/postfix/virtual</pre>
If the above doesn't work, make sure you have the following line in <em>/etc/postfix/main.cf</em>:
<pre lang="text">virtual_alias_maps = hash:/etc/postfix/virtual</pre>
and type
<pre lang="bash">service postfix reload</pre>
Thanks to Matt Simmons of ServerFault for <a href="http://serverfault.com/questions/49044/simple-postfix-configuration-forward-all-incoming-email-to-single-address/49047#49047" title="ubuntu - simple postfix configuration - forward all incoming email to single address - Server Fault" target="_blank">his answer</a>.]]></description>
				<content:encoded><![CDATA[<p>A couple of times now we&#8217;ve needed to forward <em>foo@oursite.com</em> to <em>my@gmail.com</em>. If you&#8217;re running postfix here&#8217;s how to do that.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><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>postfix<span style="color: #000000; font-weight: bold;">/</span>virtual</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Add</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">from@email.com to@email.com</pre></td></tr></table></div>
<!-- end from cahe -->
<p>then run</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">postmap <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>postfix<span style="color: #000000; font-weight: bold;">/</span>virtual</pre></td></tr></table></div>
<!-- end from cahe -->
<p>If the above doesn&#8217;t work, make sure you have the following line in <em>/etc/postfix/main.cf</em>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">virtual_alias_maps = hash:/etc/postfix/virtual</pre></td></tr></table></div>
<!-- end from cahe -->
<p>and type</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">service postfix reload</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Thanks to Matt Simmons of ServerFault for <a href="http://serverfault.com/questions/49044/simple-postfix-configuration-forward-all-incoming-email-to-single-address/49047#49047" title="ubuntu - simple postfix configuration - forward all incoming email to single address - Server Fault" target="_blank">his answer</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/03/forward-email-from-a-specified-address/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hide the Attention Button in Pidgin</title>
		<link>http://www.flynsarmy.com/2012/02/hide-the-attention-button-in-pidgin/</link>
		<comments>http://www.flynsarmy.com/2012/02/hide-the-attention-button-in-pidgin/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 04:56:47 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Pidgin]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1109</guid>
		<description><![CDATA[<div class="mceTemp mceIEcenter" draggable=""><dl id="attachment_1111" class="wp-caption aligncenter" style="width: 239px;"><dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/02/no_attention_button-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/02/no_attention_button-web-229x300.png" alt="Pidgin Attention button successfully hidden" title="No Attention button" width="229" height="300" class="size-medium wp-image-1111" /></a></dt><dd class="wp-caption-dd">Pidgin Attention button successfully hidden</dd></dl></div>
Ever since the developers added the Attention button to Pidgin, one of the most common questions asked is how to remove it. I finally set some time aside to answer this question.
<ul>
	<li>Download the plugin that does exactly this from the <a href="http://developer.pidgin.im/ticket/12202" title="#12202 (Option to disable Nudge button?) - Pidgin - Trac" target="_blank">Pidgin developer page</a>.</li>
	<li>Install the Pidgin developer dependencies if you haven't already:
<pre lang="bash" escaped="true">sudo apt-get install ubuntu-dev-tools subversion g++ pidgin-data libpurple0 libpurple-dev pidgin-dev libgtk2.0-dev</pre>
This step is important or you'll receive errors like the following:
<pre lang="text" escaped="true">$ make
[CC] hide_attention_button.o
Package pidgin was not found in the pkg-config search path.
Perhaps you should add the directory containing `pidgin.pc'
to the PKG_CONFIG_PATH environment variable
No package 'pidgin' found
Package purple was not found in the pkg-config search path.
Perhaps you should add the directory containing `purple.pc'
to the PKG_CONFIG_PATH environment variable
No package 'purple' found
Package gobject-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gobject-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gobject-2.0' found
Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found
hide_attention_button.c:24:20: fatal error: plugin.h: No such file or directory
compilation terminated.
make: *** [hide_attention_button.o] Error 1</pre>
</li>
	<li>Drop the .c and Makefile into a folder and in a terminal run the following commands:
<pre lang="bash" escaped="true">make
sudo make install</pre>
If all went well you'll see:
<pre lang="text">$ make
[CC] hide_attention_button.o
[SHLIB] hide_attention_button.so
$ sudo make install
mkdir -p /`pkg-config --variable=prefix purple`/lib/purple-2
install hide_attention_button.so /`pkg-config --variable=prefix purple`/lib/purple-2</pre>
</li>
</ul>
Restart pidgin and enable the plugin under <em>Tools - Plugins - Hide Pidgin Attention Button</em>.
<h3>Close but not Perfect</h3>
Although this plugin really does hide your Attention button, it still exists if you hover over where it used to be:
<div class="mceTemp mceIEcenter" draggable=""><dl id="attachment_1110" class="wp-caption aligncenter" style="width: 239px;"><dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/02/no_attention_button_hover-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/02/no_attention_button_hover-web-229x300.png" alt="The button is much smaller but still clickable" title="Attention button still exists" width="229" height="300" class="size-medium wp-image-1110" /></a></dt><dd class="wp-caption-dd">The button is much smaller but still clickable</dd></dl></div>
At least it's much smaller now and less likely to be accidentally clicked!]]></description>
				<content:encoded><![CDATA[<div class="mceTemp mceIEcenter" draggable="">
<dl id="attachment_1111" class="wp-caption aligncenter" style="width: 239px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/02/no_attention_button-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/02/no_attention_button-web-229x300.png" alt="Pidgin Attention button successfully hidden" title="No Attention button" width="229" height="300" class="size-medium wp-image-1111" /></a></dt>
<dd class="wp-caption-dd">Pidgin Attention button successfully hidden</dd>
</dl>
</div>
<p>Ever since the developers added the Attention button to Pidgin, one of the most common questions asked is how to remove it. I finally set some time aside to answer this question.</p>
<ul>
<li>Download the plugin that does exactly this from the <a href="http://developer.pidgin.im/ticket/12202" title="#12202 (Option to disable Nudge button?) - Pidgin - Trac" target="_blank">Pidgin developer page</a>.</li>
<li>Install the Pidgin developer dependencies if you haven&#8217;t already:
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> ubuntu-dev-tools subversion <span style="color: #c20cb9; font-weight: bold;">g++</span> pidgin-data libpurple0 libpurple-dev pidgin-dev libgtk2.0-dev</pre></td></tr></table></div>
<!-- end from cahe -->
<p>This step is important or you&#8217;ll receive errors like the following:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">$ make
[CC] hide_attention_button.o
Package pidgin was not found in the pkg-config search path.
Perhaps you should add the directory containing `pidgin.pc'
to the PKG_CONFIG_PATH environment variable
No package 'pidgin' found
Package purple was not found in the pkg-config search path.
Perhaps you should add the directory containing `purple.pc'
to the PKG_CONFIG_PATH environment variable
No package 'purple' found
Package gobject-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gobject-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gobject-2.0' found
Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found
hide_attention_button.c:24:20: fatal error: plugin.h: No such file or directory
compilation terminated.
make: *** [hide_attention_button.o] Error 1</pre></td></tr></table></div>
<!-- end from cahe -->
</li>
<li>Drop the .c and Makefile into a folder and in a terminal run the following commands:
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>If all went well you&#8217;ll see:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">$ make
[CC] hide_attention_button.o
[SHLIB] hide_attention_button.so
$ sudo make install
mkdir -p /`pkg-config --variable=prefix purple`/lib/purple-2
install hide_attention_button.so /`pkg-config --variable=prefix purple`/lib/purple-2</pre></td></tr></table></div>
<!-- end from cahe -->
</li>
</ul>
<p>Restart pidgin and enable the plugin under <em>Tools &#8211; Plugins &#8211; Hide Pidgin Attention Button</em>.</p>
<h3>Close but not Perfect</h3>
<p>Although this plugin really does hide your Attention button, it still exists if you hover over where it used to be:</p>
<div class="mceTemp mceIEcenter" draggable="">
<dl id="attachment_1110" class="wp-caption aligncenter" style="width: 239px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/02/no_attention_button_hover-web.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/02/no_attention_button_hover-web-229x300.png" alt="The button is much smaller but still clickable" title="Attention button still exists" width="229" height="300" class="size-medium wp-image-1110" /></a></dt>
<dd class="wp-caption-dd">The button is much smaller but still clickable</dd>
</dl>
</div>
<p>At least it&#8217;s much smaller now and less likely to be accidentally clicked!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/02/hide-the-attention-button-in-pidgin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP WebSocket Chat Application 2.0</title>
		<link>http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/</link>
		<comments>http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/#comments</comments>
		<pubDate>Wed, 15 Feb 2012 11:37:47 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[WebSockets]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1093</guid>
		<description><![CDATA[Even though it hasn't worked for quite some time now, my <a href="http://www.flynsarmy.com/2010/05/php-web-socket-chat-application/" title="PHP Web Socket Chat Application &#124; Flynsarmy">previous</a> PHP WebSocket chat application has garnered quite a bit of attention and is still one of my most heavily trafficked posts. As a result I thought I'd provide you all with a working script as of Feb 15, 2012. Also, because I'm your typical lazy developer, I'll be building on top of other peoples' work - most notably <a href="http://code.google.com/p/phpwebsocket/" title="phpwebsocket - PHP and WebSockets - Google Project Hosting" target="_blank">PHPWebSocket</a>.

<strong>You can download the final script <a href="https://github.com/Flynsarmy/PHPWebSocket-Chat" title="Flynsarmy/PHPWebSocket-Chat - GitHub" target="_blank">here</a></strong>. According to the <a href="http://en.wikipedia.org/wiki/Websocket#Browser_support" title="WebSocket - Wikipedia, the free encyclopedia" target="_blank">Wikipedia article</a> on WebSockets, it should work in IE10+, Firefox 7+ and Chrome 14+. Personally I tested with Chrome 17.0.963.46 and Firefox 10.0.1.

I want to stress that this tutorial is designed to be extremely basic and as such does not give alot of functionality out of the box (but provides all the tools required to add more). It's simply a working example of a PHP-based WebSocket server.]]></description>
				<content:encoded><![CDATA[<p>Even though it hasn&#8217;t worked for quite some time now, my <a href="http://www.flynsarmy.com/2010/05/php-web-socket-chat-application/" title="PHP Web Socket Chat Application | Flynsarmy">previous</a> PHP WebSocket chat application has garnered quite a bit of attention and is still one of my most heavily trafficked posts. As a result I thought I&#8217;d provide you all with a working script as of Feb 15, 2012. Because I&#8217;m your typical lazy developer, I&#8217;ll be building on top of other peoples&#8217; work &#8211; most notably <a href="http://code.google.com/p/phpwebsocket/" title="phpwebsocket - PHP and WebSockets - Google Project Hosting" target="_blank">PHPWebSocket</a>.</p>
<p><strong>You can download the final script <a href="https://github.com/Flynsarmy/PHPWebSocket-Chat" title="Flynsarmy/PHPWebSocket-Chat - GitHub" target="_blank">here</a></strong>. According to the <a href="http://en.wikipedia.org/wiki/Websocket#Browser_support" title="WebSocket - Wikipedia, the free encyclopedia" target="_blank">Wikipedia article</a> on WebSockets, it should work in IE10+, Firefox 7+ and Chrome 14+. Personally I tested with Chrome 17.0.963.46 and Firefox 10.0.1.</p>
<p>I want to stress that this tutorial is designed to be extremely basic and as such does not give alot of functionality out of the box (but provides all the tools necessary to add more). It&#8217;s simply a working example of a PHP-based WebSocket server.</p>
<p>&nbsp;</p>
<h3>The Implimentation &#8211; Server Side</h3>
<div class="mceTemp mceIEcenter" draggable="">
<dl id="attachment_1101" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/02/php-websocket-chat-application-server.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/02/php-websocket-chat-application-server-300x182.png" alt="PHP WebSocket Server" title="PHP WebSocket Server" width="300" height="182" class="size-medium wp-image-1101" /></a></dt>
<dd class="wp-caption-dd">PHP WebSocket Server</dd>
</dl>
</div>
<p>While the <a href="http://code.google.com/p/phpwebsocket/" title="phpwebsocket - PHP and WebSockets - Google Project Hosting" target="_blank">PHPWebSocket</a> class works, it puts alot of variables and constants into the global scope. This is a big no-no in my opinion so I moved the entire script into a class <em>PHPWebSocket</em> and added the following functions:</p>
<ul>
<li><strong>bind:</strong> Binds a given function name to a given event. Valid events include:
<ul>
<li><strong>open:</strong> Triggers as a user connects</li>
<li><strong>close:</strong> Triggers as a user disconnects</li>
<li><strong>message:</strong> Triggers when a user sends data to the server</li>
</ul>
</li>
<li><strong>unbind: </strong>Unbinds all functions from a given event, or all functions from all events if no event name is given.</li>
<li><strong>log:</strong> Logs a message to the standard output</li>
</ul>
<p>Below is an example of your server script for a very basic chat application (Note that I&#8217;ve set the server to run on 127.0.0.1. Set this to your network IP if you want others on the network/internet to be able to connect to your server):</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// prevent the server from timing out</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// include the web sockets server script (the server is started at the far bottom of this file)</span>
<span style="color: #b1b100;">require</span> <span style="color: #0000ff;">'class.PHPWebSocket.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// when a client sends data to the server</span>
<span style="color: #000000; font-weight: bold;">function</span> wsOnMessage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$clientID</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$messageLength</span><span style="color: #339933;">,</span> <span style="color: #000088;">$binary</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$Server</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #990000;">long2ip</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsClients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$clientID</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// check if message length is 0</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$messageLength</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsClose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$clientID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Send the message to everyone but the person who said it</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsClients</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$client</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$clientID</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsSend</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Visitor <span style="color: #006699; font-weight: bold;">$clientID</span> (<span style="color: #006699; font-weight: bold;">$ip</span>) said <span style="color: #000099; font-weight: bold;">&quot;</span><span style="color: #006699; font-weight: bold;">$message</span><span style="color: #000099; font-weight: bold;">&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// when a client connects</span>
<span style="color: #000000; font-weight: bold;">function</span> wsOnOpen<span style="color: #009900;">&#40;</span><span style="color: #000088;">$clientID</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$Server</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #990000;">long2ip</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsClients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$clientID</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$ip</span> (<span style="color: #006699; font-weight: bold;">$clientID</span>) has connected.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Send a join notice to everyone but the person who joined</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsClients</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$client</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$clientID</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsSend</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Visitor <span style="color: #006699; font-weight: bold;">$clientID</span> (<span style="color: #006699; font-weight: bold;">$ip</span>) has joined the room.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// when a client closes or lost connection</span>
<span style="color: #000000; font-weight: bold;">function</span> wsOnClose<span style="color: #009900;">&#40;</span><span style="color: #000088;">$clientID</span><span style="color: #339933;">,</span> <span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$Server</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #990000;">long2ip</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsClients</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$clientID</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$ip</span> (<span style="color: #006699; font-weight: bold;">$clientID</span>) has disconnected.&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Send a user left notice to everyone in the room</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsClients</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$id</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$client</span> <span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsSend</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Visitor <span style="color: #006699; font-weight: bold;">$clientID</span> (<span style="color: #006699; font-weight: bold;">$ip</span>) has left the room.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// start the server</span>
<span style="color: #000088;">$Server</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PHPWebSocket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wsOnMessage'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'open'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wsOnOpen'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'close'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wsOnClose'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// for other computers to connect, you will probably need to change this to your LAN IP or external IP,</span>
<span style="color: #666666; font-style: italic;">// alternatively use: gethostbyaddr(gethostbyname($_SERVER['SERVER_NAME']))</span>
<span style="color: #000088;">$Server</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">wsStartServer</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>The Implimentation &#8211; Client Side</h3>
<div class="mceTemp mceIEcenter" draggable="">
<dl id="attachment_1102" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2012/02/php-websocket-chat-application-client.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2012/02/php-websocket-chat-application-client-300x223.png" alt="WebSocket Client" title="WebSocket Client" width="300" height="223" class="size-medium wp-image-1102" /></a></dt>
<dd class="wp-caption-dd">Very basic WebSocket Client</dd>
</dl>
</div>
<p>I wasn&#8217;t impressed with the JavaScript class provided with PHPWebSocket either, so instead I&#8217;m using a more flexible one called <em>FancyWebSocket</em> (which I&#8217;ve also made modifications to). Like the server functions I added, FancyWebSocket allows you to bind functions to <em>open</em>, <em>close</em>, and <em>message</em> events so your page should look something like the following:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;!doctype html&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'UTF-8'</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
		input, textarea {border:1px solid #CCC;margin:0px;padding:0px}
&nbsp;
		#body {max-width:800px;margin:auto}
		#log {width:100%;height:400px}
		#message {width:100%;line-height:20px}
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">style</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fancywebsocket.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
		var Server;
&nbsp;
		function log( text ) {
			$log = $('#log');
			//Add text to log
			$log.append(($log.val()?&quot;n&quot;:'')+text);
			//Autoscroll
			$log[0].scrollTop = $log[0].scrollHeight - $log[0].clientHeight;
		}
&nbsp;
		function send( text ) {
			Server.send( 'message', text );
		}
&nbsp;
		$(document).ready(function() {
			log('Connecting...');
			Server = new FancyWebSocket('ws://127.0.0.1:9300');
&nbsp;
			$('#message').keypress(function(e) {
				if ( e.keyCode == 13 <span style="color: #ddbb00;">&amp;&amp; this.value ) {</span>
<span style="color: #ddbb00;">					log( 'You: ' + this.value );</span>
					send( this.value );
					$(this).val('');
				}
			});
&nbsp;
			//Let the user know we're connected
			Server.bind('open', function() {
				log( &quot;Connected.&quot; );
			});
&nbsp;
			//OH NOES! Disconnection occurred.
			Server.bind('close', function( data ) {
				log( &quot;Disconnected.&quot; );
			});
&nbsp;
			//Log any messages sent from server
			Server.bind('message', function( payload ) {
				log( payload );
			});
&nbsp;
			Server.connect();
		});
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'body'</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">textarea</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'log'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'log'</span> <span style="color: #000066;">readonly</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'readonly'</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">textarea</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span><span style="color: #66cc66;">/</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'text'</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'message'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'message'</span> <span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>How to Run It</h3>
<p>After <a href="https://github.com/Flynsarmy/PHPWebSocket-Chat" title="Flynsarmy/PHPWebSocket-Chat - GitHub" target="_blank">downloading</a>, simply open a terminal and type</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">php5 .<span style="color: #000000; font-weight: bold;">/</span>server.php</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Then load it up in your browser.</p>
<p>&nbsp;</p>
<h3>Further Reading</h3>
<p>If you want to see the true awesomeness of WebSockets and what they can do for you and your site, head on over to Kaazing and check out their <a href="http://blog.kaazing.com/2012/02/12/lightning-fast-stock-trade-websocket-portfolio-demo/" title="Lightning Fast Stock Trade &amp;#8211; WebSocket Portfolio Demo | The Zinger" target="_blank">Lightning Fast Stock Trade</a> demo. It&#8217;s very cool stuff.</p>
<p>A redditor whipped up a <a href="http://www.reddit.com/r/PHP/comments/takqp/php_websocket/" title="PHP Websocket : PHP" target="_blank">version 13 compatible</a> websocket implimentation here. The comments include a couple of links to other implementations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/02/php-websocket-chat-application-2-0/feed/</wfw:commentRss>
		<slash:comments>137</slash:comments>
		</item>
		<item>
		<title>Change Default Languge/Subtitles in MKV Files</title>
		<link>http://www.flynsarmy.com/2012/01/change-default-languge-subtitles-in-mkv-files/</link>
		<comments>http://www.flynsarmy.com/2012/01/change-default-languge-subtitles-in-mkv-files/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 15:31:32 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1086</guid>
		<description><![CDATA[Tonight I discovered I had an entire folder of dual audio MKV files with the wrong default language and wrong default subtitle track. I could have used mkvpropedit to manually change each file but that's such a hassle. Instead, here's a bash script to do them all at once (You'll need to tweak the highlighted rows accordingly):
<pre lang="bash" line="1" escaped="true" highlight="4,8,9,11,12">#!/bin/bash
OIFS="$IFS"
IFS=$'\n' 
for file in "/path/to/files/"*.mkv
do
	echo $file
	#Update audio track defaults
	mkvpropedit "${file}" --edit track:2 --set flag-default=0
	mkvpropedit "${file}" --edit track:3 --set flag-default=1
	#Update subtitle track defaults
	mkvpropedit "${file}" --edit track:4 --set flag-default=0
	mkvpropedit "${file}" --edit track:5 --set flag-default=1
done
IFS="$OIFS"</pre>
You'll need <em>mkvtoolnix</em> installed for the <em><a href="http://manpages.ubuntu.com/manpages/natty/man1/mkvpropedit.1.html" title="Ubuntu Manpage: mkvinfo - Print information about tracks in Matroska files" target="_blank">mkvpropedit</a></em> command. To determine what the various tracks contain, do a
<pre lang="bash" line="1" escaped="true">mkvinfo /path/to/file.mkv</pre>
or <em><a href="http://manpages.ubuntu.com/manpages/hardy/man1/mkvinfo.1.html" title="Ubuntu Manpage: mkvinfo - Print information about tracks in Matroska files" target="_blank">mkvinfo</a> -g</em> for you GUI users :)

As an added bonus, here's the Windows equivalent of this script:
<pre lang="bash" line="1" escaped="true">@echo off
FOR /f "tokens=*" %%G IN ('dir /a-d /b') DO (
	mkvpropedit.exe "%%G" --edit track:2 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:3 --set flag-default=0
	mkvpropedit.exe "%%G" --edit track:4 --set flag-default=1
	mkvpropedit.exe "%%G" --edit track:5 --set flag-default=0
	echo.
)
pause</pre>
I've been told the Windows version works but haven't tested personally.

Happy viewing!]]></description>
				<content:encoded><![CDATA[<p>Tonight I discovered I had an entire folder of dual audio MKV files with the wrong default language and wrong default subtitle track. I could have used mkvpropedit to manually change each file but that&#8217;s such a hassle. Instead, here&#8217;s a bash script to do them all at once (You&#8217;ll need to tweak the highlighted rows accordingly):</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">OIFS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$IFS</span>&quot;</span>
<span style="color: #007800;">IFS</span>=$<span style="color: #ff0000;">'n'</span> 
<span style="display:block;background-color: #ffc;"><span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #ff0000;">&quot;/path/to/files/&quot;</span><span style="color: #000000; font-weight: bold;">*</span>.mkv</span><span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$file</span>
	<span style="color: #666666; font-style: italic;">#Update audio track defaults</span>
<span style="display:block;background-color: #ffc;">	mkvpropedit <span style="color: #ff0000;">&quot;<span style="color: #007800;">${file}</span>&quot;</span> <span style="color: #660033;">--edit</span> track:<span style="color: #000000;">2</span> <span style="color: #660033;">--set</span> flag-default=<span style="color: #000000;">0</span></span><span style="display:block;background-color: #ffc;">	mkvpropedit <span style="color: #ff0000;">&quot;<span style="color: #007800;">${file}</span>&quot;</span> <span style="color: #660033;">--edit</span> track:<span style="color: #000000;">3</span> <span style="color: #660033;">--set</span> flag-default=<span style="color: #000000;">1</span></span>	<span style="color: #666666; font-style: italic;">#Update subtitle track defaults</span>
<span style="display:block;background-color: #ffc;">	mkvpropedit <span style="color: #ff0000;">&quot;<span style="color: #007800;">${file}</span>&quot;</span> <span style="color: #660033;">--edit</span> track:<span style="color: #000000;">4</span> <span style="color: #660033;">--set</span> flag-default=<span style="color: #000000;">0</span></span><span style="display:block;background-color: #ffc;">	mkvpropedit <span style="color: #ff0000;">&quot;<span style="color: #007800;">${file}</span>&quot;</span> <span style="color: #660033;">--edit</span> track:<span style="color: #000000;">5</span> <span style="color: #660033;">--set</span> flag-default=<span style="color: #000000;">1</span></span><span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #007800;">IFS</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$OIFS</span>&quot;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>You&#8217;ll need <em>mkvtoolnix</em> installed for the <em><a href="http://manpages.ubuntu.com/manpages/natty/man1/mkvpropedit.1.html" title="Ubuntu Manpage: mkvinfo - Print information about tracks in Matroska files" target="_blank">mkvpropedit</a></em> command. To determine what the various tracks contain, do a</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">mkvinfo <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>file.mkv</pre></td></tr></table></div>
<!-- end from cahe -->
<p>or <em><a href="http://manpages.ubuntu.com/manpages/hardy/man1/mkvinfo.1.html" title="Ubuntu Manpage: mkvinfo - Print information about tracks in Matroska files" target="_blank">mkvinfo</a> -g</em> for you GUI users <img src='http://www.flynsarmy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>As an added bonus, here&#8217;s the Windows equivalent of this script:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">echo</span> off
FOR <span style="color: #000000; font-weight: bold;">/</span>f <span style="color: #ff0000;">&quot;tokens=*&quot;</span> <span style="color: #000000; font-weight: bold;">%%</span>G IN <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">'dir /a-d /b'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> DO <span style="color: #7a0874; font-weight: bold;">&#40;</span>
	mkvpropedit.exe <span style="color: #ff0000;">&quot;%%G&quot;</span> <span style="color: #660033;">--edit</span> track:<span style="color: #000000;">2</span> <span style="color: #660033;">--set</span> flag-default=<span style="color: #000000;">0</span>
	mkvpropedit.exe <span style="color: #ff0000;">&quot;%%G&quot;</span> <span style="color: #660033;">--edit</span> track:<span style="color: #000000;">3</span> <span style="color: #660033;">--set</span> flag-default=<span style="color: #000000;">0</span>
	mkvpropedit.exe <span style="color: #ff0000;">&quot;%%G&quot;</span> <span style="color: #660033;">--edit</span> track:<span style="color: #000000;">4</span> <span style="color: #660033;">--set</span> flag-default=<span style="color: #000000;">1</span>
	mkvpropedit.exe <span style="color: #ff0000;">&quot;%%G&quot;</span> <span style="color: #660033;">--edit</span> track:<span style="color: #000000;">5</span> <span style="color: #660033;">--set</span> flag-default=<span style="color: #000000;">0</span>
	echo.
<span style="color: #7a0874; font-weight: bold;">&#41;</span>
pause</pre></td></tr></table></div>
<!-- end from cahe -->
<p>I&#8217;ve been told the Windows version works but haven&#8217;t tested personally.</p>
<p>Happy viewing!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/01/change-default-languge-subtitles-in-mkv-files/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>LemonStand: Maximum function nesting level of &#8217;100&#8242; reached</title>
		<link>http://www.flynsarmy.com/2012/01/lemonstand-maximum-function-nesting-level-of-100-reached/</link>
		<comments>http://www.flynsarmy.com/2012/01/lemonstand-maximum-function-nesting-level-of-100-reached/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 07:24:51 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Lemonstand]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XDebug]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1082</guid>
		<description><![CDATA[Last night I was getting a strange error in LemonStand administration area when attempting to edit a product or category:
<blockquote>Fatal error: Maximum function nesting level of '100' reached, aborting! in /path/to/<wbr>phproad/modules/phpr/helpers/<wbr>phpr_inflector.php on line 322</wbr></wbr></blockquote>
If you're also experiencing this error, it's caused by <a href="http://xdebug.org/" title="Xdebug - Debugger and Profiler Tool for PHP" target="_blank">XDebug</a> and can be solved by adding
<pre lang="php" escaped="true" line="1">ini_set('xdebug.max_nesting_level', 200);</pre>
to your <em>config/config.php</em> file.

<em>Thanks to Aleksey Bobkov and EHLOVader for their help in solving this issue. <a href="http://forum.lemonstandapp.com/tracker/issue-34-fatal-error-in-shop-categories-list-when-nested-3-levels-down/" title="Fatal Error in Shop Categories list when nested 3+ levels down - LemonStand Forum" target="_blank">Here</a> is the official LemonStand forum thread on the issue.</em>]]></description>
				<content:encoded><![CDATA[<p>Last night I was getting a strange error in LemonStand administration area when attempting to edit a product or category:</p>
<blockquote><p>Fatal error: Maximum function nesting level of &#8217;100&#8242; reached, aborting! in /path/to/<wbr>phproad/modules/phpr/helpers/<wbr>phpr_inflector.php on line 322</wbr></wbr></p></blockquote>
<p>If you&#8217;re also experiencing this error, it&#8217;s caused by <a href="http://xdebug.org/" title="Xdebug - Debugger and Profiler Tool for PHP" target="_blank">XDebug</a> and can be solved by adding</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'xdebug.max_nesting_level'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">200</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>to your <em>config/config.php</em> file.</p>
<p><em>Thanks to Aleksey Bobkov and EHLOVader for their help in solving this issue. <a href="http://forum.lemonstandapp.com/tracker/issue-34-fatal-error-in-shop-categories-list-when-nested-3-levels-down/" title="Fatal Error in Shop Categories list when nested 3+ levels down - LemonStand Forum" target="_blank">Here</a> is the official LemonStand forum thread on the issue.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/01/lemonstand-maximum-function-nesting-level-of-100-reached/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Moving WordPress Multi-Site Between Servers</title>
		<link>http://www.flynsarmy.com/2012/01/moving-wordpress-multi-site-between-servers/</link>
		<comments>http://www.flynsarmy.com/2012/01/moving-wordpress-multi-site-between-servers/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 16:43:57 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[WPMU]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1068</guid>
		<description><![CDATA[Tonight I had to move my WPMU install from my local development machine to the live server - this meant a change in installation path which is always a hassle with WordPress. Below I'll detail my issues and the corresponding fixes in the hopes it will make life easier for others experiencing the same problems.
<h3>Redirection to wp-signup.php</h3>
First thing I noticed was that when loading the site on a live domain, I'd get instantly redirected to <em>mydomain.com/wp-signup.php?new=mydomain.com</em>. With a bit of Googling I came across <a href="http:/.org/support/topic/sub-domain-redirecting-to-wp-signupphp" title="WordPress &#62; Support &#62;&#62; sub domain redirecting to wp-signup.php" target="_blank">this forum thread</a> which recommended adding the following to my <em>wp-config.php</em>:
<pre lang="php" escaped="true" line="1">define( 'NOBLOGREDIRECT', '' );
define( 'SUBDOMAIN_INSTALL', false );</pre>
<strong>Don't do this!</strong> It will get the site closer to working order but it's not going to help you in the long run - especially when you need the other domains working too. Instead here's what you should be doing:
<pre lang="bash" escaped="true" line="1">#Dump your DB
mysqldump - u&#60;username&#62; -p&#60;password&#62; -h&#60;host&#62; &#60;dbname&#62; &#62; test.sql

#Update folder path to that of the new servers
sed -i "s/path\/to\/install/new\/path\/to\/install/g" test.sql 
#If you installed into localhost/foo/bar/mysite, change that to your live servers domain
sed -i "s/url\/path\/to\/site/www\.domain\.com/g" test.sql</pre>
This is pretty standard behavior for moving WordPress sites, however if you load the above dump up on your live domain you'll probably be greeted with the dreaded <em>Error establishing a database connection</em>.
<h3>Error establishing a database connection</h3>
Heading to <em>www.domain.com/wp-admin</em> will shed a little more light on the situation - you need to update your <strong>wp_blogs</strong> table for the main site. WPMU is currently using your development servers URL from this table and ignoring what's in <em>wp-config.php</em>. To play things safe we'll update any occurrances of our test servers domain in <em>test.sql</em>:
<pre lang="bash" escaped="true" line="1">#Update your live servers subdomain in wp_blogs to your live servers domain
sed -i  "s/yoursite\.localhost\.com/www\.yourdomain\.com/g" test.sql</pre>
This should do the trick. Load that bad boy into your live server and you should be good to go!]]></description>
				<content:encoded><![CDATA[<p>Tonight I had to move my WPMU install from my local development machine to the live server &#8211; this meant a change in installation path which is always a hassle with WordPress. Below I&#8217;ll detail my issues and the corresponding fixes in the hopes it will make life easier for others experiencing the same problems.</p>
<h3>Redirection to wp-signup.php</h3>
<p>First thing I noticed was that when loading the site on a live domain, I&#8217;d get instantly redirected to <em>mydomain.com/wp-signup.php?new=mydomain.com</em>. With a bit of Googling I came across <a href="http:/.org/support/topic/sub-domain-redirecting-to-wp-signupphp" title="WordPress &gt; Support &gt;&gt; sub domain redirecting to wp-signup.php" target="_blank">this forum thread</a> which recommended adding the following to my <em>wp-config.php</em>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'NOBLOGREDIRECT'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'SUBDOMAIN_INSTALL'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p><strong>Don&#8217;t do this!</strong> It will get the site closer to working order but it&#8217;s not going to help you in the long run &#8211; especially when you need the other domains working too. Instead here&#8217;s what you should be doing:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#Dump your DB</span>
mysqldump - u<span style="color: #000000; font-weight: bold;">&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;</span> -p<span style="color: #000000; font-weight: bold;">&lt;</span>password<span style="color: #000000; font-weight: bold;">&gt;</span> -h<span style="color: #000000; font-weight: bold;">&lt;</span>host<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>dbname<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> test.sql
&nbsp;
<span style="color: #666666; font-style: italic;">#Update folder path to that of the new servers</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">&quot;s/path/to/install/new/path/to/install/g&quot;</span> test.sql 
<span style="color: #666666; font-style: italic;">#If you installed into localhost/foo/bar/mysite, change that to your live servers domain</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">&quot;s/url/path/to/site/www.domain.com/g&quot;</span> test.sql</pre></td></tr></table></div>
<!-- end from cahe -->
<p>This is pretty standard behavior for moving WordPress sites, however if you load the above dump up on your live domain you&#8217;ll probably be greeted with the dreaded <em>Error establishing a database connection</em>.</p>
<h3>Error establishing a database connection</h3>
<p>Heading to <em>www.domain.com/wp-admin</em> will shed a little more light on the situation &#8211; you need to update your <strong>wp_blogs</strong> table for the main site. WPMU is currently using your development servers URL from this table and ignoring what&#8217;s in <em>wp-config.php</em>. To play things safe we&#8217;ll update any occurrances of our test servers domain in <em>test.sql</em>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#Update your live servers subdomain in wp_blogs to your live servers domain</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span>  <span style="color: #ff0000;">&quot;s/yoursite.localhost.com/www.yourdomain.com/g&quot;</span> test.sql</pre></td></tr></table></div>
<!-- end from cahe -->
<p>This should do the trick. Load that bad boy into your live server and you should be good to go!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/01/moving-wordpress-multi-site-between-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lower Heat/Power Consumption on Dell 15z in Ubuntu</title>
		<link>http://www.flynsarmy.com/2012/01/lower-heat-power-consumption-on-dell-15z-in-ubuntu/</link>
		<comments>http://www.flynsarmy.com/2012/01/lower-heat-power-consumption-on-dell-15z-in-ubuntu/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 14:12:43 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1049</guid>
		<description><![CDATA[For users not running Bumblebee or Ironhide, you've probably noticed alot of heat, low battery life and a roaring fan even when idle. This is almost entirely due to the nVidia graphics card. If you're like me and don't need that card at all, you have the option of disabling it entirely. To do so you'll need to install acpi_call as a kernel module and use it to shut the GPU down.

Read on for a tutorial on how. I've also included some bonus Intel GPU tweaks!]]></description>
				<content:encoded><![CDATA[<p>For users not running Bumblebee or Ironhide, you&#8217;ve probably noticed alot of heat, low battery life and a roaring fan even when idle. This is almost entirely due to the nVidia graphics card. If you&#8217;re like me and don&#8217;t need that card at all, you have the option of disabling it entirely. To do so you&#8217;ll need to install acpi_call as a kernel module and use it to shut the GPU down.</p>
<p><em><strong>Note:</strong> To test current power usage, when on battery use the following command:</em></p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">grep</span> rate <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>acpi<span style="color: #000000; font-weight: bold;">/</span>battery<span style="color: #000000; font-weight: bold;">/</span>BAT0<span style="color: #000000; font-weight: bold;">/</span>state</pre></td></tr></table></div>
<!-- end from cahe -->
<h3>Compiling and Installing acpi_call</h3>
<p>To quote <a href="http://hybrid-graphics-linux.tuxfamily.org/index.php?title=Acpi_call" title="Acpi call - Hybridgraphics" target="_blank">tuxfamily</a>:</p>
<blockquote style="font-style: normal;">
<ol>
<li>Install dkms and some useful packages:
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> dkms <span style="color: #c20cb9; font-weight: bold;">git</span> build-essential
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> linux-headers-$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></td></tr></table></div>
<!-- end from cahe -->
</li>
<li>Clone the acpi_call repository from git and copy it to where dkms will look for it. We&#8217;ll call it version 0.0.1 for now:and paste this into it and save it:
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git clone</span> http:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>mkottman<span style="color: #000000; font-weight: bold;">/</span>acpi_call.git
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>acpi_call-0.0.1
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-rp</span> acpi_call<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>acpi_call-0.0.1</pre></td></tr></table></div>
<!-- end from cahe -->
</li>
<li>Create a file dkms.conf for it:
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gedit <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>acpi_call-0.0.1<span style="color: #000000; font-weight: bold;">/</span>dkms.conf</pre></td></tr></table></div>
<!-- end from cahe -->
<p>and paste this into it and save it:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">PACKAGE_NAME</span>=<span style="color: #ff0000;">&quot;acpi_call&quot;</span>
<span style="color: #007800;">PACKAGE_VERSION</span>=<span style="color: #ff0000;">&quot;0.0.1&quot;</span>
<span style="color: #007800;">CLEAN</span>=<span style="color: #ff0000;">&quot;make clean&quot;</span>
BUILT_MODULE_NAME<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;acpi_call&quot;</span>
DEST_MODULE_NAME<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;acpi_call&quot;</span>
MAKE<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;make IGNORE_CC_MISMATCH=1 KDIR=<span style="color: #007800;">$kernel_source_dir</span> PWD=<span style="color: #007800;">$dkms_tree</span>/acpi_call/0.0.1/build&quot;</span>
DEST_MODULE_LOCATION<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #ff0000;">&quot;/kernel/drivers/acpi&quot;</span>
<span style="color: #007800;">AUTOINSTALL</span>=<span style="color: #ff0000;">&quot;yes&quot;</span></pre></td></tr></table></div>
<!-- end from cahe -->
</li>
<li>Edit the makefile
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> gedit <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>acpi_call-0.0.1<span style="color: #000000; font-weight: bold;">/</span>Makefile</pre></td></tr></table></div>
<!-- end from cahe -->
<p>and paste this into it and save it:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">obj-m := acpi_call.o
&nbsp;
default:
	$<span style="color: #7a0874; font-weight: bold;">&#40;</span>MAKE<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #660033;">-C</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span>KDIR<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">SUBDIRS</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>PWD<span style="color: #7a0874; font-weight: bold;">&#41;</span> modules
&nbsp;
clean:
	<span style="color: #c20cb9; font-weight: bold;">rm</span> acpi_call.mod.o acpi_call.o acpi_call.ko</pre></td></tr></table></div>
<!-- end from cahe -->
<p><em>Editors Note: Just replace the Makefile with the above</em></li>
<li>Add the module to dkms and build and install it:If all went well, you should now be able to load the module with:and this will give some information about it:
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> dkms add <span style="color: #660033;">-m</span> acpi_call <span style="color: #660033;">-v</span> 0.0.1
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dkms build <span style="color: #660033;">-m</span> acpi_call <span style="color: #660033;">-v</span> 0.0.1
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dkms <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #660033;">-m</span> acpi_call <span style="color: #660033;">-v</span> 0.0.1</pre></td></tr></table></div>
<!-- end from cahe -->
<p>If all went well, you should now be able to load the module with:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> modprobe acpi_call</pre></td></tr></table></div>
<!-- end from cahe -->
<p>and this will give some information about it:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">modinfo acpi_call</pre></td></tr></table></div>
<!-- end from cahe -->
</li>
</ol>
<p>Notes:</p>
<ul>
<li>The AUTOINSTALL=&#8221;yes&#8221; line in dkms.conf is supposed to tell dkms to automatically build and install the module if you upgrade the kernel, but if it doesn&#8217;t work you can manually execute the dkms build and install commands in the new kernel.</li>
</ul>
<ul>
<li>If you want to remove the module (eg from all kernels), do:
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> dkms remove <span style="color: #660033;">-m</span> acpi_call <span style="color: #660033;">-v</span> 0.0.1 <span style="color: #660033;">--all</span></pre></td></tr></table></div>
<!-- end from cahe -->
</li>
</ul>
</blockquote>
<h3>Disabling the nVidia GPU</h3>
<p>Acpi_call can now be used to shut down the GPU. We&#8217;ll create 2 files. One to turn the GPU off, and one to turn it back on again should you need to.</p>
<p>In ~/cardoff.sh add the following:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">modprobe acpi_call
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;_SB.PCI0.PEG0.PEGP._DSM {0xF8,0xD8,0x86,0xA4,0xDA,0x0B,0x1B,0x47,0xA7,0x2B,0x60,0x42,0xA6,0xB5,0xBE,0xE0} 0x100 0x1A {0x1,0x0,0x0,0x3}&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>acpi<span style="color: #000000; font-weight: bold;">/</span>call
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;_SB.PCI0.PEG0.PEGP._PS3&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>acpi<span style="color: #000000; font-weight: bold;">/</span>call</pre></td></tr></table></div>
<!-- end from cahe -->
<p>and in ~/cardon.sh:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">modprobe acpi_call
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;_SB.PCI0.PEG0.PEGP._PS0&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span>acpi<span style="color: #000000; font-weight: bold;">/</span>call</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Remember to add execute permissions to the 2 files:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x ~<span style="color: #000000; font-weight: bold;">/</span>cardon.sh ~<span style="color: #000000; font-weight: bold;">/</span>cardoff.sh</pre></td></tr></table></div>
<!-- end from cahe -->
<p>That should be all there is to it. You can now turn your GPU off with <em>sudo ~/cardoff.sh</em> and back on again with <em>sudo ~/cardon.sh</em>. Note that doing so will only affect that boot and you&#8217;ll need to do it again after a reboot. Also the above ACPI call works for my GPU but if you find it doesn&#8217;t work for yours try checking <a href="http://hybrid-graphics-linux.tuxfamily.org/index.php?title=ACPI_calls#Dell" title="ACPI calls - Hybridgraphics" target="_blank">here</a> for updated information.</p>
<p>To turn the card off automatically each boot add</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>username<span style="color: #000000; font-weight: bold;">/</span>cardoff.sh</pre></td></tr></table></div>
<!-- end from cahe -->
<p>to <em>/etc/rc.local</em>.</p>
<h3>Minor Intel GPU Tweaks</h3>
<p>There are a few GRUB options that can be applied for the Intel GPU to increase battery life. I&#8217;ve been using them for a couple of hours as of the time of writing and haven&#8217;t noticed any negative affects so I&#8217;ll quote them below:</p>
<blockquote>
<ol>
<li><strong>i915.i915_enable_rc6=1</strong> – RC6 was enabled by default for a while, but then it ended up being too buggy for some hardware configuration so it had to be disabled. For affected systems on the current code-base, enabling RC6 can cause GPU hangs. The Intel RC6 feature allows the GPU to enter a lower power state when the GPU is idling.</li>
<li><strong>i915.i915_enable_fbc=1</strong> – This kernel option enables FBC (frame-buffer compression) for the Intel graphics driver. Frame-buffer compression is not enabled by default since for some systems when frame-buffer compression is active there is a bug where the screen is not being properly repainted when using a compositing window manager. As implied by the name, frame-buffer compression will compress the buffer of what’s to be drawn to the screen so that less memory bandwidth is used on screen refreshes, and as a result, less memory being confused.</li>
<li><strong>i915.lvds_downclock=1</strong> – This kernel option will down-clock the LVDS refresh rate, which can increase power savings as a result. However, for systems that do not properly support LVDS down-clocking, the screen can begin to flicker during use.</li>
</ol>
</blockquote>
<p>&nbsp;</p>
<p>Add them to your <em>GRUB_CMDLINE_LINUX_DEFAULT</em> line in <em>/etc/default/grub</em>. Mine now looks like:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash pcie_aspm=force acpi=noirq i915.semaphores=1 i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1&quot;</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Remember to do an <em>update-grub</em> when you&#8217;re finished!</p>
<p>Thanks to user welfare of Ubuntu Forums for his posts in <a href="http://ubuntuforums.org/showthread.php?t=1776254" title="[ubuntu] XPS 15z Fail - Ubuntu Forums" target="_blank">this thread</a>.</p>
<h3>Other Tweaks</h3>
<p>Firstly and most importantly, all 15z users should already be familiar with this page but if you&#8217;re not the Ubuntu Wiki has <a href="https://wiki.ubuntu.com/HardwareSupport/Machines/Laptops/Dell/XPS/15z" title="HardwareSupport/Machines/Laptops/Dell/XPS/15z - Ubuntu Wiki" target="_blank">THE goto page</a> for information on getting the various hardware components of the 15z working. Check it out if you haven&#8217;t already. Topics include:</p>
<ul>
<li>Fixing black screen on installation issue</li>
<li>Using Bumblebee/Ironhide to get nVidia Optimus working</li>
<li>Getting the 9-in-1 card reader working (This one didn&#8217;t work for me but I left a message on the forum pointed to)</li>
<li>Getting the trackpad working</li>
<li>Various GRUB tweaks</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2012/01/lower-heat-power-consumption-on-dell-15z-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL FROM_UNIXTIME() With Negative Numbers</title>
		<link>http://www.flynsarmy.com/2011/12/mysql-from_unixtime-with-negative-numbers/</link>
		<comments>http://www.flynsarmy.com/2011/12/mysql-from_unixtime-with-negative-numbers/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 14:45:29 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1043</guid>
		<description><![CDATA[MySQL's built in <a href="http://www.totalchoicehosting.com/forums/index.php?showtopic=29666" title="MySQL ::   MySQL 5.5 Reference Manual :: 11.7 Date and Time Functions" target="_blank">FROM_UNIXTIME()</a> function only handles positive numbers however we can still convert negative integers to dates using its handy <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add" title="MySQL ::   MySQL 5.5 Reference Manual :: 11.7 Date and Time Functions" target="_blank">DATE_ADD()</a> function like so:
<pre lang="sql" line="1" escaped="true">SELECT DATE_ADD(FROM_UNIXTIME(0), INTERVAL -13391999 SECOND)</pre>
which gives:
<pre lang="text" line="1" escaped="true">1969-07-30 10:00:01</pre>
Note that this also works with positive numbers, so if your database contains a mixture of both it's still safe to use.

Credit to user <em>fat_kid</em> for his tutorial <a href="http://www.totalchoicehosting.com/forums/index.php?showtopic=29666&#38;view=findpost&#38;p=239035" title="Mysql Query With From_unixtime - TotalChoice Hosting Family Forums" target="_blank">here</a>.]]></description>
				<content:encoded><![CDATA[<p>MySQL&#8217;s built in <a href="http://www.totalchoicehosting.com/forums/index.php?showtopic=29666" title="MySQL ::   MySQL 5.5 Reference Manual :: 11.7 Date and Time Functions" target="_blank">FROM_UNIXTIME()</a> function only handles positive numbers however we can still convert negative integers to dates using its handy <a href="http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add" title="MySQL ::   MySQL 5.5 Reference Manual :: 11.7 Date and Time Functions" target="_blank">DATE_ADD()</a> function like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> DATE_ADD<span style="color: #66cc66;">&#40;</span>FROM_UNIXTIME<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #993333; font-weight: bold;">INTERVAL</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">13391999</span> <span style="color: #993333; font-weight: bold;">SECOND</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>which gives:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="text" style="font-family:monospace;">1969-07-30 10:00:01</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Note that this also works with positive numbers, so if your database contains a mixture of both it&#8217;s still safe to use.</p>
<p>Credit to user <em>fat_kid</em> for his tutorial <a href="http://www.totalchoicehosting.com/forums/index.php?showtopic=29666&amp;view=findpost&amp;p=239035" title="Mysql Query With From_unixtime - TotalChoice Hosting Family Forums" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/12/mysql-from_unixtime-with-negative-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UCFirst Function for MySQL</title>
		<link>http://www.flynsarmy.com/2011/12/ucfirst-function-for-mysql/</link>
		<comments>http://www.flynsarmy.com/2011/12/ucfirst-function-for-mysql/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 02:16:15 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[ucfirst]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=1040</guid>
		<description><![CDATA[Without any adieu what-so-ever, below is a MySQL implementation of PHP's <a href="http://php.net/ucfirst" title="PHP: ucfirst - Manual" target="_blank">ucfirst</a> function which capitalizes the first letter of each word in a string.
<pre lang="sql" line="1" escaped="true">DELIMITER $$
CREATE FUNCTION CAP_FIRST (input VARCHAR(255))

RETURNS VARCHAR(255)

DETERMINISTIC

BEGIN
    DECLARE len INT;
    DECLARE i INT;

    SET len   = CHAR_LENGTH(input);
    SET input = LOWER(input);
    SET i = 0;

    WHILE (i &#60; len) DO
        IF (MID(input,i,1) = ' ' OR i = 0) THEN
            IF (i &#60; len) THEN
                SET input = CONCAT(
                    LEFT(input,i),
                    UPPER(MID(input,i + 1,1)),
                    RIGHT(input,len - i - 1)
                );
            END IF;
        END IF;
        SET i = i + 1;
    END WHILE;

    RETURN input;
END$$
DELIMITER ;</pre>
Use it like so:
<pre lang="mysql" line="1" escaped="true">SELECT CAP_FIRST('my string of words');</pre>
and you should get:
<pre lang="text" escaped="true">My String Of Words</pre>
All credit and many thanks for this function to <a href="http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/" title="MySQL Capitalize Function" target="_blank">Joezack</a>.]]></description>
				<content:encoded><![CDATA[<p>Without any adieu what-so-ever, below is a MySQL implementation of PHP&#8217;s <a href="http://php.net/ucfirst" title="PHP: ucfirst - Manual" target="_blank">ucfirst</a> function which capitalizes the first letter of each word in a string.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;">DELIMITER $$
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">FUNCTION</span> CAP_FIRST <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">INPUT</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #993333; font-weight: bold;">RETURNS</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
DETERMINISTIC
&nbsp;
<span style="color: #993333; font-weight: bold;">BEGIN</span>
    <span style="color: #993333; font-weight: bold;">DECLARE</span> len <span style="color: #993333; font-weight: bold;">INT</span>;
    <span style="color: #993333; font-weight: bold;">DECLARE</span> i <span style="color: #993333; font-weight: bold;">INT</span>;
&nbsp;
    <span style="color: #993333; font-weight: bold;">SET</span> len   <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">CHAR_LENGTH</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">INPUT</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #993333; font-weight: bold;">INPUT</span> <span style="color: #66cc66;">=</span> <span style="color: #993333; font-weight: bold;">LOWER</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">INPUT</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #993333; font-weight: bold;">SET</span> i <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span>;
&nbsp;
    WHILE <span style="color: #66cc66;">&#40;</span>i <span style="color: #66cc66;">&lt;</span> len<span style="color: #66cc66;">&#41;</span> DO
        <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>MID<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">INPUT</span><span style="color: #66cc66;">,</span>i<span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">' '</span> <span style="color: #993333; font-weight: bold;">OR</span> i <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">THEN</span>
            <span style="color: #993333; font-weight: bold;">IF</span> <span style="color: #66cc66;">&#40;</span>i <span style="color: #66cc66;">&lt;</span> len<span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">THEN</span>
                <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #993333; font-weight: bold;">INPUT</span> <span style="color: #66cc66;">=</span> CONCAT<span style="color: #66cc66;">&#40;</span>
                    <span style="color: #993333; font-weight: bold;">LEFT</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">INPUT</span><span style="color: #66cc66;">,</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
                    <span style="color: #993333; font-weight: bold;">UPPER</span><span style="color: #66cc66;">&#40;</span>MID<span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">INPUT</span><span style="color: #66cc66;">,</span>i <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">,</span>
                    <span style="color: #993333; font-weight: bold;">RIGHT</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">INPUT</span><span style="color: #66cc66;">,</span>len <span style="color: #66cc66;">-</span> i <span style="color: #66cc66;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>
                <span style="color: #66cc66;">&#41;</span>;
            <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">IF</span>;
        <span style="color: #993333; font-weight: bold;">END</span> <span style="color: #993333; font-weight: bold;">IF</span>;
        <span style="color: #993333; font-weight: bold;">SET</span> i <span style="color: #66cc66;">=</span> i <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span>;
    <span style="color: #993333; font-weight: bold;">END</span> WHILE;
&nbsp;
    <span style="color: #993333; font-weight: bold;">RETURN</span> <span style="color: #993333; font-weight: bold;">INPUT</span>;
<span style="color: #993333; font-weight: bold;">END</span>$$
DELIMITER ;</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Use it like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SELECT</span> CAP_FIRST<span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">'my string of words'</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>and you should get:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">My String Of Words</pre></td></tr></table></div>
<!-- end from cahe -->
<p>All credit and many thanks for this function to <a href="http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/" title="MySQL Capitalize Function" target="_blank">Joezack</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/12/ucfirst-function-for-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How To Save Custom Filter State with JQuery Data Tables</title>
		<link>http://www.flynsarmy.com/2011/12/save-custom-filter-state-jquery-data-tables/</link>
		<comments>http://www.flynsarmy.com/2011/12/save-custom-filter-state-jquery-data-tables/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 09:43:49 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Custom Filters]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JQuery Data Tables]]></category>
		<category><![CDATA[JQuery UI]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=989</guid>
		<description><![CDATA[<a href="http://datatables.net/" title="DataTables (table plug-in for jQuery)" target="_blank">JQuery Data Tables</a> is an incredibly handy tool that can make a developers life alot easier - notably by handling search, pagination, filtering and sorting for you. The default functionality is very good, however you'll often need a bit of customization. This post will detail how to add custom filters and position them to nicely theme with your table. The filters' state will also be saved so they'll still be there if you reload the page.

You can see the demo page for this post <a href="http://www.flynsarmy.com/examples/datatables_custom_filters/" title="Filtered JQuery Data Tables with State Saving" target="_blank">here</a>. Select a filter and reload the page to see it in action.]]></description>
				<content:encoded><![CDATA[<p><a href="http://datatables.net/" title="DataTables (table plug-in for jQuery)" target="_blank">JQuery Data Tables</a> is an incredibly handy tool that can make a developers life alot easier &#8211; notably by handling search, pagination, filtering and sorting for you. The default functionality is very good, however you&#8217;ll often need a bit of customization. This post will detail how to add custom filters and position them to nicely theme with your table. The filters&#8217; state will also be saved so they&#8217;ll still be there if you reload the page.</p>
<p>Here&#8217;s the final product (Select a filter and reload the page to test state saving):<br />
<iframe width="100%" height="310" src="http://www.flynsarmy.com/examples/datatables_custom_filters"></iframe></p>
<h3>Flash of Unstyled Content</h3>
<p>The default dataTables setup results in whats called a &#8216;flash of unstyled content&#8217;. This is where upon loading the page you&#8217;ll see the HTML table for a split second before it turns into the JQuery Data Table. This is very jarring and looks unprofessional. My quick solution to this problem is to simply hide the table until it&#8217;s time to be displayed using some simple CSS and the <a href="http://datatables.net/usage/callbacks#fnDrawCallback" target="_blank" title="DataTables - Usage">fnDrawCallback</a> callback. Note that I&#8217;ve given my table a class of <em>dtable</em>.</p>
<p>CSS:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.dtable</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>JS:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dtable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dataTable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">&quot;fnDrawCallback&quot;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>HTML:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'100%'</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'dtable'</span> <span style="color: #000066;">cellspacing</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'0'</span> <span style="color: #000066;">cellpadding</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'0'</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Name<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Gender<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">th</span>&gt;</span>Favourite Colour<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">th</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">thead</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Jeremy Smith<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Male<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Red<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Anita Hanson<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Female<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Orange<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Tim Burchall<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Male<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Orange<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Arnold Tamzarian<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Male<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Green<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Lisa Douglas<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Female<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Orange<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Mark Feeney<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Male<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Green<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Jessica Nicholson<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Female<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Red<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Jessica Williams<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Female<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Red<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Mia Huffson<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Female<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Green<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Jeremiah Evans<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Male<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Red<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tbody</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<h3>Adding the Filters</h3>
<p>I&#8217;ll be making 2 custom filters; one for <em>gender</em> and one for <em>favourite colour</em> which return any matching row in the table upon selection. You can make more complicated filters using the below code if you wish, this is only an example.</p>
<p>HTML (To be placed just before the &lt;table&gt; tag):</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'dtable_custom_controls'</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'dataTables_wrapper'</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'ui-toolbar'</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'dataTables_length'</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'cust_filter_gender'</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'dtable_filter'</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">''</span>&gt;</span>Gender<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Male'</span>&gt;</span>Male<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Female'</span>&gt;</span>Female<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
&nbsp;
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'cust_filter_colour'</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'dtable_filter'</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">''</span>&gt;</span>Colour<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Green'</span>&gt;</span>Green<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Orange'</span>&gt;</span>Orange<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
					<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Red'</span>&gt;</span>Red<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>This snippet contains our two drop down lists encapsulated within the standard data tables&#8217; header wrappers so that we get some nice theming/element sizing going on. It&#8217;ll currently be sitting above the table, but with a touch of CSS we can position it inside the header:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.dtable</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">&#125;</span>
<span style="display:block;background-color: #ffc;"><span style="color: #6666ff;">.dtable_custom_controls</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">50</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">150px</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span><span style="color: #00AA00;">&#125;</span></span><span style="display:block;background-color: #ffc;"><span style="color: #6666ff;">.dtable_custom_controls</span> <span style="color: #6666ff;">.dataTables_length</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span><span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">&#125;</span></span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Let&#8217;s also update our javascript to make this thing a bit prettier:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">&quot;sDom&quot;</span>			<span style="color: #339933;">:</span> <span style="color: #3366CC;">'R&lt;&quot;H&quot;lfr&gt;t&lt;&quot;F&quot;ip&lt;'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;bProcessing&quot;</span>		<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;bJQueryUI&quot;</span>		<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;bStateSave&quot;</span>		<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;iDisplayLength&quot;</span> 	<span style="color: #339933;">:</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;aLengthMenu&quot;</span> 		<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">8</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">8</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;All&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;sPaginationType&quot;</span>	<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;full_numbers&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;aaSorting&quot;</span> 		<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;asc&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;fnDrawCallback&quot;</span>	<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//Without the CSS call, the table occasionally appears a little too wide</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'100%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">//Don't show the filters until the table is showing</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dataTables_wrapper'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prevAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dtable_custom_controls'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">var</span> oTable <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dtable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dataTable</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Now we need to actually make them do something. This is where <a href="http://datatables.net/usage/callbacks#fnStateSaveCallback" target="_blank" title="DataTables - Usage">fnStateSaveCallback</a> and <a href="http://datatables.net/usage/callbacks#fnStateLoadCallback" title="DataTables - Usage" target="_blank">fnStateLoadCallback</a> come in. The final script:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">/*
	 * Find and assign actions to filters
	 */</span>
	$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">dataTableExt</span>.<span style="color: #660066;">afnFiltering</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">new</span> <span style="">Array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">var</span> oControls <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dtable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prevAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dtable_custom_controls:first'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':input[name]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	oControls.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">var</span> oControl <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//Add custom filters</span>
		$.<span style="color: #660066;">fn</span>.<span style="color: #660066;">dataTableExt</span>.<span style="color: #660066;">afnFiltering</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> oSettings<span style="color: #339933;">,</span> aData<span style="color: #339933;">,</span> iDataIndex <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>oControl.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>oControl.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'dtable_filter'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>aData.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> aData<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>oControl.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #009900;">&#41;</span>
					<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	options <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">&quot;sDom&quot;</span>				<span style="color: #339933;">:</span> <span style="color: #3366CC;">'R&lt;&quot;H&quot;lfr&gt;t&lt;&quot;F&quot;ip&lt;'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;bProcessing&quot;</span>		<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;bJQueryUI&quot;</span>		<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;bStateSave&quot;</span>		<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;iDisplayLength&quot;</span>	<span style="color: #339933;">:</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;aLengthMenu&quot;</span>		<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">8</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">8</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">25</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;All&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;sPaginationType&quot;</span>	<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;full_numbers&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;aaSorting&quot;</span>			<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;asc&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;fnDrawCallback&quot;</span>	<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//Without the CSS call, the table occasionally appears a little too wide</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'width'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'100%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">//Don't show the filters until the table is showing</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dataTables_wrapper'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prevAll</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dtable_custom_controls'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;fnStateSaveCallback&quot;</span><span style="color: #339933;">:</span> 	<span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span> oSettings<span style="color: #339933;">,</span> sValue <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//Save custom filters</span>
			oControls.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
					sValue <span style="color: #339933;">+=</span> <span style="color: #3366CC;">',&quot;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;: &quot;'</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&quot;'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">&quot;</span>'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> sValue<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;fnStateLoadCallback&quot;</span>	<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span> oSettings<span style="color: #339933;">,</span> oData <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//Load custom filters</span>
			oControls.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">var</span> oControl <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				$.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>oData<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> index <span style="color: #339933;">==</span> oControl.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'name'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
						oControl.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span> value <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">var</span> oTable <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dtable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dataTable</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/*
	 * Trigger the filters when the user interacts with them
	 */</span>
	oControls.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">change</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">//Redraw to apply filters</span>
			oTable.<span style="color: #660066;">fnDraw</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>I won&#8217;t go over the above code as it should be pretty easy to figure out from the JS comments, however it&#8217;s worth mentioning that I&#8217;ve only set it up in such a way that you&#8217;ll be able to place 1 filtered table on each page. If you require more than one you&#8217;ll need to tweak the javascript a little.</p>
<p>The demo page for this post can be found <a href="http://www.flynsarmy.com/examples/datatables_custom_filters/" title="Filtered JQuery Data Tables with State Saving" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/12/save-custom-filter-state-jquery-data-tables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8216;fuser&#8217; Using 100% CPU in Ubuntu 11.10</title>
		<link>http://www.flynsarmy.com/2011/11/fuser-using-100-cpu-in-ubuntu-11-10/</link>
		<comments>http://www.flynsarmy.com/2011/11/fuser-using-100-cpu-in-ubuntu-11-10/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 16:56:13 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[crontab]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=974</guid>
		<description><![CDATA[After upgrading to 11.10 recently, I occasionally noticed <a href="http://en.wikipedia.org/wiki/Fuser_(Unix)" title="fuser (Unix) - Wikipedia, the free encyclopedia" target="_blank">fuser</a> firing up and using between 70% and astoundingly 9999% CPU. Googling the issue led me to <a href="http://ubuntuforums.org/showthread.php?p=11456671" title="[ubuntu] Fuser high CPU usage - Ubuntu Forums" target="_blank">this post</a> with the solution.

As user grazer explains:
<blockquote>We have the same problem. This is the content of <em>/etc/cron.d/php5</em> on 11.10:
<pre lang="text">09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] &#38;&#38; [ -d /var/lib/php5 ] &#38;&#38; find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2&#62;/dev/null \; -delete</pre>
And this is the content on 11.04:
<pre lang="text">09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] &#38;&#38; [ -d /var/lib/php5 ] &#38;&#38; find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete</pre>
Spot the difference?

The 11.10 version runs fuser for each PHP session file, thus using all the CPU when there are hundreds of sessions.</blockquote>
After commenting out the 11.10 line and replacing with the 11.04 equivalent, this problem was solved for me aswell. Thanks, grazer!

You can also check out the <a href="https://bugs.launchpad.net/ubuntu/+source/php5/+bug/877894" title="Bug #877894 in php5 (Ubuntu): “fuser forks and never reaps its children”" target="_blank">bug report</a> to keep up to date on this issue. Hopefully a fix will be released quickly.]]></description>
				<content:encoded><![CDATA[<p>After upgrading to 11.10 recently, I occasionally noticed <a href="http://en.wikipedia.org/wiki/Fuser_(Unix)" title="fuser (Unix) - Wikipedia, the free encyclopedia" target="_blank">fuser</a> firing up and using between 70% and astoundingly 9999% CPU. Googling the issue led me to <a href="http://ubuntuforums.org/showthread.php?p=11456671" title="[ubuntu] Fuser high CPU usage - Ubuntu Forums" target="_blank">this post</a> with the solution.</p>
<p>As user grazer explains:</p>
<blockquote><p>We have the same problem. This is the content of <em>/etc/cron.d/php5</em> on 11.10:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] &amp;amp;&amp;amp; [ -d /var/lib/php5 ] &amp;amp;&amp;amp; find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) ! -execdir fuser -s {} 2&amp;gt;/dev/null ; -delete</pre></td></tr></table></div>
<!-- end from cahe -->
<p>And this is the content on 11.04:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] &amp;amp;&amp;amp; [ -d /var/lib/php5 ] &amp;amp;&amp;amp; find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Spot the difference?</p>
<p>The 11.10 version runs fuser for each PHP session file, thus using all the CPU when there are hundreds of sessions.</p></blockquote>
<p>After commenting out the 11.10 line and replacing with the 11.04 equivalent, this problem was solved for me aswell. Thanks, grazer!</p>
<p>You can also check out the <a href="https://bugs.launchpad.net/ubuntu/+source/php5/+bug/877894" title="Bug #877894 in php5 (Ubuntu): “fuser forks and never reaps its children”" target="_blank">bug report</a> to keep up to date on this issue. Hopefully a fix will be released quickly.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/11/fuser-using-100-cpu-in-ubuntu-11-10/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Getting Module AJAX Events Working in the Front End in LemonStand</title>
		<link>http://www.flynsarmy.com/2011/11/getting-module-ajax-events-working-in-the-front-end-in-lemonstand/</link>
		<comments>http://www.flynsarmy.com/2011/11/getting-module-ajax-events-working-in-the-front-end-in-lemonstand/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 12:02:55 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Lemonstand]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=939</guid>
		<description><![CDATA[I had a bit of an issue with this and the documentation wasn't of much help so I thought I'd post about the process. I currently have <a href="http://lemonstandapp.com/marketplace/module/flynsarmycampaignmonitor/" title="LemonStand - Campaign Monitor" target="_blank">CampaignMonitor</a> and <a href="http://lemonstandapp.com/marketplace/module/flynsarmymailchimp/" title="LemonStand - MailChimp" target="_blank">MailChimp</a> modules in the LemonStand marketplace and wanted to allow customers to create subscription forms on their sites that AJAX submit.

Firstly, <a href="http://lemonstandapp.com/docs/handling_lemonstand_events/" title="LemonStand - Handling LemonStand events" target="_blank">here</a> is the documentation page on custom events. The docs show that you need two things:
<ul>
	<li>A <em>subscribeEvents()</em> method in your module's setup class containing an <em>addEvent()</em> call.</li>
	<li>A method containing the code you want to execute, which will be triggered by your event.</li>
</ul>
I attempted to do the above with the following backend code:
<pre lang="php" escaped="true" line="1">&#60;?php
class MyModule_Module extends Core_ModuleBase
{
	public function subscribeEvents()
	{
		Backend::$events-&#62;addEvent('MyModule_Module:onSubmit', $this, 'on_submit');
	}

	public function onSubmit()
	{
		//...
	}
}</pre>
And frontend code:
<pre lang="html4strict" escaped="true" line="1">&#60;form onsubmit="return $(this).sendRequest('MyModule_Module:onSubmit')" action="/" method="post"&#62;
	&#60;input type='submit' name='submit' value='Submit' /&#62;
&#60;/form&#62;</pre>
I submitted the form and was greeted with an error message:
<blockquote>An AJAX error occurred: AJAX handler not found.</blockquote>
After a little digging I came across the function excuted when you perform an AJAX query. Important lines are highlighted:
<pre lang="php" escaped="true" line="1" highlight="7,12">public static function execAjaxHandler($name, $controller)
{
	$parts = explode(':', $name);
	if (count($parts) != 2)
		throw new Phpr_ApplicationException("Invalid event handler identifier: $name");

	$className = ucfirst($parts[0]).'_Actions';
	if (!Phpr::$classLoader-&#62;load($className))
		throw new Phpr_ApplicationException("Actions scope class is not found: $className");

	$method = $parts[1];
	$isEventHandler = preg_match('/^on_/', $method);
	if (!$isEventHandler)
		throw new Phpr_ApplicationException("Specified method is not AJAX event handler: $method");

	$obj = new $className();
	if (!method_exists($obj, $method))
		throw new Phpr_ApplicationException("AJAX handler not found: $name");

	$obj-&#62;copy_context_from($controller);
	try
	{
		$result = $obj-&#62;$method();
		$controller-&#62;copy_context_from($obj);
		return $result;
	}
	catch (Exception $ex)
	{
		$controller-&#62;copy_context_from($obj);
		throw $ex;
	}
}</pre>
There's a couple of things to note here.
<ul>
	<li>Your second and third arguments in <em>addEvent()</em> are ignored.</li>
	<li><em>_Actions</em> is concatenated onto the end of your class name</li>
	<li>Your method name must start with <em>on_</em></li>
</ul>
With the above in mind, it's time for some rewriting:
<pre lang="php" escaped="true" line="1">&#60;?php

class MyModule_Module extends Core_ModuleBase
{
	public function subscribeEvents()
	{
		Backend::$events-&#62;addEvent('MyModule:on_submit', $this, 'on_submit');
	}
}

class MyModule_Actions extends Cms_ActionScope
{
	public function on_submit()
	{
		//...
	}
}</pre>
That worked like a charm. Good luck to all the module developers for LS out there - I've found LemonStand a number of quirks like this and we'll just have to tackle them one at a time :)]]></description>
				<content:encoded><![CDATA[<p>I had a bit of an issue with this and the documentation wasn&#8217;t of much help so I thought I&#8217;d post about the process. I currently have <a href="http://lemonstandapp.com/marketplace/module/flynsarmycampaignmonitor/" title="LemonStand - Campaign Monitor" target="_blank">CampaignMonitor</a> and <a href="http://lemonstandapp.com/marketplace/module/flynsarmymailchimp/" title="LemonStand - MailChimp" target="_blank">MailChimp</a> modules in the LemonStand marketplace and wanted to allow customers to create subscription forms on their sites that AJAX submit.</p>
<p>Firstly, <a href="http://lemonstandapp.com/docs/handling_lemonstand_events/" title="LemonStand - Handling LemonStand events" target="_blank">here</a> is the documentation page on custom events. The docs show that you need two things:</p>
<ul>
<li>A <em>subscribeEvents()</em> method in your module&#8217;s setup class containing an <em>addEvent()</em> call.</li>
<li>A method containing the code you want to execute, which will be triggered by your event.</li>
</ul>
<p>I attempted to do the above with the following backend code:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> MyModule_Module <span style="color: #000000; font-weight: bold;">extends</span> Core_ModuleBase
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> subscribeEvents<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		Backend<span style="color: #339933;">::</span><span style="color: #000088;">$events</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MyModule_Module:onSubmit'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'on_submit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> onSubmit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//...</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>And frontend code:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">onsubmit</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;return $(this).sendRequest('MyModule_Module:onSubmit')&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'submit'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'submit'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Submit'</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>I submitted the form and was greeted with an error message:</p>
<blockquote><p>An AJAX error occurred: AJAX handler not found.</p></blockquote>
<p>After a little digging I came across the function excuted when you perform an AJAX query. Important lines are highlighted:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> execAjaxHandler<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$controller</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$parts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parts</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Phpr_ApplicationException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Invalid event handler identifier: <span style="color: #006699; font-weight: bold;">$name</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="display:block;background-color: #ffc;">	<span style="color: #000088;">$className</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ucfirst</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$parts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'_Actions'</span><span style="color: #339933;">;</span></span>	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Phpr<span style="color: #339933;">::</span><span style="color: #000088;">$classLoader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Phpr_ApplicationException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Actions scope class is not found: <span style="color: #006699; font-weight: bold;">$className</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$parts</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="display:block;background-color: #ffc;">	<span style="color: #000088;">$isEventHandler</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/^on_/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span>	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$isEventHandler</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Phpr_ApplicationException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Specified method is not AJAX event handler: <span style="color: #006699; font-weight: bold;">$method</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000088;">$className</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Phpr_ApplicationException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;AJAX handler not found: <span style="color: #006699; font-weight: bold;">$name</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">copy_context_from</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$controller</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	try
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">copy_context_from</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$ex</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$controller</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">copy_context_from</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">throw</span> <span style="color: #000088;">$ex</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>There&#8217;s a couple of things to note here.</p>
<ul>
<li>Your second and third arguments in <em>addEvent()</em> are ignored.</li>
<li><em>_Actions</em> is concatenated onto the end of your class name</li>
<li>Your method name must start with <em>on_</em></li>
</ul>
<p>With the above in mind, it&#8217;s time for some rewriting:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyModule_Module <span style="color: #000000; font-weight: bold;">extends</span> Core_ModuleBase
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> subscribeEvents<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		Backend<span style="color: #339933;">::</span><span style="color: #000088;">$events</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'MyModule:on_submit'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'on_submit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> MyModule_Actions <span style="color: #000000; font-weight: bold;">extends</span> Cms_ActionScope
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> on_submit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//...</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>That worked like a charm. Good luck to all the module developers for LS out there &#8211; I&#8217;ve found LemonStand a number of quirks like this and we&#8217;ll just have to tackle them one at a time <img src='http://www.flynsarmy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/11/getting-module-ajax-events-working-in-the-front-end-in-lemonstand/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Make Ubuntu 11.10 More Usable</title>
		<link>http://www.flynsarmy.com/2011/11/how-to-make-ubuntu-11-10-more-usable/</link>
		<comments>http://www.flynsarmy.com/2011/11/how-to-make-ubuntu-11-10-more-usable/#comments</comments>
		<pubDate>Sun, 06 Nov 2011 15:35:57 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Gnome Classic]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Ubuntu 11.10]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=902</guid>
		<description><![CDATA[Note: Also see the prequel to this post: <a href="http://www.flynsarmy.com/2011/04/why-i-hate-unity/" title="Why I Hate Unity &#124; Flynsarmy">Why I Hate Unity</a>

As your typical Ubuntu user, I find Unity infuriating and have devoted countless hours towards bringing back the usability and functionality that came with Gnome 2. I've racked up quite a few tweaks so far that have gone a long way towards doing this and figured it was about time to share them. My aim was to make 11.10 look and feel exactly like 10.10. I've attached below a screenshot of the final result.
<div><dl id="attachment_913" class="wp-caption aligncenter" style="width: 310px;"><dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/11.10-gnome-fallback.jpg"><img class="size-medium wp-image-913" title="11.10 with Gnome Session Fallback" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/11.10-gnome-fallback-300x187.jpg" alt="11.10 with Gnome Session Fallback" width="300" height="187" /></a></dt><dd class="wp-caption-dd">11.10 with Gnome Session Fallback</dd></dl></div>]]></description>
				<content:encoded><![CDATA[<p>Note: Also see the prequel to this post: <a href="http://www.flynsarmy.com/2011/04/why-i-hate-unity/" title="Why I Hate Unity | Flynsarmy">Why I Hate Unity</a></p>
<p>As your typical Ubuntu user, I find Unity infuriating and have devoted countless hours towards bringing back the usability and functionality that came with Gnome 2. I&#8217;ve racked up quite a few tweaks so far that have gone a long way towards doing this and figured it was about time to share them. My aim was to make 11.10 look and feel exactly like 10.10. I&#8217;ve attached below a screenshot of the final result.</p>
<div>
<dl id="attachment_913" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/11.10-gnome-fallback.jpg"><img class="size-medium wp-image-913" title="11.10 with Gnome Session Fallback" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/11.10-gnome-fallback-300x187.jpg" alt="11.10 with Gnome Session Fallback" width="300" height="187" /></a></dt>
<dd class="wp-caption-dd">11.10 with Gnome Session Fallback</dd>
</dl>
</div>
<p>Let&#8217;s get into it.</p>
<h3>Switch to a Gnome-2 like UI</h3>
<p>This ones the biggest and most obvious change. It gets us 90% towards where we want to go. Once installed, log out and select <em>Gnome Classic</em>. Remember you can add or remove widgets from your panels by holding <em>alt</em> while right clicking on the panel.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> gnome-session-fallback</pre></td></tr></table></div>
<!-- end from cahe -->
<div>
<dl id="attachment_912" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/gnome-classic.jpg"><img class="size-medium wp-image-912" title="Use Gnome Classic" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/gnome-classic-300x225.jpg" alt="Use Gnome Classic" width="300" height="225" /></a></dt>
<dd class="wp-caption-dd">Use Gnome Classic for a much more usable UI</dd>
</dl>
</div>
<p>&nbsp;</p>
<h3>Classic Run menu</h3>
<p>In Unity I can no longer type /hom&lt;tab&gt;/us&lt;tab&gt;/Pic&lt;tab&gt;/wal&lt;tab&gt; etc to quickly navigate to a folder of my choice. I use this feature all the time and it was a great pain in the ass to not have it present in 10.10.</p>
<p>In <em>Applications -&gt; System Tools -&gt; System Settings -&gt; Shortcuts -&gt; System</em> set <em>Show the Run Command Prompt</em> to Alt+F2</p>
<div>
<dl id="attachment_906" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/Show-the-run-command-prompt.png"><img class="size-medium wp-image-906" title="Show the run command prompt" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/Show-the-run-command-prompt-300x193.png" alt="Show the run command prompt" width="300" height="193" /></a></dt>
<dd class="wp-caption-dd">Pick a shortcut for the run menu</dd>
</dl>
</div>
<div>
<dl id="attachment_907" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/Classic-run-menu.png"><img class="size-medium wp-image-907" title="Classic run menu" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/Classic-run-menu-300x122.png" alt="Classic run menu" width="300" height="122" /></a></dt>
<dd class="wp-caption-dd">Classic run menu</dd>
</dl>
</div>
<p>&nbsp;</p>
<h3>Show Address/Path by Default in Nautilus</h3>
<p>As a matter of taste I prefer path text to the breadcrumb buttons. You can return them to the way they used to be like so:</p>
<p>In dconf-editor navigate to <em>org -&gt; gnome -&gt; nautilus -&gt; preferences</em> and set <em>always-use-location-entry</em> to true. If you&#8217;re on an older version of Ubuntu you can do the same in gconf-editor by enabling <i>apps -&gt; nautilus -&gt; preferences -&gt; always_use_location_entry</i></p>
<div class="mceTemp mceIEcenter" draggable="">
<dl id="attachment_966" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/nautilus_always_use_location_entry_dconf.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2011/11/nautilus_always_use_location_entry_dconf-300x257.png" alt="" title="Always Use Location Entry (11.10)" width="300" height="257" class="size-medium wp-image-966" /></a></dt>
<dd class="wp-caption-dd">Set this to true (11.10+)</dd>
</dl>
</div>
<div class="mceTemp mceIEcenter" draggable="">
<dl id="attachment_965" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/nautilus_always_use_location_entry.png"><img src="http://www.flynsarmy.com/wp-content/uploads/2011/11/nautilus_always_use_location_entry-300x247.png" alt="Set this to true (11.10)" title="Always use location entry" width="300" height="247" class="size-medium wp-image-965" /></a></dt>
<dd class="wp-caption-dd">Set this to true (11.04-)</dd>
</dl>
</div>
<p>&nbsp;</p>
<h3>Remove Overlay Scrollbars</h3>
<p>The new overlay scrollbars may be pretty, however I can no longer click an empty spot in the bar and have it quick-jump to that location.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get remove</span> overlay-scrollbar
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">su</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;export LIBOVERLAY_SCROLLBAR=0&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>Xsession.d<span style="color: #000000; font-weight: bold;">/</span>80overlayscrollbars</pre></td></tr></table></div>
<!-- end from cahe -->
<div>
<dl id="attachment_914" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/remove-overlay-scrollbars.png"><img class="size-medium wp-image-914" title="Remove overlay scrollbars" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/remove-overlay-scrollbars-300x216.png" alt="Remove overlay scrollbars" width="300" height="216" /></a></dt>
<dd class="wp-caption-dd">Nautilus with standard scrollbars</dd>
</dl>
</div>
<p>&nbsp;</p>
<h3>Move Nautilus Navigation Buttons Back to Left Side</h3>
<div class="mceTemp mceIEcenter" draggable="">
<dl id="attachment_983" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/moving-navvy-buttons.jpg"><img src="http://www.flynsarmy.com/wp-content/uploads/2011/11/moving-navvy-buttons-300x50.jpg" alt="Move Back/Forward buttons back on the left side in Nautilus" title="Back/Forward buttons back on the left side in Nautilus" width="300" height="50" class="size-medium wp-image-983" /></a></dt>
<dd class="wp-caption-dd">Move Back/Forward buttons back on the left side in Nautilus</dd>
</dl>
</div>
<p>This issues relatively minor but to keep things consistent, see <a href="http://ubuntuforums.org/showthread.php?p=11501676#post11501676" title="[How to] Move Nautilus Navigation Buttons back to the Left in Ubuntu" target="_blank">here</a> for instructions on how to move the navigation buttons in nautilus back to the left of the location bar.</p>
<p><strong>Warning:</strong> This involves rebuilding nautilus and you&#8217;ll probably need to do so after each nautilus update. It&#8217;s probably not worth it in the long run.</p>
<h3>Enable Ctrl+Alt+Backspace</h3>
<p>Ctrl+Alt+Backspace was a handy tool to restart X when all hope would otherwise have been lost. Unfortunately the wise minds at Canonical decided it was a bad thing and removed it. You can still get it back though.</p>
<p>In <em>Applications -&gt; System Tools -&gt; System Settings -&gt; Typing -&gt; Layout Options -&gt; Layouts -&gt; Options -&gt; </em><em>Key sequence to kill the X server</em> check <em>Control + Alt + Backspace</em></p>
<div>
<dl id="attachment_911" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/ctrl_alt_backspace.jpg"><img class="size-medium wp-image-911" title="Turn DontZap back on" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/ctrl_alt_backspace-300x233.jpg" alt="Turn DontZap back on" width="300" height="233" /></a></dt>
<dd class="wp-caption-dd">Re-enable Ctrl+Alt+Backspace</dd>
</dl>
</div>
<p>&nbsp;</p>
<h3>Enable Compiz 3D Effects in Gnome Classic</h3>
<p>In <em>/usr/share/gnome-session/sessions/gnome-fallback.session</em> change <em>metacity</em> to <em>compiz</em> under the heading <em>DefaultProvider-windowmanager</em>.</p>
<p><strong>Note</strong>: While compiz is enabled you&#8217;ll need to use <em>Alt + Super + Right click</em> instead of just <em>Alt + Right click</em> to use the panel context menu.</p>
<iframe width="640" height="385" src="http://www.youtube.com/embed/wLTq7J3URSI" frameborder="0" type="text/html"></iframe><div style="text-align:right;"><a style="color:#aaa;font-size:9px" href="http://www.clickonf5.org/" title="IFRAME Embed for Youtube Free WordPress Plugin" target="_blank">IFRAME Embed for Youtube</a></div>
<p>&nbsp;</p>
<h3>Stop the window decorator crashing</h3>
<p>This one had me stumped for a bit. When right clicking on a windows menubar to open the context menu, the window decorator would crash and I&#8217;d be left with an undraggable window without close/minimize/maximize buttons. If you&#8217;re experiencing this, here&#8217;s the fix:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> compizconfig-settings-manager</pre></td></tr></table></div>
<!-- end from cahe -->
<p>In <em>Applications -&gt; Other &#8211; CompizConfig Settings Manager -&gt; Effects -&gt; Window Decoration</em> click the <em>reset settings to default </em>button to the right of <em>command</em>.</p>
<div>
<dl id="attachment_916" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/fix-window-decorator.jpg"><img class="size-medium wp-image-916" title="Fix the window decorator" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/fix-window-decorator-300x185.jpg" alt="Fix the window decorator" width="300" height="185" /></a></dt>
<dd class="wp-caption-dd">Click this to fix your window decorator crashes</dd>
</dl>
</div>
<p>The default value should be <em>/usr/bin/compiz-decorator</em>. Thanks to Daniel Apostolov for his solution found in comment 27 <a title="Bug #740767 in compiz (Ubuntu): “gtk-window-decorator crashed with SIGSEGV in gwd_get_decor_frame()”" href="https://bugs.launchpad.net/ubuntu/+source/compiz/+bug/740767" target="_blank">here</a>. As an addendum to this solution, if your panels have already crashed you can bring them back like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">gconftool <span style="color: #660033;">--recursive-unset</span> <span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>panel <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">killall</span> gnome-panel</pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Restore Old Update-Notifier Behavior</h3>
<p>This is a niggling usability issue that has plagued Ubuntu for a few releases now. Back in the day you used to get a handy orange icon (or red for critical updates) in the top panel to inform you that updates were available. This useful functionality was bafflingly replaced with a pop-under window and no notification icon resulting in countless users completely missing updates for an inordinate amount of time before coming across the window by accident. You can return it to the way it should be by doing the following:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> dconf-tools</pre></td></tr></table></div>
<!-- end from cahe -->
<p>In <em>Applications -&gt; System Tools -&gt; dconf Editor -&gt; com -&gt; ubuntu -&gt; update-notifier</em> uncheck <em>auto-launch</em>.</p>
<div>
<dl id="attachment_917" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/old-update-notifier.jpg"><img class="size-medium wp-image-917" title="Restore old update notifier behavior" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/old-update-notifier-300x277.jpg" alt="Restore old update notifier behavior" width="300" height="277" /></a></dt>
<dd class="wp-caption-dd">Uncheck auto-launch</dd>
</dl>
</div>
<div>
<dl id="attachment_918" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/updates-available.jpg"><img class="size-medium wp-image-918" title="Updates Notification" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/updates-available-300x112.jpg" alt="Updates Notification" width="300" height="112" /></a></dt>
<dd class="wp-caption-dd">Updates Notification</dd>
</dl>
</div>
<p>&nbsp;</p>
<h3>Set Nautilus as Default FTP Handler</h3>
<p>When I click an FTP bookmark in the <em>Places</em> menu, I don&#8217;t want it to open in my default browser. I want it to open in Nautilus. The method of getting this working changed in 11.10. Check out <a title="How to set Nautilus as the default FTP handler in Linux | Flynsarmy" href="http://www.flynsarmy.com/2010/10/how-to-set-nautilus-as-the-default-ftp-handler-in-linux/">this post</a> to see how it&#8217;s done in 11.10.</p>
<p>&nbsp;</p>
<h3>Remove Copy To&#8230; and Move To&#8230; from Nautilus Context Menu</h3>
<ol>
<li>Open <em>/usr/share/nautilus/ui/nautilus-directory-view-ui.xml</em></li>
<li>Search for &#8216;CopyToMenu&#8217; and &#8216;MoveToMenu&#8217;. Make sure you&#8217;re in the &#8216;File Actions&#8217; section. They should be around line 161.</li>
<li>Comment out the &lt;menu&gt; blocks by wrapping them in &lt;!&#8211; and &#8211;&gt;</li>
<li>You&#8217;ll need to <em>killall nautilus</em> for the changes to take affect</li>
</ol>
<div>
<dl id="attachment_919" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/11/remove-nautilus-context-entries.png"><img class="size-medium wp-image-919" title="Remove Nautilus Context Menu Items" src="http://www.flynsarmy.com/wp-content/uploads/2011/11/remove-nautilus-context-entries-300x241.png" alt="Remove Nautilus Context Menu Items" width="300" height="241" /></a></dt>
<dd class="wp-caption-dd">Comment out the blocks like so</dd>
</dl>
</div>
<menu> </menu>
<p>So that about wraps up my post. If you have other tweaks you like to make to a fresh Ubuntu install let me know in the comments.</p>
<p>&nbsp;</p>
<h3>Remove Ubuntu One</h3>
<p>Don&#8217;t need/want the Ubuntu One and its annoying context menu entries in Nautilus or on your desktop? Remove it with:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="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: #660033;">--purge</span> remove .<span style="color: #000000; font-weight: bold;">*</span>ubuntuone.<span style="color: #000000; font-weight: bold;">*</span> .<span style="color: #000000; font-weight: bold;">*</span>couch.<span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #c20cb9; font-weight: bold;">killall</span> nautilus</pre></td></tr></table></div>
<!-- end from cahe -->
<p>&nbsp;</p>
<h3>Further Tweaks</h3>
<p>You may also want to check out the blog post <a href="http://mandriver.users.sourceforge.net/classic-gnome-guide.html" title="Classic Gnome guide" target="_blank">FAQ on Gnome Classic session</a> or <a href="http://ubuntuforums.org/showthread.php?t=1886799" title="[ubuntu] Oneiric Classic (No effects) Tweaks and tricks - Ubuntu Forums" target="_blank">this ubuntuforums post</a> for similar tweaks and improvements.</p>
<p>Note: Also see the prequel to this post: <a href="http://www.flynsarmy.com/2011/04/why-i-hate-unity/" title="Why I Hate Unity | Flynsarmy">Why I Hate Unity</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/11/how-to-make-ubuntu-11-10-more-usable/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Location of Error logs in a CPanel/WHM install</title>
		<link>http://www.flynsarmy.com/2011/10/location-of-error-logs-in-a-cpanel-install/</link>
		<comments>http://www.flynsarmy.com/2011/10/location-of-error-logs-in-a-cpanel-install/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 17:11:28 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[CPanel]]></category>
		<category><![CDATA[WHM]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=759</guid>
		<description><![CDATA[I was receiving a 500 internal server error on one of my CPanel sites earlier tonight but the apache error logs in CPanel admin for that user showed nothing. Instead, I had to locate the global apache error logs. This information may help others so I've listed some of the most useful CPanel/WHM log file locations below:
<h2>Apache Logs</h2>
<strong>General Error and Auditing Logs:</strong>
Location : <span style="color: #ff0000;">/usr/local/apache/logs/error_log</span>
Description : All exceptions caught by httpd along with standard error output from CGI applications are logged here..
The first place you should look when httpd crashes or you incur errors when accessing website.

<strong>Domain Access Logs:</strong>
Location : <span style="color: #ff0000;">/usr/local/apache/domlogs/domain.com</span>
Description : General access log file for each domain configured with cPanel.

<strong>Apache Access Logs:</strong>
Location : <span style="color: #ff0000;">/usr/local/apache/logs/access_log</span>
Description : Complete web server access log records all requests processed by the server.
<h2>MySQL Logs</h2>
<strong>MySQL General Information and Errors:</strong>
Location : <span style="color: #ff0000;">/var/lib/mysql/$(hostname).err</span>
Description : This path could vary, but is generally located in /var/lib/mysql. Could also be located at /var/log/mysqld.log

&#160;

For more log file locations, there are some great forum posts <a title="cPanel and WHM Log File Locations - Your HostICan Community" href="http://forum.hostican.com/virtual-private-servers-VPS-f9/cpanel-and-whm-log-file-locations-t336/" target="_blank">here</a> and <a title="cPanel and WHM Log File Locations - Your HostICan Community" href="http://forum.hostican.com/virtual-private-servers-VPS-f9/cpanel-and-whm-log-file-locations-t336/" target="_blank">here</a>.]]></description>
				<content:encoded><![CDATA[<p>I was receiving a 500 internal server error on one of my CPanel sites earlier tonight but the apache error logs in CPanel admin for that user showed nothing. Instead, I had to locate the global apache error logs. This information may help others so I&#8217;ve listed some of the most useful CPanel/WHM log file locations below:</p>
<h2>Apache Logs</h2>
<p><strong>General Error and Auditing Logs:</strong><br />
Location : <span style="color: #ff0000;">/usr/local/apache/logs/error_log</span><br />
Description : All exceptions caught by httpd along with standard error output from CGI applications are logged here..<br />
The first place you should look when httpd crashes or you incur errors when accessing website.</p>
<p><strong>Domain Access Logs:</strong><br />
Location : <span style="color: #ff0000;">/usr/local/apache/domlogs/domain.com</span><br />
Description : General access log file for each domain configured with cPanel.</p>
<p><strong>Apache Access Logs:</strong><br />
Location : <span style="color: #ff0000;">/usr/local/apache/logs/access_log</span><br />
Description : Complete web server access log records all requests processed by the server.</p>
<h2>MySQL Logs</h2>
<p><strong>MySQL General Information and Errors:</strong><br />
Location : <span style="color: #ff0000;">/var/lib/mysql/$(hostname).err</span><br />
Description : This path could vary, but is generally located in /var/lib/mysql. Could also be located at /var/log/mysqld.log</p>
<p>&nbsp;</p>
<p>For more log file locations, there are some great forum posts <a title="cPanel and WHM Log File Locations - Your HostICan Community" href="http://forum.hostican.com/virtual-private-servers-VPS-f9/cpanel-and-whm-log-file-locations-t336/" target="_blank">here</a> and <a title="cPanel and WHM Log File Locations - Your HostICan Community" href="http://forum.hostican.com/virtual-private-servers-VPS-f9/cpanel-and-whm-log-file-locations-t336/" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/10/location-of-error-logs-in-a-cpanel-install/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CPanel SoftException UID is smaller than min_uid</title>
		<link>http://www.flynsarmy.com/2011/10/cpanel-softexception-uid-is-smaller-than-min_uid/</link>
		<comments>http://www.flynsarmy.com/2011/10/cpanel-softexception-uid-is-smaller-than-min_uid/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 17:07:27 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[CPanel]]></category>
		<category><![CDATA[WHM]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=757</guid>
		<description><![CDATA[I've was playing with EasyApache in a WHM install recently and after the upgrade I came across a strange error:
<pre lang="apache">SoftException in Application.cpp:357: UID of script "/home/mysite/public_html/index.php" is smaller than min_uid
Premature end of script headers: index.php</pre>
Turns out this error is caused by apache being unable to read files added by <em>root</em> to a users public_html folder. A simple fix for this problem is to
<pre lang="bash">chown -R mysite:mysite /home/mysite/public_html</pre>
Thanks to user <em>ronniev</em> of eukhost forums for his solution <a title="How to solve Error: SoftException in Application.cpp:303" href="http://www.eukhost.com/forums/f15/how-solve-error-softexception-application-cpp-303-a-6205/" target="_blank">here</a>.]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve was playing with EasyApache in a WHM install recently and after the upgrade I came across a strange error:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="apache" style="font-family:monospace;">SoftException in Application.cpp:<span style="color: #ff0000;">357</span>: UID of <span style="color: #00007f;">script</span> <span style="color: #7f007f;">&quot;/home/mysite/public_html/index.php&quot;</span> is smaller than min_uid
Premature end of <span style="color: #00007f;">script</span> headers: index.php</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Turns out this error is caused by apache being unable to read files added by <em>root</em> to a users public_html folder. A simple fix for this problem is to</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> mysite:mysite <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>mysite<span style="color: #000000; font-weight: bold;">/</span>public_html</pre></td></tr></table></div>
<!-- end from cahe -->
<p>If you&#8217;re still having permissions issues aver doing the above, try <code>chmod</code>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> <span style="color: #000000;">755</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>mysite<span style="color: #000000; font-weight: bold;">/</span>public_html</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Thanks to user <em>ronniev</em> of eukhost forums for his solution <a title="How to solve Error: SoftException in Application.cpp:303" href="http://www.eukhost.com/forums/f15/how-solve-error-softexception-application-cpp-303-a-6205/" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/10/cpanel-softexception-uid-is-smaller-than-min_uid/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Switch Tabs with CTRL+Tab in GEdit 3</title>
		<link>http://www.flynsarmy.com/2011/10/switch-tabs-with-ctrltab-in-gedit-3/</link>
		<comments>http://www.flynsarmy.com/2011/10/switch-tabs-with-ctrltab-in-gedit-3/#comments</comments>
		<pubDate>Sat, 15 Oct 2011 13:51:52 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[gedit]]></category>
		<category><![CDATA[gnome 3]]></category>
		<category><![CDATA[tabswitch]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=669</guid>
		<description><![CDATA[One of my favourite plugins for GEdit2 was tabswitch. It made GEdit more consistant with browsers by allowing it to switch tabs with CTRL+Tab instead of CTRL+PgUp/Down. Ubuntu 11.10 comes with Gedit 3 and the plugin no longer worked - so I rewrote it!

This plugin will let you use CTRL+Tab to switch between tabs in GEdit 3. You can download a working implementation <a title="Flynsarmy/GEdit3TabSwitch - GitHub" href="https://github.com/Flynsarmy/GEdit3TabSwitch" target="_blank">here</a>.

Install it by copying the files into <em>~/.local/share/gedit/plugins</em> directory (which doesn't exist by default) or <em>/usr/lib/gedit/plugins</em> if you want it to work for all users. Remember to enable the plugin in <em>Edit - Preferences - Plugins</em> for it to work!]]></description>
				<content:encoded><![CDATA[<p>One of my favourite plugins for GEdit2 was tabswitch. It made GEdit more consistant with browsers by allowing it to switch tabs with CTRL+Tab instead of CTRL+PgUp/Down. Ubuntu 11.10 comes with Gedit 3 and the plugin no longer worked &#8211; so I rewrote it!</p>
<p>This plugin will let you use CTRL+Tab to switch between tabs in GEdit 3. You can download a working implementation <a title="Flynsarmy/GEdit3TabSwitch - GitHub" href="https://github.com/Flynsarmy/GEdit3TabSwitch" target="_blank">here</a>.</p>
<p>Install it by copying the files into <em>~/.local/share/gedit/plugins</em> directory (which doesn&#8217;t exist by default) or <em>/usr/lib/gedit/plugins</em> if you want it to work for all users. Remember to enable the plugin in <em>Edit &#8211; Preferences &#8211; Plugins</em> for it to work!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/10/switch-tabs-with-ctrltab-in-gedit-3/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Split Large MySQL Dump Files</title>
		<link>http://www.flynsarmy.com/2011/10/split-large-mysql-dump-files/</link>
		<comments>http://www.flynsarmy.com/2011/10/split-large-mysql-dump-files/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 05:13:07 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[google docs]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=657</guid>
		<description><![CDATA[I've been using my <a title="Cloud Database Backup &#124; Flynsarmy" href="http://www.flynsarmy.com/2011/05/cloud-database-backup/">Cloud Database Backup</a> script for a few months now for weekly scheduled backups of my MySQL databases to Google Docs. Everything has been going smoothly, however I'm starting to run low on quota. For this reason I decided to look into splitting the SQL dumps into chunks small enough to be convertible and doing an upload-convert rather than a zip upload which will result in literally unlimited, quote free database backups as frequently as I like! The focus of this post though is the actual splitting script which splits a given MySQL dump into chunks of x characters.

As always, download it <a href="http://www.flynsarmy.com/wp-content/uploads/2011/10/flynsarmy_dbchunk.zip">here</a>.]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been using my <a title="Cloud Database Backup | Flynsarmy" href="http://www.flynsarmy.com/2011/05/cloud-database-backup/">Cloud Database Backup</a> script for a few months now for weekly scheduled backups of my MySQL databases to Google Docs. Everything has been going smoothly, however I&#8217;m starting to run low on quota. For this reason I decided to look into splitting the SQL dumps into chunks small enough to be convertible and doing an upload-convert rather than a zip upload which will result in literally unlimited, quote free database backups as frequently as I like! The focus of this post though is the actual splitting script which splits a given MySQL dump into chunks of x characters.</p>
<p>As always, download it <a href="http://www.flynsarmy.com/wp-content/uploads/2011/10/flynsarmy_dbchunk.zip">here</a>.</p>
<p>The standard MySQL dumps with grouped <em>INSERT</em> statements won&#8217;t work here, as if you have thousands or more rows in your table, the statement may be contain more characters than the chunk size resulting in a file not able to be converted. So use <em>&#8211;skip-extended-insert</em> like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">mysqldump -u<span style="color: #000000; font-weight: bold;">&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #660033;">-p</span> <span style="color: #660033;">--databases</span> <span style="color: #000000; font-weight: bold;">&lt;</span>dbname<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #660033;">--skip-extended-insert</span> <span style="color: #000000; font-weight: bold;">&gt;</span> dbdump.sql</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Use the splitter script like so:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>flynsarmy_dbchunk.py <span style="color: #660033;">--filepath</span>=<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>dump.sql</pre></td></tr></table></div>
<!-- end from cahe -->
<p>The following arguments are accepted:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #660033;">--filepath</span>=<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">file</span>
--max_chunk_size <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1024000</span> by default<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #660033;">--debug</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>False by default<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>The script will split on the closest <em>INSERT</em> or blank line before the specified chunk size limit is reached. It&#8217;ll use the input filename as the output names appending .&lt;num&gt;.txt on the end and output the names of the chunks. Here&#8217;s an example:</p>
<p>Input:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$ </span>.<span style="color: #000000; font-weight: bold;">/</span>flynsarmy_dbchunk.py <span style="color: #660033;">--filepath</span>=tmp<span style="color: #000000; font-weight: bold;">/</span>dbdump.sql</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Output:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">tmp/mydump.sql.0.txt
tmp/mydump.sql.1.txt
tmp/mydump.sql.2.txt
tmp/mydump.sql.3.txt
tmp/mydump.sql.4.txt
tmp/mydump.sql.5.txt
tmp/mydump.sql.6.txt
tmp/mydump.sql.7.txt
tmp/mydump.sql.8.txt
tmp/mydump.sql.9.txt
tmp/mydump.sql.10.txt
tmp/mydump.sql.11.txt
tmp/mydump.sql.12.txt
tmp/mydump.sql.13.txt
tmp/mydump.sql.14.txt
tmp/mydump.sql.15.txt
tmp/mydump.sql.16.txt
tmp/mydump.sql.17.txt
tmp/mydump.sql.18.txt
tmp/mydump.sql.19.txt
tmp/mydump.sql.20.txt
tmp/mydump.sql.21.txt
tmp/mydump.sql.22.txt
tmp/mydump.sql.23.txt
tmp/mydump.sql.24.txt
tmp/mydump.sql.25.txt
tmp/mydump.sql.26.txt
tmp/mydump.sql.27.txt
tmp/mydump.sql.28.txt
tmp/mydump.sql.29.txt
tmp/mydump.sql.30.txt
tmp/mydump.sql.31.txt</pre></td></tr></table></div>
<!-- end from cahe -->
<p>This script will be uploaded into my <a title="Cloud Database Backup | Flynsarmy" href="http://www.flynsarmy.com/2011/05/cloud-database-backup/">Cloud Database Backup</a> tool once some <a title="Failure to convert - Google Docs Help" href="http://www.google.com/support/forum/p/Google+Docs/thread?tid=0240a085c9f85dd5&amp;hl=en" target="_blank">weird issues</a> have been worked out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/10/split-large-mysql-dump-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Pidgin working with the Latest Skype</title>
		<link>http://www.flynsarmy.com/2011/10/get-pidgin-working-with-latest-skype/</link>
		<comments>http://www.flynsarmy.com/2011/10/get-pidgin-working-with-latest-skype/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 07:57:59 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Pidgin]]></category>
		<category><![CDATA[Skype]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=653</guid>
		<description><![CDATA[Ubuntu fans who like having Skype chats appearing in their Pidgin windows will know of 2 useful packages - <em>skype4pidgin</em> and <em>pidgin-skype</em>. These used to work great, however with the latest Skype update things broke. You could send messages from your Pidgin window but wouldn't see any responses from your contacts. Frustrating!

Anyway, it looks like the guy behind <em>skype4pidgin</em> has come up with a solution which he's layed out on <a title="Skype API Plugin for Pidgin/libpurple/Adium" href="http://eion.robbmob.com/" target="_blank">his website</a>.

You'll need to download <em>skype4pidgin.deb</em>, <em>libskype.so</em> and <em>libskype_dbus.so</em> (or obviously the 64-bit equivalents of you're on Ubuntu64). Drop the <em>.so</em> files into /usr/lib/purple-2 remembering to back up the existing equivalents first and install <em>skype4pidgin.deb</em>.

That should be all there is to it. Pidgin is back to working the way it should. *whew*]]></description>
				<content:encoded><![CDATA[<p>Ubuntu fans who like having Skype chats appearing in their Pidgin windows will know of 2 useful packages &#8211; <em>skype4pidgin</em> and <em>pidgin-skype</em>. These used to work great, however with the latest Skype update things broke. You could send messages from your Pidgin window but wouldn&#8217;t see any responses from your contacts. Frustrating!</p>
<p>Anyway, it looks like the guy behind <em>skype4pidgin</em> has come up with a solution which he&#8217;s layed out on <a title="Skype API Plugin for Pidgin/libpurple/Adium" href="http://eion.robbmob.com/" target="_blank">his website</a>.</p>
<p>You&#8217;ll need to download <em>skype4pidgin.deb</em>, <em>libskype.so</em> and <em>libskype_dbus.so</em> (or obviously the 64-bit equivalents of you&#8217;re on Ubuntu64). Drop the <em>.so</em> files into /usr/lib/purple-2 remembering to back up the existing equivalents first and install <em>skype4pidgin.deb</em>.</p>
<p>That should be all there is to it. Pidgin is back to working the way it should. *whew*</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/10/get-pidgin-working-with-latest-skype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Automatically Import Missing GPG Keys in Ubuntu</title>
		<link>http://www.flynsarmy.com/2011/09/how-to-automatically-import-missing-gpg-keys-in-ubuntu/</link>
		<comments>http://www.flynsarmy.com/2011/09/how-to-automatically-import-missing-gpg-keys-in-ubuntu/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 04:03:00 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[applications]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=645</guid>
		<description><![CDATA[This is an issue that plagues me constantly. For each PPA you add to Ubuntu, you also need to import a GPG key for it. This is all fine and well - until don't have the key and are unsure how to get it (often happens after a reformat). Try doing an update without a valid key and you'll get the following:
<div><dl id="attachment_646" class="wp-caption aligncenter" style="width: 310px;"><dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/09/clip_image001_thumb.png"><img class="size-medium wp-image-646" title="BSOD - Ubuntu Updates style" src="http://www.flynsarmy.com/wp-content/uploads/2011/09/clip_image001_thumb-300x152.png" alt="BSOD - Ubuntu Updates style" width="300" height="152" /></a></dt><dd class="wp-caption-dd">BSOD - Ubuntu Updates style
W: GPG error: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY</dd></dl></div>
Well we finally have a solution: <em>launchpad-getkeys</em>! This handy little tool will automatically determine which PPA's require GPG keys and import them for you.
<div><dl id="attachment_647" class="wp-caption aligncenter" style="width: 310px;"><dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/09/clip_image008_thumb.png"><img class="size-medium wp-image-647" title="Finally. Sweet relief!" src="http://www.flynsarmy.com/wp-content/uploads/2011/09/clip_image008_thumb-300x152.png" alt="Finally. Sweet relief!" width="300" height="152" /></a></dt><dd class="wp-caption-dd">Finally. Sweet relief!</dd></dl></div>
Install with:
<pre lang="bash">sudo apt-add-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install launchpad-getkeys</pre>
Run with:
<pre lang="bash">sudo launchpad-getkeys</pre>
<em>Images taken from <a title="How to Automatically Import Missing GPG Keys in Ubuntu - How-To Geek" href="http://www.howtogeek.com/72934/how-to-automatically-import-missing-gpg-keys-in-ubuntu/" target="_blank">this howtogeek article</a>. For more information see <a title="Automatically Import All Missing Launchpad PPA GPG Keys [Ubuntu .deb] ~ Web Upd8: Ubuntu / Linux blog" href="http://www.webupd8.org/2010/05/automatically-import-all-missing.html" target="_blank">here</a> and <a title="http://www.webupd8.org/2011/02/launchpad-getkeys-gets-proxy-support.html" href="Launchpad-Getkeys Gets Proxy Support [Automatically Import All Missing GPG Keys With One Command] ~ Web Upd8: Ubuntu / Linux blog" target="_blank">here</a>.</em>]]></description>
				<content:encoded><![CDATA[<p>This is an issue that plagues me constantly. For each PPA you add to Ubuntu, you also need to import a GPG key for it. This is all fine and well &#8211; until don&#8217;t have the key and are unsure how to get it (often happens after a reformat). Try doing an update without a valid key and you&#8217;ll get the following:</p>
<div>
<dl id="attachment_646" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/09/clip_image001_thumb.png"><img class="size-medium wp-image-646" title="BSOD - Ubuntu Updates style" src="http://www.flynsarmy.com/wp-content/uploads/2011/09/clip_image001_thumb-300x152.png" alt="BSOD - Ubuntu Updates style" width="300" height="152" /></a></dt>
<dd class="wp-caption-dd">BSOD &#8211; Ubuntu Updates style<br />
W: GPG error: The following signatures couldn&#8217;t be verified because the public key is not available: NO_PUBKEY</dd>
</dl>
</div>
<p>Well we finally have a solution: <em>launchpad-getkeys</em>! This handy little tool will automatically determine which PPA&#8217;s require GPG keys and import them for you.</p>
<div>
<dl id="attachment_647" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/09/clip_image008_thumb.png"><img class="size-medium wp-image-647" title="Finally. Sweet relief!" src="http://www.flynsarmy.com/wp-content/uploads/2011/09/clip_image008_thumb-300x152.png" alt="Finally. Sweet relief!" width="300" height="152" /></a></dt>
<dd class="wp-caption-dd">Finally. Sweet relief!</dd>
</dl>
</div>
<p>Install with:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> apt-add-repository ppa:nilarimogard<span style="color: #000000; font-weight: bold;">/</span>webupd8
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get update</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> launchpad-getkeys</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Run with:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchpad-getkeys</pre></td></tr></table></div>
<!-- end from cahe -->
<p><em>Images taken from <a title="How to Automatically Import Missing GPG Keys in Ubuntu - How-To Geek" href="http://www.howtogeek.com/72934/how-to-automatically-import-missing-gpg-keys-in-ubuntu/" target="_blank">this howtogeek article</a>. For more information see <a title="Automatically Import All Missing Launchpad PPA GPG Keys [Ubuntu .deb] ~ Web Upd8: Ubuntu / Linux blog" href="http://www.webupd8.org/2010/05/automatically-import-all-missing.html" target="_blank">here</a> and <a title="Launchpad-Getkeys Gets Proxy Support [Automatically Import All Missing GPG Keys With One Command] ~ Web Upd8: Ubuntu / Linux blog" href="http://www.webupd8.org/2011/02/launchpad-getkeys-gets-proxy-support.html" target="_blank">here</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/09/how-to-automatically-import-missing-gpg-keys-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Tip: Discover What&#8217;s Running On Port X</title>
		<link>http://www.flynsarmy.com/2011/09/quick-tip-discover-whats-running-on-port-x/</link>
		<comments>http://www.flynsarmy.com/2011/09/quick-tip-discover-whats-running-on-port-x/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 07:32:13 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[quick tip]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=638</guid>
		<description><![CDATA[This weekend I was trying to run a server on port 9000 but something was already on there. I had no idea what it was and needed to find and stop it. Here's a super quick and easy way to do so:

You'll need <a title="lsof - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Lsof" target="_blank">lsof</a>:
<pre lang="bash">sudo apt-get install lsof
lsof -iTCP:9000</pre>
The result I got was as follows:
<pre lang="text">COMMAND     PID      USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
komodo-bi 31713 myuser   51u  IPv4 1234567      0t0  TCP *:9000 (LISTEN)</pre>
From there it was as simple as going into komodo and turning turning off its listener :)

Thanks to Laran Evans for his <a title="What&#38;#8217;s running on port XXXX? &#124; Laran Evans" href="http://www.laranevans.com/2009/12/08/whats-running-on-port-xxxx/" target="_blank">useful tutorial</a>.]]></description>
				<content:encoded><![CDATA[<p>This weekend I was trying to run a server on port 9000 but something was already on there. I had no idea what it was and needed to find and stop it. Here&#8217;s a super quick and easy way to do so:</p>
<p>You&#8217;ll need <a title="lsof - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Lsof" target="_blank">lsof</a>:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get install</span> lsof
lsof -iTCP:<span style="color: #000000;">9000</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>The result I got was as follows:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="text" style="font-family:monospace;">COMMAND     PID      USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
komodo-bi 31713 myuser   51u  IPv4 1234567      0t0  TCP *:9000 (LISTEN)</pre></td></tr></table></div>
<!-- end from cahe -->
<p>From there it was as simple as going into komodo and turning turning off its listener <img src='http://www.flynsarmy.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks to Laran Evans for his <a title="What&amp;#8217;s running on port XXXX? | Laran Evans" href="http://www.laranevans.com/2009/12/08/whats-running-on-port-xxxx/" target="_blank">useful tutorial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/09/quick-tip-discover-whats-running-on-port-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Plus Style HTML5 Image Uploads</title>
		<link>http://www.flynsarmy.com/2011/08/google-plus-style-file-uploads/</link>
		<comments>http://www.flynsarmy.com/2011/08/google-plus-style-file-uploads/#comments</comments>
		<pubDate>Sat, 27 Aug 2011 12:06:25 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[File API]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[XHR2]]></category>
		<category><![CDATA[XMLHttpRequest2]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=614</guid>
		<description><![CDATA[If you're reading this page (or my blog in general) it's a pretty safe bet you already have <a title="Google+" href="https://plus.google.com/" target="_blank">Google+</a>. If you've uploaded any photos to Google+ from Chrome or FF, you would also have noticed its snazzy HTML5 file uploader at work. This weekend I took it upon myself to whip up a quick and dirty version of that uploader and share its inner workings with the world.
<dl id="attachment_615" class="wp-caption aligncenter" style="width: 310px;"><dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/08/Google+.png"><img class="size-medium wp-image-615" title="Google+ Image Uploader" src="http://www.flynsarmy.com/wp-content/uploads/2011/08/Google+-300x202.png" alt="Google+ Image Uploader" width="300" height="202" /></a></dt><dd class="wp-caption-dd">Google+ Image Uploader</dd></dl>

Here's a short video of my uploader at work:

[yframe url='http://www.youtube.com/watch?v=AXx8cu6rxV4']

Requirements:
<ul>
	<li>PHP4+</li>
	<li>HTML5-enabled browser (<a title="File API" href="http://www.w3.org/TR/FileAPI/" target="_blank">File API</a> - including drag and drop, <a title="XMLHttpRequest Level 2" href="http://www.w3.org/TR/XMLHttpRequest2/" target="_blank">XHR2</a>)</li>
	<li>Some images to upload</li>
</ul>
<em>Disclaimer: Currently only Firefox and Webkit based browsers meet the requirements above. Opera supports the File API and probably XHR2 (I haven't tested), however it doesn't have drag and drop so this tutorial won't work with it. If you're curious about whether or not IE will work with this tutorial, I'm already laughing at you.</em>

Download the finished script <a href="http://www.flynsarmy.com/wp-content/uploads/2011/08/google-plus-style-file-uploads.zip">here</a>.]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re reading this page (or my blog in general) it&#8217;s a pretty safe bet you already have <a title="Google+" href="https://plus.google.com/" target="_blank">Google+</a>. If you&#8217;ve uploaded any photos to Google+ from Chrome or FF, you would also have noticed its snazzy HTML5 file uploader at work. This weekend I took it upon myself to whip up a quick and dirty version of that uploader and share its inner workings with the world.</p>
<dl id="attachment_615" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/08/Google+.png"><img class="size-medium wp-image-615" title="Google+ Image Uploader" src="http://www.flynsarmy.com/wp-content/uploads/2011/08/Google+-300x202.png" alt="Google+ Image Uploader" width="300" height="202" /></a></dt>
<dd class="wp-caption-dd">Google+ Image Uploader</dd>
</dl>
<p>Here&#8217;s a short video of my uploader at work:</p>
<iframe width="640" height="385" src="http://www.youtube.com/embed/AXx8cu6rxV4" frameborder="0" type="text/html"></iframe><div style="text-align:right;"><a style="color:#aaa;font-size:9px" href="http://www.clickonf5.org/" title="IFRAME Embed for Youtube Free WordPress Plugin" target="_blank">IFRAME Embed for Youtube</a></div>
<p>&nbsp;</p>
<p>Requirements:</p>
<ul>
<li>PHP4+</li>
<li>HTML5-enabled browser (<a title="File API" href="http://www.w3.org/TR/FileAPI/" target="_blank">File API</a> &#8211; including drag and drop, <a title="XMLHttpRequest Level 2" href="http://www.w3.org/TR/XMLHttpRequest2/" target="_blank">XHR2</a>)</li>
<li>Some images to upload</li>
</ul>
<p><em>Disclaimer: Currently only Firefox and Webkit based browsers meet the requirements above. Opera supports the File API and probably XHR2 (I haven&#8217;t tested), however it doesn&#8217;t have drag and drop so this tutorial won&#8217;t work with it. If you&#8217;re curious about whether or not IE will work with this tutorial, I&#8217;m already laughing at you.</em></p>
<p>Download the finished script <a href="http://www.flynsarmy.com/wp-content/uploads/2011/08/google-plus-style-file-uploads.zip">here</a>.</p>
<p>The comments pretty much make this tutorial self explanatory so I&#8217;ll let the code below speak for itself. You&#8217;ll need an <em>index.php</em>, <em>upload.php</em> and <em>uploads</em> folder writable to by apache.<br />
<strong>index.php:</strong></p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html xmlns<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>meta http<span style="color: #339933;">-</span>equiv<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span> content<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Untitled Document<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>style<span style="color: #339933;">&gt;</span>
	html<span style="color: #339933;">,</span> body <span style="color: #009900;">&#123;</span>height<span style="color: #339933;">:</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">%;</span>margin<span style="color: #339933;">:</span>0px<span style="color: #339933;">;</span>padding<span style="color: #339933;">:</span>0px<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">#message_upload {font-size:26px;color:lightgrey;margin:15px}
</span>	<span style="color: #339933;">.</span>box <span style="color: #009900;">&#123;</span>float<span style="color: #339933;">:</span>left<span style="color: #339933;">;</span>width<span style="color: #339933;">:</span>150px<span style="color: #339933;">;</span>height<span style="color: #339933;">:</span>120px<span style="color: #339933;">;</span>background<span style="color: #339933;">:</span>lightgrey<span style="color: #339933;">;</span>margin<span style="color: #339933;">:</span>8px<span style="color: #339933;">;</span>text<span style="color: #339933;">-</span>align<span style="color: #339933;">:</span>center<span style="color: #009900;">&#125;</span>
	<span style="color: #339933;">.</span>box <span style="color: #339933;">.</span>name <span style="color: #009900;">&#123;</span>height<span style="color: #339933;">:</span>25px<span style="color: #339933;">;</span>margin<span style="color: #339933;">-</span>top<span style="color: #339933;">:</span>5px<span style="color: #009900;">&#125;</span>
	<span style="color: #339933;">.</span>box <span style="color: #339933;">.</span>progresscontainer <span style="color: #009900;">&#123;</span>height<span style="color: #339933;">:</span>5px<span style="color: #339933;">;</span>margin<span style="color: #339933;">:</span>80px 5px 0px<span style="color: #009900;">&#125;</span>
	<span style="color: #339933;">.</span>box <span style="color: #339933;">.</span>progress <span style="color: #009900;">&#123;</span>background<span style="color: #339933;">:</span>grey<span style="color: #339933;">;</span>height<span style="color: #339933;">:</span>5px<span style="color: #339933;">;</span>width<span style="color: #339933;">:</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">%</span><span style="color: #009900;">&#125;</span>
	<span style="color: #339933;">.</span>box<span style="color: #339933;">.</span>picture <span style="color: #009900;">&#123;</span>background<span style="color: #339933;">:</span>none center top no<span style="color: #339933;">-</span>repeat<span style="color: #339933;">;</span>background<span style="color: #339933;">-</span>size<span style="color: #339933;">:</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">%</span><span style="color: #009900;">&#125;</span>
	<span style="color: #339933;">.</span>box<span style="color: #339933;">.</span>picture <span style="color: #339933;">.</span>progresscontainer<span style="color: #339933;">,</span> <span style="color: #339933;">.</span>box<span style="color: #339933;">.</span>picture <span style="color: #339933;">.</span>name <span style="color: #009900;">&#123;</span>display<span style="color: #339933;">:</span>none<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>style<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">'text/javascript'</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">'http://code.jquery.com/jquery-1.6.2.min.js'</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">'text/javascript'</span><span style="color: #339933;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">var</span> tpl_box <span style="color: #339933;">=</span>
		<span style="color: #0000ff;">&quot;&lt;div class='box'&gt;
			&lt;div class='name'&gt;&lt;/div&gt;
			&lt;div class='progresscontainer'&gt;&lt;div class='progress'&gt;&lt;/div&gt;&lt;/div&gt;
		&lt;/div&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Check for the various File API support.</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>window<span style="color: #339933;">.</span><span style="color: #990000;">File</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>window<span style="color: #339933;">.</span>FileReader <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>window<span style="color: #339933;">.</span>FileList <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>window<span style="color: #339933;">.</span>Blob <span style="color: #009900;">&#41;</span>
			alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The File APIs are not fully supported in this browser. Please upgrade your browser.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Listen for file drag and drop</span>
		document<span style="color: #339933;">.</span>body<span style="color: #339933;">.</span>addEventListener<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dragover'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e<span style="color: #339933;">.</span>stopPropagation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		document<span style="color: #339933;">.</span>body<span style="color: #339933;">.</span>addEventListener<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'drop'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e<span style="color: #339933;">.</span>stopPropagation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			e<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			upload_files<span style="color: #009900;">&#40;</span> e<span style="color: #339933;">.</span>dataTransfer<span style="color: #339933;">.</span>files <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * Upload a given FileList
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> upload_files<span style="color: #009900;">&#40;</span> files <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#message_upload'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>hide<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Loop through dropped files, uploading only images and ignoring all others</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> f<span style="color: #339933;">;</span> f <span style="color: #339933;">=</span> files<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> i  <span style="color: #009900;">&#41;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> f<span style="color: #339933;">.</span>type<span style="color: #339933;">==</span><span style="color: #0000ff;">'image/jpeg'</span> <span style="color: #339933;">||</span> f<span style="color: #339933;">.</span>type<span style="color: #339933;">==</span><span style="color: #0000ff;">'image/png'</span> <span style="color: #339933;">||</span> f<span style="color: #339933;">.</span>type<span style="color: #339933;">==</span><span style="color: #0000ff;">'image/gif'</span> <span style="color: #009900;">&#41;</span>
					upload_file<span style="color: #009900;">&#40;</span> f <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">else</span>
					alert<span style="color: #009900;">&#40;</span> f<span style="color: #339933;">.</span>name   <span style="color: #0000ff;">' is not a valid image file.'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * Upload a given File
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> upload_file<span style="color: #009900;">&#40;</span> f <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Truncate long filenames</span>
		<span style="color: #000000; font-weight: bold;">var</span> name <span style="color: #339933;">=</span> f<span style="color: #339933;">.</span>name<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> name<span style="color: #339933;">.</span>length <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">15</span> <span style="color: #009900;">&#41;</span> name <span style="color: #339933;">=</span> name<span style="color: #339933;">.</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">'...'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Create our new upload box to display</span>
		<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$box</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>tpl_box<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>find<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>html<span style="color: #009900;">&#40;</span> name <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Do the actual uploading</span>
		<span style="color: #000000; font-weight: bold;">var</span> XHR <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		XHR<span style="color: #339933;">.</span>open<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PUT'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'upload.php'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//Send the file details along with the request</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #990000;">key</span> in f<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> val <span style="color: #339933;">=</span> f<span style="color: #009900;">&#91;</span><span style="color: #990000;">key</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">//This line is required for Firefox compatability</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> typeof<span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'string'</span> <span style="color: #339933;">||</span> typeof<span style="color: #009900;">&#40;</span>val<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'number'</span> <span style="color: #009900;">&#41;</span>
				XHR<span style="color: #339933;">.</span>setRequestHeader<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'file_'</span> <span style="color: #990000;">key</span><span style="color: #339933;">,</span> val<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">//Update our box's progress bar as the file uploads</span>
		XHR<span style="color: #339933;">.</span>upload<span style="color: #339933;">.</span>addEventListener<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;progress&quot;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<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>e<span style="color: #339933;">.</span>lengthComputable<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> percentComplete <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>e<span style="color: #339933;">.</span>loaded <span style="color: #339933;">/</span> e<span style="color: #339933;">.</span>total <span style="color: #339933;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$box</span><span style="color: #339933;">.</span>find<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.progress'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'width'</span><span style="color: #339933;">,</span> percentComplete   <span style="color: #0000ff;">'%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//Display the uploaded pictures thumbnail once upload is complete</span>
		XHR<span style="color: #339933;">.</span>onreadystatechange <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// in case of network errors this might not give reliable results</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> this<span style="color: #339933;">.</span>readyState <span style="color: #339933;">==</span> this<span style="color: #339933;">.</span>DONE <span style="color: #009900;">&#41;</span>
				<span style="color: #000088;">$box</span><span style="color: #339933;">.</span>addClass<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'picture'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'background-image'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'url('</span> escape<span style="color: #009900;">&#40;</span>this<span style="color: #339933;">.</span>responseText<span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		XHR<span style="color: #339933;">.</span>send<span style="color: #009900;">&#40;</span> f <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//Display the upload box</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>append<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$box</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span>
<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">'message_upload'</span><span style="color: #339933;">&gt;</span>Drag images here to upload<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p><strong>upload.php</strong></p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">//http://php.net/manual/en/features.file-upload.put-method.php</span>
	<span style="color: #666666; font-style: italic;">//http://stackoverflow.com/questions/541430/how-do-i-read-any-request-header-in-php</span>
&nbsp;
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">apache_request_headers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//Webkit uses file_fileName, FF uses file_name</span>
	<span style="color: #000088;">$name_header</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file_fileName'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file_fileName'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file_name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$upload_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'uploads/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$name_header</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* PUT data comes in on the stdin stream */</span>
	<span style="color: #000088;">$putdata</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;php://input&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* Open a file for writing */</span>
	<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$upload_url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;w&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* Read the data 1 KB at a time and write to the file */</span>
	<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$putdata</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/* Close the streams */</span>
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$putdata</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$upload_url</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<dl id="attachment_616" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/08/HTML5Upload1.png"><img class="size-medium wp-image-616" title="HTML5 Drag and Drop Upload" src="http://www.flynsarmy.com/wp-content/uploads/2011/08/HTML5Upload1-300x61.png" alt="HTML5 Drag and Drop Upload" width="300" height="61" /></a></dt>
<dd class="wp-caption-dd">4 images uploading away</dd>
</dl>
<dl id="attachment_619" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/08/HTML5Upload2.png"><img class="size-medium wp-image-619" title="HTML5 Drag and Drop File Upload 2" src="http://www.flynsarmy.com/wp-content/uploads/2011/08/HTML5Upload2-300x60.png" alt="HTML5 Drag and Drop File Upload 2" width="300" height="60" /></a></dt>
<dd class="wp-caption-dd">3/4 uploaded and thumbnails showing</dd>
</dl>
<p>Simply drag image files into your browser window and they&#8217;ll upload away as they do in Google+.</p>
<p>Have fun with it!</p>
<p>Download the finished script <a href="http://www.flynsarmy.com/wp-content/uploads/2011/08/google-plus-style-file-uploads.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/08/google-plus-style-file-uploads/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Enable FTP Keepalives in Nautilus</title>
		<link>http://www.flynsarmy.com/2011/08/enable-ftp-keepalives-in-nautilus/</link>
		<comments>http://www.flynsarmy.com/2011/08/enable-ftp-keepalives-in-nautilus/#comments</comments>
		<pubDate>Thu, 25 Aug 2011 04:06:41 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[FTP]]></category>
		<category><![CDATA[Nautilus]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=609</guid>
		<description><![CDATA[<strong>Update 2011-10-26:</strong> Added support for Ubuntu 11.04+ which uses slightly different FTP folder names

Lack of FTP keepalive functionality in Nautilus has been one of my biggest gripes in Ubuntu for a long time now. It's infuriating attempting to open a folder only to discover the session has timed out and I need to reconnect. Well that problem is now solved!

Run the following bash script in the background each time you boot and you're good to go:
<pre lang="bash" escaped="true">#!/bin/bash

while true
do
	#10.10 and earlier
	ls ~/.gvfs/ftp* &#38;&#62; /dev/null
	#11.04+
	ls ~/.gvfs/FTP* &#38;&#62; /dev/null
	sleep 15
done</pre>
Many thanks go to the user who originally posted this script in a mailing list <a title="OSDir.com - ubuntu-bugs - [Bug 410288] Re: Nautilus does not handle FTP timeouts well - msg#12128" href="http://osdir.com/ml/ubuntu-bugs/2011-05/msg12128.html" target="_blank">here</a>.

PS. If anyone knows how to integrate this into a <a title="Nautilus File Manager Scripts: Questions and Answers" href="http://g-scripts.sourceforge.net/faq.php" target="_blank">nautilus script</a> I'd much appreciate it!]]></description>
				<content:encoded><![CDATA[<p><strong>Update 2011-10-26:</strong> Added support for Ubuntu 11.04+ which uses slightly different FTP folder names</p>
<p>Lack of FTP keepalive functionality in Nautilus has been one of my biggest gripes in Ubuntu for a long time now. It&#8217;s infuriating attempting to open a folder only to discover the session has timed out and I need to reconnect. Well that problem is now solved!</p>
<p>Run the following bash script in the background each time you boot and you&#8217;re good to go:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #666666; font-style: italic;">#10.10 and earlier</span>
	<span style="color: #c20cb9; font-weight: bold;">ls</span> ~<span style="color: #000000; font-weight: bold;">/</span>.gvfs<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ftp</span><span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
	<span style="color: #666666; font-style: italic;">#11.04+</span>
	<span style="color: #c20cb9; font-weight: bold;">ls</span> ~<span style="color: #000000; font-weight: bold;">/</span>.gvfs<span style="color: #000000; font-weight: bold;">/</span>FTP<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
	<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">15</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Many thanks go to the user who originally posted this script in a mailing list <a title="OSDir.com - ubuntu-bugs - [Bug 410288] Re: Nautilus does not handle FTP timeouts well - msg#12128" href="http://osdir.com/ml/ubuntu-bugs/2011-05/msg12128.html" target="_blank">here</a>.</p>
<p>PS. If anyone knows how to integrate this into a <a title="Nautilus File Manager Scripts: Questions and Answers" href="http://g-scripts.sourceforge.net/faq.php" target="_blank">nautilus script</a> I&#8217;d much appreciate it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/08/enable-ftp-keepalives-in-nautilus/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Fix Strange Web Page Widths on Android Browser</title>
		<link>http://www.flynsarmy.com/2011/08/how-to-fix-strange-web-page-widths-on-android-browser/</link>
		<comments>http://www.flynsarmy.com/2011/08/how-to-fix-strange-web-page-widths-on-android-browser/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 16:17:37 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=596</guid>
		<description><![CDATA[I'm currently working on a mobile version of an existing website utilizing the <a title="A List Apart: Articles: Responsive Web Design" href="http://www.alistapart.com/articles/responsive-web-design/" target="_blank">Responsive Web Design</a> paradigm. One problem I instantly came across was a perplexing page width issue on Android. Even with a blank, HTML5 webpage, the page width was appearing at almost twice the width of my phones native resolution (and 2.5x that of my browsers width). For the record, I'm using Android 2.3.3 vanilla with the default browser on a Nexus One.

Firstly an example:
<pre lang="html4strict" escaped="true">&#60;!DOCTYPE html&#62;
&#60;html xmlns="http://www.w3.org/1999/xhtml"&#62;
&#60;head&#62;
&#60;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&#62;
&#60;title&#62;Untitled Document&#60;/title&#62;
&#60;script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' /&#62;
&#60;script type='text/javascript'&#62;
	$(document).ready(function() {
		document.body.innerHTML = $(window).width();
	});
&#60;/script&#62;
&#60;/head&#62;
&#60;body&#62;
&#60;/body&#62;
&#60;/html&#62;</pre>
The above code gives a blank, HTML5 webpage that will display the pages width on load. When loaded, it would print '800' on the screen - indicating the page was set to an 800px width. This was clearly wrong.

I quickly noticed that using the following doctype:
<pre lang="html4strict" escaped="true">&#60;!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"&#62;</pre>
gave me the width I was expecting - 320px. Obviously this isn't an acceptable solution for responsive web design and so another was needed. Meet <a title="A tale of two viewports - part one" href="http://www.quirksmode.org/mobile/viewports.html" target="_blank">viewports</a>. With the addition of a simple META tag I was able to fix the issue (albeit losing the ability to zoom in the process). Simply add the following to your HEAD tag and you should be good to go:
<pre lang="html4strict" escaped="true">&#60;meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" /&#62;</pre>
With this line added, my page now prints 320 to the screen as it should.

For more information, please see <a title="How do I get the WVGA Android browser to stop scaling my images? - Stack Overflow" href="http://stackoverflow.com/questions/2796814/how-do-i-get-the-wvga-android-browser-to-stop-scaling-my-images/2799580" target="_blank">this StackOverflow post</a> on the issue.]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m currently working on a mobile version of an existing website utilizing the <a title="A List Apart: Articles: Responsive Web Design" href="http://www.alistapart.com/articles/responsive-web-design/" target="_blank">Responsive Web Design</a> paradigm. One problem I instantly came across was a perplexing page width issue on Android. Even with a blank, HTML5 webpage, the page width was appearing at almost twice the width of my phones native resolution (and 2.5x that of my browsers width). For the record, I&#8217;m using Android 2.3.3 vanilla with the default browser on a Nexus One.</p>
<p>Firstly an example:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Untitled Document<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'text/javascript'</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'text/javascript'</span>&gt;</span>
	$(document).ready(function() {
		document.body.innerHTML = $(window).width();
	});
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>The above code gives a blank, HTML5 webpage that will display the pages width on load. When loaded, it would print &#8217;800&#8242; on the screen &#8211; indicating the page was set to an 800px width. This was clearly wrong.</p>
<p>I quickly noticed that using the following doctype:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//WAPFORUM//DTD XHTML Mobile 1.0//EN&quot; &quot;http://www.wapforum.org/DTD/xhtml-mobile10.dtd&quot;&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>gave me the width I was expecting &#8211; 320px. Obviously this isn&#8217;t an acceptable solution for responsive web design and so another was needed. Meet <a title="A tale of two viewports - part one" href="http://www.quirksmode.org/mobile/viewports.html" target="_blank">viewports</a>. With the addition of a simple META tag I was able to fix the issue (albeit losing the ability to zoom in the process). Simply add the following to your HEAD tag and you should be good to go:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;viewport&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>With this line added, my page now prints 320 to the screen as it should.</p>
<p>For more information, please see <a title="How do I get the WVGA Android browser to stop scaling my images? - Stack Overflow" href="http://stackoverflow.com/questions/2796814/how-do-i-get-the-wvga-android-browser-to-stop-scaling-my-images/2799580" target="_blank">this StackOverflow post</a> on the issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/08/how-to-fix-strange-web-page-widths-on-android-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Return Custom Error Messages with JQuery Form Validations &#8216;Remote&#8217; Validator</title>
		<link>http://www.flynsarmy.com/2011/08/how-to-return-custom-error-messages-with-jquery-form-validations-remote-validator/</link>
		<comments>http://www.flynsarmy.com/2011/08/how-to-return-custom-error-messages-with-jquery-form-validations-remote-validator/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 03:27:51 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=589</guid>
		<description><![CDATA[It appears <a title="Plugins/Validation - jQuery JavaScript Library" href="http://docs.jquery.com/Plugins/Validation/" target="_blank">JQuery Form Validation</a> supports returning a string when using the <a title="Plugins/Validation/Methods/remote - jQuery JavaScript Library" href="http://docs.jquery.com/Plugins/Validation/Methods/remote#options" target="_blank">remote</a> validator but it's not immediately clear how to do this and the <em>examples</em> tab doesn't have an example for doing so. Getting this working is actually very easy. All you need to do is return a JavaScript string in your response. Here's an example:

Firstly, the javascript:
<pre lang="javascript">$(document).ready(function() {
	$("#form").validate({
		rules: {
			username: {
				required: true,
				remote: "/your/url.php"
			}
		},
		messages: {
			username: "Username is required."
		}
	});
});</pre>
Pretty standard, nothing out of the ordinary here. Now for the server side response. As I'm sure you're aware, you can return 'true' or 'false' however if you want a string, it needs to be formatted as a javascript string:
<pre lang="php">// /your/url.php
echo '"This username is already taken. Please enter a different username and try again."';</pre>]]></description>
				<content:encoded><![CDATA[<p>It appears <a title="Plugins/Validation - jQuery JavaScript Library" href="http://docs.jquery.com/Plugins/Validation/" target="_blank">JQuery Form Validation</a> supports returning an error string when using the <a title="Plugins/Validation/Methods/remote - jQuery JavaScript Library" href="http://docs.jquery.com/Plugins/Validation/Methods/remote#options" target="_blank">remote</a> validator but it&#8217;s not immediately clear how to do this and the <em>examples</em> tab doesn&#8217;t have an example for doing so. Getting this working is actually very easy. All you need to do is return a JavaScript string (complete with quotations) in your response. Here&#8217;s an example:</p>
<p>Firstly, the javascript:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#form&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		rules<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
			username<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
				required<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
				remote<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/your/url.php&quot;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		messages<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
			username<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Username is required.&quot;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>Pretty standard, nothing out of the ordinary here. Now for the server side response &#8211; be sure to remember the quotations and relevant escaping!:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// /your/url.php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&quot;This username is already taken. Please enter a different username and try again.&quot;'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
<!-- end from cahe -->
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/08/how-to-return-custom-error-messages-with-jquery-form-validations-remote-validator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Upload and Download via SSH Terminal</title>
		<link>http://www.flynsarmy.com/2011/06/upload-and-download-via-ssh-terminal/</link>
		<comments>http://www.flynsarmy.com/2011/06/upload-and-download-via-ssh-terminal/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 13:58:46 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=564</guid>
		<description><![CDATA[Tonight I needed to transfer files directly between two servers via the terminal and figured this would be useful information for others, so here's how to do it:

Upload to a remove server:
<pre lang="bash" escaped="true">$ ssh username@remote_address cat &#60; localfile "&#62;" remote_file</pre>
Download to your server:
<pre lang="bash" escaped="true">$ ssh username@remote_address cat remote_file &#62; local_file</pre>
<em>Source: <a title="[Linux] Upload and Download via SSH terminal" href="http://news.metaparadigma.de/linux-upload-and-download-via-ssh-terminal-226/" target="_blank">the incomplete news project</a></em>]]></description>
				<content:encoded><![CDATA[<p>Tonight I needed to transfer files directly between two servers via the terminal and figured this would be useful information for others, so here&#8217;s how to do it:</p>
<p>Upload to a remove server:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> username<span style="color: #000000; font-weight: bold;">@</span>remote_address <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&lt;</span> localfile <span style="color: #ff0000;">&quot;&gt;&quot;</span> remote_file</pre></td></tr></table></div>
<!-- end from cahe -->
<p>Download to your server:</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666;">$</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span> username<span style="color: #000000; font-weight: bold;">@</span>remote_address <span style="color: #c20cb9; font-weight: bold;">cat</span> remote_file <span style="color: #000000; font-weight: bold;">&gt;</span> local_file</pre></td></tr></table></div>
<!-- end from cahe -->
<p><em>Source: <a title="[Linux] Upload and Download via SSH terminal" href="http://news.metaparadigma.de/linux-upload-and-download-via-ssh-terminal-226/" target="_blank">the incomplete news project</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/06/upload-and-download-via-ssh-terminal/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>S3 Extension for Google Chrome with File Upload Support</title>
		<link>http://www.flynsarmy.com/2011/06/s3-extension-for-google-chrome-with-file-upload-support/</link>
		<comments>http://www.flynsarmy.com/2011/06/s3-extension-for-google-chrome-with-file-upload-support/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 03:53:19 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[amazon s3]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Google Chrome]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=551</guid>
		<description><![CDATA[I've been frustrated for a while now at Chromes lack of a decent Amazon S3 extension. Firefox has <a title="S3Fox Organizer(S3Fox)" href="http://www.s3fox.net/" target="_blank">S3Fox</a> but the closest Chrome users come is <a title="S3 - Chrome Web Store" href="https://chrome.google.com/webstore/detail/appeggcmoaojledegaonmdaakfhjhchf" target="_blank">S3</a> which only lets you browse and not modify the files in your buckets. Well that's just changed!

Over the weekend I finally gathered up enough free time to add support for creation and deletion of files/buckets. While I was in there I made a few other modifications to improve performance and clean things up a bit.

<a title="S3Browser - Chrome Web Store" href="https://chrome.google.com/webstore/detail/ojnelaaghkdnnihjbfigmcbndkomcnin?hl=en" target="_blank">Download the latest version</a> (and the source: <a title="Flynsarmy/chrome-s3 - GitHub" href="https://github.com/Flynsarmy/chrome-s3" target="_blank">Github repo</a>)
<div><dl id="attachment_552" class="wp-caption aligncenter" style="width: 310px;"> <dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/bucket-add.png"><img class="size-medium wp-image-552" title="Adding a bucket" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/bucket-add-300x191.png" alt="Adding a bucket" width="300" height="191" /></a></dt> <dd class="wp-caption-dd">Adding a bucket</dd> </dl></div>
<div><dl id="attachment_553" class="wp-caption aligncenter" style="width: 310px;"> <dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/bucket-delete.png"><img class="size-medium wp-image-553" title="Deleting a bucket" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/bucket-delete-300x191.png" alt="Deleting a bucket" width="300" height="191" /></a></dt> <dd class="wp-caption-dd">Delete link when hovering over buckets</dd> </dl></div>
<div><dl id="attachment_554" class="wp-caption aligncenter" style="width: 310px;"> <dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-add.png"><img class="size-medium wp-image-554" title="Adding files" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-add-300x191.png" alt="Adding files" width="300" height="191" /></a></dt> <dd class="wp-caption-dd">Multi-select file browser for uploading files</dd> </dl></div>
<div><dl id="attachment_556" class="wp-caption aligncenter" style="width: 310px;"> <dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-uploading.png"><img class="size-medium wp-image-556" title="Uploading Files" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-uploading-300x192.png" alt="Uploading Files" width="300" height="192" /></a></dt> <dd class="wp-caption-dd">The uploading window</dd> </dl></div>
<div><dl id="attachment_555" class="wp-caption aligncenter" style="width: 310px;"> <dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-delete.png"><img class="size-medium wp-image-555" title="File delete" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-delete-300x191.png" alt="File delete" width="300" height="191" /></a></dt> <dd class="wp-caption-dd">The confirmation you see when deleting files</dd> </dl></div>
<div><dl id="attachment_561" class="wp-caption aligncenter" style="width: 310px;"> <dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/Full-bucket-delete.png"><img class="size-medium wp-image-561" title="Deleting a bucket with files in it" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/Full-bucket-delete-300x192.png" alt="Deleting a bucket with files in it" width="300" height="192" /></a></dt> <dd class="wp-caption-dd">Error you see when attempting to delete a bucket with files in it</dd> </dl></div>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been frustrated for a while now at Chromes lack of a decent Amazon S3 extension. Firefox has <a title="S3Fox Organizer(S3Fox)" href="http://www.s3fox.net/" target="_blank">S3Fox</a> but the closest Chrome users come is <a title="S3 - Chrome Web Store" href="https://chrome.google.com/webstore/detail/appeggcmoaojledegaonmdaakfhjhchf" target="_blank">S3</a> which only lets you browse and not modify the files in your buckets. Well that&#8217;s just changed!</p>
<p>Over the weekend I finally gathered up enough free time to add support for creation and deletion of files/buckets. While I was in there I made a few other modifications to improve performance and clean things up a bit.</p>
<p><a title="S3Browser - Chrome Web Store" href="https://chrome.google.com/webstore/detail/ojnelaaghkdnnihjbfigmcbndkomcnin?hl=en" target="_blank">Download the latest version</a> (and the source: <a title="Flynsarmy/chrome-s3 - GitHub" href="https://github.com/Flynsarmy/chrome-s3" target="_blank">Github repo</a>)</p>
<div>
<dl id="attachment_552" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/bucket-add.png"><img class="size-medium wp-image-552" title="Adding a bucket" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/bucket-add-300x191.png" alt="Adding a bucket" width="300" height="191" /></a></dt>
<dd class="wp-caption-dd">Adding a bucket</dd>
</dl>
</div>
<div>
<dl id="attachment_553" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/bucket-delete.png"><img class="size-medium wp-image-553" title="Deleting a bucket" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/bucket-delete-300x191.png" alt="Deleting a bucket" width="300" height="191" /></a></dt>
<dd class="wp-caption-dd">Delete link when hovering over buckets</dd>
</dl>
</div>
<div>
<dl id="attachment_554" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-add.png"><img class="size-medium wp-image-554" title="Adding files" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-add-300x191.png" alt="Adding files" width="300" height="191" /></a></dt>
<dd class="wp-caption-dd">Multi-select file browser for uploading files</dd>
</dl>
</div>
<div>
<dl id="attachment_556" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-uploading.png"><img class="size-medium wp-image-556" title="Uploading Files" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-uploading-300x192.png" alt="Uploading Files" width="300" height="192" /></a></dt>
<dd class="wp-caption-dd">The uploading window</dd>
</dl>
</div>
<div>
<dl id="attachment_555" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-delete.png"><img class="size-medium wp-image-555" title="File delete" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/files-delete-300x191.png" alt="File delete" width="300" height="191" /></a></dt>
<dd class="wp-caption-dd">The confirmation you see when deleting files</dd>
</dl>
</div>
<div>
<dl id="attachment_561" class="wp-caption aligncenter" style="width: 310px;">
<dt class="wp-caption-dt"><a href="http://www.flynsarmy.com/wp-content/uploads/2011/06/Full-bucket-delete.png"><img class="size-medium wp-image-561" title="Deleting a bucket with files in it" src="http://www.flynsarmy.com/wp-content/uploads/2011/06/Full-bucket-delete-300x192.png" alt="Deleting a bucket with files in it" width="300" height="192" /></a></dt>
<dd class="wp-caption-dd">Error you see when attempting to delete a bucket with files in it</dd>
</dl>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/06/s3-extension-for-google-chrome-with-file-upload-support/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Log SQL Queries in Django</title>
		<link>http://www.flynsarmy.com/2011/06/how-to-log-sql-queries-in-django/</link>
		<comments>http://www.flynsarmy.com/2011/06/how-to-log-sql-queries-in-django/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 14:05:52 +0000</pubDate>
		<dc:creator>Flynsarmy</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.flynsarmy.com/?p=542</guid>
		<description><![CDATA[Earlier today I completed my first project in Django and it came time to do some database optimization. I wanted to get a list of SQL queries executed for each page and a bit of Googling let me to <a title="Django snippets: SQL Log Middleware w/query count &#38; exec time" href="http://djangosnippets.org/snippets/161/" target="_blank">this script</a> on DjangoSnippets. It did everything I needed it to do, however I noticed it interfered with dynamically generated binary file outputs (such as the images made with <a title="django-simple-captcha - A very simple, yet powerful, Django captcha application - Google Project Hosting" href="http://code.google.com/p/django-simple-captcha/" target="_blank">django-simple-captcha</a>). For this I needed to check if the output was in binary, and if so just return it without attempting to print the SQL log. I found what I was looking for <a title="test if a file or string is text or binary - Python recipes - ActiveState Code" href="http://code.activestate.com/recipes/173220-test-if-a-file-or-string-is-text-or-binary/" target="_blank">here</a> and after combining the two had the perfect SQL logger! Below is my finished code.
<pre lang="python" escaped="true" line="1" highlight="3,5,8,9,10,29,39,43">from django.db import connection
from django.template import Template, Context
import string

#http://djangosnippets.org/snippets/161/
class SQLLogMiddleware:
    def process_response ( self, request, response ):
        #Don't print SQL queries for binary outputs!
        if istext(response.content) == 0:
            return response

        time = 0.0
        for q in connection.queries:
            time += float(q['time'])

        t = Template('''
            &#60;p&#62;&#60;em&#62;Total query count:&#60;/em&#62; {{ count }}&#60;br/&#62;
            &#60;em&#62;Total execution time:&#60;/em&#62; {{ time }}&#60;/p&#62;
            &#60;ul class="sqllog"&#62;
                {% for sql in sqllog %}
                    &#60;li&#62;{{ sql.time }}: {{ sql.sql }}&#60;/li&#62;
                {% endfor %}
            &#60;/ul&#62;
        ''')

        response.content = "%s%s" % ( response.content, t.render(Context({'sqllog':connection.queries,'count':len(connection.queries),'time':time})))
        return response

#http://code.activestate.com/recipes/173220-test-if-a-file-or-string-is-text-or-binary/
def istext(s):
    if "\0" in s:
        return 0

    if not s:  # Empty files are considered text
        return 1

    # Get the non-text characters (maps a character to itself then
    # use the 'remove' option to get rid of the text characters.)
    t = s.translate(string.maketrans("", ""), "".join(map(chr, range(32, 127)) + list("\n\r\t\b")))

    # If more than 30% non-text characters, then
    # this is considered a binary file
    if float(len(t))/len(s) &#62;= 0.30:
        return 0</pre>
To get this working on your site just add it to your MIDDLEWARE_CLASSES in <em>settings.py</em> and make DEBUG is set to <em>True</em>.]]></description>
				<content:encoded><![CDATA[<p>Earlier today I completed my first project in Django and it came time to do some database optimization. I wanted to get a list of SQL queries executed for each page and a bit of Googling let me to <a title="Django snippets: SQL Log Middleware w/query count &amp; exec time" href="http://djangosnippets.org/snippets/161/" target="_blank">this script</a> on DjangoSnippets. It did everything I needed it to do, however I noticed it interfered with dynamically generated binary file outputs (such as the images made with <a title="django-simple-captcha - A very simple, yet powerful, Django captcha application - Google Project Hosting" href="http://code.google.com/p/django-simple-captcha/" target="_blank">django-simple-captcha</a>). For this I needed to check if the output was in binary, and if so just return it without attempting to print the SQL log. I found what I was looking for <a title="test if a file or string is text or binary - Python recipes - ActiveState Code" href="http://code.activestate.com/recipes/173220-test-if-a-file-or-string-is-text-or-binary/" target="_blank">here</a> and after combining the two had the perfect SQL logger! Below is my finished code.</p>
<!-- from cache -->
<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">db</span> <span style="color: #ff7700;font-weight:bold;">import</span> connection
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">template</span> <span style="color: #ff7700;font-weight:bold;">import</span> Template<span style="color: #66cc66;">,</span> Context
<span style="display:block;background-color: #ffc;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span></span>&nbsp;
<span style="display:block;background-color: #ffc;"><span style="color: #808080; font-style: italic;">#http://djangosnippets.org/snippets/161/</span></span><span style="color: #ff7700;font-weight:bold;">class</span> SQLLogMiddleware:
    <span style="color: #ff7700;font-weight:bold;">def</span> process_response <span style="color: black;">&#40;</span> <span style="color: #008000;">self</span><span style="color: #66cc66;">,</span> request<span style="color: #66cc66;">,</span> response <span style="color: black;">&#41;</span>:
<span style="display:block;background-color: #ffc;">        <span style="color: #808080; font-style: italic;">#Don't print SQL queries for binary outputs!</span></span><span style="display:block;background-color: #ffc;">        <span style="color: #ff7700;font-weight:bold;">if</span> istext<span style="color: black;">&#40;</span>response.<span style="color: black;">content</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">==</span> <span style="color: #ff4500;">0</span>:</span><span style="display:block;background-color: #ffc;">            <span style="color: #ff7700;font-weight:bold;">return</span> response</span>&nbsp;
        <span style="color: #dc143c;">time</span> <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">0.0</span>
        <span style="color: #ff7700;font-weight:bold;">for</span> q <span style="color: #ff7700;font-weight:bold;">in</span> connection.<span style="color: black;">queries</span>:
            <span style="color: #dc143c;">time</span> +<span style="color: #66cc66;">=</span> <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>q<span style="color: black;">&#91;</span><span style="color: #483d8b;">'time'</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
        t <span style="color: #66cc66;">=</span> Template<span style="color: black;">&#40;</span><span style="color: #483d8b;">'''</span>
<span style="color: #483d8b;">            &lt;p&gt;&lt;em&gt;Total query count:&lt;/em&gt; {{ count }}&lt;br/&gt;</span>
<span style="color: #483d8b;">            &lt;em&gt;Total execution time:&lt;/em&gt; {{ time }}&lt;/p&gt;</span>
<span style="color: #483d8b;">            &lt;ul class=&quot;sqllog&quot;&gt;</span>
<span style="color: #483d8b;">                {% for sql in sqllog %}</span>
<span style="color: #483d8b;">                    &lt;li&gt;{{ sql.time }}: {{ sql.sql }}&lt;/li&gt;</span>
<span style="color: #483d8b;">                {% endfor %}</span>
<span style="color: #483d8b;">            &lt;/ul&gt;</span>
<span style="color: #483d8b;">        '''</span><span style="color: black;">&#41;</span>
&nbsp;
        response.<span style="color: black;">content</span> <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">&quot;%s%s&quot;</span> % <span style="color: black;">&#40;</span> response.<span style="color: black;">content</span><span style="color: #66cc66;">,</span> t.<span style="color: black;">render</span><span style="color: black;">&#40;</span>Context<span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'sqllog'</span>:connection.<span style="color: black;">queries</span><span style="color: #66cc66;">,</span><span style="color: #483d8b;">'count'</span>:<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>connection.<span style="color: black;">queries</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><span style="color: #483d8b;">'time'</span>:<span style="color: #dc143c;">time</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> response
&nbsp;
<span style="display:block;background-color: #ffc;"><span style="color: #808080; font-style: italic;">#http://code.activestate.com/recipes/173220-test-if-a-file-or-string-is-text-or-binary/</span></span><span style="color: #ff7700;font-weight:bold;">def</span> istext<span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;"> </span>&quot;</span> <span style="color: #ff7700;font-weight:bold;">in</span> s:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> s:  <span style="color: #808080; font-style: italic;"># Empty files are considered text</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">1</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># Get the non-text characters (maps a character to itself then</span>
    <span style="color: #808080; font-style: italic;"># use the 'remove' option to get rid of the text characters.)</span>
<span style="display:block;background-color: #ffc;">    t <span style="color: #66cc66;">=</span> s.<span style="color: black;">translate</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">string</span>.<span style="color: black;">maketrans</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;&quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #008000;">chr</span><span style="color: #66cc66;">,</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">32</span><span style="color: #66cc66;">,</span> <span style="color: #ff4500;">127</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #008000;">list</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">n</span><span style="color: #000099; font-weight: bold;">r</span><span style="color: #000099; font-weight: bold;">t</span><span style="color: #000099; font-weight: bold;">b</span>&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></span>&nbsp;
    <span style="color: #808080; font-style: italic;"># If more than 30% non-text characters, then</span>
    <span style="color: #808080; font-style: italic;"># this is considered a binary file</span>
<span style="display:block;background-color: #ffc;">    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">float</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>/<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>s<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;=</span> <span style="color: #ff4500;">0.30</span>:</span>        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #ff4500;">0</span></pre></td></tr></table></div>
<!-- end from cahe -->
<p>To get this working on your site just add it to your MIDDLEWARE_CLASSES in <em>settings.py</em> and make DEBUG is set to <em>True</em>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flynsarmy.com/2011/06/how-to-log-sql-queries-in-django/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
