<?xml version="1.0" encoding="utf-8"?>
<!-- generator="Joomla! - Open Source Content Management" -->
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Blog</title>
		<description>Web development blog. Hint's, tips, and tutorials for PHP, Javascript, CSS, XHTML, Joomla and more.</description>
		<link>http://paulmason.name</link>
		<lastBuildDate>Tue, 14 Apr 2026 22:07:23 +0000</lastBuildDate>
		<generator>Joomla! - Open Source Content Management</generator>
		<atom:link rel="self" type="application/rss+xml" href="http://paulmason.name/?format=feed&amp;task=feed&amp;type=rss&amp;app_id=1"/>
		<language>en-gb</language>
		<item>
			<title>Javascript Particle Engine &amp; Effects Tutorial</title>
			<link>http://paulmason.name/item/javascript-particle-engine-effects</link>
			<guid isPermaLink="true">http://paulmason.name/item/javascript-particle-engine-effects</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>A random particle generator built with pure javascript &amp; CSS. Gives you the ability to change the size, velocity and frame rate of the particles.&nbsp;</p></div><div><h2>Demo</h2>
<p>

</p>

<h2>HTML</h2>
<pre class="prettyprint lang-html">
&lt;div id=&quot;particle-frame&quot; style=&quot;width: 580px; height: 250px;&quot;&gt;&lt;/div&gt;
</pre>

<h2>CSS</h2>
<pre class="prettyprint lang-css">
#particle-frame {
  position: relative;
  display: block;
  background: #040625;
  overflow: hidden;
  border-radius: 5px;
}

particle-1, particle-2 {
  display: block; position: absolute;
}

/*  Color  Variations */
particle-1 { background-color: #ff5434; }
particle-2 { background-color: #cc1e2c; }
</pre>

<h2>Javascript</h2>
<pre class="prettyprint lang-css">
window.onload = function(){
  
  // init vars
  var particles = new Array();
  var frame = document.getElementById('particle-frame');
  var canvas_width = parseInt(frame.style.width);
  var canvas_height = parseInt(frame.style.height);

  // settings
  var frame_rate = 31; // per second
  var max_particle_size = 50; // pixels
  var max_velocity = 2; // pixels per frame
  createParticles(30);
  var runtime = 0; // seconds, 0 for infinite
  var time_elapsed = 0;

  // timer
  var timer = setInterval(function() {
    animateParticles();

    if (runtime != 0) { 
      time_elapsed += 1 / frame_rate;
      if (time_elapsed >= runtime) clearInterval(timer);
    }

  }, 1000 / frame_rate);

  // functions
  function createParticles(amount) {
    for (var i = 1; i <= amount; i++) {
      particles[i] = {'dom': document.createElement("particle-" + getRandomInt(1,2)),
                      'opacity' : getRandomInt(50,100)/100,
                      'size' : getRandomInt(1, max_particle_size),
                      'left' : canvas_width * Math.floor(Math.random() * 101) / 100,
                       'top' : canvas_height * Math.floor(Math.random() * 101) / 100, 
                      'x-velocity' : getRandomInt(-max_velocity*100, max_velocity*100) / 100, 
                      'y-velocity' : getRandomInt(-max_velocity*100, max_velocity*100) / 100 }

      particles[i]['dom'].style.cssText = "opacity: " + particles[i]['opacity'] + "; border-radius: " + particles[i]['size']/2 + "px; height:" + particles[i]['size'] + "px; width: " +particles[i]['size'] + "px; left:" + particles[i]['left'] + "px; top:" + particles[i]['top'] + "px;";
      particles[i]['dom'].setAttribute("x-velocity",particles[i]['x-velocity']);
      particles[i]['dom'].setAttribute("y-velocity",particles[i]['y-velocity']);
      document.body.appendChild(particles[i]['dom']);
      frame.appendChild(particles[i]['dom']);
    }
  }

  function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }

  function animateParticles() {
    for (var i = 1; i < particles.length; i++) {
      // particle hits left side
      if ((particles[i]['left'] + particles[i]['size']) < 0 && particles[i]['x-velocity'] < 0) {
        particles[i]['dom'].style.left = (canvas_width + particles[i]['x-velocity']) + 'px';
        particles[i]['dom'].style.top = particles[i]['top'] + particles[i]['y-velocity'] + 'px';

      // particle hits top side
      } else if ((particles[i]['top'] + particles[i]['size']) < 0 && particles[i]['y-velocity'] < 0) {
        particles[i]['dom'].style.top = (canvas_height - particles[i]['size']) + particles[i]['y-velocity'] + 'px';
        particles[i]['dom'].style.left = particles[i]['left'] + particles[i]['x-velocity'] + 'px';

      // particle hits right side
      } else if (particles[i]['left'] > canvas_width && particles[i]['x-velocity'] > 0) {
        particles[i]['dom'].style.left = particles[i]['x-velocity'] + 'px';
        particles[i]['dom'].style.top = particles[i]['top'] + particles[i]['y-velocity'] + 'px';

      // particle hits bottom side
      } else if (particles[i]['top'] > canvas_height && particles[i]['y-velocity'] > 0) {
        particles[i]['dom'].style.top = particles[i]['y-velocity'] + 'px';
        particles[i]['dom'].style.left = particles[i]['left'] + particles[i]['x-velocity'] + 'px';

       // particle floating in middle
       } else {
        particles[i]['dom'].style.left = (particles[i]['left']+(particles[i]['x-velocity'])) + 'px';
        particles[i]['dom'].style.top = (particles[i]['top']+(particles[i]['y-velocity'])) + 'px';
      }

      // update particle array values
      particles[i]['left'] = parseFloat(particles[i]['dom'].style.left);
      particles[i]['top'] = parseFloat(particles[i]['dom'].style.top);

    }
  }

}
</pre>
</div></div>]]></description>
			<pubDate>Wed, 20 Jun 2012 23:16:54 +0000</pubDate>
		</item>
		<item>
			<title>Simple jQuery Carousel Slider Tutorial</title>
			<link>http://paulmason.name/item/simple-jquery-carousel-slider-tutorial</link>
			<guid isPermaLink="true">http://paulmason.name/item/simple-jquery-carousel-slider-tutorial</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>This is a simple jQuery carousel slider that I use quite often in my projects, it's the most basic version and a great starting point if you want to learn how to use animation with jQuery.</p>
<p>With this slider you'll be able to easily change the dimensions, animation times, and choose custom classes/id's for the container and slides (handy for applying to existing html).</p></div><div><h2>Demo</h2>
<p></p>
<h2>Play with the Code</h2>
<ul>
<li><a href="http://jsfiddle.net/paulmason411/TZy7A/2/" target="_blank">jsFiddle Editable Demo</a></li>
</ul>
<h2>Download</h2>
<ul>
<li><a title="Download the Demo Files" href="https://github.com/paulmason/Simple-jQuery-Carousel-Slider/archive/master.zip" target="_blank">Download the jQuery Slider demo files</a></li>
<li>or view them on <a title="Simple jQuery Carousel Slider on Github" target="_blank" href="https://github.com/paulmason/Simple-jQuery-Carousel-Slider">Github</a></li>
</ul>
<h2>HTML</h2>
<pre class="prettyprint lang-xhtml">&lt;ul class="slider"&gt;<br /> &lt;li&gt;<br /> &nbsp; &lt;img src="http://paulmason.name/image-1.jpg" /&gt;<br /> &lt;/li&gt;<br /> &lt;li&gt;<br /> &nbsp; &lt;img src="http://paulmason.name/image-2.jpg" /&gt;<br /> &lt;/li&gt;<br /> &lt;li&gt;<br /> &nbsp; &lt;img src="http://paulmason.name/image-3.jpg" /&gt;<br /> &lt;/li&gt;<br /> &lt;li&gt;<br /> &nbsp; &lt;img src="http://paulmason.name/image-4.jpg" /&gt;<br /> &lt;/li&gt;<br />&lt;/ul&gt;
</pre>
<h2>CSS</h2>
<pre class="prettyprint lang-css">.slider {
  margin: 10px 0;
  width: 580px; /* Update to your slider width */
  height: 250px; /* Update to your slider height */
  position: relative;
  overflow: hidden;
}

.slider li {
  display: none;
  position: absolute; 
  top: 0; 
  left: 0; 
}
</pre>
<h2>jQuery Javascript</h2>
<pre class="prettyprint lang-javascript">jQuery(function($) { 

  // settings<br />  var $slider = $('.slider'); // class or id of carousel slider
  var $slide = 'li'; // could also use 'img' if you're not using a ul
  var $transition_time = 1000; // 1 second
  var $time_between_slides = 4000; // 4 seconds

  function slides(){
    return $slider.find($slide);
  }

  slides().fadeOut();

  // set active classes
  slides().first().addClass('active');
  slides().first().fadeIn($transition_time);

  // auto scroll 
  $interval = setInterval(
    function(){
      var $i = $slider.find($slide + '.active').index();

      slides().eq($i).removeClass('active');
      slides().eq($i).fadeOut($transition_time);

      if (slides().length == $i + 1) $i = -1; // loop to start

      slides().eq($i + 1).fadeIn($transition_time);
      slides().eq($i + 1).addClass('active');
    }
    , $transition_time +  $time_between_slides 
  );

});
</pre>
<h2>More to Come</h2>
<p>This is the first to come of a series of tutorials on jQuery sliders. I'll be adding more features soon.</p></div></div>]]></description>
			<pubDate>Sat, 07 Apr 2012 02:59:42 +0000</pubDate>
		</item>
		<item>
			<title>Enable Write Permissions for the Native Built-In Apache in Mac OS X Lion</title>
			<link>http://paulmason.name/item/change-apache-user-group-in-lion-os-x</link>
			<guid isPermaLink="true">http://paulmason.name/item/change-apache-user-group-in-lion-os-x</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>When using the native built in version of Apache in Lion OS X you won't have write permissions unless you change the User and Group settings in apache's httpd.conf file. Here are some quick instructions on how to achieve that.</p></div><div><h2>Open Terminal and Enter</h2>
<pre class="prettyprint lang-bash">sudo nano /private/etc/apache2/httpd.conf
</pre>
<h2>Find and change http.conf code from</h2>
<pre class="prettyprint lang-php">User _www
Group _www
</pre>
<h2>To</h2>
<pre class="prettyprint lang-bash">User your_mac_username
Group staff
# With earlier versions such as Leopard, capitalise staff to Staff
</pre>
<p>Restart apache by going to System Preferences &gt; Sharing and un-tick then tick Web Sharing.</p>
<h2>PHP to check write permissions are enabled</h2>
<pre class="prettyprint lang-php">echo (is_writable('.')) ? "writable" : "not writable";
</pre></div></div>]]></description>
			<pubDate>Thu, 23 Feb 2012 23:22:37 +0000</pubDate>
		</item>
		<item>
			<title>How to write PHP with CSS Syntax</title>
			<link>http://paulmason.name/item/php-with-css-syntax</link>
			<guid isPermaLink="true">http://paulmason.name/item/php-with-css-syntax</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>I've recently designed a template system, and wanted to make it as easy as possible for the designers to enter values into PHP&nbsp;functions. So I wrote a little function to allow a CSS style string to be converted into an array.</p></div><div><h2>Regular PHP Method</h2>
<pre class="prettyprint lang-php">//The line of code the designer has to edit
echo createPosition('header', '100px', '200px');

function createPosition($name, $height, $width)
{
  return  '&lt;div id="' . $name . '" style="height:' . $height . ';width:' . $width . ';"&gt;' . $name . '&lt;/div&gt;';
}
</pre>
<h2>CSS Style PHP</h2>
<pre class="prettyprint lang-php">//The line of code the designer has to edit
echo createPosition('name:header; width:100px; height:200px');

function attrStringToArray($attr_string)
{
  $attr = array();
  foreach(explode(';', $attr_string) AS $attr_temp) {
    if (strlen(trim($attr_temp)) &gt; 0) {
      list($name, $value) = explode(':', $attr_temp);
      $attr[trim($name)] = trim($value);
    }
  }
  return $attr;
}

function createPosition($attr_string)
{
  $attributes = attrStringToArray($attr_string);
  return  '&lt;div id="' . $attributes['name'] . '" style="height:' . $attributes['height'] . ';width:' . $attributes['width'] . ';"&gt;' . $attributes['name'] .'&lt;/div&gt;';
}
</pre>
<p>So you can see that the line of code the designer has to edit is a lot easier to understand with the CSS style PHP. The attributes can also be in any order. This is just one scenario and can be used in many.</p></div></div>]]></description>
			<pubDate>Tue, 02 Aug 2011 22:29:48 +0000</pubDate>
		</item>
		<item>
			<title>Add a MySQL User, Simple &amp; Reliable</title>
			<link>http://paulmason.name/item/add-a-mysql-user-simple-reliable</link>
			<guid isPermaLink="true">http://paulmason.name/item/add-a-mysql-user-simple-reliable</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>I've found the easiest most reliable way to add a MySQL user with all priviledges is with a simple query.</p></div><div><h2>MySQL</h2>
<pre class="prettyprint lang-mysql">CREATE USER 'db_username'@'localhost';
GRANT ALL PRIVILEGES ON db_name.* TO 'db_username'@'localhost';
SET PASSWORD FOR 'db_username'@'localhost' = PASSWORD('password');
FLUSH PRIVILEGES;
</pre>
<p>All you need to do is replace 'db_username', 'db_name', and 'password' with your relevant database details, execute the MySQL and presto!</p></div></div>]]></description>
			<pubDate>Mon, 01 Aug 2011 03:03:13 +0000</pubDate>
		</item>
		<item>
			<title>Search Engine Friendly (SEF) Urls for Virtuemart</title>
			<link>http://paulmason.name/item/search-engine-friendly-sef-urls-for-virtuemart</link>
			<guid isPermaLink="true">http://paulmason.name/item/search-engine-friendly-sef-urls-for-virtuemart</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>I've come up with a very simple FREE solution to give your VirtueMart Joomla! 1.5 sites SEF URLs. This is the an example of the format you will achieve:</p>
<p>http://yoursite.com/store-alias/category-name/product-name/unique-id</p></div><div><h2>Install Instructions</h2>
<ol>
<li>Download the <strong><a title="Download Virtuemart SEF router" href="http://paulmason.name/media/uploads/blog/virtuemart-sef/virtuemart-sef-router.zip">router.php</a></strong> file</li>
<li>Place the&nbsp;<strong><a title="Download Virtuemart SEF router" href="http://paulmason.name/media/uploads/blog/virtuemart-sef/virtuemart-sef-router.zip">router.php</a>&nbsp;</strong>file into your <strong>components/com_virtuemart</strong> folder in your joomla installation.<br />
<div class="shadow" style="width: 551px;"><img style="border-style: initial; border-color: initial;" src="http://paulmason.name/media/uploads/blog/virtuemart-sef/path.jpg" alt="2. Virtuemart Router Path" /></div>
</li>
<li>Enable Joomla SEF URLs in your Joomla admin under Global Configuration-&gt; Site -&gt; SEO Settings as shown in the image below:<br />
<div class="shadow" style="width: 313px;"><img src="http://paulmason.name/media/uploads/blog/virtuemart-sef/sef-config.jpg" alt="3. Joomla! SEF Configuration" /></div>
</li>
</ol>
<h2>Features</h2>
<ul>
<li>SEF URLS for all important landing pages (products, categories and manufactures)</li>
<li>Handles categories and products with the same name</li>
<li>Converts / characters to - in URL</li>
<li>Handles multiple categories for one product by choosing the category with the highest list order</li>
<li>No duplicate URLs</li>
</ul>
<h2>Example</h2>
<p><a title="Buy Pass Port  Skate Products" href="http://pactstore.com.au" target="_blank">http://pactstore.com.au</a>&nbsp;</p>
<h2>Linking directly to categories, products &amp; manufacturers</h2>
<p>If you are linking to a product or category directly. You need to supply the same link that Virtuemart uses throughout its component. The easiest way to do this is to create a new menu item as an external link like the following:</p>
<p><strong>Category</strong>:&nbsp;index.php?option=com_virtuemart&amp;page=shop.browse&amp;Itemid=<strong>32</strong>&amp;category_id=<strong>4</strong></p>
<p><strong>Product</strong>:&nbsp;index.php?option=com_virtuemart&amp;page=shop.product_details&amp;Itemid=<strong>32</strong>&amp;product_id=<strong>79</strong></p>
<p><strong>Manufacturer</strong>:&nbsp;index.php?option=com_virtuemart&amp;page=shop.browse&amp;Itemid=<strong>32</strong>&amp;manufacturer_id=<strong>4</strong></p>
<p>So you will need to change the numbers marked in bold, i.e the Itemid, category_id &amp; product_id to the relevant id's. The Itemid is the menu item id of the Virtuemart component. This can be found by viewing the last column in the menu manager for the relevant menu.</p>
<p>This might seem a bit technical but it's quite easy, and will make a vast difference to your SEO. Also I'll do my best to help if you have any problems.</p>
<h2>Known Issues</h2>
<p>The sort by Product Name, Price, Latest Products list box doesn't preserve SEF URLs. This is because Virtuemart has not taken SEF into consideration and used javascript to redirect which doesn't allow the router to rewrite the URL. You can hide the listbox in the Virtuemart configuration if need be.</p>
<h2>Other 3rd Party Virtuemart SEF Plugins</h2>
<p>There are quite a few third party plugins you can use for Virtuemart SEF URLs. I had a look through the methods on&nbsp;<a title="VirtueMart SEF Url Guide" href="http://www.ianrsmith.co.uk/search-engine-friendly-sef-urls-virtuemart/" target="_blank">this site</a>&nbsp;and found the closest I could get to neat SEF URLs was by using the sh404sef component. It is a very complex component, and takes a lot of tweaking, not the most elegant solution in my opinion.</p>
<h2>References</h2>
<ul>
<li><a title="Corresponding VirtueMart Forum Thread" href="http://forum.virtuemart.net/index.php?topic=88290.0" target="_blank">Related VirtueMart Forum Thread</a></li>
<li><a title="Joomla SEF URLs with router.php" href="http://docs.joomla.org/Supporting_SEF_URLs_in_your_component" target="_blank">How to code SEF URLs for your Joomla component</a></li>
<li><a title="Alternative methods for VirtueMart SEF URLs" href="http://www.ianrsmith.co.uk/search-engine-friendly-sef-urls-virtuemart/" target="_blank">Reviews on third party VirtueMart SEF components</a></li>
</ul>
<h2><a href="http://paulmason.name/media/uploads/blog/virtuemart-sef/virtuemart-sef-router.zip" title="Download Virtuemart SEF Router">Download</a></h2></div></div>]]></description>
			<pubDate>Tue, 14 Jun 2011 13:37:01 +0000</pubDate>
		</item>
		<item>
			<title>PHP Microtime Function</title>
			<link>http://paulmason.name/item/test-php-execution-time-with-microtime</link>
			<guid isPermaLink="true">http://paulmason.name/item/test-php-execution-time-with-microtime</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>The PHP microtime() function&nbsp;returns the current Unix timestamp in microseconds.</p>
<p>microtime() returns a string and alternatively microtime(true) returns a float.</p></div><div><h2>Usage</h2>
<pre class="prettyprint lang-php">
// microtime()
echo &quot;microtime() = &quot; . microtime() . &quot; &quot; 
  . ((is_string(microtime())) ? &quot;string&quot; : &quot; not string&quot;) . &quot;&lt;br /&gt;&quot;; 

// microtime(false)
echo &quot;microtime(false) = &quot; . microtime(false) . &quot; &quot; 
  . ((is_string(microtime(false))) ? &quot;string&quot; : &quot; not string&quot;)  . &quot;&lt;br /&gt;&quot;; 

// microtime(true)
echo &quot;microtime(true) = &quot; . microtime(true) . &quot; &quot; 
  . ((is_float(microtime(true))) ? &quot;float&quot; : &quot; not float&quot;) . &quot;&lt;br /&gt;&quot;; 

/* Sample Output
 
  microtime() = 0.49883700 1339648679 string
  microtime(false) = 0.49885600 1339648679 string
  microtime(true) = 1339648679.4989 float

 */
</pre>

<h2>Helpful Examples</h2>
<pre class="prettyprint lang-php">// Test your servers PHP execution time

// Start timer
$time_start = microtime(true);


// Code to test (the counter is an example)
$counter = 1;

while ($counter &lt;= 1000000) {
  $counter++;
}


// End timer
$time_end = microtime(true);
$time = $time_end - $time_start;

echo "php execution time in microseconds: " . $time;

/* Sample Output
 
  php execution time in microseconds: 0.19492197036743

 */ 
</pre>

<h2>Take it Further</h2>
<p>You could extend this and set a maximum execution time variable. Then in the 'end timer' block check to see if it is exceeded and log or email the warning. This would be handy in determining server side performance issues.</p>
<h2>Reference</h2>
<p><a title="php microtime() function" href="http://php.net/manual/en/function.microtime.php" target="_blank">microtime()</a></p></div></div>]]></description>
			<pubDate>Mon, 09 May 2011 10:22:10 +0000</pubDate>
		</item>
		<item>
			<title>Flexible Random String Generator with PHP</title>
			<link>http://paulmason.name/item/unique-random-alphanumeric-string-generator-in-php</link>
			<guid isPermaLink="true">http://paulmason.name/item/unique-random-alphanumeric-string-generator-in-php</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>This is a short &nbsp;and relatively simple tutorial with some useful php functions to generate unique random alphanumeric codes. These can be useful for generating url codes, like the ones featured in bit.ly, tinyurl, youtube etc.</p>
<p>These php functions allow you to create as many codes as you like with the characters you chose. It also lets you add in your existing codes so that you don't get duplicates.</p></div><div><p>I've used the character set '23456789ABCDEFGHJKLMNPQRSTUVWXYZ' you'll notice I removed 01OI as some fonts make this hard to distinguish the difference.</p>
<h2>PHP</h2>
<pre class="prettyprint lang-php">function createRandomString($string_length, $character_set) {
  $random_string = array();
  for ($i = 1; $i &lt;= $string_length; $i++) {
    $rand_character = $character_set[rand(0, strlen($character_set) - 1)];
    $random_string[] = $rand_character;
  }
  shuffle($random_string);
  return implode('', $random_string);
}

function validUniqueString($string_collection, $new_string, $existing_strings='') {
  if (!strlen($string_collection) &amp;&amp; !strlen($existing_strings))
    return true;
  $combined_strings = $string_collection . ", " . $existing_strings;
  return (strlen(strpos($combined_strings, $new_string))) ? false : true;
}

function createRandomStringCollection($string_length, $number_of_strings, $character_set, $existing_strings = '') {
  $string_collection = '';
  for ($i = 1; $i &lt;= $number_of_strings; $i++) {
    $random_string = createRandomString($string_length, $character_set);
    while (!validUniqueString($string_collection, $random_string, $existing_strings)) {
      $random_string = createRandomString($string_length, $character_set);
    }
    $string_collection .= ( !strlen($string_collection)) ? $random_string : ", " . $random_string;
  }
  return $string_collection;
}

$character_set = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';
$existing_strings = "NXC, BRL, CVN";
$string_length = 3;
$number_of_strings = 10;
echo createRandomStringCollection($string_length, $number_of_strings, $character_set, $existing_strings);
</pre>
<h2>Sample Output</h2>
<p>QPP, 9EK, 67J, TAA, 23X, BWV, YWP, G8W, 3LJ, A8G</p>
<h2>PHP References</h2>
<ul>
<li><a title="PHP String Length Function" href="http://au2.php.net/manual/en/function.strlen.php" target="_blank">strlen</a></li>
<li><a title="PHP String Position Function" href="http://au2.php.net/manual/en/function.strpos.php" target="_blank">strpos</a></li>
<li><a title="PHP Implode Function" href="http://au2.php.net/manual/en/function.implode.php" target="_blank">implode</a></li>
<li><a title="PHP Shuffle Function" href="http://au2.php.net/manual/en/function.shuffle.php" target="_blank">shuffle</a></li>
<li><a title="PHP Random Function" href="http://au2.php.net/manual/en/function.rand.php" target="_blank">rand</a></li>
</ul>
<h2>Examples of Usage</h2>
<ul>
<li><a title="Tiny URL" href="http://tinyurl.com/" target="_blank">tinyurl</a></li>
<li><a title="bit.ly" href="http://bit.ly" target="_blank">bit.ly</a></li>
<li><a title="Youtube Urls" href="http://youtube.com" target="_blank">youtube urls</a></li>
<li>Voucher/Coupon codes</li>
<li>Raffle Tickets</li>
</ul></div></div>]]></description>
			<pubDate>Wed, 06 Apr 2011 08:35:37 +0000</pubDate>
		</item>
		<item>
			<title>Yootheme Zoo - Accessing Element Data with Joomla Code</title>
			<link>http://paulmason.name/item/yootheme-zoo-accessing-element-data-with-joomla-code</link>
			<guid isPermaLink="true">http://paulmason.name/item/yootheme-zoo-accessing-element-data-with-joomla-code</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>If you're looking to write some custom code with <a title="Yootheme Zoo" href="http://www.yootheme.com/zoo/" target="_blank">yootheme's zoo</a>&nbsp;then you'll probably be wondering how to access all the data in those dynamic fields you created through their lovely admin user interface. If you look in the jos_zoo_item table in your database you'll see a column called elements. If you look at the contents you'll see that majority of your zoo items data is stored in there as XML.</p></div><div><p>If you are coding within a zoo page you can use their <a title="Accessing Element Data in Zoo" href="http://www.yootheme.com/docs/home/item/accessing-element-data">tutorial</a>. However if you want a simple global function that will work anywhere in Joomla you can use the function that I've written below:</p>
<h2>PHP Function</h2>
<pre class="prettyprint lang-php">function getZooElementData($item_id, $element_identifier, $element_child) {
  $db =&amp; JFactory::getDBO();
  $query = "SELECT elements FROM #__zoo_item WHERE id = " . $item_id;
  $db-&gt;setQuery($query);
  $element_xml = $db-&gt;loadResult();
  $elements = simplexml_load_string($element_xml);
  foreach ($elements-&gt;children() as $element) {
    if((string)$element-&gt;attributes() == $element_identifier) {
      return (string)$element-&gt;$element_child;
    }
  }
}
</pre>
<h2>PHP Usage</h2>
<pre class="prettyprint lang-php">echo getZooElementData(2, '43aa1b15-986e-4303-afcf-628b835f10e5', 'value');
</pre>
You would use the code above to extract a textarea from a zoo item with the id 2 from the following XML:
<pre class="prettyprint lang-xml">&lt;textarea identifier="43aa1b15-986e-4303-afcf-628b835f10e5"&gt;&nbsp;&nbsp;
  &lt;value&gt;&lt;![CDATA[&lt;p&gt;This is some sample yootheme zoo element data.&lt;/p&gt;]]&gt;&lt;/value&gt;
&lt;/textarea&gt;</pre>
<h2>References</h2>
<ul>
<li><a title="Simple XML Load String" href="http://php.net/manual/en/function.simplexml-load-string.php" target="_blank">simplexml_load_string()</a></li>
<li><a title="Joomla Database Tutorial" href="http://docs.joomla.org/How_to_use_the_database_classes_in_your_script" target="_blank">Joomla Database Tutorial</a></li>
<li><a title="Joomla Extension for Writing Custom Code" href="http://extensions.joomla.org/extensions/edition/custom-code-in-content/1023" target="_blank">Joomla Extension for Writing Custom Code</a></li>
</ul>
<p>Hope this was helpful!&nbsp;</p></div></div>]]></description>
			<pubDate>Wed, 23 Mar 2011 11:05:58 +0000</pubDate>
		</item>
		<item>
			<title>Dynamic PHP Copyright Date Code</title>
			<link>http://paulmason.name/item/dynamic-php-copyright-date-code</link>
			<guid isPermaLink="true">http://paulmason.name/item/dynamic-php-copyright-date-code</guid>
			<description><![CDATA[<div class="element element-textarea first last">
	<div><p>Pretty simple but pretty handy too! Here's a short tutorial to generate the current year in your footer's copyright declaration. It also detects if the the site has been running for less than a year to avoid the date printing out like this &copy; 2011-2011 rather than just this &copy; 2011.</p>
<p><strong>Example:</strong> Your Company Name &copy; 2010-2011 All Rights Reserved.</p></div><div><p>Both of these methods work the same way.</p>
<h2>Pure PHP</h2>
<pre class="prettyprint lang-php"><p>echo "&lt;p&gt;Your Company Name &amp;copy "; <br />$start_year = 2010; //change to the year you launched your website<br />echo (date('Y') == $start_year) ? $start_year : $start_year . "-" . date('Y');<br />echo " All Rights Reserved.&lt;/p&gt;";</p></pre>
<h2>Mixed HTML &amp; PHP</h2>
<pre class="prettyprint lang-php"><p>&lt;p&gt;Your Company Name &amp;copy; <br />&lt;?php<br />&nbsp; $start_year = 2010; //change to the year you launched your website<br />&nbsp; echo (date('Y') == $start_year) ? $start_year : $start_year . "-" . date('Y');<br />?&gt;<br />All Rights Reserved.&lt;/p&gt;</p></pre>
<p>If you're looking to add the trademark symbol (&trade;) or any others check out <a href="http://www.copypastecharacter.com/" target="_blank">CopyPasteCharacter.com</a></p></div></div>]]></description>
			<pubDate>Thu, 24 Feb 2011 08:14:21 +0000</pubDate>
		</item>
	</channel>
</rss>
