Dit is de hele pagina
<?php
/*
@ZenWordCloud
Author:
- Nathan Keilar (
www.madteckhead.com)
Version 0.1;
The is the project page for the ZenTagCloud. Its in development right now, its open source and I'd love input / contributions.
Note: the current version is not recommended for live online stores (where you have something to loose), however by all means try it out on you test site, have a look at the code and give me feedback.
p.s. Don't hold me responsible if something breaks.
What is a Tag Cloud?
A tag cloud (or weighted list in visual design) can be used as a visual depiction of content tags used on a website. Often, more frequently used tags are depicted in a larger font or otherwise emphasized, while the displayed order is generally alphabetical. Thus both finding a tag by alphabet and by popularity is possible. Selecting a single tag within a tag cloud will generally lead to a collection of items that are associated with that tag.
Features:
2/June/07: Displays category titles with random weights
3/June/07: Tags links to you Zen Cart site category pages.
Install:
1. Copy the code from this file to one of the Defined Pages using: Tools > Defined Pages Editor.
2. Ensure that the Defined Pages module is enables under: Tools > Layout Box Controller
3. Visit your site, and go to the defined page you pasted the code into. You should see a list of your sites categorie, with random sizes assigned to each one.
Todo/Wishlist:
- Save weights to database
- Add code to ?category's page? so that visits to category's changes weights
- Incorporate some noise in the category's weights to enable new category's a fair chance.
- Option to read tags from meta data
- Option to weight tags my relevance to current tag. (If you like a, you might like b type of thing)
With some code from:
- Derek Harvey (
www.derekharvey.co.uk)
- Zen Cart Team (
www.zen-cart.com)
Security Note: I've copied and modified a zen cart function to retrieve data from the db, and I think that by leaving the function embeded with the code if may pose some security risk. I'm open to advice on where to put it for best security practice.
*/
class wordCloud
{
var $gtags = array(); // tags array
/*
* PHP 5 Constructor
*
* @param array $words
* @return void
*/
function __construct($newtags = false)
{
if ($newtags !== false && is_array($newtags))
{
foreach ($newtags as $key => $value)
{
$this->addTag($value[0],$value[1],$value[2]);
}
}
}
/*
* PHP 4 Constructor
*
* @param array $words
* @return void
*/
function wordCloud($newtags = false)
{
$this->__construct($newtags);
}
/*
* Assign word to array
*
* @param
* @return
*/
function addTag($count, $url, $tag)
{
if (!$count > 0)
$count = 0;
$utag = strtoupper($tag);
if (!$this->gtags[$utag])
$this->gtags[$utag] = array('count' => $count, 'url' => $url, 'tag' => $tag);
$this->gtags[$utag]['count']++;
}
/*
* Get the class range using a percentage
*
* @returns int $class
*/
function getClassFromPercent($percent)
{
if ($percent >= 99)
$class = 1;
else if ($percent >= 70)
$class = 2;
else if ($percent >= 60)
$class = 3;
else if ($percent >= 50)
$class = 4;
else if ($percent >= 40)
$class = 5;
else if ($percent >= 30)
$class = 6;
else if ($percent >= 20)
$class = 7;
else if ($percent >= 10)
$class = 8;
else if ($percent >= 5)
$class = 9;
else
$class = 0;
return $class;
}
/*
* Create the HTML code for each word and apply font size.
*
* @returns string $spans
*/
function showCloud($returnType = "html")
{
$max = 0;
if (is_array($this->gtags))
{
foreach ($this->gtags as $key => $value)
{
if ($value['count'] > $max)
{
$max = $value['count'];
}
}
}
if (is_array($this->gtags))
{
$return = ($returnType == "html" ? "" : ($returnType == "array" ? array() : ""));
foreach ($this->gtags as $key => $value)
{
$sizeRange = $this->getClassFromPercent(($value['count'] / $max) * 100);
if ($returnType == "html")
{
$return .= '<a class="category-top" href="' . $value['url'] . '">';
$return .= "<span class='word size{$sizeRange}'> {$value['tag']} </span></a>";
}
}
return $return;
}
}
}
?>