function widget($args, $instance)
 {
     global $wpdb, $bp;
     if ($bp->gtm->slug == $bp->current_action) {
         extract($args);
         echo $before_widget;
         echo $before_title . $widget_name . $after_title;
         $data = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT `term_id`, `taxon` FROM {$bp->gtm->table_taxon}\n                  WHERE `group_id` = %d", $bp->groups->current_group->id));
         if ($instance['display_count'] == 1) {
             $count = true;
         } else {
             $count = false;
         }
         // need to get all tags and cats separately
         if (count($data) != '0') {
             foreach ($data as $term) {
                 if ($term->taxon == 'tag') {
                     $tags[$term->term_id]->id = $term->term_id;
                 }
                 if ($term->taxon == 'cat') {
                     $cats[$term->term_id]->id = $term->term_id;
                 }
             }
             // lets work with tags
             if ($instance['display_tags'] == '1') {
                 _e('<strong>Tags:</strong>', 'bp_gtm');
                 // display tags in a list
                 if ($instance['display_type_tags'] == 'list') {
                     echo '<ul id="disply-tags">';
                     if (count($tags) > 0) {
                         foreach ($tags as $tag) {
                             if ($instance['display_count'] == 1) {
                                 $count_func = ' (' . bp_gtm_count_term_usage($tag->id, $bp->groups->current_group->id) . ')';
                             }
                             echo '<li>' . stripslashes(bp_gtm_get_term_name_by_id($tag->id, $link = true)) . $count_func . '</li>';
                         }
                     } else {
                         echo '<li>' . __('No tags to display', 'bp_gtm') . '</li>';
                     }
                     echo '</ul>';
                 } elseif ($instance['display_type_tags'] == 'cloud') {
                     // display tags in a cloud
                     echo '<p>';
                     if (count($tags) > 0) {
                         foreach ($tags as $tag) {
                             echo stripslashes(bp_gtm_get_term_name_by_id($tag->id, $link = true, $count)) . ' ';
                         }
                     } else {
                         echo '<li>' . __('No tags to display', 'bp_gtm') . '</li>';
                     }
                     echo '</p>';
                 }
             }
             // now lets work with categories
             if ($instance['display_cats'] == '1') {
                 _e('<strong>Categories:</strong>', 'bp_gtm');
                 if ($instance['display_type_cats'] == 'list') {
                     echo '<ul id="disply-cats">';
                     if (count($cats) > 0) {
                         foreach ($cats as $cat) {
                             if ($instance['display_count'] == 1) {
                                 $count_func = ' (' . bp_gtm_count_term_usage($cat->id, $bp->groups->current_group->id) . ')';
                             }
                             echo '<li>' . stripslashes(bp_gtm_get_term_name_by_id($cat->id, true)) . $count_func . '</li>';
                         }
                     } else {
                         echo '<li>' . __('No categories to display', 'bp_gtm') . '</li>';
                     }
                     echo '</ul>';
                 } elseif ($instance['display_type_cats'] == 'cloud') {
                     // display categories in a cloud
                     echo '<p>';
                     if (count($cats) > 0) {
                         foreach ($cats as $cat) {
                             echo stripslashes(bp_gtm_get_term_name_by_id($cat->id, true, $count)) . ' ';
                         }
                     } else {
                         echo '<li>' . __('No categories to display', 'bp_gtm') . '</li>';
                     }
                     echo '</p>';
                 }
             }
         } else {
             echo '<div class="widget-error">' . __('There is nothing to display yet.', 'bp_gtm') . '</div>';
         }
         echo $after_widget;
     }
 }
Exemple #2
0
function bp_gtm_term_name_by_id($term_id, $link = false)
{
    echo bp_gtm_get_term_name_by_id($term_id, $link);
}