Exemplo n.º 1
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 ) ?>) <span><a href="<?php echo $bp->displayed_user->domain . $bp->friends->slug ?>"><?php _e('See All', 'buddypress') ?> &rarr;</a></span></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_user_domain( $friend_ids[$i] ) ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $friend_ids[$i], 'type' => 'thumb' ) ) ?></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
}
Exemplo n.º 2
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>';
         }
     }
 }
/**
 * Output a block of random friends.
 *
 * No longer used in BuddyPress.
 *
 * @todo Deprecate
 */
function bp_friends_random_friends()
{
    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());
    ?>
) <span><a href="<?php 
    echo trailingslashit(bp_displayed_user_domain() . bp_get_friends_slug());
    ?>
"><?php 
    _e('See All', 'buddypress');
    ?>
</a></span></h4>

		<?php 
    if ($friend_ids) {
        ?>

			<ul class="horiz-gallery">

			<?php 
        for ($i = 0, $count = count($friend_ids); $i < $count; ++$i) {
            ?>

				<li>
					<a href="<?php 
            echo bp_core_get_user_domain($friend_ids[$i]);
            ?>
"><?php 
            echo bp_core_fetch_avatar(array('item_id' => $friend_ids[$i], 'type' => 'thumb'));
            ?>
</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 
}
 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');
     }
 }
Exemplo n.º 5
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')));
}
 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);
     }
 }
Exemplo n.º 7
0
/**
 * Get a total friend count for a given user.
 *
 * @param int $user_id Optional. ID of the user whose friendships you are
 *        counting. Default: displayed user (if any), otherwise logged-in user.
 * @return int Friend count for the user.
 */
function friends_get_friend_count_for_user($user_id)
{
    return BP_Friends_Friendship::total_friend_count($user_id);
}
Exemplo n.º 8
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);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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');
 }
Exemplo n.º 11
0
	function populate_extras() {
		global $bp;

		if ( function_exists('friends_install') )
			$this->total_friends = BP_Friends_Friendship::total_friend_count( $this->id );

		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' );
			}
		}
	}
 /**
  * Sets up the invite to show.
  *
  * @since 1.1.0
  */
 public 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(__('Profile photo 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(__('Profile photo 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(__('Profile photo 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);
     }
     $this->invite->user->total_blogs = null;
     // Global'ed in bp_group_has_invites()
     $this->invite->group_id = $group_id;
     // loop has just started
     if (0 == $this->current_invite) {
         /**
          * Fires if the current invite item is the first in the loop.
          *
          * @since 1.1.0
          * @since 2.3.0 `$this` parameter added.
          * @since 2.7.0 Action renamed from `loop_start`.
          *
          * @param BP_Groups_Invite_Template $this Instance of the current Invites template.
          */
         do_action('group_invitation_loop_start', $this);
     }
 }