collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 390
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

Thanks for having an interest with our portal. If you have any requests for features, have a look at the Feature Requests board.

Author Topic: [TIPS]Tags cloud in PHP block  (Read 9215 times)

0 Members and 1 Guest are viewing this topic.

Offline fotografo74

  • Jr. Member
  • **
  • Posts: 51
  • SMF Version: 2 RC1-1
  • SP Version: 2.3
[TIPS]Tags cloud in PHP block
« on: April 10, 2009, 05:35:00 AM »
Hi :-)
I have Simple Tagging Mod, useful and nice: http://custom.simplemachines.org/mods/index.php?mod=1411
In http://www.macroforum.org/index.php?action=tags;cloud i have the tags clouds.
How can i manage this cloud for display it in PHP block ?
This could be nice addition in portal home page! :-)

In tagging.php i have :
Code: [Select]
function ViewCloud(){
global $context, $smcFunc, $modSettings, $txt;

$context['tags'] = array();

// A big thank you to Prism Perfect for this code!
// http://prism-perfect.net/archive/php-tag-cloud-tutorial/

$result = $smcFunc['db_query']('', '
SELECT t.tag_name, COUNT(tt.id_tag) AS amount
FROM {db_prefix}tags AS t
INNER JOIN {db_prefix}tag_topics AS tt ON (tt.id_tag = t.id_tag)
GROUP BY tt.id_tag
LIMIT {int:limit}',
array(
'limit' => $modSettings['tags_to_show']
)
);

while ($row = $smcFunc['db_fetch_assoc']($result)) {
$tags[$row['tag_name']] = $row['amount'];
}

$smcFunc['db_free_result']($result);

// Let's shuffle these puppies up, to make it more fun
$keys = array_keys($tags);
shuffle($keys);

foreach ($keys as $key)
$context['tags'][$key] = $tags[$key];

$context['max_size'] = (int) $modSettings['max_tag_percentage'];
$context['min_size'] = (int) $modSettings['min_tag_percentage'];
$context['max_qty'] = (int) max(array_values($context['tags']));
$context['min_qty'] = (int) min(array_values($context['tags']));

$spread = $context['max_qty'] - $context['min_qty'];
$spread = ($spread > 0) ? $spread : 1;

$context['step'] = ($context['max_size'] - $context['min_size']) / $spread;

// Load the main Tags template
loadtemplate('Tagging');

// Setup the title and template.
$context['page_title'] = $txt['tags'] . ' - ' . $txt['tags_cloud'];
$context['sub_template'] = 'cloud';

}

and in Tagging.template.php i have:
Code: [Select]
function template_cloud()
{
global $txt, $context, $scripturl;

// I'm settings this here so that you can change it on a per-theme basis
$context['tag_colors'] = array(
'#0AC92B', // Green
'#CC00FF', // Purple
'#FF0033', // Red
'#4D4DFF', // Blue
'#000000', // Black
);

$num_colors = count($context['tag_colors']) - 1;

echo '
<table border="0" cellspacing="0" cellpadding="8" align="center" class="tborder" style="width: 60%;">
<tr class="catbg3">
<td align="center"><b>', $txt['tags_tag_cloud'], '</b></td>
</tr>
<tr>
<td class="windowbg" style="padding: 1em 2em 1em 2em; text-align: center;">';

if(!empty($context['tags']))
foreach ($context['tags'] as $key => $value){
$color = $context['tag_colors'][mt_rand(0, $num_colors)];
$size = ceil($context['min_size'] + (($value - $context['min_qty']) * $context['step']));
// The index is so we can put smaller elements in front, so they won't get swallowed by the big ones.
$index = abs($size - $context['max_size']);

echo '<a href="', $scripturl, '?action=tags;name=', urlencode($key), '" style="z-index: ', $index, '; position: relative; font-size: ', $size, '%; color: ', $color, ';" title="', $value, ' ', $txt['tags_tagged_with'], ' ', ucwords($key), '">', str_replace(' ', '&nbsp;', ucwords($key)), '</a>&nbsp;<span class="smalltext">(', $value, ')</span> ';
}
else
echo $txt['tags_none_in_cloud'];

echo '
</td>
</tr>
</table>';
}

Bye !
Antonio
« Last Edit: April 13, 2009, 03:32:51 AM by fotografo74 »

Offline fotografo74

  • Jr. Member
  • **
  • Posts: 51
  • SMF Version: 2 RC1-1
  • SP Version: 2.3
Re: Tags cloud in PHP block
« Reply #1 on: April 10, 2009, 03:46:40 PM »
Thanks. This is nice trick.
Hi :-)
This is help request...not my trick!  :D
I hope that anyone help me :-)
Antonio

Offline Yağız...

  • Jr. Member
  • **
  • Posts: 80
  • Gender: Male
Re: Tags cloud in PHP block
« Reply #2 on: April 10, 2009, 04:38:55 PM »
Code: [Select]
   global $context, $smcFunc, $modSettings, $txt, $scripturl;

   $context['tags'] = array();

   // A big thank you to Prism Perfect for this code!
   // http://prism-perfect.net/archive/php-tag-cloud-tutorial/

   $result = $smcFunc['db_query']('', '
      SELECT t.tag_name, COUNT(tt.id_tag) AS amount
      FROM {db_prefix}tags AS t
         INNER JOIN {db_prefix}tag_topics AS tt ON (tt.id_tag = t.id_tag)
      GROUP BY tt.id_tag
      LIMIT {int:limit}',
      array(
         'limit' => $modSettings['tags_to_show']
      )
   );

   while ($row = $smcFunc['db_fetch_assoc']($result)) {
      $tags[$row['tag_name']] = $row['amount'];
   }

   $smcFunc['db_free_result']($result);

   // Let's shuffle these puppies up, to make it more fun
   $keys = array_keys($tags);
   shuffle($keys);

   foreach ($keys as $key)
      $context['tags'][$key] = $tags[$key];

   $context['max_size'] = (int) $modSettings['max_tag_percentage'];
   $context['min_size'] = (int) $modSettings['min_tag_percentage'];
   $context['max_qty'] = (int) max(array_values($context['tags']));
   $context['min_qty'] = (int) min(array_values($context['tags']));

   $spread = $context['max_qty'] - $context['min_qty'];
   $spread = ($spread > 0) ? $spread : 1;

   $context['step'] = ($context['max_size'] - $context['min_size']) / $spread;

   // Load the main Tags template
   loadtemplate('Tagging');

  // I'm settings this here so that you can change it on a per-theme basis
   $context['tag_colors'] = array(
      '#0AC92B', // Green
      '#CC00FF', // Purple
      '#FF0033', // Red
      '#4D4DFF', // Blue
      '#000000', // Black
   );

   $num_colors = count($context['tag_colors']) - 1;

   echo '
      <table border="0" cellspacing="0" cellpadding="8" align="center" class="tborder" style="width: 60%;">
         <tr class="catbg3">
            <td align="center"><b>', $txt['tags_tag_cloud'], '</b></td>
         </tr>
         <tr>
            <td class="windowbg" style="padding: 1em 2em 1em 2em; text-align: center;">';

   if(!empty($context['tags']))
      foreach ($context['tags'] as $key => $value){
         $color = $context['tag_colors'][mt_rand(0, $num_colors)];
         $size = ceil($context['min_size'] + (($value - $context['min_qty']) * $context['step']));
         // The index is so we can put smaller elements in front, so they won't get swallowed by the big ones.
         $index = abs($size - $context['max_size']);

         echo '<a href="', $scripturl, '?action=tags;name=', urlencode($key), '" style="z-index: ', $index, '; position: relative; font-size: ', $size, '%; color: ', $color, ';" title="', $value, ' ', $txt['tags_tagged_with'], ' ', ucwords($key), '">', str_replace(' ', '&nbsp;', ucwords($key)), '</a>&nbsp;<span class="smalltext">(', $value, ')</span> ';
      }
   else
      echo $txt['tags_none_in_cloud'];

   echo '
            </td>
         </tr>
      </table>';
Not sure but you can try this.

Offline fotografo74

  • Jr. Member
  • **
  • Posts: 51
  • SMF Version: 2 RC1-1
  • SP Version: 2.3
Re: Tags cloud in PHP block
« Reply #3 on: April 11, 2009, 12:49:00 AM »
Code: [Select]
   global $context, $smcFunc, $modSettings, $txt, $scripturl;

   $context['tags'] = array();

   // A big thank you to Prism Perfect for this code!
   // http://prism-perfect.net/archive/php-tag-cloud-tutorial/

   $result = $smcFunc['db_query']('', '
      SELECT t.tag_name, COUNT(tt.id_tag) AS amount
      FROM {db_prefix}tags AS t
         INNER JOIN {db_prefix}tag_topics AS tt ON (tt.id_tag = t.id_tag)
      GROUP BY tt.id_tag
      LIMIT {int:limit}',
      array(
         'limit' => $modSettings['tags_to_show']
      )
   );

   while ($row = $smcFunc['db_fetch_assoc']($result)) {
      $tags[$row['tag_name']] = $row['amount'];
   }

   $smcFunc['db_free_result']($result);

   // Let's shuffle these puppies up, to make it more fun
   $keys = array_keys($tags);
   shuffle($keys);

   foreach ($keys as $key)
      $context['tags'][$key] = $tags[$key];

   $context['max_size'] = (int) $modSettings['max_tag_percentage'];
   $context['min_size'] = (int) $modSettings['min_tag_percentage'];
   $context['max_qty'] = (int) max(array_values($context['tags']));
   $context['min_qty'] = (int) min(array_values($context['tags']));

   $spread = $context['max_qty'] - $context['min_qty'];
   $spread = ($spread > 0) ? $spread : 1;

   $context['step'] = ($context['max_size'] - $context['min_size']) / $spread;

   // Load the main Tags template
   loadtemplate('Tagging');

  // I'm settings this here so that you can change it on a per-theme basis
   $context['tag_colors'] = array(
      '#0AC92B', // Green
      '#CC00FF', // Purple
      '#FF0033', // Red
      '#4D4DFF', // Blue
      '#000000', // Black
   );

   $num_colors = count($context['tag_colors']) - 1;

   echo '
      <table border="0" cellspacing="0" cellpadding="8" align="center" class="tborder" style="width: 60%;">
         <tr class="catbg3">
            <td align="center"><b>', $txt['tags_tag_cloud'], '</b></td>
         </tr>
         <tr>
            <td class="windowbg" style="padding: 1em 2em 1em 2em; text-align: center;">';

   if(!empty($context['tags']))
      foreach ($context['tags'] as $key => $value){
         $color = $context['tag_colors'][mt_rand(0, $num_colors)];
         $size = ceil($context['min_size'] + (($value - $context['min_qty']) * $context['step']));
         // The index is so we can put smaller elements in front, so they won't get swallowed by the big ones.
         $index = abs($size - $context['max_size']);

         echo '<a href="', $scripturl, '?action=tags;name=', urlencode($key), '" style="z-index: ', $index, '; position: relative; font-size: ', $size, '%; color: ', $color, ';" title="', $value, ' ', $txt['tags_tagged_with'], ' ', ucwords($key), '">', str_replace(' ', '&nbsp;', ucwords($key)), '</a>&nbsp;<span class="smalltext">(', $value, ')</span> ';
      }
   else
      echo $txt['tags_none_in_cloud'];

   echo '
            </td>
         </tr>
      </table>';
Not sure but you can try this.
Thanks!
I don't understand....in preview mode the block works perfect, but in normal mode i have this error:
Fatal error: Cannot redeclare template_main() (previously declared in /home/macrofor/public_html/Sources/Load.php(2015) : eval()'d code:6) in /home/macrofor/public_html/Sources/Load.php(2015) : eval()'d code on line 69

Thanks for helps!
Antonio

Offline Yağız...

  • Jr. Member
  • **
  • Posts: 80
  • Gender: Male
Re: Tags cloud in PHP block
« Reply #4 on: April 11, 2009, 05:13:58 AM »
Remove that:
Code: [Select]
   // Load the main Tags template
   loadtemplate('Tagging');

Offline Daydreamer

  • Jr. Member
  • **
  • Posts: 59
  • Gender: Male
  • ЯocKayseri
    • mnyk
  • SMF Version: 2 RC1
  • SP Version: 2.2
Re: Tags cloud in PHP block
« Reply #5 on: April 11, 2009, 12:27:30 PM »
Sorry. I was write wrong topic.

Offline fotografo74

  • Jr. Member
  • **
  • Posts: 51
  • SMF Version: 2 RC1-1
  • SP Version: 2.3
Re: Tags cloud in PHP block
« Reply #6 on: April 12, 2009, 03:08:12 PM »
Remove that:
Code: [Select]
   // Load the main Tags template
   loadtemplate('Tagging');
Thanks,it works perfects! thanks!
i put the code in php block,no body,no title,and i modified width to 100%.
The results:www.macroforum.org,top block.
thanks!
antonio

Offline marcozambi

  • Just Registered
  • Posts: 1
  • SMF Version: 2 RC1
  • SP Version: 2.2
Re: [TIPS]Tags cloud in PHP block
« Reply #7 on: April 29, 2009, 05:25:07 AM »
Hi!
I modified code to just fit into a standard custom PHP block for SimplePortal 2.2
In this way we have better lines separation, centered text, and you can use normal block's Title property.
Code: [Select]
global $context, $smcFunc, $modSettings, $txt, $scripturl;

   $context['tags'] = array();

   // A big thank you to Prism Perfect for this code!
   // http://prism-perfect.net/archive/php-tag-cloud-tutorial/

   $result = $smcFunc['db_query']('', '
      SELECT t.tag_name, COUNT(tt.id_tag) AS amount
      FROM {db_prefix}tags AS t
         INNER JOIN {db_prefix}tag_topics AS tt ON (tt.id_tag = t.id_tag)
      GROUP BY tt.id_tag
      LIMIT {int:limit}',
      array(
         'limit' => $modSettings['tags_to_show']
      )
   );

   while ($row = $smcFunc['db_fetch_assoc']($result)) {
      $tags[$row['tag_name']] = $row['amount'];
   }

   $smcFunc['db_free_result']($result);

   // Let's shuffle these puppies up, to make it more fun
   $keys = array_keys($tags);
   shuffle($keys);

   foreach ($keys as $key)
      $context['tags'][$key] = $tags[$key];

   $context['max_size'] = (int) $modSettings['max_tag_percentage'];
   $context['min_size'] = (int) $modSettings['min_tag_percentage'];
   $context['max_qty'] = (int) max(array_values($context['tags']));
   $context['min_qty'] = (int) min(array_values($context['tags']));

   $spread = $context['max_qty'] - $context['min_qty'];
   $spread = ($spread > 0) ? $spread : 1;

   $context['step'] = ($context['max_size'] - $context['min_size']) / $spread;

  // I'm settings this here so that you can change it on a per-theme basis
   $context['tag_colors'] = array(
      '#0AC92B', // Green
      '#CC00FF', // Purple
      '#FF0033', // Red
      '#4D4DFF', // Blue
      '#000000', // Black
   );

   echo "<div style=\"text-align:center;\">";
   $num_colors = count($context['tag_colors']) - 1;
   if(!empty($context['tags']))
      foreach ($context['tags'] as $key => $value){
         $color = $context['tag_colors'][mt_rand(0, $num_colors)];
         $size = ceil($context['min_size'] + (($value - $context['min_qty']) * $context['step']));
         // The index is so we can put smaller elements in front, so they won't get swallowed by the big ones.
         $index = abs($size - $context['max_size']);

         echo '<a href="', $scripturl, '?action=tags;name=', urlencode($key), '" style="line-height:1.2; z-index: ', $index, '; position: relative; font-size: ', $size, '%; color: ', $color, ';" title="', $value, ' ', $txt['tags_tagged_with'], ' ', ucwords($key), '">', str_replace(' ', ' ', ucwords($key)), '</a> <span class="smalltext">(', $value, ')</span> ';
      }
   else
      echo $txt['tags_none_in_cloud'];
echo "</div>";

Offline Blue

  • Customizer
  • *
  • Posts: 379
  • Gender: Male
  • Block Maker? =P
Re: [TIPS]Tags cloud in PHP block
« Reply #8 on: April 29, 2009, 04:22:20 PM »
Hi,

I'm using Tagging System (by vgamer) and I wanted a block with the cloud system too.

So, I messed up here and there and IT'S WORKING ;D

If someone wants it, just add a php block with this code: (for SMF 2)
Code: [Select]
global $context, $txt, $mbname,$scripturl, $user_info, $smcFunc,  $modSettings;

  // Tag cloud from http://www.prism-perfect.net/archive/php-tag-cloud-tutorial/
$result = $smcFunc['db_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 " .  $modSettings['smftags_set_cloud_tags_to_show']);

// 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 = $smcFunc['db_fetch_assoc']($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 = $modSettings['smftags_set_cloud_max_font_size_precent']; // max font size in %
$min_size = $modSettings['smftags_set_cloud_min_font_size_precent']; // 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;tagid=' . $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 > ($modSettings['smftags_set_cloud_tags_per_row']-1))
   {
   $context['poptags'] .= '<br />';
   $row_count =0;
   }
    // notice the space at the end of the link
}
}


// Find Results
$dbresult = $smcFunc['db_query']('', "
SELECT DISTINCT l.ID_TOPIC, t.num_replies,t.num_views,m.id_member,m.poster_name,m.subject,m.id_topic,m.poster_time, m.thank_you_post_counter, t.id_board
FROM ({db_prefix}tags_log as l,{db_prefix}boards AS b, {db_prefix}topics as t, {db_prefix}messages as m)
WHERE b.ID_BOARD = t.id_board AND l.ID_TOPIC = t.id_topic AND t.approved = 1 AND t.id_first_msg = m.id_msg AND " . $user_info['query_see_board'] . " ORDER BY l.ID DESC LIMIT 20");

$context['tags_topics'] = array();
while ($row = $smcFunc['db_fetch_assoc']($dbresult))
{
$context['tags_topics'][] = array(
'id_member' => $row['id_member'],
'poster_name' => $row['poster_name'],
'subject' => $row['subject'],
'id_topic' => $row['id_topic'],
'poster_time' => $row['poster_time'],
'num_views' => $row['num_views'],
'num_replies' => $row['num_replies'],
'thank_you_post_counter' => $row['thank_you_post_counter'],
);
}
$smcFunc['db_free_result']($dbresult);
echo'
<center>';
if (isset($context['poptags']))
  echo $context['poptags'];
echo'
</center>';

Don't thank me, thank vgamer for this great mod ;)
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Offline fotografo74

  • Jr. Member
  • **
  • Posts: 51
  • SMF Version: 2 RC1-1
  • SP Version: 2.3
Re: [TIPS]Tags cloud in PHP block
« Reply #9 on: May 15, 2009, 03:01:47 AM »
Hi!
I modified code to just fit into a standard custom PHP block for SimplePortal 2.2
In this way we have better lines separation, centered text, and you can use normal block's Title property.
Code: [Select]
global $context, $smcFunc, $modSettings, $txt, $scripturl;

   $context['tags'] = array();

   // A big thank you to Prism Perfect for this code!
   // http://prism-perfect.net/archive/php-tag-cloud-tutorial/

   $result = $smcFunc['db_query']('', '
      SELECT t.tag_name, COUNT(tt.id_tag) AS amount
      FROM {db_prefix}tags AS t
         INNER JOIN {db_prefix}tag_topics AS tt ON (tt.id_tag = t.id_tag)
      GROUP BY tt.id_tag
      LIMIT {int:limit}',
      array(
         'limit' => $modSettings['tags_to_show']
      )
   );

   while ($row = $smcFunc['db_fetch_assoc']($result)) {
      $tags[$row['tag_name']] = $row['amount'];
   }

   $smcFunc['db_free_result']($result);

   // Let's shuffle these puppies up, to make it more fun
   $keys = array_keys($tags);
   shuffle($keys);

   foreach ($keys as $key)
      $context['tags'][$key] = $tags[$key];

   $context['max_size'] = (int) $modSettings['max_tag_percentage'];
   $context['min_size'] = (int) $modSettings['min_tag_percentage'];
   $context['max_qty'] = (int) max(array_values($context['tags']));
   $context['min_qty'] = (int) min(array_values($context['tags']));

   $spread = $context['max_qty'] - $context['min_qty'];
   $spread = ($spread > 0) ? $spread : 1;

   $context['step'] = ($context['max_size'] - $context['min_size']) / $spread;

  // I'm settings this here so that you can change it on a per-theme basis
   $context['tag_colors'] = array(
      '#0AC92B', // Green
      '#CC00FF', // Purple
      '#FF0033', // Red
      '#4D4DFF', // Blue
      '#000000', // Black
   );

   echo "<div style=\"text-align:center;\">";
   $num_colors = count($context['tag_colors']) - 1;
   if(!empty($context['tags']))
      foreach ($context['tags'] as $key => $value){
         $color = $context['tag_colors'][mt_rand(0, $num_colors)];
         $size = ceil($context['min_size'] + (($value - $context['min_qty']) * $context['step']));
         // The index is so we can put smaller elements in front, so they won't get swallowed by the big ones.
         $index = abs($size - $context['max_size']);

         echo '<a href="', $scripturl, '?action=tags;name=', urlencode($key), '" style="line-height:1.2; z-index: ', $index, '; position: relative; font-size: ', $size, '%; color: ', $color, ';" title="', $value, ' ', $txt['tags_tagged_with'], ' ', ucwords($key), '">', str_replace(' ', ' ', ucwords($key)), '</a> <span class="smalltext">(', $value, ')</span> ';
      }
   else
      echo $txt['tags_none_in_cloud'];
echo "</div>";

Thanks Marco! It's better!
Grazie Marco, questo è migliore!
Antonio