Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
04/13/2010 04:01:07 PM (14 years ago)
Author:
apeatling
Message:

Replacing function_exists() checks with bp_is_active() checks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r2770 r2919  
    256256    }
    257257
    258     /* TODO: Merge all these get_() functions into one. */
    259 
    260     function get_newest( $limit = null, $page = null, $user_id = false, $search_terms = false, $populate_extras = true ) {
    261         global $wpdb, $bp;
    262 
    263         if ( $limit && $page )
    264             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     258    function get( $type = 'newest', $per_page = null, $page = null, $user_id = false, $search_terms = false, $include = false, $populate_extras = true ) {
     259        global $wpdb, $bp;
     260
     261        $sql = array();
     262
     263        $sql['select'] = "SELECT g.*, gm1.meta_value AS total_member_count, gm2.meta_value AS last_activity";
     264        $sql['from']   = " FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2,";
     265
     266        if ( !empty( $user_id ) )
     267            $sql['members_from'] = " {$bp->groups->table_name_members} m,";
     268
     269        $sql['group_from'] = " {$bp->groups->table_name} g WHERE";
     270
     271        if ( !empty( $user_id ) )
     272            $sql['user_where'] = " g.id = m.group_id AND";
     273
     274        $sql['where'] = " g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count'";
    265275
    266276        if ( !is_user_logged_in() || ( !is_site_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
    267             $hidden_sql = "AND g.status != 'hidden'";
     277            $sql['hidden'] = " AND g.status != 'hidden'";
    268278
    269279        if ( $search_terms ) {
    270280            $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    271             $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
    272         }
    273 
    274         if ( $user_id ) {
    275             $user_id = $wpdb->escape( $user_id );
    276             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY g.date_created DESC {$pag_sql}" );
    277             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0" );
    278         } else {
    279             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} ORDER BY g.date_created DESC {$pag_sql}" );
    280             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm INNER JOIN {$bp->groups->table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}" );
    281         }
    282 
     281            $sql['search'] = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
     282        }
     283
     284        if ( !empty( $user_id ) )
     285            $sql['user'] = $wpdb->prepare( " AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id );
     286
     287        if ( !empty( $include ) ) {
     288            $include = $wpdb->escape( $include );
     289            $sql['include'] = " AND g.id IN ({$include})";
     290        }
     291
     292        switch ( $type ) {
     293            case 'newest': default:
     294                $sql['order'] = " ORDER BY g.date_created DESC";
     295                break;
     296            case 'active':
     297                $sql[] = "ORDER BY last_activity DESC";
     298                break;
     299            case 'popular':
     300                $sql[] = "ORDER BY CONVERT(gm1.meta_value, SIGNED) DESC";
     301                break;
     302            case 'alphabetical':
     303                $sql[] = "ORDER BY g.name ASC";
     304                break;
     305            case 'random':
     306                $sql[] = "ORDER BY rand()";
     307                break;
     308        }
     309
     310        if ( $per_page && $page )
     311            $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page), intval( $per_page ) );
     312
     313        /* Get paginated results */
     314        $paged_groups = $wpdb->get_results( join( ' ', (array)$sql ) );
     315
     316        $total_sql['select'] = "SELECT COUNT(g.id) FROM {$bp->groups->table_name} g";
     317
     318        if ( !empty( $user_id ) )
     319            $total_sql['select'] .= ", {$bp->groups->table_name_members} m";
     320
     321        if ( !empty( $sql['hidden'] ) )
     322            $total_sql['where'][] = "g.status != 'hidden'";
     323
     324        if ( !empty( $sql['search'] ) )
     325            $total_sql['where'][] = "( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
     326
     327        if ( !empty( $user_id ) )
     328            $total_sql['where'][] = "m.group_id = g.id AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0";
     329
     330        $t_sql = $total_sql['select'];
     331
     332        if ( !empty( $total_sql['where'] ) )
     333            $t_sql .= " WHERE " . join( ' AND ', (array)$total_sql['where'] );
     334
     335        /* Get total group results */
     336        $total_groups = $wpdb->get_var( join( ' ', (array)$t_sql ) );
     337
     338        /* Populate some extra information instead of querying each time in the loop */
    283339        if ( !empty( $populate_extras ) ) {
    284340            foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    285341            $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    286             $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
    287         }
    288 
    289         return array( 'groups' => $paged_groups, 'total' => $total_groups );
    290     }
    291 
    292     function get_active( $limit = null, $page = null, $user_id = false, $search_terms = false, $populate_extras = true ) {
    293         global $wpdb, $bp;
    294 
    295         if ( $limit && $page )
    296             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    297 
    298         if ( !is_user_logged_in() || ( !is_site_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
    299             $hidden_sql = "AND g.status != 'hidden'";
    300 
    301         if ( $search_terms ) {
    302             $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    303             $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
    304         }
    305 
    306         if ( $user_id ) {
    307             $user_id = $wpdb->escape( $user_id );
    308             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY last_activity DESC {$pag_sql}" );
    309             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0" );
    310         } else {
    311             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} ORDER BY last_activity DESC {$pag_sql}" );
    312             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm INNER JOIN {$bp->groups->table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}" );
    313         }
    314 
    315         if ( !empty( $populate_extras ) ) {
    316             foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    317             $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    318             $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
    319         }
    320 
    321         return array( 'groups' => $paged_groups, 'total' => $total_groups );
    322     }
    323 
    324     function get_popular( $limit = null, $page = null, $user_id = false, $search_terms = false, $populate_extras = true ) {
    325         global $wpdb, $bp;
    326 
    327         if ( $limit && $page ) {
    328             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    329         }
    330 
    331         if ( !is_user_logged_in() || ( !is_site_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
    332             $hidden_sql = "AND g.status != 'hidden'";
    333 
    334         if ( $search_terms ) {
    335             $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    336             $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
    337         }
    338 
    339         if ( $user_id ) {
    340             $user_id = $wpdb->escape( $user_id );
    341             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY CONVERT(gm1.meta_value, SIGNED) DESC {$pag_sql}" );
    342             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0" );
    343         } else {
    344             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} ORDER BY CONVERT(gm1.meta_value, SIGNED) DESC {$pag_sql}" );
    345             $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} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql}" );
    346         }
    347 
    348         if ( !empty( $populate_extras ) ) {
    349             foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    350             $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    351             $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
    352         }
    353 
    354         return array( 'groups' => $paged_groups, 'total' => $total_groups );
    355     }
    356 
    357     function get_alphabetically( $limit = null, $page = null, $user_id = false, $search_terms = false, $populate_extras = true ) {
    358         global $wpdb, $bp;
    359 
    360         if ( $limit && $page )
    361             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    362 
    363         if ( !is_user_logged_in() || ( !is_site_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
    364             $hidden_sql = " AND g.status != 'hidden'";
    365 
    366         if ( $search_terms ) {
    367             $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    368             $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
    369         }
    370 
    371         if ( $user_id ) {
    372             $user_id = $wpdb->escape( $user_id );
    373             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY g.name ASC {$pag_sql}" );
    374             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0" );
    375         } else {
    376             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} ORDER BY g.name ASC {$pag_sql}" );
    377             $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} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql}" );
    378         }
    379 
    380         if ( !empty( $populate_extras ) ) {
    381             foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    382             $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    383             $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
    384         }
     342            $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, $type );
     343        }
     344
     345        unset( $sql, $total_sql );
    385346
    386347        return array( 'groups' => $paged_groups, 'total' => $total_groups );
     
    459420    }
    460421
    461     function get_all( $limit = null, $page = null, $only_public = true, $sort_by = false, $order = false ) {
    462         global $wpdb, $bp;
    463 
    464         // Default sql WHERE conditions are blank. TODO: generic handler function.
    465         $where_sql = null;
    466         $where_conditions = array();
    467 
    468         // Limit results to public status
    469         if ( $only_public )
    470             $where_conditions[] = $wpdb->prepare( "g.status = 'public'" );
    471 
    472         if ( !is_site_admin() )
    473             $where_conditions[] = $wpdb->prepare( "g.status != 'hidden'");
    474 
    475         // Build where sql statement if necessary
    476         if ( !empty( $where_conditions ) )
    477             $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
    478 
    479         if ( $limit && $page )
    480             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    481 
    482         if ( $sort_by && $order ) {
    483             $sort_by = $wpdb->escape( $sort_by );
    484             $order = $wpdb->escape( $order );
    485             $order_sql = "ORDER BY g.$sort_by $order";
    486 
    487             switch ( $sort_by ) {
    488                 default:
    489                     $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g {$where_sql} {$order_sql} {$pag_sql}" );
    490                     break;
    491                 case 'members':
    492                     $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g, {$bp->groups->table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'total_member_count' {$hidden_sql} {$public_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}" );
    493                     break;
    494                 case 'last_active':
    495                     $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g, {$bp->groups->table_name_groupmeta} gm WHERE g.id = gm.group_id AND gm.meta_key = 'last_activity' {$hidden_sql} {$public_sql} ORDER BY CONVERT(gm.meta_value, SIGNED) {$order} {$pag_sql}" );
    496                     break;
    497             }
    498         } else {
    499             $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name} g {$where_sql} {$order_sql} {$pag_sql}" );
    500         }
    501 
    502         return $wpdb->get_results($sql);
    503     }
    504 
    505422    function get_by_letter( $letter, $limit = null, $page = null, $populate_extras = true ) {
    506423        global $wpdb, $bp;
     
    520437
    521438        $paged_groups = $wpdb->get_results( $wpdb->prepare( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' AND g.name LIKE '$letter%%' {$hidden_sql} {$search_sql} ORDER BY g.name ASC {$pag_sql}"  ) );
    522 
    523         if ( !empty( $populate_extras ) ) {
    524             foreach ( (array)$paged_groups as $group ) $group_ids[] = $group->id;
    525             $group_ids = $wpdb->escape( join( ',', (array)$group_ids ) );
    526             $paged_groups = BP_Groups_Group::get_group_extras( &$paged_groups, $group_ids, 'newest' );
    527         }
    528 
    529         return array( 'groups' => $paged_groups, 'total' => $total_groups );
    530     }
    531 
    532     function get_random( $limit = null, $page = null, $user_id = false, $search_terms = false, $populate_extras = true ) {
    533         global $wpdb, $bp;
    534 
    535         if ( $limit && $page )
    536             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    537 
    538         if ( !is_user_logged_in() || ( !is_site_admin() && ( $user_id != $bp->loggedin_user->id ) ) )
    539             $hidden_sql = "AND g.status != 'hidden'";
    540 
    541         if ( $search_terms ) {
    542             $search_terms = like_escape( $wpdb->escape( $search_terms ) );
    543             $search_sql = " AND ( g.name LIKE '%%{$search_terms}%%' OR g.description LIKE '%%{$search_terms}%%' )";
    544         }
    545 
    546         if ( $user_id ) {
    547             $user_id = $wpdb->escape( $user_id );
    548             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.id = m.group_id AND g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() {$pag_sql}" );
    549             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m LEFT JOIN {$bp->groups->table_name_groupmeta} gm ON m.group_id = gm.group_id INNER JOIN {$bp->groups->table_name} g ON m.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql} AND m.user_id = {$user_id} AND m.is_confirmed = 1 AND m.is_banned = 0" );
    550         } else {
    551             $paged_groups = $wpdb->get_results( "SELECT g.*, gm1.meta_value as total_member_count, gm2.meta_value as last_activity FROM {$bp->groups->table_name_groupmeta} gm1, {$bp->groups->table_name_groupmeta} gm2, {$bp->groups->table_name} g WHERE g.id = gm1.group_id AND g.id = gm2.group_id AND gm2.meta_key = 'last_activity' AND gm1.meta_key = 'total_member_count' {$hidden_sql} {$search_sql} ORDER BY rand() {$pag_sql}" );
    552             $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT g.id) FROM {$bp->groups->table_name_groupmeta} gm INNER JOIN {$bp->groups->table_name} g ON gm.group_id = g.id WHERE gm.meta_key = 'last_activity'{$hidden_sql} {$search_sql}" );
    553         }
    554439
    555440        if ( !empty( $populate_extras ) ) {
     
    1013898        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
    1014899
    1015         if ( function_exists( 'friends_install' ) ) {
     900        if ( bp_is_active( 'friends' ) ) {
    1016901            $friend_status = $wpdb->get_results( $wpdb->prepare( "SELECT initiator_user_id, friend_user_id, is_confirmed FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d AND friend_user_id IN ( {$user_ids} ) ) OR (initiator_user_id IN ( {$user_ids} ) AND friend_user_id = %d )", $bp->loggedin_user->id, $bp->loggedin_user->id ) );
    1017902            for ( $i = 0; $i < count( $members ); $i++ ) {
     
    1103988        global $bp;
    1104989
     990        /* When we are viewing a single group, add the group extension nav item */
     991        if ( $this->visbility == 'public' || ( $this->visbility != 'public' && $bp->groups->current_group->user_has_access ) ) {
     992            if ( $this->enable_nav_item ) {
     993                if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item )
     994                    bp_core_new_subnav_item( array( 'name' => ( !$this->nav_item_name ) ? $this->name : $this->nav_item_name, 'slug' => $this->slug, 'parent_slug' => BP_GROUPS_SLUG, 'parent_url' => bp_get_group_permalink( $bp->groups->current_group ), 'position' => $this->nav_item_position, 'item_css_id' => 'nav-' . $this->slug, 'screen_function' => array( &$this, '_display_hook' ), 'user_has_access' => $this->enable_nav_item ) );
     995
     996                /* When we are viewing the extension display page, set the title and options title */
     997                if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && $bp->current_action == $this->slug ) {
     998                    add_action( 'bp_template_content_header', create_function( '', 'echo "' . attribute_escape( $this->name ) . '";' ) );
     999                    add_action( 'bp_template_title', create_function( '', 'echo "' . attribute_escape( $this->name ) . '";' ) );
     1000                }
     1001            }
     1002
     1003            /* Hook the group home widget */
     1004            if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
     1005                add_action( $this->display_hook, array( &$this, 'widget_display' ) );
     1006        }
     1007
    11051008        if ( $this->enable_create_step ) {
    11061009            /* Insert the group creation step for the new group extension */
     
    11201023            /* Catch the edit screen and forward it to the plugin template */
    11211024            if ( $bp->current_component == $bp->groups->slug && 'admin' == $bp->current_action && $this->slug == $bp->action_variables[0] ) {
    1122                 add_action( 'wp', array( &$this, 'edit_screen_save' ) );
     1025                $this->edit_screen_save();
    11231026                add_action( 'groups_custom_edit_steps', array( &$this, 'edit_screen' ) );
    11241027
     
    11321035            }
    11331036        }
    1134 
    1135         /* When we are viewing a single group, add the group extension nav item */
    1136         if ( $this->visbility == 'public' || ( $this->visbility != 'public' && $bp->groups->current_group->user_has_access ) ) {
    1137             if ( $this->enable_nav_item ) {
    1138                 if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item )
    1139                     bp_core_new_subnav_item( array( 'name' => ( !$this->nav_item_name ) ? $this->name : $this->nav_item_name, 'slug' => $this->slug, 'parent_slug' => BP_GROUPS_SLUG, 'parent_url' => bp_get_group_permalink( $bp->groups->current_group ), 'position' => $this->nav_item_position, 'item_css_id' => 'nav-' . $this->slug, 'screen_function' => array( &$this, '_display_hook' ), 'user_has_access' => $this->enable_nav_item ) );
    1140 
    1141                 /* When we are viewing the extension display page, set the title and options title */
    1142                 if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && $bp->current_action == $this->slug ) {
    1143                     add_action( 'bp_template_content_header', create_function( '', 'echo "' . attribute_escape( $this->name ) . '";' ) );
    1144                     add_action( 'bp_template_title', create_function( '', 'echo "' . attribute_escape( $this->name ) . '";' ) );
    1145                 }
    1146             }
    1147 
    1148             /* Hook the group home widget */
    1149             if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
    1150                 add_action( $this->display_hook, array( &$this, 'widget_display' ) );
    1151         }
    11521037    }
    11531038
     
    11651050
    11661051    /* Register the group extension on the plugins_loaded action so we have access to all plugins */
    1167     add_action( 'bp_init', create_function( '', '$extension = new ' . $group_extension_class . '; add_action( "wp", array( &$extension, "_register" ), 2 );' ), 11 );
     1052    add_action( 'init', create_function( '', '$extension = new ' . $group_extension_class . '; add_action( "pre_get_posts", array( &$extension, "_register" ) );' ) );
    11681053}
    11691054
Note: See TracChangeset for help on using the changeset viewer.