private static function record_activity($args = array())
 {
     // Default activity args
     $activity = array_merge(array('id' => null, 'user_id' => get_current_user_id(), 'type' => '', 'action' => '', 'item_id' => '', 'secondary_item_id' => '', 'content' => '', 'primary_link' => '', 'component' => 'dln-product-component', 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false), $args);
     // Add the activity
     return bp_activity_add($activity);
 }
Example #2
0
 /**
  * Create a single message
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function create_item($request)
 {
     if (!empty($request['id'])) {
         return new WP_Error('bp_json_message_exists', __('Cannot create existing message.', BP_API_PLUGIN_SLUG), array('status' => 400));
     }
     $message = $this->prepare_item_for_database($request);
     $message_id = messages_new_message(array('sender_id' => $message->sender_id ? $message->sender_id : bp_loggedin_user_id(), 'thread_id' => $message->thread_id, 'recipients' => $message->recipients, 'subject' => $message->subject, 'content' => $message->content, 'date_sent' => $message->date_sent ? $message->date_sent : bp_core_current_time()));
     if (!$message_id) {
         return new WP_Error('bp_json_message_create', __('Error creating new message.', BP_API_PLUGIN_SLUG), array('status' => 500));
     }
     $this->update_additional_fields_for_object($message, $request);
     /**
      * Fires after a message is created via the REST API
      *
      * @param object $message Data used to create message
      * @param WP_REST_Request $request Request object.
      * @param bool $bool A boolean that is false.
      */
     do_action('bp_json_insert_message', $message, $request, false);
     $response = $this->get_item(array('id' => $message_id, 'context' => 'view'));
     $response = rest_ensure_response($response);
     $response->set_status(201);
     $response->header('Location', rest_url('/users/' . $message_id));
     return $response;
 }
function friends_add_friend($initiator_userid, $friend_userid, $force_accept = false)
{
    global $bp;
    $friendship = new BP_Friends_Friendship();
    if ((int) $friendship->is_confirmed) {
        return true;
    }
    $friendship->initiator_user_id = $initiator_userid;
    $friendship->friend_user_id = $friend_userid;
    $friendship->is_confirmed = 0;
    $friendship->is_limited = 0;
    $friendship->date_created = bp_core_current_time();
    if ($force_accept) {
        $friendship->is_confirmed = 1;
    }
    if ($friendship->save()) {
        if (!$force_accept) {
            // Add the on screen notification
            bp_core_add_notification($friendship->initiator_user_id, $friendship->friend_user_id, $bp->friends->id, 'friendship_request');
            // Send the email notification
            friends_notification_new_request($friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
            do_action('friends_friendship_requested', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        } else {
            do_action('friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id);
        }
        return true;
    }
    return false;
}
 /**
  * Constructor.
  *
  * @param int $id Optional. ID of the message.
  */
 public function __construct($id = null)
 {
     $this->date_sent = bp_core_current_time();
     $this->sender_id = bp_loggedin_user_id();
     if (!empty($id)) {
         $this->populate($id);
     }
 }
/**
 * Record an activity item related to the Friends component.
 *
 * A wrapper for {@link bp_activity_add()} that provides some Friends-specific
 * defaults.
 *
 * @since 1.0.0
 *
 * @see bp_activity_add() for more detailed description of parameters and
 *      return values.
 *
 * @param array|string $args {
 *     An array of arguments for the new activity item. Accepts all parameters
 *     of {@link bp_activity_add()}. The one difference is the following
 *     argument, which has a different default here:
 *     @type string $component Default: the id of your Friends component
 *                             (usually 'friends').
 * }
 * @return bool See {@link bp_activity_add()}.
 */
function friends_record_activity($args = '')
{
    if (!bp_is_active('activity')) {
        return false;
    }
    $r = wp_parse_args($args, array('user_id' => bp_loggedin_user_id(), 'action' => '', 'content' => '', 'primary_link' => '', 'component' => buddypress()->friends->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false));
    return bp_activity_add($r);
}
Example #6
0
 /**
  *
  * @param int $post_id
  * @param int $post_author_id
  * @param int $user_id
  *
  * @return int|bool  notification id on success or false
  */
 function add_notification($post_id, $post_author_id, $user_id)
 {
     global $rtmedia;
     $args_add_noification = array('item_id' => $post_id, 'user_id' => $post_author_id, 'component_name' => $this->component_id, 'component_action' => $this->component_action . $post_id, 'secondary_item_id' => $user_id, 'date_notified' => bp_core_current_time());
     if (isset($rtmedia->options['buddypress_enableNotification']) && 0 !== intval($rtmedia->options['buddypress_enableNotification'])) {
         return bp_notifications_add_notification($args_add_noification);
     }
     return false;
 }
Example #7
0
 function create_object($args)
 {
     if (!isset($args['creator_id'])) {
         $args['creator_id'] = get_current_user_id();
     }
     $group_id = groups_create_group($args);
     groups_update_groupmeta($group_id, 'total_member_count', 1);
     groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
     return $this->get_object_by_id($group_id);
 }
 public static function EnrolledCourse($student_id, $course_id, $status)
 {
     global $wpdb;
     $group_id = get_post_meta($course_id, 'buddypress_id', true);
     // Get BuddyPress
     $bp = buddypress();
     $group = $wpdb->get_row($wpdb->prepare("SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $group_id));
     groups_invite_user(array('user_id' => $student_id, 'group_id' => $group_id, 'inviter_id' => $group->creator_id, 'date_modified' => bp_core_current_time(), 'is_confirmed' => 1));
     $forums = bbp_get_group_forum_ids($group_id);
     bbp_add_user_forum_subscription(bbp_get_current_user_id(), $forums[0]);
 }
Example #9
0
 /**
  * Populate necessary variables.
  *
  * @since 1.0.0
  * @access protected
  *
  * @param int $muted_id The ID of the user to be muted.
  * @param int $user_id The ID of the user initiating the mute request.
  */
 protected function populate($muted_id, $user_id)
 {
     $this->muted_id = (int) $muted_id;
     $this->user_id = (int) $user_id;
     $this->date_recorded = bp_core_current_time();
     global $bp, $wpdb;
     $id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$bp->mute->table_name} WHERE muted_id = %d AND user_id = %d", $this->muted_id, $this->user_id));
     if ($id) {
         $this->id = $id;
     }
 }
function groups_update_last_activity($group_id = 0)
{
    global $bp;
    if (empty($group_id)) {
        $group_id = $bp->groups->current_group->id;
    }
    if (empty($group_id)) {
        return false;
    }
    groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
}
function bp_course_add_notification($args = '')
{
    global $bp;
    if (!bp_is_active('notifications') || !function_exists('bp_notifications_add_notification')) {
        return;
    }
    $defaults = array('user_id' => $bp->loggedin_user->id, 'item_id' => false, 'secondary_item_id' => false, 'component_name' => 'course', 'component_action' => '', 'date_notified' => bp_core_current_time(), 'is_new' => 1);
    $r = wp_parse_args($args, $defaults);
    extract($r);
    return bp_notifications_add_notification(array('user_id' => $user_id, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'component_name' => $component_name, 'component_action' => $component_action, 'date_notified' => $date_notified, 'is_new' => $is_new));
}
function friends_record_activity($args = '')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    $defaults = array('user_id' => $bp->loggedin_user->id, 'action' => '', 'content' => '', 'primary_link' => '', 'component' => $bp->friends->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    return bp_activity_add(array('user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
function groups_left_group($group_id, $user_id = 0)
{
    global $bp;
    if (empty($user_id)) {
        $user_id = bp_loggedin_user_id();
    }
    // Record this in activity streams
    groups_record_activity(array('type' => 'left_group', 'item_id' => $group_id, 'user_id' => $user_id));
    // Modify group meta
    groups_update_groupmeta($group_id, 'last_activity', bp_core_current_time());
    return true;
}
 /**
  * @group add
  */
 public function test_add()
 {
     $time = bp_core_current_time();
     $args = array('domain' => 'foo', 'path' => 'bar', 'title' => 'Foo bar', 'user_login' => 'user1', 'user_email' => '*****@*****.**', 'registered' => $time, 'activation_key' => '12345', 'meta' => array('field_1' => 'Foo Bar', 'meta1' => 'meta2'));
     $signup = BP_Signup::add($args);
     $this->assertNotEmpty($signup);
     $s = new BP_Signup($signup);
     // spot check
     $this->assertSame($signup, $s->id);
     $this->assertSame('user1', $s->user_login);
     $this->assertSame('12345', $s->activation_key);
 }
function bp_media_record_activity($args = '')
{
    global $bp;
    if (!function_exists('bp_activity_add')) {
        return false;
    }
    $defaults = array('id' => false, 'action' => '', 'content' => '', 'component' => BP_MEDIA_SLUG, 'type' => false, 'primary_link' => '', 'user_id' => $bp->loggedin_user->id, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false);
    add_filter('bp_activity_allowed_tags', 'bp_media_override_allowed_tags');
    $r = wp_parse_args($args, $defaults);
    extract($r);
    $activity_id = bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
    return $activity_id;
}
Example #16
0
 /**
  * @group bp_xprofile_updated_profile_activity
  */
 public function test_bp_xprofile_updated_profile_activity_outside_of_throttle()
 {
     $d = $this->setup_updated_profile_data();
     $time = strtotime(bp_core_current_time());
     $prev_time = date('Y-m-d H:i:s', $time - 121 * 60);
     $now_time = date('Y-m-d H:i:s', $time);
     $this->factory->activity->create(array('user_id' => $d['u'], 'component' => buddypress()->profile->id, 'type' => 'updated_profile', 'recorded_time' => $prev_time));
     // Fake new/old values to ensure a change
     $old_values = array($this->updated_profile_data['f'] => array('value' => 'foo', 'visibility' => 'public'));
     $new_values = array($this->updated_profile_data['f'] => array('value' => 'foo2', 'visibility' => 'public'));
     $this->assertTrue(bp_xprofile_updated_profile_activity($d['u'], array($d['f']), false, $old_values, $new_values));
     $existing = bp_activity_get(array('max' => 1, 'filter' => array('user_id' => $d['u'], 'object' => buddypress()->profile->id, 'action' => 'updated_profile'), 'count_total' => 'count_query'));
     $this->assertEquals(1, $existing['total']);
 }
 public static function addUserFromCourseToGroup($courseId, $groupId)
 {
     global $wpdb;
     if (get_current_user_id() != 30) {
         return;
     }
     $bp = buddypress();
     $group = $wpdb->get_row($wpdb->prepare("SELECT g.* FROM {$bp->groups->table_name} g WHERE g.id = %d", $groupId));
     $userIdList = $wpdb->get_results($wpdb->prepare("SELECT user_id FROM `wp_namaste_student_courses` WHERE course_id=%d", $courseId));
     foreach ($userIdList as $userId) {
         groups_invite_user(array('user_id' => $userId->user_id, 'group_id' => $groupId, 'inviter_id' => $group->creator_id, 'date_modified' => bp_core_current_time(), 'is_confirmed' => 1));
         $forums = bbp_get_group_forum_ids($groupId);
         bbp_add_user_forum_subscription($userId, $forums[0]);
     }
 }
/**
 * Add a notification for a specific user, from a specific component
 *
 * @deprecated Deprecated since BuddyPress 1.9.0. Use
 *  bp_notifications_add_notification() instead.
 *
 * @since BuddyPress (1.0)
 * @param string $item_id
 * @param int $user_id
 * @param string $component_name
 * @param string $component_action
 * @param string $secondary_item_id
 * @param string $date_notified
 * @param int $is_new
 * @return boolean True on success, false on fail
 */
function bp_core_add_notification($item_id, $user_id, $component_name, $component_action, $secondary_item_id = 0, $date_notified = false, $is_new = 1)
{
    // Bail if notifications is not active
    if (!bp_is_active('notifications')) {
        return false;
    }
    // Trigger the deprecated function notice
    _deprecated_function(__FUNCTION__, '1.9', 'bp_notifications_add_notification()');
    // Notifications must always have a time
    if (false === $date_notified) {
        $date_notified = bp_core_current_time();
    }
    // Add the notification
    return bp_notifications_add_notification(array('item_id' => $item_id, 'user_id' => $user_id, 'component_name' => $component_name, 'component_action' => $component_action, 'secondary_item_id' => $secondary_item_id, 'date_notified' => $date_notified, 'is_new' => $is_new));
}
/**
 * Create a new friendship.
 *
 * @since 1.0.0
 *
 * @param int  $initiator_userid ID of the "initiator" user (the user who is
 *                               sending the friendship request).
 * @param int  $friend_userid    ID of the "friend" user (the user whose friendship
 *                               is being requested).
 * @param bool $force_accept     Optional. Whether to force acceptance. When false,
 *                               running friends_add_friend() will result in a friendship request.
 *                               When true, running friends_add_friend() will result in an accepted
 *                               friendship, with no notifications being sent. Default: false.
 * @return bool True on success, false on failure.
 */
function friends_add_friend($initiator_userid, $friend_userid, $force_accept = false)
{
    // You cannot be friends with yourself!
    if ($initiator_userid == $friend_userid) {
        return false;
    }
    // Check if already friends, and bail if so.
    if (friends_check_friendship($initiator_userid, $friend_userid)) {
        return true;
    }
    // Setup the friendship data.
    $friendship = new BP_Friends_Friendship();
    $friendship->initiator_user_id = $initiator_userid;
    $friendship->friend_user_id = $friend_userid;
    $friendship->is_confirmed = 0;
    $friendship->is_limited = 0;
    $friendship->date_created = bp_core_current_time();
    if (!empty($force_accept)) {
        $friendship->is_confirmed = 1;
    }
    // Bail if friendship could not be saved (how sad!).
    if (!$friendship->save()) {
        return false;
    }
    // Send notifications.
    if (empty($force_accept)) {
        $action = 'requested';
        // Update friend totals.
    } else {
        $action = 'accepted';
        friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id, 'add');
    }
    /**
     * Fires at the end of initiating a new friendship connection.
     *
     * This is a variable hook, depending on context.
     * The two potential hooks are: friends_friendship_requested, friends_friendship_accepted.
     *
     * @since 1.0.0
     *
     * @param int    $id                ID of the pending friendship connection.
     * @param int    $initiator_user_id ID of the friendship initiator.
     * @param int    $friend_user_id    ID of the friend user.
     * @param object $friendship        BuddyPress Friendship Object.
     */
    do_action('friends_friendship_' . $action, $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship);
    return true;
}
Example #20
0
function _likebtn_bp_notifications_add_notification($entity_name, $entity_id, $voter_id, $action)
{
    if (!in_array($action, array('like', 'dislike'))) {
        $action = 'like';
    }
    // No notifications from Anonymous
    if (!$voter_id) {
        return false;
    }
    $author_id = _likebtn_get_author_id($entity_name, $entity_id);
    if (!$author_id || $author_id == $voter_id) {
        return false;
    }
    bp_notifications_add_notification(array('user_id' => $author_id, 'item_id' => $entity_id, 'secondary_item_id' => $voter_id, 'component_name' => LIKEBTN_BP_COMPONENT_NAME, 'component_action' => 'likebtn_' . $entity_name . '_' . $action, 'date_notified' => bp_core_current_time(), 'is_new' => 1));
    // bp_notifications_add_meta($notification_id, 'entity_name', $entity_name, true)
}
Example #21
0
/**
 * Builds the argument of the reshared activity
 *
 * @package BP Reshare
 * @since    1.0
 * 
 * @param  integer $activity_id the activity id
 * @uses   bp_activity_get_specific() to fetch the specific activity
 * @uses   bp_activity_get_meta() to get some meta infos about the activity
 * @uses   bp_loggedin_user_id() to get current user id
 * @uses   bp_activity_update_meta() to save some meta infos for the activity
 * @uses   bp_core_fetch_avatar() to build the avatar for the user
 * @uses   bp_core_get_userlink() to build the user link
 * @uses   bp_core_current_time() to date the reshare
 * @uses   apply_filters() at various places to let plugins/themes override values
 * @return array the reshared activity arguments
 */
function buddyreshare_prepare_reshare($activity_id = 0)
{
    $activity_to_reshare = bp_activity_get_specific(array('activity_ids' => $activity_id));
    if (empty($activity_to_reshare)) {
        return array('error' => __('OOps, looks like the activity does not exist anymore', 'bp-reshare'));
    }
    $activity = $activity_to_reshare['activities'][0];
    $reshared_by = bp_activity_get_meta($activity_id, 'reshared_by');
    if (is_array($reshared_by) && in_array(bp_loggedin_user_id(), $reshared_by)) {
        return array('error' => __('OOps, looks like you already reshared this activity', 'bp-reshare'));
    }
    if ($activity->user_id == bp_loggedin_user_id()) {
        return array('error' => __('OOps, looks like you are trying to reshare your own activity', 'bp-reshare'));
    }
    /* get and increment reshared count */
    $rs_count = bp_activity_get_meta($activity_id, 'reshared_count');
    $rs_count = !empty($rs_count) ? (int) $rs_count + 1 : 1;
    bp_activity_update_meta($activity_id, 'reshared_count', $rs_count);
    if (is_array($reshared_by) && !in_array(bp_loggedin_user_id(), $reshared_by)) {
        $reshared_by[] = bp_loggedin_user_id();
    } else {
        $reshared_by[] = bp_loggedin_user_id();
    }
    bp_activity_update_meta($activity_id, 'reshared_by', $reshared_by);
    $secondary_avatar = bp_core_fetch_avatar(array('item_id' => $activity->user_id, 'object' => 'user', 'type' => 'thumb', 'class' => 'avatar', 'width' => 20, 'height' => 20));
    $component = $activity->component;
    $item_id = $activity->item_id;
    if ($component != 'activity') {
        $user_link = bp_core_get_userlink($activity->user_id);
        if (strpos($activity->primary_link, $user_link) === false) {
            $action = apply_filters('buddyreshare_prepare_reshare_content', sprintf(__('%s reshared a <a href="%s">content</a> originally shared by %s', 'bp-reshare'), bp_core_get_userlink(bp_loggedin_user_id()), $activity->primary_link, bp_core_get_userlink($activity->user_id)), $activity);
        } else {
            $action = apply_filters('buddyreshare_prepare_reshare_nocontent', sprintf(__('%s reshared some content originally shared by %s', 'bp-reshare'), bp_core_get_userlink(bp_loggedin_user_id()), bp_core_get_userlink($activity->user_id)), $activity);
        }
    } else {
        $action = apply_filters('buddyreshare_prepare_reshare_activity', sprintf(__('%s reshared an activity originally shared by %s', 'bp-reshare'), bp_core_get_userlink(bp_loggedin_user_id()), $secondary_avatar . bp_core_get_userlink($activity->user_id)), $activity);
    }
    $reshared_args = array('action' => apply_filters('bp_reshare_action_parent_activity', $action, $activity->type), 'content' => $activity->content, 'component' => $component, 'type' => 'reshare_update', 'user_id' => bp_loggedin_user_id(), 'secondary_item_id' => $activity_id, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => $activity->hide_sitewide);
    if (!empty($item_id)) {
        $reshared_args['item_id'] = $item_id;
    }
    return apply_filters('buddyreshare_prepare_reshare', $reshared_args, $activity_id);
}
Example #22
0
 /**
  * @group bp_xprofile_update_meta_cache
  * @group bp_has_profile
  */
 public function test_bp_has_profile_meta_cache_update_meta_cache_false()
 {
     $u = $this->factory->user->create();
     $g = $this->factory->xprofile_group->create();
     $f = $this->factory->xprofile_field->create(array('field_group_id' => $g));
     $d = new BP_XProfile_ProfileData($f, $u);
     $d->user_id = $u;
     $d->field_id = $f;
     $d->value = 'foo';
     $d->last_updated = bp_core_current_time();
     $d->save();
     bp_xprofile_add_meta($g, 'group', 'group_foo', 'group_bar');
     bp_xprofile_add_meta($f, 'field', 'field_foo', 'field_bar');
     bp_xprofile_add_meta($d->id, 'data', 'data_foo', 'data_bar');
     // prime cache
     bp_has_profile(array('user_id' => $u, 'profile_group_id' => $g, 'update_meta_cache' => false));
     $this->assertFalse(wp_cache_get($g, 'xprofile_group_meta'));
     $this->assertFalse(wp_cache_get($f, 'xprofile_field_meta'));
     $this->assertFalse(wp_cache_get($d->id, 'xprofile_data_meta'));
 }
/**
 * Add a notification for a specific user, from a specific component
 *
 * @since BuddyPress (1.0)
 * @param string $item_id
 * @param int $user_id
 * @param string $component_name
 * @param string $component_action
 * @param string $secondary_item_id
 * @param string $date_notified
 * @return boolean True on success, false on fail
 */
function bp_core_add_notification($item_id, $user_id, $component_name, $component_action, $secondary_item_id = 0, $date_notified = false)
{
    if (empty($date_notified)) {
        $date_notified = bp_core_current_time();
    }
    $notification = new BP_Core_Notification();
    $notification->item_id = $item_id;
    $notification->user_id = $user_id;
    $notification->component_name = $component_name;
    $notification->component_action = $component_action;
    $notification->date_notified = $date_notified;
    $notification->is_new = 1;
    if (!empty($secondary_item_id)) {
        $notification->secondary_item_id = $secondary_item_id;
    }
    if ($notification->save()) {
        return true;
    }
    return false;
}
Example #24
0
function bp_core_add_notification( $item_id, $user_id, $component_name, $component_action, $secondary_item_id = false, $date_notified = false ) {
	global $bp;

	if ( !$date_notified )
		$date_notified = bp_core_current_time();

	$notification = new BP_Core_Notification;
	$notification->item_id = $item_id;
	$notification->user_id = $user_id;
	$notification->component_name = $component_name;
	$notification->component_action = $component_action;
	$notification->date_notified = $date_notified;
	$notification->is_new = 1;

	if ( $secondary_item_id )
		$notification->secondary_item_id = $secondary_item_id;

	if ( !$notification->save() )
		return false;

	return true;
}
Example #25
0
 /**
  * @group bp_groups_update_meta_cache
  */
 public function test_bp_groups_update_meta_cache()
 {
     $g1 = $this->factory->group->create();
     $g2 = $this->factory->group->create();
     $time = bp_core_current_time();
     // Set up some data
     groups_update_groupmeta($g1, 'total_member_count', 4);
     groups_update_groupmeta($g1, 'last_activity', $time);
     groups_update_groupmeta($g1, 'foo', 'bar');
     groups_update_groupmeta($g2, 'total_member_count', 81);
     groups_update_groupmeta($g2, 'last_activity', $time);
     groups_update_groupmeta($g2, 'foo', 'baz');
     // Prime the cache for $g1
     groups_update_groupmeta($g1, 'foo', 'bar');
     groups_get_groupmeta($g1, 'foo');
     // Ensure an empty cache for $g2
     wp_cache_delete($g2, 'group_meta');
     bp_groups_update_meta_cache(array($g1, $g2));
     $expected = array($g1 => array('total_member_count' => array(4), 'last_activity' => array($time), 'foo' => array('bar')), $g2 => array('total_member_count' => array(81), 'last_activity' => array($time), 'foo' => array('baz')));
     $found = array($g1 => wp_cache_get($g1, 'group_meta'), $g2 => wp_cache_get($g2, 'group_meta'));
     $this->assertEquals($expected, $found);
 }
function bp_blogs_record_activity($args = '')
{
    global $bp;
    if (!bp_is_active('activity')) {
        return false;
    }
    $defaults = array('user_id' => bp_loggedin_user_id(), 'action' => '', 'content' => '', 'primary_link' => '', 'component' => $bp->blogs->id, 'type' => false, 'item_id' => false, 'secondary_item_id' => false, 'recorded_time' => bp_core_current_time(), 'hide_sitewide' => false);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Remove large images and replace them with just one image thumbnail
    if (bp_is_active('activity') && !empty($content)) {
        $content = bp_activity_thumbnail_content_images($content, $primary_link);
    }
    if (!empty($action)) {
        $action = apply_filters('bp_blogs_record_activity_action', $action);
    }
    if (!empty($content)) {
        $content = apply_filters('bp_blogs_record_activity_content', bp_create_excerpt($content), $content);
    }
    // Check for an existing entry and update if one exists.
    $id = bp_activity_get_activity_id(array('user_id' => $user_id, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id));
    return bp_activity_add(array('id' => $id, 'user_id' => $user_id, 'action' => $action, 'content' => $content, 'primary_link' => $primary_link, 'component' => $component, 'type' => $type, 'item_id' => $item_id, 'secondary_item_id' => $secondary_item_id, 'recorded_time' => $recorded_time, 'hide_sitewide' => $hide_sitewide));
}
/**
 * Start following a user's activity.
 *
 * @since 1.0.0
 *
 * @param array $args {
 *     Array of arguments.
 *     @type int $leader_id The user ID of the person we want to follow.
 *     @type int $follower_id The user ID initiating the follow request.
 * }
 * @return bool
 */
function bp_follow_start_following($args = '')
{
    global $bp;
    $r = wp_parse_args($args, array('leader_id' => bp_displayed_user_id(), 'follower_id' => bp_loggedin_user_id(), 'follow_type' => '', 'date_recorded' => bp_core_current_time()));
    $follow = new BP_Follow($r['leader_id'], $r['follower_id'], $r['follow_type']);
    // existing follow already exists
    if (!empty($follow->id)) {
        return false;
    }
    // add other properties before save
    $follow->date_recorded = $r['date_recorded'];
    // save!
    if (!$follow->save()) {
        return false;
    }
    // hooks!
    if (empty($r['follow_type'])) {
        do_action_ref_array('bp_follow_start_following', array(&$follow));
    } else {
        do_action_ref_array('bp_follow_start_following_' . $r['follow_type'], array(&$follow));
    }
    return true;
}
/**
 * Add a notification for a specific user, from a specific component.
 *
 * @since BuddyPress (1.9.0)
 *
 * @param array $args {
 *     Array of arguments describing the notification. All are optional.
 *     @type int $user_id ID of the user to associate the notification with.
 *     @type int $item_id ID of the item to associate the notification with.
 *     @type int $secondary_item_id ID of the secondary item to associate the
 *           notification with.
 *     @type string $component_name Name of the component to associate the
 *           notification with.
 *     @type string $component_action Name of the action to associate the
 *           notification with.
 *     @type string $date_notified Timestamp for the notification.
 * }
 * @return int|bool ID of the newly created notification on success, false
 *         on failure.
 */
function bp_notifications_add_notification($args = array())
{
    $r = wp_parse_args($args, array('user_id' => 0, 'item_id' => 0, 'secondary_item_id' => 0, 'component_name' => '', 'component_action' => '', 'date_notified' => bp_core_current_time(), 'is_new' => 1, 'allow_duplicate' => false));
    // Check for existing duplicate notifications
    if (!$r['allow_duplicate']) {
        // date_notified, allow_duplicate don't count toward
        // duplicate status
        $existing = BP_Notifications_Notification::get(array('user_id' => $r['user_id'], 'item_id' => $r['item_id'], 'secondary_item_id' => $r['secondary_item_id'], 'component_name' => $r['component_name'], 'component_action' => $r['component_action'], 'is_new' => $r['is_new']));
        if (!empty($existing)) {
            return false;
        }
    }
    // Setup the new notification
    $notification = new BP_Notifications_Notification();
    $notification->user_id = $r['user_id'];
    $notification->item_id = $r['item_id'];
    $notification->secondary_item_id = $r['secondary_item_id'];
    $notification->component_name = $r['component_name'];
    $notification->component_action = $r['component_action'];
    $notification->date_notified = $r['date_notified'];
    $notification->is_new = $r['is_new'];
    // Save the new notification
    return $notification->save();
}
Example #29
0
/**
 * Create a new friendship.
 *
 * @param int $initiator_userid ID of the "initiator" user (the user who is
 *        sending the friendship request).
 * @param int $friend_userid ID of the "friend" user (the user whose friendship
 *        is being requested).
 * @param bool $force_accept Optional. Whether to force acceptance. When false,
 *        running friends_add_friend() will result in a friendship request.
 *        When true, running friends_add_friend() will result in an accepted
 *        friendship, with no notifications being sent. Default: false.
 * @return bool True on success, false on failure.
 */
function friends_add_friend($initiator_userid, $friend_userid, $force_accept = false)
{
    // You cannot be friends with yourself!
    if ($initiator_userid == $friend_userid) {
        return false;
    }
    // Check if already friends, and bail if so
    if (friends_check_friendship($initiator_userid, $friend_userid)) {
        return true;
    }
    // Setup the friendship data
    $friendship = new BP_Friends_Friendship();
    $friendship->initiator_user_id = $initiator_userid;
    $friendship->friend_user_id = $friend_userid;
    $friendship->is_confirmed = 0;
    $friendship->is_limited = 0;
    $friendship->date_created = bp_core_current_time();
    if (!empty($force_accept)) {
        $friendship->is_confirmed = 1;
    }
    // Bail if friendship could not be saved (how sad!)
    if (!$friendship->save()) {
        return false;
    }
    // Send notifications
    if (empty($force_accept)) {
        $action = 'friends_friendship_requested';
        // Update friend totals
    } else {
        $action = 'friends_friendship_accepted';
        friends_update_friend_totals($friendship->initiator_user_id, $friendship->friend_user_id, 'add');
    }
    // Call the above titled action and pass friendship data into it
    do_action($action, $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship);
    return true;
}
Example #30
-1
/**
 * When a Notepad is edited, record the fact to the activity stream
 *
 * @since 1.0
 * @param int $post_id
 * @param object $post
 * @return int The id of the activity item posted
 */
function participad_notepad_record_notepad_activity($post_id, $post)
{
    global $bp;
    // Run only for participad_notebook post type
    if (empty($post->post_type) || participad_notepad_post_type_name() != $post->post_type) {
        return;
    }
    // Throttle activity updates: No duplicate posts (same user, same
    // notepad) within 60 minutes
    $already_args = array('max' => 1, 'sort' => 'DESC', 'show_hidden' => 1, 'filter' => array('user_id' => get_current_user_id(), 'action' => 'participad_notepad_edited', 'secondary_id' => $post_id));
    $already_activity = bp_activity_get($already_args);
    // If any activity items are found, compare its date_recorded with time() to
    // see if it's within the allotted throttle time. If so, don't record the
    // activity item
    if (!empty($already_activity['activities'])) {
        $date_recorded = $already_activity['activities'][0]->date_recorded;
        $drunix = strtotime($date_recorded);
        if (time() - $drunix <= apply_filters('participad_notepad_edit_activity_throttle_time', 60 * 60)) {
            return;
        }
    }
    $post_permalink = get_permalink($post_id);
    $action = sprintf(__('%1$s edited a notepad %2$s on the site %3$s', 'participad'), bp_core_get_userlink(get_current_user_id()), '<a href="' . $post_permalink . '">' . esc_html($post->post_title) . '</a>', '<a href="' . get_option('siteurl') . '">' . get_option('blogname') . '</a>');
    $activity_id = bp_activity_add(array('user_id' => get_current_user_id(), 'component' => bp_is_active('blogs') ? $bp->blogs->id : 'blogs', 'action' => $action, 'primary_link' => $post_permalink, 'type' => 'participad_notepad_edited', 'item_id' => get_current_blog_id(), 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_modified_gmt, 'hide_sitewide' => get_option('blog_public') <= 0));
    if (function_exists('bp_blogs_update_blogmeta')) {
        bp_blogs_update_blogmeta(get_current_blog_id(), 'last_activity', bp_core_current_time());
    }
    return $activity_id;
}