Skip to:
Content

BuddyPress.org

Changeset 10323


Ignore:
Timestamp:
11/02/2015 02:07:44 AM (9 years ago)
Author:
tw2113
Message:

More docs cleanup for Friends component.

See #6400.

Location:
trunk/src/bp-friends
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/bp-friends-activity.php

    r10147 r10323  
    9191    $bp = buddypress();
    9292
    93     // These two added in BP 1.6
     93    // These two added in BP 1.6.
    9494    bp_activity_set_action(
    9595        $bp->friends->id,
     
    110110    );
    111111
    112     // < BP 1.6 backpat
     112    // < BP 1.6 backpat.
    113113    bp_activity_set_action( $bp->friends->id, 'friends_register_activity_action', __( 'New friendship created', 'buddypress' ) );
    114114
     
    129129 * @param string $action   Activity action string.
    130130 * @param object $activity Activity data.
    131  *
    132131 * @return string $action Formatted activity action.
    133132 */
     
    140139    // Backward compatibility for legacy filter
    141140    // The old filter has the $friendship object passed to it. We want to
    142     // avoid having to build this object if it's not necessary
     141    // avoid having to build this object if it's not necessary.
    143142    if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) {
    144143        $friendship = new BP_Friends_Friendship( $activity->item_id );
     
    164163 * @param string $action   Static activity action.
    165164 * @param object $activity Activity data.
    166  *
    167165 * @return string $action Formatted activity action.
    168166 */
     
    175173    // Backward compatibility for legacy filter
    176174    // The old filter has the $friendship object passed to it. We want to
    177     // avoid having to build this object if it's not necessary
     175    // avoid having to build this object if it's not necessary.
    178176    if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) {
    179177        $friendship = new BP_Friends_Friendship( $activity->item_id );
     
    200198 *
    201199 * @param array $activities Array of activity items.
    202  *
    203200 * @return array
    204201 */
     
    219216
    220217    if ( ! empty( $friend_ids ) ) {
    221         // Fire a user query to prime user caches
     218        // Fire a user query to prime user caches.
    222219        new BP_User_Query( array(
    223220            'user_ids'          => $friend_ids,
     
    238235 * @since 2.2.0
    239236 *
    240  * @param array $retval Empty array by default
    241  * @param array $filter Current activity arguments
    242  *
     237 * @param array $retval Empty array by default.
     238 * @param array $filter Current activity arguments.
    243239 * @return array
    244240 */
    245241function bp_friends_filter_activity_scope( $retval = array(), $filter = array() ) {
    246242
    247     // Determine the user_id
     243    // Determine the user_id.
    248244    if ( ! empty( $filter['user_id'] ) ) {
    249245        $user_id = $filter['user_id'];
     
    254250    }
    255251
    256     // Determine friends of user
     252    // Determine friends of user.
    257253    $friends = friends_get_friend_user_ids( $user_id );
    258254    if ( empty( $friends ) ) {
     
    268264        ),
    269265
    270         // we should only be able to view sitewide activity content for friends
     266        // We should only be able to view sitewide activity content for friends.
    271267        array(
    272268            'column' => 'hide_sitewide',
     
    274270        ),
    275271
    276         // overrides
     272        // Overrides.
    277273        'override' => array(
    278274            'filter'      => array( 'user_id' => 0 ),
     
    292288 * @since 2.2.0
    293289 *
    294  * @param array $retval Empty array by default
    295  * @param array $filter Current activity arguments
     290 * @param array $retval Empty array by default.
     291 * @param array $filter Current activity arguments.
    296292 *
    297293 * @return array
     
    299295function bp_friends_filter_activity_just_me_scope( $retval = array(), $filter = array() ) {
    300296
    301     // Determine the user_id
     297    // Determine the user_id.
    302298    if ( ! empty( $filter['user_id'] ) ) {
    303299        $user_id = $filter['user_id'];
     
    308304    }
    309305
    310     // Get the requested action
     306    // Get the requested action.
    311307    $action = $filter['filter']['action'];
    312308
    313     // Make sure actions are listed in an array
     309    // Make sure actions are listed in an array.
    314310    if ( ! is_array( $action ) ) {
    315311        $action = explode( ',', $filter['filter']['action'] );
     
    326322    }
    327323
    328     // Juggle existing override value
     324    // Juggle existing override value.
    329325    $override = array();
    330326    if ( ! empty( $retval['override'] ) ) {
     
    354350    );
    355351
    356     // Juggle back override value
     352    // Juggle back override value.
    357353    if ( ! empty( $override ) ) {
    358354        $retval['override'] = $override;
     
    369365 * @since 1.9.0
    370366 *
    371  * @param int         $friendship_id
    372  * @param int         $initiator_user_id
    373  * @param int         $friend_user_id
    374  * @param object|bool $friendship Optional
     367 * @param int         $friendship_id       ID of the friendship.
     368 * @param int         $initiator_user_id   ID of friendship initiator.
     369 * @param int         $friend_user_id      ID of user whose friendship is requested.
     370 * @param object|bool $friendship Optional Friendship object.
    375371 */
    376372function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_user_id, $friend_user_id, $friendship = false ) {
     
    379375    }
    380376
    381     // Record in activity streams for the initiator
     377    // Record in activity streams for the initiator.
    382378    friends_record_activity( array(
    383379        'user_id'           => $initiator_user_id,
  • trunk/src/bp-friends/bp-friends-cache.php

    r10147 r10323  
    1818 * @param int $friendship_id ID of the friendship whose two members should
    1919 *                           have their friends cache busted.
    20  *
    2120 * @return bool
    2221 */
     
    2928}
    3029
    31 // List actions to clear object caches on
     30// List actions to clear object caches on.
    3231add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' );
    3332add_action( 'friends_friendship_deleted',  'friends_clear_friend_object_cache' );
     
    6968 *
    7069 * @param int                   $friendship_id The friendship ID.
    71  * @param BP_Friends_Friendship $friendship
     70 * @param BP_Friends_Friendship $friendship Friendship object.
    7271 */
    7372function bp_friends_clear_request_cache_on_remove( $friendship_id, BP_Friends_Friendship $friendship ) {
     
    7776add_action( 'friends_friendship_rejected',  'bp_friends_clear_request_cache_on_remove', 10, 2 );
    7877
    79 // List actions to clear super cached pages on, if super cache is installed
     78// List actions to clear super cached pages on, if super cache is installed.
    8079add_action( 'friends_friendship_rejected',  'bp_core_clear_cache' );
    8180add_action( 'friends_friendship_accepted',  'bp_core_clear_cache' );
  • trunk/src/bp-friends/bp-friends-filters.php

    r10147 r10323  
    2727    global $wpdb;
    2828
    29     // stop if user isn't logged in
     29    // Stop if user isn't logged in.
    3030    if ( ! is_user_logged_in() ) {
    3131        return;
     
    3434    $bp = buddypress();
    3535
    36     // Fetch whether or not the user is a friend of the current user
     36    // Fetch whether or not the user is a friend of the current user.
    3737    $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_sql} ) ) OR (initiator_user_id IN ( {$user_ids_sql} ) AND friend_user_id = %d )", bp_loggedin_user_id(), bp_loggedin_user_id() ) );
    3838
    39     // Keep track of members that have a friendship status with the current user
     39    // Keep track of members that have a friendship status with the current user.
    4040    $friend_user_ids = array();
    4141
    42     // The "friend" is the user ID in the pair who is *not* the logged in user
     42    // The "friend" is the user ID in the pair who is *not* the logged in user.
    4343    foreach ( (array) $friend_status as $fs ) {
    4444        $friend_id = bp_loggedin_user_id() == $fs->initiator_user_id ? $fs->friend_user_id : $fs->initiator_user_id;
     
    5757    }
    5858
    59     // The rest are not friends with the current user, so set status accordingly
     59    // The rest are not friends with the current user, so set status accordingly.
    6060    $not_friends = array_diff( $user_query->user_ids, $friend_user_ids );
    6161    foreach ( (array) $not_friends as $nf ) {
  • trunk/src/bp-friends/bp-friends-functions.php

    r10147 r10323  
    2626 *                               When true, running friends_add_friend() will result in an accepted
    2727 *                               friendship, with no notifications being sent. Default: false.
    28  *
    2928 * @return bool True on success, false on failure.
    3029 */
     
    3635    }
    3736
    38     // Check if already friends, and bail if so
     37    // Check if already friends, and bail if so.
    3938    if ( friends_check_friendship( $initiator_userid, $friend_userid ) ) {
    4039        return true;
    4140    }
    4241
    43     // Setup the friendship data
     42    // Setup the friendship data.
    4443    $friendship = new BP_Friends_Friendship;
    4544    $friendship->initiator_user_id = $initiator_userid;
     
    5352    }
    5453
    55     // Bail if friendship could not be saved (how sad!)
     54    // Bail if friendship could not be saved (how sad!).
    5655    if ( ! $friendship->save() ) {
    5756        return false;
    5857    }
    5958
    60     // Send notifications
     59    // Send notifications.
    6160    if ( empty( $force_accept ) ) {
    6261        $action = 'requested';
    6362
    64     // Update friend totals
     63    // Update friend totals.
    6564    } else {
    6665        $action = 'accepted';
     
    9392 * @param int $initiator_userid ID of the friendship initiator.
    9493 * @param int $friend_userid    ID of the friend user.
    95  *
    9694 * @return bool True on success, false on failure.
    9795 */
     
    113111    do_action( 'friends_before_friendship_delete', $friendship_id, $initiator_userid, $friend_userid );
    114112
    115     // Remove the activity stream items about the friendship id
     113    // Remove the activity stream items about the friendship id.
    116114    friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_created', 'user_id' => 0 ) );
    117115
     
    155153 *
    156154 * @param int $friendship_id ID of the pending friendship object.
    157  *
    158155 * @return bool True on success, false on failure.
    159156 */
    160157function friends_accept_friendship( $friendship_id ) {
    161158
    162     // Get the friendship data
     159    // Get the friendship data.
    163160    $friendship = new BP_Friends_Friendship( $friendship_id, true, false );
    164161
    165     // Accepting friendship
     162    // Accepting friendship.
    166163    if ( empty( $friendship->is_confirmed ) && BP_Friends_Friendship::accept( $friendship_id ) ) {
    167164
    168         // Bump the friendship counts
     165        // Bump the friendship counts.
    169166        friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
    170167
     
    191188 *
    192189 * @param int $friendship_id ID of the pending friendship object.
    193  *
    194190 * @return bool True on success, false on failure.
    195191 */
     
    220216 *                              user who requested the friendship, and is doing the withdrawing.
    221217 * @param int $friend_userid    ID of the requested friend.
    222  *
    223218 * @return bool True on success, false on failure.
    224219 */
     
    253248 * @param int $user_id            ID of the first user.
    254249 * @param int $possible_friend_id ID of the other user.
    255  *
    256250 * @return bool Returns true if the two users are friends, otherwise false.
    257251 */
     
    271265 * @param int $user_id            ID of the first user.
    272266 * @param int $possible_friend_id ID of the other user.
    273  *
    274267 * @return string Friend status of the two users.
    275268 */
     
    277270    global $members_template;
    278271
    279     // check the BP_User_Query first
    280     // @see bp_friends_filter_user_query_populate_extras()
     272    // Check the BP_User_Query first
     273    // @see bp_friends_filter_user_query_populate_extras().
    281274    if ( ! empty( $members_template->in_the_loop ) ) {
    282275        if ( isset( $members_template->member->friendship_status ) ) {
     
    292285 *
    293286 * @param int $user_id ID of the user whose friends are being counted.
    294  *
    295287 * @return int Friend count of the user.
    296288 */
     
    317309 *
    318310 * @param int $user_id ID of the user whose friends are being checked.
    319  *
    320311 * @return bool True if the user has friends, otherwise false.
    321312 */
     
    337328 * @param int $initiator_user_id ID of the first user.
    338329 * @param int $friend_user_id    ID of the second user.
    339  *
    340330 * @return int|bool ID of the friendship if found, otherwise false.
    341331 */
     
    353343 *                                   'user_id' => $user_id; false to get a one-dimensional
    354344 *                                   array of user IDs. Default: false.
    355  *
    356345 * @return array
    357346 */
     
    369358 * @param int    $pag_page     Optional. The page of results to return. Default: null (no
    370359 *                             pagination - return all results).
    371  *
    372360 * @return array|bool On success, an array: {
    373361 *     @type array $friends IDs of friends returned by the query.
     
    384372 *
    385373 * @param int $user_id The ID of the user who has received the friendship requests.
    386  *
    387374 * @return array|bool An array of user IDs, or false if none are found.
    388375 */
     
    403390 * @param string $filter   Optional. Limit results to those matching a search
    404391 *                         string.
    405  *
    406392 * @return array See {@link BP_Core_User::get_users()}.
    407393 */
     
    433419 * @param string $filter   Optional. Limit results to those matching a search
    434420 *                         string.
    435  *
    436421 * @return array See {@link BP_Core_User::get_users()}.
    437422 */
     
    463448 * @param string $filter   Optional. Limit results to those matching a search
    464449 *                         string.
    465  *
    466450 * @return array See {@link BP_Core_User::get_users()}.
    467451 */
     
    488472 *
    489473 * @param array $friend_ids See BP_Friends_Friendship::get_bulk_last_active().
    490  *
    491474 * @return array $user_ids See BP_Friends_Friendship::get_bulk_last_active().
    492475 */
     
    506489 *                      ID of the logged-in user.
    507490 * @param int $group_id Group to check possible invitations against.
    508  *
    509491 * @return mixed False if no friends, array of users if friends.
    510492 */
    511493function friends_get_friends_invite_list( $user_id = 0, $group_id = 0 ) {
    512494
    513     // Default to logged in user id
     495    // Default to logged in user id.
    514496    if ( empty( $user_id ) )
    515497        $user_id = bp_loggedin_user_id();
    516498
    517     // Only group admins can invited previously banned users
     499    // Only group admins can invited previously banned users.
    518500    $user_is_admin = (bool) groups_is_user_admin( $user_id, $group_id );
    519501
    520     // Assume no friends
     502    // Assume no friends.
    521503    $friends = array();
    522504
     
    534516    ) );
    535517
    536     // User has friends
     518    // User has friends.
    537519    if ( bp_has_members( $args ) ) {
    538520
     
    547529        while ( bp_members() ) :
    548530
    549             // Load the member
     531            // Load the member.
    550532            bp_the_member();
    551533
    552             // Get the user ID of the friend
     534            // Get the user ID of the friend.
    553535            $friend_user_id = bp_get_member_user_id();
    554536
    555             // Skip friend if already in the group
     537            // Skip friend if already in the group.
    556538            if ( groups_is_user_member( $friend_user_id, $group_id ) )
    557539                continue;
    558540
    559             // Skip friend if not group admin and user banned from group
     541            // Skip friend if not group admin and user banned from group.
    560542            if ( ( false === $user_is_admin ) && groups_is_user_banned( $friend_user_id, $group_id ) )
    561543                continue;
    562544
    563             // Friend is safe, so add it to the array of possible friends
     545            // Friend is safe, so add it to the array of possible friends.
    564546            $friends[] = array(
    565547                'id'        => $friend_user_id,
     
    570552    }
    571553
    572     // If no friends, explicitly set to false
     554    // If no friends, explicitly set to false.
    573555    if ( empty( $friends ) )
    574556        $friends = false;
     
    597579 * @param int $user_id  ID of the user whose friends are being counted.
    598580 * @param int $group_id ID of the group friends are being invited to.
    599  *
    600581 * @return int $invitable_count Eligible friend count.
    601582 */
     
    609590 * @param int $user_id Optional. ID of the user whose friendships you are
    610591 *                     counting. Default: displayed user (if any), otherwise logged-in user.
    611  *
    612592 * @return int Friend count for the user.
    613593 */
     
    625605 * @param int    $pag_page     Number of the page being requested. Default: 0 (no
    626606 *                             pagination - show all results).
    627  *
    628607 * @return array Array of BP_Core_User objects corresponding to friends.
    629608 */
     
    646625 *
    647626 * @param int $friendship_id The ID of the friendship being checked.
    648  *
    649627 * @return bool True if the friendship is confirmed, otherwise false.
    650628 */
     
    702680    BP_Friends_Friendship::delete_all_for_user( $user_id );
    703681
    704     // Remove usermeta
     682    // Remove usermeta.
    705683    bp_delete_user_meta( $user_id, 'total_friend_count' );
    706684
     
    740718
    741719    $friends_query = array(
    742         'count_total'     => '',                    // Prevents total count
     720        'count_total'     => '',                    // Prevents total count.
    743721        'populate_extras' => false,
    744722
  • trunk/src/bp-friends/bp-friends-loader.php

    r10147 r10323  
    1212defined( 'ABSPATH' ) || exit;
    1313
     14/**
     15 * Defines the BuddyPress Friends Component.
     16 */
    1417class BP_Friends_Component extends BP_Component {
    1518
     
    7578        }
    7679
    77         // Define a slug, if necessary
     80        // Define a slug, if necessary.
    7881        if ( ! defined( 'BP_FRIENDS_SLUG' ) ) {
    7982            define( 'BP_FRIENDS_SLUG', $this->id );
    8083        }
    8184
    82         // Global tables for the friends component
     85        // Global tables for the friends component.
    8386        $global_tables = array(
    8487            'table_name'      => $bp->table_prefix . 'bp_friends',
     
    113116    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
    114117
    115         // Determine user to use
     118        // Determine user to use.
    116119        if ( bp_displayed_user_domain() ) {
    117120            $user_domain = bp_displayed_user_domain();
     
    126129        $friends_link = trailingslashit( $user_domain . $slug );
    127130
    128         // Add 'Friends' to the main navigation
     131        // Add 'Friends' to the main navigation.
    129132        $count    = friends_get_total_friend_count();
    130133        $class    = ( 0 === $count ) ? 'no-count' : 'count';
     
    138141        );
    139142
    140         // Add the subnav items to the friends nav item
     143        // Add the subnav items to the friends nav item.
    141144        $sub_nav[] = array(
    142145            'name'            => _x( 'Friendships', 'Friends screen sub nav', 'buddypress' ),
     
    174177    public function setup_admin_bar( $wp_admin_nav = array() ) {
    175178
    176         // Menus for logged in user
     179        // Menus for logged in user.
    177180        if ( is_user_logged_in() ) {
    178181
    179             // Setup the logged in user variables
     182            // Setup the logged in user variables.
    180183            $friends_link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() );
    181184
    182             // Pending friend requests
     185            // Pending friend requests.
    183186            $count = count( friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) );
    184187            if ( !empty( $count ) ) {
     
    190193            }
    191194
    192             // Add the "My Account" sub menus
     195            // Add the "My Account" sub menus.
    193196            $wp_admin_nav[] = array(
    194197                'parent' => buddypress()->my_account_menu_id,
     
    198201            );
    199202
    200             // My Friends
     203            // My Friends.
    201204            $wp_admin_nav[] = array(
    202205                'parent' => 'my-account-' . $this->id,
     
    206209            );
    207210
    208             // Requests
     211            // Requests.
    209212            $wp_admin_nav[] = array(
    210213                'parent' => 'my-account-' . $this->id,
     
    223226    public function setup_title() {
    224227
    225         // Adjust title
     228        // Adjust title.
    226229        if ( bp_is_friends_component() ) {
    227230            $bp = buddypress();
     
    249252    public function setup_cache_groups() {
    250253
    251         // Global groups
     254        // Global groups.
    252255        wp_cache_add_global_groups( array(
    253256            'bp_friends_requests'
  • trunk/src/bp-friends/bp-friends-notifications.php

    r10147 r10323  
    2424 * @param int $initiator_id  ID of the user who initiated the request.
    2525 * @param int $friend_id     ID of the request recipient.
    26  *
    2726 * @return bool
    2827 */
     
    4039    $initiator_link    = bp_core_get_user_domain( $initiator_id );
    4140
    42     // Set up and send the message
     41    // Set up and send the message.
    4342    $to       = $ud->user_email;
    4443    $subject  = bp_get_email_subject( array( 'text' => sprintf( __( 'New friendship request from %s', 'buddypress' ), $initiator_name ) ) );
     
    5352', 'buddypress' ), $initiator_name, $all_requests_link, $initiator_name, $initiator_link );
    5453
    55     // Only show the disable notifications line if the settings component is enabled
     54    // Only show the disable notifications line if the settings component is enabled.
    5655    if ( bp_is_active( 'settings' ) ) {
    5756        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     
    116115 * @param int $initiator_id  ID of the user who initiated the request.
    117116 * @param int $friend_id     ID of the request recipient.
    118  *
    119117 * @return bool
    120118 */
     
    131129    $settings_link = trailingslashit( bp_core_get_user_domain( $initiator_id ) . $settings_slug . '/notifications' );
    132130
    133     // Set up and send the message
     131    // Set up and send the message.
    134132    $to       = $ud->user_email;
    135133    $subject  = bp_get_email_subject( array( 'text' => sprintf( __( '%s accepted your friendship request', 'buddypress' ), $friend_name ) ) );
     
    142140', 'buddypress' ), $friend_name, $friend_name, $friend_link );
    143141
    144     // Only show the disable notifications line if the settings component is enabled
     142    // Only show the disable notifications line if the settings component is enabled.
    145143    if ( bp_is_active( 'settings' ) ) {
    146144        $message .= sprintf( __( 'To disable these notifications please log in and go to: %s', 'buddypress' ), $settings_link );
     
    207205 * @param string $format            'string' for BuddyBar-compatible notifications;
    208206 *                                  'array' for WP Toolbar. Default: 'string'.
    209  *
    210207 * @return array|string
    211208 */
     
    219216            $action = 'accepted';
    220217
    221             // Set up the string and the filter
     218            // Set up the string and the filter.
    222219            if ( (int) $total_items > 1 ) {
    223220                $text = sprintf( __( '%d friends accepted your friendship requests', 'buddypress' ), (int) $total_items );
     
    235232            $action = 'request';
    236233
    237             // Set up the string and the filter
     234            // Set up the string and the filter.
    238235            if ( (int) $total_items > 1 ) {
    239236                $text = sprintf( __( 'You have %d pending friendship requests', 'buddypress' ), (int) $total_items );
     
    247244    }
    248245
    249     // Return either an HTML link or an array, depending on the requested format
     246    // Return either an HTML link or an array, depending on the requested format.
    250247    if ( 'string' == $format ) {
    251248
     
    332329 *
    333330 * @since 1.9.0
     331 *
    334332 * @param int $friendship_id     The unique ID of the friendship.
    335333 * @param int $initiator_user_id The friendship initiator user ID.
     
    356354 * @since 1.9.0
    357355 *
    358  * @param int    $friendship_id (not used)
    359  * @param object $friendship
     356 * @param int    $friendship_id Friendship ID (not used).
     357 * @param object $friendship    Friendship object.
    360358 */
    361359function bp_friends_mark_friendship_rejected_notifications_by_item_id( $friendship_id, $friendship ) {
     
    377375function bp_friends_add_friendship_accepted_notification( $friendship_id, $initiator_user_id, $friend_user_id ) {
    378376
    379     // Bail if notifications is not active
     377    // Bail if notifications is not active.
    380378    if ( ! bp_is_active( 'notifications' ) ) {
    381379        return;
    382380    }
    383381
    384     // Remove the friend request notice
     382    // Remove the friend request notice.
    385383    bp_notifications_mark_notifications_by_item_id( $friend_user_id, $initiator_user_id, buddypress()->friends->id, 'friendship_request' );
    386384
    387     // Add a friend accepted notice for the initiating user
     385    // Add a friend accepted notice for the initiating user.
    388386    bp_notifications_add_notification(  array(
    389387        'user_id'           => $initiator_user_id,
     
    403401 * @since 1.9.0
    404402 *
    405  * @param int    $friendship_id (not used)
    406  * @param object $friendship
     403 * @param int    $friendship_id Friendship ID (not used).
     404 * @param object $friendship    Friendship Object.
    407405 */
    408406function bp_friends_mark_friendship_withdrawn_notifications_by_item_id( $friendship_id, $friendship ) {
     
    418416 * @since 1.9.0
    419417 *
    420  * @param int $user_id
     418 * @param int $user_id ID of the user whose notifications are removed.
    421419 */
    422420function bp_friends_remove_notifications_data( $user_id = 0 ) {
  • trunk/src/bp-friends/bp-friends-screens.php

    r10147 r10323  
    4141function friends_screen_requests() {
    4242    if ( bp_is_action_variable( 'accept', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) {
    43         // Check the nonce
     43        // Check the nonce.
    4444        check_admin_referer( 'friends_accept_friendship' );
    4545
     
    5252
    5353    } elseif ( bp_is_action_variable( 'reject', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) {
    54         // Check the nonce
     54        // Check the nonce.
    5555        check_admin_referer( 'friends_reject_friendship' );
    5656
     
    6363
    6464    } elseif ( bp_is_action_variable( 'cancel', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) {
    65         // Check the nonce
     65        // Check the nonce.
    6666        check_admin_referer( 'friends_withdraw_friendship' );
    6767
  • trunk/src/bp-friends/bp-friends-template.php

    r10147 r10323  
    263263     * @param int $user_id Optional. If provided, the function will simply
    264264     *                     return this value.
    265      *
    266265     * @return int ID of potential friend.
    267266     */
     
    291290 * @param int $user_id ID of the potential friend. Default: the value of
    292291 *                     {@link bp_get_potential_friend_id()}.
    293  *
    294292 * @return string 'is_friend', 'not_friends', or 'pending'.
    295293 */
     
    332330     *                                  applies. Default: value of {@link bp_get_potential_friend_id()}.
    333331     * @param bool $friend_status       Not currently used.
    334      *
    335332     * @return string HTML for the Add Friend button.
    336333     */
     
    357354                    'link_text'         => __( 'Cancel Friendship Request', 'buddypress' ),
    358355                    'link_title'        => __( 'Cancel Friendship Requested', 'buddypress' ),
    359                     'link_id'           => 'friend-' . $potential_friend_id,
    360                     'link_rel'          => 'remove',
     356                    'link_id'           => 'friend-' . $potential_friend_id,
     357                    'link_rel'          => 'remove',
    361358                    'link_class'        => 'friendship-button pending_friend requested'
    362359                );
     
    430427 * @param int $user_id Optional. Default: the displayed user's ID, or the
    431428 *                     logged-in user's ID.
    432  *
    433429 * @return string|bool A comma-separated list of friend IDs if any are found,
    434430 *                     otherwise false.
     
    455451 * @param int $user_id ID of the user whose requests are being retrieved.
    456452 *                     Defaults to displayed user.
    457  *
    458453 * @return array|int An array of user IDs if found, or a 0 if none are found.
    459454 */
     
    584579     *
    585580     * @param int $user_id See {@link friends_get_total_friend_count()}.
    586      *
    587581     * @return int Total friend count.
    588582     */
     
    615609     * @param int $user_id ID of the user whose requests are being counted.
    616610     *                     Default: ID of the logged-in user.
    617      *
    618611     * @return int Friend count.
    619612     */
     
    641634 * @uses bp_friends_get_profile_stats() to get the stats.
    642635 *
    643  * @param array|string $args before|after|user_id
     636 * @param array|string $args before|after|user_id.
    644637 */
    645638function bp_friends_profile_stats( $args = '' ) {
     
    653646 * @since 2.0.0
    654647 *
    655  * @param array|string $args before|after|user_id
    656  *
     648 * @param array|string $args before|after|user_id.
    657649 * @return string HTML for stats output.
    658650 */
    659651function bp_friends_get_profile_stats( $args = '' ) {
    660652
    661     // Parse the args
     653    // Parse the args.
    662654    $r = bp_parse_args( $args, array(
    663655        'before'  => '<li class="bp-friends-profile-stats">',
     
    668660    ), 'friends_get_profile_stats' );
    669661
    670     // Allow completely overloaded output
     662    // Allow completely overloaded output.
    671663    if ( empty( $r['output'] ) ) {
    672664
    673         // Only proceed if a user ID was passed
     665        // Only proceed if a user ID was passed.
    674666        if ( ! empty( $r['user_id'] ) ) {
    675667
    676             // Get the user's friends
     668            // Get the user's friends.
    677669            if ( empty( $r['friends'] ) ) {
    678670                $r['friends'] = absint( friends_get_total_friend_count( $r['user_id'] ) );
    679671            }
    680672
    681             // If friends exist, show some formatted output
     673            // If friends exist, show some formatted output.
    682674            $r['output'] = $r['before'] . sprintf( _n( '%s friend', '%s friends', $r['friends'], 'buddypress' ), '<strong>' . $r['friends'] . '</strong>' ) . $r['after'];
    683675        }
  • trunk/src/bp-friends/bp-friends-widgets.php

    r10276 r10323  
    157157     * @param array $new_instance The parameters saved by the user.
    158158     * @param array $old_instance The parameters as previously saved to the database.
    159      *
    160159     * @return array $instance The processed settings to save.
    161160     */
     
    174173     *
    175174     * @param array $instance The saved widget settings.
    176      *
    177      * @return string
     175     * @return void
    178176     */
    179177    function form( $instance ) {
     
    240238
    241239    if ( bp_has_members( $members_args ) ) : ?>
    242         <?php echo '0[[SPLIT]]'; // return valid result. TODO: remove this. ?>
     240        <?php echo '0[[SPLIT]]'; // Return valid result. TODO: remove this. ?>
    243241        <?php while ( bp_members() ) : bp_the_member(); ?>
    244242            <li class="vcard">
  • trunk/src/bp-friends/classes/class-bp-friends-friendship.php

    r10248 r10323  
    149149        do_action_ref_array( 'friends_friendship_before_save', array( &$this ) );
    150150
    151         // Update
     151        // Update.
    152152        if (!empty( $this->id ) ) {
    153153            $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
    154154
    155         // Save
     155        // Save.
    156156        } else {
    157157            $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, %s )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );
     
    171171    }
    172172
     173    /**
     174     * Delete the current friendship from the database.
     175     *
     176     * @return bool|int
     177     */
    173178    public function delete() {
    174179        global $wpdb;
     
    190195     *                                   keyed as 'user_id' => $user_id; false to get a one-dimensional
    191196     *                                   array of user IDs. Default: false.
    192      *
    193197     * @return array $fids IDs of friends for provided user.
    194198     */
     
    224228     * @param int $user_id   The ID of the first user.
    225229     * @param int $friend_id The ID of the second user.
    226      *
    227230     * @return int|bool The ID of the friendship object if found, otherwise false.
    228231     */
     
    240243     * @param int $user_id The ID of the user who has received the
    241244     *                     friendship requests.
    242      *
    243245     * @return array|bool An array of user IDs, or false if none are found.
    244246     */
     
    265267     *                     are counting. Default: displayed user (if any), otherwise
    266268     *                     logged-in user.
    267      *
    268269     * @return int Friend count for the user.
    269270     */
     
    276277        $bp = buddypress();
    277278
    278         /* This is stored in 'total_friend_count' usermeta.
    279            This function will recalculate, update and return. */
     279        /*
     280         * This is stored in 'total_friend_count' usermeta.
     281         * This function will recalculate, update and return.
     282         */
    280283
    281284        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id ) );
    282285
    283         // Do not update meta if user has never had friends
     286        // Do not update meta if user has never had friends.
    284287        if ( empty( $count ) && !bp_get_user_meta( $user_id, 'total_friend_count', true ) )
    285288            return 0;
     
    309312        global $wpdb;
    310313
    311         // TODO: Optimize this function.
     314        /*
     315         * TODO: Optimize this function.
     316         */
    312317
    313318        if ( empty( $user_id ) )
     
    315320
    316321        // Only search for matching strings at the beginning of the
    317         // name (@todo - figure out why this restriction)
     322        // name (@todo - figure out why this restriction).
    318323        $search_terms_like = bp_esc_like( $filter ) . '%';
    319324
     
    333338        $bp = buddypress();
    334339
    335         // filter the user_ids based on the search criteria.
     340        // Filter the user_ids based on the search criteria.
    336341        if ( bp_is_active( 'xprofile' ) ) {
    337342            $sql       = $wpdb->prepare( "SELECT DISTINCT user_id FROM {$bp->profile->table_name_data} WHERE user_id IN ({$fids}) AND value LIKE %s {$pag_sql}", $search_terms_like );
     
    357362     * request to $possible_friend_userid that has not yet been approved,
    358363     * while 'awaiting_response' is the other way around ($possible_friend_userid
    359      * sent the initial request)
     364     * sent the initial request).
    360365     *
    361366     * @param int $initiator_userid       The ID of the user who is the initiator
     
    363368     * @param int $possible_friend_userid The ID of the user who is the
    364369     *                                    recipient of the potential friendship/request.
    365      *
    366370     * @return string $value The friendship status, from among 'not_friends',
    367371     *                       'is_friend', 'pending', and 'awaiting_response'.
     
    398402     * @param array $user_ids IDs of users whose last_active meta is
    399403     *                        being queried.
    400      *
    401404     * @return array $retval Array of last_active values + user_ids.
    402405     */
     
    406409        $last_activities = BP_Core_User::get_last_activity( $user_ids );
    407410
    408         // Sort and structure as expected in legacy function
     411        // Sort and structure as expected in legacy function.
    409412        usort( $last_activities, create_function( '$a, $b', '
    410413            if ( $a["date_recorded"] == $b["date_recorded"] ) {
     
    431434     *
    432435     * @param int $friendship_id ID of the friendship to be accepted.
    433      *
    434436     * @return int Number of database rows updated.
    435437     */
     
    446448     *
    447449     * @param int $friendship_id ID of the friendship to be withdrawn.
    448      *
    449450     * @return int Number of database rows deleted.
    450451     */
     
    461462     *
    462463     * @param int $friendship_id ID of the friendship to be rejected.
    463      *
    464464     * @return int Number of database rows deleted.
    465465     */
     
    482482     * @param int    $page    Optional. Number of the page to return. Default:
    483483     *                        false (no pagination - return all results).
    484      *
    485484     * @return array $filtered_ids IDs of users who match the query.
    486485     */
     
    489488
    490489        // Only search for matching strings at the beginning of the
    491         // name (@todo - figure out why this restriction)
     490        // name (@todo - figure out why this restriction).
    492491        $search_terms_like = bp_esc_like( $filter ) . '%';
    493492
     
    501500        $bp = buddypress();
    502501
    503         // filter the user_ids based on the search criteria.
     502        // Filter the user_ids based on the search criteria.
    504503        if ( bp_is_active( 'xprofile' ) ) {
    505504            $sql = $wpdb->prepare( "SELECT DISTINCT d.user_id as id FROM {$bp->profile->table_name_data} d, {$users_table} u WHERE d.user_id = u.id AND d.value LIKE %s ORDER BY d.value DESC {$pag_sql}", $search_terms_like );
     
    522521     *
    523522     * @param string $filter Search term.
    524      *
    525523     * @return int Count of users matching the search term.
    526524     */
     
    529527
    530528        // Only search for matching strings at the beginning of the
    531         // name (@todo - figure out why this restriction)
     529        // name (@todo - figure out why this restriction).
    532530        $search_terms_like = bp_esc_like( $filter ) . '%';
    533531
     
    537535        $bp = buddypress();
    538536
    539         // filter the user_ids based on the search criteria.
     537        // Filter the user_ids based on the search criteria.
    540538        if ( bp_is_active( 'xprofile' ) ) {
    541539            $sql = $wpdb->prepare( "SELECT COUNT(DISTINCT d.user_id) FROM {$bp->profile->table_name_data} d, {$users_table} u WHERE d.user_id = u.id AND d.value LIKE %s", $search_terms_like );
     
    558556     *
    559557     * @param array $user_ids Array of user IDs.
    560      *
    561558     * @return array User IDs, sorted by the associated display names.
    562559     */
     
    580577     * @param int $total_friends Optional. Number of random friends to get.
    581578     *                           Default: 5.
    582      *
    583579     * @return array|bool An array of random friend user IDs on success;
    584580     *                    false if none are found.
     
    596592        }
    597593
    598         // remove duplicates
     594        // Remove duplicates.
    599595        if ( count( $fids ) > 0 )
    600596            return array_flip( array_flip( $fids ) );
     
    614610     * @param int $user_id  ID of the user whose friends are being counted.
    615611     * @param int $group_id ID of the group friends are being invited to.
    616      *
    617612     * @return int $invitable_count Eligible friend count.
    618613     */
    619614    public static function get_invitable_friend_count( $user_id, $group_id ) {
    620615
    621         // Setup some data we'll use below
     616        // Setup some data we'll use below.
    622617        $is_group_admin  = BP_Groups_Member::check_is_admin( $user_id, $group_id );
    623618        $friend_ids      = BP_Friends_Friendship::get_friend_user_ids( $user_id );
     
    626621        for ( $i = 0, $count = count( $friend_ids ); $i < $count; ++$i ) {
    627622
    628             // If already a member, they cannot be invited again
     623            // If already a member, they cannot be invited again.
    629624            if ( BP_Groups_Member::check_is_member( (int) $friend_ids[$i], $group_id ) )
    630625                continue;
    631626
    632             // If user already has invite, they cannot be added
     627            // If user already has invite, they cannot be added.
    633628            if ( BP_Groups_Member::check_has_invite( (int) $friend_ids[$i], $group_id )  )
    634629                continue;
    635630
    636             // If user is not group admin and friend is banned, they cannot be invited
     631            // If user is not group admin and friend is banned, they cannot be invited.
    637632            if ( ( false === $is_group_admin ) && BP_Groups_Member::check_is_banned( (int) $friend_ids[$i], $group_id ) )
    638633                continue;
     
    648643     *
    649644     * @param int $friendship_id ID of the friendship.
    650      *
    651645     * @return object friend_user_id and initiator_user_id.
    652646     */
     
    669663        $bp = buddypress();
    670664
    671         // Get friends of $user_id
     665        // Get friends of $user_id.
    672666        $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );
    673667
    674         // Delete all friendships related to $user_id
     668        // Delete all friendships related to $user_id.
    675669        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id ) );
    676670
     
    681675        }
    682676
    683         // Loop through friend_ids and update their counts
     677        // Loop through friend_ids and update their counts.
    684678        foreach ( (array) $friend_ids as $friend_id ) {
    685679            BP_Friends_Friendship::total_friend_count( $friend_id );
Note: See TracChangeset for help on using the changeset viewer.