Skip to:
Content

BuddyPress.org

Changeset 1810


Ignore:
Timestamp:
09/07/2009 07:25:59 PM (15 years ago)
Author:
apeatling
Message:

Fixes #982

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-friends.php

    r1801 r1810  
    4444       
    4545    $bp->friends->table_name = $wpdb->base_prefix . 'bp_friends';
    46     $bp->friends->format_activity_function = 'friends_format_activity';
    4746    $bp->friends->format_notification_function = 'friends_format_notifications';
    4847    $bp->friends->slug = BP_FRIENDS_SLUG;
     
    271270 */
    272271
    273 function friends_record_activity( $args ) {
    274     if ( function_exists('bp_activity_record') ) {
     272function friends_record_activity( $args = '' ) {
     273    global $bp;
     274   
     275    if ( !function_exists( 'bp_activity_add' ) )
     276        return false;
     277
     278    $defaults = array(
     279        'user_id' => $bp->loggedin_user->id,
     280        'content' => false,
     281        'primary_link' => false,
     282        'component_name' => $bp->friends->id,
     283        'component_action' => false,
     284        'item_id' => false,
     285        'secondary_item_id' => false,
     286        'recorded_time' => time(),
     287        'hide_sitewide' => false
     288    );
     289
     290    $r = wp_parse_args( $args, $defaults );
     291    extract( $r, EXTR_SKIP );   
     292
     293    return bp_activity_add( array( 'user_id' => $user_id, 'content' => $content, 'primary_link' => $primary_link, 'component_name' => $component_name, 'component_action' => $component_action, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide ) );
     294}
     295
     296function friends_delete_activity( $args ) {
     297    if ( function_exists('bp_activity_delete_by_item_id') ) {
    275298        extract( (array)$args );
    276         bp_activity_record( $item_id, $component_name, $component_action, $is_private, $secondary_item_id, $user_id, $secondary_user_id );
    277     }
    278 }
    279 add_action( 'friends_friendship_accepted', 'friends_record_activity' );
    280 
    281 function friends_delete_activity( $args ) {
    282     if ( function_exists('bp_activity_delete') ) {
    283         extract( (array)$args );
    284         bp_activity_delete( $item_id, $component_name, $component_action, $user_id, $secondary_item_id );
    285     }
    286 }
    287 
    288 function friends_format_activity( $item_id, $user_id, $action, $secondary_item_id = false, $for_secondary_user = false ) {
    289     global $bp;
    290    
    291     switch( $action ) {
    292         case 'friendship_created':
    293             $friendship = new BP_Friends_Friendship( $item_id, false, false );
    294 
    295             if ( !$friendship->initiator_user_id || !$friendship->friend_user_id )
    296                 return false;
    297            
    298             if ( $for_secondary_user ) {
    299                
    300                 $user_1 = bp_core_get_userlink( $friendship->initiator_user_id );
    301                 $user_2 = bp_core_get_userlink($friendship->friend_user_id, false, false, true);
    302                
    303                 return array(
    304                     'primary_link' => bp_core_get_userlink( $friendship->friend_user_id, false, true ),
    305                     'content' => apply_filters( 'bp_friends_friendship_accepted_activity', sprintf( __( '%s and %s are now friends', 'buddypress' ), $user_1, $user_2 ) . ' <span class="time-since">%s</span>', $user_1, $user_2 )
    306                 );             
    307             } else {
    308                
    309                 $user_1 = bp_core_get_userlink( $friendship->friend_user_id );
    310                 $user_2 = bp_core_get_userlink($friendship->initiator_user_id);
    311                
    312                 return array(
    313                     'primary_link' => bp_core_get_userlink( $friendship->friend_user_id, false, true ),
    314                     'content' => apply_filters( 'bp_friends_friendship_accepted_activity', sprintf( __( '%s and %s are now friends', 'buddypress' ), bp_core_get_userlink( $friendship->friend_user_id ), bp_core_get_userlink($friendship->initiator_user_id) ) . ' <span class="time-since">%s</span>', $user_1, $user_2 )
    315                 );         
    316             }
    317         break;
    318     }
    319    
    320     do_action( 'friends_format_activity', $action, $item_id, $user_id, $action, $secondary_item_id, $for_secondary_user );
    321    
    322     return false;
     299        bp_activity_delete_by_item_id( array( 'item_id' => $item_id, 'component_name' => $bp->friends->id, 'component_action' => $component_action, 'user_id' => $user_id, 'secondary_item_id' => $secondary_item_id ) );
     300    }
    323301}
    324302
     
    619597    $friendship = new BP_Friends_Friendship( $friendship_id );
    620598   
    621     // Remove the activity stream items
    622     friends_delete_activity( array( 'item_id' => $friendship_id, 'component_name' => $bp->friends->slug, 'component_action' => 'friendship_accepted', 'user_id' => $bp->displayed_user->id ) );
     599    // Remove the activity stream item for the user who canceled the friendship
     600    friends_delete_activity( array( 'item_id' => $friendship_id, 'component_action' => 'friendship_accepted', 'user_id' => $bp->displayed_user->id ) );
    623601   
    624602    do_action( 'friends_friendship_deleted', $friendship_id, $initiator_userid, $friend_userid );
     
    641619        friends_update_friend_totals( $friendship->initiator_user_id, $friendship->friend_user_id );
    642620       
    643         // Remove the friend request notice
     621        /* Remove the friend request notice */
    644622        bp_core_delete_notifications_for_user_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_request' );   
    645623       
    646         // Add a friend accepted notice for the initiating user
     624        /* Add a friend accepted notice for the initiating user */
    647625        bp_core_add_notification( $friendship->friend_user_id, $friendship->initiator_user_id, 'friends', 'friendship_accepted' );
    648626       
    649         // Record in activity streams
    650         friends_record_activity( array( 'item_id' => $friendship_id, 'component_name' => $bp->friends->slug, 'component_action' => 'friendship_created', 'is_private' => 0, 'user_id' => $friendship->initiator_user_id, 'secondary_user_id' => $friendship->friend_user_id ) );
    651        
    652         // Send the email notification
     627        $initiator_link = bp_core_get_userlink( $friendship->initiator_user_id );
     628        $friend_link = bp_core_get_userlink( $friendship->friend_user_id );
     629       
     630        $primary_link = apply_filters( 'bp_friends_friendship_accepted_primary_link', bp_core_get_userlink( $friendship->initiator_user_id ), &$friendship );
     631        $activity_content = apply_filters( 'bp_friends_friendship_accepted_activity', sprintf( __( '%s and %s are now friends', 'buddypress' ), $initiator_link, $friend_link ), &$friendship );
     632           
     633        /* Record in activity streams for the initiator */
     634        friends_record_activity( array(
     635            'user_id' => $friendship->initiator_user_id,
     636            'component_action' => 'friendship_created',
     637            'content' => $activity_content,
     638            'primary_link' => $primary_link,
     639            'item_id' => $friendship_id
     640        ) );
     641       
     642        /* Record in activity streams for the friend */
     643        friends_record_activity( array(
     644            'user_id' => $friendship->friend_user_id,
     645            'component_action' => 'friendship_created',
     646            'content' => $activity_content,
     647            'primary_link' => $primary_link,
     648            'item_id' => $friendship_id,
     649            'hide_sitewide' => true /* We've already got the first entry site wide */
     650        ) );
     651       
     652        /* Send the email notification */
    653653        require_once( BP_PLUGIN_DIR . '/bp-friends/bp-friends-notifications.php' );
    654654        friends_notification_accepted_request( $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id );
Note: See TracChangeset for help on using the changeset viewer.