/**
* Notify user roles on new topic
*/
public function notify_new_topic($topic_id = 0, $forum_id = 0, $anonymous_data = 0, $topic_author = 0)
{
$user_roles = Falcon::get_option('bbsub_topic_notification', array());
// bail out if no user roles found
if (!$user_roles) {
return;
}
$recipients = array();
foreach ($user_roles as $role) {
$users = get_users(array('role' => $role, 'fields' => array('ID', 'user_email', 'display_name')));
$recipients = array_merge($recipients, $users);
}
// still no users?
if (!$recipients) {
return;
}
// subscribe the users automatically
foreach ($recipients as $user) {
bbp_add_user_subscription($user->ID, $topic_id);
}
// Sanitize the HTML into text
$content = apply_filters('bbsub_html_to_text', bbp_get_topic_content($topic_id));
// Build email
$text = "%1\$s\n\n";
$text .= "---\nReply to this email directly or view it online:\n%2\$s\n\n";
$text .= "You are receiving this email because you subscribed to it. Login and visit the topic to unsubscribe from these emails.";
$text = sprintf($text, $content, bbp_get_topic_permalink($topic_id));
$text = apply_filters('bbsub_topic_email_message', $text, $topic_id, $content);
$subject = apply_filters('bbsub_topic_email_subject', 'Re: [' . get_option('blogname') . '] ' . bbp_get_topic_title($topic_id), $topic_id);
$options = array('author' => bbp_get_topic_author_display_name($topic_id), 'id' => $topic_id);
$this->handler->send_mail($recipients, $subject, $text, $options);
do_action('bbp_post_notify_topic_subscribers', $topic_id, $recipients);
}
开发者ID:rmccue,项目名称:Falcon,代码行数:36,代码来源:bbPress.php
示例2: wp_slack_bbpress
/**
* Plugin Name: WP Slack bbPress
* Plugin URI: https://github.com/rolfkleef/wp-slack-bbpress
* Description: Send notifications to Slack channels for events in bbPress.
* Version: 0.5
* Author: Rolf Kleef
* Author URI: https://drostan.org
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: wp-slack-bbpress
*/
function wp_slack_bbpress($events)
{
$events['wp_slack_bbp_new_topic'] = array('action' => 'bbp_new_topic', 'description' => __('When a new topic is added in bbPress', 'wp-slack-bbpress'), 'message' => function ($topic_id, $forum_id, $anonymous_data, $topic_author) {
return array(array('fallback' => sprintf(__('<%1$s|New topic "%2$s"> in forum <%3$s|%4$s>', 'wp-slack-bbpress'), bbp_get_topic_permalink($topic_id), bbp_get_topic_title($topic_id), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id)), 'pretext' => sprintf(__('New topic in forum <%1$s|%2$s>', 'wp-slack-bbpress'), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id)), 'author_name' => bbp_get_topic_author_display_name($topic_id), 'author_link' => bbp_get_topic_author_link($topic_id), 'author_icon' => get_avatar_url($topic_author, array('size' => 16)), 'title' => sprintf('%1$s', bbp_get_topic_title($topic_id)), 'title_link' => bbp_get_topic_permalink($topic_id), 'text' => html_entity_decode(bbp_get_topic_excerpt($topic_id, 150))));
});
$events['wp_slack_bbp_new_reply'] = array('action' => 'bbp_new_reply', 'description' => __('When a new reply is added in bbPress', 'wp-slack-bbpress'), 'message' => function ($reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, $bool, $reply_to) {
return array(array('fallback' => sprintf(__('<%1$s|New reply> in forum <%2$s|%3$s> on topic <%4$s|%5$s>', 'wp-slack-bbpress'), bbp_get_reply_url($reply_id), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id), bbp_get_topic_permalink($topic_id), bbp_get_topic_title($topic_id)), 'pretext' => sprintf(__('New reply in forum <%1$s|%2$s> on topic <%3$s|%4$s>', 'wp-slack-bbpress'), bbp_get_forum_permalink($forum_id), bbp_get_forum_title($forum_id), bbp_get_topic_permalink($topic_id), bbp_get_topic_title($topic_id)), 'author_name' => bbp_get_reply_author_display_name($reply_id), 'author_link' => bbp_get_reply_author_link($reply_id), 'author_icon' => get_avatar_url($reply_author, array('size' => 16)), 'title' => sprintf(__('New reply to "%1$s"', 'wp-slack-bbpress'), bbp_get_topic_title($topic_id)), 'title_link' => bbp_get_reply_url($reply_id), 'text' => html_entity_decode(bbp_get_reply_excerpt($reply_id, 150))));
});
return $events;
}
/**
* Notify admins on new topic
*
* @param type $topic_id
* @param type $forum_id
* @param type $anonymous_data
* @param type $topic_author
* @return boolean
*/
public function notify_topic($topic_id, $forum_id, $anonymous_data, $topic_author)
{
$topic_id = bbp_get_topic_id($topic_id);
$forum_id = bbp_get_forum_id($forum_id);
remove_all_filters('bbp_get_topic_content');
remove_all_filters('bbp_get_topic_title');
$topic_title = strip_tags(bbp_get_topic_title($topic_id));
$topic_content = strip_tags(bbp_get_topic_content($topic_id));
$topic_url = bbp_get_topic_permalink($topic_id);
$topic_author_name = bbp_get_topic_author_display_name($topic_id);
$message = sprintf(__('%1$s created new topic:
%2$s
Topic Link: %3$s
-----------
You are receiving this email because you askd for it.
Login and visit the settings to disable these emails.', 'bbp-notify-admin'), $topic_author_name, $topic_content, $topic_url);
$message = apply_filters('bbp_notify_admin_topic_mail_message', $message, $topic_id, $forum_id);
if (empty($message)) {
return;
}
$subject = apply_filters('bbp_notify_admin_reply_mail_title', $this->get_subject(__('New Topic: ', 'bbp-notify-admin') . $topic_title), $topic_id, $forum_id);
if (empty($subject)) {
return;
}
$headers = $this->get_headers();
//get the users to send an email
$users = $this->get_users_to_notify('topic');
$users = apply_filters('bbp_notify_admin_topic_notifiable_users', $users);
if (empty($users)) {
return false;
}
//get all users emails
$emails = $this->get_emails($users, 'topic');
if (empty($emails)) {
return false;
//no one to send to
}
$to_email = array_shift($emails);
// Loop through users
foreach ($emails as $email) {
//add all other users as bcc(only applies in case we have more than 1 admin )
$headers[] = 'Bcc:' . $email;
}
//send email
//even if an admin posts, It will notify everyone including him
$this->notify(array('subject' => $subject, 'message' => $message, 'to' => $to_email, 'headers' => $headers));
}
/**
* Load localizations for topic script.
*
* These localizations require information that may not be loaded even by init.
*
* @since bbPress (r2652)
*
* @uses bbp_is_single_topic() To check if it's the topic page
* @uses bbp_get_current_user_id() To get the current user id
* @uses bbp_get_topic_id() To get the topic id
* @uses bbp_get_favorites_permalink() To get the favorites permalink
* @uses bbp_is_user_favorite() To check if the topic is in user's favorites
* @uses bbp_is_subscriptions_active() To check if the subscriptions are active
* @uses bbp_is_user_subscribed() To check if the user is subscribed to topic
* @uses bbp_get_topic_permalink() To get the topic permalink
* @uses wp_localize_script() To localize the script
*/
function bbp_skeleton_topic_script_localization()
{
if (!bbp_is_single_topic()) {
return;
}
$user_id = bbp_get_current_user_id();
$localizations = array('currentUserId' => $user_id, 'topicId' => bbp_get_topic_id());
// Favorites
if (bbp_is_favorites_active()) {
$localizations['favoritesActive'] = 1;
$localizations['favoritesLink'] = bbp_get_favorites_permalink($user_id);
$localizations['isFav'] = (int) bbp_is_user_favorite($user_id);
$localizations['favLinkYes'] = __('favorites', 'bbpress');
$localizations['favLinkNo'] = __('?', 'bbpress');
$localizations['favYes'] = __('This topic is one of your %favLinkYes% [%favDel%]', 'bbpress');
$localizations['favNo'] = __('%favAdd% (%favLinkNo%)', 'bbpress');
$localizations['favDel'] = __('×', 'bbpress');
$localizations['favAdd'] = __('Add this topic to your favorites', 'bbpress');
} else {
$localizations['favoritesActive'] = 0;
}
// Subscriptions
if (bbp_is_subscriptions_active()) {
$localizations['subsActive'] = 1;
$localizations['isSubscribed'] = (int) bbp_is_user_subscribed($user_id);
$localizations['subsSub'] = __('Subscribe', 'bbpress');
$localizations['subsUns'] = __('Unsubscribe', 'bbpress');
$localizations['subsLink'] = bbp_get_topic_permalink();
} else {
$localizations['subsActive'] = 0;
}
wp_localize_script('bbp_topic', 'bbpTopicJS', $localizations);
}
/**
* Return the link to the last topic in a forum
*
* @since bbPress (r2464)
*
* @param int $forum_id Optional. Forum id
* @uses bbp_get_forum_id() To get the forum id
* @uses bbp_get_forum_last_topic_id() To get the forum's last topic id
* @uses bbp_get_topic_permalink() To get the topic's permalink
* @uses apply_filters() Calls 'bbp_get_forum_last_topic_permalink' with
* the topic link and forum id
* @return string Permanent link to topic
*/
function bbp_get_forum_last_topic_permalink($forum_id = 0)
{
$forum_id = bbp_get_forum_id($forum_id);
return apply_filters('bbp_get_forum_last_topic_permalink', bbp_get_topic_permalink(bbp_get_forum_last_topic_id($forum_id)), $forum_id);
}
/**
* Handles the front end reporting/un-reporting of topics
*
* @since 1.0.0
*
* @param string $action The requested action to compare this function to
*/
public function toggle_topic_handler($action = '')
{
// Bail if required GET actions aren't passed
if (empty($_GET['topic_id'])) {
return;
}
// Setup possible get actions
$possible_actions = array('bbp_rc_toggle_topic_report');
// Bail if actions aren't meant for this function
if (!in_array($action, $possible_actions)) {
return;
}
$failure = '';
// Empty failure string
$view_all = false;
// Assume not viewing all
$topic_id = (int) $_GET['topic_id'];
// What's the topic id?
$success = false;
// Flag
$post_data = array('ID' => $topic_id);
// Prelim array
$redirect = '';
// Empty redirect URL
// Make sure topic exists
$topic = bbp_get_topic($topic_id);
if (empty($topic)) {
return;
}
// Bail if non-logged-in user
if (!is_user_logged_in()) {
return;
}
// What action are we trying to perform?
switch ($action) {
// Toggle reported
case 'bbp_rc_toggle_topic_report':
check_ajax_referer('report-topic_' . $topic_id);
$is_reported = $this->is_topic_reported($topic_id);
$success = true === $is_reported ? $this->unreport_topic($topic_id) : $this->report_topic($topic_id);
$failure = true === $is_reported ? __('<strong>ERROR</strong>: There was a problem unmarking the topic as reported.', 'bbpress-report-content') : __('<strong>ERROR</strong>: There was a problem reporting the topic.', 'bbpress-report-content');
// $view_all = !$is_reported; // Only need this if we want to hide it, like spam
break;
}
// No errors
if (false !== $success && !is_wp_error($success)) {
// Redirect back to the topic's forum
if (isset($sub_action) && 'delete' === $sub_action) {
$redirect = bbp_get_forum_permalink($success->post_parent);
// Redirect back to the topic
} else {
// Get the redirect destination
$permalink = bbp_get_topic_permalink($topic_id);
$redirect = bbp_add_view_all($permalink, $view_all);
}
wp_safe_redirect($redirect);
// For good measure
exit;
// Handle errors
} else {
bbp_add_error('bbp_rc_toggle_topic', $failure);
}
}
请发表评论