TinyPortal
Development => International => German => Topic started by: Paragaya on August 13, 2009, 10:30:18 AM
Fügen Sie eine neue PHP-Blocks
Mod : This (http://custom.simplemachines.org/mods/index.php?mod=579)
global $context, $db_prefix, $scripturl, $txt;
//Tag cloud from http://www.prism-perfect.net/archive/php-tag-cloud-tutorial/
$query = "SELECT t.tag AS tag, l.ID_TAG, COUNT(l.ID_TAG) AS quantity
FROM {$db_prefix}tags as t, {$db_prefix}tags_log as l WHERE t.ID_TAG = l.ID_TAG
GROUP BY l.ID_TAG
ORDER BY l.ID DESC LIMIT 50";
$result = db_query($query, __FILE__, __LINE__);
// here we loop through the results and put them into a simple array:
// $tag['thing1'] = 12;
// $tag['thing2'] = 25;
// etc. so we can use all the nifty array functions
// to calculate the font-size of each tag
$tags = array();
$tags2 = array();
while ($row = mysql_fetch_array($result))
{
$tags[$row['tag']] = $row['quantity'];
$tags2[$row['tag']] = $row['ID_TAG'];
}
if(count($tags2) > 0)
{
// change these font sizes if you will
$max_size = 250; // max font size in %
$min_size = 100; // min font size in %
// get the largest and smallest array values
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));
// find the range of values
$spread = $max_qty - $min_qty;
if (0 == $spread)
{ // we don't want to divide by zero
$spread = 1;
}
// determine the font-size increment
// this is the increase per tag quantity (times used)
$step = ($max_size - $min_size)/($spread);
// loop through our tag array
$context['poptags'] = '';
$row_count = 0;
foreach ($tags as $key => $value)
{
$row_count++;
// calculate CSS font-size
// find the $value in excess of $min_qty
// multiply by the font-size increment ($size)
// and add the $min_size set above
$size = $min_size + (($value - $min_qty) * $step);
// uncomment if you want sizes in whole %:
// $size = ceil($size);
// you'll need to put the link destination in place of the #
// (assuming your tag links to some sort of details page)
$context['poptags'] .= '<a href="' . $scripturl . '?action=tags;id=' . $tags2[$key] . '" style="font-size: '.$size.'%"';
// perhaps adjust this title attribute for the things that are tagged
$context['poptags'] .= ' title="'.$value.' things tagged with '.$key.'"';
$context['poptags'] .= '>'.$key.'</a> ';
if ($row_count > 5)
{
$context['poptags'] .= '<br />';
$row_count =0;
}
// notice the space at the end of the link
}
}
if(isset($context['poptags']))
echo $context['poptags'];
Paragaya,
Is there a reason for posting this information here instead of encouraging people to use the built in tagging system for TinyPortal 1.0 beta 4?
ZarPrime
ZarPrime, in the source you see in the first lines the info about a TAG-CLOUD. Imho TP hasn't that as a feature build in? Anyway, his posting is here in the german section a bit wrong I think.
PowerPyx,
Yeah probably. Anyway, I think there is a tag cloud block code snippet somewhere in the snippets board, but I can't really be bothered to look for it right now. Perhaps I'll stick this code on one of my test sites and see what it does. If it is productive then I'll move it to the block code snippets board.
ZarPrime