<?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>Tortoise IT &#187; Tutorials</title>
	<atom:link href="http://www.sean-barton.co.uk/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sean-barton.co.uk</link>
	<description>Homepage of Sean Barton, a freelance website developer from Cheshire</description>
	<lastBuildDate>Sat, 19 Jun 2010 12:24:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Recursive PHP function for finding a top level parent post</title>
		<link>http://www.sean-barton.co.uk/2010/06/recursive-php-function-for-finding-a-top-level-parent-post/</link>
		<comments>http://www.sean-barton.co.uk/2010/06/recursive-php-function-for-finding-a-top-level-parent-post/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 23:16:14 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=449</guid>
		<description><![CDATA[So&#8230; the name says it all doesn&#8217;t it! Here&#8217;s the story.. I wanted to apply different sidebar widget areas in Wordress for different pages.
One of the sites I am working on has three top level pages which will form three distinct sections of the site. I decided that it would be good to show different [...]]]></description>
			<content:encoded><![CDATA[<p>So&#8230; the name says it all doesn&#8217;t it! Here&#8217;s the story.. I wanted to apply different sidebar widget areas in Wordress for different pages.</p>
<p>One of the sites I am working on has three top level pages which will form three distinct sections of the site. I decided that it would be good to show different sets of widgets within these sections and therefore had to concoct a way to determine from any page it&#8217;s top level parent page. The function below simply returns true or false if the first argument is a child of the second. It also returns true if the first argument is the same as the second.</p>
<p><strong>The Function</strong></p>
<pre>function page_has_parent($current_page, $target_parent=0) {
	global $wpdb;

	$return = false;

	if ($current_page == $target_parent) {
		$return = true;
	} else {
		$sql = 'SELECT post_parent
			FROM ' . $wpdb-&gt;posts . '
			WHERE ID = ' . $current_page;
		if ($parent = $wpdb-&gt;get_var($sql)) {
			if ($parent == $target_parent) {
				$return = true;
			} else if ($parent) {
				$return = page_has_parent($parent, $target_parent);
			}
		}
	}

	return $return;
}</pre>
<p><strong>The Usage</strong></p>
<p>The following is a Wordpress example of showing one sidebar or the other based on page</p>
<pre>$this_page = get_the_ID();
if (page_has_parent($this_page, 7)) {
	dynamic_sidebar('Sidebar2');
} else if (page_has_parent($this_page, 11)) {
	dynamic_sidebar('Sidebar2');
} else ....</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2010/06/recursive-php-function-for-finding-a-top-level-parent-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SB Author Comments: Author Commenting plugin for Wordpress</title>
		<link>http://www.sean-barton.co.uk/2010/04/sb-author-comments-author-commenting-plugin-for-wordpress/</link>
		<comments>http://www.sean-barton.co.uk/2010/04/sb-author-comments-author-commenting-plugin-for-wordpress/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 19:27:22 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[comment author]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Wordpress Plugins]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=422</guid>
		<description><![CDATA[To my knowledge it&#8217;s not possible to comment on an author in Wordpress. &#8220;Why would you want to do that?&#8221; you ask&#8230; Well for example a client of mine is running a classifieds site using the Classipress theme. The site uses classifieds as jobs for people to do and the people posting and signing up [...]]]></description>
			<content:encoded><![CDATA[<p>To my knowledge it&#8217;s not possible to comment on an author in Wordpress. &#8220;Why would you want to do that?&#8221; you ask&#8230; Well for example a client of mine is running a classifieds site using the Classipress theme. The site uses classifieds as jobs for people to do and the people posting and signing up to the site are tradesmen. Comments, in this case, can be used as a feedback system and therefore are a valuable addition.</p>
<p>The wp_comments table doesn&#8217;t have support or scope to store comments with an associated user (as opposed to post). At this juncture I would have inserted a null (or 0) value into the post_id column and added a row into the wp_commentmeta table with the user ID it refers to. However, I didn&#8217;t write the core code for the project so I simply updated a neat little system written by <em>Dan Wellman</em>. Dan&#8217;s system is pretty good and uses AJAX and JSON to add comments to a new database table with two fields (author and comment). It was what I would call &#8216;a good start&#8217; as DB details were required in a number of different files and the database had room for improvement. I have a few more plans for the code but for now have changed a couple of things and bundled it into a Wordpress plugin for you.</p>
<p>In my version the database table is created for you, it has several more fields including a primary key (!), timestamps and room for additional information (not currently utilised) to be stored. The Wordpress database class is used now so no duplication of the connection details is necessary.</p>
<p>Take a look at the plugin and comments and suggestions for additions are very welcome.</p>
<p><strong>Download</strong><br />
<a class="downloadlink" href="http://www.sean-barton.co.uk/wp-content/plugins/download-monitor/download.php?id=17" title="Version 1 downloaded 59 times" >SB Author Comments (1.84 KB)</a></p>
<p><strong>Usage</strong><br />
Upload and activate the plugin as normal. Then add the following code to your author.php theme template making sure to edit the $author_id variable as appropriate.</p>
<pre>&lt;?php
if (function_exists('sb_ac_comment_form')) {
echo sb_ac_comment_form($author_id);
}
?&gt;</pre>
<p><strong>Credit</strong><br />
Once again credit goes to <em>Dan Wellman</em> who detailed the integration into his site on his <a href="http://net.tutsplus.com/tutorials/php/asynchronous-comments-with-jquery-and-json/" target="_blank">blog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2010/04/sb-author-comments-author-commenting-plugin-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to convert your site to Wordpress</title>
		<link>http://www.sean-barton.co.uk/2010/03/how-to-convert-your-site-to-wordpress/</link>
		<comments>http://www.sean-barton.co.uk/2010/03/how-to-convert-your-site-to-wordpress/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 12:00:25 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Personal Blog]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Wordpress migration]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=413</guid>
		<description><![CDATA[I recently had a conversation with someone who had decided to come to Wordpress to take advantage of a plugin or two and wanted to know how to get an existing site into the correct theme structure as required. It took a lengthy email or two to explain but it struck me that lots of [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-416" title="Wordpress Logo" src="http://www.sean-barton.co.uk/wp-content/uploads/2010/03/23-wordpress_logo.png" alt="Wordpress Logo" width="154" height="154" />I recently had a conversation with someone who had decided to come to Wordpress to take advantage of a plugin or two and wanted to know how to get an existing site into the correct theme structure as required. It took a lengthy email or two to explain but it struck me that lots of people must be asking the same questions over and over. So in this post i shall try to explain how to get a theme together, or rather where to start</p>
<p><em>So&#8230; first, a bit of logic</em></p>
<p>Logically speaking a standard layout web page can be split into four distinct areas as follows:</p>
<ul>
<li>Header</li>
<li>Footer</li>
<li>Sidebar(s)</li>
<li>Content</li>
</ul>
<p>And as such Wordpress uses different theme files to render the appropriate sections. We need to split our HTML page into those different files. There are, however, lines of code that Wordpress needs you to put into each of these files and so tbe best way todo this without missing anything is to recycle another theme. So&#8230; go to your Wordpress install and visit <em>/wp-content/themes/</em> and&#8230;</p>
<ol>
<li>Duplicate the directory called &#8216;<em>default</em>&#8216;</li>
<li>Open style.css in a text editor and edit the name of the theme and any other information you feel like</li>
<li>Either remove or replace <em>screenshot.jpg</em> from the theme directory so it looks different in the theme menu</li>
</ol>
<p>That&#8217;s it, you now have a skeleton to work from and it&#8217;s time to make it look like your site. Let&#8217;s assume you have a simple brochureware site and, therefore, don&#8217;t need any blog type pages. Largely these sites have a standard consistent layout on each page (often except the home page but that difference is for another tutorial) and Wordpress uses this consistency to slot in the appropriate information for each page. We do this by&#8230;</p>
<ol>
<li>Choose a short yet typical page from your site and view the HTML source</li>
<li>Open 4 separate text files from the new theme directory in your favourite text editor. They are: <em>header.php, footer.php, sidebar.php and page.php</em></li>
<li>From the HTML source take the top section of code (usually as far as the content and sidebar code inclusive of a menu assuming you are using a top horizontal bar navigation) and place it into <em>header.php</em> making sure to preserve the obvious dynamic sections of code (anything between <em>&lt;?php</em> and <em>?&gt;</em> can be assumed to be dynamic)</li>
<li>Do the same with the footer into<em> footer.php</em> (the section below the content and sidebar that often contains SEO links and copyright notices)</li>
<li>The remaining block should contain the content and sidebar code&#8230; simply cut out the sidebar code into <em>sidebar.php</em></li>
<li>Finally split the content code into the bit before the text and the bit after the text (ie: layout code stripping out the text itself). Then paste these sections around the &#8216;while&#8217; loop within <em>page.php</em>.</li>
<li>(optional) copy your stylesheet into style.css making sure to preserve the comment at the top of the file as this is used by Wordpress to define the theme and without which will not pick up any of the code.</li>
</ol>
<p>Step 6 will likely be the most difficult to do as there are three or four important lines of PHP code in there. Firstly the line that reads &lt;?php get_header(); ?&gt; is the code that calls header.php. Likewise &lt;?php get_footer(); ?&gt; and &lt;?php get_sidebar(); ?&gt; call their appropriate namesakes. Make sure that they are in the correct logical positions for the page to render in the right order.</p>
<p><strong>The Loop</strong></p>
<p>The hardest section is what is called &#8216;the loop&#8217; by Wordpress bods. This is the section of code that shows the post(s) from the database relative to the page you are looking at. The Loop often falls into the following form:</p>
<pre>&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
 &lt;div id="post-&lt;?php the_ID(); ?&gt;"&gt;
 &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
 &lt;div&gt;
 &lt;?php the_content('&lt;p&gt;Read the rest of this page &amp;raquo;&lt;/p&gt;'); ?&gt;

 &lt;?php wp_link_pages(array('before' =&gt; '&lt;p&gt;&lt;strong&gt;Pages:&lt;/strong&gt; ', 'after' =&gt; '&lt;/p&gt;', 'next_or_number' =&gt; 'number')); ?&gt;

 &lt;/div&gt;
 &lt;/div&gt;
 &lt;?php endwhile; endif; ?&gt;</pre>
<p>You shouldn&#8217;t really need to change any of the code itself but you might need to edit the encapsulating HTML to make your styles fit in. For example if your page titles are not in H2 tags then you need to change it to suit etc etc&#8230;</p>
<p><strong>Testing it!</strong></p>
<p>This will always be a case of trial and error until you know what you are doing so don&#8217;t worry if it all goes pear shaped. That&#8217;s what the undo button is for!</p>
<p>To test that your theme is working properly then you need to visit your sites back end at <em>/wp-admin</em> and click the link on the left hand side called &#8216;<em>appearance</em>&#8216;. The themes page will appear and to activate your theme you simply find it in the list and click &#8216;activate&#8217;. Then view the front end of the site and see what it looks like.</p>
<p>At this stage you might be confused because the home page looks different to the rest of the site. This is because, by default, Wordpress uses the <em>index.php</em> file from your theme directory to generate the home page. To change this visit the <em>settings -&gt; reading</em> page from the left menu and use the dropdown box to choose an appropriate page to be used for the home page.</p>
<p><strong>What&#8217;s next?</strong></p>
<p>Ok so your theme looks like it did before you spent hours making the them for the Wordpress site&#8230; why on earth are we using Wordpress at all you ask! Well if you were to create a new page for your old site then you would have to duplicate an HTML file, trawl through code (or look at Dreamweaver or another WYSIWYG) to find the sections to replace before uploading to your site and updating the links in the various menus as appropriate. With Wordpress you just add a &#8216;<em>page</em>&#8216; using the nice admin system and it&#8217;s all done for you.</p>
<p>I always tell my clients to go and have a look at the Wordpress plugins directory for ideas and things to ad to their site. A word of warning though, some plugins conflict with others and too many plugins might slow your site down considerably. Over time you will get used to a core few you know and trust.</p>
<p><em>Feel free to ask me any questions about Wordpress, PHP or other and hopefully I will be able to help you decide what&#8217;s the best direction for your site to take. Expect a lecture about how good Wordpress is though!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2010/03/how-to-convert-your-site-to-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Live Countdown Timer using Javascript</title>
		<link>http://www.sean-barton.co.uk/2009/10/live-countdown-timer-using-javascript/</link>
		<comments>http://www.sean-barton.co.uk/2009/10/live-countdown-timer-using-javascript/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 10:52:40 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Teaching]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[timer]]></category>
		<category><![CDATA[Wordpress Plugins]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=350</guid>
		<description><![CDATA[Been done? Yes of course it has! However you don&#8217;t learn anything unless you get stuck in and have a go yourself and that is exactly what I did during an empty half hour period I had the other day (slow lecture). Whilst at university I am doing a lot of timed tasks (ten minutes [...]]]></description>
			<content:encoded><![CDATA[<p>Been done? Yes of course it has! However you don&#8217;t learn anything unless you get stuck in and have a go yourself and that is exactly what I did during an empty half hour period I had the other day (slow lecture). Whilst at university I am doing a lot of timed tasks (ten minutes etc.. as opposed to days) and the timers used are always a mobile phone timer or horrible Powerpoint countdown presentation. I wanted to write something which is simple to build on to create a JS version to ultimately integrate into online resources and lessons (Eg: this task will take you ten minutes. Click here to turn on the timer&#8230;).</p>
<p>The  code at the bottom of this post is the raw HTML file I wrote. I obviously made it into a Wordpress plugin as well. see below example.</p>
<p><strong>Example</strong></p>
<p>Yes, it&#8217;s basic but it works well for demonstrative purposes.</p>
<div id="countdown_body_wrapper">
                <form id="countdown_form" onsubmit="return do_countdown();">
                    Countdown from: <input style="width: 50px;" id="value" />
                    <select id="countdown_unit">
                        <option value="1">Seconds</option>
                        <option value="60">Minutes</option>
                        <option value="3600">Hours</option>
                    </select>
                    <input type="submit" value="Go" />
                </form>
                <div id="countdown_div"></div>
            </div>
<p><strong>Usage</strong></p>
<p>write sb_countdown in square brackets in a post or page and you will get the above example. If you want to edit the text or style it then just open the plugin file and right near the top is a few defines to get you going. I didn&#8217;t spend a lot of time on it so didn&#8217;t create an admin page. I may well do in the future though.</p>
<p><strong>The Download</strong></p>
<a class="downloadlink" href="http://www.sean-barton.co.uk/wp-content/plugins/download-monitor/download.php?id=15" title="Version 1 downloaded 288 times" >SB JS Countdown Timer (1.42 KB)</a>
<p><strong>Raw HTML Version</strong></p>
<pre>&lt;html&gt;
 &lt;head&gt;
 &lt;title&gt;Countdown Timer&lt;/title&gt;

 &lt;style&gt;
 body {
 font-family: tahoma;
 }

 #countdown_div {
 font-weight: bold;
 font-size: 56px;
 }

 #body_wrapper {
 padding: 10px;
 margin: 20px;
 }
 &lt;/style&gt;

 &lt;script&gt;
 function do_countdown() {
 var start_num = document.getElementById("value").value;
 var unit_var = document.getElementById("countdown_unit").value;

 start_num = start_num * parseInt(unit_var);

 var countdown_output = document.getElementById('countdown_div');

 if (start_num &gt; 0) {
 countdown_output.innerHTML = format_as_time(start_num);
 var t=setTimeout("update_clock(\"countdown_div\", "+start_num+")", 1000);
 }

 return false;
 }

 function update_clock(countdown_div, new_value) {
 var countdown_output = document.getElementById(countdown_div);
 var new_value = new_value - 1;

 if (new_value &gt; 0) {
 new_formatted_value = format_as_time(new_value);
 countdown_output.innerHTML = new_formatted_value;

 var t=setTimeout("update_clock(\"countdown_div\", "+new_value+")", 1000);
 } else {
 countdown_output.innerHTML = "And... Stop!";
 }
 }

 function format_as_time(seconds) {
 var minutes = parseInt(seconds/60);
 var seconds = seconds - (minutes*60);

 if (minutes &lt; 10) {
 minutes = "0"+minutes;
 }

 if (seconds &lt; 10) {
 seconds = "0"+seconds;
 }

 var return_var = minutes+':'+seconds;

 return return_var;
 }
 &lt;/script&gt;
 &lt;/head&gt;

 &lt;body&gt;
 &lt;div id="body_wrapper"&gt;
 &lt;form id="countdown_form" onsubmit="return do_countdown();"&gt;
 Countdown from: &lt;input style="width: 50px;" id="value" /&gt;
 &lt;select id="countdown_unit"&gt;
 &lt;option value="1"&gt;Seconds&lt;/option&gt;
 &lt;option value="60"&gt;Minutes&lt;/option&gt;
 &lt;option value="3600"&gt;Hours&lt;/option&gt;
 &lt;/select&gt;
 &lt;input type="submit" value="Go" /&gt;
 &lt;/form&gt;
 &lt;div id="countdown_div"&gt;&amp;nbsp;&lt;/div&gt;
 &lt;/div&gt;
 &lt;/body&gt;

&lt;/html&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/10/live-countdown-timer-using-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Learning Event Generator</title>
		<link>http://www.sean-barton.co.uk/2009/09/learning-event-generator/</link>
		<comments>http://www.sean-barton.co.uk/2009/09/learning-event-generator/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 18:32:05 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Personal Blog]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[lesson planning]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=343</guid>
		<description><![CDATA[The learning event generator is something which I was shown on the first day of my PGCE. It was demonstrated and was intriguing to say the least! It would be an interesting way to allow the children we teach to decide their own activities.
I have been in a coding mood today so thought that I [...]]]></description>
			<content:encoded><![CDATA[<p>The learning event generator is something which I was shown on the first day of my PGCE. It was demonstrated and was intriguing to say the least! It would be an interesting way to allow the children we teach to decide their own activities.</p>
<p>I have been in a coding mood today so thought that I would bash together a tiny little PHP script to emulate the same thing. Yes it&#8217;s basic but works from two text files which are defined in the first few lines of the file itself. It&#8217;s not the most elegant bit of code I have ever written but if you know anything about PHP or have a web server then why not have a fiddle and see what you can make it do?</p>
<p>Consider this&#8230; it doesn&#8217;t have to be learning events. Why not use it as a kind of &#8216;What shall we do tomorrow?&#8217; kind of thing. eg: &#8216;Do a 5 mile run with a friend dressed as a horse&#8217; or &#8216;Do go out and get a bit merry&#8217;.</p>
<p><strong>The Code</strong></p>
<pre>&lt;?php

$cwd = getcwd();
$outcome_source = $cwd . '/' . 'activities.txt';
$method_source = $cwd . '/' . 'methods.txt';

$outcomes = file($outcome_source);
$methods = file($method_source);

$outcome = trim($outcomes[array_rand($outcomes)]);
$method = trim($methods[array_rand($methods)]);

echo 'Do ' . $outcome . ' as a ' . $method . '.';

?&gt;</pre>
<p><strong>The Download</strong></p>
<p>The file is available as a download here: <a class="downloadlink" href="http://www.sean-barton.co.uk/wp-content/plugins/download-monitor/download.php?id=14" title="Version 1 downloaded 216 times" >Learning Event Generator (1.23 KB)</a></p>
<p><strong>References</strong></p>
<p>The original idea is available on the following <a title="Learning Event Generator Homepage" href="http://www.newtools.org/showtxt.php?docid=724" target="_blank">website</a> and is credited to John Davitt</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/09/learning-event-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP File Rename Script</title>
		<link>http://www.sean-barton.co.uk/2009/09/php-file-rename-script/</link>
		<comments>http://www.sean-barton.co.uk/2009/09/php-file-rename-script/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 16:20:32 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=339</guid>
		<description><![CDATA[Ever downloaded an archive of files and all of them had file names about 200 characters wrong with the same string in each? It&#8217;s more common that you might think&#8230; If you look at any audio archives you may have acquired, the chances are that the file names will have the quality in it (192 [...]]]></description>
			<content:encoded><![CDATA[<p>Ever downloaded an archive of files and all of them had file names about 200 characters wrong with the same string in each? It&#8217;s more common that you might think&#8230; If you look at any audio archives you may have acquired, the chances are that the file names will have the quality in it (192 or 128 etc..). Additionally if you have video files the resolution or quality might be present.</p>
<p>I, for one, don&#8217;t really care what the quality is in the file name and would prefer it to be readable. I spend a lot of time removing this extraneous data so decided to make a short PHP script to remove certain strings on mass.</p>
<p>See the following code which can be run from the command line using the following format:</p>
<pre>php -f &lt;filename&gt; &lt;text_to_remove&gt; [int live_mode=0]</pre>
<p><strong>Code</strong></p>
<pre>#!/usr/bin/php

  [int live_mode=0]';
    exit;
} else {
    $remove = $argv[1];
}

$live_mode = (int)$argv[2];

if ($dir = scandir($cwd)) {
    foreach ($dir as $file) {
        $path = $cwd . '/' . $file;

        if (!in_array($file, $ignore)) {
            if (!is_link($path) &amp;&amp; !is_dir($path)) {
                if (strpos($file, $remove) !== false &amp;&amp; $file != $_SERVER['SCRIPT_FILENAME'] &amp;&amp; $file != $remove) {
                    $output .= 'Renamed "' . $path . '" to "' . $cwd . '/' . trim(str_replace($remove, '', $file)) . '"' . "\n";

                    if ($live_mode) {
                        $new_path = $cwd . '/' . trim(str_replace($remove, '', $file));
                        rename($path, $new_path);
                    }
                }
            }
        }
    }

    if ($output) {
        $output = ($live_mode ? 'LIVE':'TEST') . ' MODE' . "\n\n" . 'Text to remove from filenames was "' . $remove . '"' . "\n\n" . $output;
    } else {
        $output = 'There were no matches by your criteria: "' . $remove . '"';
    }    

    echo $output . "\n\n";
}

?&gt;
</pre>
<p><strong>Download</strong></p>
<p>To download the code in file form click the following link: <a class="downloadlink" href="http://www.sean-barton.co.uk/wp-content/plugins/download-monitor/download.php?id=13" title="Version 1 downloaded 199 times" >File Rename Script (783 bytes)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/09/php-file-rename-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The REAL Auto Increment</title>
		<link>http://www.sean-barton.co.uk/2009/08/the-real-auto-increment/</link>
		<comments>http://www.sean-barton.co.uk/2009/08/the-real-auto-increment/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 13:48:54 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Auto Increment]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Mysql Tables]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=313</guid>
		<description><![CDATA[I came across an interesting problem today. Not something that most people will realise or care about but something which seemed to absorb a good hour of my life searching for a solution.
Here goes..
MySQL tables, like any other, have an auto increment value to determine the next in line when inserting new data. How do [...]]]></description>
			<content:encoded><![CDATA[<p>I came across an interesting problem today. Not something that most people will realise or care about but something which seemed to absorb a good hour of my life searching for a solution.</p>
<p>Here goes..</p>
<p>MySQL tables, like any other, have an auto increment value to determine the next in line when inserting new data. How do we preempt this data though? How do we get the next insert ID before we insert the data? I can almost hear you now reeling off the following code:</p>
<pre>SELECT MAX(id)+1 FROM table1;</pre>
<p>You are wrong&#8230; What happens if you have 100 rows in &#8216;table1&#8242;.. the next insert is 101 right? wrong. We don&#8217;t have enough data to make anything other than an educated (and usually correct) guess.</p>
<p>Let me explain&#8230; What happens if you inserted a row by accident. This is easily done when the programmer doesn&#8217;t use single use tokens on insert queries. You then have to delete that row. What then would the next insert value be? 102 is the answer.</p>
<p>There is a MySQL command to allow you to get a list of table information within which is the Auto Increment value as follows:</p>
<pre>SHOW TABLE STATUS LIKE 'table1';</pre>
<p>There are two downsides to using this method..</p>
<ol>
<li>Your host might not allow you to use SHOW on your database meaning it would either result in an access denied or no recordset.</li>
<li>The data is not sortable or filterable. This means you need to use some PHP logic to get the actual Auto Increment value from the recordset.</li>
</ol>
<p>It isn&#8217;t that bad actually getting the data out of the recordset using PHP. See the following example using Wordpress database calls:</p>
<pre>$sql = 'SHOW TABLE STATUS LIKE "wp_nmv_version"';
$status = $wpdb-&gt;get_row($sql);
echo $status-&gt;Auto_increment;</pre>
<p>So if knowing the correct Auto Increment is vital to your system bare this article in mind before proceeding.</p>
<p><em>If anyone has any idea how to tidy this process up a bit to remove the PHP element from the filtering process then I would be glad to listen.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/08/the-real-auto-increment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSS Enclosures in Wordpress Vs Content Protection (YM)</title>
		<link>http://www.sean-barton.co.uk/2009/07/rss-enclosures-in-wordpress-vs-content-protection-ym/</link>
		<comments>http://www.sean-barton.co.uk/2009/07/rss-enclosures-in-wordpress-vs-content-protection-ym/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 11:27:54 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=309</guid>
		<description><![CDATA[I have just completed an email exchange with a YM client which lasted around 50 replies and a good month. More down to my hectic schedule than anything else but I, with Googles help, have just solved it.
As you well know I work with Tim Nash over at CNMS and between us we develop and [...]]]></description>
			<content:encoded><![CDATA[<p>I have just completed an email exchange with a <a title="Newmedias, home of Your Members" href="http://www.newmedias.co.uk" target="_blank">YM</a> client which lasted around 50 replies and a good month. More down to my hectic schedule than anything else but I, with Googles help, have just solved it.</p>
<p>As you well know I work with <a title="Tims homepage" href="http://www.timnash.co.uk" target="_blank">Tim Nash</a> over at <a title="Newmedias" href="http://www.newmedias.co.uk" target="_blank">CNMS</a> and between us we develop and sell the <a title="Your Members Homepage" href="http://www.newmedias.co.uk/wordpress-membership/" target="_blank">Your Members</a> plugin. The plugin protects blog content based on member levels and then provides the means to pay for access using a variety of methods. &lt;/plug&gt;</p>
<p>It&#8217;s pretty standard stuff. However&#8230; What happens if you want to add some sort of streaming media to the protected section in a blog post?</p>
<p><strong>It doesn&#8217;t work is the answer!</strong> Ever helpful Wordpress scans the post for the presence of certain HTML strings and adds post custom fields if it gets a hit. This is the case for podcasting and flash type plugins. Normally this would be a good thing, however, not when the Object in question is <em>supposed</em> to be protected. A pretty bit security hole in any content protection plugin.</p>
<p>At the most basic level the protection can be restored using the following code&#8230;</p>
<pre>function delete_enclosure(){
    return '';
}

add_filter( 'get_enclosed', 'delete_enclosure' );
add_filter( 'rss_enclosure', 'delete_enclosure' );
add_filter( 'atom_enclosure', 'delete_enclosure' );</pre>
<p>The code should be put into either a new plugin or more simply your functions.php file within your theme. Dead easy!</p>
<p>If you understand it, the code simply picks up on any filters and removes them. Problem solved.  For YM, the next step is not to remove the enlosure if the user should have access. Additionally we don&#8217;t want to remove the enclosure if the object is outside of the protected content area. However the function above will suffice for now <img src='http://www.sean-barton.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/07/rss-enclosures-in-wordpress-vs-content-protection-ym/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Converting any number to a Currency (or 2 decimal places)</title>
		<link>http://www.sean-barton.co.uk/2009/05/converting-any-number-to-a-currency-or-2-decimal-places/</link>
		<comments>http://www.sean-barton.co.uk/2009/05/converting-any-number-to-a-currency-or-2-decimal-places/#comments</comments>
		<pubDate>Fri, 29 May 2009 15:31:56 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Convert Currency]]></category>
		<category><![CDATA[Converting Currency]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=287</guid>
		<description><![CDATA[Yes it sounds fairly elementary doesn&#8217;t it&#8230; yet I can&#8217;t find a PHP function to just do it?
If, like me, you store your currency values in your database as integers (don&#8217;t ask why, I just do) then you need to multiply by 100 on the way in and divide by 100 on the way out.
The [...]]]></description>
			<content:encoded><![CDATA[<p>Yes it sounds fairly elementary doesn&#8217;t it&#8230; yet I can&#8217;t find a PHP function to just do it?</p>
<p>If, like me, you store your currency values in your database as integers (don&#8217;t ask why, I just do) then you need to multiply by 100 on the way in and divide by 100 on the way out.</p>
<p>The obvious problem (or maybe not so obvious) is that when multiplying a number 100.1 is different to 100.10 and therefore the former needs to be converted to 100.10 for the resultant number to be correct.</p>
<p>The following function simply does that whilst checking for the occurence of a decimal place and concatenating .00 in that situation.</p>
<pre>function convert_to_currency($num) {
    if (strpos($num, '.') == false) {
        $num = $num . '.00';
    } else {
        $num = sprintf("%01.2f", (float)$num);
    }
    return $num;
}</pre>
<p>This should reliably format the number ready to be manipulated for either a database or to be directly output.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/05/converting-any-number-to-a-currency-or-2-decimal-places/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing a Microsoft Office Product Key</title>
		<link>http://www.sean-barton.co.uk/2009/04/changing-a-microsoft-office-product-key/</link>
		<comments>http://www.sean-barton.co.uk/2009/04/changing-a-microsoft-office-product-key/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 10:13:13 +0000</pubDate>
		<dc:creator>Sean</dc:creator>
				<category><![CDATA[Time Savers]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Microsoft Key]]></category>
		<category><![CDATA[Microsoft Office Product]]></category>
		<category><![CDATA[Microsoft Office Product Key]]></category>
		<category><![CDATA[Office Product Key]]></category>

		<guid isPermaLink="false">http://www.sean-barton.co.uk/?p=276</guid>
		<description><![CDATA[I just had a problem at work whereby the version of office installed in the last 30 days needed activating and the product key was not working. Luckily we have several Office keys sitting in the server room so I set about trying to change the key on the machine without having to reinstall. This [...]]]></description>
			<content:encoded><![CDATA[<p>I just had a problem at work whereby the version of office installed in the last 30 days needed activating and the product key was not working. Luckily we have several Office keys sitting in the server room so I set about trying to change the key on the machine without having to reinstall. This means you don&#8217;t need to uninstall/reinstall Office which will take half an hour. This took me 2 minutes <img src='http://www.sean-barton.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>After a short Google search I came across a Microsoft article that told me exactly how to do it. Here are the steps I took:</p>
<ol>
<li>Close any Microsoft Office Applications</li>
<li>Open the registry (<strong>Start -</strong>&gt; <strong>Run -</strong>&gt; <strong>regedit</strong>)</li>
<li>Find the appropriate office installation key under  <em>HKEY_LOCAL_MACHINE \Software\Microsoft\Office</em> followed by your version
<ul>
<li><strong>Office XP</strong> -&gt;<em>&#8230;\10.0\Registration</em></li>
<li><strong>Office 2003</strong> -&gt; <em>&#8230;11.0\Registration</em></li>
<li><strong>Office 2007</strong> -&gt; <em>&#8230;\12.0\Registration</em></li>
</ul>
</li>
<li>In one of the subfolders you will see a product name field. Select the subfolder with your Office name in it (IE: <em>Microsoft Office 2003</em>)</li>
<li>Delete the following key names:
<ul>
<li>DigitalProductID</li>
<li>ProductID</li>
</ul>
</li>
<li>Close the registry (no need to look for a save button, there isn&#8217;t one!)</li>
<li>Open up any Office Application and you will be prompted for your product key and then to activate.</li>
</ol>
<p><em>Thanks to Microsoft for writing a clear and concise how-to for a change without referring you to various knowledgebase articles. I used the following site for reference: <a title="Microsoft Article to do the same thing" href="http://support.microsoft.com/kb/895456" target="_blank">http://support.microsoft.com/kb/895456</a></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sean-barton.co.uk/2009/04/changing-a-microsoft-office-product-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
