8, 'largest' => 22, 'unit' => 'pt', 'limit' => 45, 'format' => 'flat', 'minimum' => 0, 'maximum' => 0, 'forums' => 0, 'since' => 0, 'sort' => 0, 'colors' => 0 ); $args = wp_parse_args( $args, $defaults ); if ($args['colors']===0) {$args['colors']=array('24244C','600000','C00000');} if ( 1 < $fn = func_num_args() ) { // legacy $args['smallest'] = func_get_arg(0); $args['largest'] = func_get_arg(1); $args['unit'] = 2 < $fn ? func_get_arg(2) : $unit; $args['limit'] = 3 < $fn ? func_get_arg(3) : $limit; } if ($hot_tags_plus['cache']) { $filename=""; foreach ($args as $key=>$value) {if (is_array($value)) {$value=implode("_",$value);} $filename .= "_".$key."_".$value;} $filename=$hot_tags_plus['cache_dir'].$hot_tags_plus['prefix'].bb_slug_sanitize($filename); if (file_exists($filename)) {return file_get_contents($filename);} } extract($args, EXTR_SKIP); // turn arguments into strings // $tags = bb_get_top_tags( false, $limit ); // print " "; // diagnostic $limit=intval($limit); if (empty($since)) {$since="";} else { if (intval($since)<99999) { $since=strtotime($since." GMT"); } $since=" AND topic_time >= '".gmdate('Y-m-d H:i:s',intval($since))."' "; } if (empty($forums)) {$forums="";} else { if (is_array($forums)) {foreach ($forums as $key=>$value) {$forums[$key]=intval($value);}} else {$forums=intval($forums);} $forums=" AND forum_id IN (".implode(',',(array) $forums).") "; } if (empty($maximum)) {$maximum=""; $having="";} else { $maximum=" tcount <= ".intval($maximum); $having=" HAVING $maximum ";} if (empty($minimum)) {$minimum="";} else { $minimum=" tcount >= ".intval($minimum); $having=($having ? " AND " : " HAVING ").$minimum;} if (defined('BACKPRESS_PATH')) { $query="SELECT COUNT( relationships.term_taxonomy_id ) AS tcount, terms.name AS raw_tag, terms.slug AS tag, terms.term_id AS id FROM $bbdb->term_relationships AS relationships LEFT JOIN $bbdb->term_taxonomy AS taxonomy ON relationships.term_taxonomy_id = taxonomy.term_taxonomy_id LEFT JOIN $bbdb->terms AS terms ON taxonomy.term_taxonomy_id = terms.term_id LEFT JOIN $bbdb->topics AS topics ON object_id = topic_id WHERE topic_status = 0 $forums $since GROUP BY relationships.term_taxonomy_id $having ORDER BY tcount DESC, topic_time DESC LIMIT $limit"; // WHERE term_taxonomy_id IN ($ids) // AND term_taxonomy_id NOT IN (".$related_topics['exclude_tags'].") // AND object_id NOT IN (".$related_topics['exclude_topics'].") } else { $query="SELECT COUNT(relationships.tag_id) as tcount, terms.raw_tag AS raw_tag, terms.tag AS tag,terms.tag_id AS id FROM $bbdb->tagged AS relationships LEFT JOIN $bbdb->tags AS terms ON relationships.tag_id = terms.tag_id LEFT JOIN $bbdb->topics AS topics ON relationships.topic_id = topics.topic_id WHERE topic_status = 0 $forums $since GROUP BY relationships.tag_id $having ORDER BY tcount DESC, topic_time DESC LIMIT $limit"; // WHERE tag_id IN ($ids) // AND tag_id NOT IN (".$related_topics['exclude_tags'].") // AND topic_id NOT IN (".$related_topics['exclude_topics'].") } $tags=$bbdb->get_results($query); if (empty($tags)) {return '';} if ( bb_get_option('mod_rewrite') ) { $path = bb_get_option('uri' )."tags/"; } else { $path = bb_get_option('uri' )."tags.php?tag=";} foreach ( (array) $tags as $tag ) { $ids{$tag->raw_tag} = $tag->id; $counts{$tag->raw_tag} = $tag->tcount; $taglinks{$tag->raw_tag} = apply_filters( 'bb_get_tag_link', $path.$tag->tag, $tag->tag, 1 ); // $taglinks{$tag->raw_tag} = bb_get_tag_link( $tag->tag ); } $min_count = min($counts); $spread = max($counts) - $min_count; if ( $spread <= 0 ) { $spread = 1; } $fontspread = $largest - $smallest; if ( $fontspread <= 0 ) { $fontspread = 1; } $fontstep = $fontspread / $spread; $sort=strtolower($sort); if ($sort==="alphabetical") { uksort($counts, 'strnatcasecmp'); } elseif ( $sort==="highest" || $sort==="count" || $sort==="counts" || $sort==="numeric" ) { arsort($counts, SORT_NUMERIC); } elseif ( $sort==="raw" ) { // do nothing - use db sort } else { do_action_ref_array( 'sort_tag_heat_map', array(&$counts) ); } if ($colors!==0) { if (is_array($colors) && count($colors)>1) {$gradient = hot_tags_plus_gradient($colors,$spread);} // calculate color ranges max($counts) else { if (is_array($colors)) {$colors=reset($colors);} for ($i = 0; $i <= $spread ; $i++) { $gradient[$i]=$colors;} } } if ($hot_tags_plus['related']) { if (defined('BACKPRESS_PATH')) { $query="SELECT id, GROUP_CONCAT(DISTINCT CAST( related_id AS CHAR )) AS related FROM ( SELECT t2.term_taxonomy_id AS id, t1.term_taxonomy_id AS related_id FROM $bbdb->term_relationships AS t1 LEFT JOIN $bbdb->term_relationships AS t2 ON ( t1.object_id = t2.object_id ) LEFT JOIN $bbdb->term_taxonomy AS t3 ON ( t1.term_taxonomy_id = t3.term_taxonomy_id ) WHERE t2.term_taxonomy_id IN (".implode(',',$ids).") AND t1.term_taxonomy_id IN (".implode(',',$ids).") ORDER BY id,related_id ASC ) AS tags WHERE id!=related_id GROUP BY id"; // maybe WHERE t3. term_id IN ? taxonomy_id is not really = term_id } else { $query="SELECT id, GROUP_CONCAT(DISTINCT CAST( related_id AS CHAR )) AS related FROM ( SELECT t2.tag_id AS id, t1.tag_id AS related_id FROM $bbdb->tagged AS t1 LEFT JOIN $bbdb->tagged AS t2 ON ( t1.topic_id = t2.topic_id ) LEFT JOIN $bbdb->tags AS t3 ON ( t1.tag_id = t3.tag_id ) WHERE t2.tag_id IN (".implode(',',$ids).") AND t1.tag_id IN (".implode(',',$ids).") ORDER BY id,related_id ASC ) AS tags WHERE id!=related_id GROUP BY id"; } $results=$bbdb->get_results($query); if (!empty($results) && is_array($results) && count($results)) { foreach ($results as $result) {$HTP_related[$result->id]=$result->related;} $output .= <<< HTPJSEOF HTPJSEOF; } // previous line MUST be blank because of heredoc } foreach ( $counts as $tag => $count ) { $id=($hot_tags_plus['related'] ? " id='tag_".$ids[$tag]."'" : ""); $taglink = attribute_escape($taglinks{$tag}); $tag = wp_specialchars( $tag ); // str_replace(' ', ' ', wp_specialchars( $tag )); $a[] = ""; } switch ( $format ) : case 'array' : $output .= $a; break; case 'list' : $output .= "\n"; break; default : $output .= join("\n", $a) ."\n"; break; endswitch; if ($hot_tags_plus['cache']) { $current=get_current_user(); if (!($current && !in_array($current,array("nobody","httpd","apache","root")) && strpos(__FILE__,$current))) {$current="";} $x=posix_getuid (); if (0 == $x && $current) {$org_uid = posix_get_uid(); $pw_info = posix_getpwnam ($current); $uid = $pw_info["uid"]; posix_setuid ($uid);} $fh=@fopen($filename,"wb"); if ($fh) {@fwrite($fh,$output); fclose($fh);} if ($org_uid) {posix_setuid($org_uid);} } return $output; } function hot_tags_plus_delete($x='',$y='',$z='') { global $hot_tags_plus; // $files=glob($hot_tags_plus['cache_dir'].$hot_tags_plus['prefix']."*"); if ($files) {foreach($files as $fn) {@unlink($fn);}} if (empty($hot_tags_plus['cache']) || ($dir=opendir($hot_tags_plus['cache_dir']))===false) {return;} while(($file=readdir($dir))!==false) { if (strpos($file,$hot_tags_plus['prefix'])===0) { unlink($hot_tags_plus['cache_dir'].$file); } } if (!empty($dir)) {closedir($dir);} } function hot_tags_plus_head() { global $hot_tags_plus; echo ''; } function hot_tags_plus_gradient($hex_array, $steps) { $hex_array= (array) $hex_array; $tot = count($hex_array); $gradient = array(); $steps++; $fixend = 2; $passages = $tot-1; if ($passages<1) {$passages=1;} $stepsforpassage = floor($steps/$passages); $stepsremain = $steps - ($stepsforpassage*$passages); for ($pointer = 0; $pointer < $tot-1 ; $pointer++) { $hexstart = $hex_array[$pointer]; $hexend = $hex_array[$pointer + 1]; if ($stepsremain > 0) { if ($stepsremain--) {$stepsforthis = $stepsforpassage + 1;} } else {$stepsforthis = $stepsforpassage; if ($stepsforthis == 0) {$stepsforthis = 0.001;}} if ($pointer > 0) { $fixend = 1; } $start['r'] = hexdec(substr($hexstart, 0, 2)); $start['g'] = hexdec(substr($hexstart, 2, 2)); $start['b'] = hexdec(substr($hexstart, 4, 2)); $end['r'] = hexdec(substr($hexend, 0, 2)); $end['g'] = hexdec(substr($hexend, 2, 2)); $end['b'] = hexdec(substr($hexend, 4, 2)); $step['r'] = ($start['r']-$end['r'])/($stepsforthis); $step['g'] = ($start['g']-$end['g'])/($stepsforthis); $step['b'] = ($start['b']-$end['b'])/($stepsforthis); for($i = 0; $i <= $stepsforthis-$fixend; $i++) { $rgb['r'] = floor($start['r'] - ($step['r'] * $i)); $rgb['g'] = floor($start['g'] - ($step['g'] * $i)); $rgb['b'] = floor($start['b'] - ($step['b'] * $i)); $hex['r'] = sprintf('%02x', ($rgb['r'])); $hex['g'] = sprintf('%02x', ($rgb['g'])); $hex['b'] = sprintf('%02x', ($rgb['b'])); $gradient[] = strtoupper(implode(NULL, $hex)); } } $gradient[] = $hex_array[$tot-1]; return $gradient; } ?>