コード例 #1
0
/**
 * Catch and process Remove Friendship requests.
 *
 * @since 1.0.1
 */
function friends_action_remove_friend()
{
    if (!bp_is_friends_component() || !bp_is_current_action('remove-friend')) {
        return false;
    }
    if (!($potential_friend_id = (int) bp_action_variable(0))) {
        return false;
    }
    if ($potential_friend_id == bp_loggedin_user_id()) {
        return false;
    }
    $friendship_status = BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $potential_friend_id);
    if ('is_friend' == $friendship_status) {
        if (!check_admin_referer('friends_remove_friend')) {
            return false;
        }
        if (!friends_remove_friend(bp_loggedin_user_id(), $potential_friend_id)) {
            bp_core_add_message(__('Friendship could not be canceled.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Friendship canceled', 'buddypress'));
        }
    } elseif ('is_friends' == $friendship_status) {
        bp_core_add_message(__('You are not yet friends with this user', 'buddypress'), 'error');
    } else {
        bp_core_add_message(__('You have a pending friendship request with this user', 'buddypress'), 'error');
    }
    bp_core_redirect(wp_get_referer());
    return false;
}
コード例 #2
0
 /**
  * @group friends_get_friendship_request_user_ids
  * @group friends_add_friend
  */
 public function test_requests_on_request()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $u3 = $this->factory->user->create();
     // request friendship
     friends_add_friend($u2, $u1);
     // Set the time of the earlier friendship for reliable ordering of the results.
     $fid = friends_get_friendship_id($u2, $u1);
     $friendship = new BP_Friends_Friendship($fid, false, false);
     $friendship->date_created = date('Y-m-d H:i:s', time() - 60);
     $friendship->save();
     // get request count for user 1 and assert
     $requests = friends_get_friendship_request_user_ids($u1);
     $this->assertEquals(array($u2), $requests);
     // request another friendship
     friends_add_friend($u3, $u1);
     // refetch request count for user 1 and assert
     $requests = friends_get_friendship_request_user_ids($u1);
     $this->assertEquals(array($u3, $u2), $requests);
 }
コード例 #3
0
/**
 * Filter BP_User_Query::populate_extras to add confirmed friendship status.
 *
 * Each member in the user query is checked for confirmed friendship status
 * against the logged-in user.
 *
 * @since 1.7.0
 *
 * @global WPDB $wpdb WordPress database access object.
 *
 * @param BP_User_Query $user_query   The BP_User_Query object.
 * @param string        $user_ids_sql Comma-separated list of user IDs to fetch extra
 *                                    data for, as determined by BP_User_Query.
 */
function bp_friends_filter_user_query_populate_extras(BP_User_Query $user_query, $user_ids_sql)
{
    global $wpdb;
    // Stop if user isn't logged in.
    if (!($user_id = bp_loggedin_user_id())) {
        return;
    }
    $maybe_friend_ids = wp_parse_id_list($user_ids_sql);
    foreach ($maybe_friend_ids as $friend_id) {
        $status = BP_Friends_Friendship::check_is_friend($user_id, $friend_id);
        $user_query->results[$friend_id]->friendship_status = $status;
        if ('is_friend' == $status) {
            $user_query->results[$friend_id]->is_friend = 1;
        }
    }
}
コード例 #4
0
function example_friends_ajax_addremove_friend()
{
    global $bp;
    if ('is_friend' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
        if (!friends_remove_friend($bp->loggedin_user->id, $_POST['fid'])) {
            echo __('Friendship could not be canceled.', 'bp-component');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'bp-component') . '" href="' . $bp->loggedin_user->domain . $bp['friends']['slug'] . '/add-friend/' . $_POST['fid'] . '">' . __('Add Friend', 'bp-component') . '</a>';
        }
    } else {
        if ('not_friends' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
            if (!friends_add_friend($bp->loggedin_user->id, $_POST['fid'])) {
                echo __('Friendship could not be requested.', 'bp-component');
            } else {
                echo '<a href="' . $bp->loggedin_user->domain . $bp['friends']['slug'] . '" class="requested">' . __('Friendship Requested', 'bp-component') . '</a>';
            }
        } else {
            echo __('Request Pending', 'bp-component');
        }
    }
    return false;
}
コード例 #5
0
function wpmudev_chat_buddypress_member_header_actions()
{
    global $bp, $members_template, $wpmudev_chat, $current_user;
    if ($bp->loggedin_user->id === bp_displayed_user_id()) {
        return;
    }
    //if (!is_object('BP_Friends_Friendship')) return;
    if (!bp_is_active('friends')) {
        return;
    }
    if (!class_exists('BP_Friends_Friendship')) {
        return $is_friend_ret = BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), bp_displayed_user_id());
    }
    //echo "is_friend_ret[". $is_friend_ret ."]<br />";
    // Set this so when we get to wp_footer it knows we need to load the JS/CSS for the Friends display.
    $wpmudev_chat->_chat_plugin_settings['blocked_urls']['front'] = false;
    if (BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), bp_displayed_user_id()) == 'is_friend' || $bp->loggedin_user->is_site_admin == true) {
        $content = '';
        $content .= '<div id="wpmudev-chat-now-button-' . bp_displayed_user_id() . '" class="generic-button wpmudev-chat-now-button">';
        $friends_status = wpmudev_chat_get_friends_status($bp->loggedin_user->id, bp_displayed_user_id());
        if (!empty($friends_status[0])) {
            $friends_status = $friends_status[0];
        } else {
            $friends_status = '';
        }
        $friend_data = wpmudev_chat_get_chat_status_data(bp_displayed_user_id(), $friends_status);
        //echo "friend_data<pre>"; print_r($friend_data); echo "</pre>";
        $friend_status_display = $friend_data['icon'] . $friend_data['label'];
        if (!empty($friend_data['href'])) {
            $content .= '<a class="button wpmudev-chat-button ' . $friend_data['href_class'] . '" title="' . $friend_data['href_title'] . '" href="#" rel="' . $friend_data['href'] . '">' . $friend_status_display . '</a>';
        } else {
            $content .= '<a onclick="return false;" disabled="disabled" class="wpmudev-chat-button ' . $friend_data['href_class'] . '" title="' . $friend_data['href_title'] . '" href="#">' . $friend_status_display . '</a>';
        }
        $content .= '</div>';
        echo $content;
    }
}
コード例 #6
0
function friends_ajax_addremove_friend()
{
    global $bp;
    if ('is_friend' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
        check_ajax_referer('friends_remove_friend');
        if (!friends_remove_friend($bp->loggedin_user->id, $_POST['fid'])) {
            echo __("Friendship could not be canceled.", 'buddypress');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'buddypress') . '" href="' . wp_nonce_url($bp->loggedin_user->domain . $bp->friends->slug . '/add-friend/' . $_POST['fid'], 'friends_add_friend') . '">' . __('Add Friend', 'buddypress') . '</a>';
        }
    } else {
        if ('not_friends' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
            check_ajax_referer('friends_add_friend');
            if (!friends_add_friend($bp->loggedin_user->id, $_POST['fid'])) {
                echo __("Friendship could not be requested.", 'buddypress');
            } else {
                echo '<a href="' . $bp->loggedin_user->domain . $bp->friends->slug . '" class="requested">' . __('Friendship Requested', 'buddypress') . '</a>';
            }
        } else {
            echo __('Request Pending', 'buddypress');
        }
    }
    return false;
}
コード例 #7
0
 function populate_extras()
 {
     global $bp;
     if (function_exists('friends_install')) {
         $this->total_friends = BP_Friends_Friendship::total_friend_count($this->id);
         if ($this->total_friends) {
             if (1 == $this->total_friends) {
                 $this->total_friends .= ' ' . __('friend', 'buddypress');
             } else {
                 $this->total_friends .= ' ' . __('friends', 'buddypress');
             }
             $this->total_friends = '<a href="' . $this->user_url . $bp->friends->slug . '" title="' . sprintf(__("%s's friend list", 'buddypress'), $this->fullname) . '">' . $this->total_friends . '</a>';
         }
     }
     if (function_exists('bp_blogs_install')) {
         if ($this->total_blogs) {
             if (1 == $this->total_blogs) {
                 $this->total_blogs .= ' ' . __('blog', 'buddypress');
             } else {
                 $this->total_blogs .= ' ' . __('blogs', 'buddypress');
             }
             $this->total_blogs = '<a href="' . $this->user_url . $bp->blogs->slug . '" title="' . sprintf(__("%s's blog list", 'buddypress'), $this->fullname) . '">' . $this->total_blogs . '</a>';
         }
     }
     if (function_exists('groups_install')) {
         $this->total_groups = BP_Groups_Member::total_group_count($this->id);
         if ($this->total_groups) {
             if (1 == $this->total_groups) {
                 $this->total_groups .= ' ' . __('group', 'buddypress');
             } else {
                 $this->total_groups .= ' ' . __('groups', 'buddypress');
             }
             $this->total_groups = '<a href="' . $this->user_url . $bp->groups->slug . '" title="' . sprintf(__("%s's group list", 'buddypress'), $this->fullname) . '">' . $this->total_groups . '</a>';
         }
     }
 }
コード例 #8
0
 function delete_all_for_user($user_id)
 {
     global $nxtdb, $bp;
     // Get friends of $user_id
     $friend_ids = BP_Friends_Friendship::get_friend_user_ids($user_id);
     // Delete all friendships related to $user_id
     $nxtdb->query($nxtdb->prepare("DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id));
     // Delete friend request notifications for members who have a notification from this user.
     $nxtdb->query($nxtdb->prepare("DELETE FROM {$bp->core->table_name_notifications} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id));
     // Loop through friend_ids and update their counts
     foreach ((array) $friend_ids as $friend_id) {
         BP_Friends_Friendship::total_friend_count($friend_id);
     }
 }
コード例 #9
0
ファイル: bp-friends-functions.php プロジェクト: eresyyl/mk
/**
 * Remove all friends-related data concerning a given user.
 *
 * Removes the following:
 *
 * - Friendships of which the user is a member
 * - Cached friend count for the user
 * - Notifications of friendship requests sent by the user
 *
 * @param int $user_id ID of the user whose friend data is being removed.
 */
function friends_remove_data($user_id)
{
    do_action('friends_before_remove_data', $user_id);
    BP_Friends_Friendship::delete_all_for_user($user_id);
    // Remove usermeta
    bp_delete_user_meta($user_id, 'total_friend_count');
    do_action('friends_remove_data', $user_id);
}
コード例 #10
0
function bp_friends_random_friends()
{
    global $bp;
    if (!($friend_ids = wp_cache_get('friends_friend_ids_' . $bp->displayed_user->id, 'bp'))) {
        $friend_ids = BP_Friends_Friendship::get_random_friends($bp->displayed_user->id);
        wp_cache_set('friends_friend_ids_' . $bp->displayed_user->id, $friend_ids, 'bp');
    }
    ?>
	
	<div class="info-group">
		<h4><?php 
    bp_word_or_name(__("My Friends", 'buddypress'), __("%s's Friends", 'buddypress'));
    ?>
  (<?php 
    echo BP_Friends_Friendship::total_friend_count($bp->displayed_user->id);
    ?>
)  <a href="<?php 
    echo $bp->displayed_user->domain . $bp->friends->slug;
    ?>
"><?php 
    _e('See All', 'buddypress');
    ?>
 &raquo;</a></h4>
		
		<?php 
    if ($friend_ids) {
        ?>
			<ul class="horiz-gallery">
			<?php 
        for ($i = 0; $i < count($friend_ids); $i++) {
            ?>
				<li>
					<a href="<?php 
            echo bp_core_get_userurl($friend_ids[$i]);
            ?>
"><?php 
            echo bp_core_get_avatar($friend_ids[$i], 1);
            ?>
</a>
					<h5><?php 
            echo bp_core_get_userlink($friend_ids[$i]);
            ?>
</h5>
				</li>
			<?php 
        }
        ?>
			</ul>
		<?php 
    } else {
        ?>
			<div id="message" class="info">
				<p><?php 
        bp_word_or_name(__("You haven't added any friend connections yet.", 'buddypress'), __("%s hasn't created any friend connections yet.", 'buddypress'));
        ?>
</p>
			</div>
		<?php 
    }
    ?>
		<div class="clear"></div>
	</div>
<?php 
}
コード例 #11
0
/**
 * AJAX handler for autocomplete.
 *
 * Displays friends only, unless BP_MESSAGES_AUTOCOMPLETE_ALL is defined.
 *
 * @since BuddyPress (1.2.0)
 *
 * @return string HTML.
 */
function bp_legacy_theme_ajax_messages_autocomplete_results()
{
    // Include everyone in the autocomplete, or just friends?
    if (bp_is_current_component(bp_get_messages_slug())) {
        $autocomplete_all = buddypress()->messages->autocomplete_all;
    }
    $pag_page = 1;
    $limit = (int) $_GET['limit'] ? $_GET['limit'] : apply_filters('bp_autocomplete_max_results', 10);
    $search_terms = isset($_GET['q']) ? $_GET['q'] : '';
    $user_query_args = array('search_terms' => $search_terms, 'page' => intval($pag_page), 'per_page' => intval($limit));
    // If only matching against friends, get an $include param for
    // BP_User_Query
    if (!$autocomplete_all && bp_is_active('friends')) {
        $include = BP_Friends_Friendship::get_friend_user_ids(bp_loggedin_user_id());
        // Ensure zero matches if no friends are found
        if (empty($include)) {
            $include = array(0);
        }
        $user_query_args['include'] = $include;
    }
    $user_query = new BP_User_Query($user_query_args);
    // Backward compatibility - if a plugin is expecting a legacy
    // filter, pass the IDs through the filter and requery (groan)
    if (has_filter('bp_core_autocomplete_ids') || has_filter('bp_friends_autocomplete_ids')) {
        $found_user_ids = wp_list_pluck($user_query->results, 'ID');
        if ($autocomplete_all) {
            $found_user_ids = apply_filters('bp_core_autocomplete_ids', $found_user_ids);
        } else {
            $found_user_ids = apply_filters('bp_friends_autocomplete_ids', $found_user_ids);
        }
        if (empty($found_user_ids)) {
            $found_user_ids = array(0);
        }
        // Repopulate the $user_query variable
        $user_query = new BP_User_Query(array('include' => $found_user_ids));
    }
    if (!empty($user_query->results)) {
        foreach ($user_query->results as $user) {
            if (bp_is_username_compatibility_mode()) {
                // Sanitize for spaces. Use urlencode() rather
                // than rawurlencode() because %20 breaks JS
                $username = urlencode($user->user_login);
            } else {
                $username = $user->user_nicename;
            }
            // Note that the final line break acts as a delimiter for the
            // autocomplete javascript and thus should not be removed
            echo '<span id="link-' . esc_attr($username) . '" href="' . bp_core_get_user_domain($user->ID) . '"></span>' . bp_core_fetch_avatar(array('item_id' => $user->ID, 'type' => 'thumb', 'width' => 15, 'height' => 15, 'alt' => $user->display_name)) . ' &nbsp;' . bp_core_get_user_displayname($user->ID) . ' (' . esc_html($username) . ')' . "\n";
        }
    }
    exit;
}
コード例 #12
0
ファイル: bp-friends.php プロジェクト: alvaropereyra/shrekcms
function friends_remove_data($user_id)
{
    BP_Friends_Friendship::delete_all_for_user($user_id);
    /* Remove usermeta */
    delete_usermeta($user_id, 'total_friend_count');
    /* Remove friendship requests FROM user */
    bp_core_delete_notifications_from_user($user_id, $bp->friends->slug, 'friendship_request');
    do_action('friends_remove_data', $user_id);
}
コード例 #13
0
/**
 * Catch the 'to' email address of sent email notifications, and hook message filter if necessary
 *
 * This function is necessary because the groups_notification_group_invites_message
 * filter doesn't receive easily parsable info about the invitee.
 *
 * @since 1.0.22
 */
function invite_anyone_group_invite_maybe_filter_invite_message($to)
{
    if (!bp_is_active('friends')) {
        return $to;
    }
    $invited_user = get_user_by('email', $to);
    $friendship_status = BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $invited_user->ID);
    if ('is_friend' !== $friendship_status) {
        add_action('groups_notification_group_invites_message', 'invite_anyone_group_invite_email_message', 10, 7);
    }
    return $to;
}
コード例 #14
0
ファイル: ajax.php プロジェクト: nxtclass/NXTClass-Plugin
function bp_dtheme_ajax_addremove_friend()
{
    global $bp;
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if ('is_friend' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
        check_ajax_referer('friends_remove_friend');
        if (!friends_remove_friend($bp->loggedin_user->id, $_POST['fid'])) {
            echo __("Friendship could not be canceled.", 'buddypress');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'buddypress') . '" href="' . nxt_nonce_url($bp->loggedin_user->domain . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend') . '">' . __('Add Friend', 'buddypress') . '</a>';
        }
    } else {
        if ('not_friends' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $_POST['fid'])) {
            check_ajax_referer('friends_add_friend');
            if (!friends_add_friend($bp->loggedin_user->id, $_POST['fid'])) {
                echo __("Friendship could not be requested.", 'buddypress');
            } else {
                echo '<a href="' . $bp->loggedin_user->domain . bp_get_friends_slug() . '/requests" class="requested">' . __('Friendship Requested', 'buddypress') . '</a>';
            }
        } else {
            echo __('Request Pending', 'buddypress');
        }
    }
    return false;
}
コード例 #15
0
 function the_invite()
 {
     global $group_id;
     $this->in_the_loop = true;
     $user_id = $this->next_invite();
     $this->invite = new stdClass();
     $this->invite->user = $this->invite_data[$user_id];
     // This method previously populated the user object with
     // BP_Core_User. We manually configure BP_Core_User data for
     // backward compatibility.
     if (bp_is_active('xprofile')) {
         $this->invite->user->profile_data = BP_XProfile_ProfileData::get_all_for_user($user_id);
     }
     $this->invite->user->avatar = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'full', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname)));
     $this->invite->user->avatar_thumb = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname)));
     $this->invite->user->avatar_mini = bp_core_fetch_avatar(array('item_id' => $user_id, 'type' => 'thumb', 'alt' => sprintf(__('Avatar of %s', 'buddypress'), $this->invite->user->fullname), 'width' => 30, 'height' => 30));
     $this->invite->user->email = $this->invite->user->user_email;
     $this->invite->user->user_url = bp_core_get_user_domain($user_id, $this->invite->user->user_nicename, $this->invite->user->user_login);
     $this->invite->user->user_link = "<a href='{$this->invite->user->user_url}' title='{$this->invite->user->fullname}'>{$this->invite->user->fullname}</a>";
     $this->invite->user->last_active = bp_core_get_last_activity($this->invite->user->last_activity, __('active %s', 'buddypress'));
     if (bp_is_active('groups')) {
         $total_groups = BP_Groups_Member::total_group_count($user_id);
         $this->invite->user->total_groups = sprintf(_n('%d group', '%d groups', $total_groups, 'buddypress'), $total_groups);
     }
     if (bp_is_active('friends')) {
         $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id);
     }
     if (bp_is_active('friends')) {
         $this->invite->user->total_friends = BP_Friends_Friendship::total_friend_count($user_id);
     }
     $this->invite->user->total_blogs = null;
     $this->invite->group_id = $group_id;
     // Globaled in bp_group_has_invites()
     if (0 == $this->current_invite) {
         // loop has just started
         do_action('loop_start');
     }
 }
コード例 #16
0
function friends_remove_data($user_id)
{
    global $bp;
    do_action('friends_before_remove_data', $user_id);
    BP_Friends_Friendship::delete_all_for_user($user_id);
    // Remove usermeta
    bp_delete_user_meta($user_id, 'total_friend_count');
    // Remove friendship requests FROM user
    bp_core_delete_notifications_from_user($user_id, $bp->friends->id, 'friendship_request');
    do_action('friends_remove_data', $user_id);
}
コード例 #17
0
/**
 * Check if the User Can access Friends only privacy
 * @param type $component_type
 * @param type $component_id
 * @param type $user_id
 * @return type
 */
function mpp_check_friends_access($component_type, $component_id, $user_id = null)
{
    $allow = false;
    if (is_super_admin() || $component_id == $user_id || bp_is_active('friends') && 'is_friend' == BP_Friends_Friendship::check_is_friend($user_id, $component_id)) {
        $allow = true;
    }
    return apply_filters('mpp_check_friends_access', $allow, $component_type, $component_id, $user_id);
}
コード例 #18
0
ファイル: bp-default-data.php プロジェクト: vsalx/rattieinfo
function bpdd_import_users_friends()
{
    $users = bpdd_get_random_users_ids(50);
    for ($con = 0, $i = 0; $i < 100; $i++) {
        $user_one = $users[array_rand($users)];
        $user_two = $users[array_rand($users)];
        if (BP_Friends_Friendship::check_is_friend($user_one, $user_two) == 'not_friends') {
            // make them friends
            if (friends_add_friend($user_one, $user_two, true)) {
                $con++;
            }
        }
    }
    return $con;
}
コード例 #19
0
 function bp_displayed_user_is_friend()
 {
     global $bp;
     $friend_privacy_enable = get_option('tn_wpmu_friend_privacy_status');
     $friend_privacy_redirect = get_option('tn_wpmu_friend_privacy_redirect');
     if ($friend_privacy_enable == "enable") {
         if (bp_is_user_activity() || bp_is_user_profile() || bp_is_user()) {
             if ('is_friend' != BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $bp->displayed_user->id) && bp_loggedin_user_id() != bp_displayed_user_id()) {
                 if (!is_super_admin(bp_loggedin_user_id())) {
                     if ($friend_privacy_redirect == '') {
                         bp_core_redirect($bp->root_domain);
                     } else {
                         bp_core_redirect($friend_privacy_redirect);
                     }
                 }
             }
         }
     }
     //enable
 }
コード例 #20
0
 /**
  * @group BP6247
  */
 public function test_save_method_should_update_existing_row()
 {
     $u1 = $this->factory->user->create();
     $u2 = $this->factory->user->create();
     $friendship = new BP_Friends_Friendship();
     $friendship->initiator_user_id = $u1;
     $friendship->friend_user_id = $u2;
     $friendship->is_confirmed = 0;
     $friendship->is_limited = 0;
     $friendship->date_created = bp_core_current_time();
     $friendship->is_confirmed = 1;
     $friendship->save();
     $fid = $friendship->id;
     $f = new BP_Friends_Friendship($fid);
     $f->is_confirmed = 1;
     $f->save();
     $f2 = new BP_Friends_Friendship($fid);
     $this->assertEquals(1, $f2->is_confirmed);
 }
コード例 #21
0
ファイル: ajax.php プロジェクト: raminjan/logicalbones_hug
/**
 * Friend/un-friend a user via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_dtheme_ajax_addremove_friend()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if ('is_friend' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $_POST['fid'])) {
        check_ajax_referer('friends_remove_friend');
        if (!friends_remove_friend(bp_loggedin_user_id(), $_POST['fid'])) {
            echo __('Friendship could not be canceled.', 'logicalboneshug');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'logicalboneshug') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend') . '">' . __('Add Friend', 'logicalboneshug') . '</a>';
        }
    } elseif ('not_friends' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $_POST['fid'])) {
        check_ajax_referer('friends_add_friend');
        if (!friends_add_friend(bp_loggedin_user_id(), $_POST['fid'])) {
            echo __(' Friendship could not be requested.', 'logicalboneshug');
        } else {
            echo '<a id="friend-' . $_POST['fid'] . '" class="remove" rel="remove" title="' . __('Cancel Friendship Request', 'logicalboneshug') . '" 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', 'logicalboneshug') . '</a>';
        }
    } elseif ('pending' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), (int) $_POST['fid'])) {
        check_ajax_referer('friends_withdraw_friendship');
        if (friends_withdraw_friendship(bp_loggedin_user_id(), (int) $_POST['fid'])) {
            echo '<a id="friend-' . $_POST['fid'] . '" class="add" rel="add" title="' . __('Add Friend', 'logicalboneshug') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $_POST['fid'], 'friends_add_friend') . '">' . __('Add Friend', 'logicalboneshug') . '</a>';
        } else {
            echo __("Friendship request could not be cancelled.", 'logicalboneshug');
        }
    } else {
        echo __('Request Pending', 'logicalboneshug');
    }
    exit;
}
コード例 #22
0
 /**
  * Delete all friendships and friend notifications related to a user.
  *
  * @since 1.0.0
  *
  * @param int $user_id ID of the user being expunged.
  */
 public static function delete_all_for_user($user_id)
 {
     global $wpdb;
     $bp = buddypress();
     // Get all friendships, of any status, for the user.
     $friendships = self::get_friendships($user_id);
     $friend_ids = array();
     $friendship_ids = array();
     foreach ($friendships as $friendship) {
         $friendship_ids[] = $friendship->id;
         if ($friendship->is_confirmed) {
             $friend_ids[] = $friendship->friend_user_id == $user_id ? $friendship->initiator_user_id : $friendship->friend_user_id;
         }
     }
     // Delete the friendships from the database.
     if ($friendship_ids) {
         $friendship_ids_sql = implode(',', wp_parse_id_list($friendship_ids));
         $wpdb->query("DELETE FROM {$bp->friends->table_name} WHERE id IN ({$friendship_ids_sql})");
     }
     // Delete friend request notifications for members who have a
     // notification from this user.
     if (bp_is_active('notifications')) {
         $wpdb->query($wpdb->prepare("DELETE FROM {$bp->notifications->table_name} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id));
     }
     // Clean up the friendships cache.
     foreach ($friendship_ids as $friendship_id) {
         wp_cache_delete($friendship_id, 'bp_friends_friendships');
     }
     // Loop through friend_ids to scrub user caches and update total count metas.
     foreach ((array) $friend_ids as $friend_id) {
         // Delete cached friendships.
         wp_cache_delete($friend_id, 'bp_friends_friendships_for_user');
         BP_Friends_Friendship::total_friend_count($friend_id);
     }
     // Delete cached friendships.
     wp_cache_delete($user_id, 'bp_friends_friendships_for_user');
 }
コード例 #23
0
/**
 * Friend/un-friend a user via a POST request.
 *
 * @return string HTML
 * @since BuddyPress (1.2)
 */
function bp_legacy_theme_ajax_addremove_friend()
{
    // Bail if not a POST action
    if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    // Cast fid as an integer
    $friend_id = (int) $_POST['fid'];
    // Trying to cancel friendship
    if ('is_friend' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $friend_id)) {
        check_ajax_referer('friends_remove_friend');
        if (!friends_remove_friend(bp_loggedin_user_id(), $friend_id)) {
            echo __('Friendship could not be canceled.', 'buddypress');
        } else {
            echo '<a id="friend-' . esc_attr($friend_id) . '" class="add" rel="add" title="' . __('Add Friend', 'buddypress') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend') . '">' . __('Add Friend', 'buddypress') . '</a>';
        }
        // Trying to request friendship
    } elseif ('not_friends' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $friend_id)) {
        check_ajax_referer('friends_add_friend');
        if (!friends_add_friend(bp_loggedin_user_id(), $friend_id)) {
            echo __(' Friendship could not be requested.', 'buddypress');
        } else {
            echo '<a id="friend-' . esc_attr($friend_id) . '" class="remove" rel="remove" title="' . __('Cancel Friendship Request', 'buddypress') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $friend_id . '/', 'friends_withdraw_friendship') . '" class="requested">' . __('Cancel Friendship Request', 'buddypress') . '</a>';
        }
        // Trying to cancel pending request
    } elseif ('pending' == BP_Friends_Friendship::check_is_friend(bp_loggedin_user_id(), $friend_id)) {
        check_ajax_referer('friends_withdraw_friendship');
        if (friends_withdraw_friendship(bp_loggedin_user_id(), $friend_id)) {
            echo '<a id="friend-' . esc_attr($friend_id) . '" class="add" rel="add" title="' . __('Add Friend', 'buddypress') . '" href="' . wp_nonce_url(bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $friend_id, 'friends_add_friend') . '">' . __('Add Friend', 'buddypress') . '</a>';
        } else {
            echo __("Friendship request could not be cancelled.", 'buddypress');
        }
        // Request already pending
    } else {
        echo __('Request Pending', 'buddypress');
    }
    exit;
}
コード例 #24
0
function bp_friend_get_total_requests_count($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    return apply_filters('bp_friend_get_total_requests_count', count(BP_Friends_Friendship::get_friend_user_ids($user_id, true)));
}
コード例 #25
0
/**
 * Recalculate friend counts for each user.
 *
 * @since BuddyPress (2.0.0)
 *
 * @return array
 */
function bp_admin_repair_friend_count()
{
    global $wpdb;
    if (!bp_is_active('friends')) {
        return;
    }
    $statement = __('Counting the number of friends for each user&hellip; %s', 'buddypress');
    $result = __('Failed!', 'buddypress');
    $sql_delete = "DELETE FROM {$wpdb->usermeta} WHERE meta_key IN ( 'total_friend_count' );";
    if (is_wp_error($wpdb->query($sql_delete))) {
        return array(1, sprintf($statement, $result));
    }
    $bp = buddypress();
    // Walk through all users on the site
    $total_users = $wpdb->get_row("SELECT count(ID) as c FROM {$wpdb->users}")->c;
    $updated = array();
    if ($total_users > 0) {
        $per_query = 500;
        $offset = 0;
        while ($offset < $total_users) {
            // Only bother updating counts for users who actually have friendships
            $friendships = $wpdb->get_results($wpdb->prepare("SELECT initiator_user_id, friend_user_id FROM {$bp->friends->table_name} WHERE is_confirmed = 1 AND ( ( initiator_user_id > %d AND initiator_user_id <= %d ) OR ( friend_user_id > %d AND friend_user_id <= %d ) )", $offset, $offset + $per_query, $offset, $offset + $per_query));
            // The previous query will turn up duplicates, so we
            // filter them here
            foreach ($friendships as $friendship) {
                if (!isset($updated[$friendship->initiator_user_id])) {
                    BP_Friends_Friendship::total_friend_count($friendship->initiator_user_id);
                    $updated[$friendship->initiator_user_id] = 1;
                }
                if (!isset($updated[$friendship->friend_user_id])) {
                    BP_Friends_Friendship::total_friend_count($friendship->friend_user_id);
                    $updated[$friendship->friend_user_id] = 1;
                }
            }
            $offset += $per_query;
        }
    } else {
        return array(2, sprintf($statement, $result));
    }
    return array(0, sprintf($statement, __('Complete!', 'buddypress')));
}
コード例 #26
0
 /**
  * Populates extra fields such as group and friendship counts.
  */
 public function populate_extras()
 {
     if (bp_is_active('friends')) {
         $this->total_friends = BP_Friends_Friendship::total_friend_count($this->id);
     }
     if (bp_is_active('groups')) {
         $this->total_groups = BP_Groups_Member::total_group_count($this->id);
         $this->total_groups = sprintf(_n('%d group', '%d groups', $this->total_groups, 'buddypress'), $this->total_groups);
     }
 }
コード例 #27
0
/**
 * Remove all friends-related data concerning a given user.
 *
 * Removes the following:
 *
 * - Friendships of which the user is a member.
 * - Cached friend count for the user.
 * - Notifications of friendship requests sent by the user.
 *
 * @since 1.0.0
 *
 * @param int $user_id ID of the user whose friend data is being removed.
 */
function friends_remove_data($user_id)
{
    /**
     * Fires before deletion of friend-related data for a given user.
     *
     * @since 1.5.0
     *
     * @param int $user_id ID for the user whose friend data is being removed.
     */
    do_action('friends_before_remove_data', $user_id);
    BP_Friends_Friendship::delete_all_for_user($user_id);
    // Remove usermeta.
    bp_delete_user_meta($user_id, 'total_friend_count');
    /**
     * Fires after deletion of friend-related data for a given user.
     *
     * @since 1.0.0
     *
     * @param int $user_id ID for the user whose friend data is being removed.
     */
    do_action('friends_remove_data', $user_id);
}
コード例 #28
0
 /**
  * Delete all friendships and friend notifications related to a user.
  *
  * @param int $user_id ID of the user being expunged.
  */
 public static function delete_all_for_user($user_id)
 {
     global $wpdb;
     $bp = buddypress();
     // Get friends of $user_id
     $friend_ids = BP_Friends_Friendship::get_friend_user_ids($user_id);
     // Delete all friendships related to $user_id
     $wpdb->query($wpdb->prepare("DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id));
     // Delete friend request notifications for members who have a
     // notification from this user.
     if (bp_is_active('notifications')) {
         $wpdb->query($wpdb->prepare("DELETE FROM {$bp->notifications->table_name} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id));
     }
     // Loop through friend_ids and update their counts
     foreach ((array) $friend_ids as $friend_id) {
         BP_Friends_Friendship::total_friend_count($friend_id);
     }
 }
コード例 #29
0
/**
 * Return the total friendship request count for a given user.
 *
 * @param int $user_id ID of the user whose requests are being counted.
 *                     Default: ID of the logged-in user.
 * @return int Friend count.
 */
function bp_friend_get_total_requests_count($user_id = 0)
{
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    /**
     * Filters the total friendship request count for a given user.
     *
     * @since 1.2.0
     *
     * @param int $value Friendship request count.
     */
    return apply_filters('bp_friend_get_total_requests_count', count(BP_Friends_Friendship::get_friend_user_ids($user_id, true)));
}
コード例 #30
0
/**
 * Check if the current profile a user is on is a friend or not
 *
 * @since BuddyBoss 2.0
 */
function buddyboss_is_my_friend($id = null)
{
    global $bp;
    if ($id === null) {
        $id = $bp->displayed_user->id;
    }
    return 'is_friend' == BP_Friends_Friendship::check_is_friend($bp->loggedin_user->id, $id);
}