/**
* Sends an email notification and a BP notification when someone mentions you in an update
*
* @since BuddyPress (1.2)
*
* @param int $activity_id The id of the activity update
* @param int $receiver_user_id The unique user_id of the user who is receiving the update
*
* @uses bp_core_add_notification()
* @uses bp_get_user_meta()
* @uses bp_core_get_user_displayname()
* @uses bp_activity_get_permalink()
* @uses bp_core_get_user_domain()
* @uses bp_get_settings_slug()
* @uses bp_activity_filter_kses()
* @uses bp_core_get_core_userdata()
* @uses wp_specialchars_decode()
* @uses get_blog_option()
* @uses bp_is_active()
* @uses bp_is_group()
* @uses bp_get_current_group_name()
* @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook
* @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook
* @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook
* @uses wp_mail()
* @uses do_action() To call the 'bp_activity_sent_mention_email' hook
*/
function bp_activity_at_message_notification($activity_id, $receiver_user_id)
{
// Don't leave multiple notifications for the same activity item
$notifications = BP_Core_Notification::get_all_for_user($receiver_user_id, 'all');
foreach ($notifications as $notification) {
if ($activity_id == $notification->item_id) {
return;
}
}
$activity = new BP_Activity_Activity($activity_id);
$subject = '';
$message = '';
$content = '';
// Add the BP notification
bp_core_add_notification($activity_id, $receiver_user_id, 'activity', 'new_at_mention', $activity->user_id);
// 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)) {
$poster_name = bp_core_get_user_displayname($activity->user_id);
$message_link = bp_activity_get_permalink($activity_id);
$settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
$settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/';
$poster_name = stripslashes($poster_name);
$content = bp_activity_filter_kses(strip_tags(stripslashes($activity->content)));
// Set up and send the message
$ud = bp_core_get_core_userdata($receiver_user_id);
$to = $ud->user_email;
$subject = bp_get_email_subject(array('text' => sprintf(__('%s mentioned you in an update', 'buddypress'), $poster_name)));
if (bp_is_active('groups') && bp_is_group()) {
$message = sprintf(__('%1$s mentioned you in the group "%2$s":
"%3$s"
To view and respond to the message, log in and visit: %4$s
---------------------
', 'buddypress'), $poster_name, bp_get_current_group_name(), $content, $message_link);
} else {
$message = sprintf(__('%1$s mentioned you in an update:
"%2$s"
To view and respond to the message, log in and visit: %3$s
---------------------
', 'buddypress'), $poster_name, $content, $message_link);
}
// Only show the disable notifications line if the settings component is enabled
if (bp_is_active('settings')) {
$message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
}
/* Send the message */
$to = apply_filters('bp_activity_at_message_notification_to', $to);
$subject = apply_filters('bp_activity_at_message_notification_subject', $subject, $poster_name);
$message = apply_filters('bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link);
wp_mail($to, $subject, $message);
}
do_action('bp_activity_sent_mention_email', $activity, $subject, $message, $content);
}
/**
* Sends an email notification and a BP notification when someone mentions you in an update
*
* @since 1.2.0
*
* @param int $activity_id The id of the activity update
* @param int $receiver_user_id The unique user_id of the user who is receiving the update
*
* @global object $bp BuddyPress global settings
* @uses bp_core_add_notification()
* @uses bp_get_user_meta()
* @uses bp_core_get_user_displayname()
* @uses bp_activity_get_permalink()
* @uses bp_core_get_user_domain()
* @uses bp_get_settings_slug()
* @uses bp_activity_filter_kses()
* @uses bp_core_get_core_userdata()
* @uses nxt_specialchars_decode()
* @uses get_blog_option()
* @uses bp_is_active()
* @uses bp_is_group()
* @uses bp_get_current_group_name()
* @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook
* @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook
* @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook
* @uses nxt_mail()
* @uses do_action() To call the 'bp_activity_sent_mention_email' hook
*/
function bp_activity_at_message_notification($activity_id, $receiver_user_id)
{
global $bp;
$activity = new BP_Activity_Activity($activity_id);
$subject = '';
$message = '';
// Add the BP notification
bp_core_add_notification($activity_id, $receiver_user_id, 'activity', 'new_at_mention', $activity->user_id);
// 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)) {
$poster_name = bp_core_get_user_displayname($activity->user_id);
$message_link = bp_activity_get_permalink($activity_id);
$settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
$settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/';
$poster_name = stripslashes($poster_name);
$content = bp_activity_filter_kses(strip_tags(stripslashes($activity->content)));
// Set up and send the message
$ud = bp_core_get_core_userdata($receiver_user_id);
$to = $ud->user_email;
$sitename = nxt_specialchars_decode(get_blog_option(bp_get_root_blog_id(), 'blogname'), ENT_QUOTES);
$subject = '[' . $sitename . '] ' . sprintf(__('%s mentioned you in an update', 'buddypress'), $poster_name);
if (bp_is_active('groups') && bp_is_group()) {
$message = sprintf(__('%1$s mentioned you in the group "%2$s":
"%3$s"
To view and respond to the message, log in and visit: %4$s
---------------------
', 'buddypress'), $poster_name, bp_get_current_group_name(), $content, $message_link);
} else {
$message = sprintf(__('%1$s mentioned you in an update:
"%2$s"
To view and respond to the message, log in and visit: %3$s
---------------------
', 'buddypress'), $poster_name, $content, $message_link);
}
$message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
/* Send the message */
$to = apply_filters('bp_activity_at_message_notification_to', $to);
$subject = apply_filters('bp_activity_at_message_notification_subject', $subject, $poster_name);
$message = apply_filters('bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link);
nxt_mail($to, $subject, $message);
}
do_action('bp_activity_sent_mention_email', $activity, $subject, $message, $content);
}
/**
* Send email and BP notifications when a user is mentioned in an update.
*
* @since 1.2.0
*
* @uses bp_notifications_add_notification()
* @uses bp_get_user_meta()
* @uses bp_core_get_user_displayname()
* @uses bp_activity_get_permalink()
* @uses bp_core_get_user_domain()
* @uses bp_get_settings_slug()
* @uses bp_activity_filter_kses()
* @uses bp_core_get_core_userdata()
* @uses wp_specialchars_decode()
* @uses get_blog_option()
* @uses bp_is_active()
* @uses bp_is_group()
* @uses bp_get_current_group_name()
* @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook.
* @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook.
* @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook.
* @uses wp_mail()
* @uses do_action() To call the 'bp_activity_sent_mention_email' hook.
*
* @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);
}
/**
* Update an existing group forum post.
*
* Uses the bundled version of bbPress packaged with BuddyPress.
*
* @since BuddyPress (1.1.0)
*
* @param int $post_id The post ID of the existing forum post.
* @param string $post_text The text for the forum post.
* @param int $topic_id The topic ID of the existing forum topic.
* @param mixed $page The page number where the new forum post should reside.
* Optional.
* @return mixed The forum post ID on success. Boolean false on failure.
*/
function groups_update_group_forum_post($post_id, $post_text, $topic_id, $page = false)
{
$bp = buddypress();
$post_text = apply_filters('group_forum_post_text_before_save', $post_text);
$topic_id = apply_filters('group_forum_post_topic_id_before_save', $topic_id);
$post = bp_forums_get_post($post_id);
$post_id = bp_forums_insert_post(array('post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id));
if (empty($post_id)) {
return false;
}
$topic = bp_forums_get_topic_details($topic_id);
$activity_action = sprintf(__('%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink($post->poster_id), '<a href="' . bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '">' . esc_attr($topic->topic_title) . '</a>', '<a href="' . bp_get_group_permalink(groups_get_current_group()) . '">' . esc_attr(bp_get_current_group_name()) . '</a>');
$activity_content = bp_create_excerpt($post_text);
$primary_link = bp_get_group_permalink(groups_get_current_group()) . 'forum/topic/' . $topic->topic_slug . '/';
if (!empty($page)) {
$primary_link .= "?topic_page=" . $page;
}
// Get the corresponding activity item
if (bp_is_active('activity')) {
$id = bp_activity_get_activity_id(array('user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => bp_get_current_group_id(), 'secondary_item_id' => $post_id));
}
// Update the entry in activity streams
groups_record_activity(array('id' => $id, 'action' => apply_filters_ref_array('groups_activity_new_forum_post_action', array($activity_action, $post_text, &$topic, &$topic)), 'content' => apply_filters_ref_array('groups_activity_new_forum_post_content', array($activity_content, $post_text, &$topic, &$topic)), 'primary_link' => apply_filters('groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id), 'type' => 'new_forum_post', 'item_id' => (int) bp_get_current_group_id(), 'user_id' => (int) $post->poster_id, 'secondary_item_id' => $post_id, 'recorded_time' => $post->post_time));
do_action_ref_array('groups_update_group_forum_post', array($post, &$topic));
return $post_id;
}
/**
* Send email and BP notifications when a user is mentioned in an update.
*
* @since 1.2.0
*
* @uses bp_notifications_add_notification()
* @uses bp_get_user_meta()
* @uses bp_core_get_user_displayname()
* @uses bp_activity_get_permalink()
* @uses bp_core_get_user_domain()
* @uses bp_get_settings_slug()
* @uses bp_activity_filter_kses()
* @uses bp_core_get_core_userdata()
* @uses wp_specialchars_decode()
* @uses get_blog_option()
* @uses bp_is_active()
* @uses bp_is_group()
* @uses bp_get_current_group_name()
* @uses apply_filters() To call the 'bp_activity_at_message_notification_to' hook.
* @uses apply_filters() To call the 'bp_activity_at_message_notification_subject' hook.
* @uses apply_filters() To call the 'bp_activity_at_message_notification_message' hook.
* @uses wp_mail()
* @uses do_action() To call the 'bp_activity_sent_mention_email' hook.
*
* @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)
{
// Don't leave multiple notifications for the same activity item.
$notifications = BP_Core_Notification::get_all_for_user($receiver_user_id, 'all');
foreach ($notifications as $notification) {
if ($activity_id == $notification->item_id) {
return;
}
}
$activity = new BP_Activity_Activity($activity_id);
$subject = '';
$message = '';
$content = '';
// 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)) {
$poster_name = bp_core_get_user_displayname($activity->user_id);
$message_link = bp_activity_get_permalink($activity_id);
$settings_slug = function_exists('bp_get_settings_slug') ? bp_get_settings_slug() : 'settings';
$settings_link = bp_core_get_user_domain($receiver_user_id) . $settings_slug . '/notifications/';
$poster_name = stripslashes($poster_name);
$content = bp_activity_filter_kses(strip_tags(stripslashes($activity->content)));
// Set up and send the message.
$ud = bp_core_get_core_userdata($receiver_user_id);
$to = $ud->user_email;
$subject = bp_get_email_subject(array('text' => sprintf(__('%s mentioned you in an update', 'buddypress'), $poster_name)));
if (bp_is_active('groups') && bp_is_group()) {
$message = sprintf(__('%1$s mentioned you in the group "%2$s":
"%3$s"
To view and respond to the message, log in and visit: %4$s
---------------------
', 'buddypress'), $poster_name, bp_get_current_group_name(), $content, $message_link);
} else {
$message = sprintf(__('%1$s mentioned you in an update:
"%2$s"
To view and respond to the message, log in and visit: %3$s
---------------------
', 'buddypress'), $poster_name, $content, $message_link);
}
// Only show the disable notifications line if the settings component is enabled.
if (bp_is_active('settings')) {
$message .= sprintf(__('To disable these notifications please log in and go to: %s', 'buddypress'), $settings_link);
}
/**
* Filters the user email that the @mention notification will be sent to.
*
* @since 1.2.0
*
* @param string $to User email the notification is being sent to.
*/
$to = apply_filters('bp_activity_at_message_notification_to', $to);
/**
* Filters the @mention notification subject that will be sent to user.
*
* @since 1.2.0
*
* @param string $subject Email notification subject text.
* @param string $poster_name Name of the person who made the @mention.
*/
$subject = apply_filters('bp_activity_at_message_notification_subject', $subject, $poster_name);
/**
* Filters the @mention notification message that will be sent to user.
*
* @since 1.2.0
*
* @param string $message Email notification message text.
* @param string $poster_name Name of the person who made the @mention.
* @param string $content Content of the @mention.
//.........这里部分代码省略.........
function ass_admin_notice()
{
if (bp_is_groups_component() && bp_is_current_action('admin') && bp_is_action_variable('notifications', 0)) {
// Make sure the user is an admin
if (!groups_is_user_admin(bp_loggedin_user_id(), bp_get_current_group_id()) && !is_super_admin()) {
return;
}
if (get_option('ass-admin-can-send-email') == 'no') {
return;
}
// make sure the correct form variables are here
if (!isset($_POST['ass_admin_notice_send'])) {
return;
}
if (empty($_POST['ass_admin_notice'])) {
bp_core_add_message(__('The email notice was sent not sent. Please enter email content.', 'bp-ass'), 'error');
} else {
$group = groups_get_current_group();
$group_id = $group->id;
$group_name = bp_get_current_group_name();
$group_link = bp_get_group_permalink($group);
if ($group->status != 'public') {
$group_link = ass_get_login_redirect_url($group_link, 'admin_notice');
}
$blogname = '[' . get_blog_option(BP_ROOT_BLOG, 'blogname') . ']';
$subject = $_POST['ass_admin_notice_subject'];
$subject .= __(' - sent from the group ', 'bp-ass') . $group_name . ' ' . $blogname;
$subject = apply_filters('ass_admin_notice_subject', $subject, $_POST['ass_admin_notice_subject'], $group_name, $blogname);
$subject = ass_clean_subject($subject, false);
$notice = apply_filters('ass_admin_notice_message', $_POST['ass_admin_notice']);
$notice = ass_clean_content($notice);
$message = sprintf(__('This is a notice from the group \'%s\':
"%s"
To view this group log in and follow the link below:
%s
---------------------
', 'bp-ass'), $group_name, $notice, $group_link);
$message .= __('Please note: admin notices are sent to everyone in the group and cannot be disabled.
If you feel this service is being misused please speak to the website administrator.', 'bp-ass');
$user_ids = BP_Groups_Member::get_group_member_ids($group_id);
// allow others to perform an action when this type of email is sent, like adding to the activity feed
do_action('ass_admin_notice', $group_id, $subject, $notice);
// cycle through all group members
foreach ((array) $user_ids as $user_id) {
$user = bp_core_get_core_userdata($user_id);
// Get the details for the user
if ($user->user_email) {
wp_mail($user->user_email, $subject, $message);
}
// Send the email
//echo '<br>Email: ' . $user->user_email;
}
bp_core_add_message(__('The email notice was sent successfully.', 'bp-ass'));
//echo '<p>Subject: ' . $subject;
//echo '<pre>'; print_r( $message ); echo '</pre>';
}
bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/notifications/');
}
}
请发表评论