<?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>My Rant &#187; Computers</title>
	<atom:link href="http://www.myrant.net/category/computers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.myrant.net</link>
	<description></description>
	<lastBuildDate>Wed, 08 Feb 2012 09:43:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Symfony 1.4 Doctrine 1.2 MS SQL Server</title>
		<link>http://www.myrant.net/2012/02/02/symfony-1-4-doctrine-1-2-ms-sql-server/</link>
		<comments>http://www.myrant.net/2012/02/02/symfony-1-4-doctrine-1-2-ms-sql-server/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 00:03:57 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=310</guid>
		<description><![CDATA[Web server: Linux (Ubuntu on my dev setup), Apache, PHP 5.3, Symfony 1.4, Doctrine 1.2. Database server: Microsoft Windows 2008 Server, MS SQL Server Trying to get Symfony to talk to the database server has been a painful experience for the last few days. But perseverance has paid off. Lots of Googling with trial &#38; [...]]]></description>
			<content:encoded><![CDATA[<p>Web server: Linux (Ubuntu on my dev setup), Apache, PHP 5.3, Symfony 1.4, Doctrine 1.2.<br />
Database server: Microsoft Windows 2008 Server, MS SQL Server</p>
<p>Trying to get Symfony to talk to the database server has been a painful experience for the last few days. But perseverance has paid off.</p>
<p>Lots of Googling with trial &amp; error has resulted in actually achieving a development setup that will mirror the eventual production setup.</p>
<p>Short version:</p>
<ol>
<li>Follow the FreeTDS and ODBC setup instructions of <a href="http://jamesrossiter.wordpress.com/2011/03/08/connecting-to-microsoft-sql-server-using-odbc-from-ubuntu-server/">http://jamesrossiter.wordpress.com/2011/03/08/connecting-to-microsoft-sql-server-using-odbc-from-ubuntu-server/</a></li>
<li>Use the following in config/databases.yml</li>
</ol>
<pre name="code" class="yml">all:
  doctrine:
    class: sfDoctrineDatabase
      param:
        dsn: dblib:dbname=datasourcename;host=sqlserver;
        username: ###
        password: ###</pre>
<p>In the above snippit, replace &#8216;datasourcename&#8217; with whatever you used in /etc/odbc.ini and replace &#8216;sqlserver&#8217; with the name used in /etc/freetds/freetds.conf &amp; /etc/odbc.ini</p>
<p>It&#8217;s late and I&#8217;ve been struggling to get this working for some time. I may expand this entry in the future if required.</p>
<p>References and insperation:<br />
1) <a href="http://blog.acjacinto.com/2011/11/compiling-php-with-mssql-servers-native.html">http://blog.acjacinto.com/2011/11/compiling-php-with-mssql-servers-native.html</a><br />
2) <a href="http://www.microsoft.com/download/en/details.aspx?id=28160">http://www.microsoft.com/download/en/details.aspx?id=28160</a><br />
3) <a href="http://jamesrossiter.wordpress.com/2011/03/08/connecting-to-microsoft-sql-server-using-odbc-from-ubuntu-server/">http://jamesrossiter.wordpress.com/2011/03/08/connecting-to-microsoft-sql-server-using-odbc-from-ubuntu-server/</a><br />
4) <a href="http://trac.symfony-project.org/wiki/HowToConnectToMSSQLServer">http://trac.symfony-project.org/wiki/HowToConnectToMSSQLServer</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2012/02/02/symfony-1-4-doctrine-1-2-ms-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google calendar in Mozilla Thunderbird on Ubuntu 11.10</title>
		<link>http://www.myrant.net/2011/11/18/google-calendar-in-mozilla-thunderbird-on-ubuntu-11-10/</link>
		<comments>http://www.myrant.net/2011/11/18/google-calendar-in-mozilla-thunderbird-on-ubuntu-11-10/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 12:12:40 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=307</guid>
		<description><![CDATA[Via the Ubuntu Software Centre: Search for thunderbird Click on the search result &#8220;Thunderbird Email&#8221; and then on the &#8220;More Info&#8221; button Enable at least the &#8220;Calendar Extension for Thunderbird &#8211; Google Calendar support (xul-ext-gdata-provider)&#8221; Install the add-ons Open your Google Calendar in your web browser In the left-hand column, under &#8220;My calendars&#8221;, hover over [...]]]></description>
			<content:encoded><![CDATA[<p>Via the Ubuntu Software Centre:</p>
<ol>
<li>Search for thunderbird</li>
<li>Click on the search result &#8220;Thunderbird Email&#8221; and then on the &#8220;More Info&#8221; button</li>
<li>Enable at least the &#8220;Calendar Extension for Thunderbird &#8211; Google Calendar support (xul-ext-gdata-provider)&#8221;</li>
<li>Install the add-ons</li>
<li>Open your Google Calendar in your web browser</li>
<li>In the left-hand column, under &#8220;My calendars&#8221;, hover over the calendar of choice and click the down arrow that appears after the calendar name</li>
<li>Select &#8220;Calendar settings&#8221;</li>
<li>Close to the bottom of the page will be the &#8220;Calendar ID&#8221; (in my case it is my full email address. Make a note of this ID.</li>
<li>Start up Thunderbird upon completion.</li>
<li>File -&gt; New -&gt; Calendar</li>
<li>Select &#8220;On the Network&#8221; and click Next</li>
<li>Select &#8220;CalDAV&#8221;</li>
<li>In the Location field enter: https://www.google.com/calendar/dav/calendar.id.noted.in.point.8/events</li>
<li>Click Next then enter a name for the calendar and set an email account against it</li>
<li>When prompted, enter your username and password for accessing this calendar</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2011/11/18/google-calendar-in-mozilla-thunderbird-on-ubuntu-11-10/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fixing odd characters</title>
		<link>http://www.myrant.net/2011/08/04/fixing-odd-characters/</link>
		<comments>http://www.myrant.net/2011/08/04/fixing-odd-characters/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 15:54:54 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=296</guid>
		<description><![CDATA[One of the biggest complaints that web developers have is their lack of control over end users. When will we be able to tell them a) not to paste Micosoft Word or b) if you must, paste it into something that doesn&#8217;t do formatting 1st. It has a nasty habit of converting quotes into &#8220;smart&#8221; quotes as [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest complaints that web developers have is their lack of control over end users.</p>
<p>When will we be able to tell them a) not to paste Micosoft Word or b) if you must, paste it into something that doesn&#8217;t do formatting 1st.</p>
<p>It has a nasty habit of converting quotes into &#8220;smart&#8221; quotes as well as messing up characters such as the euro symbol €.</p>
<p>This is the fix I came up with that allows end users to continue to paste from such programs and bring their weird charset issues with them:</p>
<pre name="code" class="php">function fixChars($text)
{
  $chars = array(
    "/\xe2\x82\xac/" => "&amp;euro;",
    "/\xe2\x80\x99/" => "'",
    "/\xe2\x80\x9c/" => "&amp;#8220;", // open quotes
    "/\xe2\x80\x9d/" => "&amp;#8221;", // close quotes
    "/\xe2\x80\x93/" => "&amp;mdash;",

    "/\x80/" => "&amp;euro;",
    "/\x92/" => "'",
    "/\x93/" => "&amp;#8220;", // open quotes
    "/\x94/" => "&amp;#8221;", // close quotes
    "/\x96/" => "&amp;mdash;",
    "/\xa3/" => "&amp;pound;",
  );

  $find = array_keys($chars);
  $replace = array_values($chars);

  return preg_replace($find, $replace, $text);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2011/08/04/fixing-odd-characters/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Downloading SoundCloud Playlists</title>
		<link>http://www.myrant.net/2011/07/19/downloading-soundcloud-playlists/</link>
		<comments>http://www.myrant.net/2011/07/19/downloading-soundcloud-playlists/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 15:15:08 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=286</guid>
		<description><![CDATA[[Updated 7th Feb 2012 Changes: + file names are now as they would be if you downloaded via web browser + Playlist is now in reverse date uploaded order] I like to have music while I&#8217;m coding. It breaks the silence while working alone at home. When I have music playing, it&#8217;s best if I [...]]]></description>
			<content:encoded><![CDATA[<p>[Updated 7th Feb 2012<br />
Changes:<br />
+ file names are now as they would be if you downloaded via web browser<br />
+ Playlist is now in reverse date uploaded order]</p>
<p>I like to have music while I&#8217;m coding. It breaks the silence while working alone at home.</p>
<p>When I have music playing, it&#8217;s best if I don&#8217;t have to think about setting up playlists, which is why I used to listen to the radio. The radio has it&#8217;s limits though, not enough Ninja Tune I think.</p>
<p>Speaking of Ninja Tune, I &lt;3 their SolidSteel mixes <a href="http://soundcloud.com/ninja-tune/sets/solid-steel-radio-shows/">http://soundcloud.com/ninja-tune/sets/solid-steel-radio-shows/</a></p>
<p>What I don&#8217;t like is having to listen via my web browser and their music player in Flash. A recourse hog and not great if you want their music on a device disconnected from the &#8216;net.</p>
<p>Thankfully, with SoundCloud tracks, you can download any file you wish. The downside to it is that there&#8217;s a lot to download. What if you want a whole playlist? A playlist of (currently) 151 tracks for instance?</p>
<p>The script below will download all of the tracks in a set to a directory and create a .m3u playlist at the same time.</p>
<p>Please excuse the justified text and syntax-highlighting gone wrong. View plain, or copy to clipboard and it&#8217;ll be fine.</p>
<pre name="code" class="php">&lt;?php
$baseDir = "mp3s";
$soundcloudURL = "http://soundcloud.com/ninja-tune/sets/solid-steel-radio-shows/"; 

$urlBits = str_replace('http://', '', $soundcloudURL);
$urlBits = preg_replace('@/$@', '', $urlBits);
$urlBits = explode("/", $urlBits);

/**
 * http://soundcloud.com/ninja-tune/sets/solid-steel-radio-shows/
 * Array
 * (
 *     [0] => soundcloud.com
 *     [1] => ninja-tune
 *     [2] => sets
 *     [3] => solid-steel-radio-shows
 * )
 */

array_shift($urlBits);
$storage_dir = $baseDir . "/" . implode("/", $urlBits);
if (!file_exists($storage_dir))
{
	mkdir($storage_dir, 0755, true);
}

$playListFile = $storage_dir . "/" . $urlBits[count($urlBits) - 1] . ".m3u";
if (file_exists($playListFile))
{
	unlink($playListFile);
}

$playList = array();

$file = getPage($soundcloudURL);
if (!$file) die ("Can't get SoundCloud page\n");

$rows = explode("\n", $file);

$uris = array();
$pattern = '@"/.+download"@i';
$baseURL = 'http://soundcloud.com';
foreach ($rows as $row)
{
	preg_match($pattern, $row, $matches);
	if (count($matches) > 0)
	{
		$uris[] = str_replace("\"", '', $matches[0]);
	}
}

$i = 0;
$uriCount = count($uris);
foreach ($uris as $uri)
{
	$i++;
	echo "\nFetching file " . $i . " of " . $uriCount . "\n";

	$uriHeaders = get_headers($baseURL . $uri);
	foreach ($uriHeaders as $header)
	{
		preg_match("/^Content\-Disposition\: attachment\;filename=\"(.*)\"$/", $header, $matches);
		if (isset($matches[1]))
		{
			$outputFilename = $matches[1];
			break;
		}
	}

	$playList[] = $outputFilename;

	if (file_exists($storage_dir . "/" . $outputFilename))
	{
		echo "File exists, skipping.\n";
		continue;
	}

	$command = "wget " . $baseURL . $uri . " -O " . $storage_dir . "/" . $outputFilename;
	`$command`;
}

echo "\nWriting play list\n";
file_put_contents($playListFile, implode("\n", array_reverse($playList)), FILE_APPEND);
echo "\nDone\n";

function getPage($url, $referer = false, $timeout = 30, $header = false)
{
	$curl = curl_init();

	if(strstr($referer,"://")){
		curl_setopt ($curl, CURLOPT_REFERER, $referer);
	}

	curl_setopt ($curl, CURLOPT_URL, $url);
	curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout);
	curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
	curl_setopt ($curl, CURLOPT_HEADER, (int)$header);
	curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);

	$html = curl_exec ($curl);
	curl_close ($curl);

	return $html;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2011/07/19/downloading-soundcloud-playlists/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>wp-block as a shortcode</title>
		<link>http://www.myrant.net/2011/03/21/wp-block-as-a-shortcode/</link>
		<comments>http://www.myrant.net/2011/03/21/wp-block-as-a-shortcode/#comments</comments>
		<pubDate>Mon, 21 Mar 2011 16:54:32 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=282</guid>
		<description><![CDATA[In my last post I raved about the excellent plugin wp-blocks by Keir Whitaker and then went on to extend it a little. Time to extend it a little further, this time by adding a shortcode. Shortcodes are the handy square bracketed code snippets which conjure up more content and functionality direct from a page [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post I raved about the excellent plugin <a href="http://wordpress.org/extend/plugins/wp-blocks/" target="_blank">wp-blocks</a> by <a href="http://keirwhitaker.com/" target="_blank">Keir Whitaker</a> and then went on to extend it a little.</p>
<p>Time to extend it a little further, this time by adding a shortcode.</p>
<p>Shortcodes are the handy square bracketed code snippets which conjure up more content and functionality direct from a page or post content.</p>
<p>The wp-blocks plugin is currently intended to work with the theme template files in PHP. Unfortunately (or fortunately?) PHP does not get parsed within the content areas. This does stop malicious code from being included, but it does limit things when you know what you&#8217;re doing.</p>
<p>The following code will give you a short code to work with which looks similar to the PHP code snippit you would include in your theme template file.</p>
<pre name="code" class="php">  /**
   * Gets the block data by 'name' and returns it for use in a content shortcode
   * Requires http://wordpress.org/extend/plugins/wp-blocks/
   *
   * @param string $name
   * @return string
   * @author Iain Cuthbertson
   */
  function get_wp_block_shortcode( $atts ) {
    extract( shortcode_atts( array(
      'name' =&gt; '',
    ), $atts ) );

    global $wpdb;
    $block_slug = trim($name);
    $data = (array)$wpdb-&gt;get_row("SELECT * FROM {$wpdb-&gt;prefix}wpb_content WHERE name = '{$name}' AND active = TRUE");
    if($data) return get_wrapped_block_content($data);
  }

  add_shortcode('get_wp_block', 'get_wp_block_shortcode');
</pre>
<p>Add that to your theme&#8217;s functions.php file and then you will be able to add blocks to your content with, for example:</p>
<pre name="code">&#91;get_wp_block name="foo"&#93;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2011/03/21/wp-block-as-a-shortcode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting a random wp-block by regex</title>
		<link>http://www.myrant.net/2011/03/18/getting-a-random-wp-block-by-regex/</link>
		<comments>http://www.myrant.net/2011/03/18/getting-a-random-wp-block-by-regex/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 10:10:04 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=277</guid>
		<description><![CDATA[If you&#8217;re used to developing with a CMS such as CMS Made Simple, you would be quite used to having blocks of content separate from the main content system. These blocks can be re-used through-out existing content and within the theme templates. One might even consider this a core function for a CMS. Sadly it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re used to developing with a CMS such as <a title="cmsmadesimple.org" href="http://www.cmsmadesimple.org/" target="_blank">CMS Made Simple</a>, you would be quite used to having blocks of content separate from the main content system. These blocks can be re-used through-out existing content and within the theme templates.</p>
<p>One might even consider this a core function for a CMS. Sadly it&#8217;s missing from WordPress. <a title="keirwhitaker.com" href="http://keirwhitaker.com/" target="_blank">Keir Whitaker</a> has been working on this missing option and gives us <a title="wordpress.org/extend/plugins/wp-blocks" href="http://wordpress.org/extend/plugins/wp-blocks/" target="_blank">wp-blocks</a>.</p>
<p>It&#8217;s a great little plugin, though it currently has a couple of niggles:</p>
<ul>
<li>Apostrophes are escaped in the output: \&#8217;</li>
<li>One can&#8217;t call a block from inside content, it has to be from the theme template.</li>
</ul>
<p>Despite this, I&#8217;m glad that he&#8217;s made the plugin available for public use.</p>
<p>Now, time to extend it!</p>
<p>As with global content blocks in CMS Made Simple, wp-blocks does not offer a way to fetch a random content block. I fixed this in CMS Made Simple by writing the <a title="dev.cmsmadesimple.org/projects/rgcb" href="http://dev.cmsmadesimple.org/projects/rgcb" target="_blank">Random Global Content Block</a> plugin.</p>
<p>Now I&#8217;ve done something similar for wp-blocks:</p>
<pre name="code" class="php">/**
 * Gets a random block data by 'regex'
 * Requires http://wordpress.org/extend/plugins/wp-blocks/
 *
 * @param string $block_slug_regex
 * @return string
 * @author Iain Cuthbertson
 */
function get_wp_block_random($block_slug_regex) {
  global $wpdb;
  $block_slug_regex = trim($block_slug_regex);
  $data = (array)$wpdb-&gt;get_results("SELECT id FROM {$wpdb-&gt;prefix}wpb_content WHERE name REGEXP '{$block_slug_regex}' AND active = TRUE"); 
  if (isset($data) &amp;&amp; is_array($data) &amp;&amp; count($data) &gt; 0)
  {
    $arrayIndex = array();
    foreach ($data as $row)
    {
      $arrayIndex[] = $row-&gt;id;
    }
    $randomIndex = mt_rand(0, count($arrayIndex) - 1);

    return get_wp_block_by_id($arrayIndex[$randomIndex]);
  }
}</pre>
<p>Copy that code into your theme&#8217;s functions.php and then call from within your template with, as an example:</p>
<pre name="code" class="php">&lt;?php get_wp_block_random('^testimonial_'); ?&gt;</pre>
<p>This will then fetch a wp-block with a name starting with testimonial_.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2011/03/18/getting-a-random-wp-block-by-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mimicking wordpress.com&#8217;s image resize URIs</title>
		<link>http://www.myrant.net/2011/03/07/mimicking-wordpress-coms-image-resize-uris/</link>
		<comments>http://www.myrant.net/2011/03/07/mimicking-wordpress-coms-image-resize-uris/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 17:02:47 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=261</guid>
		<description><![CDATA[To follow up from last night&#8217;s entry, I was determined to remove the intermediary step of my_resize_script.php. I&#8217;ve acheived this goal in the mod_rewrite rule, file name and query string now get passed on to timthumb.php. Updated rules: RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_URI} \.(gif&#124;png&#124;jpg&#124;jpeg) RewriteCond %{QUERY_STRING} (w&#124;h)=(.*)$ RewriteRule (.*) /full/path/to/timthumb.php?src=$1&#38;%1=%2&#38;%3=%4 [L] This will pass both [...]]]></description>
			<content:encoded><![CDATA[<p>To follow up from <a title="Resize images on the fly without messing with image URLs" href="http://www.myrant.net/2011/03/07/resize-images-on-the-fly-without-messing-with-image-urls/">last night&#8217;s entry</a>, I was determined to remove the intermediary step of my_resize_script.php.</p>
<p>I&#8217;ve acheived this goal in the mod_rewrite rule, file name and query string now get passed on to <a href="http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/" target="_blank">timthumb.php</a>.</p>
<p>Updated rules:</p>
<pre name="code">RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} \.(gif|png|jpg|jpeg)
RewriteCond %{QUERY_STRING} (w|h)=(.*)$
RewriteRule (.*) /full/path/to/timthumb.php?src=$1&amp;%1=%2&amp;%3=%4 [L]</pre>
<p>This will pass both width and height variables into timthumb if they are declared.</p>
<p>Quick breakdown of the rules:</p>
<ol>
<li>Check that the URI exists as a file.</li>
<li>Check that the URI in question is an image. Expand to other formats as needed.</li>
<li>Check that one or both of width and height are being altered.</li>
<li>Pass the file following to timthumb as variables:<br />
$1 = filename<br />
%1 = w or h<br />
%2 = value of w or h<br />
%3 = w or h<br />
%4 = value of w or h</li>
</ol>
<p>If conditions 1 to 3 all return true, then the rewrite rule in 4 will be executed.</p>
<p>In summary, the URI<br />
<code>http://myrant.net/wp-content/uploads/2010/03/high_res_horsey.png?w=300&amp;h=100</code></p>
<p>Will be passed on as<br />
<code>http://myrant.net/timtumb.php?src=wp-content/uploads/2010/03/high_res_horsey.png&amp;w=300&amp;h=100</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2011/03/07/mimicking-wordpress-coms-image-resize-uris/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Resize images on the fly without messing with image URLs</title>
		<link>http://www.myrant.net/2011/03/07/resize-images-on-the-fly-without-messing-with-image-urls/</link>
		<comments>http://www.myrant.net/2011/03/07/resize-images-on-the-fly-without-messing-with-image-urls/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 00:12:18 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=251</guid>
		<description><![CDATA[[EDIT: I've made this simpler with a follow up post: Mimicking wordpress.com’s image resize URIs] Exporting a wordpress.com site for use on a standalone wordpress.org install is a joy to set up. The export and import system are simple to use and give little or no issues. What is a problem is the automatic resizing [...]]]></description>
			<content:encoded><![CDATA[<p><span style="background-color: #404040; color: #ffcc00;">[EDIT: I've made this simpler with a follow up post: </span><a title="Mimicking wordpress.com’s image resize URIs" href="http://www.myrant.net/2011/03/07/mimicking-wordpress-coms-image-resize-uris/"><span style="background-color: #404040; color: #ffcc00;">Mimicking wordpress.com’s image resize URIs</span></a><span style="background-color: #404040; color: #ffcc00;">]</span></p>
<p>Exporting a wordpress.com site for use on a standalone wordpress.org install is a joy to set up. The export and import system are simple to use and give little or no issues.</p>
<p>What is a problem is the automatic resizing of images that wordpress.com offers.</p>
<p>One can insert an image in the normal way and then append the image URI with some variables such as width (w) and height (h). This is also a d options, I assume this is for depth, but haven&#8217;t looked into it yet.</p>
<p>So an image URI might be http://myrant.net/wp-content/uploads/2010/03/high_res_horsey.png?w=300</p>
<p>This URI would display the image resized to 300px wide and retain the aspect ratio.</p>
<p>Currently, wordpress.org do not offer this facility (that I have seen). So I&#8217;ve been working on how it might be done:</p>
<p>1st off, we need to set up a mod_rewrite rule to cater for image URIs that have query string variables. This can be added to a vhost config or the site&#8217;s .htaccess file. I prefer to use .htaccess</p>
<pre name="code" class="text">RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} \.(gif|png|jpg|jpeg)
RewriteCond %{QUERY_STRING} (w|h)=(.*)$
RewriteRule (.*) /my_resize_script.php?file=$1 [L]</pre>
<p>Then we need a script (my_resize_script.php) to make use of the variables.</p>
<pre name="code" class="php">&lt;?php
$urlBits = explode("?", $_SERVER['REQUEST_URI']);
$queryString = explode("&amp;", $urlBits[1]);
$urlVars = array('file' =&gt; $_GET['file']);
foreach ($queryString as $bit)
{
	$varBits = explode("=", $bit);
	$urlVars[$varBits[0]] = $varBits[1];
}
?&gt;
&lt;pre&gt;&lt;?php print_r($urlVars); ?&gt;&lt;/pre&gt;</pre>
<p>The output of this script as it is would be:</p>
<pre class="text" name="code">Array
(
    [file] =&gt; wp-content/uploads/2010/03/high_res_horsey.png
    [w] =&gt; 300
)</pre>
<p>As you can see, I&#8217;m not actually making use of the variables yet. But all of the information that it does extract can be given to a proper resize script, such as <a href="http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/" target="_blank">TimThumb</a>.</p>
<p>This is all a bit messy right now. I would much rather be able to pass variables directly into a resize script rather than have to use an intermediary one. If anybody wants to give some pointers, please do <img src='http://www.myrant.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2011/03/07/resize-images-on-the-fly-without-messing-with-image-urls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating WordPress site URLs for different hosts</title>
		<link>http://www.myrant.net/2011/03/03/updating-wordpress-site-urls-for-different-hosts/</link>
		<comments>http://www.myrant.net/2011/03/03/updating-wordpress-site-urls-for-different-hosts/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 09:33:54 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=245</guid>
		<description><![CDATA[Why oh why does WordPress insist on storing the site URLs within the database? Every other project I can think of either keeps it in a config file or doesn&#8217;t bother with one and just works with whatever URL it finds itself on. This is most irritating when you have: more than one developer working [...]]]></description>
			<content:encoded><![CDATA[<p>Why oh why does WordPress insist on storing the site URLs within the database?<br />
Every other project I can think of either keeps it in a config file or doesn&#8217;t bother with one and just works with whatever URL it finds itself on.</p>
<p>This is most irritating when you have:</p>
<ul>
<li>more than one developer working on the same project</li>
<li>more than one system for hosting the project (dev, test, live, etc)</li>
</ul>
<p>One way to cope with this irritation is to have a collection of .sql files to handily update the database from the CLI.</p>
<p>For example, a WP site has the URL <a href="http://www.idophp.co.uk" target="_blank">www.idophp.co.uk</a> on a live host and uses idophp.iain on a dev host.</p>
<p>We would have 2 .sql files such as live_options.sql and dev_options.sql.</p>
<p>In live_options.sql:</p>
<pre name="code" class="sql">UPDATE wp_options SET option_value = REPLACE(option_value, 'http://idophp.iain', 'http://www.idophp.co.uk') WHERE option_value LIKE 'http://idophp.iain%';</pre>
<p>In dev_options.sql:</p>
<pre name="code" class="sql">UPDATE wp_options SET option_value = REPLACE(option_value, 'http://www.idophp.co.uk', 'http://idophp.iain') WHERE option_value LIKE 'http://www.idophp.co.uk%';</pre>
<p>These settings can be imported over the top of a database without altering anything but the site URLs using:</p>
<pre name="code" class="bash">$ mysql -u idophp -p idophp &lt; live_options.sql</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2011/03/03/updating-wordpress-site-urls-for-different-hosts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get sfFormExtraPlugin working in Symfony 1.4 using Doctrine</title>
		<link>http://www.myrant.net/2010/10/17/how-to-get-sfformextraplugin-working-in-symfony-1-4-using-doctrine/</link>
		<comments>http://www.myrant.net/2010/10/17/how-to-get-sfformextraplugin-working-in-symfony-1-4-using-doctrine/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 01:49:08 +0000</pubDate>
		<dc:creator>Iain</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.myrant.net/?p=208</guid>
		<description><![CDATA[I&#8217;m talking about this plugin: http://www.symfony-project.org/plugins/sfFormExtraPlugin For some reason, getting the plugin to work took a lot of Googling and some trial and error. So here is how I got it working. Hopefully I did this in the &#8216;correct&#8217; way&#8230; cd plugins wget "http://plugins.symfony-project.org/get/sfFormExtraPlugin/sfFormExtraPlugin-1.1.3.tgz" tar zxvf sfFormExtraPlugin-1.1.3.tgz mv sfFormExtraPlugin-1.1.3 sfFormExtraPlugin cd .. ./symfony plugin:publish-assets cd [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m talking about this plugin: <a href="http://www.symfony-project.org/plugins/sfFormExtraPlugin" target="_blank">http://www.symfony-project.org/plugins/sfFormExtraPlugin</a></p>
<p>For some reason, getting the plugin to work took a lot of Googling and some trial and error.<br />
So here is how I got it working. Hopefully I did this in the &#8216;correct&#8217; way&#8230;</p>
<pre name="code" class="php">cd plugins
wget "http://plugins.symfony-project.org/get/sfFormExtraPlugin/sfFormExtraPlugin-1.1.3.tgz"
tar zxvf sfFormExtraPlugin-1.1.3.tgz
mv sfFormExtraPlugin-1.1.3 sfFormExtraPlugin
cd ..
./symfony plugin:publish-assets
cd web/js
wget "http://code.jquery.com/jquery-1.4.3.min.js"
wget "http://jqueryui.com/download/jquery-ui-1.8.5.custom.zip"
mkdir jquery-ui
cd jquery-ui
unzip ../jquery-ui-1.8.5.custom.zip
mv jquery-ui/css/smoothness ../css</pre>
<p>Edit config/ProjectConfiguration.class.php to add sfFormExtraPlugin as an enabled plugin:</p>
<pre name="code" class="php">class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this-&gt;enablePlugins(array('sfDoctrinePlugin', 'sfFormExtraPlugin'));
  }
}</pre>
<p>Edit apps/&lt;app_name&gt;/config/view.yml to include the JS and CSS:</p>
<pre name="code" class="php">
  stylesheets:    [main.css, smoothness/jquery-ui-1.8.5.custom.css]

  javascripts:    [jquery-1.4.3.min.js, jquery-ui/js/jquery-ui-1.8.5.custom.min.js]
</pre>
<p>Edit lib/form/doctrine/&lt;your_module_name&gt;Form.class.php to make use of the widgets you want. I&#8217;m interested in sfWidgetFormJQueryDate:</p>
<pre name="code" class="php">
  public function configure()
  {
    $this->widgetSchema['created_at'] = new sfWidgetFormJQueryDate(array(
      'image' => '/images/silk_icons/calendar.png',
      'config' => '{}',
    ));
    $this->widgetSchema['updated_at'] = new sfWidgetFormJQueryDate(array(
      'image' => '/images/silk_icons/calendar.png',
      'config' => '{}',
    ));
  }
</pre>
<p>I have used the calendar.png icon from the famfamfam silk icon set. You can get the set here: <a href="http://www.famfamfam.com/lab/icons/silk/" target="_blank">http://www.famfamfam.com/lab/icons/silk/</a></p>
<p>I&#8217;ve used the date picker widget for filling in the created_at and updated_at fields. You can replace these values with the fields you need to manipulate in a user friendly way.</p>
<p>[Edit 17/10/2010:]<br />
I&#8217;m not going mad, there is an issue with the &#8216;magic&#8217; fields created_at and updated_at in that they have to be unset to become magic.<br />
Found help here: <a href="http://levelx.me/technology/programming/symfony-1-4-doctrine-timestampable-behaviour/" target="_blank">http://levelx.me/technology/programming/symfony-1-4-doctrine-timestampable-behaviour/</a><br />
Though the unset lines are better off being added just once to /lib/form/doctrine/BaseFormDoctrine.class.php, rather than each xxxForm.class.php file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.myrant.net/2010/10/17/how-to-get-sfformextraplugin-working-in-symfony-1-4-using-doctrine/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

