PLEASE NOTE! The following snippets are user submitted. Use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.

This page snippet shows a graphical display of the hottest content on your site. It works like c|Net's what's hot, but is not a simple copy: the way of choosing colors and calculating block positions is not exactly the same and directly depends on page statistics. Three different views are available: hottest of all time, hottest of today and the hottest topic of last weeks.

To use this code, you first need to activate the watchdog/statistics module and to activate the node counters for today and all time counts.

Click here to view a demonstration: http://aam.ugpl.de/?q=node/1298

It would be very nice, when somebody can make a module upon this code in the same way, like the (very nice) tagadelic module ;-)

<?php
/**
* This php snippet displays a list of links
* to most viewed pages 
*
* To increase/decrease the number of nodes listed
* change the $list_length value to suit.
*
* Works with Drupal 5.x, 4.7.x, 4.6.x and 4.5.x
*
* Snippet submitted by aam
*/
$output = "<table border=0><tr><td>\n";

$output .= "<div id='container' style='position:relative; top:0; left:0; padding:0 0 0 0; width:510px; height:510px;'>\n";

/* ************** Hottest of all time *************************/
$list_length = 15;
$sql = "SELECT b.title, a.nid, b.created AS min_time, CASE WHEN a.totalcount > 0 THEN a.totalcount ELSE 1 END AS rec_cnt FROM node_counter a LEFT JOIN node b ON a.nid = b.nid ORDER BY rec_cnt DESC LIMIT $list_length";
$all_nodes = array();
$result = db_query($sql);
$i=0;
$max_time_all = 19000101;
$min_time_all = 99991231;
$max_rec_cnt_all = 0;
$min_rec_cnt_all = 999999999;
$rec_cnt_all = 0;
while ($mynode = db_fetch_object($result)) {
  $i += 1;
  $all_nodes[$i] = array(
    'title' => $mynode->title,
    'path' => ('?q=node/'.$mynode->nid),
    'min_time' => format_date($mynode->min_time,'custom', 'Ymd')+0,
    'rec_cnt' => $mynode->rec_cnt
    );
  $rec_cnt_all += $mynode->rec_cnt;
  if ( $all_nodes[$i]['min_time'] > $max_time_all ) $max_time_all = $all_nodes[$i]['min_time'];
  if ( $all_nodes[$i]['min_time'] < $min_time_all ) $min_time_all = $all_nodes[$i]['min_time'];
  if ( $all_nodes[$i]['rec_cnt'] > $max_rec_cnt_all ) $max_rec_cnt_all = $all_nodes[$i]['rec_cnt'];
  if ( $all_nodes[$i]['rec_cnt'] < $min_rec_cnt_all ) $min_rec_cnt_all = $all_nodes[$i]['rec_cnt'];
  }
$a_x = 0;   $a_y = 0;
$d_x = 500; $d_y = 500;
$ratio = 0.4;
//$output .= "<br /> rec_cnt_all = $rec_cnt_all \n";
//$output .= "<br /> max_time_all = $max_time_all \n";
//$output .= "<br /> min_time_all = $min_time_all \n";
//$output .= "<br /> max_rec_cnt_all = $max_rec_cnt_all \n";
//$output .= "<br /> min_rec_cnt_all = $min_rec_cnt_all \n";
$output .= "<div id='alltime' style='position:absolute; top:0; left:0; padding:0 0 0 0; width:".$d_x."px; height:".$d_y."px; visibility:visible;'>\n";
$sum_rec_cnt = 0;
$myitems = array();
$i=1;
foreach ($all_nodes as $mynode) {
  $myitems[$i] = $mynode;
  $i += 1;
  $sum_rec_cnt += $mynode['rec_cnt'];
  if ( ($sum_rec_cnt+$mynode['rec_cnt'])/$rec_cnt_all > $ratio ) {
    if ( $d_y-$a_y <= $d_x-$a_x  ) {
      // drawing area
      $width = round( ($sum_rec_cnt/$rec_cnt_all) * ($d_x-$a_x) );
      $pos=$a_y;
      foreach($myitems as $node) {
        $output .= "<div style='position:absolute; top:".$pos."px; left:".$a_x."px; width:". ($width-2) ."px; height:". (round(($node['rec_cnt']/$sum_rec_cnt)*($d_y-$a_y))-2) ."px; background-color:rgb(". (50+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*40) ."%,". (70+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*30) ."%,". (90+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*10) ."%); padding:0 0 0 0; magrin:0 0 0 0; border-style:solid; border-width:1px; border-color:#003377; overflow:hidden;'>";
        $output .= "<a href='". $node['path'] ."' style='color:#000000; font-size:". round(8+(($node['rec_cnt']-$min_rec_cnt_all+1)/($max_rec_cnt_all-$min_rec_cnt_all+1))*14, 0) ."px;' alt='". $node['title'] ."'>". $node['title'] ."</a>";
        $output .= "</div>\n";
        $pos += round(($node['rec_cnt']/$sum_rec_cnt)*($d_y-$a_y));
        }
      // set the target area
      $a_x += $width;
      }
    else {
      // drawing area
      $width = round( ($sum_rec_cnt/$rec_cnt_all) * ($d_y-$a_y) );
      $pos=$a_x;
      foreach($myitems as $node) {
        $output .= "<div style='position:absolute; top:".$a_y."px; left:".$pos."px; width:". (round(($node['rec_cnt']/$sum_rec_cnt)*($d_x-$a_x))-2) ."px; height:". ($width-2) ."px; background-color:rgb(". (50+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*40) ."%,". (70+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*30) ."%,". (90+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*10) ."%); padding:0 0 0 0; magrin:0 0 0 0; border-style:solid; border-width:1px; border-color:#003377; overflow:hidden;'>";
        $output .= "<a href='". $node['path'] ."' style='color:#000000; font-size:". round(8+(($node['rec_cnt']-$min_rec_cnt_all+1)/($max_rec_cnt_all-$min_rec_cnt_all+1))*14, 0) ."px;' alt='". $node['title'] ."'>". $node['title'] ."</a>";
        $output .= "</div>\n";
        $pos += round(($node['rec_cnt']/$sum_rec_cnt)*($d_x-$a_x));
        }
      // set the target area
      $a_y += $width;
      }
    // reset algorithm
    $i = 1;
    $rec_cnt_all -= $sum_rec_cnt;
    $sum_rec_cnt = 0;
    unset($myitems);
    $myitems = array();
    }
  }
$output .= "</div>\n";

/* ************** Hottest of today *************************/
$list_length = 15;
$sql = "SELECT b.title, a.nid, b.created AS min_time, CASE WHEN a.daycount > 0 THEN a.daycount ELSE 1 END AS rec_cnt FROM node_counter a LEFT JOIN node b ON a.nid = b.nid ORDER BY rec_cnt DESC LIMIT $list_length";
$all_nodes = array();
$result = db_query($sql);
$i=0;
$max_time_all = 19000101;
$min_time_all = 99991231;
$max_rec_cnt_all = 0;
$min_rec_cnt_all = 999999999;
$rec_cnt_all = 0;
while ($mynode = db_fetch_object($result)) {
  $i += 1;
  $all_nodes[$i] = array(
    'title' => $mynode->title,
    'path' => ('?q=node/'.$mynode->nid),
    'min_time' => format_date($mynode->min_time,'custom', 'Ymd')+0,
    'rec_cnt' => $mynode->rec_cnt
    );
  $rec_cnt_all += $mynode->rec_cnt;
  if ( $all_nodes[$i]['min_time'] > $max_time_all ) $max_time_all = $all_nodes[$i]['min_time'];
  if ( $all_nodes[$i]['min_time'] < $min_time_all ) $min_time_all = $all_nodes[$i]['min_time'];
  if ( $all_nodes[$i]['rec_cnt'] > $max_rec_cnt_all ) $max_rec_cnt_all = $all_nodes[$i]['rec_cnt'];
  if ( $all_nodes[$i]['rec_cnt'] < $min_rec_cnt_all ) $min_rec_cnt_all = $all_nodes[$i]['rec_cnt'];
  }
$a_x = 0;   $a_y = 0;
$d_x = 500; $d_y = 500;
$ratio = 0.4;
//$output .= "<br /> rec_cnt_all = $rec_cnt_all \n";
//$output .= "<br /> max_time_all = $max_time_all \n";
//$output .= "<br /> min_time_all = $min_time_all \n";
//$output .= "<br /> max_rec_cnt_all = $max_rec_cnt_all \n";
//$output .= "<br /> min_rec_cnt_all = $min_rec_cnt_all \n";
$output .= "<div id='today' style='position:absolute; top:0; left:0; padding:0 0 0 0; width:".$d_x."px; height:".$d_y."px; visibility:hidden;'>\n";
$sum_rec_cnt = 0;
$myitems = array();
$i=1;
foreach ($all_nodes as $mynode) {
  $myitems[$i] = $mynode;
  $i += 1;
  $sum_rec_cnt += $mynode['rec_cnt'];
  if ( ($sum_rec_cnt+$mynode['rec_cnt'])/$rec_cnt_all > $ratio ) {
    if ( $d_y-$a_y <= $d_x-$a_x  ) {
      // drawing area
      $width = round( ($sum_rec_cnt/$rec_cnt_all) * ($d_x-$a_x) );
      $pos=$a_y;
      foreach($myitems as $node) {
        $output .= "<div style='position:absolute; top:".$pos."px; left:".$a_x."px; width:". ($width-2) ."px; height:". (round(($node['rec_cnt']/$sum_rec_cnt)*($d_y-$a_y))-2) ."px; background-color:rgb(". (50+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*40) ."%,". (70+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*30) ."%,". (90+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*10) ."%); padding:0 0 0 0; magrin:0 0 0 0; border-style:solid; border-width:1px; border-color:#003377; overflow:hidden;'>";
        $output .= "<a href='". $node['path'] ."' style='color:#000000; font-size:". round(8+(($node['rec_cnt']-$min_rec_cnt_all+1)/($max_rec_cnt_all-$min_rec_cnt_all+1))*14, 0) ."px;' alt='". $node['title'] ."'>". $node['title'] ."</a>";
        $output .= "</div>\n";
        $pos += round(($node['rec_cnt']/$sum_rec_cnt)*($d_y-$a_y));
        }
      // set the target area
      $a_x += $width;
      }
    else {
      // drawing area
      $width = round( ($sum_rec_cnt/$rec_cnt_all) * ($d_y-$a_y) );
      $pos=$a_x;
      foreach($myitems as $node) {
        $output .= "<div style='position:absolute; top:".$a_y."px; left:".$pos."px; width:". (round(($node['rec_cnt']/$sum_rec_cnt)*($d_x-$a_x))-2) ."px; height:". ($width-2) ."px; background-color:rgb(". (50+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*40) ."%,". (70+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*30) ."%,". (90+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*10) ."%); padding:0 0 0 0; magrin:0 0 0 0; border-style:solid; border-width:1px; border-color:#003377; overflow:hidden;'>";
        $output .= "<a href='". $node['path'] ."' style='color:#000000; font-size:". round(8+(($node['rec_cnt']-$min_rec_cnt_all+1)/($max_rec_cnt_all-$min_rec_cnt_all+1))*14, 0) ."px;' alt='". $node['title'] ."'>". $node['title'] ."</a>";
        $output .= "</div>\n";
        $pos += round(($node['rec_cnt']/$sum_rec_cnt)*($d_x-$a_x));
        }
      // set the target area
      $a_y += $width;
      }
    // reset algorithm
    $i = 1;
    $rec_cnt_all -= $sum_rec_cnt;
    $sum_rec_cnt = 0;
    unset($myitems);
    $myitems = array();
    }
  }
$output .= "</div>\n";

/* ************** Hottest of last week *************************/
$list_length = 15;
$sql = "SELECT title, path, MAX(timestamp) AS min_time, COUNT(*) AS rec_cnt FROM accesslog WHERE path LIKE '%book/%' OR path LIKE '%node/%' OR path LIKE '%image/%' GROUP BY title, path ORDER BY rec_cnt DESC LIMIT $list_length";
$all_nodes = array();
$result = db_query($sql);
$i=0;
$max_time_all = 19000101;
$min_time_all = 99991231;
$max_rec_cnt_all = 0;
$min_rec_cnt_all = 999999999;
$rec_cnt_all = 0;
while ($mynode = db_fetch_object($result)) {
  $i += 1;
  $all_nodes[$i] = array(
    'title' => $mynode->title,
    'path' => $mynode->path,
    'min_time' => format_date($mynode->min_time,'custom', 'Ymd')+0,
    'rec_cnt' => $mynode->rec_cnt
    );
  $rec_cnt_all += $mynode->rec_cnt;
  if ( $all_nodes[$i]['min_time'] > $max_time_all ) $max_time_all = $all_nodes[$i]['min_time'];
  if ( $all_nodes[$i]['min_time'] < $min_time_all ) $min_time_all = $all_nodes[$i]['min_time'];
  if ( $all_nodes[$i]['rec_cnt'] > $max_rec_cnt_all ) $max_rec_cnt_all = $all_nodes[$i]['rec_cnt'];
  if ( $all_nodes[$i]['rec_cnt'] < $min_rec_cnt_all ) $min_rec_cnt_all = $all_nodes[$i]['rec_cnt'];
  }
$a_x = 0;   $a_y = 0;
$d_x = 500; $d_y = 500;
$ratio = 0.4;
//$output .= "<br /> rec_cnt_all = $rec_cnt_all \n";
//$output .= "<br /> max_time_all = $max_time_all \n";
//$output .= "<br /> min_time_all = $min_time_all \n";
//$output .= "<br /> max_rec_cnt_all = $max_rec_cnt_all \n";
//$output .= "<br /> min_rec_cnt_all = $min_rec_cnt_all \n";
$output .= "<div id='weeks' style='position:absolute; top:0; left:0; padding:0 0 0 0; width:".$d_x."px; height:".$d_y."px; visibility:hidden;'>\n";
$sum_rec_cnt = 0;
$myitems = array();
$i=1;
foreach ($all_nodes as $mynode) {
  $myitems[$i] = $mynode;
  $i += 1;
  $sum_rec_cnt += $mynode['rec_cnt'];
  if ( ($sum_rec_cnt+$mynode['rec_cnt'])/$rec_cnt_all > $ratio ) {
    if ( $d_y-$a_y <= $d_x-$a_x  ) {
      // drawing area
      $width = round( ($sum_rec_cnt/$rec_cnt_all) * ($d_x-$a_x) );
      $pos=$a_y;
      foreach($myitems as $node) {
        $output .= "<div style='position:absolute; top:".$pos."px; left:".$a_x."px; width:". ($width-2) ."px; height:". (round(($node['rec_cnt']/$sum_rec_cnt)*($d_y-$a_y))-2) ."px; background-color:rgb(". (50+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*40) ."%,". (70+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*30) ."%,". (90+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*10) ."%); padding:0 0 0 0; magrin:0 0 0 0; border-style:solid; border-width:1px; border-color:#003377; overflow:hidden;'>";
        $output .= "<a href='". $node['path'] ."' style='color:#000000; font-size:". round(8+(($node['rec_cnt']-$min_rec_cnt_all+1)/($max_rec_cnt_all-$min_rec_cnt_all+1))*14, 0) ."px;' alt='". $node['title'] ."'>". $node['title'] ."</a>";
        $output .= "</div>\n";
        $pos += round(($node['rec_cnt']/$sum_rec_cnt)*($d_y-$a_y));
        }
      // set the target area
      $a_x += $width;
      }
    else {
      // drawing area
      $width = round( ($sum_rec_cnt/$rec_cnt_all) * ($d_y-$a_y) );
      $pos=$a_x;
      foreach($myitems as $node) {
        $output .= "<div style='position:absolute; top:".$a_y."px; left:".$pos."px; width:". (round(($node['rec_cnt']/$sum_rec_cnt)*($d_x-$a_x))-2) ."px; height:". ($width-2) ."px; background-color:rgb(". (50+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*40) ."%,". (70+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*30) ."%,". (90+(($node['min_time']-$min_time_all+1)/($max_time_all-$min_time_all+1))*10) ."%); padding:0 0 0 0; magrin:0 0 0 0; border-style:solid; border-width:1px; border-color:#003377; overflow:hidden;'>";
        $output .= "<a href='". $node['path'] ."' style='color:#000000; font-size:". round(8+(($node['rec_cnt']-$min_rec_cnt_all+1)/($max_rec_cnt_all-$min_rec_cnt_all+1))*14, 0) ."px;' alt='". $node['title'] ."'>". $node['title'] ."</a>";
        $output .= "</div>\n";
        $pos += round(($node['rec_cnt']/$sum_rec_cnt)*($d_x-$a_x));
        }
      // set the target area
      $a_y += $width;
      }
    // reset algorithm
    $i = 1;
    $rec_cnt_all -= $sum_rec_cnt;
    $sum_rec_cnt = 0;
    unset($myitems);
    $myitems = array();
    }
  }
$output .= "</div>\n";

/* ******* end of container ************ */

$output .= "</div>\n";

$output .= "</td><td style='vertical-align:top;'>\n";

$output .= "<h4>Hottest:</h4> <a onmouseover='{ document.getElementById(\"alltime\").style.visibility=\"visible\"; document.getElementById(\"today\").style.visibility=\"hidden\"; document.getElementById(\"weeks\").style.visibility=\"hidden\" }' href=''>of all time</a>\n";

$output .= "<br /> <a onmouseover='{ document.getElementById(\"alltime\").style.visibility=\"hidden\"; document.getElementById(\"today\").style.visibility=\"visible\"; document.getElementById(\"weeks\").style.visibility=\"hidden\"; }' href=''>of today</a>\n";

$output .= "<br /> <a onmouseover='{ document.getElementById(\"alltime\").style.visibility=\"hidden\"; document.getElementById(\"today\").style.visibility=\"hidden\"; document.getElementById(\"weeks\").style.visibility=\"visible\"; }' href=''>of last weeks</a>\n";

$output .= "<p>Larger boxes indicate more popular items.\n";
$output .= "<br />Darker boxes indicate older items.</p>\n";
$output .= "</td></tr></table>\n";

print $output;
?>