8, 'largest' => 22, 'number' => 45, 'orderby' => 'name', 'order' => 'ASC' ); /* how many popular tags to show in the tag editing and creation form */ $popular_tag_limit = 30; /* - HERE BEGINS THE CODE - */ // load the javascript for the group tag clicks to work function gtags_enqueue() { wp_enqueue_script('gtags=group-tags', WP_PLUGIN_URL.'/buddypress-group-tags/group-tags.js'); load_plugin_textdomain( 'gtags', false, dirname( plugin_basename( __FILE__ ) ).'/lang' ); } add_action('init', 'gtags_enqueue'); //add css function gtags_header() { echo ''."\n"; } add_action('wp_head', 'gtags_header'); // this catches the ajax call, and loads the groups template function gtags_ajax() { locate_template( array( "groups/groups-loop.php" ), true ); } add_action( 'wp_ajax_gtags', 'gtags_ajax' ); // hook into group listing function, output the groups that match a given tag function gtags_show_groups_for_tag( $groups ) { global $bp, $groups_template; //echo '
'; print_r( $_POST ); echo '
'; if ( $_POST['action'] == 'groups_filter' ) return $groups; if ( $_POST['tag'] ) $tag = urldecode( $_POST['tag'] ); // this is what ajax sends if we are in group directory else if ( $bp->current_action == 'tag' ) $tag = urldecode( $bp->action_variables[0] ); // this is for the widget from all other places if ( $tag ) { echo '
'.__('Results for tag', 'gtags').': ' . $tag . '
'; $gtags_groups = gtags_get_groups_by_tag( null, null, false, false, $tag ); $groups_template->groups = $gtags_groups[groups]; // turn off pagination $groups_template->group_count = $gtags_groups[total]; $groups_template->total_group_count = $gtags_groups[total]; $groups_template->pag_num = $gtags_groups[total]; $groups_template->pag_page = 1; $groups_template->pag_links = ''; $groups = $gtags_groups; } //echo '
'; print_r( $bp->current_action ); echo '
'; //echo '
'; print_r( $bp->action_variables[0] ); echo '
'; return $groups; } add_filter( 'bp_has_groups', 'gtags_show_groups_for_tag' ); // Return an array of the groups for a specific tag (plus number of groups) // this is a modified copy of many similar functions found in bp-groups-classes.php function gtags_get_groups_by_tag( $limit = null, $page = null, $user_id = false, $search_terms = false, $group_tag = null ) { global $wpdb, $bp; if ( $limit && $page ) { $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) ); } if ( !is_user_logged_in() || ( !is_site_admin() && ( $user_id != $bp->loggedin_user->id ) ) ) $hidden_sql = "AND g.status != 'hidden'"; if ( $search_terms ) { $search_terms = like_escape( $wpdb->escape( $search_terms ) ); $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )"; } if ( $group_tag ) { $group_tag = like_escape( $wpdb->escape( $group_tag ) ); $tag_sql = " AND ( gm3.meta_value LIKE '%%{$group_tag}%%' )"; } $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity, gm3.meta_value as gtags_group_tags FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND gm3.meta_key = 'gtags_group_tags' {$hidden_sql} {$search_sql} {$tag_sql} ORDER BY CONVERT(gm1.meta_value, SIGNED) DESC {$pag_sql}" ); // this is commented out because it doesn't really work due to the over-inclusive issue. //$total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_groupmeta} gm3, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND g.id = gm3.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND gm3.meta_key = 'gtags_group_tags' {$hidden_sql} {$search_sql} {$tag_sql}" ); // loop through results and return only exact matches in comma separated list. $paged_groups2 = array(); foreach ( (array)$paged_groups as $group ) { $items = explode( ",", $group->gtags_group_tags ); $match = false; foreach( $items as $item ) { if ( trim( strtolower( $item ) ) == strtolower( $group_tag ) ) $match = true; } if ( $match == true ) $paged_groups2[] = $group; } $total_groups = count($paged_groups2); // in place of the commented out code above //echo "
"; print_r($paged_groups2); echo "
"; foreach ( (array)$paged_groups2 as $group ) $group_ids[] = $group->id; $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) ); $paged_groups2 = BP_Groups_Group::get_group_extras( &$paged_groups2, $group_ids, 'popular' ); return array( 'groups' => $paged_groups2, 'total' => $total_groups ); } // Return an array with tag objects function gtags_make_tags( $urlencode=false ) { global $bp, $wpdb, $gtags_args; $all_group_tags = $wpdb->get_col( $wpdb->prepare( "SELECT meta_value FROM " . $bp->groups->table_name_groupmeta . " WHERE meta_key = 'gtags_group_tags' " ) ); //count the occurances $all_tags = array(); foreach( $all_group_tags as $group_tags ) { $items = explode( ",", $group_tags ); foreach( $items as $item ) { $item = trim( strtolower( $item ) ); if ($item=='') continue; if ( isset( $all_tags[ $item ] ) ) { $all_tags[ $item ] += 1; } else { $all_tags[ $item ] = 1; } } } $tags = array(); $i=0; foreach( $all_tags as $tag => $count ) { $tag = stripcslashes( $tag ); $link = $bp->root_domain . '/' . BP_GROUPS_SLUG . '/tag/' . urlencode( $tag ) ; $tags[$i] = (object)array( 'name' => $tag, 'count' => $count, 'link' => $link, 'id' => $i ); ++$i; } //echo "
"; print_r($tags); echo "
"; return $tags; } // show the tags above the group directory function gtags_display_tags() { global$gtags_show_cloud; if ( $gtags_show_cloud ){ global $gtags_args; echo '
'; echo wp_generate_tag_cloud( gtags_make_tags(), $gtags_args ); // use the built in wordrpess tag function :) echo '
'; } global $bp; } add_action( 'bp_before_directory_groups_content', 'gtags_display_tags' ); // create the form to add tags function gtags_add_tags_form() { global $show_group_add_form; if ($show_group_add_form) return; $show_group_add_form = true; ?>

:
count > $a->count);') ); foreach ( $tags as $tag ) { echo ' ' . $tag->name .''; //$sep = '  '; ++$i; if ( $i >= $popular_tag_limit ) break; } } // Save the tag values in the group meta - perhaps use serialize() and maybe_unserialize() function gtags_save_tags( $group_id ) { global $bp; if($bp->groups->new_group_id) $id = $bp->groups->new_group_id; else $id = $group_id; if ( $_POST['group-tags'] ) groups_update_groupmeta( $id, 'gtags_group_tags', $_POST['group-tags'] ); } add_action( 'groups_create_group_step_save_group-details', 'gtags_save_tags' ); add_action( 'groups_details_updated', 'gtags_save_tags' ); // Get or return the tag values function gtags_group_tags() { echo gtags_get_group_tags(); } function gtags_get_group_tags( $group = false ) { global $groups_template; if ( !$group ) $group =& $groups_template->group; $group_tags = groups_get_groupmeta( $group->id, 'gtags_group_tags' ); $group_tags = stripcslashes( $group_tags ); return apply_filters( 'gtags_get_group_tags', $group_tags ); } // show tags in group directory listing function gtags_show_tags_in_directory() { global $gtags_show_tags_in_directory; if ( gtags_get_group_tags() && $gtags_show_tags_in_directory ) { ?>
:
'. __('Tags', 'gtags').': '. gtags_make_tags_for_group().''; } return $description; } add_filter( 'bp_get_group_description', 'gtags_show_tags_in_header' ); // show tags for an individual group with links function gtags_make_tags_for_group() { global $bp, $wpdb, $gtags_args; $group_tags = gtags_get_group_tags(); $items = explode( ",", $group_tags ); foreach( $items as $item ) { $item = trim( strtolower( $item ) ); if ($item=='') continue; $link = $bp->root_domain . '/' . BP_GROUPS_SLUG . '/tag/' . urlencode( $item ); $output .= ' '.$item.' '; } return $output; } // add a happy group tag widget function gtags_group_tags_widget() { global $gtags_args; ?>

gtags->id = 'gtags'; $bp->gtags->slug = 'tag'; } add_action( 'bp_setup_globals', 'bp_gtags_setup_globals' ); // this gets called as a hook, but never shows on the page due to low precedence level - strange but works // it does however show up on /members/admin/groups/ so I hacked it so the name of the sub nav item does not show. function bp_gtags_setup_nav() { global $bp; bp_core_new_subnav_item( array( 'name' => 'Tags', 'slug' => $bp->gtags->slug, 'parent_slug' => BP_GROUPS_SLUG, 'parent_url' => $bp->root_domain .'/'. BP_GROUPS_SLUG . '/', 'screen_function' => 'gtags_display_hook', 'position' => 1 ) ); } add_action( 'bp_setup_nav', 'bp_gtags_setup_nav', 1 ); function gtags_display_hook() { global $bp; add_action( 'bp_has_groups', 'gtags_show_groups_for_tag' ); bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'groups/index' ) ); } function mybp(){ global $bp; //echo '
'; print_r( $bp ); echo '
'; } //add_action('bp_before_footer','mybp'); ?>