2009-11-20, 21:04:58
Simple function to extract all the meta tags from pages and display a Tag Cloud.
You'll need to change the link tags depending on what you want to do with the link, either through onlick or normal links.
Might be of use to someone....
Mike.
This is revision 1.1 of the code.
You'll need to change the link tags depending on what you want to do with the link, either through onlick or normal links.
Might be of use to someone....
Mike.
This is revision 1.1 of the code.
Code:
function tagCloud(){
$minFont=14; // change to min font size
$maxFont=20; // change to max font size
$tags = array();
$cloud = array();
// Grab the tags from the database
$path = "data/pages";
$dir_handle = @opendir($path) or die("Unable to open $path");
$filenames = array();
while ($filename = readdir($dir_handle)) {
$filenames[] = $filename;
}
$count=0;
$value="";
if (count($filenames) != 0) {
foreach ($filenames as $file) {
if ($file == "." || $file == ".." || is_dir("data/pages/".$file) || $file == ".htaccess" ) {
// not a page data file
} else {
$thisfile = @file_get_contents('data/pages/'.$file);
$data = simplexml_load_string($thisfile);
if ($data->private != 'Y') {
$metaData = $data->meta;
$db = explode(' ', $metaData);
while(list($key, $value) = each($db)){
@$tags[(string)$value] += 1;
}
$count++;
}
}
}
}
// Get totals to use for font size
$min = min(array_values($tags));
$max = max(array_values($tags));
$fix = ($max - $min == 0) ? 1 : $max - $min;
// Display the tags
foreach ($tags as $tag => $count) {
$size = $minFont + ($count - $min) * ($maxFont - $minFont) / $fix;
$jsLink=" onclick=\"searchTag('".$tag."');\" "; // change this if
$normalLink='#'; // change if you want to use normal links
$cloud[] = '<a style="font-size:'. floor($size) .'px" class="cloud" href="'.$normalLink.'" title=" '. ucfirst($tag) .' ('. $count .')" '.$jsLink.' >'. htmlspecialchars(stripslashes(ucfirst($tag))) . '</a>';
}
$shown = join("\n", $cloud) . "\n";
echo $shown;
}