Example #1
0
 /**
  * @covers ::bbp_topic_reply_count_hidden
  * @covers ::bbp_get_topic_reply_count_hidden
  */
 public function test_bbp_get_topic_reply_count_hidden()
 {
     $f = $this->factory->forum->create();
     $int_value = 3;
     $formatted_value = bbp_number_format($int_value);
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create_many($int_value, array('post_parent' => $t, 'post_status' => bbp_get_spam_status_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     bbp_update_topic_reply_count_hidden($t);
     bbp_spam_reply($r[1]);
     // Output
     $this->expectOutputString($formatted_value);
     bbp_topic_reply_count_hidden($t);
     // Formatted string
     $count = bbp_get_topic_reply_count_hidden($t, false);
     $this->assertSame($formatted_value, $count);
     // Integer
     $count = bbp_get_topic_reply_count_hidden($t, true);
     $this->assertSame($int_value, $count);
 }
Example #2
0
 /**
  * @covers ::bbp_decrease_forum_topic_count_hidden
  */
 public function test_bbp_decrease_forum_topic_count_hidden()
 {
     $f = $this->factory->forum->create();
     $count = bbp_get_forum_topic_count_hidden($f);
     $this->assertSame('0', $count);
     $t = $this->factory->topic->create_many(2, array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id(), 'topic_meta' => array('forum_id' => $f, 'spam_meta_status' => 'publish')));
     bbp_update_forum_topic_count_hidden($f);
     $count = bbp_get_forum_topic_count_hidden($f);
     $this->assertSame('2', $count);
     bbp_decrease_forum_topic_count_hidden($f);
     $count = bbp_get_forum_topic_count_hidden($f);
     $this->assertSame('1', $count);
 }
Example #3
0
 /**
  * Add forum dropdown to topic and reply list table filters
  *
  * @since 2.0.0 bbPress (r2991)
  *
  * @uses bbp_get_reply_post_type() To get the reply post type
  * @uses bbp_get_topic_post_type() To get the topic post type
  * @uses bbp_dropdown() To generate a forum dropdown
  * @return bool False. If post type is not topic or reply
  */
 public function filter_dropdown()
 {
     if ($this->bail()) {
         return;
     }
     // Add Empty Spam button
     if (!empty($_GET['post_status']) && bbp_get_spam_status_id() === $_GET['post_status'] && current_user_can('moderate')) {
         wp_nonce_field('bulk-destroy', '_destroy_nonce');
         $title = esc_attr__('Empty Spam', 'bbpress');
         submit_button($title, 'button-secondary apply', 'delete_all', false);
     }
     // Get which forum is selected
     $selected = !empty($_GET['bbp_forum_id']) ? $_GET['bbp_forum_id'] : '';
     // Show the forums dropdown
     bbp_dropdown(array('selected' => $selected, 'show_none' => __('In all forums', 'bbpress')));
 }
Example #4
0
/**
 * Unspams a topic
 *
 * @since bbPress (r2740)
 *
 * @param int $topic_id Topic id
 * @uses bbp_get_topic() To get the topic
 * @uses do_action() Calls 'bbp_unspam_topic' with the topic id
 * @uses get_post_meta() To get the previous status
 * @uses delete_post_meta() To delete the previous status meta
 * @uses wp_update_post() To update the topic with the new status
 * @uses do_action() Calls 'bbp_unspammed_topic' with the topic id
 * @return mixed False or {@link WP_Error} on failure, topic id on success
 */
function bbp_unspam_topic($topic_id = 0)
{
    // Get the topic
    $topic = bbp_get_topic($topic_id);
    if (empty($topic)) {
        return $topic;
    }
    // Bail if already not spam
    if (bbp_get_spam_status_id() !== $topic->post_status) {
        return false;
    }
    // Execute pre unspam code
    do_action('bbp_unspam_topic', $topic_id);
    /** Untrash Replies *******************************************************/
    // Get the replies that were not previously trashed
    $pre_spammed_replies = get_post_meta($topic_id, '_bbp_pre_spammed_replies', true);
    // There are replies to untrash
    if (!empty($pre_spammed_replies)) {
        // Maybe reverse the trashed replies array
        if (is_array($pre_spammed_replies)) {
            $pre_spammed_replies = array_reverse($pre_spammed_replies);
        }
        // Loop through replies
        foreach ((array) $pre_spammed_replies as $reply) {
            wp_untrash_post($reply);
        }
    }
    /** Topic Tags ************************************************************/
    // Get pre-spam topic tags
    $terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true);
    // Topic had tags before it was spammed
    if (!empty($terms)) {
        // Set the tax_input of the topic
        $topic->tax_input = array(bbp_get_topic_tag_tax_id() => $terms);
        // Delete pre-spam topic tag meta
        delete_post_meta($topic_id, '_bbp_spam_topic_tags');
    }
    /** Topic Status **********************************************************/
    // Get pre spam status
    $topic_status = get_post_meta($topic_id, '_bbp_spam_meta_status', true);
    // If no previous status, default to publish
    if (empty($topic_status)) {
        $topic_status = bbp_get_public_status_id();
    }
    // Set post status to pre spam
    $topic->post_status = $topic_status;
    // Delete pre spam meta
    delete_post_meta($topic_id, '_bbp_spam_meta_status');
    // No revisions
    remove_action('pre_post_update', 'wp_save_post_revision');
    // Update the topic
    $topic_id = wp_update_post($topic);
    // Execute post unspam code
    do_action('bbp_unspammed_topic', $topic_id);
    // Return topic_id
    return $topic_id;
}
Example #5
0
/**
 * Return admin links for reply
 *
 * @since bbPress (r2667)
 *
 * @param array $args This function supports these arguments:
 *  - id: Optional. Reply id
 *  - before: HTML before the links. Defaults to
 *             '<span class="bbp-admin-links">'
 *  - after: HTML after the links. Defaults to '</span>'
 *  - sep: Separator. Defaults to ' | '
 *  - links: Array of the links to display. By default, edit, trash,
 *            spam, reply move, and topic split links are displayed
 * @uses bbp_is_topic() To check if it's the topic page
 * @uses bbp_is_reply() To check if it's the reply page
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_edit_link() To get the reply edit link
 * @uses bbp_get_reply_trash_link() To get the reply trash link
 * @uses bbp_get_reply_spam_link() To get the reply spam link
 * @uses bbp_get_reply_move_link() To get the reply move link
 * @uses bbp_get_topic_split_link() To get the topic split link
 * @uses current_user_can() To check if the current user can edit or
 *                           delete the reply
 * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the
 *                        reply admin links and args
 * @return string Reply admin links
 */
function bbp_get_reply_admin_links($args = array())
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array()), 'get_reply_admin_links');
    $r['id'] = bbp_get_reply_id((int) $r['id']);
    // If post is a topic, return the topic admin links instead
    if (bbp_is_topic($r['id'])) {
        return bbp_get_topic_admin_links($args);
    }
    // If post is not a reply, return
    if (!bbp_is_reply($r['id'])) {
        return;
    }
    // If topic is trashed, do not show admin links
    if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) {
        return;
    }
    // If no links were passed, default to the standard
    if (empty($r['links'])) {
        $r['links'] = apply_filters('bbp_reply_admin_links', array('edit' => bbp_get_reply_edit_link($r), 'move' => bbp_get_reply_move_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r), 'reply' => bbp_get_reply_to_link($r)), $r['id']);
    }
    // See if links need to be unset
    $reply_status = bbp_get_reply_status($r['id']);
    if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) {
        // Spam link shouldn't be visible on trashed topics
        if (bbp_get_trash_status_id() === $reply_status) {
            unset($r['links']['spam']);
            // Trash link shouldn't be visible on spam topics
        } elseif (bbp_get_spam_status_id() === $reply_status) {
            unset($r['links']['trash']);
        }
    }
    // Process the admin links
    $links = implode($r['sep'], array_filter($r['links']));
    $retval = $r['before'] . $links . $r['after'];
    return apply_filters('bbp_get_reply_admin_links', $retval, $r, $args);
}
Example #6
0
/**
 * Recount topic hidden replies (spammed/trashed)
 *
 * @since bbPress (r2747)
 *
 * @uses wpdb::query() To run our recount sql queries
 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
 * @return array An array of the status code and the message
 */
function bbp_admin_repair_topic_hidden_reply_count()
{
    global $wpdb;
    $statement = __('Counting the number of spammed and trashed replies in each topic&hellip; %s', 'bbpress');
    $result = __('Failed!', 'bbpress');
    $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden';";
    if (is_wp_error($wpdb->query($sql_delete))) {
        return array(1, sprintf($statement, $result));
    }
    $sql = "INSERT INTO `{$wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` IN ( '" . implode("','", array(bbp_get_trash_status_id(), bbp_get_spam_status_id())) . "') GROUP BY `post_parent`);";
    if (is_wp_error($wpdb->query($sql))) {
        return array(2, sprintf($statement, $result));
    }
    return array(0, sprintf($statement, __('Complete!', 'bbpress')));
}
/**
 * Unspams a reply
 *
 * @since bbPress (r2740)
 *
 * @param int $reply_id Reply id
 * @uses bbp_get_reply() To get the reply
 * @uses do_action() Calls 'bbp_unspam_reply' with the reply ID
 * @uses get_post_meta() To get the previous status meta
 * @uses delete_post_meta() To delete the previous status meta
 * @uses wp_update_post() To insert the updated post
 * @uses do_action() Calls 'bbp_unspammed_reply' with the reply ID
 * @return mixed False or {@link WP_Error} on failure, reply id on success
 */
function bbp_unspam_reply($reply_id = 0)
{
    // Get reply
    $reply = bbp_get_reply($reply_id);
    if (empty($reply)) {
        return $reply;
    }
    // Bail if already not spam
    if (bbp_get_spam_status_id() !== $reply->post_status) {
        return false;
    }
    // Execute pre unspam code
    do_action('bbp_unspam_reply', $reply_id);
    // Get pre spam status
    $reply->post_status = get_post_meta($reply_id, '_bbp_spam_meta_status', true);
    // If no previous status, default to publish
    if (empty($reply->post_status)) {
        $reply->post_status = bbp_get_public_status_id();
    }
    // Delete pre spam meta
    delete_post_meta($reply_id, '_bbp_spam_meta_status');
    // No revisions
    remove_action('pre_post_update', 'wp_save_post_revision');
    // Update the reply
    $reply_id = wp_update_post($reply);
    // Execute post unspam code
    do_action('bbp_unspammed_reply', $reply_id);
    // Return reply_id
    return $reply_id;
}
Example #8
0
/**
 * Unspams a topic
 *
 * @since bbPress (r2740)
 *
 * @param int $topic_id Topic id
 * @uses wp_get_single_post() To get the topic
 * @uses do_action() Calls 'bbp_unspam_topic' with the topic id
 * @uses get_post_meta() To get the previous status
 * @uses delete_post_meta() To delete the previous status meta
 * @uses wp_insert_post() To update the topic with the new status
 * @uses do_action() Calls 'bbp_unspammed_topic' with the topic id
 * @return mixed False or {@link WP_Error} on failure, topic id on success
 */
function bbp_unspam_topic($topic_id = 0)
{
    // Get the topic
    if (!($topic = wp_get_single_post($topic_id, ARRAY_A))) {
        return $topic;
    }
    // Bail if already not spam
    if (bbp_get_spam_status_id() != $topic['post_status']) {
        return false;
    }
    // Execute pre unspam code
    do_action('bbp_unspam_topic', $topic_id);
    // Get pre spam status
    $topic_status = get_post_meta($topic_id, '_bbp_spam_meta_status', true);
    // Set post status to pre spam
    $topic['post_status'] = $topic_status;
    // Delete pre spam meta
    delete_post_meta($topic_id, '_bbp_spam_meta_status');
    // No revisions
    remove_action('pre_post_update', 'wp_save_post_revision');
    // Get pre-spam topic tags
    $terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true);
    // Topic had tags before it was spammed
    if (!empty($terms)) {
        // Set the tax_input of the topic
        $topic['tax_input'] = array(bbp_get_topic_tag_tax_id() => $terms);
        // Delete pre-spam topic tag meta
        delete_post_meta($topic_id, '_bbp_spam_topic_tags');
    }
    // Update the topic
    $topic_id = wp_insert_post($topic);
    // Execute post unspam code
    do_action('bbp_unspammed_topic', $topic_id);
    // Return topic_id
    return $topic_id;
}
Example #9
0
/**
 * Adjust the total hidden topic count of a forum (hidden includes trashed,
 * spammed and pending topics)
 *
 * @since 2.0.0 bbPress (r2888)
 * @since 2.6.0 bbPress (r5954) Replace direct queries with WP_Query() objects
 *
 * @param int $forum_id Optional. Topic id to update.
 * @param int $topic_count Optional. Set the topic count manually.
 * @uses bbp_is_topic() To check if the supplied id is a topic
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic_forum_id() To get the topic forum id
 * @uses bbp_get_forum_id() To get the forum id
 * @uses bbp_get_trash_status_id() To get the trash status id
 * @uses bbp_get_spam_status_id() To get the spam status id
 * @uses bbp_get_pending_status_id() To get the pending status id
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses update_post_meta() To update the forum hidden topic count meta
 * @uses apply_filters() Calls 'bbp_update_forum_topic_count_hidden' with the
 *                        hidden topic count and forum id
 * @return int Topic hidden topic count
 */
function bbp_update_forum_topic_count_hidden($forum_id = 0, $topic_count = 0)
{
    // If topic_id was passed as $forum_id, then get its forum
    if (bbp_is_topic($forum_id)) {
        $topic_id = bbp_get_topic_id($forum_id);
        $forum_id = bbp_get_topic_forum_id($topic_id);
        // $forum_id is not a topic_id, so validate and proceed
    } else {
        $forum_id = bbp_get_forum_id($forum_id);
    }
    // Can't update what isn't there
    if (!empty($forum_id)) {
        // Get topics of forum
        if (empty($topic_count)) {
            $query = new WP_Query(array('fields' => 'ids', 'post_parent' => $forum_id, 'post_status' => array(bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id()), 'post_type' => bbp_get_topic_post_type(), 'posts_per_page' => -1, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'ignore_sticky_posts' => true));
            $topic_count = $query->post_count;
            unset($query);
        }
        $topic_count = (int) $topic_count;
        // Update the count
        update_post_meta($forum_id, '_bbp_topic_count_hidden', $topic_count);
    }
    return (int) apply_filters('bbp_update_forum_topic_count_hidden', $topic_count, $forum_id);
}
Example #10
0
/**
 * Return admin links for reply
 *
 * @since bbPress (r2667)
 *
 * @param mixed $args This function supports these arguments:
 *  - id: Optional. Reply id
 *  - before: HTML before the links. Defaults to
 *             '<span class="bbp-admin-links">'
 *  - after: HTML after the links. Defaults to '</span>'
 *  - sep: Separator. Defaults to ' | '
 *  - links: Array of the links to display. By default, edit, trash,
 *            spam and topic split links are displayed
 * @uses bbp_is_topic() To check if it's the topic page
 * @uses bbp_is_reply() To check if it's the reply page
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_edit_link() To get the reply edit link
 * @uses bbp_get_reply_trash_link() To get the reply trash link
 * @uses bbp_get_reply_spam_link() To get the reply spam link
 * @uses bbp_get_topic_split_link() To get the topic split link
 * @uses current_user_can() To check if the current user can edit or
 *                           delete the reply
 * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the
 *                        reply admin links and args
 * @return string Reply admin links
 */
function bbp_get_reply_admin_links($args = '')
{
    $defaults = array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array());
    $r = bbp_parse_args($args, $defaults, 'get_reply_admin_links');
    $r['id'] = bbp_get_reply_id((int) $r['id']);
    // If post is a topic, return the topic admin links instead
    if (bbp_is_topic($r['id'])) {
        return bbp_get_topic_admin_links($args);
    }
    // If post is not a reply, return
    if (!bbp_is_reply($r['id'])) {
        return;
    }
    // Make sure user can edit this reply
    if (!current_user_can('edit_reply', $r['id'])) {
        return;
    }
    // If topic is trashed, do not show admin links
    if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) {
        return;
    }
    // If no links were passed, default to the standard
    if (empty($r['links'])) {
        $r['links'] = array('edit' => bbp_get_reply_edit_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r));
    }
    // Check caps for trashing the topic
    if (!current_user_can('delete_reply', $r['id']) && !empty($r['links']['trash'])) {
        unset($r['links']['trash']);
    }
    // See if links need to be unset
    $reply_status = bbp_get_reply_status($r['id']);
    if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) {
        // Spam link shouldn't be visible on trashed topics
        if ($reply_status == bbp_get_trash_status_id()) {
            unset($r['links']['spam']);
            // Trash link shouldn't be visible on spam topics
        } elseif (isset($r['links']['trash']) && bbp_get_spam_status_id() == $reply_status) {
            unset($r['links']['trash']);
        }
    }
    // Process the admin links
    $links = implode($r['sep'], array_filter($r['links']));
    $retval = $r['before'] . $links . $r['after'];
    return apply_filters('bbp_get_reply_admin_links', $retval, $args);
}
 /**
  * Post new topic by email handler.
  *
  * For bbPress, the logic in this method is the same as {@link bbp_new_topic_handler()}.
  * It's duplicated because bbPress doesn't utilize hooks for verifying topics.
  *
  * @todo No fancy support for topic tags, subscriptions yet. Will probably need shortcodes.
  *
  * @param array $data {
  *     An array of arguments.
  *
  *     @type array $headers Email headers.
  *     @type string $content The email body content.
  *     @type string $subject The email subject line.
  *     @type int $user_id The user ID who sent the email.
  *     @type bool $is_html Whether the email content is HTML or not.
  *     @type int $i The email message number.
  * }
  * @param array $params Parsed paramaters from the email address querystring.
  *   See {@link BP_Reply_By_Email_Parser::get_parameters()}.
  * @return array|object Array of the parsed item on success. WP_Error object
  *  on failure.
  */
 private function post_new_topic($data, $params)
 {
     //private function post_new_topic( $connection, $i, $headers, $params, $body, $topic_author ) {
     /** SETUP DATA ***************************************************/
     $i = $data['i'];
     $topic_author = $data['user_id'];
     $forum_id = $params[$this->forum_id_param];
     /* current email is a bbPress new topic, let's proceed! */
     // let RBE know that we're in the process of rendering a bbP new topic
     // BuddyPress group new topic
     if (!empty($params[$this->item_id_param])) {
         bp_rbe_log('Message #' . $i . ': this is a bbPress group forum new topic');
         // bbPress
     } else {
         bp_rbe_log('Message #' . $i . ': this is a bbPress new topic');
     }
     // other variables
     $anonymous_data = 0;
     /** GROUP PERMISSIONS ********************************************/
     // posting from a BP group
     if (!empty($params[$this->item_id_param])) {
         global $bp;
         // set group ID and cache it in global for later use
         // $bp->rbe->temp->group_id gets passed to the set_group_id() method later on
         $group_id = $bp->rbe->temp->group_id = $params[$this->item_id_param];
         // get all group member data for the user in one swoop!
         $group_member_data = bp_rbe_get_group_member_info($topic_author, $group_id);
         // user is not a member of the group anymore
         if (empty($group_member_data)) {
             //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_not_group_member' );
             return new WP_Error('user_not_group_member', '', $data);
         }
         // user is banned from group
         if ((int) $group_member_data->is_banned == 1) {
             //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_banned_from_group' );
             return new WP_Error('user_banned_from_group', '', $data);
         }
         // override groups_get_current_group() with our cached group ID
         add_filter('groups_get_current_group', array($this, 'set_group_id'));
         // temporarily add some GES filters here
         add_filter('bp_ass_activity_notification_subject', 'wp_specialchars_decode');
         add_filter('bp_ass_activity_notification_content', 'wp_specialchars_decode');
     }
     /** TOPIC / FORUM PERMISSIONS ************************************/
     // Allow member to pass default cap checks.
     // The reason why we keep the user_can() checks below is b/c bbPress
     // plugins may disable cap access for a specific user if they have hooked into
     // the 'bbp_map_meta_caps' filter.
     add_filter('bbp_map_meta_caps', array($this, 'map_forum_meta_caps'), 5, 4);
     // User cannot create topics
     if (!user_can($topic_author, 'publish_topics')) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_permissions' );
         return new WP_Error('bbp_topic_permissions', '', $data);
     }
     // Forum is a category
     if (bbp_is_forum_category($forum_id)) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_category' );
         //bbp_add_error( 'bbp_edit_topic_forum_category', __( '<strong>ERROR</strong>: This forum is a category. No topics can be created in this forum.', 'bbpress' ) );
         return new WP_Error('bbp_edit_topic_forum_category', '', $data);
         // Forum is not a category
     } else {
         // Forum is closed and user cannot access
         if (bbp_is_forum_closed($forum_id) && !user_can($topic_author, 'edit_forum')) {
             //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_closed' );
             //bbp_add_error( 'bbp_edit_topic_forum_closed', __( '<strong>ERROR</strong>: This forum has been closed to new topics.', 'bbpress' ) );
             return new WP_Error('bbp_edit_topic_forum_closed', '', $data);
         }
         // Forum is private and user cannot access
         if (bbp_is_forum_private($forum_id)) {
             if (!user_can($topic_author, 'read_private_forums')) {
                 //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_private' );
                 //bbp_add_error( 'bbp_edit_topic_forum_private', __( '<strong>ERROR</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
                 return new WP_Error('bbp_edit_topic_forum_private', '', $data);
             }
         }
         // Forum is hidden and user cannot access
         if (bbp_is_forum_hidden($forum_id)) {
             if (!user_can($topic_author, 'read_hidden_forums')) {
                 //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_edit_topic_forum_hidden' );
                 //bbp_add_error( 'bbp_edit_topic_forum_hidden', __( '<strong>ERROR</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) );
                 return new WP_Error('bbp_edit_topic_forum_hidden', '', $data);
             }
         }
     }
     /** UNFILTERED HTML **********************************************/
     // Remove wp_filter_kses filters from title and content for capable users
     if (user_can($topic_author, 'unfiltered_html')) {
         remove_filter('bbp_new_topic_pre_title', 'wp_filter_kses');
         remove_filter('bbp_new_topic_pre_content', 'wp_filter_kses');
     }
     /** TOPIC DATA ***************************************************/
     $topic_content = $data['content'];
     $topic_title = $data['subject'];
     bp_rbe_log('Message #' . $i . ': body contents - ' . $topic_content);
     bp_rbe_log('Subject - ' . $topic_title);
     if (empty($topic_content) || empty($topic_title)) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_new_forum_topic_empty' );
         return new WP_Error('bbp_new_forum_topic_empty', '', $data);
     }
     // Filter and sanitize
     $topic_title = apply_filters('bbp_new_topic_pre_title', $topic_title);
     $topic_content = apply_filters('bbp_new_topic_pre_content', $topic_content);
     /** Topic Tags ****************************************************/
     /* TODO
     		if ( bbp_allow_topic_tags() ) {
     
     			// Escape tag input
     			$terms = esc_attr( strip_tags( $_POST['bbp_topic_tags'] ) );
     
     			// Explode by comma
     			if ( strstr( $terms, ',' ) ) {
     				$terms = explode( ',', $terms );
     			}
     
     			// Add topic tag ID as main key
     			$terms = array( bbp_get_topic_tag_tax_id() => $terms );
     		}
     		*/
     /** TOPIC MODERATION *********************************************/
     // Post Flooding
     if (!bbp_check_for_flood($anonymous_data, $topic_author)) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_flood' );
         //bbp_add_error( 'bbp_reply_flood', __( '<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress' ) );
         return new WP_Error('bbp_topic_flood', '', $data);
     }
     // Topic Duplicate
     if (!bbp_check_for_duplicate(array('post_type' => bbp_get_topic_post_type(), 'post_author' => $topic_author, 'post_content' => $topic_content, 'anonymous_data' => $anonymous_data))) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_duplicate' );
         return new WP_Error('bbp_topic_duplicate', '', $data);
     }
     // Topic Blacklist
     if (!bbp_check_for_blacklist($anonymous_data, $topic_author, $topic_title, $topic_content)) {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_blacklist' );
         return new WP_Error('bbp_topic_blacklist', '', $data);
     }
     // Topic Status
     // Maybe put into moderation
     if (!bbp_check_for_moderation($anonymous_data, $topic_author, $topic_title, $topic_content)) {
         $topic_status = bbp_get_pending_status_id();
         // Default
     } else {
         $topic_status = bbp_get_public_status_id();
     }
     /** POSTING TIME! ************************************************/
     // bbP hook before save
     do_action('bbp_new_topic_pre_extras', $forum_id);
     // Setup reply data
     $topic_data = apply_filters('bbp_new_topic_pre_insert', array('post_author' => $topic_author, 'post_title' => $topic_title, 'post_content' => $topic_content, 'post_status' => $topic_status, 'post_parent' => $forum_id, 'post_type' => bbp_get_topic_post_type(), 'comment_status' => 'closed'));
     // Insert topic
     $topic_id = wp_insert_post($topic_data);
     // Topic posted!
     if (!is_wp_error($topic_id)) {
         // more internal logging
         bp_rbe_log('Message #' . $i . ': bbPress topic successfully posted!');
         // Problem posting
     } else {
         //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_topic_error' );
         return new WP_Error('bbp_topic_error', '', $data);
     }
     /** AFTER POSTING ************************************************/
     // stuff that needs to happen after a bbP topic is posted occurs here... bbP
     // should preferably do the following at the 'bbp_new_reply' hook, until then
     // do what bbP does inline.
     // Trash Check ////////////////////////////////////////////////////
     // If the forum is trash, or the topic_status is switched to
     // trash, trash it properly
     if (get_post_field('post_status', $forum_id) == bbp_get_trash_status_id() || $topic_data['post_status'] == bbp_get_trash_status_id()) {
         // Trash the reply
         wp_trash_post($topic_id);
     }
     // Spam Check /////////////////////////////////////////////////////
     // If reply or topic are spam, officially spam this reply
     if ($topic_data['post_status'] == bbp_get_spam_status_id()) {
         add_post_meta($topic_id, '_bbp_spam_meta_status', bbp_get_public_status_id());
     }
     // Reply By Email /////////////////////////////////////////////////
     // Add a RBE marker to the post's meta
     // Could potentially show that post was made via email on the frontend
     add_post_meta($topic_id, 'bp_rbe', 1);
     /** POST HOOKS ***************************************************/
     // RBE Custom Hooks ///////////////////////////////////////////////
     // change activity action
     add_filter('bbp_before_record_activity_parse_args', array($this, 'change_activity_action'));
     // add RBE's special activity hook
     add_action('bp_activity_after_save', array($this, 'activity_rbe_hook'));
     // bbPress Topic Hooks ////////////////////////////////////////////
     do_action('bbp_new_topic', $topic_id, $forum_id, $anonymous_data, $topic_author);
     do_action('bbp_new_topic_post_extras', $topic_id);
     return array('bbp_topic_id' => $topic_id);
 }
Example #12
0
        /**
         * Output the forums for a group in the edit screens
         *
         * @since bbPress (r3653)
         * @uses bp_get_current_group_id()
         * @uses bbp_get_group_forum_ids()
         * @uses bbp_has_forums()
         * @uses bbp_get_template_part()
         */
        public function display_forums($offset = 0)
        {
            // Allow actions immediately before group forum output
            do_action('bbp_before_group_forum_display');
            // Load up bbPress once
            $bbp = bbpress();
            // Forum data
            $forum_slug = bp_action_variable($offset);
            $forum_ids = bbp_get_group_forum_ids(bp_get_current_group_id());
            $forum_args = array('post__in' => $forum_ids, 'post_parent' => null);
            // Unset global queries
            $bbp->forum_query = new stdClass();
            $bbp->topic_query = new stdClass();
            $bbp->reply_query = new stdClass();
            // Unset global ID's
            $bbp->current_forum_id = 0;
            $bbp->current_topic_id = 0;
            $bbp->current_reply_id = 0;
            $bbp->current_topic_tag_id = 0;
            // Reset the post data
            wp_reset_postdata();
            // Allow admins special views
            $post_status = array(bbp_get_closed_status_id(), bbp_get_public_status_id());
            if (is_super_admin() || current_user_can('moderate') || bp_is_item_admin() || bp_is_item_mod()) {
                $post_status = array_merge($post_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()));
            }
            ?>

		<div id="bbpress-forums">

			<?php 
            // Looking at the group forum root
            if (empty($forum_slug) || 'page' == $forum_slug) {
                // Query forums and show them if they exist
                if (!empty($forum_ids) && bbp_has_forums($forum_args)) {
                    // Only one forum found
                    if (1 == $bbp->forum_query->post_count) {
                        // Remove 'name' check for paginated requests
                        if ('page' == $forum_slug) {
                            $forum_args = array('post_type' => bbp_get_forum_post_type());
                        } else {
                            $forum_args = array('name' => $forum_slug, 'post_type' => bbp_get_forum_post_type());
                        }
                        // Get the forums
                        $forums = get_posts($forum_args);
                        bbp_the_forum();
                        // Forum exists
                        if (!empty($forums)) {
                            $forum = $forums[0];
                            // Suppress subforums for now
                            add_filter('bbp_get_forum_subforum_count', '__return_false');
                            // Set up forum data
                            bbpress()->current_forum_id = $forum->ID;
                            bbp_set_query_name('bbp_single_forum');
                            ?>

							<h3><?php 
                            bbp_forum_title();
                            ?>
</h3>

							<?php 
                            bbp_get_template_part('content', 'single-forum');
                            ?>

							<?php 
                            // Remove the subforum suppression filter
                            remove_filter('bbp_get_forum_subforum_count', '__return_false');
                            ?>

						<?php 
                        } else {
                            ?>

							<?php 
                            bbp_get_template_part('feedback', 'no-topics');
                            ?>

							<?php 
                            bbp_get_template_part('form', 'topic');
                            ?>

						<?php 
                        }
                        // More than 1 forum found or group forum admin screen
                    } elseif (1 < $bbp->forum_query->post_count) {
                        ?>

						<h3><?php 
                        _e('Forums', 'bbpress');
                        ?>
</h3>

						<?php 
                        bbp_get_template_part('loop', 'forums');
                        ?>

						<h3><?php 
                        _e('Topics', 'bbpress');
                        ?>
</h3>

						<?php 
                        if (bbp_has_topics(array('post_parent__in' => $forum_ids))) {
                            ?>

							<?php 
                            bbp_get_template_part('pagination', 'topics');
                            ?>

							<?php 
                            bbp_get_template_part('loop', 'topics');
                            ?>

							<?php 
                            bbp_get_template_part('pagination', 'topics');
                            ?>

							<?php 
                            bbp_get_template_part('form', 'topic');
                            ?>

						<?php 
                        } else {
                            ?>

							<?php 
                            bbp_get_template_part('feedback', 'no-topics');
                            ?>

							<?php 
                            bbp_get_template_part('form', 'topic');
                            ?>

						<?php 
                        }
                        // No forums found
                    } else {
                        ?>

						<div id="message" class="info">
							<p><?php 
                        _e('This group does not currently have any forums.', 'bbpress');
                        ?>
</p>
						</div>

					<?php 
                    }
                    // No forums found
                } else {
                    ?>

					<div id="message" class="info">
						<p><?php 
                    _e('This group does not currently have any forums.', 'bbpress');
                    ?>
</p>
					</div>

				<?php 
                }
                // Single forum
            } elseif (bp_action_variable($offset) != $this->slug && bp_action_variable($offset) != $this->topic_slug && bp_action_variable($offset) != $this->reply_slug) {
                // Get forum data
                $forum_slug = bp_action_variable($offset);
                $forum_args = array('name' => $forum_slug, 'post_type' => bbp_get_forum_post_type());
                $forums = get_posts($forum_args);
                // Forum exists
                if (!empty($forums)) {
                    $forum = $forums[0];
                    // Set up forum data
                    $forum_id = bbpress()->current_forum_id = $forum->ID;
                    // Reset necessary forum_query attributes for forums loop to function
                    $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
                    $bbp->forum_query->in_the_loop = true;
                    $bbp->forum_query->post = get_post($forum_id);
                    // Forum edit
                    if (bp_action_variable($offset + 1) == $bbp->edit_id) {
                        global $wp_query, $post;
                        $wp_query->bbp_is_edit = true;
                        $wp_query->bbp_is_forum_edit = true;
                        $post = $forum;
                        bbp_set_query_name('bbp_forum_form');
                        bbp_get_template_part('form', 'forum');
                    } else {
                        bbp_set_query_name('bbp_single_forum');
                        ?>

						<h3><?php 
                        bbp_forum_title();
                        ?>
</h3>

						<?php 
                        bbp_get_template_part('content', 'single-forum');
                    }
                } else {
                    bbp_get_template_part('feedback', 'no-topics');
                    bbp_get_template_part('form', 'topic');
                }
                // Single topic
            } elseif (bp_action_variable($offset) == $this->topic_slug) {
                // Get topic data
                $topic_slug = bp_action_variable($offset + 1);
                $topic_args = array('name' => $topic_slug, 'post_type' => bbp_get_topic_post_type(), 'post_status' => $post_status);
                $topics = get_posts($topic_args);
                // Topic exists
                if (!empty($topics)) {
                    $topic = $topics[0];
                    // Set up topic data
                    $topic_id = bbpress()->current_topic_id = $topic->ID;
                    $forum_id = bbp_get_topic_forum_id($topic_id);
                    // Reset necessary forum_query attributes for topics loop to function
                    $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
                    $bbp->forum_query->in_the_loop = true;
                    $bbp->forum_query->post = get_post($forum_id);
                    // Reset necessary topic_query attributes for topics loop to function
                    $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
                    $bbp->topic_query->in_the_loop = true;
                    $bbp->topic_query->post = $topic;
                    // Topic edit
                    if (bp_action_variable($offset + 2) == $bbp->edit_id) {
                        global $wp_query, $post;
                        $wp_query->bbp_is_edit = true;
                        $wp_query->bbp_is_topic_edit = true;
                        $post = $topic;
                        // Merge
                        if (!empty($_GET['action']) && 'merge' == $_GET['action']) {
                            bbp_set_query_name('bbp_topic_merge');
                            bbp_get_template_part('form', 'topic-merge');
                            // Split
                        } elseif (!empty($_GET['action']) && 'split' == $_GET['action']) {
                            bbp_set_query_name('bbp_topic_split');
                            bbp_get_template_part('form', 'topic-split');
                            // Edit
                        } else {
                            bbp_set_query_name('bbp_topic_form');
                            bbp_get_template_part('form', 'topic');
                        }
                        // Single Topic
                    } else {
                        bbp_set_query_name('bbp_single_topic');
                        ?>

						<h3><?php 
                        bbp_topic_title();
                        ?>
</h3>

						<?php 
                        bbp_get_template_part('content', 'single-topic');
                    }
                    // No Topics
                } else {
                    bbp_get_template_part('feedback', 'no-topics');
                    bbp_get_template_part('form', 'topic');
                }
                // Single reply
            } elseif (bp_action_variable($offset) == $this->reply_slug) {
                // Get reply data
                $reply_slug = bp_action_variable($offset + 1);
                $reply_args = array('name' => $reply_slug, 'post_type' => bbp_get_reply_post_type());
                $replies = get_posts($reply_args);
                if (empty($replies)) {
                    return;
                }
                // Get the first reply
                $reply = $replies[0];
                // Set up reply data
                $reply_id = bbpress()->current_reply_id = $reply->ID;
                $topic_id = bbp_get_reply_topic_id($reply_id);
                $forum_id = bbp_get_reply_forum_id($reply_id);
                // Reset necessary forum_query attributes for reply to function
                $bbp->forum_query->query_vars['post_type'] = bbp_get_forum_post_type();
                $bbp->forum_query->in_the_loop = true;
                $bbp->forum_query->post = get_post($forum_id);
                // Reset necessary topic_query attributes for reply to function
                $bbp->topic_query->query_vars['post_type'] = bbp_get_topic_post_type();
                $bbp->topic_query->in_the_loop = true;
                $bbp->topic_query->post = get_post($topic_id);
                // Reset necessary reply_query attributes for reply to function
                $bbp->reply_query->query_vars['post_type'] = bbp_get_reply_post_type();
                $bbp->reply_query->in_the_loop = true;
                $bbp->reply_query->post = $reply;
                if (bp_action_variable($offset + 2) == $bbp->edit_id) {
                    global $wp_query, $post;
                    $wp_query->bbp_is_edit = true;
                    $wp_query->bbp_is_reply_edit = true;
                    $post = $reply;
                    bbp_set_query_name('bbp_reply_form');
                    bbp_get_template_part('form', 'reply');
                }
            }
            ?>

		</div>

		<?php 
            // Allow actions immediately after group forum output
            do_action('bbp_after_group_forum_display');
        }
Example #13
0
 /**
  * @covers ::bbp_forum_topic_count_hidden
  * @covers ::bbp_get_forum_topic_count_hidden
  */
 public function test_bbp_get_forum_topic_count_hidden()
 {
     $f = $this->factory->forum->create();
     $int_value = 3;
     $formatted_value = bbp_number_format($int_value);
     $this->factory->topic->create_many($int_value, array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id()));
     bbp_update_forum_topic_count_hidden($f);
     // Output
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->expectOutputString($formatted_value);
     bbp_forum_topic_count_hidden($f);
     // Formatted string
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->assertSame($formatted_value, $count);
     // Integer
     $count = bbp_get_forum_topic_count_hidden($f, true, true);
     $this->assertSame($int_value, $count);
 }
Example #14
0
/**
 * bbPress Dashboard Right Now Widget
 *
 * Adds a dashboard widget with forum statistics
 *
 * @since 2.0.0 bbPress (r2770)
 *
 * @deprecated 2.6.0 bbPress (r5268)
 *
 * @uses bbp_get_version() To get the current bbPress version
 * @uses bbp_get_statistics() To get the forum statistics
 * @uses current_user_can() To check if the user is capable of doing things
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses get_admin_url() To get the administration url
 * @uses add_query_arg() To add custom args to the url
 * @uses do_action() Calls 'bbp_dashboard_widget_right_now_content_table_end'
 *                    below the content table
 * @uses do_action() Calls 'bbp_dashboard_widget_right_now_table_end'
 *                    below the discussion table
 * @uses do_action() Calls 'bbp_dashboard_widget_right_now_discussion_table_end'
 *                    below the discussion table
 * @uses do_action() Calls 'bbp_dashboard_widget_right_now_end' below the widget
 */
function bbp_dashboard_widget_right_now()
{
    // Get the statistics
    $r = bbp_get_statistics();
    ?>

	<div class="table table_content">

		<p class="sub"><?php 
    esc_html_e('Discussion', 'bbpress');
    ?>
</p>

		<table>

			<tr class="first">

				<?php 
    $num = $r['forum_count'];
    $text = _n('Forum', 'Forums', $r['forum_count'], 'bbpress');
    if (current_user_can('publish_forums')) {
        $link = add_query_arg(array('post_type' => bbp_get_forum_post_type()), get_admin_url(null, 'edit.php'));
        $num = '<a href="' . esc_url($link) . '">' . $num . '</a>';
        $text = '<a href="' . esc_url($link) . '">' . $text . '</a>';
    }
    ?>

				<td class="first b b-forums"><?php 
    echo $num;
    ?>
</td>
				<td class="t forums"><?php 
    echo $text;
    ?>
</td>

			</tr>

			<tr>

				<?php 
    $num = $r['topic_count'];
    $text = _n('Topic', 'Topics', $r['topic_count'], 'bbpress');
    if (current_user_can('publish_topics')) {
        $link = add_query_arg(array('post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit.php'));
        $num = '<a href="' . esc_url($link) . '">' . $num . '</a>';
        $text = '<a href="' . esc_url($link) . '">' . $text . '</a>';
    }
    ?>

				<td class="first b b-topics"><?php 
    echo $num;
    ?>
</td>
				<td class="t topics"><?php 
    echo $text;
    ?>
</td>

			</tr>

			<tr>

				<?php 
    $num = $r['reply_count'];
    $text = _n('Reply', 'Replies', $r['reply_count'], 'bbpress');
    if (current_user_can('publish_replies')) {
        $link = add_query_arg(array('post_type' => bbp_get_reply_post_type()), get_admin_url(null, 'edit.php'));
        $num = '<a href="' . esc_url($link) . '">' . $num . '</a>';
        $text = '<a href="' . esc_url($link) . '">' . $text . '</a>';
    }
    ?>

				<td class="first b b-replies"><?php 
    echo $num;
    ?>
</td>
				<td class="t replies"><?php 
    echo $text;
    ?>
</td>

			</tr>

			<?php 
    if (bbp_allow_topic_tags()) {
        ?>

				<tr>

					<?php 
        $num = $r['topic_tag_count'];
        $text = _n('Topic Tag', 'Topic Tags', $r['topic_tag_count'], 'bbpress');
        if (current_user_can('manage_topic_tags')) {
            $link = add_query_arg(array('taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit-tags.php'));
            $num = '<a href="' . esc_url($link) . '">' . $num . '</a>';
            $text = '<a href="' . esc_url($link) . '">' . $text . '</a>';
        }
        ?>

					<td class="first b b-topic_tags"><span class="total-count"><?php 
        echo $num;
        ?>
</span></td>
					<td class="t topic_tags"><?php 
        echo $text;
        ?>
</td>

				</tr>

			<?php 
    }
    ?>

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

		</table>

	</div>


	<div class="table table_discussion">

		<p class="sub"><?php 
    esc_html_e('Users &amp; Moderation', 'bbpress');
    ?>
</p>

		<table>

			<tr class="first">

				<?php 
    $num = $r['user_count'];
    $text = _n('User', 'Users', $r['user_count'], 'bbpress');
    if (current_user_can('edit_users')) {
        $link = get_admin_url(null, 'users.php');
        $num = '<a href="' . $link . '">' . $num . '</a>';
        $text = '<a href="' . $link . '">' . $text . '</a>';
    }
    ?>

				<td class="b b-users"><span class="total-count"><?php 
    echo $num;
    ?>
</span></td>
				<td class="last t users"><?php 
    echo $text;
    ?>
</td>

			</tr>

			<?php 
    if (isset($r['topic_count_hidden'])) {
        ?>

				<tr>

					<?php 
        $num = $r['topic_count_hidden'];
        $text = _n('Hidden Topic', 'Hidden Topics', $r['topic_count_hidden'], 'bbpress');
        $link = add_query_arg(array('post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit.php'));
        if ('0' !== $num) {
            $link = add_query_arg(array('post_status' => bbp_get_spam_status_id()), $link);
        }
        $num = '<a href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_topic_title']) . '">' . $num . '</a>';
        $text = '<a class="waiting" href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_topic_title']) . '">' . $text . '</a>';
        ?>

					<td class="b b-hidden-topics"><?php 
        echo $num;
        ?>
</td>
					<td class="last t hidden-replies"><?php 
        echo $text;
        ?>
</td>

				</tr>

			<?php 
    }
    ?>

			<?php 
    if (isset($r['reply_count_hidden'])) {
        ?>

				<tr>

					<?php 
        $num = $r['reply_count_hidden'];
        $text = _n('Hidden Reply', 'Hidden Replies', $r['reply_count_hidden'], 'bbpress');
        $link = add_query_arg(array('post_type' => bbp_get_reply_post_type()), get_admin_url(null, 'edit.php'));
        if ('0' !== $num) {
            $link = add_query_arg(array('post_status' => bbp_get_spam_status_id()), $link);
        }
        $num = '<a href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_reply_title']) . '">' . $num . '</a>';
        $text = '<a class="waiting" href="' . esc_url($link) . '" title="' . esc_attr($r['hidden_reply_title']) . '">' . $text . '</a>';
        ?>

					<td class="b b-hidden-replies"><?php 
        echo $num;
        ?>
</td>
					<td class="last t hidden-replies"><?php 
        echo $text;
        ?>
</td>

				</tr>

			<?php 
    }
    ?>

			<?php 
    if (bbp_allow_topic_tags() && isset($r['empty_topic_tag_count'])) {
        ?>

				<tr>

					<?php 
        $num = $r['empty_topic_tag_count'];
        $text = _n('Empty Topic Tag', 'Empty Topic Tags', $r['empty_topic_tag_count'], 'bbpress');
        $link = add_query_arg(array('taxonomy' => bbp_get_topic_tag_tax_id(), 'post_type' => bbp_get_topic_post_type()), get_admin_url(null, 'edit-tags.php'));
        $num = '<a href="' . esc_url($link) . '">' . $num . '</a>';
        $text = '<a class="waiting" href="' . esc_url($link) . '">' . $text . '</a>';
        ?>

					<td class="b b-hidden-topic-tags"><?php 
        echo $num;
        ?>
</td>
					<td class="last t hidden-topic-tags"><?php 
        echo $text;
        ?>
</td>

				</tr>

			<?php 
    }
    ?>

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

		</table>

	</div>

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

	<div class="versions">

		<span id="wp-version-message">
			<?php 
    printf(__('You are using <span class="b">bbPress %s</span>.', 'bbpress'), bbp_get_version());
    ?>
		</span>

	</div>

	<br class="clear" />

	<?php 
    do_action('bbp_dashboard_widget_right_now_end');
}
Example #15
0
/**
 * Unspams a reply
 *
 * @since bbPress (r2740)
 *
 * @param int $reply_id Reply id
 * @uses get_post() To get the reply
 * @uses do_action() Calls 'bbp_unspam_reply' with the reply ID
 * @uses get_post_meta() To get the previous status meta
 * @uses delete_post_meta() To delete the previous status meta
 * @uses wp_insert_post() To insert the updated post
 * @uses do_action() Calls 'bbp_unspammed_reply' with the reply ID
 * @return mixed False or {@link WP_Error} on failure, reply id on success
 */
function bbp_unspam_reply($reply_id = 0)
{
    // Get reply
    $reply = get_post($reply_id, ARRAY_A);
    if (empty($reply)) {
        return $reply;
    }
    // Bail if already not spam
    if (bbp_get_spam_status_id() != $reply['post_status']) {
        return false;
    }
    // Execute pre unspam code
    do_action('bbp_unspam_reply', $reply_id);
    // Get pre spam status
    $reply['post_status'] = get_post_meta($reply_id, '_bbp_spam_meta_status', true);
    // Delete pre spam meta
    delete_post_meta($reply_id, '_bbp_spam_meta_status');
    // No revisions
    remove_action('pre_post_update', 'wp_save_post_revision');
    // Update the reply
    $reply_id = wp_insert_post($reply);
    // Execute post unspam code
    do_action('bbp_unspammed_reply', $reply_id);
    // Return reply_id
    return $reply_id;
}
Example #16
0
/**
 * Query the DB and get a the child id's of all children
 *
 * @since 2.0.0 bbPress (r3325)
 *
 * @param int $parent_id  Parent id
 * @param string $post_type Post type. Defaults to 'post'
 * @uses wp_cache_get() To check if there is a cache of the children
 * @uses bbp_get_public_status_id() To get the public status id
 * @uses bbp_get_private_status_id() To get the private status id
 * @uses bbp_get_hidden_status_id() To get the hidden status id
 * @uses bbp_get_pending_status_id() To get the pending status id
 * @uses bbp_get_closed_status_id() To get the closed status id
 * @uses bbp_get_trash_status_id() To get the trash status id
 * @uses bbp_get_spam_status_id() To get the spam status id
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses wpdb::prepare() To prepare the query
 * @uses wpdb::get_col() To get the result of the query in an array
 * @uses wp_cache_set() To set the cache for future use
 * @uses apply_filters() Calls 'bbp_get_all_child_ids' with the child ids,
 *                        parent id and post type
 * @return array The array of children
 */
function bbp_get_all_child_ids($parent_id = 0, $post_type = 'post')
{
    // Bail if nothing passed
    if (empty($parent_id)) {
        return false;
    }
    // The ID of the cached query
    $cache_id = 'bbp_parent_all_' . $parent_id . '_type_' . $post_type . '_child_ids';
    // Check for cache and set if needed
    $child_ids = wp_cache_get($cache_id, 'bbpress_posts');
    if (false === $child_ids) {
        $post_status = array(bbp_get_public_status_id());
        // Extra post statuses based on post type
        switch ($post_type) {
            // Forum
            case bbp_get_forum_post_type():
                $post_status[] = bbp_get_private_status_id();
                $post_status[] = bbp_get_hidden_status_id();
                break;
                // Topic
            // Topic
            case bbp_get_topic_post_type():
                $post_status[] = bbp_get_pending_status_id();
                $post_status[] = bbp_get_closed_status_id();
                $post_status[] = bbp_get_trash_status_id();
                $post_status[] = bbp_get_spam_status_id();
                break;
                // Reply
            // Reply
            case bbp_get_reply_post_type():
                $post_status[] = bbp_get_pending_status_id();
                $post_status[] = bbp_get_trash_status_id();
                $post_status[] = bbp_get_spam_status_id();
                break;
        }
        // Join post statuses together
        $post_status = "'" . implode("', '", $post_status) . "'";
        $bbp_db = bbp_db();
        $query = $bbp_db->prepare("SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type);
        $child_ids = (array) $bbp_db->get_col($query);
        wp_cache_set($cache_id, $child_ids, 'bbpress_posts');
    } else {
        $child_ids = (array) $child_ids;
    }
    // Filter and return
    return (array) apply_filters('bbp_get_all_child_ids', $child_ids, $parent_id, $post_type);
}
Example #17
0
 /**
  * @covers ::bbp_forum_topic_count_hidden
  * @covers ::bbp_get_forum_topic_count_hidden
  */
 public function test_bbp_get_forum_topic_count_hidden()
 {
     $c = $this->factory->forum->create(array('forum_meta' => array('forum_type' => 'category')));
     $f = $this->factory->forum->create(array('post_parent' => $c, 'forum_meta' => array('forum_id' => $c)));
     $int_value = 3;
     $formatted_value = bbp_number_format($int_value);
     $this->factory->topic->create_many($int_value, array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id()));
     bbp_update_forum_topic_count_hidden($c);
     bbp_update_forum_topic_count_hidden($f);
     // Forum output.
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->expectOutputString($formatted_value);
     bbp_forum_topic_count_hidden($f);
     // Forum formatted string.
     $count = bbp_get_forum_topic_count_hidden($f, false);
     $this->assertSame($formatted_value, $count);
     // Forum integer.
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame($int_value, $count);
     // Category topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
     // Category total topic count hidden.
     $count = bbp_get_forum_topic_count_hidden($c, true);
     $this->assertSame(0, $count);
 }
Example #18
0
 /**
  * @covers ::bbp_get_all_child_ids
  */
 public function test_bbp_get_all_child_ids()
 {
     $f = $this->factory->forum->create();
     // Test initial forum public child counts
     $count = count(bbp_get_all_child_ids($f, bbp_get_forum_post_type()));
     $this->assertSame(0, $count);
     $count = count(bbp_get_all_child_ids($f, bbp_get_topic_post_type()));
     $this->assertSame(0, $count);
     /* Sub-Forums *********************************************************/
     $this->factory->forum->create_many(3, array('post_parent' => $f));
     $this->factory->forum->create(array('post_parent' => $f, 'post_status' => bbp_get_private_status_id()));
     $count = count(bbp_get_all_child_ids($f, bbp_get_forum_post_type()));
     $this->assertSame(4, $count);
     $this->factory->forum->create_many(2, array('post_parent' => $f));
     $count = count(bbp_get_all_child_ids($f, bbp_get_forum_post_type()));
     $this->assertSame(6, $count);
     /* Topics *************************************************************/
     $t1 = $this->factory->topic->create_many(3, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $this->factory->topic->create(array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id(), 'topic_meta' => array('forum_id' => $f)));
     $count = count(bbp_get_all_child_ids($f, bbp_get_topic_post_type()));
     $this->assertSame(4, $count);
     $this->factory->topic->create_many(2, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $count = count(bbp_get_all_child_ids($f, bbp_get_topic_post_type()));
     $this->assertSame(6, $count);
     $this->factory->topic->create(array('post_parent' => $f, 'post_status' => bbp_get_pending_status_id(), 'topic_meta' => array('forum_id' => $f)));
     $count = count(bbp_get_all_child_ids($f, bbp_get_topic_post_type()));
     $this->assertSame(7, $count);
     /* Replies ************************************************************/
     $this->factory->reply->create_many(3, array('post_parent' => $t1[0], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $this->factory->reply->create(array('post_parent' => $t1[0], 'post_status' => bbp_get_spam_status_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $count = count(bbp_get_all_child_ids($t1[0], bbp_get_reply_post_type()));
     $this->assertSame(4, $count);
     $this->factory->reply->create_many(2, array('post_parent' => $t1[0], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $count = count(bbp_get_all_child_ids($t1[0], bbp_get_reply_post_type()));
     $this->assertSame(6, $count);
     $this->factory->reply->create(array('post_parent' => $t1[0], 'post_status' => bbp_get_pending_status_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $count = count(bbp_get_all_child_ids($t1[0], bbp_get_reply_post_type()));
     $this->assertSame(7, $count);
 }
Example #19
0
/**
 * Unspams a topic
 *
 * @since 2.0.0 bbPress (r2740)
 *
 * @param int $topic_id Topic id
 * @uses bbp_get_topic() To get the topic
 * @uses do_action() Calls 'bbp_unspam_topic' with the topic id
 * @uses get_post_meta() To get the previous status
 * @uses delete_post_meta() To delete the previous status meta
 * @uses wp_update_post() To update the topic with the new status
 * @uses do_action() Calls 'bbp_unspammed_topic' with the topic id
 * @return mixed False or {@link WP_Error} on failure, topic id on success
 */
function bbp_unspam_topic($topic_id = 0)
{
    // Get the topic
    $topic = bbp_get_topic($topic_id);
    if (empty($topic)) {
        return $topic;
    }
    // Bail if already not spam
    if (bbp_get_spam_status_id() !== $topic->post_status) {
        return false;
    }
    // Execute pre unspam code
    do_action('bbp_unspam_topic', $topic_id);
    // Get pre spam status
    $topic_status = get_post_meta($topic_id, '_bbp_spam_meta_status', true);
    // If no previous status, default to publish
    if (empty($topic_status)) {
        $topic_status = bbp_get_public_status_id();
    }
    // Set post status to pre spam
    $topic->post_status = $topic_status;
    $topic->tax_input = bbp_unspam_topic_tags($topic_id);
    // Delete pre spam meta
    delete_post_meta($topic_id, '_bbp_spam_meta_status');
    // No revisions
    remove_action('pre_post_update', 'wp_save_post_revision');
    // Update the topic
    $topic_id = wp_update_post($topic);
    // Execute post unspam code
    do_action('bbp_unspammed_topic', $topic_id);
    // Return topic_id
    return $topic_id;
}
/**
 * Mark a users topics and replies as spam when the user is marked as spam
 *
 * @since bbPress (r3405)
 *
 * @global WPDB $wpdb
 * @param int $user_id Optional. User ID to unspam. Defaults to displayed user.
 *
 * @uses bbp_is_single_user()
 * @uses bbp_is_user_home()
 * @uses bbp_get_displayed_user_id()
 * @uses bbp_is_user_keymaster()
 * @uses get_blogs_of_user()
 * @uses bbp_get_topic_post_type()
 * @uses bbp_get_reply_post_type()
 * @uses switch_to_blog()
 * @uses get_post_type()
 * @uses bbp_unspam_topic()
 * @uses bbp_unspam_reply()
 * @uses restore_current_blog()
 *
 * @return If no user ID passed
 */
function bbp_make_ham_user($user_id = 0)
{
    // Use displayed user if it's not yourself
    if (empty($user_id) && bbp_is_single_user() && !bbp_is_user_home()) {
        $user_id = bbp_get_displayed_user_id();
    }
    // Bail if no user ID
    if (empty($user_id)) {
        return false;
    }
    // Bail if user ID is keymaster
    if (bbp_is_user_keymaster($user_id)) {
        return false;
    }
    // Arm the torpedos
    global $wpdb;
    // Get the blog IDs of the user to mark as spam
    $blogs = get_blogs_of_user($user_id, true);
    // If user has no blogs, they are a guest on this site
    if (empty($blogs)) {
        $blogs[$wpdb->blogid] = array();
    }
    // Make array of post types to mark as spam
    $post_types = array(bbp_get_topic_post_type(), bbp_get_reply_post_type());
    $post_types = "'" . implode("', '", $post_types) . "'";
    // Loop through blogs and remove their posts
    foreach ((array) array_keys($blogs) as $blog_id) {
        // Switch to the blog ID
        switch_to_blog($blog_id);
        // Get topics and replies
        $posts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_spam_status_id()));
        // Loop through posts and spam them
        if (!empty($posts)) {
            foreach ($posts as $post_id) {
                // The routines for topics ang replies are different, so use the
                // correct one based on the post type
                switch (get_post_type($post_id)) {
                    case bbp_get_topic_post_type():
                        bbp_unspam_topic($post_id);
                        break;
                    case bbp_get_reply_post_type():
                        bbp_unspam_reply($post_id);
                        break;
                }
            }
        }
        // Switch back to current blog
        restore_current_blog();
    }
    // Success
    return true;
}
Example #21
0
 /**
  * Update post meta after a spam check
  *
  * @since bbPress (r3308)
  *
  * @param int $post_id
  * @param object $_post
  *
  * @global object $this->last_post
  *
  * @uses get_post() To get the post object
  * @uses get_userdata() To get the user data
  * @uses bbp_filter_anonymous_user_data() To get anonymous user data
  * @uses update_post_meta() To update post meta with Akismet data
  * @uses BBP_Akismet::update_post_history() To update post Akismet history
  */
 public function update_post_meta($post_id = 0, $_post = false)
 {
     // Define local variable(s)
     $as_submitted = false;
     // Setup some variables
     $post_id = (int) $post_id;
     // Ensure we have a post object
     if (empty($_post)) {
         $_post = get_post($post_id);
     }
     // Set up Akismet last post data
     if (!empty($this->last_post)) {
         $as_submitted = $this->last_post['bbp_post_as_submitted'];
     }
     // wp_insert_post() might be called in other contexts. Ensure this is
     // the same topic/reply as was checked by BBP_Akismet::check_post()
     if (is_object($_post) && !empty($this->last_post) && is_array($as_submitted)) {
         // Get user data
         $userdata = get_userdata($_post->post_author);
         $anonymous_data = bbp_filter_anonymous_post_data();
         // More checks
         if (intval($as_submitted['comment_post_ID']) == intval($_post->post_parent) && $as_submitted['comment_author'] == ($anonymous_data ? $anonymous_data['bbp_anonymous_name'] : $userdata->display_name) && $as_submitted['comment_author_email'] == ($anonymous_data ? $anonymous_data['bbp_anonymous_email'] : $userdata->user_email)) {
             // Normal result: true
             if ($this->last_post['bbp_akismet_result'] == 'true') {
                 // Leave a trail so other's know what we did
                 update_post_meta($post_id, '_bbp_akismet_result', 'true');
                 $this->update_post_history($post_id, __('Akismet caught this post as spam', 'bbpress'), 'check-spam');
                 // If post_status isn't the spam status, as expected, leave a note
                 if ($_post->post_status != bbp_get_spam_status_id()) {
                     $this->update_post_history($post_id, sprintf(__('Post status was changed to %s', 'bbpress'), $_post->post_status), 'status-changed-' . $_post->post_status);
                 }
                 // Normal result: false
             } elseif ($this->last_post['bbp_akismet_result'] == 'false') {
                 // Leave a trail so other's know what we did
                 update_post_meta($post_id, '_bbp_akismet_result', 'false');
                 $this->update_post_history($post_id, __('Akismet cleared this post', 'bbpress'), 'check-ham');
                 // If post_status is the spam status, which isn't expected, leave a note
                 if ($_post->post_status == bbp_get_spam_status_id()) {
                     // @todo Use wp_blacklist_check()
                     $this->update_post_history($post_id, sprintf(__('Post status was changed to %s', 'bbpress'), $_post->post_status), 'status-changed-' . $_post->post_status);
                 }
                 // Abnormal result: error
             } else {
                 // Leave a trail so other's know what we did
                 update_post_meta($post_id, '_bbp_akismet_error', time());
                 $this->update_post_history($post_id, sprintf(__('Akismet was unable to check this post (response: %s), will automatically retry again later.', 'bbpress'), $this->last_post['bbp_akismet_result']), 'check-error');
             }
             // Record the complete original data as submitted for checking
             if (isset($this->last_post['bbp_post_as_submitted'])) {
                 update_post_meta($post_id, '_bbp_akismet_as_submitted', $this->last_post['bbp_post_as_submitted']);
             }
         }
     }
 }
Example #22
0
/**
 * The main search loop. WordPress does the heavy lifting.
 *
 * @since bbPress (r4579)
 *
 * @param mixed $args All the arguments supported by {@link WP_Query}
 * @uses bbp_get_view_all() Are we showing all results?
 * @uses bbp_get_public_status_id() To get the public status id
 * @uses bbp_get_closed_status_id() To get the closed status id
 * @uses bbp_get_spam_status_id() To get the spam status id
 * @uses bbp_get_trash_status_id() To get the trash status id
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_replies_per_page() To get the replies per page option
 * @uses bbp_get_paged() To get the current page value
 * @uses bbp_get_search_terms() To get the search terms
 * @uses WP_Query To make query and get the search results
 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
 * @uses bbp_get_search_url() To get the forum search url
 * @uses paginate_links() To paginate search results
 * @uses apply_filters() Calls 'bbp_has_search_results' with
 *                        bbPress::search_query::have_posts()
 *                        and bbPress::reply_query
 * @return object Multidimensional array of search information
 */
function bbp_has_search_results($args = '')
{
    global $wp_rewrite;
    /** Defaults **************************************************************/
    $default_post_type = array(bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type());
    // Default query args
    $default = array('post_type' => $default_post_type, 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true, 's' => bbp_get_search_terms());
    // What are the default allowed statuses (based on user caps)
    if (bbp_get_view_all()) {
        // Default view=all statuses
        $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id());
        // Add support for private status
        if (current_user_can('read_private_topics')) {
            $post_statuses[] = bbp_get_private_status_id();
        }
        // Join post statuses together
        $default['post_status'] = implode(',', $post_statuses);
        // Lean on the 'perm' query var value of 'readable' to provide statuses
    } else {
        $default['perm'] = 'readable';
    }
    /** Setup *****************************************************************/
    // Parse arguments against default values
    $r = bbp_parse_args($args, $default, 'has_search_results');
    // Get bbPress
    $bbp = bbpress();
    // Call the query
    if (!empty($r['s'])) {
        $bbp->search_query = new WP_Query($r);
    }
    // Add pagination values to query object
    $bbp->search_query->posts_per_page = $r['posts_per_page'];
    $bbp->search_query->paged = $r['paged'];
    // Never home, regardless of what parse_query says
    $bbp->search_query->is_home = false;
    // Only add pagination is query returned results
    if (!empty($bbp->search_query->found_posts) && !empty($bbp->search_query->posts_per_page)) {
        // Array of arguments to add after pagination links
        $add_args = array();
        // If pretty permalinks are enabled, make our pagination pretty
        if ($wp_rewrite->using_permalinks()) {
            // Shortcode territory
            if (is_page() || is_single()) {
                $base = trailingslashit(get_permalink());
                // Default search location
            } else {
                $base = trailingslashit(bbp_get_search_results_url());
            }
            // Add pagination base
            $base = $base . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/');
            // Unpretty permalinks
        } else {
            $base = add_query_arg('paged', '%#%');
        }
        // Add args
        if (bbp_get_view_all()) {
            $add_args['view'] = 'all';
        }
        // Add pagination to query object
        $bbp->search_query->pagination_links = paginate_links(apply_filters('bbp_search_results_pagination', array('base' => $base, 'format' => '', 'total' => ceil((int) $bbp->search_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->search_query->paged, 'prev_text' => is_rtl() ? '&rarr;' : '&larr;', 'next_text' => is_rtl() ? '&larr;' : '&rarr;', 'mid_size' => 1, 'add_args' => $add_args)));
        // Remove first page from pagination
        if ($wp_rewrite->using_permalinks()) {
            $bbp->search_query->pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $bbp->search_query->pagination_links);
        } else {
            $bbp->search_query->pagination_links = str_replace('&#038;paged=1', '', $bbp->search_query->pagination_links);
        }
    }
    // Return object
    return apply_filters('bbp_has_search_results', $bbp->search_query->have_posts(), $bbp->search_query);
}
function tehnik_bbp_has_topics($args = '')
{
    global $wp_rewrite;
    /** Defaults ************************************************************* */
    // Other defaults
    $default_topic_search = !empty($_REQUEST['ts']) ? $_REQUEST['ts'] : false;
    $default_show_stickies = (bool) (bbp_is_single_forum() || bbp_is_topic_archive()) && false === $default_topic_search;
    $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any';
    // Default argument array
    $default = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $default_post_parent, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 's' => $default_topic_search, 'show_stickies' => $default_show_stickies, 'max_num_pages' => false);
    //Get an array of IDs which the current user has permissions to view
    $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($default));
    // The default forum query with allowed forum ids array added
    $default['post__in'] = $allowed_forums;
    // What are the default allowed statuses (based on user caps)
    if (bbp_get_view_all()) {
        // Default view=all statuses
        $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id());
        // Add support for private status
        if (current_user_can('read_private_topics')) {
            $post_statuses[] = bbp_get_private_status_id();
        }
        // Join post statuses together
        $default['post_status'] = join(',', $post_statuses);
        // Lean on the 'perm' query var value of 'readable' to provide statuses
    } else {
        $default['perm'] = 'readable';
    }
    // Maybe query for topic tags
    if (bbp_is_topic_tag()) {
        $default['term'] = bbp_get_topic_tag_slug();
        $default['taxonomy'] = bbp_get_topic_tag_tax_id();
    }
    /** Setup **************************************************************** */
    // Parse arguments against default values
    $r = bbp_parse_args($args, $default, 'has_topics');
    // Get bbPress
    $bbp = bbpress();
    // Call the query
    $bbp->topic_query = new WP_Query($r);
    // Set post_parent back to 0 if originally set to 'any'
    if ('any' == $r['post_parent']) {
        $r['post_parent'] = 0;
    }
    // Limited the number of pages shown
    if (!empty($r['max_num_pages'])) {
        $bbp->topic_query->max_num_pages = $r['max_num_pages'];
    }
    /** Stickies ************************************************************* */
    // Put sticky posts at the top of the posts array
    if (!empty($r['show_stickies']) && $r['paged'] <= 1) {
        // Get super stickies and stickies in this forum
        $stickies = bbp_get_super_stickies();
        // Get stickies for current forum
        if (!empty($r['post_parent'])) {
            $stickies = array_merge($stickies, bbp_get_stickies($r['post_parent']));
        }
        // Remove any duplicate stickies
        $stickies = array_unique($stickies);
        // We have stickies
        if (is_array($stickies) && !empty($stickies)) {
            // Start the offset at -1 so first sticky is at correct 0 offset
            $sticky_offset = -1;
            // Loop over topics and relocate stickies to the front.
            foreach ($stickies as $sticky_index => $sticky_ID) {
                // Get the post offset from the posts array
                $post_offsets = wp_filter_object_list($bbp->topic_query->posts, array('ID' => $sticky_ID), 'OR', 'ID');
                // Continue if no post offsets
                if (empty($post_offsets)) {
                    continue;
                }
                // Loop over posts in current query and splice them into position
                foreach (array_keys($post_offsets) as $post_offset) {
                    $sticky_offset++;
                    $sticky = $bbp->topic_query->posts[$post_offset];
                    // Remove sticky from current position
                    array_splice($bbp->topic_query->posts, $post_offset, 1);
                    // Move to front, after other stickies
                    array_splice($bbp->topic_query->posts, $sticky_offset, 0, array($sticky));
                    // Cleanup
                    unset($stickies[$sticky_index]);
                    unset($sticky);
                }
                // Cleanup
                unset($post_offsets);
            }
            // Cleanup
            unset($sticky_offset);
            // If any posts have been excluded specifically, Ignore those that are sticky.
            if (!empty($stickies) && !empty($r['post__not_in'])) {
                $stickies = array_diff($stickies, $r['post__not_in']);
            }
            // Fetch sticky posts that weren't in the query results
            if (!empty($stickies)) {
                // Query to use in get_posts to get sticky posts
                $sticky_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => 'any', 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies);
                //Get an array of IDs which the current user has permissions to view
                $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($sticky_query));
                // The default forum query with allowed forum ids array added
                $sticky_query['post__in'] = $allowed_forums;
                // Cleanup
                unset($stickies);
                // What are the default allowed statuses (based on user caps)
                if (bbp_get_view_all()) {
                    $sticky_query['post_status'] = $r['post_status'];
                    // Lean on the 'perm' query var value of 'readable' to provide statuses
                } else {
                    $sticky_query['post_status'] = $r['perm'];
                }
                // Get all stickies
                $sticky_posts = get_posts($sticky_query);
                if (!empty($sticky_posts)) {
                    // Get a count of the visible stickies
                    $sticky_count = count($sticky_posts);
                    // Merge the stickies topics with the query topics .
                    $bbp->topic_query->posts = array_merge($sticky_posts, $bbp->topic_query->posts);
                    // Adjust loop and counts for new sticky positions
                    $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count;
                    $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count;
                    // Cleanup
                    unset($sticky_posts);
                }
            }
        }
    }
    // If no limit to posts per page, set it to the current post_count
    if (-1 == $r['posts_per_page']) {
        $r['posts_per_page'] = $bbp->topic_query->post_count;
    }
    // Add pagination values to query object
    $bbp->topic_query->posts_per_page = $r['posts_per_page'];
    $bbp->topic_query->paged = $r['paged'];
    // Only add pagination if query returned results
    if (((int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts) && (int) $bbp->topic_query->posts_per_page) {
        // Limit the number of topics shown based on maximum allowed pages
        if (!empty($r['max_num_pages']) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count) {
            $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count;
        }
        // If pretty permalinks are enabled, make our pagination pretty
        if ($wp_rewrite->using_permalinks()) {
            // User's topics
            if (bbp_is_single_user_topics()) {
                $base = bbp_get_user_topics_created_url(bbp_get_displayed_user_id());
                // User's favorites
            } elseif (bbp_is_favorites()) {
                $base = bbp_get_favorites_permalink(bbp_get_displayed_user_id());
                // User's subscriptions
            } elseif (bbp_is_subscriptions()) {
                $base = bbp_get_subscriptions_permalink(bbp_get_displayed_user_id());
                // Root profile page
            } elseif (bbp_is_single_user()) {
                $base = bbp_get_user_profile_url(bbp_get_displayed_user_id());
                // View
            } elseif (bbp_is_single_view()) {
                $base = bbp_get_view_url();
                // Topic tag
            } elseif (bbp_is_topic_tag()) {
                $base = bbp_get_topic_tag_link();
                // Page or single post
            } elseif (is_page() || is_single()) {
                $base = get_permalink();
                // Topic archive
            } elseif (bbp_is_topic_archive()) {
                $base = bbp_get_topics_url();
                // Default
            } else {
                $base = get_permalink((int) $r['post_parent']);
            }
            // Use pagination base
            $base = trailingslashit($base) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/');
            // Unpretty pagination
        } else {
            $base = add_query_arg('paged', '%#%');
        }
        // Pagination settings with filter
        $bbp_topic_pagination = apply_filters('bbp_topic_pagination', array('base' => $base, 'format' => '', 'total' => $r['posts_per_page'] == $bbp->topic_query->found_posts ? 1 : ceil((int) $bbp->topic_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->topic_query->paged, 'prev_text' => is_rtl() ? '&rarr;' : '&larr;', 'next_text' => is_rtl() ? '&larr;' : '&rarr;', 'mid_size' => 1));
        // Add pagination to query object
        $bbp->topic_query->pagination_links = paginate_links($bbp_topic_pagination);
        // Remove first page from pagination
        $bbp->topic_query->pagination_links = str_replace($wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links);
    }
    // Return object
    return array($bbp->topic_query->have_posts(), $bbp->topic_query);
}
Example #24
0
/**
 * Adjust the total hidden topic count of a forum (hidden includes trashed and spammed topics)
 *
 * @since bbPress (r2888)
 *
 * @param int $forum_id Optional. Topic id to update
 * @param int $topic_count Optional. Set the topic count manually
 * @uses bbp_is_topic() To check if the supplied id is a topic
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic_forum_id() To get the topic forum id
 * @uses bbp_get_forum_id() To get the forum id
 * @uses wpdb::prepare() To prepare our sql query
 * @uses wpdb::get_col() To execute our query and get the column back
 * @uses update_post_meta() To update the forum hidden topic count meta
 * @uses apply_filters() Calls 'bbp_update_forum_topic_count_hidden' with the
 *                        hidden topic count and forum id
 * @return int Topic hidden topic count
 */
function bbp_update_forum_topic_count_hidden($forum_id = 0, $topic_count = 0)
{
    global $wpdb;
    // If topic_id was passed as $forum_id, then get its forum
    if (bbp_is_topic($forum_id)) {
        $topic_id = bbp_get_topic_id($forum_id);
        $forum_id = bbp_get_topic_forum_id($topic_id);
        // $forum_id is not a topic_id, so validate and proceed
    } else {
        $forum_id = bbp_get_forum_id($forum_id);
    }
    // Can't update what isn't there
    if (!empty($forum_id)) {
        // Get topics of forum
        if (empty($topic_count)) {
            $post_status = "'" . implode("','", array(bbp_get_trash_status_id(), bbp_get_spam_status_id())) . "'";
            $topic_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $forum_id, bbp_get_topic_post_type()));
        }
        // Update the count
        update_post_meta($forum_id, '_bbp_topic_count_hidden', (int) $topic_count);
    }
    return (int) apply_filters('bbp_update_forum_topic_count_hidden', (int) $topic_count, $forum_id);
}
Example #25
0
 /**
  * Register the post statuses used by bbPress
  *
  * We do some manipulation of the 'trash' status so trashed topics and
  * replies can be viewed from within the theme.
  *
  * @since bbPress (r2727)
  * @uses register_post_status() To register post statuses
  * @uses $wp_post_statuses To modify trash and private statuses
  * @uses current_user_can() To check if the current user is capable &
  *                           modify $wp_post_statuses accordingly
  */
 public static function register_post_statuses()
 {
     // Closed
     register_post_status(bbp_get_closed_status_id(), apply_filters('bbp_register_closed_post_status', array('label' => _x('Closed', 'post', 'bbpress'), 'label_count' => _nx_noop('Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', 'post', 'bbpress'), 'public' => true, 'show_in_admin_all' => true)));
     // Spam
     register_post_status(bbp_get_spam_status_id(), apply_filters('bbp_register_spam_post_status', array('label' => _x('Spam', 'post', 'bbpress'), 'label_count' => _nx_noop('Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'post', 'bbpress'), 'protected' => true, 'exclude_from_search' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => false)));
     // Orphan
     register_post_status(bbp_get_orphan_status_id(), apply_filters('bbp_register_orphan_post_status', array('label' => _x('Orphan', 'post', 'bbpress'), 'label_count' => _nx_noop('Orphan <span class="count">(%s)</span>', 'Orphans <span class="count">(%s)</span>', 'post', 'bbpress'), 'protected' => true, 'exclude_from_search' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => false)));
     // Hidden
     register_post_status(bbp_get_hidden_status_id(), apply_filters('bbp_register_hidden_post_status', array('label' => _x('Hidden', 'post', 'bbpress'), 'label_count' => _nx_noop('Hidden <span class="count">(%s)</span>', 'Hidden <span class="count">(%s)</span>', 'post', 'bbpress'), 'private' => true, 'exclude_from_search' => true, 'show_in_admin_status_list' => true, 'show_in_admin_all_list' => true)));
     /**
      * Trash fix
      *
      * We need to remove the internal arg and change that to
      * protected so that the users with 'view_trash' cap can view
      * single trashed topics/replies in the front-end as wp_query
      * doesn't allow any hack for the trashed topics to be viewed.
      */
     global $wp_post_statuses;
     if (!empty($wp_post_statuses['trash'])) {
         // User can view trash so set internal to false
         if (current_user_can('view_trash')) {
             $wp_post_statuses['trash']->internal = false;
             $wp_post_statuses['trash']->protected = true;
             // User cannot view trash so set internal to true
         } else {
             $wp_post_statuses['trash']->internal = true;
         }
     }
 }
Example #26
0
/**
 * Displays topic notices
 *
 * @since 2.0.0 bbPress (r2744)
 *
 * @uses bbp_is_single_topic() To check if it's a topic page
 * @uses bbp_get_topic_status() To get the topic status
 * @uses bbp_get_topic_id() To get the topic id
 * @uses apply_filters() Calls 'bbp_topic_notices' with the notice text, topic
 *                        status and topic id
 * @uses bbp_add_error() To add an error message
 */
function bbp_topic_notices()
{
    // Bail if not viewing a topic
    if (!bbp_is_single_topic()) {
        return;
    }
    // Get the topic_status
    $topic_status = bbp_get_topic_status();
    // Get the topic status
    switch ($topic_status) {
        // Spam notice
        case bbp_get_spam_status_id():
            $notice_text = __('This topic is marked as spam.', 'bbpress');
            break;
            // Trashed notice
        // Trashed notice
        case bbp_get_trash_status_id():
            $notice_text = __('This topic is in the trash.', 'bbpress');
            break;
            // Standard status
        // Standard status
        default:
            $notice_text = '';
            break;
    }
    // Filter notice text and bail if empty
    $notice_text = apply_filters('bbp_topic_notices', $notice_text, $topic_status, bbp_get_topic_id());
    if (empty($notice_text)) {
        return;
    }
    bbp_add_error('topic_notice', $notice_text, 'message');
}
Example #27
0
 /**
  * @covers ::bbp_spam_topic
  */
 public function test_bbp_spam_topic()
 {
     $f = $this->factory->forum->create();
     $now = time();
     $post_date_topic = date('Y-m-d H:i:s', $now - 60 * 60 * 100);
     $post_date_reply = date('Y-m-d H:i:s', $now - 60 * 60 * 80);
     $topic_time = '4 days, 4 hours ago';
     $reply_time = '3 days, 8 hours ago';
     $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date_topic, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create_many(2, array('post_parent' => $t, 'post_date' => $post_date_reply, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     bbp_spam_topic($t);
     $count = bbp_get_forum_topic_count($f, false, true);
     $this->assertSame(0, $count);
     $count = bbp_get_forum_topic_count_hidden($f, true);
     $this->assertSame(1, $count);
     $count = bbp_get_forum_reply_count($f, false, true);
     $this->assertSame(0, $count);
     $last_topic_id = bbp_get_forum_last_topic_id($f);
     $this->assertSame($t, $last_topic_id);
     $last_reply_id = bbp_get_forum_last_reply_id($f);
     $this->assertSame($t, $last_reply_id);
     $last_active_id = bbp_get_forum_last_active_id($f);
     $this->assertSame($t, $last_active_id);
     $last_active_time = bbp_get_forum_last_active_time($f);
     $this->assertSame($topic_time, $last_active_time);
     $count = bbp_get_topic_reply_count($t, true, true);
     $this->assertSame(0, $count);
     $count = bbp_get_topic_reply_count_hidden($t, true, true);
     $this->assertSame(2, $count);
     // ToDo: Result should be 0 when a topic has no replies
     //	$last_reply_id = bbp_get_topic_last_reply_id( $t );
     //	$this->assertSame( $t, $last_reply_id );
     $last_active_id = bbp_get_topic_last_active_id($t);
     $this->assertSame($t, $last_active_id);
     $last_active_time = bbp_get_topic_last_active_time($t);
     $this->assertSame($topic_time, $last_active_time);
     $topic_spam_status = get_post_status($t);
     $this->assertSame(bbp_get_spam_status_id(), $topic_spam_status);
     $topic_meta_pre_spammed_replies = get_post_meta($t, '_bbp_pre_spammed_replies', true);
     $this->assertEquals(array($r[1], $r[0]), $topic_meta_pre_spammed_replies);
     $topic_spam_meta_status = get_post_meta($t, '_bbp_spam_meta_status', true);
     $this->assertSame(bbp_get_public_status_id(), $topic_spam_meta_status);
 }
Example #28
0
/**
 * Recount topic hidden replies (spammed/trashed)
 *
 * @since 2.0.0 bbPress (r2747)
 *
 * @uses wpdb::query() To run our recount sql queries
 * @uses is_wp_error() To check if the executed query returned {@link WP_Error}
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_trash_status_id() To get the trash status id
 * @uses bbp_get_spam_status_id() To get the spam status id
 * @uses bbp_get_pending_status_id() To get the pending status id
 * @return array An array of the status code and the message
 */
function bbp_admin_repair_topic_hidden_reply_count()
{
    // Define variables
    $bbp_db = bbp_db();
    $statement = __('Counting the number of pending, spammed, and trashed replies in each topic&hellip; %s', 'bbpress');
    $result = __('Failed!', 'bbpress');
    $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden';";
    if (is_wp_error($bbp_db->query($sql_delete))) {
        return array(1, sprintf($statement, $result));
    }
    // Post types and status
    $rpt = bbp_get_reply_post_type();
    $tps = bbp_get_trash_status_id();
    $sps = bbp_get_spam_status_id();
    $pps = bbp_get_pending_status_id();
    $sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ( '{$tps}', '{$sps}', '{$pps}' ) GROUP BY `post_parent`);";
    if (is_wp_error($bbp_db->query($sql))) {
        return array(2, sprintf($statement, $result));
    }
    return array(0, sprintf($statement, __('Complete!', 'bbpress')));
}
function pg_get_user_unread($user_id = 0)
{
    // Default to the displayed user
    $user_id = bbp_get_user_id($user_id);
    if (empty($user_id)) {
        return false;
    }
    // If user has unread topics, load them
    $read_ids = (string) get_user_meta($user_id, '_bbp_mar_read_ids', true);
    $read_ids = (array) explode(',', $read_ids);
    $read_ids = array_filter($read_ids);
    if (!empty($read_ids)) {
        //so we have unreads, so need to create a list of unread that the user can see
        //so first we create a list of topics the user can see
        global $wpdb;
        $topic = bbp_get_topic_post_type();
        $post_ids = $wpdb->get_col("select ID from {$wpdb->posts} where post_type = '{$topic}'");
        //check this list against those the user is allowed to see, and create a list of valid ones for the wp_query in bbp_has_topics
        $allowed_posts = check_private_groups_topic_ids($post_ids);
        //now we need to take out of that list all read topics for that user
        foreach ($read_ids as $read_id) {
            if (($key = array_search($read_id, $allowed_posts)) !== false) {
                unset($allowed_posts[$key]);
            }
        }
        //so now we have an allowed list that has only topics the user can see, but not topics the user has read
        //now we use the code from bbp_has_topics to run the list - we can't call it as PG already filters the original function
        global $wp_rewrite;
        /** Defaults **************************************************************/
        // Other defaults
        $default_topic_search = !empty($_REQUEST['ts']) ? $_REQUEST['ts'] : false;
        $default_show_stickies = (bool) (bbp_is_single_forum() || bbp_is_topic_archive()) && false === $default_topic_search;
        $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any';
        // Default argument array
        $default = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $default_post_parent, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 's' => $default_topic_search, 'show_stickies' => $default_show_stickies, 'max_num_pages' => false, 'post__in' => $allowed_posts);
        // What are the default allowed statuses (based on user caps)
        if (bbp_get_view_all()) {
            // Default view=all statuses
            $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id());
            // Add support for private status
            if (current_user_can('read_private_topics')) {
                $post_statuses[] = bbp_get_private_status_id();
            }
            // Join post statuses together
            $default['post_status'] = implode(',', $post_statuses);
            // Lean on the 'perm' query var value of 'readable' to provide statuses
        } else {
            $default['perm'] = 'readable';
        }
        // Maybe query for topic tags
        if (bbp_is_topic_tag()) {
            $default['term'] = bbp_get_topic_tag_slug();
            $default['taxonomy'] = bbp_get_topic_tag_tax_id();
        }
        /** Setup *****************************************************************/
        // Parse arguments against default values
        //stopped to prevent parsing
        //$r = bbp_parse_args( $args, $default, 'has_topics' );
        // Get bbPress
        $bbp = bbpress();
        // Call the query
        //now query the original default
        $bbp->topic_query = new WP_Query($default);
        // Set post_parent back to 0 if originally set to 'any'
        if ('any' === $r['post_parent']) {
            $r['post_parent'] = 0;
        }
        // Limited the number of pages shown
        if (!empty($r['max_num_pages'])) {
            $bbp->topic_query->max_num_pages = $r['max_num_pages'];
        }
        /** Stickies **************************************************************/
        // Put sticky posts at the top of the posts array
        if (!empty($r['show_stickies']) && $r['paged'] <= 1) {
            // Get super stickies and stickies in this forum
            $stickies = bbp_get_super_stickies();
            // Get stickies for current forum
            if (!empty($r['post_parent'])) {
                $stickies = array_merge($stickies, bbp_get_stickies($r['post_parent']));
            }
            // Remove any duplicate stickies
            $stickies = array_unique($stickies);
            // We have stickies
            if (is_array($stickies) && !empty($stickies)) {
                // Start the offset at -1 so first sticky is at correct 0 offset
                $sticky_offset = -1;
                // Loop over topics and relocate stickies to the front.
                foreach ($stickies as $sticky_index => $sticky_ID) {
                    // Get the post offset from the posts array
                    $post_offsets = wp_filter_object_list($bbp->topic_query->posts, array('ID' => $sticky_ID), 'OR', 'ID');
                    // Continue if no post offsets
                    if (empty($post_offsets)) {
                        continue;
                    }
                    // Loop over posts in current query and splice them into position
                    foreach (array_keys($post_offsets) as $post_offset) {
                        $sticky_offset++;
                        $sticky = $bbp->topic_query->posts[$post_offset];
                        // Remove sticky from current position
                        array_splice($bbp->topic_query->posts, $post_offset, 1);
                        // Move to front, after other stickies
                        array_splice($bbp->topic_query->posts, $sticky_offset, 0, array($sticky));
                        // Cleanup
                        unset($stickies[$sticky_index]);
                        unset($sticky);
                    }
                    // Cleanup
                    unset($post_offsets);
                }
                // Cleanup
                unset($sticky_offset);
                // If any posts have been excluded specifically, Ignore those that are sticky.
                if (!empty($stickies) && !empty($r['post__not_in'])) {
                    $stickies = array_diff($stickies, $r['post__not_in']);
                }
                // Fetch sticky posts that weren't in the query results
                if (!empty($stickies)) {
                    // Query to use in get_posts to get sticky posts
                    $sticky_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => 'any', 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies);
                    // Cleanup
                    unset($stickies);
                    // Conditionally exclude private/hidden forum ID's
                    $exclude_forum_ids = bbp_exclude_forum_ids('array');
                    if (!empty($exclude_forum_ids)) {
                        $sticky_query['post_parent__not_in'] = $exclude_forum_ids;
                    }
                    // What are the default allowed statuses (based on user caps)
                    if (bbp_get_view_all()) {
                        $sticky_query['post_status'] = $r['post_status'];
                        // Lean on the 'perm' query var value of 'readable' to provide statuses
                    } else {
                        $sticky_query['post_status'] = $r['perm'];
                    }
                    // Get all stickies
                    $sticky_posts = get_posts($sticky_query);
                    if (!empty($sticky_posts)) {
                        // Get a count of the visible stickies
                        $sticky_count = count($sticky_posts);
                        // Merge the stickies topics with the query topics .
                        $bbp->topic_query->posts = array_merge($sticky_posts, $bbp->topic_query->posts);
                        // Adjust loop and counts for new sticky positions
                        $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count;
                        $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count;
                        // Cleanup
                        unset($sticky_posts);
                    }
                }
            }
        }
        // If no limit to posts per page, set it to the current post_count
        if (-1 === $r['posts_per_page']) {
            $r['posts_per_page'] = $bbp->topic_query->post_count;
        }
        // Add pagination values to query object
        $bbp->topic_query->posts_per_page = $r['posts_per_page'];
        $bbp->topic_query->paged = $r['paged'];
        // Only add pagination if query returned results
        if (((int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts) && (int) $bbp->topic_query->posts_per_page) {
            // Limit the number of topics shown based on maximum allowed pages
            if (!empty($r['max_num_pages']) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count) {
                $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count;
            }
            // If pretty permalinks are enabled, make our pagination pretty
            if ($wp_rewrite->using_permalinks()) {
                // User's topics
                if (bbp_is_single_user_topics()) {
                    $base = bbp_get_user_topics_created_url(bbp_get_displayed_user_id());
                    // User's favorites
                } elseif (bbp_is_favorites()) {
                    $base = bbp_get_favorites_permalink(bbp_get_displayed_user_id());
                    // User's subscriptions
                } elseif (bbp_is_subscriptions()) {
                    $base = bbp_get_subscriptions_permalink(bbp_get_displayed_user_id());
                    // Root profile page
                } elseif (bbp_is_single_user()) {
                    $base = bbp_get_user_profile_url(bbp_get_displayed_user_id());
                    // View
                } elseif (bbp_is_single_view()) {
                    $base = bbp_get_view_url();
                    // Topic tag
                } elseif (bbp_is_topic_tag()) {
                    $base = bbp_get_topic_tag_link();
                    // Page or single post
                } elseif (is_page() || is_single()) {
                    $base = get_permalink();
                    // Forum archive
                } elseif (bbp_is_forum_archive()) {
                    $base = bbp_get_forums_url();
                    // Topic archive
                } elseif (bbp_is_topic_archive()) {
                    $base = bbp_get_topics_url();
                    // Default
                } else {
                    $base = get_permalink((int) $r['post_parent']);
                }
                // Use pagination base
                $base = trailingslashit($base) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/');
                // Unpretty pagination
            } else {
                $base = add_query_arg('paged', '%#%');
            }
            // Pagination settings with filter
            $bbp_topic_pagination = apply_filters('bbp_topic_pagination', array('base' => $base, 'format' => '', 'total' => $r['posts_per_page'] === $bbp->topic_query->found_posts ? 1 : ceil((int) $bbp->topic_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->topic_query->paged, 'prev_text' => is_rtl() ? '&rarr;' : '&larr;', 'next_text' => is_rtl() ? '&larr;' : '&rarr;', 'mid_size' => 1));
            // Add pagination to query object
            $bbp->topic_query->pagination_links = paginate_links($bbp_topic_pagination);
            // Remove first page from pagination
            $bbp->topic_query->pagination_links = str_replace($wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links);
        }
        // Return object
        return apply_filters('pg_get_user_unread', $bbp->topic_query->have_posts(), $bbp->topic_query);
    }
    //if no unread
    return bbp_has_topics();
    // default query
}