Commit 118732e1 authored by lucha's avatar lucha

[auto] plugin: buddypress 2.8.2

parent 28ebb9c2
......@@ -832,7 +832,11 @@ function bp_activity_transition_post_type_comment_status( $new_status, $old_stat
// Add "new_post_type_comment" to the whitelisted activity types, so that the activity's Akismet history is generated
$post_type_comment_action = $activity_comment_object->action_id;
$comment_akismet_history = create_function( '$t', '$t[] = $post_type_comment_action; return $t;' );
$comment_akismet_history = function ( $activity_types ) use ( $post_type_comment_action ) {
$activity_types[] = $post_type_comment_action;
return $activity_types;
};
add_filter( 'bp_akismet_get_activity_types', $comment_akismet_history );
// Make sure the activity change won't edit the comment if sync is on
......
......@@ -16,10 +16,6 @@ defined( 'ABSPATH' ) || exit;
// Include WP's list table class.
if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
if ( ! buddypress()->do_autoload ) {
require dirname( __FILE__ ) . '/classes/class-bp-activity-list-table.php';
}
// Per_page screen option. Has to be hooked in extremely early.
if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-activity' == $_REQUEST['page'] )
add_filter( 'set-screen-option', 'bp_activity_admin_screen_options', 10, 3 );
......@@ -169,8 +165,9 @@ function bp_activity_admin_screen_options( $value, $option, $new_value ) {
* @return array Hidden Meta Boxes.
*/
function bp_activity_admin_edit_hidden_metaboxes( $hidden, $screen ) {
if ( empty( $screen->id ) || 'toplevel_page_bp-activity' != $screen->id && 'toplevel_page_bp-activity_network' != $screen->id )
if ( empty( $screen->id ) || 'toplevel_page_bp-activity' !== $screen->id && 'toplevel_page_bp-activity-network' !== $screen->id ) {
return $hidden;
}
// Hide the primary link meta box by default.
$hidden = array_merge( (array) $hidden, array( 'bp_activity_itemids', 'bp_activity_link', 'bp_activity_type', 'bp_activity_userid', ) );
......@@ -393,8 +390,8 @@ function bp_activity_admin_load() {
* Remove moderation and blacklist checks in case we want to ham an activity
* which contains one of these listed keys.
*/
remove_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2, 1 );
remove_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2, 1 );
remove_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2 );
remove_action( 'bp_activity_before_save', 'bp_activity_check_blacklist_keys', 2 );
bp_activity_mark_as_ham( $activity );
$result = $activity->save();
......
......@@ -10,10 +10,6 @@
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
if ( ! buddypress()->do_autoload ) {
require dirname( __FILE__ ) . '/classes/class-bp-akismet.php';
}
/**
* Loads Akismet filtering for activity.
*
......
......@@ -450,14 +450,7 @@ function bp_activity_truncate_entry( $text, $args = array() ) {
*/
$append_text = apply_filters( 'bp_activity_excerpt_append_text', __( '[Read more]', 'buddypress' ) );
/**
* Filters the excerpt length for the activity excerpt.
*
* @since 1.5.0
*
* @param int $value Number indicating how many words to trim the excerpt down to.
*/
$excerpt_length = apply_filters( 'bp_activity_excerpt_length', 358 );
$excerpt_length = bp_activity_get_excerpt_length();
$args = wp_parse_args( $args, array( 'ending' => __( '…', 'buddypress' ) ) );
......@@ -603,7 +596,7 @@ function bp_activity_heartbeat_last_recorded( $response = array(), $data = array
ob_end_clean();
// Remove the temporary filter.
remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10, 1 );
remove_filter( 'bp_get_activity_css_class', 'bp_activity_newest_class', 10 );
if ( ! empty( $newest_activities['last_recorded'] ) ) {
$response['bp_activity_newest_activities'] = $newest_activities;
......
......@@ -406,7 +406,7 @@ function bp_activity_set_action( $component_id, $type, $description, $format_cal
* @param array $args {
* An associative array of tracking parameters. All items are optional.
* @type string $bp_activity_admin_filter String to use in the Dashboard > Activity dropdown.
* @type string $bp_activity_front_filter String to use in frontend dropdown.
* @type string $bp_activity_front_filter String to use in the front-end dropdown.
* @type string $bp_activity_new_post String format to use for generating the activity action. Should be a
* translatable string where %1$s is replaced by a user link and %2$s is
* the URL of the newly created post.
......@@ -839,6 +839,63 @@ function bp_activity_get_types() {
return apply_filters( 'bp_activity_get_types', $actions );
}
/**
* Gets the current activity context.
*
* The "context" is the current view type, corresponding roughly to the
* current component. Use this context to determine which activity actions
* should be whitelisted for the filter dropdown.
*
* @since 2.8.0
*
* @return string Activity context. 'member', 'member_groups', 'group', 'activity'.
*/
function bp_activity_get_current_context() {
// On member pages, default to 'member', unless this is a user's Groups activity.
if ( bp_is_user() ) {
if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) {
$context = 'member_groups';
} else {
$context = 'member';
}
// On individual group pages, default to 'group'.
} elseif ( bp_is_active( 'groups' ) && bp_is_group() ) {
$context = 'group';
// 'activity' everywhere else.
} else {
$context = 'activity';
}
return $context;
}
/**
* Gets a flat list of activity actions compatible with a given context.
*
* @since 2.8.0
*
* @param string $context Optional. Name of the context. Defaults to the current context.
* @return array
*/
function bp_activity_get_actions_for_context( $context = '' ) {
if ( ! $context ) {
$context = bp_activity_get_current_context();
}
$actions = array();
foreach ( bp_activity_get_actions() as $component_actions ) {
foreach ( $component_actions as $component_action ) {
if ( in_array( $context, (array) $component_action['context'], true ) ) {
$actions[] = $component_action;
}
}
}
return $actions;
}
/** Favorites ****************************************************************/
/**
......@@ -1445,7 +1502,7 @@ function bp_activity_generate_action_string( $activity ) {
$action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity );
// Remove the filter for future activity items.
remove_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
remove_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10 );
return $action;
}
......@@ -1724,7 +1781,7 @@ function bp_activity_get_specific( $args = '' ) {
'sort' => 'DESC', // Sort ASC or DESC
'spam' => 'ham_only', // Retrieve items marked as spam.
'update_meta_cache' => true,
) );
), 'activity_get_specific' );
$get_args = array(
'display_comments' => $r['display_comments'],
......@@ -2615,9 +2672,9 @@ function bp_activity_new_comment( $args = '' ) {
*
* @since 1.2.0
*
* @param int $comment_id ID of the newly posted activity comment.
* @param array $r Array of parsed comment arguments.
* @param int $activity ID of the activity item being commented on.
* @param int $comment_id ID of the newly posted activity comment.
* @param array $r Array of parsed comment arguments.
* @param BP_Activity_Activity $activity Activity item being commented on.
*/
do_action( 'bp_activity_comment_posted', $comment_id, $r, $activity );
} else {
......@@ -2627,9 +2684,9 @@ function bp_activity_new_comment( $args = '' ) {
*
* @since 2.5.0
*
* @param int $comment_id ID of the newly posted activity comment.
* @param array $r Array of parsed comment arguments.
* @param int $activity ID of the activity item being commented on.
* @param int $comment_id ID of the newly posted activity comment.
* @param array $r Array of parsed comment arguments.
* @param BP_Activity_Activity $activity Activity item being commented on.
*/
do_action( 'bp_activity_comment_posted_notification_skipped', $comment_id, $r, $activity );
}
......@@ -3112,6 +3169,24 @@ function bp_activity_thumbnail_content_images( $content, $link = false, $args =
return apply_filters( 'bp_activity_thumbnail_content_images', $content, $matches, $args );
}
/**
* Gets the excerpt length for activity items.
*
* @since 2.8.0
*
* @return int Character length for activity excerpts.
*/
function bp_activity_get_excerpt_length() {
/**
* Filters the excerpt length for the activity excerpt.
*
* @since 1.5.0
*
* @param int Character length for activity excerpts.
*/
return (int) apply_filters( 'bp_activity_excerpt_length', 358 );
}
/**
* Create a rich summary of an activity item for the activity stream.
*
......@@ -3321,7 +3396,7 @@ function bp_activity_mark_as_spam( &$activity, $source = 'by_a_person' ) {
// If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity.
if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4 );
// Build data package for Akismet.
$activity_data = BP_Akismet::build_akismet_data_package( $activity );
......@@ -3368,7 +3443,7 @@ function bp_activity_mark_as_ham( &$activity, $source = 'by_a_person' ) {
// If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity.
if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4 );
// Build data package for Akismet.
$activity_data = BP_Akismet::build_akismet_data_package( $activity );
......@@ -3423,7 +3498,7 @@ function bp_activity_at_message_notification( $activity_id, $receiver_user_id )
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 );
$content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $activity->content, &$activity ) );
add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
add_filter( 'bp_get_activity_content_body', 'wpautop' );
......@@ -3491,7 +3566,7 @@ function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id =
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', $params['content'] );
$content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $params['content'], &$original_activity ) );
add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
add_filter( 'bp_get_activity_content_body', 'wpautop' );
......@@ -3675,7 +3750,7 @@ add_action( 'bp_before_activity_comment', 'bp_activity_comment_embed' );
function bp_dtheme_embed_read_more( $activity ) {
buddypress()->activity->read_more_id = $activity->id;
add_filter( 'embed_post_id', create_function( '', 'return buddypress()->activity->read_more_id;' ) );
add_filter( 'embed_post_id', function() { return buddypress()->activity->read_more_id; } );
add_filter( 'bp_embed_get_cache', 'bp_embed_activity_cache', 10, 3 );
add_action( 'bp_embed_update_cache', 'bp_embed_activity_save_cache', 10, 3 );
}
......@@ -3745,21 +3820,21 @@ function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
*
* @since 2.0.0
*
* directory.
* is the group activities.
*
* @return bool True if activity heartbeat is enabled, otherwise false.
*/
function bp_activity_do_heartbeat() {
$retval = false;
if ( ! bp_is_activity_heartbeat_active() ) {
return $retval;
}
if ( bp_is_activity_directory() || bp_is_group_activity() ) {
if ( bp_is_activity_heartbeat_active() && ( bp_is_activity_directory() || bp_is_group_activity() ) ) {
$retval = true;
}
return $retval;
/**
* Filters whether the heartbeat feature in the activity stream should be active.
*
* @since 2.8.0
*
* @param bool $retval Whether or not activity heartbeat is active.
*/
return (bool) apply_filters( 'bp_activity_do_heartbeat', $retval );
}
......@@ -12,10 +12,6 @@
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
if ( ! buddypress()->do_autoload ) {
require dirname( __FILE__ ) . '/classes/class-bp-activity-component.php';
}
/**
* Set up the bp-activity component.
*
......
......@@ -14,10 +14,6 @@
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
if ( ! buddypress()->do_autoload ) {
require dirname( __FILE__ ) . '/classes/class-bp-activity-theme-compat.php';
}
/**
* Load the Activity directory.
*
......
......@@ -10,10 +10,6 @@
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
if ( ! buddypress()->do_autoload ) {
require dirname( __FILE__ ) . '/classes/class-bp-activity-template.php';
}
/**
* Output the activity component slug.
*
......@@ -1390,7 +1386,8 @@ function bp_activity_content_body() {
*
* @since 1.2.0
*
* @param array $value Array containing the current activity content body and the current activity.
* @param string $content Content body.
* @param object $activity Activity object. Passed by reference.
*/
return apply_filters_ref_array( 'bp_get_activity_content_body', array( $activities_template->activity->content, &$activities_template->activity ) );
}
......@@ -2230,19 +2227,61 @@ function bp_activity_comment_count() {
* Output the depth of the current activity comment.
*
* @since 2.0.0
* @since 2.8.0 Added $comment as a parameter.
*
* @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary
* when used in activity comment loop.
*/
function bp_activity_comment_depth() {
echo bp_activity_get_comment_depth();
function bp_activity_comment_depth( $comment = 0 ) {
echo bp_activity_get_comment_depth( $comment );
}
/**
* Return the current activity comment depth.
*
* @since 2.0.0
* @since 2.8.0 Added $comment as a parameter.
*
* @return int $depth Depth for the current activity comment.
* @param object|int $comment Object of the activity comment or activity comment ID. Usually unnecessary
* when used in activity comment loop.
* @return int
*/
function bp_activity_get_comment_depth() {
global $activities_template;
function bp_activity_get_comment_depth( $comment = 0 ) {
$depth = 0;
// Activity comment loop takes precedence.
if ( isset( $GLOBALS['activities_template']->activity->current_comment->depth ) ) {
$depth = $GLOBALS['activities_template']->activity->current_comment->depth;
// Get depth for activity comment manually.
} elseif ( ! empty( $comment ) ) {
// We passed an activity ID, so fetch the activity object.
if ( is_int( $comment ) ) {
$comment = new BP_Activity_Activity( $comment );
}
// Recurse through activity tree to find the depth.
if ( is_object( $comment ) && isset( $comment->type ) && 'activity_comment' === $comment->type ) {
// Fetch the entire root comment tree... ugh.
$comments = BP_Activity_Activity::get_activity_comments( $comment->item_id, 1, constant( 'PHP_INT_MAX' ) );
// Recursively find our comment object from the comment tree.
$iterator = new RecursiveArrayIterator( $comments );
$recursive = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::SELF_FIRST );
foreach ( $recursive as $cid => $cobj ) {
// Skip items that are not a comment object.
if ( ! is_numeric( $cid ) || ! is_object( $cobj ) ) {
continue;
}
// We found the activity comment! Set the depth.
if ( $cid === $comment->id && isset( $cobj->depth ) ) {
$depth = $cobj->depth;
break;
}
}
}
}
/**
* Filters the comment depth of the current activity comment.
......@@ -2251,7 +2290,7 @@ function bp_activity_comment_depth() {
*
* @param int $depth Depth for the current activity comment.
*/
return apply_filters( 'bp_activity_get_comment_depth', $activities_template->activity->current_comment->depth );
return apply_filters( 'bp_activity_get_comment_depth', $depth );
}
/**
......@@ -2697,7 +2736,7 @@ function bp_activity_latest_update( $user_id = 0 ) {
* @param string $value The excerpt for the latest update.
* @param int $user_id ID of the queried user.
*/
$latest_update = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], 358 ) ) ), $user_id );
$latest_update = apply_filters( 'bp_get_activity_latest_update_excerpt', trim( strip_tags( bp_create_excerpt( $update['content'], bp_activity_get_excerpt_length() ) ) ), $user_id );
$latest_update = sprintf(
'%s <a href="%s">%s</a>',
......@@ -2887,7 +2926,7 @@ function bp_activity_can_comment_reply( $comment = false ) {
// Fall back on current comment in activity loop.
$comment_depth = isset( $comment->depth )
? intval( $comment->depth )
: bp_activity_get_comment_depth();
: bp_activity_get_comment_depth( $comment );
// Threading is turned on, so check the depth.
if ( get_option( 'thread_comments' ) ) {
......@@ -3799,45 +3838,15 @@ function bp_activity_show_filters( $context = '' ) {
* @return string HTML for <option> values.
*/
function bp_get_activity_show_filters( $context = '' ) {
// Set default context based on current page.
if ( empty( $context ) ) {
// On member pages, default to 'member', unless this
// is a user's Groups activity.
if ( bp_is_user() ) {
if ( bp_is_active( 'groups' ) && bp_is_current_action( bp_get_groups_slug() ) ) {
$context = 'member_groups';
} else {
$context = 'member';
}
// On individual group pages, default to 'group'.
} elseif ( bp_is_active( 'groups' ) && bp_is_group() ) {
$context = 'group';
// 'activity' everywhere else.
} else {
$context = 'activity';
}
}
$filters = array();
// Walk through the registered actions, and prepare an the
// select box options.
foreach ( bp_activity_get_actions() as $actions ) {
foreach ( $actions as $action ) {
if ( ! in_array( $context, (array) $action['context'] ) ) {
continue;
}
// Friends activity collapses two filters into one.
if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) {
$action['key'] = 'friendship_accepted,friendship_created';
}
$filters[ $action['key'] ] = $action['label'];
$actions = bp_activity_get_actions_for_context( $context );
foreach ( $actions as $action ) {
// Friends activity collapses two filters into one.
if ( in_array( $action['key'], array( 'friendship_accepted', 'friendship_created' ) ) ) {
$action['key'] = 'friendship_accepted,friendship_created';
}
$filters[ $action['key'] ] = $action['label'];
}
/**
......
......@@ -185,22 +185,25 @@ class BP_Activity_Activity {
wp_cache_set( $this->id, $row, 'bp_activity' );
}
if ( ! empty( $row ) ) {
$this->id = (int) $row->id;
$this->item_id = (int) $row->item_id;
$this->secondary_item_id = (int) $row->secondary_item_id;
$this->user_id = (int) $row->user_id;
$this->primary_link = $row->primary_link;
$this->component = $row->component;
$this->type = $row->type;
$this->action = $row->action;
$this->content = $row->content;
$this->date_recorded = $row->date_recorded;
$this->hide_sitewide = (int) $row->hide_sitewide;
$this->mptt_left = (int) $row->mptt_left;
$this->mptt_right = (int) $row->mptt_right;
$this->is_spam = (int) $row->is_spam;
}
if ( empty( $row ) ) {
$this->id = 0;
return;
}
$this->id = (int) $row->id;
$this->item_id = (int) $row->item_id;
$this->secondary_item_id = (int) $row->secondary_item_id;
$this->user_id = (int) $row->user_id;
$this->primary_link = $row->primary_link;
$this->component = $row->component;
$this->type = $row->type;
$this->action = $row->action;
$this->content = $row->content;
$this->date_recorded = $row->date_recorded;
$this->hide_sitewide = (int) $row->hide_sitewide;
$this->mptt_left = (int) $row->mptt_left;
$this->mptt_right = (int) $row->mptt_right;
$this->is_spam = (int) $row->is_spam;
// Generate dynamic 'action' when possible.
$action = bp_activity_generate_action_string( $this );
......@@ -373,8 +376,7 @@ class BP_Activity_Activity {
10 => 'spam'
);
$func_args = func_get_args();
$args = bp_core_parse_args_array( $old_args_keys, $func_args );
$args = bp_core_parse_args_array( $old_args_keys, func_get_args() );
}
$bp = buddypress();
......@@ -423,7 +425,7 @@ class BP_Activity_Activity {
// Override some arguments if needed.
if ( ! empty( $scope_query['override'] ) ) {
$r = self::array_replace_recursive( $r, $scope_query['override'] );
$r = array_replace_recursive( $r, $scope_query['override'] );
}
// Advanced filtering.
......@@ -1471,7 +1473,6 @@ class BP_Activity_Activity {
}
// Legacy query - not recommended.
$func_args = func_get_args();
/**
* Filters if BuddyPress should use the legacy activity query.
......@@ -1482,7 +1483,7 @@ class BP_Activity_Activity {
* @param BP_Activity_Activity $value Magic method referring to currently called method.
* @param array $func_args Array of the method's argument list.
*/
if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $func_args ) ) {