name == $b->name) return 0;
return ($a->name < $b->name) ? -1 : 1;
}
$exclusions = '';
if (!empty($exclude)) {
$excats = preg_split('/[\s,]+/',$exclude);
if (count($excats)) {
foreach ($excats as $excat) {
$exclusions .= ' AND '.$wpdb->categories.'.cat_ID <> ' . intval($excat) . ' ';
}
}
}
$query = "SELECT $wpdb->categories.cat_ID AS `id`, $wpdb->categories.cat_name AS `name`, $wpdb->categories.category_nicename AS `nicename`, count($wpdb->post2cat.rel_id) as `posts` FROM $wpdb->categories, $wpdb->post2cat WHERE $wpdb->categories.cat_ID = $wpdb->post2cat.category_id $exclusions GROUP BY $wpdb->categories.cat_id ORDER BY posts DESC";
if ($limit != 0) {
$query .= " LIMIT ".$limit;
}
$results = $wpdb->get_results($query);
usort($results, 'sort_cat_name');
foreach ($results as $result) {
$counts[] = $result->posts;
}
$min = min($counts);
$max = max($counts);
$spread = $max - $min;
if ($largest != $smallest) {
$fontspread = $largest - $smallest;
if ($spread != 0) {
$fontstep = $fontspread / $spread;
} else {
$fontstep = 0;
}
}
if ($hot != $cold) {
for ($i = 0; $i < 3; $i++) {
$coldval[] = hexdec($cold[$i]);
$hotval[] = hexdec($hot[$i]);
$colorspread[] = hexdec($hot[$i]) - hexdec($cold[$i]);
if ($spread != 0) {
$colorstep[] = (hexdec($hot[$i]) - hexdec($cold[$i])) / $spread;
} else {
$colorstep[] = 0;
}
}
}
foreach ($results as $result) {
$url = get_category_link($result->id);
$text = stripslashes($result->name);
$fraction = ($result->posts - $min);
$fontsize = $smallest + ($fontstep * $fraction);
$color = "";
for ($i = 0; $i < 3; $i++) {
$color .= dechex($coldval[$i] + ($colorstep[$i] * $fraction));
}
$style = "style=\"";
if ($largest != $smallest) {
$style .= "font-size:".round($fontsize).$unit.";";
}
if ($hot != $cold) {
$style .= "color:#".$color.";";
}
$style .= "\"";
echo $before
."posts
." entries\" "
.$style
.">"
.$text
.""
.$after
."\n";
}
}
function heatmap_archives($smallest=10, $largest=36, $unit="pt", $cold="00f", $hot="f00", $before='', $after=' ') {
global $querystring_start, $querystring_equal, $querystring_separator, $month, $wpdb;
$now = current_time('mysql');
$results = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) AS `posts` FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit);
foreach ($results as $result) {
$counts[] = $result->posts;
}
$min = min($counts);
$max = max($counts);
$spread = $max - $min;
if ($largest != $smallest) {
$fontspread = $largest - $smallest;
if ($spread != 0) {
$fontstep = $fontspread / $spread;
} else {
$fontstep = 0;
}
}
if ($hot != $cold) {
for ($i = 0; $i < 3; $i++) {
$coldval[] = hexdec($cold[$i]);
$hotval[] = hexdec($hot[$i]);
$colorspread[] = hexdec($hot[$i]) - hexdec($cold[$i]);
if ($spread != 0) {
$colorstep[] = (hexdec($hot[$i]) - hexdec($cold[$i])) / $spread;
} else {
$colorstep[] = 0;
}
}
}
foreach ($results as $result) {
$url = get_month_link($result->year, $result->month);
$text = sprintf('%s %d', $month[zeroise($result->month,2)], $result->year);
$fraction = ($result->posts - $min);
$fontsize = $smallest + ($fontstep * $fraction);
$color = "";
for ($i = 0; $i < 3; $i++) {
$color .= dechex($coldval[$i] + ($colorstep[$i] * $fraction));
}
$style = "style=\"";
if ($largest != $smallest) {
$style .= "font-size:".round($fontsize).$unit.";";
}
if ($hot != $cold) {
$style .= "color:#".$color.";";
}
$style .= "\"";
echo $before
."posts
." entries\" "
.$style
.">"
.$text
.""
.$after
."\n";
}
}
?>