Skip to:
Content

BuddyPress.org

Ticket #3897: bp-cancel-friendship-request.patch

File bp-cancel-friendship-request.patch, 6.5 KB (added by ddean, 13 years ago)

Proposal to wire up the friendship pending button

  • bp-friends/bp-friends-classes.php

    ### Eclipse Workspace Patch 1.0
    #P BuddyPress-trunk
     
    207207                return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, bp_loggedin_user_id() ) );
    208208        }
    209209
     210        public static function withdraw($friendship_id) {
     211                global $wpdb, $bp;
     212
     213                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE id = %d AND initiator_user_id = %d", $friendship_id, bp_loggedin_user_id() ) );
     214        }
     215
    210216        public static function reject($friendship_id) {
    211217                global $wpdb, $bp;
    212218
  • bp-friends/bp-friends-functions.php

     
    139139        return false;
    140140}
    141141
     142function friends_withdraw_friendship( $initiator_userid, $friend_userid ) {
     143        global $bp;
     144
     145        $friendship_id = BP_Friends_Friendship::get_friendship_id( $initiator_userid, $friend_userid );
     146        $friendship = new BP_Friends_Friendship( $friendship_id, true, false );
     147       
     148        if ( !$friendship->is_confirmed && BP_Friends_Friendship::withdraw( $friendship_id ) ) {
     149                // Remove the friend request notice
     150                bp_core_delete_notifications_by_item_id( $friendship->friend_user_id, $friendship->initiator_user_id, $bp->friends->id, 'friendship_request' );
     151
     152                do_action_ref_array( 'friends_friendship_whithdrawn', array( $friendship_id, &$friendship ) );
     153                return true;
     154        }
     155
     156        return false;
     157}
     158
    142159function friends_check_friendship( $user_id, $possible_friend_id ) {
    143160
    144161        if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) )
  • bp-themes/bp-default/_inc/ajax.php

     
    477477                if ( !friends_add_friend( bp_loggedin_user_id(), $_POST['fid'] ) ) {
    478478                        echo __("Friendship could not be requested.", 'buddypress');
    479479                } else {
    480                         echo '<a href="' . bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests" class="requested">' . __( 'Friendship Requested', 'buddypress' ) . '</a>';
     480                        echo '<a id="friend-' . $_POST['fid'] . '" class="remove" rel="remove" title="' . __( 'Cancel Friendship Request', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . (int)$_POST['fid'] . '/', 'friends_withdraw_friendship' ) . '" class="requested">' . __( 'Cancel Friendship Request', 'buddypress' ) . '</a>';
    481481                }
     482        } else if( 'pending' == BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), (int)$_POST['fid'] ) ) {
     483               
     484                check_ajax_referer('friends_withdraw_friendship');
     485               
     486                if ( friends_withdraw_friendship( bp_loggedin_user_id(), (int)$_POST['fid'] ) ) {
     487                        echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __( 'Add Friend', 'buddypress' ) . '" href="' . wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend' ) . '">' . __( 'Add Friend', 'buddypress' ) . '</a>';
     488                } else {
     489                        echo __("Friendship request could not be cancelled.", 'buddypress');
     490                }
    482491        } else {
    483492                echo __( 'Request Pending', 'buddypress' );
    484493        }
  • bp-themes/bp-default/_inc/global.js

     
    917917                                        function() {
    918918                                                parentdiv.removeClass('add_friend');
    919919                                                parentdiv.removeClass('loading');
    920                                                 parentdiv.addClass('pending');
     920                                                parentdiv.addClass('pending_friend');
    921921                                                parentdiv.fadeIn(200).html(response);
    922922                                        }
    923923                                        );
  • bp-friends/bp-friends-screens.php

     
    4747                        bp_core_add_message( __( 'Friendship could not be rejected', 'buddypress' ), 'error' );
    4848
    4949                bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action() ) );
     50               
     51        } elseif ( bp_is_action_variable( 'cancel', 0 ) && is_numeric( bp_action_variable( 1 ) ) ) {
     52                // Check the nonce
     53                check_admin_referer( 'friends_withdraw_friendship' );
     54
     55                if ( friends_withdraw_friendship( bp_loggedin_user_id(), bp_action_variable( 1 ) ) )
     56                        bp_core_add_message( __( 'Friendship request withdrawn', 'buddypress' ) );
     57                else
     58                        bp_core_add_message( __( 'Friendship request could not be withdrawn', 'buddypress' ), 'error' );
     59
     60                bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_current_component() . '/' . bp_current_action() ) );
    5061        }
    5162
    5263        do_action( 'friends_screen_requests' );
  • bp-friends/bp-friends-template.php

     
    318318                                        'component'         => 'friends',
    319319                                        'must_be_logged_in' => true,
    320320                                        'block_self'        => true,
    321                                         'wrapper_class'     => 'friendship-button pending',
     321                                        'wrapper_class'     => 'friendship-button pending_friend',
    322322                                        'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    323                                         'link_href'         => trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests' ),
    324                                         'link_text'         => __( 'Friendship Requested', 'buddypress' ),
    325                                         'link_title'        => __( 'Friendship Requested', 'buddypress' ),
    326                                         'link_class'        => 'friendship-button pending requested'
     323                                        'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),
     324                                        'link_text'         => __( 'Cancel Friendship Request', 'buddypress' ),
     325                                        'link_title'        => __( 'Cancel Friendship Requested', 'buddypress' ),
     326                                        'link_id'                       => 'friend-' . $potential_friend_id,
     327                                        'link_rel'                      => 'remove',
     328                                        'link_class'        => 'friendship-button pending_friend requested'
    327329                                );
    328330                                break;
    329331