<?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>amnuts &#187; tag cloud</title>
	<atom:link href="http://blog.amnuts.com/tag/tag-cloud/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.amnuts.com</link>
	<description>php projects, javascript, and... stuff.</description>
	<lastBuildDate>Fri, 07 May 2010 09:11:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tag cloud view helper</title>
		<link>http://blog.amnuts.com/2008/06/11/tag-cloud-view-helper/</link>
		<comments>http://blog.amnuts.com/2008/06/11/tag-cloud-view-helper/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 13:43:16 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Code snippets]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[tag cloud]]></category>
		<category><![CDATA[view helper]]></category>

		<guid isPermaLink="false">http://blog.amnuts.com/?p=66</guid>
		<description><![CDATA[Here&#8217;s a little view helper to display a tag cloud.  All you have to do is supply an array of tags, with the tag name being the index and how many times it&#8217;s used as the value, and the url you&#8217;d like the tags to go to.


&#60; ?php

/**
 * Display a tag cloud
 *
 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.amnuts.com/wp-content/uploads/2008/06/tagcloud.gif"><img class="alignright size-full wp-image-67" title="Tag cloud example" src="http://blog.amnuts.com/wp-content/uploads/2008/06/tagcloud.gif" alt="" width="222" height="180" /></a>Here&#8217;s a little view helper to display a tag cloud.  All you have to do is supply an array of tags, with the tag name being the index and how many times it&#8217;s used as the value, and the url you&#8217;d like the tags to go to.</p>
<p><span id="more-66"></span></p>
<div style="clear:both;"></div>
<pre class="brush: php;">&lt; ?php

/**
 * Display a tag cloud
 *
 * @category   Amnuts
 * @package    Amnuts_View
 * @subpackage Amnuts_View_Helper
 * @copyright  Copyright (c) 2008 Andrew Collington (http://www.amnuts.com/)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Amnuts_View_Helper_TagCloud
{
    public $view;

    /**
     * Output the tag cloud.
     *
     * The $tags parameter is expected to be an array with the tag being the
     * index and the number of times it's used as the value.  For example:
     *
     *     array(
     *         'foo' =&gt; 3,
     *         'bar' =&gt; 1,
     *         'dog' =&gt; 5,
     *         'cat' =&gt; 1
     *     )
     *
     * The url will have the tag text appended to it, so that if you supply
     * '/filter/by/tag/' as the url, then given the above array you will have:
     *
     *     &lt;a href=&quot;/filter/by/tag/foo&quot;&gt;foo&lt;/a&gt;
     *     &lt;a href=&quot;/filter/by/tag/bar&quot;&gt;bar&lt;/a&gt;
     *
     * and so on.
     *
     * @param array $tags The tag array
     * @param string $url The link for each tag (with the tag name appended)
     * @param int|string $minFont The minimum font value
     * @param int|string $maxFont The maximum font value
     * @param string $unit The unit of size type (%, em, px, etc.)
     * @return string
     */
    public function tagCloud(array $tags, $url, $minFont = 100, $maxFont = 150, $unit = '%')
    {
        $xhtml = '';
        $cloud = array();

        if (!empty($tags)) {
            $min  = min(array_values($tags));
            $max  = max(array_values($tags));
            $diff = $max - $min;
            if (!$diff) {
                ++$diff;
            }

            foreach ($tags as $tag =&gt; $count) {
                $size = $minFont + ($count - $min) * ($maxFont - $minFont) / $diff;
                $cloud[] = '&lt;a href=&quot;' . $url . urlencode($tag)
                         . '&quot; style=&quot;font-size:' . $size . $unit . ';&quot;&gt;'
                         . $this-&gt;view-&gt;escape($tag) . '&lt;/a&gt;';
            }
            $xhtml .= '&lt;div class=&quot;tagCloudContainer&quot;&gt;&lt;h4&gt;Tag cloud&lt;/h4&gt;' . join(', ', $cloud) . &quot;&lt;/div&gt;\n&quot;;
        }
        return $xhtml;
    }

    /**
     * Set the view object
     *
     * @param Zend_View_Interface $view
     */
    public function setView(Zend_View_Interface $view)
    {
        $this-&gt;view = $view;
    }
}

?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.amnuts.com/2008/06/11/tag-cloud-view-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
