Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/06/2010 04:24:57 PM (14 years ago)
Author:
apeatling
Message:

Merging 1.2 branch with trunk

File:
1 edited

Legend:

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

    r2989 r3232  
    634634        groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );
    635635
    636         $group_count = get_usermeta( $this->user_id, 'total_group_count' );
     636        $group_count = get_user_meta( $this->user_id, 'total_group_count', true );
    637637        if ( !empty( $group_count ) )
    638             update_usermeta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
     638            update_user_meta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
    639639
    640640        return $this->save();
     
    648648
    649649        groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) + 1 ) );
    650         update_usermeta( $this->user_id, 'total_group_count', (int)get_usermeta( $this->user_id, 'total_group_count' ) + 1 );
     650        update_user_meta( $this->user_id, 'total_group_count', (int)get_user_meta( $this->user_id, 'total_group_count', true ) + 1 );
    651651
    652652        return $this->save();
     
    656656        $this->inviter_id = 0;
    657657        $this->is_confirmed = 1;
    658         $this->date_modified = gmdate( "Y-m-d H:i:s" );
     658        $this->date_modified = bp_core_current_time();
    659659    }
    660660
    661661    function accept_request() {
    662662        $this->is_confirmed = 1;
    663         $this->date_modified = gmdate( "Y-m-d H:i:s" );
     663        $this->date_modified = bp_core_current_time();
     664    }
     665
     666    function remove( $user_id, $group_id ) {
     667        global $wpdb, $bp;
     668
     669        $sql = $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id );
     670
     671        if ( !$result = $wpdb->query( $sql ) )
     672            return false;
     673
     674        groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );
     675
     676        $group_count = get_user_meta( $this->user_id, 'total_group_count', true );
     677        if ( !empty( $group_count ) )
     678            update_user_meta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
     679
     680        return $result;
    664681    }
    665682
     
    758775            $user_id = $bp->displayed_user->id;
    759776
    760         if ( $user_id != $bp->loggedin_user->id && !is_site_admin() ) {
     777        if ( $user_id != $bp->loggedin_user->id && !is_super_admin() ) {
    761778            return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    762779        } else {
     
    795812    }
    796813
     814    function delete_request( $user_id, $group_id ) {
     815        global $wpdb, $bp;
     816
     817        if ( !$user_id )
     818            return false;
     819
     820        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d AND is_confirmed = 0 AND inviter_id = 0 AND invite_sent = 0", $user_id, $group_id ) );
     821    }
     822
    797823    function check_is_admin( $user_id, $group_id ) {
    798824        global $wpdb, $bp;
     
    829855
    830856        return $wpdb->get_var( $wpdb->prepare( "SELECT is_banned FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $user_id, $group_id ) );
     857    }
     858
     859    /**
     860     * Is the specified user the creator of the group?
     861     *
     862     * @global object $bp BuddyPress global settings
     863     * @global wpdb $wpdb WordPress database object
     864     * @param int $user_id
     865     * @param int $group_id
     866     * @since 1.2.6
     867     */
     868    function check_is_creator( $user_id, $group_id ) {
     869        global $bp, $wpdb;
     870
     871        if ( !$user_id )
     872            return false;
     873
     874        return $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->groups->table_name} WHERE creator_id = %d AND id = %d", $user_id, $group_id ) );
    831875    }
    832876
     
    888932
    889933        if ( bp_is_active( 'xprofile' ) )
    890             $members = $wpdb->get_results( apply_filters( 'bp_group_members_user_join_filter', $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, pd.value as display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u, {$bp->profile->table_name_data} pd WHERE u.ID = m.user_id AND u.ID = pd.user_id AND pd.field_id = 1 AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) ) );
     934            $members = $wpdb->get_results( $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, pd.value as display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u, {$bp->profile->table_name_data} pd WHERE u.ID = m.user_id AND u.ID = pd.user_id AND pd.field_id = 1 AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) );
    891935        else
    892             $members = $wpdb->get_results( apply_filters( 'bp_group_members_user_join_filter', $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u WHERE u.ID = m.user_id AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) ) );
     936            $members = $wpdb->get_results( $wpdb->prepare( "SELECT m.user_id, m.date_modified, m.is_banned, u.user_login, u.user_nicename, u.user_email, u.display_name FROM {$bp->groups->table_name_members} m, {$wpdb->users} u WHERE u.ID = m.user_id AND group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql} ORDER BY m.date_modified DESC {$pag_sql}", $group_id ) );
    893937
    894938        if ( !$members )
     
    898942            $total_member_count = count($members);
    899943        else
    900             $total_member_count = $wpdb->get_var( apply_filters( 'bp_group_members_count_user_join_filter', $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql}", $group_id ) ) );
     944            $total_member_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(user_id) FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 {$banned_sql} {$exclude_sql}", $group_id ) );
    901945
    902946        /* Fetch whether or not the user is a friend */
     
    904948        $user_ids = $wpdb->escape( join( ',', (array)$user_ids ) );
    905949
    906         if ( bp_is_active( 'friends' ) ) {
     950        if ( function_exists( 'friends_install' ) ) {
    907951            $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 ) );
    908952            for ( $i = 0; $i < count( $members ); $i++ ) {
     
    923967    }
    924968
     969    /**
     970     * Delete all group membership information for the specified user
     971     *
     972     * @global object $bp BuddyPress global settings
     973     * @global wpdb $wpdb WordPress database object
     974     * @param int $user_id
     975     * @since 1.0
     976     * @uses BP_Groups_Member
     977     */
    925978    function delete_all_for_user( $user_id ) {
    926         global $wpdb, $bp;
     979        global $bp, $wpdb;
     980
     981        // Get all the group ids for the current user's groups and update counts
     982        $group_ids = BP_Groups_Member::get_group_ids( $user_id );
     983        foreach ( $group_ids['groups'] as $group_id ) {
     984            groups_update_groupmeta( $group_id, 'total_member_count', groups_get_total_member_count( $group_id ) - 1 );
     985
     986            // If current user is the creator of a group and is the sole admin, delete that group to avoid counts going out-of-sync
     987            if ( groups_is_user_admin( $user_id, $group_id ) && count( groups_get_group_admins( $group_id ) ) < 2 && groups_is_user_creator( $user_id, $group_id ) )
     988                groups_delete_group( $group_id );
     989        }
    927990
    928991        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d", $user_id ) );
     
    9941057        global $bp;
    9951058
    996         /* When we are viewing a single group, add the group extension nav item */
    997         if ( $this->visbility == 'public' || ( $this->visbility != 'public' && $bp->groups->current_group->user_has_access ) ) {
    998             if ( $this->enable_nav_item ) {
    999                 if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item )
    1000                     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 ) );
    1001 
    1002                 /* When we are viewing the extension display page, set the title and options title */
    1003                 if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && $bp->current_action == $this->slug ) {
    1004                     add_action( 'bp_template_content_header', create_function( '', 'echo "' . attribute_escape( $this->name ) . '";' ) );
    1005                     add_action( 'bp_template_title', create_function( '', 'echo "' . attribute_escape( $this->name ) . '";' ) );
    1006                 }
    1007             }
    1008 
    1009             /* Hook the group home widget */
    1010             if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
    1011                 add_action( $this->display_hook, array( &$this, 'widget_display' ) );
    1012         }
    1013 
    10141059        if ( $this->enable_create_step ) {
    1015             /* Insert the group creation step for the new group extension */
     1060            // Insert the group creation step for the new group extension
    10161061            $bp->groups->group_creation_steps[$this->slug] = array( 'name' => $this->name, 'slug' => $this->slug, 'position' => $this->create_step_position );
    10171062
    1018             /* Attach the group creation step display content action */
     1063            // Attach the group creation step display content action
    10191064            add_action( 'groups_custom_create_steps', array( &$this, 'create_screen' ) );
    10201065
    1021             /* Attach the group creation step save content action */
     1066            // Attach the group creation step save content action
    10221067            add_action( 'groups_create_group_step_save_' . $this->slug, array( &$this, 'create_screen_save' ) );
    10231068        }
    10241069
    1025         /* Construct the admin edit tab for the new group extension */
     1070        // Construct the admin edit tab for the new group extension
    10261071        if ( $this->enable_edit_item ) {
    1027             add_action( 'groups_admin_tabs', create_function( '$current, $group_slug', 'if ( "' . attribute_escape( $this->slug ) . '" == $current ) $selected = " class=\"current\""; echo "<li{$selected}><a href=\"' . $bp->root_domain . '/' . $bp->groups->slug . '/{$group_slug}/admin/' . attribute_escape( $this->slug ) . '\">' . attribute_escape( $this->name ) . '</a></li>";' ), 10, 2 );
    1028 
    1029             /* Catch the edit screen and forward it to the plugin template */
     1072            add_action( 'groups_admin_tabs', create_function( '$current, $group_slug', 'if ( "' . esc_attr( $this->slug ) . '" == $current ) $selected = " class=\"current\""; echo "<li{$selected}><a href=\"' . $bp->root_domain . '/' . $bp->groups->slug . '/{$group_slug}/admin/' . esc_attr( $this->slug ) . '\">' . esc_attr( $this->name ) . '</a></li>";' ), 10, 2 );
     1073
     1074            // Make sure user has access
     1075            if ( !$bp->is_item_admin )
     1076                return false;
     1077
     1078            // Catch the edit screen and forward it to the plugin template
    10301079            if ( $bp->current_component == $bp->groups->slug && 'admin' == $bp->current_action && $this->slug == $bp->action_variables[0] ) {
    1031                 $this->edit_screen_save();
     1080                add_action( 'wp', array( &$this, 'edit_screen_save' ) );
    10321081                add_action( 'groups_custom_edit_steps', array( &$this, 'edit_screen' ) );
    10331082
     
    10411090            }
    10421091        }
     1092
     1093        // When we are viewing a single group, add the group extension nav item
     1094        if ( $this->visibility == 'public' || ( $this->visibility != 'public' && $bp->groups->current_group->user_has_access ) ) {
     1095            if ( $this->enable_nav_item ) {
     1096                if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item )
     1097                    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 ) );
     1098
     1099                // When we are viewing the extension display page, set the title and options title
     1100                if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && $bp->current_action == $this->slug ) {
     1101                    add_action( 'bp_template_content_header', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) );
     1102                    add_action( 'bp_template_title', create_function( '', 'echo "' . esc_attr( $this->name ) . '";' ) );
     1103                }
     1104            }
     1105
     1106            // Hook the group home widget
     1107            if ( $bp->current_component == $bp->groups->slug && $bp->is_single_item && ( !$bp->current_action || 'home' == $bp->current_action ) )
     1108                add_action( $this->display_hook, array( &$this, 'widget_display' ) );
     1109        }
    10431110    }
    10441111
     
    10551122        return false;
    10561123
    1057     /* Register the group extension on the plugins_loaded action so we have access to all plugins */
    1058     add_action( 'init', create_function( '', '$extension = new ' . $group_extension_class . '; add_action( "pre_get_posts", array( &$extension, "_register" ) );' ) );
     1124    /* Register the group extension on the bp_init action so we have access to all plugins */
     1125    add_action( 'bp_init', create_function( '', '$extension = new ' . $group_extension_class . '; add_action( "wp", array( &$extension, "_register" ), 2 );' ), 11 );
    10591126}
    10601127
Note: See TracChangeset for help on using the changeset viewer.