Commit a4ec787d authored by lucha's avatar lucha
Browse files

[auto] plugin: buddypress 2.7.3

parent 6580b6b9
......@@ -71,7 +71,7 @@ function bp_activity_action_permalink_router() {
} else {
// Set redirect to group activity stream.
if ( $group = groups_get_group( array( 'group_id' => $activity->item_id ) ) ) {
if ( $group = groups_get_group( $activity->item_id ) ) {
$redirect = bp_get_group_permalink( $group ) . bp_get_activity_slug() . '/' . $activity->id . '/';
}
}
......@@ -604,45 +604,6 @@ function bp_activity_action_favorites_feed() {
}
add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
/**
* Loads Akismet filtering for activity.
*
* @since 1.6.0
* @since 2.3.0 We only support Akismet 3+.
*/
function bp_activity_setup_akismet() {
$bp = buddypress();
// Bail if Akismet is not active.
if ( ! defined( 'AKISMET_VERSION' ) ) {
return;
}
// Bail if older version of Akismet.
if ( ! class_exists( 'Akismet' ) ) {
return;
}
// Bail if no Akismet key is set.
if ( ! bp_get_option( 'wordpress_api_key' ) && ! defined( 'WPCOM_API_KEY' ) ) {
return;
}
/**
* Filters if BuddyPress Activity Akismet support has been disabled by another plugin.
*
* @since 1.6.0
*
* @param bool $value Return value of bp_is_akismet_active boolean function.
*/
if ( ! apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
return;
}
// Instantiate Akismet for BuddyPress.
$bp->activity->akismet = new BP_Akismet();
}
/**
* AJAX endpoint for Suggestions API lookups.
*
......
......@@ -14,6 +14,29 @@ if ( ! buddypress()->do_autoload ) {
require dirname( __FILE__ ) . '/classes/class-bp-akismet.php';
}
/**
* Loads Akismet filtering for activity.
*
* @since 1.6.0
* @since 2.3.0 We only support Akismet 3+.
*/
function bp_activity_setup_akismet() {
/**
* Filters if BuddyPress Activity Akismet support has been disabled by another plugin.
*
* @since 1.6.0
*
* @param bool $value Return value of bp_is_akismet_active boolean function.
*/
if ( ! apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
return;
}
// Instantiate Akismet for BuddyPress.
buddypress()->activity->akismet = new BP_Akismet();
}
add_action( 'bp_activity_setup_globals', 'bp_activity_setup_akismet' );
/**
* Delete old spam activity meta data.
*
......
......@@ -63,3 +63,24 @@ function bp_activity_clear_cache_for_deleted_activity( $deleted_ids ) {
}
}
add_action( 'bp_activity_deleted_activities', 'bp_activity_clear_cache_for_deleted_activity' );
/**
* Reset cache incrementor for the Activity component.
*
* Called whenever an activity item is created, updated, or deleted, this
* function effectively invalidates all cached results of activity queries.
*
* @since 2.7.0
*
* @return bool True on success, false on failure.
*/
function bp_activity_reset_cache_incrementor() {
$without_last_activity = bp_core_reset_incrementor( 'bp_activity' );
$with_last_activity = bp_core_reset_incrementor( 'bp_activity_with_last_activity' );
return $without_last_activity && $with_last_activity;
}
add_action( 'bp_activity_delete', 'bp_activity_reset_cache_incrementor' );
add_action( 'bp_activity_add', 'bp_activity_reset_cache_incrementor' );
add_action( 'added_activity_meta', 'bp_activity_reset_cache_incrementor' );
add_action( 'updated_activity_meta', 'bp_activity_reset_cache_incrementor' );
add_action( 'deleted_activity_meta', 'bp_activity_reset_cache_incrementor' );
......@@ -207,13 +207,15 @@ function bp_activity_filter_kses( $content ) {
global $allowedtags;
$activity_allowedtags = $allowedtags;
$activity_allowedtags['a']['class'] = array();
$activity_allowedtags['a']['id'] = array();
$activity_allowedtags['a']['rel'] = array();
$activity_allowedtags['a']['title'] = array();
$activity_allowedtags['b'] = array();
$activity_allowedtags['code'] = array();
$activity_allowedtags['i'] = array();
$activity_allowedtags['a']['class'] = array();
$activity_allowedtags['a']['id'] = array();
$activity_allowedtags['a']['rel'] = array();
$activity_allowedtags['a']['title'] = array();
$activity_allowedtags['b'] = array();
$activity_allowedtags['code'] = array();
$activity_allowedtags['i'] = array();
$activity_allowedtags['img'] = array();
$activity_allowedtags['img']['src'] = array();
$activity_allowedtags['img']['alt'] = array();
......@@ -222,8 +224,10 @@ function bp_activity_filter_kses( $content ) {
$activity_allowedtags['img']['class'] = array();
$activity_allowedtags['img']['id'] = array();
$activity_allowedtags['img']['title'] = array();
$activity_allowedtags['span'] = array();
$activity_allowedtags['span']['class'] = array();
$activity_allowedtags['span'] = array();
$activity_allowedtags['span']['class'] = array();
$activity_allowedtags['span']['data-livestamp'] = array();
/**
......@@ -278,7 +282,7 @@ function bp_activity_at_name_filter( $content, $activity_id = 0 ) {
// Linkify the mentions with the username.
foreach ( (array) $usernames as $user_id => $username ) {
$content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
$content = preg_replace( '/(@' . $username . '\b)/', "<a class='bp-suggestions-mention' href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $content );
}
// Put everything back.
......@@ -319,7 +323,7 @@ function bp_activity_at_name_filter_updates( $activity ) {
if ( ! empty( $usernames ) ) {
// Replace @mention text with userlinks.
foreach( (array) $usernames as $user_id => $username ) {
$activity->content = preg_replace( '/(@' . $username . '\b)/', "<a href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $activity->content );
$activity->content = preg_replace( '/(@' . $username . '\b)/', "<a class='bp-suggestions-mention' href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $activity->content );
}
// Add our hook to send @mention emails after the activity item is saved.
......
......@@ -1663,56 +1663,28 @@ function bp_activity_get( $args = '' ) {
* );
*/
'filter' => array()
) );
// Attempt to return a cached copy of the first page of sitewide activity.
if ( ( 1 === (int) $r['page'] ) && empty( $r['max'] ) && ( 'all' === $r['fields'] ) && empty( $r['search_terms'] ) && empty( $r['meta_query'] ) && empty( $r['date_query'] ) && empty( $r['filter_query'] ) && empty( $r['filter'] ) && empty( $r['scope'] )&& empty( $r['exclude'] ) && empty( $r['in'] ) && ( 'DESC' === $r['sort'] ) && empty( $r['exclude'] ) && ( 'ham_only' === $r['spam'] ) ) {
$activity = wp_cache_get( 'bp_activity_sitewide_front', 'bp' );
if ( false === $activity ) {
$activity = BP_Activity_Activity::get( array(
'page' => $r['page'],
'per_page' => $r['per_page'],
'max' => $r['max'],
'fields' => $r['fields'],
'sort' => $r['sort'],
'search_terms' => $r['search_terms'],
'meta_query' => $r['meta_query'],
'date_query' => $r['date_query'],
'filter_query' => $r['filter_query'],
'filter' => $r['filter'],
'scope' => $r['scope'],
'display_comments' => $r['display_comments'],
'show_hidden' => $r['show_hidden'],
'spam' => $r['spam'],
'update_meta_cache' => $r['update_meta_cache'],
'count_total' => $r['count_total'],
) );
wp_cache_set( 'bp_activity_sitewide_front', $activity, 'bp' );
}
), 'activity_get' );
} else {
$activity = BP_Activity_Activity::get( array(
'page' => $r['page'],
'per_page' => $r['per_page'],
'max' => $r['max'],
'sort' => $r['sort'],
'search_terms' => $r['search_terms'],
'meta_query' => $r['meta_query'],
'date_query' => $r['date_query'],
'filter_query' => $r['filter_query'],
'filter' => $r['filter'],
'scope' => $r['scope'],
'display_comments' => $r['display_comments'],
'show_hidden' => $r['show_hidden'],
'exclude' => $r['exclude'],
'in' => $r['in'],
'spam' => $r['spam'],
'count_total' => $r['count_total'],
) );
}
$activity = BP_Activity_Activity::get( array(
'page' => $r['page'],
'per_page' => $r['per_page'],
'max' => $r['max'],
'sort' => $r['sort'],
'search_terms' => $r['search_terms'],
'meta_query' => $r['meta_query'],
'date_query' => $r['date_query'],
'filter_query' => $r['filter_query'],
'filter' => $r['filter'],
'scope' => $r['scope'],
'display_comments' => $r['display_comments'],
'show_hidden' => $r['show_hidden'],
'exclude' => $r['exclude'],
'in' => $r['in'],
'spam' => $r['spam'],
'update_meta_cache' => $r['update_meta_cache'],
'count_total' => $r['count_total'],
'fields' => $r['fields'],
) );
/**
* Filters the requested activity item(s).
......@@ -1898,10 +1870,13 @@ function bp_activity_add( $args = '' ) {
* @since 1.2.0
*
* @param array|string $args {
* @type string $content The content of the activity update.
* @type int $user_id Optional. Defaults to the logged-in user.
* @type string $content The content of the activity update.
* @type int $user_id Optional. Defaults to the logged-in user.
* @type string $error_type Optional. Error type to return. Either 'bool' or 'wp_error'. Defaults to
* 'bool' for boolean. 'wp_error' will return a WP_Error object.
* }
* @return int $activity_id The activity id.
* @return int|bool|WP_Error $activity_id The activity id on success. On failure, either boolean false or WP_Error
* object depending on the 'error_type' $args parameter.
*/
function bp_activity_post_update( $args = '' ) {
......@@ -3417,6 +3392,211 @@ function bp_activity_mark_as_ham( &$activity, $source = 'by_a_person' ) {
do_action( 'bp_activity_mark_as_ham', $activity, $source );
}
/* Emails *********************************************************************/
/**
* Send email and BP notifications when a user is mentioned in an update.
*
* @since 1.2.0
*
* @param int $activity_id The ID of the activity update.
* @param int $receiver_user_id The ID of the user who is receiving the update.
*/
function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) {
$notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' );
// Don't leave multiple notifications for the same activity item.
foreach( $notifications as $notification ) {
if ( $activity_id == $notification->item_id ) {
return;
}
}
$activity = new BP_Activity_Activity( $activity_id );
$email_type = 'activity-at-message';
$group_name = '';
$message_link = bp_activity_get_permalink( $activity_id );
$poster_name = bp_core_get_user_displayname( $activity->user_id );
remove_filter( 'bp_get_activity_content_body', 'convert_smilies' );
remove_filter( 'bp_get_activity_content_body', 'wpautop' );
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 );
add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
add_filter( 'bp_get_activity_content_body', 'wpautop' );
add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
// Now email the user with the contents of the message (if they have enabled email notifications).
if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
if ( bp_is_active( 'groups' ) && bp_is_group() ) {
$email_type = 'groups-at-message';
$group_name = bp_get_current_group_name();
}
$unsubscribe_args = array(
'user_id' => $receiver_user_id,
'notification_type' => $email_type,
);
$args = array(
'tokens' => array(
'activity' => $activity,
'usermessage' => wp_strip_all_tags( $content ),
'group.name' => $group_name,
'mentioned.url' => $message_link,
'poster.name' => $poster_name,
'receiver-user.id' => $receiver_user_id,
'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
),
);
bp_send_email( $email_type, $receiver_user_id, $args );
}
/**
* Fires after the sending of an @mention email notification.
*
* @since 1.5.0
* @since 2.5.0 $subject, $message, $content arguments unset and deprecated.
*
* @param BP_Activity_Activity $activity Activity Item object.
* @param string $deprecated Removed in 2.5; now an empty string.
* @param string $deprecated Removed in 2.5; now an empty string.
* @param string $deprecated Removed in 2.5; now an empty string.
* @param int $receiver_user_id The ID of the user who is receiving the update.
*/
do_action( 'bp_activity_sent_mention_email', $activity, '', '', '', $receiver_user_id );
}
/**
* Send email and BP notifications when an activity item receives a comment.
*
* @since 1.2.0
* @since 2.5.0 Updated to use new email APIs.
*
* @param int $comment_id The comment id.
* @param int $commenter_id The ID of the user who posted the comment.
* @param array $params {@link bp_activity_new_comment()}.
*/
function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) {
$original_activity = new BP_Activity_Activity( $params['activity_id'] );
$poster_name = bp_core_get_user_displayname( $commenter_id );
$thread_link = bp_activity_get_permalink( $params['activity_id'] );
remove_filter( 'bp_get_activity_content_body', 'convert_smilies' );
remove_filter( 'bp_get_activity_content_body', 'wpautop' );
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'] );
add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
add_filter( 'bp_get_activity_content_body', 'wpautop' );
add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
if ( $original_activity->user_id != $commenter_id ) {
// Send an email if the user hasn't opted-out.
if ( 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
$unsubscribe_args = array(
'user_id' => $original_activity->user_id,
'notification_type' => 'activity-comment',
);
$args = array(
'tokens' => array(
'comment.id' => $comment_id,
'commenter.id' => $commenter_id,
'usermessage' => wp_strip_all_tags( $content ),
'original_activity.user_id' => $original_activity->user_id,
'poster.name' => $poster_name,
'thread.url' => esc_url( $thread_link ),
'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
),
);
bp_send_email( 'activity-comment', $original_activity->user_id, $args );
}
/**
* Fires at the point that notifications should be sent for activity comments.
*
* @since 2.6.0
*
* @param BP_Activity_Activity $original_activity The original activity.
* @param int $comment_id ID for the newly received comment.
* @param int $commenter_id ID of the user who made the comment.
* @param array $params Arguments used with the original activity comment.
*/
do_action( 'bp_activity_sent_reply_to_update_notification', $original_activity, $comment_id, $commenter_id, $params );
}
/*
* If this is a reply to another comment, send an email notification to the
* author of the immediate parent comment.
*/
if ( empty( $params['parent_id'] ) || ( $params['activity_id'] == $params['parent_id'] ) ) {
return;
}
$parent_comment = new BP_Activity_Activity( $params['parent_id'] );
if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id ) {
// Send an email if the user hasn't opted-out.
if ( 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) {
$unsubscribe_args = array(
'user_id' => $parent_comment->user_id,
'notification_type' => 'activity-comment-author',
);
$args = array(
'tokens' => array(
'comment.id' => $comment_id,
'commenter.id' => $commenter_id,
'usermessage' => wp_strip_all_tags( $content ),
'parent-comment-user.id' => $parent_comment->user_id,
'poster.name' => $poster_name,
'thread.url' => esc_url( $thread_link ),
'unsubscribe' => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
),
);
bp_send_email( 'activity-comment-author', $parent_comment->user_id, $args );
}
/**
* Fires at the point that notifications should be sent for comments on activity replies.
*
* @since 2.6.0
*
* @param BP_Activity_Activity $parent_comment The parent activity.
* @param int $comment_id ID for the newly received comment.
* @param int $commenter_id ID of the user who made the comment.
* @param array $params Arguments used with the original activity comment.
*/
do_action( 'bp_activity_sent_reply_to_reply_notification', $parent_comment, $comment_id, $commenter_id, $params );
}
}
/**
* Helper method to map action arguments to function parameters.
*
* @since 1.9.0
*
* @param int $comment_id ID of the comment being notified about.
* @param array $params Parameters to use with notification.
*/
function bp_activity_new_comment_notification_helper( $comment_id, $params ) {
bp_activity_new_comment_notification( $comment_id, $params['user_id'], $params );
}
add_action( 'bp_activity_comment_posted', 'bp_activity_new_comment_notification_helper', 10, 2 );
/** Embeds *******************************************************************/
......
......@@ -17,7 +17,7 @@ if ( ! buddypress()->do_autoload ) {
}
/**
* Bootstrap the Activity component.
* Set up the bp-activity component.
*
* @since 1.6.0
*/
......
......@@ -10,194 +10,6 @@
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
/* Emails *********************************************************************/
/**
* Send email and BP notifications when a user is mentioned in an update.
*
* @since 1.2.0
*
* @param int $activity_id The ID of the activity update.
* @param int $receiver_user_id The ID of the user who is receiving the update.
*/
function bp_activity_at_message_notification( $activity_id, $receiver_user_id ) {
$notifications = BP_Core_Notification::get_all_for_user( $receiver_user_id, 'all' );
// Don't leave multiple notifications for the same activity item.
foreach( $notifications as $notification ) {
if ( $activity_id == $notification->item_id ) {
return;
}
}
$activity = new BP_Activity_Activity( $activity_id );
$email_type = 'activity-at-message';
$group_name = '';
$message_link = bp_activity_get_permalink( $activity_id );
$poster_name = bp_core_get_user_displayname( $activity->user_id );
remove_filter( 'bp_get_activity_content_body', 'convert_smilies' );
remove_filter( 'bp_get_activity_content_body', 'wpautop' );
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 );
add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
add_filter( 'bp_get_activity_content_body', 'wpautop' );
add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
// Now email the user with the contents of the message (if they have enabled email notifications).
if ( 'no' != bp_get_user_meta( $receiver_user_id, 'notification_activity_new_mention', true ) ) {
if ( bp_is_active( 'groups' ) && bp_is_group() ) {
$email_type = 'groups-at-message';
$group_name = bp_get_current_group_name();
}
$args = array(
'tokens' => array(
'activity' => $activity,
'usermessage' => wp_strip_all_tags( $content ),
'group.name' => $group_name,
'mentioned.url' => $message_link,
'poster.name' => $poster_name,
'receiver-user.id' => $receiver_user_id,
),
);
bp_send_email( $email_type, $receiver_user_id, $args );
}
/**
* Fires after the sending of an @mention email notification.
*
* @since 1.5.0
* @since 2.5.0 $subject, $message, $content arguments unset and deprecated.
*
* @param BP_Activity_Activity $activity Activity Item object.
* @param string $deprecated Removed in 2.5; now an empty string.
* @param string $deprecated Removed in 2.5; now an empty string.
* @param string $deprecated Removed in 2.5; now an empty string.
* @param int $receiver_user_id The ID of the user who is receiving the update.
*/
do_action( 'bp_activity_sent_mention_email', $activity, '', '', '', $receiver_user_id );
}
/**
* Send email and BP notifications when an activity item receives a comment.
*
* @since 1.2.0
* @since 2.5.0 Updated to use new email APIs.
*
* @param int $comment_id The comment id.
* @param int $commenter_id The ID of the user who posted the comment.
* @param array $params {@link bp_activity_new_comment()}.
*/
function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) {
$original_activity = new BP_Activity_Activity( $params['activity_id'] );
$poster_name = bp_core_get_user_displayname( $commenter_id );
$thread_link = bp_activity_get_permalink( $params['activity_id'] );
remove_filter( 'bp_get_activity_content_body', 'convert_smilies' );
remove_filter( 'bp_get_activity_content_body', 'wpautop' );