Beispiel #1
0
 /**
  * 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);
 }
Beispiel #2
0
/**
 * Returns a trimmed reply content string.
 * Works for replies as well as topics.
 * Must be used while inside the loop
 */
function buddyboss_global_search_reply_intro($character_limit = 50)
{
    $content = '';
    switch (get_post_type(get_the_ID())) {
        case 'topic':
            $reply_content = bbp_get_topic_content(get_the_ID());
            break;
        case 'reply':
            $reply_content = bbp_get_reply_content(get_the_ID());
            break;
        default:
            $reply_content = get_the_content();
            break;
    }
    if ($reply_content) {
        $content = wp_strip_all_tags($reply_content, true);
        $search_term = buddyboss_global_search()->search->get_search_term();
        $search_term_position = strpos($content, $search_term);
        if ($search_term_position !== false) {
            $shortened_content = '...' . substr($content, $search_term_position, $character_limit);
            //highlight search keyword
            $shortened_content = str_replace($search_term, "<strong>" . $search_term . "</strong>", $shortened_content);
        } else {
            $shortened_content = substr($content, 0, $character_limit);
        }
        if (strlen($content) > $character_limit) {
            $shortened_content .= '...';
        }
        $content = $shortened_content;
    }
    return apply_filters('buddyboss_global_search_reply_intro', $content);
}
Beispiel #3
0
 /**
  * @group canonical
  * @covers ::bbp_insert_topic
  */
 public function test_bbp_insert_topic()
 {
     $f = $this->factory->forum->create();
     $now = time();
     $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100);
     $t = $this->factory->topic->create(array('post_title' => 'Topic 1', 'post_content' => 'Content for Topic 1', 'post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Get the topic.
     $topic = bbp_get_topic($t);
     remove_all_filters('bbp_get_topic_content');
     // Topic post.
     $this->assertSame('Topic 1', bbp_get_topic_title($t));
     $this->assertSame('Content for Topic 1', bbp_get_topic_content($t));
     $this->assertSame('publish', bbp_get_topic_status($t));
     $this->assertSame($f, wp_get_post_parent_id($t));
     $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?topic=' . $topic->post_name, $topic->guid);
     // Topic meta.
     $this->assertSame($f, bbp_get_topic_forum_id($t));
     $this->assertSame(1, bbp_get_topic_reply_count($t, true));
     $this->assertSame(0, bbp_get_topic_reply_count_hidden($t, true));
     $this->assertSame(1, bbp_get_topic_voice_count($t, true));
     $this->assertSame($r, bbp_get_topic_last_reply_id($t));
     $this->assertSame($r, bbp_get_topic_last_active_id($t));
     $this->assertSame('4 days, 4 hours ago', bbp_get_topic_last_active_time($t));
 }
 public static function topic_message($message, $topic_id, $forum_id, $user_id)
 {
     $topic_content = strip_tags(bbp_get_topic_content($topic_id));
     $topic_url = bbp_get_topic_permalink($topic_id);
     $topic_author = bbp_get_topic_author_display_name($topic_id);
     $custom_message = get_option('_bbp_topic_notice_body');
     $message = $custom_message ? $custom_message : $message;
     $message = str_replace('{author}', $topic_author, $message);
     $message = str_replace('{content}', $topic_content, $message);
     $message = str_replace('{url}', $topic_url, $message);
     return $message;
 }
    /**
     * 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));
    }
/**
 * Sends notification emails for new topics to subscribed forums
 *
 * Gets new post's ID and check if there are subscribed users to that forum, and
 * if there are, send notifications
 *
 * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email
 * with everyone BCC'd. This may have negative repercussions for email services
 * that limit the number of addresses in a BCC field (often to around 500.) In
 * those cases, we recommend unhooking this function and creating your own
 * custom emailer script.
 *
 * @since 2.5.0 bbPress (r5156)
 *
 * @param int $topic_id ID of the newly made reply
 * @param int $forum_id ID of the forum for the topic
 * @param mixed $anonymous_data Array of anonymous user data
 * @param int $topic_author ID of the topic author ID
 *
 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
 * @uses bbp_get_topic_id() To validate the topic ID
 * @uses bbp_get_forum_id() To validate the forum ID
 * @uses bbp_is_topic_published() To make sure the topic is published
 * @uses bbp_get_forum_subscribers() To get the forum subscribers
 * @uses bbp_get_topic_author_display_name() To get the topic author's display name
 * @uses do_action() Calls 'bbp_pre_notify_forum_subscribers' with the topic id,
 *                    forum id and user id
 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_message' with the
 *                    message, topic id, forum id and user id
 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_title' with the
 *                    topic title, topic id, forum id and user id
 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_headers'
 * @uses get_userdata() To get the user data
 * @uses wp_mail() To send the mail
 * @uses do_action() Calls 'bbp_post_notify_forum_subscribers' with the topic,
 *                    id, forum id and user id
 * @return bool True on success, false on failure
 */
function bbp_notify_forum_subscribers($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0)
{
    // Bail if subscriptions are turned off
    if (!bbp_is_subscriptions_active()) {
        return false;
    }
    /** Validation ************************************************************/
    $topic_id = bbp_get_topic_id($topic_id);
    $forum_id = bbp_get_forum_id($forum_id);
    /**
     * Necessary for backwards compatibility
     *
     * @see https://bbpress.trac.wordpress.org/ticket/2620
     */
    $user_id = 0;
    /** Topic *****************************************************************/
    // Bail if topic is not published
    if (!bbp_is_topic_published($topic_id)) {
        return false;
    }
    // Poster name
    $topic_author_name = bbp_get_topic_author_display_name($topic_id);
    /** Mail ******************************************************************/
    // Remove filters from reply content and topic title to prevent content
    // from being encoded with HTML entities, wrapped in paragraph tags, etc...
    remove_all_filters('bbp_get_topic_content');
    remove_all_filters('bbp_get_topic_title');
    // Strip tags from text and setup mail data
    $topic_title = strip_tags(bbp_get_topic_title($topic_id));
    $topic_content = strip_tags(bbp_get_topic_content($topic_id));
    $topic_url = get_permalink($topic_id);
    $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    // For plugins to filter messages per reply/topic/user
    $message = sprintf(__('%1$s wrote:

%2$s

Topic Link: %3$s

-----------

You are receiving this email because you subscribed to a forum.

Login and visit the topic to unsubscribe from these emails.', 'bbpress'), $topic_author_name, $topic_content, $topic_url);
    $message = apply_filters('bbp_forum_subscription_mail_message', $message, $topic_id, $forum_id, $user_id);
    if (empty($message)) {
        return;
    }
    // For plugins to filter titles per reply/topic/user
    $subject = apply_filters('bbp_forum_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $topic_id, $forum_id, $user_id);
    if (empty($subject)) {
        return;
    }
    /** User ******************************************************************/
    // Get the noreply@ address
    $no_reply = bbp_get_do_not_reply_address();
    // Setup "From" email address
    $from_email = apply_filters('bbp_subscription_from_email', $no_reply);
    // Setup the From header
    $headers = array('From: ' . get_bloginfo('name') . ' <' . $from_email . '>');
    // Get topic subscribers and bail if empty
    $user_ids = bbp_get_forum_subscribers($forum_id, true);
    // Dedicated filter to manipulate user ID's to send emails to
    $user_ids = apply_filters('bbp_forum_subscription_user_ids', $user_ids);
    if (empty($user_ids)) {
        return false;
    }
    // Loop through users
    foreach ((array) $user_ids as $user_id) {
        // Don't send notifications to the person who made the post
        if (!empty($topic_author) && (int) $user_id === (int) $topic_author) {
            continue;
        }
        // Get email address of subscribed user
        $headers[] = 'Bcc: ' . get_userdata($user_id)->user_email;
    }
    /** Send it ***************************************************************/
    // Custom headers
    $headers = apply_filters('bbp_subscription_mail_headers', $headers);
    $to_email = apply_filters('bbp_subscription_to_email', $no_reply);
    do_action('bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids);
    // Send notification email
    wp_mail($to_email, $subject, $message, $headers);
    do_action('bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids);
    return true;
}
Beispiel #7
0
		<?php 
do_action('bbp_theme_before_topic_title');
?>

		<a class="bbp-topic-permalink" href="<?php 
bbp_topic_permalink();
?>
"><?php 
bbp_topic_title();
?>
</a>
        
        <div class="bbp-topic-content-preview">
			<p><?php 
$content = bbp_get_topic_content();
$content = strip_tags($content);
echo substr($content, 0, 100) . '...';
?>
</p>
            <a href="<?php 
bbp_topic_permalink();
?>
" class="btnReadMore">Read More</a>
        </div>

		<?php 
do_action('bbp_theme_after_topic_title');
?>

		<?php 
Beispiel #8
0
function load_more_topics()
{
    $content = '';
    ob_start();
    $forum_id = $_POST['forum'];
    if ($topics = bbp_has_topics(array('post_parent' => $forum_id, 'posts_per_page' => 11, 'paged' => $_POST['list']))) {
        $counter = 0;
        while (bbp_topics()) {
            bbp_the_topic();
            if (++$counter == 12) {
                break;
            }
            ?>
<div class="topics_list_single_topic  <?php 
            $postUser = new WP_User(bbp_get_topic_author_id());
            echo $postUser->has_cap('bbp_keymaster') || $postUser->has_cap('bbp_moderator') ? "isAdmin" : "";
            ?>
"
	id="topic-<?php 
            echo bbp_get_topic_id();
            ?>
"
	data-bbp_forum_id="<?php 
            echo $forum_id;
            ?>
"
	data-id="<?php 
            echo bbp_get_topic_id();
            ?>
">
	<div class="single_topic_header">
		<div class="photo">
			<a
				href="<?php 
            echo bp_core_get_user_domain(bbp_get_topic_author_id());
            ?>
"><?php 
            echo bp_core_fetch_avatar(array('item_id' => bbp_get_topic_author_id(), 'height' => 40, 'width' => 40));
            ?>
</a>
		</div>
		<div class="info">
			<div class="name">
				<a
					href="<?php 
            echo bp_core_get_user_domain(bbp_get_topic_author_id());
            ?>
"><?php 
            echo bbp_get_topic_author_display_name(bbp_get_topic_id());
            ?>
</a>
                <?php 
            if ($postUser->has_cap('bbp_keymaster')) {
                echo "<small>(Администратор форума)</small>";
            } elseif ($postUser->has_cap('bbp_moderator')) {
                echo "<small>(Преподаватель)</small>";
            }
            ?>
			</div>
			<div class="date"><?php 
            echo get_post_time('j F ', false, bbp_get_topic_id(), true) . __('at', 'qode') . get_post_time(' H:i', false, bbp_get_topic_id(), true);
            ?>
</div>
		</div>
                    <?php 
            if (bbp_get_topic_author_id() == get_current_user_id()) {
                ?>
                        <a href="#" class="addi_actions_open"></a>
		<div class="addi_actions" style="display: none">
			<ul>
				<li><a class="edit_action" href="#">Редактировать</a></li>
				<li><a class="remove_action" href="#">Удалить</a></li>
			</ul>
		</div>
                    <?php 
            }
            ?>
                </div>
	<div class="single_topic_content">
                    <?php 
            $content = bbp_get_topic_content();
            if (mb_strlen($content) > 500) {
                echo '<div class="show">' . mb_substr($content, 0, 500) . '... <a href="#" class="show_all">' . __('More', 'qode') . '</a></div>';
                ?>
                        <div class="hide"><?php 
                echo $content;
                ?>
</div>
                    <?php 
            } else {
                echo $content;
            }
            ?>
                </div>
	<div style="display: none" class="single_topic_content_edit">
		<textarea class="edit_content"><?php 
            echo get_post_field('post_content', bbp_get_topic_id());
            ?>
</textarea>

		<div class="edit_actions">
			<button class="cancel"><?php 
            _e('Cancel', 'qode');
            ?>
</button>
			<button class="save"><?php 
            _e('Save', 'qode');
            ?>
</button>
		</div>
	</div>
	<div class="single_topic_replies_container">
		<div class="single_topic_replies">
                        <?php 
            $replies = get_posts($default = array('post_type' => bbp_get_reply_post_type(), 'post_parent' => bbp_get_topic_id(), 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true));
            // Stickies not supported
            $i = count($replies);
            if ($i == 5) {
                $count = new WP_Query($default = array('numberposts' => -1, 'post_type' => bbp_get_reply_post_type(), 'post_parent' => bbp_get_topic_id(), 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true));
                // Stickies not supported
                $count = $count->found_posts - 4;
                ?>
<a href="#" class="load_all_replies"><i class="comments_img"></i>Просмотреть
                            еще <?php 
                echo $count . ' ' . custom_plural_form($count, 'комментарий', 'комментария', 'комментариев');
                ?>
                            </a>
                        <?php 
            }
            $replies = array_reverse($replies);
            //array_shift ( $replies );
            foreach ($replies as $reply) {
                ?>
				<div class="single_topic_reply <?php 
                $postUser = new WP_User($reply->post_author);
                echo $postUser->has_cap('bbp_keymaster') || $postUser->has_cap('bbp_moderator') ? "isAdmin" : "";
                ?>
"
				data-id="<?php 
                echo $reply->ID;
                ?>
">
				<div class="photo">
					<a
						href="<?php 
                echo bp_core_get_user_domain($reply->post_author);
                ?>
"><?php 
                echo bp_core_fetch_avatar(array('item_id' => $reply->post_author, 'height' => 32, 'width' => 32));
                ?>
</a>
				</div>
				<div class="content_wrapper">
					<div class="reply_content">
						<a class="author-link"
							href="<?php 
                echo bp_core_get_user_domain($reply->post_author);
                ?>
"><?php 
                echo bbp_get_reply_author_display_name($reply->ID);
                ?>
</a>
                            
                        <?php 
                if ($postUser->has_cap('bbp_keymaster')) {
                    echo "<small>(Администратор форума)</small>";
                } elseif ($postUser->has_cap('bbp_moderator')) {
                    echo "<small>(Преподаватель)</small>";
                }
                ?>
							<?php 
                echo bbp_get_reply_content($reply->ID);
                ?>
                    </div>
					<div style="display: none" class="reply_content_edit">
						<textarea class="reply_content_edit_textarea"><?php 
                echo get_post_field('post_content', $reply->ID);
                ?>
</textarea>
						
						<div class="edit_actions">
							<a class="cancel" href="#">Отменить</a>
						</div>
					</div>
					<div class="date">
						<?php 
                echo get_post_time('j F ', false, $reply->ID, true) . __('at', 'qode') . get_post_time(' H:i', false, $reply->ID, true);
                ?>
</span><?php 
                $like = get_post_meta($reply->ID, 'like_' . get_current_user_id(), true);
                ?>
					</div>
				</div>
				<?php 
                if ($reply->post_author == get_current_user_id()) {
                    ?>
				<a class="addi_actions_open" href="#"></a>
				<div class="addi_actions" style="display: none">
					<ul>
						<li><a class="edit_action" href="#">Редактировать</a></li>
						<li><a class="remove_action" href="#">Удалить</a></li>
					</ul>
				</div>
                                <?php 
                }
                ?>
                            </div>
                        <?php 
            }
            $url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
            ?>
                    </div>
		<div class="single_topic_reply_form">
			<form
				action="<?php 
            echo $url;
            ?>
#topic-<?php 
            echo bbp_get_topic_id();
            ?>
"
				data-bbp_forum_id="<?php 
            echo $forum_id;
            ?>
"
				data-bbp_topic_id="<?php 
            echo bbp_get_topic_id();
            ?>
" method="post">
				<div class="photo">
					<a
						href="<?php 
            echo bp_core_get_user_domain(get_current_user_id());
            ?>
"><?php 
            echo bp_core_fetch_avatar(array('item_id' => get_current_user_id(), 'height' => 32, 'width' => 32));
            ?>
</a>
				</div>
				<div class="reply-form">
					<textarea
						placeholder="<?php 
            _e('Введите текст сообщения...', 'qode');
            ?>
"
						name="content"></textarea>
				</div>

				<input type="hidden" name="bbp_forum_id"
					value="<?php 
            echo $forum_id;
            ?>
"> <input type="hidden"
					name="bbp_topic_id" value="<?php 
            echo bbp_get_topic_id();
            ?>
"> <input
					type="hidden" name="action" value="custom-bbp-reply-create"> <input
					type="hidden" name="security"
					value="<?php 
            echo wp_create_nonce('custom-bbp-reply-create');
            ?>
">
			</form>
		</div>
	</div>
</div>
<?php 
        }
        if ($counter == 11) {
            ?>
<a class="load_more_topics" href="#"><?php 
            _e('Load more discussions', 'qode');
            ?>
</a>
<?php 
        }
    }
    $content = ob_get_contents();
    ob_end_clean();
    die(json_encode(array('result' => 'OK', 'content' => $content)));
}
Beispiel #9
0
/**
 * Return the excerpt of the topic
 *
 * @since bbPress (r2780)
 *
 * @param int $topic_id Optional. topic id
 * @param int $length Optional. Length of the excerpt. Defaults to 100
 *                     letters
 * @uses bbp_get_topic_id() To get the topic id
 * @uses get_post_field() To get the excerpt
 * @uses bbp_get_topic_content() To get the topic content
 * @uses apply_filters() Calls 'bbp_get_topic_excerpt' with the excerpt,
 *                        topic id and length
 * @return string topic Excerpt
 */
function bbp_get_topic_excerpt($topic_id = 0, $length = 100)
{
    $topic_id = bbp_get_topic_id($topic_id);
    $length = (int) $length;
    $excerpt = get_post_field($topic_id, 'post_excerpt');
    if (empty($excerpt)) {
        $excerpt = bbp_get_topic_content($topic_id);
    }
    $excerpt = trim(strip_tags($excerpt));
    if (!empty($length) && strlen($excerpt) > $length) {
        $excerpt = substr($excerpt, 0, $length - 1);
        $excerpt .= '&hellip;';
    }
    return apply_filters('bbp_get_topic_excerpt', $excerpt, $topic_id, $length);
}
Beispiel #10
0
/**
 * Sends notification emails for new topics to subscribed forums
 *
 * Gets new post's ID and check if there are subscribed users to that topic, and
 * if there are, send notifications
 *
 * @since bbPress (r5156)
 *
 * @param int $topic_id ID of the newly made reply
 * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
 * @uses bbp_get_topic_id() To validate the topic ID
 * @uses bbp_get_forum_id() To validate the forum ID
 * @uses bbp_is_topic_published() To make sure the topic is published
 * @uses bbp_get_forum_subscribers() To get the forum subscribers
 * @uses bbp_get_topic_author_display_name() To get the topic author's display name
 * @uses do_action() Calls 'bbp_pre_notify_forum_subscribers' with the topic id,
 *                    forum id and user id
 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_message' with the
 *                    message, topic id, forum id and user id
 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_title' with the
 *                    topic title, topic id, forum id and user id
 * @uses apply_filters() Calls 'bbp_forum_subscription_mail_headers'
 * @uses get_userdata() To get the user data
 * @uses wp_mail() To send the mail
 * @uses do_action() Calls 'bbp_post_notify_forum_subscribers' with the topic,
 *                    id, forum id and user id
 * @return bool True on success, false on failure
 */
function bbp_notify_forum_subscribers($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0)
{
    // Bail if subscriptions are turned off
    if (!bbp_is_subscriptions_active()) {
        return false;
    }
    /** Validation ************************************************************/
    $topic_id = bbp_get_topic_id($topic_id);
    $forum_id = bbp_get_forum_id($forum_id);
    /** Topic *****************************************************************/
    // Bail if topic is not published
    if (!bbp_is_topic_published($topic_id)) {
        return false;
    }
    /** User ******************************************************************/
    // Get forum subscribers and bail if empty
    $user_ids = bbp_get_forum_subscribers($forum_id, true);
    if (empty($user_ids)) {
        return false;
    }
    // Poster name
    $topic_author_name = bbp_get_topic_author_display_name($topic_id);
    /** Mail ******************************************************************/
    do_action('bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids);
    // Remove filters from reply content and topic title to prevent content
    // from being encoded with HTML entities, wrapped in paragraph tags, etc...
    remove_all_filters('bbp_get_topic_content');
    remove_all_filters('bbp_get_topic_title');
    // Strip tags from text
    $topic_title = strip_tags(bbp_get_topic_title($topic_id));
    $topic_content = strip_tags(bbp_get_topic_content($topic_id));
    $topic_url = get_permalink($topic_id);
    $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    // Loop through users
    foreach ((array) $user_ids as $user_id) {
        // Don't send notifications to the person who made the post
        if (!empty($topic_author) && (int) $user_id === (int) $topic_author) {
            continue;
        }
        // For plugins to filter messages per reply/topic/user
        $message = sprintf(__('%1$s wrote:

%2$s

Topic Link: %3$s

-----------

You are receiving this email because you subscribed to a forum.

Login and visit the topic to unsubscribe from these emails.', 'bbpress'), $topic_author_name, $topic_content, $topic_url);
        $message = apply_filters('bbp_forum_subscription_mail_message', $message, $topic_id, $forum_id, $user_id);
        if (empty($message)) {
            continue;
        }
        // For plugins to filter titles per reply/topic/user
        $subject = apply_filters('bbp_forum_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $topic_id, $forum_id, $user_id);
        if (empty($subject)) {
            continue;
        }
        // Custom headers
        $headers = apply_filters('bbp_forum_subscription_mail_headers', array());
        // Get user data of this user
        $user = get_userdata($user_id);
        // Send notification email
        wp_mail($user->user_email, $subject, $message, $headers);
    }
    do_action('bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids);
    return true;
}
Beispiel #11
0
        function getMetaTags()
        {
            global $ilen_seo, $post, $authordata, $if_utils, $post_type, $meta_seo;
            $meta_keyword = null;
            $meta_description = null;
            $tags_to_metakeyword = null;
            $meta_facebook = null;
            $meta_twitter = null;
            $meta_google = null;
            $meta_title_custom = null;
            $meta_keyword_custom = null;
            $meta_description_custom = null;
            $post_type = isset($post->ID) && $post->ID ? get_post_type($post->ID) : rand(10000, 25000);
            $meta_seo = get_post_meta($post->ID, $this->parameter['name_option'] . "_metabox");
            if ($post_type == "post" || $post_type == "page") {
                if (isset($meta_seo[0]['keyword_seo']) && $meta_seo[0]['keyword_seo']) {
                    $meta_keyword_custom = $meta_seo[0]['keyword_seo'];
                }
            }
            // Get image post for social network
            $image_post = null;
            if (is_single()) {
                $image_post = $if_utils->IF_get_image('medium', null, $post->ID);
                if (!$image_post['src']) {
                    if (isset($ilen_seo->default_image) && $ilen_seo->default_image) {
                        $image_post = $ilen_seo->default_image;
                    }
                } else {
                    $image_post = $image_post['src'];
                }
            } elseif (is_home() || is_front_page()) {
                if (isset($ilen_seo->home_image) && $ilen_seo->home_image) {
                    $image_post = $ilen_seo->home_image;
                }
            }
            if (isset($ilen_seo->meta_keywork) && $ilen_seo->meta_keywork || is_singular() && isset($ilen_seo->tag_keyword) && $ilen_seo->tag_keyword || is_singular() && $meta_keyword_custom) {
                if (is_singular() && isset($ilen_seo->tag_keyword) && $ilen_seo->tag_keyword) {
                    $t = wp_get_post_tags($post->ID);
                    if ($t) {
                        $tags = array();
                        foreach ($t as $tag) {
                            $tags[] = $tag->name;
                        }
                        $tags_to_metakeyword = implode(",", $tags);
                    }
                    if ($tags_to_metakeyword) {
                        $meta_keyword_custom = ",{$meta_keyword_custom}";
                    }
                    $meta_keyword = '
<meta name="keywords" content="' . $tags_to_metakeyword . $meta_keyword_custom . '" />';
                } else {
                    if ($ilen_seo->meta_keywork) {
                        $meta_keyword_custom = ",{$meta_keyword_custom}";
                    }
                    $meta_keyword = '
<meta name="keywords" content="' . $ilen_seo->meta_keywork . $meta_keyword_custom . '" />';
                }
            }
            if (get_query_var('paged')) {
                $meta_description = "";
            } elseif (is_home() || is_front_page()) {
                $meta_description = mb_substr($ilen_seo->meta_description, 0, 155, 'utf-8');
                if (isset($ilen_seo->facebook_open_graph) && $ilen_seo->facebook_open_graph) {
                    $meta_facebook = '
<!-- open Graph data -->
<meta property="og:title" content="' . get_bloginfo('name') . '" />
<meta property="og:description" content="' . $meta_description . '" />
<meta property="og:url" content="' . get_bloginfo('url') . '" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="' . get_locale() . '" />
<meta property="og:site_name" content="' . get_bloginfo('name') . '" />
<meta property="og:image" content="' . $image_post . '" />
';
                }
                if (isset($ilen_seo->twitter_user) && $ilen_seo->twitter_user) {
                    $meta_twitter = '
<!-- twitter Card data -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@' . $ilen_seo->twitter_user . '" />
<meta name="twitter:title" content="' . get_bloginfo('name') . '" />
<meta name="twitter:description" content="' . $meta_description . '" />
<meta name="twitter:image" content="' . $image_post . '" />
';
                }
            } elseif (is_tag()) {
                if (isset($ilen_seo->facebook_open_graph) && $ilen_seo->facebook_open_graph) {
                    $tag = ucfirst(single_tag_title("", false));
                    $tag_id = get_query_var('tag_id');
                    $meta_facebook = '
<!-- open Graph data -->
<meta property="og:title" content="' . $tag . '" />
<meta property="og:url" content="' . get_tag_link($tag_id) . '" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="' . get_locale() . '" />
<meta property="article:section" content="' . $tag . '" />
<meta property="og:site_name" content="' . get_bloginfo('name') . '" />
<meta property="og:image" content="' . $image_post . '" />';
                }
                if (isset($ilen_seo->twitter_user) && $ilen_seo->twitter_user) {
                    $meta_twitter = '
<!-- twitter Card data -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@' . $ilen_seo->twitter_user . '" />
<meta name="twitter:title" content="' . $tag . '" />
<meta name="twitter:image" content="' . $image_post . '" />
';
                }
                $meta_description = "";
            } elseif (is_singular()) {
                if ($post->post_type == "forum") {
                    $excert = strip_shortcodes(strip_tags(trim(mb_substr($ilen_seo->meta_description, 0, 155, 'utf-8'))));
                    $excert1 = preg_replace('/\\s\\s+/', ' ', $excert);
                    $excert2 = $if_utils->IF_removeShortCode($excert1);
                    $content = mb_substr(trim($excert2), 0, 155, 'utf-8') . "...";
                    $meta_description = htmlspecialchars($content, ENT_QUOTES | 'ENT_HTML5');
                } elseif ($post->post_type == "topic") {
                    $excert = strip_shortcodes(strip_tags(trim(bbp_get_topic_content())));
                    $excert1 = preg_replace('/\\s\\s+/', ' ', $excert);
                    $excert2 = $if_utils->IF_removeShortCode($excert1);
                    $content = mb_substr(trim($excert2), 0, 155, 'utf-8') . "...";
                    $meta_description = htmlspecialchars($content, ENT_QUOTES | 'ENT_HTML5');
                } elseif ($post->post_type != "topic" && $post->post_type != "forum") {
                    $excert = strip_shortcodes(strip_tags(trim($post->post_content)));
                    $excert1 = preg_replace('/\\s\\s+/', ' ', $excert);
                    $excert2 = $if_utils->IF_removeShortCode($excert1);
                    $content = mb_substr(trim($excert2), 0, 155, 'utf-8') . "...";
                    $meta_description = htmlspecialchars($content, ENT_QUOTES | 'ENT_HTML5');
                }
                if (isset($meta_seo[0]['title_seo']) && $meta_seo[0]['title_seo']) {
                    $meta_title_custom = $meta_seo[0]['title_seo'];
                } else {
                    $meta_title_custom = get_the_title();
                }
                if (isset($meta_seo[0]['description_seo']) && $meta_seo[0]['description_seo']) {
                    $meta_description_custom = $meta_seo[0]['description_seo'];
                } else {
                    $meta_description_custom = $meta_description;
                }
                $meta_description = $meta_description_custom;
                $tags_string = "";
                $categories_string = "";
                if (isset($ilen_seo->facebook_open_graph) && $ilen_seo->facebook_open_graph) {
                    if (isset($ilen_seo->facebook_open_graph_tag) && $ilen_seo->facebook_open_graph_tag) {
                        $t = wp_get_post_tags($post->ID);
                        if ($t) {
                            $tags = array();
                            foreach ($t as $tag) {
                                $tag_link = get_tag_link($tag->term_id);
                                $tags[] = $tag->name;
                            }
                            if (is_array($tags)) {
                                foreach ($tags as $tt) {
                                    $tags_string .= '
<meta property="article:tag" content="$tt" />
';
                                }
                                $tags_string = "\n{$tags_string}\n";
                            }
                        }
                    }
                    $c = get_the_category();
                    $array_cat = array();
                    if ($c) {
                        foreach ($c as $category) {
                            $array_cat[] = $category->cat_name;
                        }
                        if (is_array($array_cat)) {
                            $categories_string = implode(",", $array_cat);
                        }
                    }
                    $meta_facebook = '
<!-- open graph data -->
<meta property="og:title" content="' . $meta_title_custom . '" />
<meta property="og:description" content="' . $meta_description_custom . '" />
<meta property="og:url" content="' . get_permalink() . '" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="' . get_locale() . '" />
<meta property="og:image" content="' . $image_post . '" />
<meta property="article:section" content="' . $categories_string . '" />
<meta property="og:site_name" content="' . get_bloginfo('name') . '" />';
                }
                if (isset($ilen_seo->twitter_user) && $ilen_seo->twitter_user) {
                    $meta_twitter = '
<!-- twitter card data -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@' . $ilen_seo->twitter_user . '" />
<meta name="twitter:title" content="' . $meta_title_custom . '" />
<meta name="twitter:description" content="' . $meta_description_custom . '" />
<meta name="twitter:image" content="' . $image_post . '" />';
                }
            } elseif (is_category()) {
                $current_url = rtrim($_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"], "/");
                $arr_current_url = explode("/", $current_url);
                $thecategory = get_category_by_slug(end($arr_current_url));
                //$category      = get_the_category();
                $category_desc = $thecategory->description;
                $category_name = $thecategory->name;
                $category_id = $thecategory->term_id;
                if (isset($ilen_seo->facebook_open_graph) && $ilen_seo->facebook_open_graph) {
                    $meta_facebook = '
<!-- open graph data -->
<meta property="og:title" content="' . $category_name . '" />
<meta property="og:description" content="' . $category_desc . '" />
<meta property="og:url" content="' . get_category_link($category_id) . '" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="' . get_locale() . '" />
<meta property="article:section" content="' . $category_name . '" />
<meta property="og:site_name" content="' . get_bloginfo('name') . '" />
<meta property="og:image" content="' . $image_post . '" />';
                }
                if (isset($ilen_seo->twitter_user) && $ilen_seo->twitter_user) {
                    $meta_twitter = '
<!-- twitter card data -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@' . $ilen_seo->twitter_user . '" />
<meta name="twitter:title" content="' . $category_name . '" />
<meta name="twitter:description" content="' . $category_desc . '" />
<meta name="twitter:image" content="' . $image_post . '" />';
                }
            } elseif (is_search()) {
                $meta_description = "";
            } elseif (is_day()) {
                $meta_description = "";
            } elseif (is_month()) {
                $meta_description = "";
            } elseif (is_year()) {
                $meta_description = "";
            } elseif (is_author()) {
                if ($des_aut = get_the_author_meta('description', $authordata->ID)) {
                    $meta_description = htmlspecialchars($des_aut, ENT_QUOTES | 'ENT_HTML5');
                }
                if (isset($ilen_seo->facebook_open_graph) && $ilen_seo->facebook_open_graph) {
                    $meta_facebook = '
<!-- open graph data -->
<meta property="og:title" content="' . $authordata->display_name . '" />
<meta property="og:description" content="' . $meta_description . '" />
<meta property="og:url" content="' . get_author_posts_url($authordata->ID) . '" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="' . get_locale() . '" />
<meta property="og:site_name" content="' . get_bloginfo('name') . '" />
<meta property="og:image" content="' . $image_post . '" />
';
                }
                if (isset($ilen_seo->twitter_user) && $ilen_seo->twitter_user) {
                    $meta_twitter = '<!-- twitter card data -->
<meta name="twitter:card" content="summary" />
<meta name="twitter:site" content="@' . $ilen_seo->twitter_user . '" />
<meta name="twitter:title" content="' . $authordata->display_name . '" />
<meta name="twitter:description" content="' . $meta_description . '" />
<meta name="twitter:image" content="' . $image_post . '" />
';
                }
            } elseif (is_404()) {
                $meta_description = "";
            }
            if ($meta_description) {
                $meta_description = '
<meta name="description" content="' . htmlspecialchars($meta_description, ENT_QUOTES | 'ENT_HTML5') . '" />';
            }
            if (isset($ilen_seo->google_publisher) && $ilen_seo->google_publisher) {
                $meta_google = '
<!-- google publisher -->
<link href="' . $ilen_seo->google_publisher . '" rel="publisher" />
';
            }
            echo "\n<!-- This site is optimized with the WordPress Bubble SEO  plugin v" . $this->parameter['version'] . "- https://wordpress.org/plugins/bubble-seo/  -->" . $meta_description . $meta_keyword . $meta_facebook . $meta_twitter . $meta_google . "<!-- /Bubble SEO -->\n\n";
        }
 /**
  * @since 1.4
  */
 private function _build_email($type, $post_id)
 {
     $email_subject = get_option("bbpress_notify_new{$type}_email_subject");
     $email_body = get_option("bbpress_notify_new{$type}_email_body");
     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $excerpt_size = apply_filters('bpnns_excerpt_size', 100);
     // Replace shortcodes
     if ('topic' === $type) {
         $content = bbp_get_topic_content($post_id);
         $title = html_entity_decode(strip_tags(bbp_get_topic_title($post_id)), ENT_NOQUOTES, 'UTF-8');
         $excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($post_id, $excerpt_size)), ENT_NOQUOTES, 'UTF-8');
         $author = bbp_get_topic_author($post_id);
         $url = apply_filters('bbpnns_topic_url', bbp_get_topic_permalink($post_id), $post_id, $title);
         $forum = html_entity_decode(strip_tags(get_the_title(bbp_get_topic_forum_id($post_id))), ENT_NOQUOTES, 'UTF-8');
     } elseif ('reply' === $type) {
         $content = bbp_get_reply_content($post_id);
         $title = html_entity_decode(strip_tags(bbp_get_reply_title($post_id)), ENT_NOQUOTES, 'UTF-8');
         $excerpt = html_entity_decode(strip_tags(bbp_get_reply_excerpt($post_id, $excerpt_size)), ENT_NOQUOTES, 'UTF-8');
         $author = bbp_get_reply_author($post_id);
         $url = apply_filters('bbpnns_reply_url', bbp_get_reply_permalink($post_id), $post_id, $title);
         $forum = html_entity_decode(strip_tags(get_the_title(bbp_get_reply_forum_id($post_id))), ENT_NOQUOTES, 'UTF-8');
     } else {
         wp_die('Invalid type!');
     }
     $content = preg_replace('/<br\\s*\\/?>/is', PHP_EOL, $content);
     $content = preg_replace('/(?:<\\/p>\\s*<p>)/ism', PHP_EOL . PHP_EOL, $content);
     $content = html_entity_decode(strip_tags($content), ENT_NOQUOTES, 'UTF-8');
     $topic_reply = apply_filters('bbpnns_topic_reply', bbp_get_reply_url($post_id), $post_id, $title);
     $email_subject = str_replace('[blogname]', $blogname, $email_subject);
     $email_subject = str_replace("[{$type}-title]", $title, $email_subject);
     $email_subject = str_replace("[{$type}-content]", $content, $email_subject);
     $email_subject = str_replace("[{$type}-excerpt]", $excerpt, $email_subject);
     $email_subject = str_replace("[{$type}-author]", $author, $email_subject);
     $email_subject = str_replace("[{$type}-url]", $url, $email_subject);
     $email_subject = str_replace("[{$type}-replyurl]", $topic_reply, $email_subject);
     $email_subject = str_replace("[{$type}-forum]", $forum, $email_subject);
     $email_body = str_replace('[blogname]', $blogname, $email_body);
     $email_body = str_replace("[{$type}-title]", $title, $email_body);
     $email_body = str_replace("[{$type}-content]", $content, $email_body);
     $email_body = str_replace("[{$type}-excerpt]", $excerpt, $email_body);
     $email_body = str_replace("[{$type}-author]", $author, $email_body);
     $email_body = str_replace("[{$type}-url]", $url, $email_body);
     $email_body = str_replace("[{$type}-replyurl]", $topic_reply, $email_body);
     $email_body = str_replace("[{$type}-forum]", $forum, $email_body);
     /**
      * Allow subject and body modifications
      * @since 1.6.6
      */
     $email_subject = apply_filters('bbpnns_filter_email_subject_in_build', $email_subject, $type, $post_id);
     $email_body = apply_filters('bbpnns_filter_email_body_in_build', $email_body, $type, $post_id);
     return array($email_subject, $email_body);
 }
Beispiel #13
0
 /**
  * @covers ::bbp_topic_content
  * @covers ::bbp_get_topic_content
  */
 public function test_bbp_get_topic_content()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_content' => 'Content of Topic 1', 'post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     remove_all_filters('bbp_get_topic_content');
     $topic_content = bbp_get_topic_content($t);
     $this->assertSame('Content of Topic 1', $topic_content);
 }
Beispiel #14
0
 function wm_bbp_large_topic()
 {
     global $paged;
     //Requirements check
     if (!(bbp_is_single_topic() || bbp_is_single_reply())) {
         return;
     }
     //Helper variables
     $output = array();
     $post_id = bbp_is_single_reply() ? bbp_get_reply_topic_id() : get_the_id();
     //Preparing output
     $output[10] = '<div class="bbp-large-topic">';
     $output[20] = '<div class="wrap-inner">';
     $output[30] = '<div class="content-area site-content pane twelve">';
     $output[100] = '<div ' . bbp_get_reply_class() . wm_schema_org('article') . '>';
     //Author
     $output[110] = '<div class="bbp-reply-author">';
     $output[120] = bbp_get_reply_author_link(array('post_id' => $post_id, 'sep' => '<br />', 'show_role' => true));
     $output[130] = '</div>';
     // /.bbp-reply-author
     //Heading and content
     $output[200] = '<div class="bbp-reply-content">';
     $output[210] = '<h1 class="bbp-topic-title">';
     if (1 < $paged) {
         $output[210] .= '<a href="' . get_permalink($post_id) . '">';
     }
     $output[210] .= bbp_get_topic_title($post_id);
     if (1 < $paged) {
         $output[210] .= '</a> ' . wm_paginated_suffix('small');
     }
     $output[210] .= '</h1>';
     $output[220] = bbp_get_topic_tag_list($post_id);
     if (!post_password_required($post_id)) {
         $output[230] = '<div class="bbp-content-container">';
         setup_postdata(get_post($post_id));
         $output[240] = apply_filters('wmhook_content_filters', bbp_get_topic_content($post_id), $post_id);
         wp_reset_postdata();
         $output[250] = '</div>';
         // /.bbp-content-container
     }
     $output[260] = '</div>';
     // /.bbp-reply-content
     //Meta
     $output[300] = '<div class="bbp-meta">';
     $output[310] = '<span class="bbp-reply-post-date">' . bbp_get_reply_post_date($post_id) . '</span>';
     if (bbp_is_single_user_replies()) {
         $output[320] = '<span class="bbp-header">';
         $output[330] = __('in reply to: ', 'mustang');
         $output[340] = '<a class="bbp-topic-permalink" href="' . bbp_get_topic_permalink(bbp_get_reply_topic_id($post_id)) . '">';
         $output[350] = bbp_get_topic_title(bbp_get_reply_topic_id($post_id));
         $output[360] = '</a>';
         // /.bbp-topic-permalink
         $output[370] = '</span>';
         // /.bbp-header
     }
     $output[380] = bbp_get_reply_admin_links(array('id' => $post_id));
     $output[390] = '</div>';
     // /.bbp-meta
     $output[500] = '</div>';
     // /.bbp_get_reply_class()
     $output[600] = '</div>';
     // /.content-area
     $output[610] = '</div>';
     // /.wrap-inner
     $output[620] = '</div>';
     // /.bbp-large-topic
     //Output
     $output = apply_filters('wmhook_wm_bbp_large_topic_output', $output, $post_id);
     echo implode('', $output);
 }
Beispiel #15
0
 /**
  * @group canonical
  * @covers ::bbp_create_initial_content
  */
 public function test_bbp_create_initial_content()
 {
     $category_id = $this->factory->forum->create(array('forum_meta' => array('_bbp_forum_type' => 'category', '_bbp_status' => 'open')));
     bbp_create_initial_content(array('forum_parent' => $category_id));
     $forum_id = bbp_forum_query_subforum_ids($category_id);
     $forum_id = (int) $forum_id[0];
     $topic_id = bbp_get_forum_last_topic_id($forum_id);
     $reply_id = bbp_get_forum_last_reply_id($forum_id);
     // Forum post
     $this->assertSame('General', bbp_get_forum_title($forum_id));
     $this->assertSame('General chit-chat', bbp_get_forum_content($forum_id));
     $this->assertSame('open', bbp_get_forum_status($forum_id));
     $this->assertTrue(bbp_is_forum_public($forum_id));
     $this->assertSame($category_id, bbp_get_forum_parent_id($forum_id));
     // Topic post
     $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame('Hello World!', bbp_get_topic_title($topic_id));
     remove_all_filters('bbp_get_topic_content');
     $topic_content = "I am the first topic in your new forums.";
     $this->assertSame($topic_content, bbp_get_topic_content($topic_id));
     $this->assertSame('publish', bbp_get_topic_status($topic_id));
     $this->assertTrue(bbp_is_topic_published($topic_id));
     // Reply post
     $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame('Reply To: Hello World!', bbp_get_reply_title($reply_id));
     $this->assertSame($reply_id, bbp_get_reply_title_fallback($reply_id));
     remove_all_filters('bbp_get_reply_content');
     $reply_content = "Oh, and this is what a reply looks like.";
     $this->assertSame($reply_content, bbp_get_reply_content($reply_id));
     $this->assertSame('publish', bbp_get_reply_status($reply_id));
     $this->assertTrue(bbp_is_reply_published($reply_id));
     // Category meta
     $this->assertSame(1, bbp_get_forum_subforum_count($category_id, true));
     $this->assertSame(0, bbp_get_forum_topic_count($category_id, false, true));
     $this->assertSame(0, bbp_get_forum_topic_count_hidden($category_id, true));
     $this->assertSame(0, bbp_get_forum_reply_count($category_id, false, true));
     $this->assertSame(1, bbp_get_forum_topic_count($category_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($category_id, true, true));
     $this->assertSame(0, bbp_get_forum_post_count($category_id, false, true));
     $this->assertSame(2, bbp_get_forum_post_count($category_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($category_id));
     $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($category_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($category_id));
     $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($category_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($category_id));
     $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($category_id));
     // Forum meta
     $this->assertSame(0, bbp_get_forum_subforum_count($forum_id, true));
     $this->assertSame(1, bbp_get_forum_topic_count($forum_id, false, true));
     $this->assertSame(0, bbp_get_forum_topic_count_hidden($forum_id, true));
     $this->assertSame(1, bbp_get_forum_reply_count($forum_id, false, true));
     $this->assertSame(1, bbp_get_forum_topic_count($forum_id, true, true));
     $this->assertSame(1, bbp_get_forum_reply_count($forum_id, true, true));
     $this->assertSame(2, bbp_get_forum_post_count($forum_id, false, true));
     $this->assertSame(2, bbp_get_forum_post_count($forum_id, true, true));
     $this->assertSame($topic_id, bbp_get_forum_last_topic_id($forum_id));
     $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_reply_id($forum_id));
     $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($forum_id));
     $this->assertSame($reply_id, bbp_get_forum_last_active_id($forum_id));
     $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($forum_id));
     // Topic meta
     $this->assertSame('127.0.0.1', bbp_current_author_ip($topic_id));
     $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id));
     $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true));
     $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true));
     $this->assertSame(0, bbp_get_topic_reply_count_hidden($topic_id, true));
     $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id));
     $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id));
     $this->assertSame('1 day, 16 hours ago', bbp_get_topic_last_active_time($topic_id));
     // Reply Meta
     $this->assertSame('127.0.0.1', bbp_current_author_ip($reply_id));
     $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id));
     $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id));
 }
Beispiel #16
0
/**
 * Return the excerpt of the topic
 *
 * @since 2.0.0 bbPress (r2780)
 *
 * @param int $topic_id Optional. topic id
 * @param int $length Optional. Length of the excerpt. Defaults to 100
 *                     letters
 * @uses bbp_get_topic_id() To get the topic id
 * @uses get_post_field() To get the excerpt
 * @uses bbp_get_topic_content() To get the topic content
 * @uses apply_filters() Calls 'bbp_get_topic_excerpt' with the excerpt,
 *                        topic id and length
 * @return string topic Excerpt
 */
function bbp_get_topic_excerpt($topic_id = 0, $length = 100)
{
    $topic_id = bbp_get_topic_id($topic_id);
    $length = (int) $length;
    $excerpt = get_post_field('post_excerpt', $topic_id);
    if (empty($excerpt)) {
        $excerpt = bbp_get_topic_content($topic_id);
    }
    $excerpt = trim(strip_tags($excerpt));
    // Multibyte support
    if (function_exists('mb_strlen')) {
        $excerpt_length = mb_strlen($excerpt);
    } else {
        $excerpt_length = strlen($excerpt);
    }
    if (!empty($length) && $excerpt_length > $length) {
        $excerpt = substr($excerpt, 0, $length - 1);
        $excerpt .= '&hellip;';
    }
    return apply_filters('bbp_get_topic_excerpt', $excerpt, $topic_id, $length);
}
 /**
  * Record an activity stream entry when a topic is created
  *
  * @since bbPress (r3395)
  * @param int $topic_id
  * @param int $forum_id
  * @param array $anonymous_data
  * @param int $topic_author_id
  * @uses bbp_get_topic_id()
  * @uses bbp_get_forum_id()
  * @uses bbp_get_user_profile_link()
  * @uses bbp_get_topic_permalink()
  * @uses bbp_get_topic_title()
  * @uses bbp_get_topic_content()
  * @uses bbp_get_forum_permalink()
  * @uses bbp_get_forum_title()
  * @uses bp_create_excerpt()
  * @uses apply_filters()
  * @return Bail early if topic is by anonywous user
  */
 public function topic_create($topic_id, $forum_id, $anonymous_data, $topic_author_id)
 {
     // Bail early if topic is by anonywous user
     if (!empty($anonymous_data)) {
         return;
     }
     // Bail if site is private
     if (!bbp_is_site_public()) {
         return;
     }
     // Validate activity data
     $user_id = $topic_author_id;
     $topic_id = bbp_get_topic_id($topic_id);
     $forum_id = bbp_get_forum_id($forum_id);
     // Bail if user is not active
     if (bbp_is_user_inactive($user_id)) {
         return;
     }
     // Bail if topic is not published
     if (!bbp_is_topic_published($topic_id)) {
         return;
     }
     // Bail if forum is not public
     if (!bbp_is_forum_public($forum_id, false)) {
         return;
     }
     // User link for topic author
     $user_link = bbp_get_user_profile_link($user_id);
     // Topic
     $topic_permalink = bbp_get_topic_permalink($topic_id);
     $topic_title = bbp_get_topic_title($topic_id);
     $topic_content = bbp_get_topic_content($topic_id);
     $topic_link = '<a href="' . $topic_permalink . '" title="' . $topic_title . '">' . $topic_title . '</a>';
     // Forum
     $forum_permalink = bbp_get_forum_permalink($forum_id);
     $forum_title = bbp_get_forum_title($forum_id);
     $forum_link = '<a href="' . $forum_permalink . '" title="' . $forum_title . '">' . $forum_title . '</a>';
     // Activity action & text
     $activity_text = sprintf(__('%1$s started the topic %2$s in the forum %3$s', 'bbpress'), $user_link, $topic_link, $forum_link);
     $activity_action = apply_filters('bbp_activity_topic_create', $activity_text, $user_id, $topic_id, $forum_id);
     $activity_content = apply_filters('bbp_activity_topic_create_excerpt', bp_create_excerpt($topic_content), $topic_content);
     // Compile the activity stream results
     $activity = array('user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $topic_permalink, 'type' => $this->topic_create, 'item_id' => $topic_id, 'secondary_item_id' => $forum_id);
     // Record the activity
     $activity_id = $this->record_activity($activity);
     // Add the activity entry ID as a meta value to the topic
     if (!empty($activity_id)) {
         update_post_meta($topic_id, '_bbp_activity_id', $activity_id);
     }
 }
 /**
  * send_notification()
  *
  * Send the notification e-mails to the addresses defined in options
  */
 function send_notification($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0)
 {
     // Grab stuff we will be needing for the email
     $recipients = $this->get_recipients();
     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     $topic_title = html_entity_decode(strip_tags(bbp_get_topic_title($topic_id)), ENT_NOQUOTES, 'UTF-8');
     $topic_content = html_entity_decode(strip_tags(bbp_get_topic_content($topic_id)), ENT_NOQUOTES, 'UTF-8');
     $topic_excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($topic_id, 100)), ENT_NOQUOTES, 'UTF-8');
     $topic_author = bbp_get_topic_author($topic_id);
     $topic_url = bbp_get_topic_permalink($topic_id);
     // Get the template
     $email_template = get_option('ja_bbp_notification_email_template');
     // Swap out the shortcodes with useful information :)
     $find = array('[topic-title]', '[topic-content]', '[topic-excerpt]', '[topic-author]', '[topic-url]');
     $replace = array($topic_title, $topic_content, $topic_excerpt, $topic_author, $topic_url);
     $email_body = str_replace($find, $replace, $email_template);
     $email_subject = $blogname . __(' new topic', 'ja_bbp_notifications') . ' - ' . $topic_title;
     if (!empty($recipients)) {
         // Send email to each user
         foreach ($recipients as $recipient) {
             @wp_mail($recipient, $email_subject, $email_body);
         }
     }
 }
Beispiel #19
0
 /**
  * @covers ::bbp_check_for_blacklist
  */
 public function test_should_return_false_when_html_wrapped_content_matches_blacklist_keys()
 {
     $u = $this->factory->user->create();
     $t = $this->factory->topic->create(array('post_author' => $u, 'post_title' => 'Sting', 'post_content' => 'Beware, there maybe bees <strong>hiber</strong><em>nating</em>.'));
     $anonymous_data = false;
     $author_id = bbp_get_topic_author_id($t);
     $title = bbp_get_topic_title($t);
     $content = bbp_get_topic_content($t);
     update_option('blacklist_keys', "hibernating\nfoo");
     $result = bbp_check_for_blacklist($anonymous_data, $author_id, $title, $content);
     $this->assertFalse($result);
 }
function new_reply_notification($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0, $is_edit = false, $reply_to = 0)
{
    $admin_email = get_option('admin_email');
    $user_id = (int) $reply_author_id;
    $reply_id = bbp_get_reply_id($reply_id);
    $topic_id = bbp_get_topic_id($topic_id);
    $forum_id = bbp_get_forum_id($forum_id);
    $email_subject = get_option('bbpress_notify_newreply_email_subject');
    $email_body = get_option('bbpress_notify_newreply_email_body');
    $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    $topic_title = html_entity_decode(strip_tags(bbp_get_topic_title($topic_id)), ENT_NOQUOTES, 'UTF-8');
    $topic_content = html_entity_decode(strip_tags(bbp_get_topic_content($topic_id)), ENT_NOQUOTES, 'UTF-8');
    $topic_excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($topic_id, 100)), ENT_NOQUOTES, 'UTF-8');
    $topic_author = bbp_get_topic_author($topic_id);
    $topic_url = bbp_get_topic_permalink($topic_id);
    $topic_reply = bbp_get_reply_url($topic_id);
    $reply_url = bbp_get_reply_url($reply_id);
    $reply_content = get_post_field('post_content', $reply_id, 'raw');
    $reply_author = bbp_get_topic_author($user_id);
    $email_subject = $blog_name . " New Reply Alert: " . $topic_title;
    $email_body = $blog_name . ": {$topic_title}\n\r";
    $email_body .= $reply_content;
    $email_body .= "\n\r--------------------------------\n\r";
    $email_body .= "Reply Url: " . $reply_url . "\n\rAuthor: {$reply_author}" . "\n\rYou can reply at: {$reply_url}";
    @wp_mail($admin_email, $email_subject, $email_body);
}