function bp_core_check_notification_access($user_id, $notification_id)
{
    if (!BP_Core_Notification::check_access($user_id, $notification_id)) {
        return false;
    }
    return true;
}
/**
 * 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);
}
/**
 * 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);
}
/**
 * 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.
         * @param string $message_link  URL permalink for the activity message.
         * @param string $settings_link URL permalink for the user's notification settings area.
         */
        $message = apply_filters('bp_activity_at_message_notification_message', $message, $poster_name, $content, $message_link, $settings_link);
        wp_mail($to, $subject, $message);
    }
    /**
     * Fires after the sending of an @mention email notification.
     *
     * @since 1.5.0
     *
     * @param BP_Activity_Activity $activity         Activity Item object.
     * @param string               $subject          Email notification subject text.
     * @param string               $message          Email notification message text.
     * @param string               $content          Content of the @mention.
     * @param int                  $receiver_user_id The ID of the user who is receiving the update.
     */
    do_action('bp_activity_sent_mention_email', $activity, $subject, $message, $content, $receiver_user_id);
}
Ejemplo n.º 5
0
function bp_core_delete_notifications_for_user_by_item_id($user_id, $item_id, $component_name, $component_action, $secondary_item_id = false)
{
    _deprecated_function(__FUNCTION__, '1.5', 'bp_core_delete_notifications_by_item_id()');
    return BP_Core_Notification::delete_for_user_by_item_id($user_id, $item_id, $component_name, $component_action, $secondary_item_id);
}
Ejemplo n.º 6
0
/**
 * Send email and BP notifications when a users update is liked.
 *
 * @since 0.4
 *
 * @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_like_update_liked_notification_to' hook.
 * @uses apply_filters() To call the 'bp_like_update_liked_notification_subject' hook.
 * @uses apply_filters() To call the 'bp_like_update_liked_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 notification.
 */
function bp_like_activity_update_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).
    // TODO change 'notification_activity_new_mention' to bp like notification settings options
    if ('no' != bp_get_user_meta($receiver_user_id, 'notification_activity_new_mention', true)) {
        // TODO change this to user who liked activty update
        $users_who_like = array_keys((array) bp_activity_get_meta($bp_like_id, 'liked_count', true));
        if (count($users_who_like) == 1) {
            // If only one person likes the current item.
            if ($receiver_user_id == $users_who_like[0]) {
                // if the user liked their own update we should do nothing.
            } else {
                $liker_name = bp_core_get_user_displayname($users_who_like[0]);
                $subject = bp_get_email_subject(array('text' => sprintf(__('%s liked your update', 'buddypress-like'), $liker_name)));
            }
        } elseif (count($users_who_like) == 2) {
            $liker_one = bp_core_get_user_displayname($users_who_like[0]);
            $liker_two = bp_core_get_user_displayname($users_who_like[1]);
            $subject = bp_get_email_subject(array('text' => sprintf(__('%s and %s liked your update', 'buddypress-like'), $liker_one, $liker_two)));
        } elseif (count($users_who_like) > 2) {
            $others = count($users_who_like);
            $liker_one = bp_core_get_user_displayname($users_who_like[$others - 1]);
            $liker_two = bp_core_get_user_displayname($users_who_like[$others - 2]);
            // TODO comment this better
            // $users_who_like will always be greater than 2 in here
            if ($users_who_like == 3) {
                // if 3 users like an update we remove 1 as we output 2 user names
                // to match the format of - "User1, User2 and 1 other like this"
                $others = $others - 1;
            } else {
                // remove the two named users from the count
                $others = $others - 2;
            }
            //  $string .= '%s, %s and %d ' . _n( 'other', 'others', $others );
            $subject = bp_get_email_subject(array('text' => sprintf(__('%s, %s and %d ' . _n('other', 'others', $others), 'buddypress-like'), $liker_one, $liker_two)));
            //  printf( $string , $one , $two , $others );
        }
        $likers_text = __('%s and %s like this.', 'buddypress-like');
        //  $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 has been declared and assigned its value previously
        //$subject  = bp_get_email_subject( array( 'text' => sprintf( __( '%s liked your update', 'buddypress-like' ), $liker_names ) ) );
        if (bp_is_active('groups') && bp_is_group()) {
            $message = sprintf(__('%1$s liked your update in the group "%2$s":

"%3$s"

To view your liked update, log in and visit: %4$s

---------------------
', 'buddypress-like'), $poster_name, bp_get_current_group_name(), $content, $message_link);
        } else {
            $message = sprintf(__('%1$s liked your update:

"%2$s"

To view your liked update, log in and visit: %3$s

---------------------
', 'buddypress-like'), $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 0.4
         *
         * @param string $to User email the notification is being sent to.
         */
        $to = apply_filters('bp_like_update_liked_notification_to', $to);
        /**
         * Filters the @mention notification subject that will be sent to user.
         *
         * @since 0.4
         *
         * @param string $subject     Email notification subject text.
         * @param string $poster_name Name of the person who made the @mention.
         */
        $subject = apply_filters('bp_like_update_liked_notification_subject', $subject, $poster_name);
        /**
         * Filters the @mention notification message that will be sent to user.
         *
         * @since 0.4
         *
         * @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 liked update.
         * @param string $message_link  URL permalink for the liked activity update.
         * @param string $settings_link URL permalink for the user's notification settings area.
         */
        $message = apply_filters('bp_like_update_liked_notification_message', $message, $poster_name, $content, $message_link, $settings_link);
        wp_mail($to, $subject, $message);
    }
    /**
     * Fires after the sending of an @mention email notification.
     *
     * @since 1.5.0
     *
     * @param BP_Activity_Activity $activity         Activity Item object.
     * @param string               $subject          Email notification subject text.
     * @param string               $message          Email notification message text.
     * @param string               $content          Content of the @mention.
     * @param int                  $receiver_user_id The ID of the user who is receiving the update.
     */
    do_action('bp_like_sent_update_email', $activity, $subject, $message, $content, $receiver_user_id);
}