refreshOptions(); $this->tags = bb_get_top_tags( false, $this->limit); } /** * get the options from the database * * @author Aditya Naik * @version 1.0 * @return array */ public function getOptions() { return bb_get_option('enhanced_tag_heat_map'); } /** * put the options from the database * * @author Aditya Naik * @version 1.0 * @return array */ public function putOptions() { $options = array(); $options['smallest'] = $this->smallest; $options['largest'] = $this->largest; $options['limit'] = $this->limit; $options['unit'] = $this->unit; $options['related_foreground'] = $this->related_foreground; $options['related_background'] = $this->related_background; bb_update_option('enhanced_tag_heat_map',$options); } /** * if the database option is not retrieved, retrieve it; * @return */ private function refreshOptions() { $options = $this->getOptions(); if (!$options) { $this->setDefaultHeatMapParams(); $this->putOptions(); } else { if (isset($options['smallest'])) $this->smallest = $options['smallest']; if (isset($options['largest'])) $this->largest = $options['largest']; if (isset($options['unit'])) $this->unit = $options['unit']; if (isset($options['limit'])) $this->limit = $options['limit']; if (isset($options['related_foreground'])) $this->related_foreground = $options['related_foreground']; if (isset($options['related_background'])) $this->related_background = $options['related_background']; } } /** * get foreground color for related link hover * * @author Aditya Naik * @version 1.0 * @return string */ public function getRelatedForegroundColor() { return $this->related_foreground; } /** * set foreground color for related link hover * * @author Aditya Naik * @version 1.0 * @return string */ public function setRelatedForegroundColor($related_foreground) { $this->related_foreground = $related_foreground; } /** * get background color for related link hover * * @author Aditya Naik * @version 1.0 * @return string */ public function getRelatedBackgroundColor() { return $this->related_background; } /** * set background color for related link hover * * @author Aditya Naik * @version 1.0 * @return string */ public function setRelatedBackgroundColor($related_background) { $this->related_background = $related_background; } /** * get smallest size options for the plugin * * @author Aditya naik * @version 1.0 * @return int */ public function getSmallestSize() { return (int)$this->smallest; } /** * set smallest size options for the plugin * * @author Aditya naik * @version 1.0 * @return void */ public function setSmallestSize($smallest) { $this->smallest = (int)$smallest; } /** * get largest size options for the plugin * * @author Aditya naik * @version 1.0 * @return int */ public function getLargestSize() { return (int)$this->largest; } /** * set largest size options for the plugin * * @author Aditya naik * @version 1.0 * @return void */ public function setLargestSize($largest) { $this->largest = (int)$largest; } /** * get size unit options for the plugin * * @author Aditya naik * @version 1.0 * @return string */ public function getUnit() { return $this->unit; } /** * set size unit options for the plugin * * @author Aditya naik * @version 1.0 * @return void */ public function setUnit($unit) { $this->unit = $unit; } /** * get limit options for the plugin * * @author Aditya naik * @version 1.0 * @return int */ public function getLimit() { return (int)$this->limit; } /** * set limit options for the plugin * * @author Aditya naik * @version 1.0 * @return void */ public function setLimit($limit) { $this->limit = (int)$limit; } /** * set the parameters * * @author Aditya Naik * @return void * @param $args arguments as query parameters - smallest, largest, unit, limit */ public function setDefaultHeatMapParams() { $defaults = array( 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'limit' => 45, 'related_foreground' => '#FFFFFF', 'related_background' => '#990000'); extract($defaults, EXTR_SKIP); $this->smallest = $smallest; $this->largest = $largest; $this->unit = $unit; $this->limit = $limit; $this->related_foreground = $related_foreground; $this->related_background = $related_background; } /** * Creates a tag heat map * * @author Aditya Naik * @version 1.0 * @return string */ public function getTagHeatMap($smallest = 8, $largest = 22, $unit = 'pt', $limit = 45, $format = 'flat') { $smallest = (int)$this->smallest; $largest = (int)$this->largest; $unit = $this->unit; $limit = (int)$this->limit; $tags = $this->tags; foreach ( (array) $tags as $k => $tag ) { $counts{$tag->raw_tag} = $tag->tag_count; $taglinks{$tag->raw_tag} = bb_get_tag_link( $tag->tag ); $ids{$tag->raw_tag} = $k; } $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; do_action_ref_array( 'sort_tag_heat_map', array(&$counts) ); $a = array(); foreach ( $counts as $t => $count ) { $tag = $tags[$ids[$t]]; $taglink = attribute_escape(bb_get_tag_link( $tag->tag )); $tag_name = str_replace(' ', ' ', wp_specialchars( $t )); $a[] = "tag_count ) ) . "' class='aajax tagheata' rel='tag' style='font-size: " . ( $smallest + ( ( $tag->tag_count - $min_count ) * $fontstep ) ) . "$unit;'>$tag_name"; } $r = join("\n", $a); return $r; } /** * Print script and style for the enhanced heat map * The function will be added to the action bb_head or wp_head * * @author Aditya Naik * @version 1.0.1 * @return void */ function getTagHeatMapScript() { ?> tags; $related_tags_result = $bbdb->get_results( "SELECT t.tag_id as t, tt.tag_id as rt FROM $bbdb->tagged t JOIN $bbdb->tagged AS tt ON (t.topic_id = tt.topic_id)" ); $related_tags = array(); if ($related_tags_result) foreach($related_tags_result as $r ) { if (isset($related_tags[$r->t])) { $related_tags[$r->t] = array_merge($related_tags[$r->t], array($r->rt)); } else { $related_tags[$r->t] = array($r->rt); } } foreach($tags as $tag) { ?> tag_relation[=$tag->tag_id; ?>] = new Array(tag_id]) > 0): foreach($related_tags[$tag->tag_id] as $r_tag) { if ($tag->tag_id != $r_tag) $a_r_tags[] = "'tag_" . $r_tag . "'"; } echo "" . join ($a_r_tags, ","); $a_r_tags = null; endif; ?>);getTagHeatMap(); } // Filter to replace the current heat map add_filter('tag_heat_map','show_enhanced_tag_heat_map'); // Add script to the head if user is loading it in bbpress bb_enqueue_script('prototype'); add_action('bb_head','enhanced_tag_heat_map_script'); /** * Print script and style for the enhanced heat map * The function will be added to the action bb_head or wp_head * * @author Aditya Naik * @version 1.0 * @return void */ function enhanced_tag_heat_map_script() { global $ethm; if(!$ethm) $ethm = new enhancedTagHeatMap(); return $ethm->getTagHeatMapScript(); } global $ethm; if(!$ethm) $ethm = new enhancedTagHeatMap(); // Don't bother with admin interface unless we are loading an admin page if (!BB_IS_ADMIN) { return; } // Add filters for the admin area add_action('bb_admin_menu_generator', 'enhanced_tag_heat_map_admin_page_add'); add_action('bb_admin-header.php', 'enhanced_tag_heat_map_admin_page_process'); if($_GET['plugin']=='enhanced_tag_heat_map_admin_page') { if($_GET['reset']=='true') { add_action('bb_admin_notices','show_enhanced_tag_heat_map_reset_notice'); } else if ($_GET['updated']==true) { add_action('bb_admin_notices','show_enhanced_tag_heat_map_update_notice'); } } /** * Adds in menu item to the admin page * * @author Aditya Naik * @version 10 * @return void **/ function enhanced_tag_heat_map_admin_page_add() { bb_admin_add_submenu(__('Enhanced Tag Heat Map'), 'use_keys', 'enhanced_tag_heat_map_admin_page'); } /** * Creates an admin page for the plugin * * @author Aditya Naik * @version 1.0 * @return void */ function enhanced_tag_heat_map_admin_page() { global $ethm; if (!$ethm) $ethm = new enhancedTagHeatMap(); ?>