<?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>Ed&#039;s World &#187; php</title>
	<atom:link href="http://www.jellard.co.uk/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jellard.co.uk</link>
	<description>Bringing data into real life in a meaningful way</description>
	<lastBuildDate>Fri, 14 May 2010 15:00:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MythTweet &#8211; Twitter MythTV recordings</title>
		<link>http://www.jellard.co.uk/2010/03/mythtweet-twitter-mythtv-recordings/</link>
		<comments>http://www.jellard.co.uk/2010/03/mythtweet-twitter-mythtv-recordings/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 21:32:39 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[mythtv]]></category>
		<category><![CDATA[mythTweet]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=164</guid>
		<description><![CDATA[In the move to put as much of my house onto twitter as possible, MythTV was the next victim.  I&#8217;d previously made a PHP script that sent MSN alerts, but now I don&#8217;t use MSN, it needed a revamp.

I knocked up a small PHP script that grabs the backend status, finds what is being [...]]]></description>
			<content:encoded><![CDATA[<p>In the move to put as much of my house onto twitter as possible, MythTV was the next victim.  I&#8217;d previously made a PHP script that sent MSN alerts, but now I don&#8217;t use MSN, it needed a revamp.</p>
<p><img src="http://www.jellard.co.uk/wp-content/uploads/2010/03/Screenshot-1.png" alt="MythTweet" /></p>
<p>I knocked up a small PHP script that grabs the backend status, finds what is being recorded or watched, compares with the previous run, and sends a message to twitter using wget.</p>
<p>To use it, grab the <a href="http://www.jellard.co.uk/wp-content/uploads/2010/03/mythTweet.phps">script</a>, change the username/password variables, chmod +x it, and then add it to your &#8220;Startup Applications&#8221; or equivalent if you&#8217;re not using Ubuntu.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2010/03/mythtweet-twitter-mythtv-recordings/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Handwritten post-it notes generated from Google Calendar</title>
		<link>http://www.jellard.co.uk/2010/02/handwritten-post-it-notes-generated-from-google-calendar/</link>
		<comments>http://www.jellard.co.uk/2010/02/handwritten-post-it-notes-generated-from-google-calendar/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 20:44:26 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[GD]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scouts]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=186</guid>
		<description><![CDATA[ I&#8217;ve recently created a new website for my scout group, Highfield Scouts, and have put up a google calendar.  More out of a challenge than a real need, I&#8217;ve knocked up a script that uses the Google Data API for PHP to query my calendar feed, grab the next event, and make a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/2010/02/scouts4.jpg" style="float: left; margin: 10px;" alt="Scouts" /> I&#8217;ve recently created a new website for my scout group, <a href="http://www.highfieldscouts.org.uk">Highfield Scouts</a>, and have put up a google calendar.  More out of a challenge than a real need, I&#8217;ve knocked up a script that uses the <a href="http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html">Google Data API for PHP</a> to query my calendar feed, grab the next event, and make a fake handwritten postit note.  The script runs every hour to keep the images up to date.</p>
<p>I&#8217;ve made a little markup system so that the whole postit can be a link, and the time and location can be overridden (child protection malarky &#8211; can&#8217;t just put a time and location for some things!)</p>
<p>It&#8217;s all written in PHP, using the GD graphics features to put the text on a background image.  If you&#8217;re interested in the code, comment, and I&#8217;ll give it to you (if you link to me!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2010/02/handwritten-post-it-notes-generated-from-google-calendar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web based photo galleries &#8211; the unusable and the reasonable</title>
		<link>http://www.jellard.co.uk/2009/11/web-based-photo-galleries-the-unusable-and-the-reasonable/</link>
		<comments>http://www.jellard.co.uk/2009/11/web-based-photo-galleries-the-unusable-and-the-reasonable/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 23:22:37 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[photo gallery]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scouts]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=112</guid>
		<description><![CDATA[So, after yesterday&#8217;s Pinewood Derby with funky racing traffic lights, I looked for a simple, quick photo album tool to display the photos, and stumbled on Piwigo, which looked reasonable and the whole &#8220;Simple powerful&#8221; philosophy seemed to match what I wanted.  So, I downloaded the single php installer script, which automagically downloads the latest [...]]]></description>
			<content:encoded><![CDATA[<p>So, after yesterday&#8217;s Pinewood Derby with funky <a href="http://www.jellard.co.uk/2009/11/scout-racing-lights-naturally-arduino-powered/">racing traffic lights</a>, I looked for a simple, quick photo album tool to display the photos, and stumbled on <a href="http://piwigo.org/" target="_blank">Piwigo</a>, which looked reasonable and the whole &#8220;Simple powerful&#8221; philosophy seemed to match what I wanted.  So, I downloaded the single php installer script, which automagically downloads the latest version and installs everything.  So far, so good.</p>
<p>Now to actually create an album.  Yes, pretty easy. Upload a file, not so easy, but doable.  Get that file to be shown &#8211; next to impossible.  This is the worlds most convoluted software I have ever seen!  To get a photo to be shown, you first have to syncronise, then go and create thumbnails &#8211; but wait, by default the synchronise does a dummy run, so go back and tick a tick-box.  Grr, really not usable.  So, I tried looking at the documentation (which goes against my beliefs of websites should never, ever, need any help &#8211; they should be usable) and even that is appauling!  It&#8217;s a wiki with a very poor navigation structure (if there is any structure), so impossible to find anything useful.  Turn to the forums to find others having the same problem, and being told to read the instructions&#8230;</p>
<p>Right, rant over, software uninstalled.</p>
<p><a href="http://www.plogger.org/" target="_blank">Plogger</a> was the next on the list, the demo looked clean and simple &#8211; just what I needed (PHP/MySQL based).  Installed it in a couple of minutes, saw a test album had been created for me so uploaded a photo and job done &#8211; it was there!  Then spent the next hour cropping and adjusting the photos, uploaded them, and bob&#8217;s your uncle, I have a nice and simple photo gallery for the scouts!  The styling is very minimal, it&#8217;s designed to be part of a larger site, although there is one style that&#8217;s a little less minimal which I&#8217;ve gone for as there&#8217;s no &#8220;larger site&#8221; for this.</p>
<p>So steer clear of piwigo, and let me know if you have any recommendations&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/11/web-based-photo-galleries-the-unusable-and-the-reasonable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to tweet from your website with your own tinyurl URL shortening service</title>
		<link>http://www.jellard.co.uk/2009/10/how-to-tweet-from-your-website-with-your-own-tinyurl-url-shortening-service/</link>
		<comments>http://www.jellard.co.uk/2009/10/how-to-tweet-from-your-website-with-your-own-tinyurl-url-shortening-service/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 19:51:39 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tinyurl]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=55</guid>
		<description><![CDATA[As this is my first post about Magic Hat, a little introduction.  Magic Hat is a site for magicians to learn magic, with over 50 thousand users.  I started it in 2004, and since then have gradually (or not so gradually) being changing it.  We&#8217;re now at the 8th major redesign.  [...]]]></description>
			<content:encoded><![CDATA[<p>As this is my first post about Magic Hat, a little introduction.  Magic Hat is a site for magicians to learn magic, with over 50 thousand users.  I started it in 2004, and since then have gradually (or not so gradually) being changing it.  We&#8217;re now at the 8th major redesign.  It started as a good way to learn PHP/MySQL/HTML, so I didn&#8217;t touch any content management systems, and wrote the entire first 3 versions with linux&#8217;s best text editor, vim!  I then treated myself to using Eclipse, which saves a lot of work &#8211; Ctrl + Space and your website&#8217;s done (I wish!).  Then I chucked in a phpBB forum, modified it and my site so that they&#8217;re nicely integrated.  Finally, I changed to using smarty templates, which has made changing the look of the site in the last few versions significantly easier &#8211; would highly recommend it.</p>
<p>So, you&#8217;ve probably gathered that I&#8217;ll happily reinvent the wheel many times over, but hopefully for a good result.  Magic Hat is very dynamic and has lots of complicated features that I don&#8217;t think would have been feasible to get working in something like WordPress without having to learn and change most of WP.</p>
<p>I&#8217;ve setup the Magic Hat forums to tweet every time someone posts, but I didn&#8217;t really want to use tinyurl/bit.ly as I&#8217;d like to keep magichat.co.uk in the links.  So, here&#8217;s some code that creates the smallest possible hash.</p>
<p><span id="more-55"></span></p>
<pre><code style="font-size: 9px;">$letters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
function getHash($i) {
        $string = "";
        while ($i &gt;= strlen($letters)) {
                $string = substr($letters, $i % strlen($letters), 1) . $string;
                $i = floor($i / strlen($letters));
        }
        $string = substr($letters, $i, 1) . $string;
        return $string;
}
function getNumFromHash($string) {
        $letters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $k = 0;
        $count = 0;
        for ($j = strlen($string) - 1; $j &gt;= 0; $j--) {
                $letter = substr($string, $j, 1);
                $indexOfLetter = strpos($letters, $letter);
                $k += $indexOfLetter * pow(strlen($letters), $count);
                $count++;
        }
        return $k;
}
</code></pre>
<p>So, whenever I want to twitter something, I stick an entry in a database table with the URL and text contents.  I grab the auto incrementing ID from the primary key, and pass it into getHash().  Then I run this:</p>
<pre><code style="font-size: 9px;">$twitters = sql_array("SELECT id, message, link FROM twitter WHERE sent = 0 ORDER BY id");
if (count($twitters[0]) &gt; 0) {
        foreach ($twitters as $t) {
                $linkLength = 0;
                $link = "";
                $message = $t['message'];
                if (strlen($t['link']) &gt; 0) {
                        $link = "http://magichat.co.uk/w/".function_getHash($t['id']);
                        $linkLength = strlen($link) + 1;
                        $message = substr($message, 0, 140 - $linkLength);
                        $message .= " ".$link;
                }
                $message = urlencode($message);
                $ch = curl_init('http://twitter.com/statuses/update.json');
                curl_setopt ($ch, CURLOPT_POST, true);
                curl_setopt ($ch, CURLOPT_POSTFIELDS, 'status='.$message);
                curl_setopt($ch, CURLOPT_USERPWD, 'magichatuk:PASSWORD');
                curl_setopt($ch, CURLOPT_VERBOSE, 0);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,10);
                $response = curl_exec($ch);
                curl_close($ch);
                sql_update("twitter", "sent = 1", "id = ".$t['id']);
        }
}</code></pre>
<p>sql_array and sql_update are a couple of functions that I&#8217;ve written to do stuff with the database, and cache results etc.</p>
<p>The code ensures the full URL is present by shrinking the text if need be.</p>
<p>This line in my .htaccess file directs everything starting /w/ to tinyurl.php</p>
<pre><code style="font-size: 9px;">RewriteRule ^w/(.+)    /tinyurl.php?hash=$1</code></pre>
<p>tinyurl.php:</p>
<pre><code style="font-size: 9px;">
$string = $_GET['hash'];
$k = getNumFromHash($string);
$url = sql_result("link", "ma_twitter", "id = $k");
sql_update("ma_twitter", "hits = hits + 1", "id = $k");
header("Location:http://www.magichat.co.uk".$url);
</code></pre>
<p>And the job&#8217;s done!  Doing it this way (without using tinyurl) means that you can jump to #anchors on the page.</p>
<p>See it in action at <a href="http://twitter.com/magichatuk">http://twitter.com/magichatuk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/10/how-to-tweet-from-your-website-with-your-own-tinyurl-url-shortening-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
