/** * bp_like_post_to_stream() * * Posts to stream, depending on settings * * TODO, Should we be posted that people like comments to the feed? This can get messy.. * Also no point having 20 posts saying people liked the same status.. * */ function bp_like_post_to_stream($item_id, $user_id) { if (bp_like_get_settings('post_to_activity_stream') == 1) { $activity = bp_activity_get_specific(array('activity_ids' => $item_id, 'component' => 'buddypress-like')); $author_id = $activity['activities'][0]->user_id; if ($user_id == $author_id) { $action = bp_like_get_text('record_activity_likes_own'); } elseif ($user_id == 0) { $action = bp_like_get_text('record_activity_likes_an'); } else { $action = bp_like_get_text('record_activity_likes_users'); } $liker = bp_core_get_userlink($user_id); $author = bp_core_get_userlink($author_id); $activity_url = bp_activity_get_permalink($item_id); $content = ''; //content must be defined... /* Grab the content and make it into an excerpt of 140 chars if we're allowed */ if (bp_like_get_settings('show_excerpt') == 1) { $content = $activity['activities'][0]->content; if (strlen($content) > bp_like_get_settings('excerpt_length')) { $content = substr($content, 0, bp_like_get_settings('excerpt_length')); $content = strip_tags($content); $content = $content . '...'; } } /* Filter out the placeholders */ $action = str_replace('%user%', $liker, $action); $action = str_replace('%permalink%', $activity_url, $action); $action = str_replace('%author%', $author, $action); bp_activity_add(array('action' => $action, 'content' => $content, 'primary_link' => $activity_url, 'component' => 'bp-like', 'type' => 'activity_liked', 'user_id' => $user_id, 'item_id' => $item_id)); } }
/** * Catches an activity to delete if js is enabled * * @package BP Reshare * @since 1.0 * * @uses check_ajax_referer() for security reasons * @uses bp_activity_get_specific() to fetch the activity to delete * @uses buddyreshare_reset_metas() to reset some metas for the parent activity * @uses bp_activity_delete() to delete the reshare */ function buddyreshare_ajax_delete_reshare() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } check_ajax_referer('buddyreshare_delete', 'nonce'); $response = array('result' => 'error', 'message' => __('OOps, error while trying to delete your reshare..', 'bp-reshare')); $reshare_id = intval($_POST['activity']); if (empty($reshare_id)) { $response['message'] = __('The reshare was not found.', 'bp-reshare'); exit(json_encode($response)); } $reshare_to_delete = bp_activity_get_specific(array('activity_ids' => $reshare_id)); if (empty($reshare_to_delete)) { $response['message'] = __('The reshare was not found.', 'bp-reshare'); exit(json_encode($response)); } $reshare = $reshare_to_delete['activities'][0]; $reset = buddyreshare_reset_metas($reshare->secondary_item_id, $reshare->user_id); if (empty($reset)) { $response['message'] = __('Unable to reset the properties of the reshared activity', 'bp-reshare'); exit(json_encode($response)); } $deleted_reshare = bp_activity_delete(array('type' => 'reshare_update', 'id' => $reshare_id)); if (!empty($deleted_reshare)) { do_action('buddyreshare_reshare_deleted', $reshare_id); $response['result'] = 'success'; $response['message'] = __('Reshare successfully deleted.', 'bp-reshare'); } else { do_action('buddyreshare_reshare_deleted_error', $reshare_id); } exit(json_encode($response)); }
/** * Catch and route requests for single activity item permalinks. * * @since 1.2.0 * * @uses bp_is_activity_component() * @uses bp_is_current_action() * @uses bp_action_variable() * @uses bp_activity_get_specific() * @uses bp_is_active() * @uses bp_core_get_user_domain() * @uses groups_get_group() * @uses bp_get_group_permalink() * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_redirect_url' hook. * @uses bp_core_redirect() * @uses bp_get_root_domain() * * @return bool False on failure. */ function bp_activity_action_permalink_router() { // Not viewing activity. if (!bp_is_activity_component() || !bp_is_current_action('p')) { return false; } // No activity to display. if (!bp_action_variable(0) || !is_numeric(bp_action_variable(0))) { return false; } // Get the activity details. $activity = bp_activity_get_specific(array('activity_ids' => bp_action_variable(0), 'show_hidden' => true)); // 404 if activity does not exist if (empty($activity['activities'][0])) { bp_do_404(); return; } else { $activity = $activity['activities'][0]; } // Do not redirect at default. $redirect = false; // Redirect based on the type of activity. if (bp_is_active('groups') && $activity->component == buddypress()->groups->id) { // Activity is a user update. if (!empty($activity->user_id)) { $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/'; // Activity is something else. } else { // Set redirect to group activity stream. if ($group = groups_get_group(array('group_id' => $activity->item_id))) { $redirect = bp_get_group_permalink($group) . bp_get_activity_slug() . '/' . $activity->id . '/'; } } // Set redirect to users' activity stream. } elseif (!empty($activity->user_id)) { $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/'; } // If set, add the original query string back onto the redirect URL. if (!empty($_SERVER['QUERY_STRING'])) { $query_frags = array(); wp_parse_str($_SERVER['QUERY_STRING'], $query_frags); $redirect = add_query_arg(urlencode_deep($query_frags), $redirect); } /** * Filter the intended redirect url before the redirect occurs for the single activity item. * * @since 1.2.2 * * @param array $value Array with url to redirect to and activity related to the redirect. */ if (!($redirect = apply_filters_ref_array('bp_activity_permalink_redirect_url', array($redirect, &$activity)))) { bp_core_redirect(bp_get_root_domain()); } // Redirect to the actual activity permalink page. bp_core_redirect($redirect); }
function bp_reshare_prepare_reshare($activity_id) { global $bp; $activity_to_reshare = bp_activity_get_specific('activity_ids=' . $activity_id); $activity = $activity_to_reshare['activities'][0]; /* 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); /* get an array of users that reshared the activity */ $reshared_by = bp_activity_get_meta($activity_id, 'reshared_by'); 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', 'alt' => $alt, 'class' => 'avatar', 'width' => 20, 'height' => 20)); $component = $activity->component; $item_id = $activity->item_id; if ($component != 'activity') { if ($activity->type == 'new_blog_post') { $action = sprintf(__('%s reshared a <a href="%s">blog post</a> originally posted by %s', 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $activity->primary_link, $secondary_avatar . bp_core_get_userlink($activity->user_id)); } else { if ($activity->type == 'new_blog_comment') { $action = sprintf(__('%s reshared a <a href="%s">comment</a> originally posted by %s', 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $activity->primary_link, $secondary_avatar . bp_core_get_userlink($activity->user_id)); } else { if ($component == 'groups') { $group = groups_get_group(array('group_id' => $item_id)); $group_link = '<a href="' . bp_get_group_permalink($group) . '">' . $group->name . '</a>'; if ($activity->type == 'new_forum_topic') { $action = sprintf(__('%s reshared a <a href="%s">forum topic</a> originally posted by %s in the group %s', 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $activity->primary_link, $secondary_avatar . bp_core_get_userlink($activity->user_id), $group_link); } else { if ($activity->type == 'new_forum_post') { $action = sprintf(__('%s reshared a <a href="%s">forum reply</a> originally posted by %s in the group %s', 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $activity->primary_link, $secondary_avatar . bp_core_get_userlink($activity->user_id), $group_link); } else { $action = sprintf(__("%s reshared an activity originally shared by %s in the group %s", 'bp-reshare'), bp_core_get_userlink($bp->loggedin_user->id), $secondary_avatar . bp_core_get_userlink($activity->user_id), $group_link); } } } } } } else { $action = 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)); } $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('bp_reshare_prepare_reshare', $reshared_args, $activity_id); }
/** * Allow core components and dependent plugins to register activity actions * * @since BuddyPress (1.2) * * @global object $bp BuddyPress global settings * @uses bp_is_activity_component() * @uses bp_is_current_action() * @uses bp_action_variable() * @uses bp_activity_get_specific() * @uses bp_is_active() * @uses bp_core_get_user_domain() * @uses groups_get_group() * @uses bp_get_group_permalink() * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_redirect_url' hook * @uses bp_core_redirect() * @uses bp_get_root_domain() * * @return bool False on failure */ function bp_activity_action_permalink_router() { global $bp; // Not viewing activity if (!bp_is_activity_component() || !bp_is_current_action('p')) { return false; } // No activity to display if (!bp_action_variable(0) || !is_numeric(bp_action_variable(0))) { return false; } // Get the activity details $activity = bp_activity_get_specific(array('activity_ids' => bp_action_variable(0), 'show_hidden' => true)); // 404 if activity does not exist if (empty($activity['activities'][0])) { bp_do_404(); return; } else { $activity = $activity['activities'][0]; } // Do not redirect at default $redirect = false; // Redirect based on the type of activity if (bp_is_active('groups') && $activity->component == $bp->groups->id) { // Activity is a user update if (!empty($activity->user_id)) { $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/'; // Activity is something else } else { // Set redirect to group activity stream if ($group = groups_get_group(array('group_id' => $activity->item_id))) { $redirect = bp_get_group_permalink($group) . bp_get_activity_slug() . '/' . $activity->id . '/'; } } // Set redirect to users' activity stream } else { $redirect = bp_core_get_user_domain($activity->user_id, $activity->user_nicename, $activity->user_login) . bp_get_activity_slug() . '/' . $activity->id . '/'; } // If set, add the original query string back onto the redirect URL if (!empty($_SERVER['QUERY_STRING'])) { $query_frags = array(); wp_parse_str($_SERVER['QUERY_STRING'], $query_frags); $redirect = add_query_arg(urlencode_deep($query_frags), $redirect); } // Allow redirect to be filtered if (!($redirect = apply_filters_ref_array('bp_activity_permalink_redirect_url', array($redirect, &$activity)))) { bp_core_redirect(bp_get_root_domain()); } // Redirect to the actual activity permalink page bp_core_redirect($redirect); }
function bp_reshare_ajax_delete_reshare() { check_ajax_referer('_reshare_delete', 'nonce'); $reshare_id = intval($_POST['activity']); $reshare_to_delete = bp_activity_get_specific('activity_ids=' . $reshare_id); $reshare = $reshare_to_delete['activities'][0]; bp_reshare_delete($reshare->secondary_item_id, $reshare->user_id); $deleted_reshare = bp_activity_delete(array('type' => 'reshare_update', 'id' => $reshare_id)); if ($deleted_reshare) { echo '1'; } else { _e('OOps, error while trying to delete your reshare..', 'bp-reshare'); } die; }
/** * let's delete reshare update if js is disabled */ function bp_reshare_delete_reshare() { if (!empty($_GET['delete_reshare']) && is_numeric($_GET['delete_reshare'])) { check_admin_referer('_reshare_delete'); $redirect = remove_query_arg(array('delete_reshare', '_wpnonce'), wp_get_referer()); $reshare_id = intval($_GET['delete_reshare']); $reshare_to_delete = bp_activity_get_specific('activity_ids=' . $reshare_id); $reshare = $reshare_to_delete['activities'][0]; bp_reshare_delete($reshare->secondary_item_id, $reshare->user_id); $deleted_reshare = bp_activity_delete(array('type' => 'reshare_update', 'id' => $reshare_id)); if (!empty($deleted_reshare)) { do_action('bp_reshare_handle_nojs_deleted', $reshare_id); bp_core_add_message(__('Reshare deleted !', 'bp-reshare')); bp_core_redirect($redirect); } else { do_action('bp_reshare_handle_nojs_missed', $reshare_id); bp_core_add_message(__('OOps, error while trying to reshare..', 'bp-reshare'), 'error'); bp_core_redirect($redirect); } } }
function bp_activity_get_user_favorites( $user_id ) { $my_favs = maybe_unserialize( get_user_meta( $user_id, 'bp_favorite_activities', true ) ); $existing_favs = bp_activity_get_specific( array( 'activity_ids' => $my_favs ) ); foreach( (array)$existing_favs['activities'] as $fav ) $new_favs[] = $fav->id; $new_favs = array_unique( (array)$new_favs ); update_user_meta( $user_id, 'bp_favorite_activities', $new_favs ); return apply_filters( 'bp_activity_get_user_favorites', $new_favs ); }
/** * Fetches full an activity's full, non-excerpted content via a POST request. * Used for the 'Read More' link on long activity items. * * @return string HTML * @since BuddyPress (1.5) */ function bp_dtheme_get_single_activity_content() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } $activity_array = bp_activity_get_specific(array('activity_ids' => $_POST['activity_id'], 'display_comments' => 'stream')); $activity = !empty($activity_array['activities'][0]) ? $activity_array['activities'][0] : false; if (empty($activity)) { exit; } // @todo: error? do_action_ref_array('bp_dtheme_get_single_activity_content', array(&$activity)); // Activity content retrieved through AJAX should run through normal filters, but not be truncated remove_filter('bp_get_activity_content_body', 'bp_activity_truncate_entry', 5); $content = apply_filters('bp_get_activity_content_body', $activity->content); exit($content); }
/** * When posting via email, we also update the last activity entries in BuddyPress. * * This is so your BuddyPress site doesn't look dormant when your members * are emailing each other back and forth! :) * * @param array $args Depending on the filter that this function is hooked into, contents will vary * @since 1.0-RC1 */ function bp_rbe_log_last_activity($args) { // get user id from activity entry if (!empty($args['user_id'])) { $user_id = $args['user_id']; } elseif (!empty($args['sender_id'])) { $user_id = $args['sender_id']; } else { $user_id = false; } // if no user ID, return now if (empty($user_id)) { return; } // update user's last activity bp_update_user_last_activity($user_id); // now update 'last_activity' group meta entry if applicable if (!empty($args['type'])) { switch ($args['type']) { case 'new_forum_topic': case 'new_forum_post': case 'bbp_topic_create': case 'bbp_reply_create': // sanity check! if (!bp_is_active('groups')) { return; } groups_update_last_activity($args['item_id']); break; // for group activity comments, we have to look up the parent activity to see // if the activity comment came from a group // for group activity comments, we have to look up the parent activity to see // if the activity comment came from a group case 'activity_comment': // we don't need to proceed if the groups component was disabled if (!bp_is_active('groups')) { return; } // sanity check! if (!bp_is_active('activity')) { return; } // grab the parent activity $activity = bp_activity_get_specific('activity_ids=' . $args['item_id']); if (!empty($activity['activities'][0])) { $parent_activity = $activity['activities'][0]; // if parent activity update is from the groups component, // that means the activity comment was in a group! // so update group 'last_activity' meta entry if ($parent_activity->component == 'groups') { groups_update_last_activity($parent_activity->item_id); } } break; } } }
/** * Check for an existing activity stream entry for a given post_id * * @param int $post_id ID of the topic or reply * @uses get_post_meta() * @uses bp_activity_get_specific() * @return int if an activity id is verified, false if not */ private static function get_activity_id($post_id = 0) { // Try to get the activity ID of the post $activity_id = (int) get_post_meta($post_id, '_bbp_activity_id', true); // Bail if no activity ID is in post meta if (empty($activity_id)) { return null; } // Get the activity stream item, bail if it doesn't exist $existing = bp_activity_get_specific(array('activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all')); if (empty($existing['total']) || 1 != $existing['total']) { return null; } // Return the activity ID since we've verified the connection return $activity_id; }
/** * Get the user id associated with a given activity item. * * Wraps bp_activity_get_specific(), with some additional logic for * avoiding duplicate queries. * * @since BuddyPress (1.6.0) * * @param int $activity_id Activity ID to retrieve User ID for. * * @return int User ID of the activity item in question. */ protected function get_activity_user_id($activity_id) { // If there is an existing activity/user ID mapping, just return the user ID. if (!empty($this->activity_user_id[$activity_id])) { return $this->activity_user_id[$activity_id]; /** * We don't have a mapping. This means the $activity_id is not on the current * page of results, so fetch its details from the database. */ } else { $activity = bp_activity_get_specific(array('activity_ids' => $activity_id, 'show_hidden' => true, 'spam' => 'all')); /** * If, somehow, the referenced activity has been deleted, leaving its associated * activities as orphans, use the logged in user's ID to avoid errors. */ if (empty($activity['activities'])) { return bp_loggedin_user_id(); } // Store the new activity/user ID mapping for any later re-use $this->activity_user_id[$activity['activities'][0]->id] = $activity['activities'][0]->user_id; // Return the user ID return $activity['activities'][0]->user_id; } }
/** * AJAX handler for Read More link on long activity items * * @package BuddyPress * @since 1.5 */ function bp_dtheme_get_single_activity_content() { $activity_array = bp_activity_get_specific(array('activity_ids' => $_POST['activity_id'], 'display_comments' => 'stream')); $activity = !empty($activity_array['activities'][0]) ? $activity_array['activities'][0] : false; if (!$activity) { exit; } // todo: error? // Activity content retrieved through AJAX should run through normal filters, but not be // truncated remove_filter('bp_get_activity_content_body', 'bp_activity_truncate_entry', 5); $content = apply_filters('bp_get_activity_content_body', $activity->content); echo $content; exit; }
function __construct($page, $per_page, $max, $include, $sort, $filter, $search_terms, $display_comments, $show_hidden, $exclude = false, $in = false) { global $bp; $this->pag_page = isset($_REQUEST['acpage']) ? intval($_REQUEST['acpage']) : $page; $this->pag_num = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : $per_page; // Check if blog/forum replies are disabled $this->disable_blogforum_replies = isset($bp->site_options['bp-disable-blogforum-comments']) ? $bp->site_options['bp-disable-blogforum-comments'] : false; // Get an array of the logged in user's favorite activities $this->my_favs = maybe_unserialize(bp_get_user_meta($bp->loggedin_user->id, 'bp_favorite_activities', true)); // Fetch specific activity items based on ID's if (!empty($include)) { $this->activities = bp_activity_get_specific(array('activity_ids' => explode(',', $include), 'max' => $max, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden)); } else { $this->activities = bp_activity_get(array('display_comments' => $display_comments, 'max' => $max, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'filter' => $filter, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in)); } if (!$max || $max >= (int) $this->activities['total']) { $this->total_activity_count = (int) $this->activities['total']; } else { $this->total_activity_count = (int) $max; } $this->activities = $this->activities['activities']; if ($max) { if ($max >= count($this->activities)) { $this->activity_count = count($this->activities); } else { $this->activity_count = (int) $max; } } else { $this->activity_count = count($this->activities); } $this->full_name = $bp->displayed_user->fullname; // Fetch parent content for activity comments so we do not have to query in the loop foreach ((array) $this->activities as $activity) { if ('activity_comment' != $activity->type) { continue; } $parent_ids[] = $activity->item_id; } if (!empty($parent_ids)) { $activity_parents = bp_activity_get_specific(array('activity_ids' => $parent_ids)); } if (!empty($activity_parents['activities'])) { foreach ($activity_parents['activities'] as $parent) { $this->activity_parents[$parent->id] = $parent; } unset($activity_parents); } if ((int) $this->total_activity_count && (int) $this->pag_num) { $this->pag_links = paginate_links(array('base' => add_query_arg('acpage', '%#%'), 'format' => '', 'total' => ceil((int) $this->total_activity_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('←', 'Activity pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Activity pagination next text', 'buddypress'), 'mid_size' => 1)); } }
/** * Fetches an activity's full, non-excerpted content via a POST request. * Used for the 'Read More' link on long activity items. * * @return string HTML * @since BuddyPress (1.5) */ function bp_legacy_theme_get_single_activity_content() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } $activity_array = bp_activity_get_specific(array('activity_ids' => $_POST['activity_id'], 'display_comments' => 'stream')); $activity = !empty($activity_array['activities'][0]) ? $activity_array['activities'][0] : false; if (empty($activity)) { exit; } // @todo: error? /** * Fires before the return of an activity's full, non-excerpted content via a POST request. * * @since BuddyPress (1.7.0) * * @param string $activity Activity content. Passed by reference. */ do_action_ref_array('bp_legacy_theme_get_single_activity_content', array(&$activity)); // Activity content retrieved through AJAX should run through normal filters, but not be truncated remove_filter('bp_get_activity_content_body', 'bp_activity_truncate_entry', 5); /** This filter is documented in bp-activity/bp-activity-template.php */ $content = apply_filters('bp_get_activity_content_body', $activity->content); exit($content); }
/** * bp_like_button() * * Outputs the 'Like/Unlike' and 'View likes/Hide likes' buttons. * */ function bp_like_button($id = '', $type = '') { $users_who_like = 0; $liked_count = 0; /* Set the type if not already set, and check whether we are outputting the button on a blogpost or not. */ if (!$type && !is_single()) { $type = 'activity'; } elseif (!$type && is_single()) { $type = 'blogpost'; } if ($type == 'activity') { $activity = bp_activity_get_specific(array('activity_ids' => bp_get_activity_id())); $activity_type = $activity['activities'][0]->type; if (is_user_logged_in() && $activity_type !== 'activity_liked') { if (bp_activity_get_meta(bp_get_activity_id(), 'liked_count', true)) { $users_who_like = array_keys(bp_activity_get_meta(bp_get_activity_id(), 'liked_count', true)); $liked_count = count($users_who_like); } if (!bp_like_is_liked(bp_get_activity_id(), 'activity')) { ?> <a href="#" class="like" id="like-activity-<?php bp_activity_id(); ?> " title="<?php echo bp_like_get_text('like_this_item'); ?> "><?php echo bp_like_get_text('like'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a> <?php } else { ?> <a href="#" class="unlike" id="unlike-activity-<?php bp_activity_id(); ?> " title="<?php echo bp_like_get_text('unlike_this_item'); ?> "><?php echo bp_like_get_text('unlike'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a> <?php } if ($users_who_like) { ?> <a href="#" class="view-likes" id="view-likes-<?php bp_activity_id(); ?> "><?php echo bp_like_get_text('view_likes'); ?> </a> <p class="users-who-like" id="users-who-like-<?php bp_activity_id(); ?> "></p> <?php } } } elseif ($type == 'blogpost') { global $post; if (!$id && is_single()) { $id = $post->ID; } if (is_user_logged_in() && get_post_meta($id, 'liked_count', true)) { $liked_count = count(get_post_meta($id, 'liked_count', true)); } if (!bp_like_is_liked($id, 'blogpost')) { ?> <div class="like-box"><a href="#" class="like_blogpost" id="like-blogpost-<?php echo $id; ?> " title="<?php echo bp_like_get_text('like_this_item'); ?> "><?php echo bp_like_get_text('like'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a></div> <?php } else { ?> <div class="like-box"><a href="#" class="unlike_blogpost" id="unlike-blogpost-<?php echo $id; ?> " title="<?php echo bp_like_get_text('unlike_this_item'); ?> "><?php echo bp_like_get_text('unlike'); if ($liked_count) { echo ' (' . $liked_count . ')'; } ?> </a></div> <?php } } }
/** * Reset the logged-in user's new mentions data when he visits his mentions screen * * @since BuddyPress (1.2) * * @global object $bp BuddyPress global settings * @uses bp_is_activity_component() * @uses bp_activity_get_specific() * @uses bp_current_action() * @uses bp_action_variables() * @uses bp_do_404() * @uses bp_is_active() * @uses groups_get_group() * @uses groups_is_user_member() * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_access' hook * @uses do_action() To call the 'bp_activity_screen_single_activity_permalink' hook * @uses bp_core_add_message() * @uses is_user_logged_in() * @uses bp_core_redirect() * @uses site_url() * @uses esc_url() * @uses bp_get_root_domain() * @uses bp_get_activity_root_slug() * @uses bp_core_load_template() * @uses apply_filters() To call the 'bp_activity_template_profile_activity_permalink' hook */ function bp_activity_screen_single_activity_permalink() { global $bp; // No displayed user or not viewing activity component if (!bp_is_activity_component()) { return false; } if (!bp_current_action() || !is_numeric(bp_current_action())) { return false; } // Get the activity details $activity = bp_activity_get_specific(array('activity_ids' => bp_current_action(), 'show_hidden' => true, 'spam' => 'ham_only')); // 404 if activity does not exist if (empty($activity['activities'][0]) || bp_action_variables()) { bp_do_404(); return; } else { $activity = $activity['activities'][0]; } // Default access is true $has_access = true; // If activity is from a group, do an extra cap check if (isset($bp->groups->id) && $activity->component == $bp->groups->id) { // Activity is from a group, but groups is currently disabled if (!bp_is_active('groups')) { bp_do_404(); return; } // Check to see if the group is not public, if so, check the // user has access to see this activity if ($group = groups_get_group(array('group_id' => $activity->item_id))) { // Group is not public if ('public' != $group->status) { // User is not a member of group if (!groups_is_user_member(bp_loggedin_user_id(), $group->id)) { $has_access = false; } } } } // Allow access to be filtered $has_access = apply_filters_ref_array('bp_activity_permalink_access', array($has_access, &$activity)); // Allow additional code execution do_action('bp_activity_screen_single_activity_permalink', $activity, $has_access); // Access is specifically disallowed if (false === $has_access) { // User feedback bp_core_add_message(__('You do not have access to this activity.', 'buddypress'), 'error'); // Redirect based on logged in status is_user_logged_in() ? bp_core_redirect(bp_loggedin_user_domain()) : bp_core_redirect(site_url('wp-login.php?redirect_to=' . esc_url(bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . bp_current_action() . '/'))); } bp_core_load_template(apply_filters('bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink')); }
/** * Catches a reshare to delete if js is disabled * * @package BP Reshare * @since 1.0 * * @uses bp_is_activity_component() are we in activity component * @uses bp_is_current_action() to check current action * @uses buddyreshare_get_component_slug() to get component slug * @uses bp_action_variable() to check the variables * @uses check_admin_referer() for security reasons * @uses bp_activity_get_specific() to fetch the activity to delete * @uses bp_do_404() to eventually send the user on a 404 * @uses bp_core_get_user_domain() to build user's url * @uses bp_get_activity_slug() to get activity slug * @uses buddyreshare_reset_metas() to reset some metas for the parent activity * @uses bp_core_add_message() to print a warning message * @uses bp_core_redirect() to safely redirect user * @uses bp_activity_delete() to delete the reshare */ function buddyreshare_remove_reshare() { // Not deleting a reshare if (!bp_is_activity_component() || !bp_is_current_action(buddyreshare_get_component_slug())) { return false; } // No reshare to delete if (!bp_action_variable(0) || bp_action_variable(0) != 'delete' || !bp_action_variable(1) || !is_numeric(bp_action_variable(1))) { return false; } $reshare_id = bp_action_variable(1); check_admin_referer('buddyreshare_delete'); // Get the activity details $activity = bp_activity_get_specific(array('activity_ids' => bp_action_variable(1), 'show_hidden' => true)); // 404 if activity does not exist if (empty($activity['activities'][0])) { bp_do_404(); return; } else { $reshare = $activity['activities'][0]; } // redirecting to user's profile $redirect = bp_core_get_user_domain($reshare->user_id, $reshare->user_nicename, $reshare->user_login) . bp_get_activity_slug() . '/'; $reset = buddyreshare_reset_metas($reshare->secondary_item_id, $reshare->user_id); if (empty($reset)) { bp_core_add_message(__('Unable to reset the properties of the reshared activity', 'bp-reshare'), 'error'); bp_core_redirect($redirect); } $deleted_reshare = bp_activity_delete(array('type' => 'reshare_update', 'id' => $reshare_id)); if (!empty($deleted_reshare)) { do_action('buddyreshare_reshare_deleted', $reshare_id); bp_core_add_message(__('Reshare deleted !', 'bp-reshare')); bp_core_redirect($redirect); } else { do_action('buddyreshare_reshare_deleted_error', $reshare_id); bp_core_add_message(__('OOps, error while trying to reshare..', 'bp-reshare'), 'error'); bp_core_redirect($redirect); } }
/** * Hook to insert the report user on BP blog post and activity * * @global type $l10n * @global type $post * @param type $id * @param type $type */ function wangguard_bp_report_button($id = '', $type = '') { if (!is_user_logged_in()) { return; } if (!$type && !is_single()) { $type = 'activity'; } elseif (!$type && is_single()) { $type = 'blogpost'; } if (function_exists("is_textdomain_loaded")) { if (!is_textdomain_loaded("wangguard")) { load_textdomain("wangguard", PLUGINDIR . "/wangguard/languages/wangguard-" . WPLANG . ".mo"); } } else { global $l10n; if (!isset($l10n['wangguard'])) { load_textdomain("wangguard", PLUGINDIR . " /wangguard/languages/wangguard-" . WPLANG . ".mo"); } } if ($type == 'activity') { $activity = bp_activity_get_specific(array('activity_ids' => bp_get_activity_id())); if (!empty($activity['activities'][0])) { $user_id = $activity['activities'][0]->user_id; $user_object = new WP_User($user_id); if (empty($user_object->ID)) { return; } if (!wangguard_is_admin($user_object)) { if (true || !bp_like_is_liked(bp_get_activity_id(), 'activity')) { ?> <a href="javascript:void(0)" class="button wangguard-user-report" rel="<?php echo $user_object->ID; ?> " title="<?php echo __('Report user', 'wangguard'); ?> "><?php echo __('Report user', 'wangguard'); ?> </a> <?php } } } } elseif ($type == 'blogpost') { global $post; if (empty($post->post_author)) { return; } $user_id = $post->post_author; $user_object = new WP_User($user_id); if (empty($user_object->ID)) { return; } if (!wangguard_is_admin($user_object)) { if (true || !bp_like_is_liked($id, 'blogpost')) { ?> <div class="activity-list"><div class="activity-meta"><a href="javascript:void(0)" class="button wangguard-user-report" rel="<?php echo $user_object->ID; ?> " title="<?php echo __('Report user', 'wangguard'); ?> "><?php echo __('Report user', 'wangguard'); ?> </a></div></div> <?php } } } }
/** * Displays the introduction for the group and loops through each item * * I've chosen to cache on an individual-activity basis, instead of a group-by-group basis. This * requires just a touch more overhead (in terms of looping through individual activity_ids), and * doesn't really have any added effect at the moment (since an activity item can only be associated * with a single group). But it provides the greatest amount of flexibility going forward, both in * terms of the possibility that activity items could be associated with more than one group, and * the possibility that users within a single group would want more highly-filtered digests. */ function ass_digest_format_item_group($group_id, $activity_ids, $type, $group_name, $group_slug, $user_id) { global $bp, $ass_email_css; $group_permalink = bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . $group_slug . '/'; $group_name_link = '<a href="' . $group_permalink . '" name="' . $group_slug . '">' . $group_name . '</a>'; $userdomain = bp_core_get_user_domain($user_id); $unsubscribe_link = "{$userdomain}?bpass-action=unsubscribe&group={$group_id}&access_key=" . md5("{$group_id}{$user_id}unsubscribe" . wp_salt()); // add the group title bar if ($type == 'dig') { $group_message = "\n<div {$ass_email_css['group_title']}>" . sprintf(__('Group: %s', 'bp-ass'), $group_name_link) . "</div>\n\n"; } elseif ($type == 'sum') { $group_message = "\n<div {$ass_email_css['group_title']}>" . sprintf(__('Group: %s weekly summary', 'bp-ass'), $group_name_link) . "</div>\n"; } // add change email settings link $group_message .= "\n<div {$ass_email_css['change_email']}>"; $group_message .= __('To disable these notifications for this group click ', 'bp-ass') . " <a href=\"{$unsubscribe_link}\">" . __('unsubscribe', 'bp-ass') . '</a> - '; $group_message .= __('change ', 'bp-ass') . "<a href=\"" . $group_permalink . "notifications/\">" . __('email options', 'bp-ass') . "</a> "; $group_message .= "</div>\n\n"; $group_message = apply_filters('ass_digest_group_message_title', $group_message, $group_id, $type); // Finally, add the markup to the digest foreach ($activity_ids as $activity_id) { // Cache is set earlier in ass_digest_fire() $activity_item = wp_cache_get('bp_activity_' . $activity_id, 'bp'); if (!$activity_item) { // Try fetching it manually $activity_items = bp_activity_get_specific(array('sort' => 'ASC', 'activity_ids' => array($activity_item), 'show_hidden' => true)); if (!empty($activity_items)) { $activity_item = $activity_items[0]; } } if (!empty($activity_item)) { $group_message .= ass_digest_format_item($activity_item, $type); } //$group_message .= '<pre>'. $item->id .'</pre>'; } return apply_filters('ass_digest_format_item_group', $group_message, $group_id, $type); }
/** * Load the page for a single activity item. * * @since 1.2.0 * * @uses bp_is_activity_component() * @uses bp_activity_get_specific() * @uses bp_current_action() * @uses bp_action_variables() * @uses bp_do_404() * @uses bp_is_active() * @uses groups_get_group() * @uses groups_is_user_member() * @uses apply_filters_ref_array() To call the 'bp_activity_permalink_access' hook. * @uses do_action() To call the 'bp_activity_screen_single_activity_permalink' hook. * @uses bp_core_add_message() * @uses is_user_logged_in() * @uses bp_core_redirect() * @uses site_url() * @uses esc_url() * @uses bp_get_root_domain() * @uses bp_get_activity_root_slug() * @uses bp_core_load_template() * @uses apply_filters() To call the 'bp_activity_template_profile_activity_permalink' hook. */ function bp_activity_screen_single_activity_permalink() { $bp = buddypress(); // No displayed user or not viewing activity component. if (!bp_is_activity_component()) { return false; } if (!bp_current_action() || !is_numeric(bp_current_action())) { return false; } // Get the activity details. $activity = bp_activity_get_specific(array('activity_ids' => bp_current_action(), 'show_hidden' => true, 'spam' => 'ham_only')); // 404 if activity does not exist if (empty($activity['activities'][0]) || bp_action_variables()) { bp_do_404(); return; } else { $activity = $activity['activities'][0]; } // Default access is true. $has_access = true; // If activity is from a group, do an extra cap check. if (isset($bp->groups->id) && $activity->component == $bp->groups->id) { // Activity is from a group, but groups is currently disabled. if (!bp_is_active('groups')) { bp_do_404(); return; } // Check to see if the group is not public, if so, check the // user has access to see this activity. if ($group = groups_get_group(array('group_id' => $activity->item_id))) { // Group is not public. if ('public' != $group->status) { // User is not a member of group. if (!groups_is_user_member(bp_loggedin_user_id(), $group->id)) { $has_access = false; } } } } /** * Filters the access permission for a single activity view. * * @since 1.2.0 * * @param array $access Array holding the current $has_access value and current activity item instance. */ $has_access = apply_filters_ref_array('bp_activity_permalink_access', array($has_access, &$activity)); /** * Fires before the loading of a single activity template file. * * @since 1.2.0 * * @param BP_Activity_Activity $activity Object representing the current activity item being displayed. * @param bool $has_access Whether or not the current user has access to view activity. */ do_action('bp_activity_screen_single_activity_permalink', $activity, $has_access); // Access is specifically disallowed. if (false === $has_access) { // User feedback. bp_core_add_message(__('You do not have access to this activity.', 'buddypress'), 'error'); // Redirect based on logged in status. if (is_user_logged_in()) { $url = bp_loggedin_user_domain(); } else { $url = sprintf(site_url('wp-login.php?redirect_to=%s'), urlencode(esc_url_raw(bp_activity_get_permalink((int) bp_current_action())))); } bp_core_redirect($url); } /** * Filters the template to load for a single activity screen. * * @since 1.0.0 * * @param string $template Path to the activity template to load. */ bp_core_load_template(apply_filters('bp_activity_template_profile_activity_permalink', 'members/single/activity/permalink')); }
function bp_reshare_check_for_parent_type($can_comment) { global $activities_template; if ($activities_template->disable_blogforum_replies == 0) { return $can_comment; } if ('reshare_update' != bp_get_activity_type()) { return $can_comment; } else { if (!(int) bp_get_option('bp-reshare-disable-blogforum-comments') || '' == bp_get_option('bp-reshare-disable-blogforum-comments')) { return $can_comment; } /* the activity is a reshare, Admin wants to disable comments for blogs and forums we now need to check for parent type */ $activity_first_id = bp_get_activity_secondary_item_id(); $parent_activity = bp_activity_get_specific('activity_ids=' . $activity_first_id); if (in_array($parent_activity['activities'][0]->type, array('new_blog_post', 'new_blog_comment', 'new_forum_topic', 'new_forum_post'))) { return false; } else { return $can_comment; } } }
function update_activity_after_thumb_set($id) { $model = new RTMediaModel(); $mediaObj = new RTMediaMedia(); $media = $model->get(array('id' => $id)); $privacy = $media[0]->privacy; $activity_id = rtmedia_activity_id($id); if (!empty($activity_id)) { $same_medias = $mediaObj->model->get(array('activity_id' => $activity_id)); $update_activity_media = array(); foreach ($same_medias as $a_media) { $update_activity_media[] = $a_media->id; } $objActivity = new RTMediaActivity($update_activity_media, $privacy, false); global $wpdb, $bp; $activity_old_content = bp_activity_get_meta($activity_id, "bp_old_activity_content"); $activity_text = bp_activity_get_meta($activity_id, "bp_activity_text"); if ($activity_old_content == "") { // get old activity content and save in activity meta $activity_get = bp_activity_get_specific(array('activity_ids' => $activity_id)); $activity = $activity_get['activities'][0]; $activity_body = $activity->content; bp_activity_update_meta($activity_id, "bp_old_activity_content", $activity_body); //extract activity text from old content $activity_text = strip_tags($activity_body, '<span>'); $activity_text = explode("</span>", $activity_text); $activity_text = strip_tags($activity_text[0]); bp_activity_update_meta($activity_id, "bp_activity_text", $activity_text); } $activity_text = bp_activity_get_meta($activity_id, "bp_activity_text"); $objActivity->activity_text = $activity_text; $wpdb->update($bp->activity->table_name, array("type" => "rtmedia_update", "content" => $objActivity->create_activity_html()), array("id" => $activity_id)); } }
function _likebtn_get_entity($entity_name, $entity_id) { if ($entity_name == LIKEBTN_ENTITY_COMMENT) { return get_comment($entity_id); } else { if (in_array($entity_name, array(LIKEBTN_ENTITY_BP_ACTIVITY_POST, LIKEBTN_ENTITY_BP_ACTIVITY_UPDATE, LIKEBTN_ENTITY_BP_ACTIVITY_COMMENT, LIKEBTN_ENTITY_BP_ACTIVITY_TOPIC))) { if (function_exists('bp_activity_get_specific')) { $activity_list = bp_activity_get_specific(array('activity_ids' => $entity_id, 'display_comments' => true)); if (!empty($activity_list['activities']) && !empty($activity_list['activities'][0])) { return $activity_list['activities'][0]; } } } else { if ($entity_name == LIKEBTN_ENTITY_BP_MEMBER) { return get_user_by('id', $entity_id); /*} else if ($entity_name == LIKEBTN_ENTITY_PRODUCT) { if (class_exists('WC_Product_Factory')) { $_pf = new WC_Product_Factory(); return $_pf->get_product($entity_id); }*/ } else { return get_post($entity_id); } } } return null; }
/** * Constructor method. * * The arguments passed to this class constructor are of the same * format as {@link BP_Activity_Activity::get()}. * * @since 1.5.0 * * @see BP_Activity_Activity::get() for a description of the argument * structure, as well as default values. * * @param array $args { * Array of arguments. Supports all arguments from * BP_Activity_Activity::get(), as well as 'page_arg' and * 'include'. Default values for 'per_page' and 'display_comments' * differ from the originating function, and are described below. * @type string $page_arg The string used as a query parameter in * pagination links. Default: 'acpage'. * @type array|bool $include Pass an array of activity IDs to * retrieve only those items, or false to noop the 'include' * parameter. 'include' differs from 'in' in that 'in' forms * an IN clause that works in conjunction with other filters * passed to the function, while 'include' is interpreted as * an exact list of items to retrieve, which skips all other * filter-related parameters. Default: false. * @type int|bool $per_page Default: 20. * @type string|bool $display_comments Default: 'threaded'. * } */ public function __construct($args) { $bp = buddypress(); // Backward compatibility with old method of passing arguments. if (!is_array($args) || func_num_args() > 1) { _deprecated_argument(__METHOD__, '1.6', sprintf(__('Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress'), __METHOD__, __FILE__)); $old_args_keys = array(0 => 'page', 1 => 'per_page', 2 => 'max', 3 => 'include', 4 => 'sort', 5 => 'filter', 6 => 'search_terms', 7 => 'display_comments', 8 => 'show_hidden', 9 => 'exclude', 10 => 'in', 11 => 'spam', 12 => 'page_arg'); $func_args = func_get_args(); $args = bp_core_parse_args_array($old_args_keys, $func_args); } $defaults = array('page' => 1, 'per_page' => 20, 'page_arg' => 'acpage', 'max' => false, 'fields' => 'all', 'count_total' => false, 'sort' => false, 'include' => false, 'exclude' => false, 'in' => false, 'filter' => false, 'scope' => false, 'search_terms' => false, 'meta_query' => false, 'date_query' => false, 'filter_query' => false, 'display_comments' => 'threaded', 'show_hidden' => false, 'spam' => 'ham_only', 'update_meta_cache' => true); $r = wp_parse_args($args, $defaults); extract($r); $this->pag_arg = sanitize_key($r['page_arg']); $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $r['page']); $this->pag_num = bp_sanitize_pagination_arg('num', $r['per_page']); // Check if blog/forum replies are disabled. $this->disable_blogforum_replies = (bool) bp_core_get_root_option('bp-disable-blogforum-comments'); // Get an array of the logged in user's favorite activities. $this->my_favs = maybe_unserialize(bp_get_user_meta(bp_loggedin_user_id(), 'bp_favorite_activities', true)); // Fetch specific activity items based on ID's. if (!empty($include)) { $this->activities = bp_activity_get_specific(array('activity_ids' => explode(',', $include), 'max' => $max, 'count_total' => $count_total, 'page' => $this->pag_page, 'per_page' => $this->pag_num, 'sort' => $sort, 'display_comments' => $display_comments, 'show_hidden' => $show_hidden, 'spam' => $spam, 'update_meta_cache' => $update_meta_cache)); // Fetch all activity items. } else { $this->activities = bp_activity_get(array('display_comments' => $display_comments, 'max' => $max, 'count_total' => $count_total, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'sort' => $sort, 'search_terms' => $search_terms, 'meta_query' => $meta_query, 'date_query' => $date_query, 'filter_query' => $filter_query, 'filter' => $filter, 'scope' => $scope, 'show_hidden' => $show_hidden, 'exclude' => $exclude, 'in' => $in, 'spam' => $spam, 'update_meta_cache' => $update_meta_cache)); } // The total_activity_count property will be set only if a // 'count_total' query has taken place. if (!is_null($this->activities['total'])) { if (!$max || $max >= (int) $this->activities['total']) { $this->total_activity_count = (int) $this->activities['total']; } else { $this->total_activity_count = (int) $max; } } $this->has_more_items = $this->activities['has_more_items']; $this->activities = $this->activities['activities']; if ($max) { if ($max >= count($this->activities)) { $this->activity_count = count($this->activities); } else { $this->activity_count = (int) $max; } } else { $this->activity_count = count($this->activities); } $this->full_name = bp_get_displayed_user_fullname(); // Fetch parent content for activity comments so we do not have to query in the loop. foreach ((array) $this->activities as $activity) { if ('activity_comment' != $activity->type) { continue; } $parent_ids[] = $activity->item_id; } if (!empty($parent_ids)) { $activity_parents = bp_activity_get_specific(array('activity_ids' => $parent_ids)); } if (!empty($activity_parents['activities'])) { foreach ($activity_parents['activities'] as $parent) { $this->activity_parents[$parent->id] = $parent; } unset($activity_parents); } if ((int) $this->total_activity_count && (int) $this->pag_num) { $this->pag_links = paginate_links(array('base' => add_query_arg($this->pag_arg, '%#%'), 'format' => '', 'total' => ceil((int) $this->total_activity_count / (int) $this->pag_num), 'current' => (int) $this->pag_page, 'prev_text' => _x('←', 'Activity pagination previous text', 'buddypress'), 'next_text' => _x('→', 'Activity pagination next text', 'buddypress'), 'mid_size' => 1, 'add_args' => array())); } }
/** * Create the member favorites CSV when requested. * * @since 1.0.0 */ public function run_member_favorites_csv() { // Output headers so that the file is downloaded rather than displayed. header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=cc-member-favorites.csv'); // Create a file pointer connected to the output stream. $output = fopen('php://output', 'w'); // Write a header row. $row = array('user_id', 'user_email', 'favorited_post_by_user_id', 'favorited_post_by_user_email', 'date_recorded'); // Write the row. fputcsv($output, $row); // Use a WP_User_Query meta_query to find users who have favorited activities. $args = array('meta_key' => 'bp_favorite_activities', 'meta_compare' => 'EXISTS', 'orderby' => 'ID'); $user_query = new WP_User_Query($args); // User Loop if (!empty($user_query->results)) { foreach ($user_query->results as $user) { $favorites = bp_activity_get_user_favorites($user->ID); // Passing an empty array to activity_ids gets them all. Abort! if (empty($favorites)) { continue; } // Next, get all of these activity items. $items = bp_activity_get_specific(array('activity_ids' => $favorites, 'update_meta_cache' => false)); foreach ($items['activities'] as $item) { $op = get_userdata($item->user_id); $row = array($user->ID, $user->user_email, $item->user_id, $op->user_email, $item->date_recorded); fputcsv($output, $row); } } } fclose($output); exit; }
/** * @group bp_activity_remove_screen_notifications * @group mentions */ public function test_bp_activity_remove_screen_notifications_on_single_activity_permalink_wrong_user() { $this->create_notifications(); $notifications = BP_Notifications_Notification::get(array('user_id' => $this->u1)); // Double check it's there $this->assertEquals(array($this->a1), wp_list_pluck($notifications, 'item_id')); // Switch user $this->set_current_user($this->u2); // Go to the activity permalink page $this->go_to(bp_activity_get_permalink($this->a1)); $activity = bp_activity_get_specific(array('activity_ids' => $this->a1, 'show_hidden' => true, 'spam' => 'ham_only')); do_action('bp_activity_screen_single_activity_permalink', $activity['activities'][0]); $notifications = BP_Notifications_Notification::get(array('user_id' => $this->u1)); // Should be untouched $this->assertEquals(array($this->a1), wp_list_pluck($notifications, 'item_id')); $this->set_current_user($this->u1); }
/** * Returns the reshared css class in case an activity has been reshared by the user * * @package BP Reshare * @since 1.0 * * @param BP_Activity_Activity $activity the activity object * @param integer $activity_first_id the reshared activity id * @uses bp_loggedin_user_id() to get current user id * @uses bp_activity_get_meta() to get some meta infos about the activity * @uses bp_activity_get_specific() to fetch the specific activity * @return string the reshared css class */ function buddyreshare_get_class($activity = null, $activity_first_id = 0) { if (empty($activity)) { return false; } if (bp_loggedin_user_id() == $activity->user_id) { return 'reshared'; } $reshared_by = bp_activity_get_meta($activity_first_id, 'reshared_by'); if (is_array($reshared_by) && in_array(bp_loggedin_user_id(), $reshared_by)) { return 'reshared'; } // is the loggedin_user the original author ? $originally_shared = bp_activity_get_specific(array('activity_ids' => $activity_first_id)); if ($originally_shared['activities'][0]->user_id == bp_loggedin_user_id()) { return 'reshared'; } }
function miss_bp_document_title() { global $page, $paged, $wp_query; /* Set up some default variables. */ $domain = MISS_TEXTDOMAIN; $doctitle = get_bloginfo('name'); $separator = ' | '; $description = get_bloginfo('description', 'display'); /* bp */ if (function_exists('bp_is_user_friends') && bp_is_user_friends()) { $prefix = __('Friends', MISS_TEXTDOMAIN); } elseif (function_exists('bp_is_user_profile_edit') && bp_is_user_profile_edit()) { $prefix = __('Edit Profile', MISS_TEXTDOMAIN); } elseif (function_exists('bp_is_user_profile') && bp_is_user_profile()) { $prefix = __('User Profile', MISS_TEXTDOMAIN); } elseif (function_exists('bp_is_activity_component') && bp_is_activity_component() && is_numeric($bp->current_action)) { $activity = bp_activity_get_specific(array('activity_ids' => $bp->current_action)); if ($activity = $activity['activities'][0]) { if (!empty($activity->content)) { $prefix = mb_strimwidth(preg_replace("/[^A-Za-z0-9\\s\\s+\\-]/", "", strip_tags($activity->content)), 0, 70 - 3 - 3 - strlen($blog_title), '...'); } } } /* If the current page is a paged page. */ if ((($page = $wp_query->get('paged')) || ($page = $wp_query->get('page'))) && $page > 1) { $prefix = sprintf(__('%1$sPage %2$s', MISS_TEXTDOMAIN), $prefix . $separator, number_format_i18n($page)); } $doctitle = $prefix . $separator . $doctitle; /* Apply the wp_title filters so we're compatible with plugins. */ // $doctitle = apply_filters( 'bp_page_title', $doctitle, '', '' ); // echo apply_atomic( 'bp_page_title', esc_attr( $doctitle ) ); return $doctitle; }
/** * @group bp_activity_delete_by_item_id */ public function test_bp_activity_delete_by_item_id() { $args = array('user_id' => 5, 'component' => 'foo', 'type' => 'bar', 'item_id' => 12, 'secondary_item_id' => 44); $a = $this->factory->activity->create($args); $this->assertTrue(bp_activity_delete_by_item_id($args)); $found = bp_activity_get_specific(array('activity_ids' => array($a))); $this->assertSame(array(), $found['activities']); }