public static function SavePost($post_id, $post, $update)
 {
     if (wp_is_post_revision($post_id) || $post->post_status != 'publish' || $post->post_type != 'namaste_course') {
         return;
     }
     $meta = get_post_meta($post_id, 'buddypress_id', true);
     if (empty($meta)) {
         $group_id = groups_create_group(array('creator_id' => get_current_user_id(), 'name' => $post->post_title, 'description' => 'Обсуждение курса ' . $post->post_title, 'enable_forum' => 1));
         update_post_meta($post_id, 'buddypress_id', $group_id);
         groups_edit_group_settings($group_id, 1, 'private', 'mods');
         $forum_id = bbp_insert_forum($forum_data = array('post_status' => bbp_get_private_status_id(), 'post_type' => bbp_get_forum_post_type(), 'post_author' => bbp_get_current_user_id(), 'post_content' => 'Обсуждение курса ' . $post->post_title, 'post_title' => $post->post_title), $forum_meta = array());
         bbp_update_group_forum_ids($group_id, (array) $forum_id);
         bbp_update_forum_group_ids($forum_id, (array) $group_id);
     }
     bbp_add_user_forum_subscription(bbp_get_current_user_id(), $forum_id);
     update_post_meta($forum_id, '_forum_course_id', $post_id);
 }
/**
 * This function filters the list of forums based on the users rank as set by the Mebmers plugin
 */
function tehnik_bpp_filter_forums_by_permissions($args = '')
{
    $bbp = bbpress();
    // Setup possible post__not_in array
    $post_stati[] = bbp_get_public_status_id();
    // Check if user can read private forums
    if (current_user_can('read_private_forums')) {
        $post_stati[] = bbp_get_private_status_id();
    }
    // Check if user can read hidden forums
    if (current_user_can('read_hidden_forums')) {
        $post_stati[] = bbp_get_hidden_status_id();
    }
    // The default forum query for most circumstances
    $meta_query = array('post_type' => bbp_get_forum_post_type(), 'post_parent' => bbp_is_forum_archive() ? 0 : bbp_get_forum_id(), 'post_status' => implode(',', $post_stati), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'orderby' => 'menu_order', 'order' => 'ASC');
    //Get an array of IDs which the current user has permissions to view
    $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($meta_query));
    // The default forum query with allowed forum ids array added
    $meta_query['post__in'] = $allowed_forums;
    $bbp_f = bbp_parse_args($args, $meta_query, 'has_forums');
    // Run the query
    $bbp->forum_query = new WP_Query($bbp_f);
    return apply_filters('bpp_filter_forums_by_permissions', $bbp->forum_query->have_posts(), $bbp->forum_query);
}
Example #3
0
/**
 * Is the reply private?
 *
 * @since 2.6.0 bbPress (r5507)
 *
 * @param int $reply_id Optional. Topic id
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_status() To get the reply status
 * @uses apply_filters() Calls 'bbp_is_reply_private' with the reply id
 * @return bool True if private, false if not.
 */
function bbp_is_reply_private($reply_id = 0)
{
    $reply_status = bbp_get_reply_status(bbp_get_reply_id($reply_id)) === bbp_get_private_status_id();
    return (bool) apply_filters('bbp_is_reply_private', (bool) $reply_status, $reply_id);
}
Example #4
0
/**
 * Is the forum private?
 *
 * @since 2.0.0 bbPress (r2746)
 *
 * @param int $forum_id Optional. Forum id
 * @param bool $check_ancestors Check if the ancestors are private
 * @uses bbp_get_forum_id() To get the forum ID
 * @uses bbp_is_forum_visibility() To check the forum visibility ID
 * @return bool True if private, false if not
 */
function bbp_is_forum_private($forum_id = 0, $check_ancestors = true)
{
    // Get the forum ID
    $forum_id = bbp_get_forum_id($forum_id);
    // Check if the forum or one of it's ancestors is private
    $retval = bbp_is_forum_visibility($forum_id, bbp_get_private_status_id(), $check_ancestors, 'OR');
    return (bool) apply_filters('bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors);
}
Example #5
0
 /**
  * Save the Group Forum data on create
  *
  * @since bbPress (r3465)
  */
 public function create_screen_save()
 {
     check_admin_referer('groups_create_save_' . $this->slug);
     $create_forum = !empty($_POST['bbp-create-group-forum']) ? true : false;
     $forum_id = 0;
     $forum_ids = bbp_get_group_forum_ids(bp_get_new_group_id());
     if (!empty($forum_ids)) {
         $forum_id = (int) is_array($forum_ids) ? $forum_ids[0] : $forum_ids;
     }
     // Create a forum, or not
     switch ($create_forum) {
         case true:
             // Bail if initial content was already created
             if (!empty($forum_id)) {
                 return;
             }
             // Set the default forum status
             switch (bp_get_new_group_status()) {
                 case 'hidden':
                     $status = bbp_get_hidden_status_id();
                     break;
                 case 'private':
                     $status = bbp_get_private_status_id();
                     break;
                 case 'public':
                 default:
                     $status = bbp_get_public_status_id();
                     break;
             }
             // Create the initial forum
             $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => bp_get_new_group_name(), 'post_content' => bp_get_new_group_description(), 'post_status' => $status));
             // Run the BP-specific functions for new groups
             $this->new_forum(array('forum_id' => $forum_id));
             break;
         case false:
             // Forum was created but is now being undone
             if (!empty($forum_id)) {
                 wp_delete_post($forum_id, true);
                 groups_delete_groupmeta(bp_get_new_group_id(), 'forum_id');
             }
             break;
     }
 }
Example #6
0
/**
 * Adjusts forum, topic, and reply queries to exclude items that might be
 * contained inside hidden or private forums that the user does not have the
 * capability to view.
 *
 * Doing it with an action allows us to trap all WP_Query's rather than needing
 * to hardcode this logic into each query. It also protects forum content for
 * plugins that might be doing their own queries.
 *
 * @since bbPress (r3291)
 *
 * @param WP_Query $posts_query
 *
 * @uses apply_filters()
 * @uses bbp_exclude_forum_ids()
 * @uses bbp_get_topic_post_type()
 * @uses bbp_get_reply_post_type()
 * @return WP_Query
 */
function bbp_pre_get_posts_normalize_forum_visibility($posts_query = null)
{
    // Bail if all forums are explicitly allowed
    if (true === apply_filters('bbp_include_all_forums', false, $posts_query)) {
        return;
    }
    // Bail if $posts_query is not an object or of incorrect class
    if (!is_object($posts_query) || !is_a($posts_query, 'WP_Query')) {
        return;
    }
    // Get query post types array .
    $post_types = (array) $posts_query->get('post_type');
    // Forums
    if (bbp_get_forum_post_type() === implode('', $post_types)) {
        // Prevent accidental wp-admin post_row override
        if (is_admin() && isset($_REQUEST['post_status'])) {
            return;
        }
        /** Default ***********************************************************/
        // Get any existing post status
        $post_stati = $posts_query->get('post_status');
        // Default to public status
        if (empty($post_stati)) {
            $post_stati[] = bbp_get_public_status_id();
            // Split the status string
        } elseif (is_string($post_stati)) {
            $post_stati = explode(',', $post_stati);
        }
        /** Private ***********************************************************/
        // Remove bbp_get_private_status_id() if user is not capable
        if (!current_user_can('read_private_forums')) {
            $key = array_search(bbp_get_private_status_id(), $post_stati);
            if (!empty($key)) {
                unset($post_stati[$key]);
            }
            // ...or add it if they are
        } else {
            $post_stati[] = bbp_get_private_status_id();
        }
        /** Hidden ************************************************************/
        // Remove bbp_get_hidden_status_id() if user is not capable
        if (!current_user_can('read_hidden_forums')) {
            $key = array_search(bbp_get_hidden_status_id(), $post_stati);
            if (!empty($key)) {
                unset($post_stati[$key]);
            }
            // ...or add it if they are
        } else {
            $post_stati[] = bbp_get_hidden_status_id();
        }
        // Add the statuses
        $posts_query->set('post_status', array_unique(array_filter($post_stati)));
    }
    // Topics Or Replies
    if (array_intersect(array(bbp_get_topic_post_type(), bbp_get_reply_post_type()), $post_types)) {
        // Get forums to exclude
        $forum_ids = bbp_exclude_forum_ids('meta_query');
        // Bail if no forums to exclude
        if (!array_filter($forum_ids)) {
            return;
        }
        // Get any existing meta queries
        $meta_query = $posts_query->get('meta_query');
        // Add our meta query to existing
        $meta_query[] = $forum_ids;
        // Set the meta_query var
        $posts_query->set('meta_query', $meta_query);
    }
}
Example #7
0
/**
 * The main reply loop. WordPress makes this easy for us
 *
 * @since bbPress (r2553)
 *
 * @param mixed $args All the arguments supported by {@link WP_Query}
 * @uses bbp_show_lead_topic() Are we showing the topic as a lead?
 * @uses bbp_get_topic_id() To get the topic id
 * @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 get_option() To get the replies per page option
 * @uses bbp_get_paged() To get the current page value
 * @uses current_user_can() To check if the current user is capable of editing
 *                           others' replies
 * @uses WP_Query To make query and get the replies
 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
 * @uses get_permalink() To get the permalink
 * @uses add_query_arg() To add custom args to the url
 * @uses apply_filters() Calls 'bbp_replies_pagination' with the pagination args
 * @uses paginate_links() To paginate the links
 * @uses apply_filters() Calls 'bbp_has_replies' with
 *                        bbPres::reply_query::have_posts()
 *                        and bbPres::reply_query
 * @return object Multidimensional array of reply information
 */
function bbp_has_replies($args = '')
{
    global $wp_rewrite;
    /** Defaults **************************************************************/
    // Other defaults
    $default_reply_search = !empty($_REQUEST['rs']) ? $_REQUEST['rs'] : false;
    $default_post_parent = bbp_is_single_topic() ? bbp_get_topic_id() : 'any';
    $default_post_type = bbp_is_single_topic() && bbp_show_lead_topic() ? bbp_get_reply_post_type() : array(bbp_get_topic_post_type(), bbp_get_reply_post_type());
    $default_thread_replies = (bool) (bbp_is_single_topic() && bbp_thread_replies());
    // Default query args
    $default = array('post_type' => $default_post_type, 'post_parent' => $default_post_parent, 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'ASC', 'hierarchical' => $default_thread_replies, 'ignore_sticky_posts' => true, 's' => $default_reply_search);
    // 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_replies')) {
            $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_replies');
    // Set posts_per_page value if replies are threaded
    $replies_per_page = $r['posts_per_page'];
    if (true === $r['hierarchical']) {
        $r['posts_per_page'] = -1;
    }
    // Get bbPress
    $bbp = bbpress();
    // Call the query
    $bbp->reply_query = new WP_Query($r);
    // Add pagination values to query object
    $bbp->reply_query->posts_per_page = $replies_per_page;
    $bbp->reply_query->paged = $r['paged'];
    // Never home, regardless of what parse_query says
    $bbp->reply_query->is_home = false;
    // Reset is_single if single topic
    if (bbp_is_single_topic()) {
        $bbp->reply_query->is_single = true;
    }
    // Only add reply to if query returned results
    if ((int) $bbp->reply_query->found_posts) {
        // Get reply to for each reply
        foreach ($bbp->reply_query->posts as &$post) {
            // Check for reply post type
            if (bbp_get_reply_post_type() === $post->post_type) {
                $reply_to = bbp_get_reply_to($post->ID);
                // Make sure it's a reply to a reply
                if (empty($reply_to) || bbp_get_reply_topic_id($post->ID) === $reply_to) {
                    $reply_to = 0;
                }
                // Add reply_to to the post object so we can walk it later
                $post->reply_to = $reply_to;
            }
        }
    }
    // Only add pagination if query returned results
    if ((int) $bbp->reply_query->found_posts && (int) $bbp->reply_query->posts_per_page) {
        // If pretty permalinks are enabled, make our pagination pretty
        if ($wp_rewrite->using_permalinks()) {
            // User's replies
            if (bbp_is_single_user_replies()) {
                $base = bbp_get_user_replies_created_url(bbp_get_displayed_user_id());
                // Root profile page
            } elseif (bbp_is_single_user()) {
                $base = bbp_get_user_profile_url(bbp_get_displayed_user_id());
                // Page or single post
            } elseif (is_page() || is_single()) {
                $base = get_permalink();
                // Single topic
            } else {
                $base = get_permalink(bbp_get_topic_id());
            }
            $base = trailingslashit($base) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/');
            // Unpretty permalinks
        } else {
            $base = add_query_arg('paged', '%#%');
        }
        // Figure out total pages
        if (true === $r['hierarchical']) {
            $walker = new BBP_Walker_Reply();
            $total_pages = ceil((int) $walker->get_number_of_root_elements($bbp->reply_query->posts) / (int) $replies_per_page);
        } else {
            $total_pages = ceil((int) $bbp->reply_query->found_posts / (int) $replies_per_page);
            // Add pagination to query object
            $bbp->reply_query->pagination_links = paginate_links(apply_filters('bbp_replies_pagination', array('base' => $base, 'format' => '', 'total' => $total_pages, 'current' => (int) $bbp->reply_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1, 'add_args' => bbp_get_view_all() ? array('view' => 'all') : false)));
            // Remove first page from pagination
            if ($wp_rewrite->using_permalinks()) {
                $bbp->reply_query->pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $bbp->reply_query->pagination_links);
            } else {
                $bbp->reply_query->pagination_links = str_replace('&paged=1', '', $bbp->reply_query->pagination_links);
            }
        }
    }
    // Return object
    return apply_filters('bbp_has_replies', $bbp->reply_query->have_posts(), $bbp->reply_query);
}
Example #8
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 #9
0
/**
 * Return the forum visibility dropdown
 *
 * @since bbPress (r3563)
 *
 * @param int $forum_id The forum id to use
 * @uses bbp_is_topic_edit() To check if it's the topic edit page
 * @uses bbp_get_forum_visibility() To get the forum visibility
 * @uses apply_filters()
 * @return string HTML select list for selecting forum visibility
 */
function bbp_get_form_forum_visibility_dropdown($forum_id = 0)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $forum_attr = apply_filters('bbp_forum_visibilities', array(bbp_get_public_status_id() => __('Public', 'bbpress'), bbp_get_private_status_id() => __('Private', 'bbpress'), bbp_get_hidden_status_id() => __('Hidden', 'bbpress')));
    $visibility_output = '<select name="bbp_forum_visibility" id="bbp_forum_visibility_select">' . "\n";
    foreach ($forum_attr as $value => $label) {
        $visibility_output .= "\t" . '<option value="' . $value . '"' . selected(bbp_get_forum_visibility($forum_id), $value, false) . '>' . esc_html($label) . '</option>' . "\n";
    }
    $visibility_output .= '</select>';
    return apply_filters('bbp_get_form_forum_visibility_dropdown', $visibility_output, $forum_id, $forum_attr);
}
Example #10
0
 public function create_screen_save_notab($group_id = 0)
 {
     // No nonce check, since there's no tab
     // Check for possibly empty group_id
     if (empty($group_id)) {
         $group_id = bp_get_new_group_id();
     }
     // We always set this true, because we always create a forum (the user doesn't get to choose whether they want it or not anymore)
     $create_forum = true;
     //!empty( $_POST['bbp-create-group-forum'] ) ? true : false;
     $forum_id = 0;
     $forum_ids = bbp_get_group_forum_ids($group_id);
     if (!empty($forum_ids)) {
         $forum_id = (int) is_array($forum_ids) ? $forum_ids[0] : $forum_ids;
     }
     // Create a forum, or not
     switch ($create_forum) {
         case true:
             // Bail if initial content was already created
             if (!empty($forum_id)) {
                 return;
             }
             // Set the default forum status
             switch (bp_get_new_group_status()) {
                 case 'hidden':
                     $status = bbp_get_hidden_status_id();
                     break;
                 case 'private':
                     $status = bbp_get_private_status_id();
                     break;
                 case 'public':
                 default:
                     $status = bbp_get_public_status_id();
                     break;
             }
             // Create the initial forum
             $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => bp_get_new_group_name(), 'post_content' => bp_get_new_group_description(), 'post_status' => $status));
             // Run the BP-specific functions for new groups
             $this->new_forum(array('forum_id' => $forum_id));
             // Update forum active
             groups_update_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true);
             // Toggle forum on
             $this->toggle_group_forum(bp_get_new_group_id(), true);
             break;
         case false:
             // Forum was created but is now being undone
             if (!empty($forum_id)) {
                 // Delete the forum
                 wp_delete_post($forum_id, true);
                 // Delete meta values
                 groups_delete_groupmeta(bp_get_new_group_id(), 'forum_id');
                 groups_delete_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id);
                 // Toggle forum off
                 $this->toggle_group_forum(bp_get_new_group_id(), false);
             }
             break;
     }
 }
Example #11
0
/**
 * Recaches the private and hidden forums
 *
 * @since bbPress (r4104)
 *
 * @uses delete_option() to delete private and hidden forum pointers
 * @uses WP_Query() To query post IDs
 * @uses is_wp_error() To return if error occurred
 * @uses update_option() To update the private and hidden post ID pointers
 * @return array An array of the status code and the message
 */
function bbp_admin_repair_forum_visibility()
{
    $statement = __('Recalculating forum visibility &hellip; %s', 'bbpress');
    $result = __('Failed!', 'bbpress');
    // First, delete everything.
    delete_option('_bbp_private_forums');
    delete_option('_bbp_hidden_forums');
    // Next, get all the private and hidden forums
    $private_forums = new WP_Query(array('suppress_filters' => true, 'nopaging' => true, 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_private_status_id(), 'fields' => 'ids'));
    $hidden_forums = new WP_Query(array('suppress_filters' => true, 'nopaging' => true, 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_hidden_status_id(), 'fields' => 'ids'));
    // Bail if queries returned errors
    if (is_wp_error($private_forums) || is_wp_error($hidden_forums)) {
        return array(2, sprintf($statement, $result));
    }
    update_option('_bbp_private_forums', $private_forums->posts);
    // Private forums
    update_option('_bbp_hidden_forums', $hidden_forums->posts);
    // Hidden forums
    // Complete results
    $result = __('Complete!', 'bbpress');
    return array(0, sprintf($statement, $result));
}
Example #12
0
 /**
  * @covers ::bbp_is_forum_private
  */
 public function test_bbp_is_forum_private()
 {
     $f = $this->factory->forum->create(array('post_status' => 'private'));
     $forum = bbp_get_forum_visibility($f);
     $this->assertSame('private', $forum);
     $forum_status_id = bbp_get_private_status_id($f);
     $this->assertSame('private', $forum_status_id);
     $this->assertTrue(bbp_is_forum_private($f));
 }
Example #13
0
 /**
  * Forum Row actions
  *
  * Remove the quick-edit action link and display the description under
  * the forum title and add the open/close links
  *
  * @since 2.0.0 bbPress (r2577)
  *
  * @param array $actions Actions
  * @param array $forum Forum object
  * @uses bbp_get_public_status_id() To get the published forum id's
  * @uses bbp_get_private_status_id() To get the private forum id's
  * @uses bbp_get_hidden_status_id() To get the hidden forum id's
  * @uses bbp_get_closed_status_id() To get the closed forum id's
  * @uses wp_nonce_url() To nonce the url
  * @uses bbp_is_forum_open() To check if a forum is open
  * @uses bbp_forum_content() To output forum description
  * @return array $actions Actions
  */
 public function row_actions($actions, $forum)
 {
     if ($this->bail()) {
         return $actions;
     }
     unset($actions['inline hide-if-no-js']);
     // Only show the actions if the user is capable of viewing them :)
     if (current_user_can('keep_gate', $forum->ID)) {
         // Show the 'close' and 'open' link on published, private, hidden and closed posts only
         if (in_array($forum->post_status, array(bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id(), bbp_get_closed_status_id()))) {
             $close_uri = wp_nonce_url(add_query_arg(array('forum_id' => $forum->ID, 'action' => 'bbp_toggle_forum_close'), remove_query_arg(array('bbp_forum_toggle_notice', 'forum_id', 'failed', 'super'))), 'close-forum_' . $forum->ID);
             if (bbp_is_forum_open($forum->ID)) {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Close this forum', 'bbpress') . '">' . _x('Close', 'Close a Forum', 'bbpress') . '</a>';
             } else {
                 $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Open this forum', 'bbpress') . '">' . _x('Open', 'Open a Forum', 'bbpress') . '</a>';
             }
         }
     }
     // simple hack to show the forum description under the title
     bbp_forum_content($forum->ID);
     return $actions;
 }
function bbp_list_private_groups_subforums($args)
{
    // Use passed integer as post_parent
    if (is_numeric($args)) {
        $args = array('post_parent' => $args);
    }
    // Setup possible post__not_in array
    $post_stati[] = bbp_get_public_status_id();
    // Super admin get whitelisted post statuses
    if (bbp_is_user_keymaster()) {
        $post_stati = array(bbp_get_public_status_id(), bbp_get_private_status_id(), bbp_get_hidden_status_id());
        // Not a keymaster, so check caps
    } else {
        // Check if user can read private forums
        if (current_user_can('read_private_forums')) {
            $post_stati[] = bbp_get_private_status_id();
        }
        // Check if user can read hidden forums
        if (current_user_can('read_hidden_forums')) {
            $post_stati[] = bbp_get_hidden_status_id();
        }
    }
    $args['post_status'] = implode(',', $post_stati);
    return $args;
}
Example #15
0
 public static function include_private_forums($posts_query)
 {
     // Bail if $posts_query is not an object or of incorrect class
     if (!is_object($posts_query) || !is_a($posts_query, 'WP_Query')) {
         return;
     }
     // Get query post types array .
     $post_types = (array) $posts_query->get('post_type');
     // Forums
     if (bbp_get_forum_post_type() === implode('', $post_types)) {
         // Prevent accidental wp-admin post_row override
         if (is_admin() && isset($_REQUEST['post_status'])) {
             return;
         }
         /** Default ***********************************************************/
         // Get any existing post status
         $post_stati = (array) $posts_query->get('post_status');
         if (!in_array(bbp_get_private_status_id(), $post_stati)) {
             $post_stati[] = bbp_get_private_status_id();
             // Add the statuses
             $posts_query->set('post_status', array_unique(array_filter($post_stati)));
         }
     }
 }
Example #16
0
 /**
  * @covers ::bbp_is_reply_private
  */
 public function test_bbp_is_reply_private()
 {
     $forum_id = $this->factory->forum->create();
     $topic_id = $this->factory->topic->create(array('post_parent' => $forum_id, 'topic_meta' => array('forum_id' => $forum_id)));
     $reply_id = $this->factory->reply->create(array('post_parent' => $topic_id, 'reply_meta' => array('forum_id' => $forum_id, 'topic_id' => $topic_id)));
     $reply_private = bbp_is_reply_private($reply_id);
     $this->assertFalse($reply_private);
     $r = $this->factory->reply->create(array('post_parent' => $topic_id, 'post_status' => bbp_get_private_status_id(), 'reply_meta' => array('forum_id' => $forum_id, 'topic_id' => $topic_id)));
     $reply_private = bbp_is_reply_private($r);
     $this->assertTrue($reply_private);
 }
Example #17
0
/**
 * Is the forum private?
 *
 * @since bbPress (r2746)
 *
 * @param int $forum_id Optional. Forum id
 * @param bool $check_ancestors Check if the ancestors are private (only if
 *                               they're a category)
 * @uses get_post_meta() To get the forum private meta
 * @uses bbp_get_forum_ancestors() To get the forum ancestors
 * @uses bbp_is_forum_category() To check if the forum is a category
 * @uses bbp_is_forum_closed() To check if the forum is closed
 * @return bool True if closed, false if not
 */
function bbp_is_forum_private($forum_id = 0, $check_ancestors = true)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $visibility = bbp_get_forum_visibility($forum_id);
    // If post status is private, return true
    $retval = bbp_get_private_status_id() === $visibility;
    // Check ancestors and inherit their privacy setting for display
    if (!empty($check_ancestors)) {
        $ancestors = bbp_get_forum_ancestors($forum_id);
        foreach ((array) $ancestors as $ancestor) {
            if (bbp_is_forum($ancestor) && bbp_is_forum_private($ancestor, false)) {
                $retval = true;
            }
        }
    }
    return (bool) apply_filters('bbp_is_forum_private', (bool) $retval, $forum_id, $check_ancestors);
}
Example #18
0
function bp_group_organizer_admin_page()
{
    global $wpdb;
    // Permissions Check
    if (!current_user_can('manage_options')) {
        wp_die(__('Cheatin&#8217; uh?'));
    }
    // Load all the nav menu interface functions
    require_once 'includes/group-meta-boxes.php';
    require_once 'includes/group-organizer-template.php';
    require_once 'includes/group-organizer.php';
    // Container for any messages displayed to the user
    $messages = array();
    // Container that stores the name of the active menu
    $nav_menu_selected_title = '';
    // Allowed actions: add, update, delete
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'edit';
    $errored = false;
    switch ($action) {
        case 'add-group':
            check_admin_referer('add-group', 'group-settings-column-nonce');
            $group['name'] = stripslashes($_POST['group_name']);
            $group['description'] = stripslashes($_POST['group_desc']);
            $group['slug'] = groups_check_slug($_POST['group_slug']);
            $group['status'] = $_POST['group_status'];
            $group['enable_forum'] = isset($_POST['group_forum']) ? true : false;
            $group['date_created'] = date('Y-m-d H:i:s');
            if ($group['slug'] != $_POST['group_slug']) {
                $messages[] = '<div class="updated warning"><p>' . sprintf(__('The group slug you specified was unavailable or invalid. This group was created with the slug: <code>%s</code>.', 'bp-group-organizer'), $group['slug']) . '</p></div>';
            }
            if (empty($group['name'])) {
                $messages[] = '<div class="error"><p>' . __('Group could not be created because one or more required fields were not filled in', 'bp-group-organizer') . '</p></div>';
                $errored = true;
            }
            if (!$errored) {
                $group_id = groups_create_group($group);
                if (!$group_id) {
                    $wpdb->show_errors();
                    $wpdb->print_error();
                    $messages[] = '<div class="error"><p>' . __('Group was not successfully created.', 'bp-group-organizer') . '</p></div>';
                } else {
                    $messages[] = '<div class="updated"><p>' . __('Group was created successfully.', 'bp-group-organizer') . '</p></div>';
                }
            }
            if (!empty($group_id)) {
                groups_update_groupmeta($group_id, 'total_member_count', 1);
                if (bpgo_is_hierarchy_available()) {
                    $obj_group = new BP_Groups_Hierarchy($group_id);
                    $obj_group->parent_id = (int) $_POST['group_parent'];
                    $obj_group->save();
                }
                // Create the forum if enable_forum is checked
                if ($group['enable_forum']) {
                    // Ensure group forums are activated, and group does not already have a forum
                    if (bp_is_active('forums')) {
                        // Check for BuddyPress group forums
                        if (!groups_get_groupmeta($group_id, 'forum_id')) {
                            groups_new_group_forum($group_id, $group['name'], $group['description']);
                        }
                    } else {
                        if (function_exists('bbp_is_group_forums_active') && bbp_is_group_forums_active()) {
                            // Check for bbPress group forums
                            if (count(bbp_get_group_forum_ids($group_id)) == 0) {
                                // Create the group forum - implementation from BBP_Forums_Group_Extension:create_screen_save
                                // Set the default forum status
                                switch ($group['status']) {
                                    case 'hidden':
                                        $status = bbp_get_hidden_status_id();
                                        break;
                                    case 'private':
                                        $status = bbp_get_private_status_id();
                                        break;
                                    case 'public':
                                    default:
                                        $status = bbp_get_public_status_id();
                                        break;
                                }
                                // Create the initial forum
                                $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group['name'], 'post_content' => $group['description'], 'post_status' => $status));
                                bbp_add_forum_id_to_group($group_id, $forum_id);
                                bbp_add_group_id_to_forum($forum_id, $group_id);
                            }
                        }
                    }
                }
                do_action('bp_group_organizer_save_new_group_options', $group_id);
            }
            break;
        case 'delete-group':
            $group_id = (int) $_REQUEST['group_id'];
            check_admin_referer('delete-group_' . $group_id);
            break;
        case 'update':
            check_admin_referer('update-groups', 'update-groups-nonce');
            $groups_order = $_POST['group'];
            $parent_ids = $_POST['menu-item-parent-id'];
            $db_ids = $_POST['menu-item-db-id'];
            foreach ($groups_order as $id => $group) {
                $group_reference = new BP_Groups_Group($id);
                if (defined('BP_GROUP_HIERARCHY_IS_INSTALLED') && method_exists('BP_Groups_Hierarchy', 'get_tree')) {
                    // if group hierarchy is installed and available, check for tree changes
                    $group_hierarchy = new BP_Groups_Hierarchy($id);
                    if ($parent_ids[$id] !== null && $group_hierarchy->parent_id != $parent_ids[$id]) {
                        $group_hierarchy->parent_id = $parent_ids[$id];
                        $group_hierarchy->save();
                    } else {
                        if ($group_hierarchy->parent_id != $group['parent_id']) {
                            $group_hierarchy->parent_id = $group['parent_id'];
                            $group_hierarchy->save();
                        }
                    }
                    unset($group_hierarchy);
                }
                // check for group attribute changes
                $attrs_changed = array();
                if ($group['name'] != $group_reference->name) {
                    $group_reference->name = stripslashes($group['name']);
                    $attrs_changed[] = 'name';
                }
                if ($group['slug'] != $group_reference->slug) {
                    $slug = groups_check_slug($group['slug']);
                    if ($slug == $group['slug']) {
                        $group_reference->slug = $group['slug'];
                        $attrs_changed[] = 'slug';
                    }
                }
                if ($group['description'] != $group_reference->description) {
                    $group_reference->description = stripslashes($group['description']);
                    $attrs_changed[] = 'description';
                }
                if ($group['status'] != $group_reference->status && groups_is_valid_status($group['status'])) {
                    $group_reference->status = $group['status'];
                    $attrs_changed[] = 'status';
                }
                if (!isset($group['forum_enabled']) || $group['forum_enabled'] != $group_reference->enable_forum) {
                    $group_reference->enable_forum = isset($group['forum_enabled']) ? true : false;
                    $attrs_changed[] = 'enable_forum';
                }
                if (count($attrs_changed) > 0) {
                    $group_reference->save();
                }
                // finally, let plugins run any other changes
                do_action('group_details_updated', $group_reference->id);
                do_action('bp_group_organizer_save_group_options', $group, $group_reference);
            }
            break;
        case 'import':
            if (!isset($_FILES['import_groups'])) {
                // No files was uploaded
            }
            if (!is_uploaded_file($_FILES['import_groups']['tmp_name'])) {
                // Not an uploaded file
                $errors = array(UPLOAD_ERR_OK => sprintf(__('File uploaded successfully, but there is a problem. (%d)', 'bp-group-organizer'), UPLOAD_ERR_OK), UPLOAD_ERR_INI_SIZE => sprintf(__('File exceeded PHP\'s maximum upload size. (%d)', 'bp-group-organizer'), UPLOAD_ERR_INI_SIZE), UPLOAD_ERR_FORM_SIZE => sprintf(__('File exceeded the form\'s maximum upload size. (%d)', 'bp-group-organizer'), UPLOAD_ERR_FORM_SIZE), UPLOAD_ERR_PARTIAL => sprintf(__('File was only partially uploaded. (%d)', 'bp-group-organizer'), UPLOAD_ERR_PARTIAL), UPLOAD_ERR_NO_FILE => sprintf(__('No uploaded file was found. (%d)', 'bp-group-organizer'), UPLOAD_ERR_NO_FILE), 6 => sprintf(__('No temporary folder could be found for the uploaded file. (%d)', 'bp-group-organizer'), 6), 7 => sprintf(__('Could not write uploaded file to disk. (%d)', 'bp-group-organizer'), 7), 8 => sprintf(__('Upload was stopped by a PHP extension. (%d)', 'bp-group-organizer'), 8));
                $messages[] = '<div class="error"><p>' . sprintf(__('', 'bp-group-organizer'), $errors[$_FILES['import_groups']['error']]) . '</p></div>';
                break;
            }
            require_once dirname(__FILE__) . '/includes/group-organizer-import.php';
            if ($result = bp_group_organizer_import_csv_file($_FILES['import_groups']['tmp_name'], $_POST['import'])) {
                $messages[] = '<div class="updated"><p>' . implode('<br />', $result) . '</p></div>';
            } else {
                $messages[] = '<div class="error"><p>' . 'ERROR - IMPORT FAILED COMPLETELY' . '</p></div>';
            }
            break;
    }
    // Ensure the user will be able to scroll horizontally
    // by adding a class for the max menu depth.
    global $_wp_nav_menu_max_depth;
    $_wp_nav_menu_max_depth = 0;
    if (isset($_REQUEST['screen']) && $_REQUEST['screen'] == 'import') {
        $action = 'import';
    } else {
        $action = 'organize';
    }
    if ($action == 'import') {
        $edit_markup = bp_group_organizer_import_export_page();
    } else {
        $edit_markup = bp_get_groups_to_edit();
    }
    ?>
<div class="wrap">
	<h2><?php 
    esc_html_e('Group Organizer');
    ?>
</h2>
	<?php 
    foreach ($messages as $message) {
        echo $message . "\n";
    }
    ?>
	<div <?php 
    if ($action == 'organize') {
        echo 'id="nav-menus-frame"';
    }
    ?>
>
	<div id="menu-settings-column" class="metabox-holder nav-menus-php">
		<form id="group-organizer-meta" action="" class="group-organizer-meta" method="post" enctype="multipart/form-data">
			<input type="hidden" name="action" value="add-group" />
			<?php 
    wp_nonce_field('add-group', 'group-settings-column-nonce');
    ?>
			<?php 
    if ($action == 'organize') {
        do_meta_boxes('group-organizer', 'side', null);
    }
    ?>
		</form>
	</div><!-- /#menu-settings-column -->
	<div id="menu-management-liquid">
		<div id="menu-management" class="nav-menus-php">

			<div class="nav-tabs-wrapper">
			<div class="nav-tabs">
				<a href="<?php 
    echo esc_url(remove_query_arg(array('screen')));
    ?>
" class="nav-tab <?php 
    if ($action == 'organize') {
        echo 'nav-tab-active';
    }
    ?>
">
					<?php 
    printf('<abbr title="%s">%s</abbr>', esc_html__('Drag and drop your groups', 'bp-group-hierarchy'), __('Organize', 'bp-group-organizer'));
    ?>
				</a>
				<a href="<?php 
    echo esc_url(add_query_arg(array('screen' => 'import')));
    ?>
" class="nav-tab <?php 
    if ($action == 'import') {
        echo 'nav-tab-active';
    }
    ?>
">
					<?php 
    printf('<abbr title="%s">%s</abbr>', esc_html__('Import or export groups in bulk', 'bp-group-organizer'), __('Import / Export', 'bp-group-organizer'));
    ?>
				</a>
			</div>
			</div>


			<div class="menu-edit">
				<?php 
    if ($action == 'organize') {
        ?>
				<form id="update-nav-menu" action="" method="post" enctype="multipart/form-data">
				<?php 
    }
    ?>
					<div id="nav-menu-header">
						<div id="submitpost" class="submitbox">
							<div class="major-publishing-actions">
								<label class="menu-name-label howto open-label" for="menu-name">
									<span><?php 
    _e('Group Organizer', 'bp-group-organizer');
    ?>
</span>
								</label>
								<div class="publishing-action">
									<?php 
    if ($action == 'organize') {
        submit_button(__('Save Groups', 'bp-group-organizer'), 'button-primary menu-save', 'save_menu', false, array('id' => 'save_menu_header'));
    }
    ?>
								</div><!-- END .publishing-action -->
							</div><!-- END .major-publishing-actions -->
						</div><!-- END #submitpost .submitbox -->
						<?php 
    wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
    wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
    wp_nonce_field('update-groups', 'update-groups-nonce');
    ?>
						<input type="hidden" name="action" value="update" />
					</div><!-- END #nav-menu-header -->
					<div id="post-body">
						<div id="post-body-content">
							<?php 
    if (isset($edit_markup)) {
        if (!is_wp_error($edit_markup)) {
            echo $edit_markup;
        }
    } else {
        echo '<div class="post-body-plain">';
        echo '<p>' . __('You don\'t yet have any groups.', 'bp-group-organizer') . '</p>';
        echo '</div>';
    }
    ?>
						</div><!-- /#post-body-content -->
					</div><!-- /#post-body -->
					<div id="nav-menu-footer">
						<div class="major-publishing-actions">
						<div class="publishing-action">
							<?php 
    if ($action == 'organize') {
        submit_button(__('Save Groups', 'bp-group-organizer'), 'button-primary menu-save', 'save_menu', false, array('id' => 'save_menu_header'));
    }
    ?>
						</div>
						</div>
					</div><!-- /#nav-menu-footer -->
				<?php 
    if ($action == 'organize') {
        ?>
				</form><!-- /#update-nav-menu -->
				<?php 
    }
    ?>
			</div><!-- /.menu-edit -->
		</div><!-- /#menu-management -->
	</div><!-- /#menu-management-liquid -->
	</div><!-- /#nav-menus-frame -->
</div><!-- /.wrap-->

<?php 
}
Example #19
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);
}
function bp_group_organizer_import_group($group, $args = array())
{
    if (empty($group['name'])) {
        return false;
    }
    if (isset($group['path'])) {
        if (bpgo_is_hierarchy_available()) {
            // Try to place the group in the requested spot, but if the spot doesn't exist (e.g. because of slug conflicts)
            // then place it as far down the tree as possible
            $parent_path = $group['path'];
            do {
                $parent_path = dirname($parent_path);
                $parent_id = BP_Groups_Hierarchy::get_id_from_slug($parent_path);
            } while ($parent_path != '.' && $parent_id == 0);
            $group['parent_id'] = $parent_id ? $parent_id : 0;
        }
        $group['slug'] = basename($group['path']);
        unset($group['path']);
    }
    $group['slug'] = groups_check_slug($group['slug']);
    $group_id = groups_create_group($group);
    if (!$group_id) {
        return false;
    }
    groups_update_groupmeta($group_id, 'total_member_count', 1);
    if (bpgo_is_hierarchy_available()) {
        $obj_group = new BP_Groups_Hierarchy($group_id);
        $obj_group->parent_id = (int) $group['parent_id'];
        $obj_group->save();
    }
    // Create the forum if enable_forum is checked
    if ($group['enable_forum']) {
        // Ensure group forums are activated, and group does not already have a forum
        if (bp_is_active('forums')) {
            // Check for BuddyPress group forums
            if (!groups_get_groupmeta($group_id, 'forum_id')) {
                groups_new_group_forum($group_id, $group['name'], $group['description']);
            }
        } else {
            if (function_exists('bbp_is_group_forums_active') && bbp_is_group_forums_active()) {
                // Check for bbPress group forums
                if (count(bbp_get_group_forum_ids($group_id)) == 0) {
                    // Create the group forum - implementation from BBP_Forums_Group_Extension:create_screen_save
                    // Set the default forum status
                    switch ($group['status']) {
                        case 'hidden':
                            $status = bbp_get_hidden_status_id();
                            break;
                        case 'private':
                            $status = bbp_get_private_status_id();
                            break;
                        case 'public':
                        default:
                            $status = bbp_get_public_status_id();
                            break;
                    }
                    // Create the initial forum
                    $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => $group['name'], 'post_content' => $group['description'], 'post_status' => $status));
                    bbp_add_forum_id_to_group($group_id, $forum_id);
                    bbp_add_group_id_to_forum($forum_id, $group_id);
                }
            }
        }
    }
    do_action('bp_group_organizer_import_group', $group_id);
    return $group_id;
}
Example #21
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);
}
Example #22
0
 /**
  * Save the Group Forum data on create
  *
  * @since bbPress (r3465)
  */
 public function create_screen_save($group_id = 0)
 {
     // Nonce check
     if (!bbp_verify_nonce_request('groups_create_save_' . $this->slug)) {
         bbp_add_error('bbp_create_group_forum_screen_save', __('<strong>ERROR</strong>: Are you sure you wanted to do that?', 'bbpress'));
         return;
     }
     // Check for possibly empty group_id
     if (empty($group_id)) {
         $group_id = bp_get_new_group_id();
     }
     $create_forum = !empty($_POST['bbp-create-group-forum']) ? true : false;
     $forum_id = 0;
     $forum_ids = bbp_get_group_forum_ids($group_id);
     if (!empty($forum_ids)) {
         $forum_id = (int) is_array($forum_ids) ? $forum_ids[0] : $forum_ids;
     }
     // Create a forum, or not
     switch ($create_forum) {
         case true:
             // Bail if initial content was already created
             if (!empty($forum_id)) {
                 return;
             }
             // Set the default forum status
             switch (bp_get_new_group_status()) {
                 case 'hidden':
                     $status = bbp_get_hidden_status_id();
                     break;
                 case 'private':
                     $status = bbp_get_private_status_id();
                     break;
                 case 'public':
                 default:
                     $status = bbp_get_public_status_id();
                     break;
             }
             // Create the initial forum
             $forum_id = bbp_insert_forum(array('post_parent' => bbp_get_group_forums_root_id(), 'post_title' => bp_get_new_group_name(), 'post_content' => bp_get_new_group_description(), 'post_status' => $status));
             // Run the BP-specific functions for new groups
             $this->new_forum(array('forum_id' => $forum_id));
             // Update forum active
             groups_update_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true);
             // Toggle forum on
             $this->toggle_group_forum(bp_get_new_group_id(), true);
             break;
         case false:
             // Forum was created but is now being undone
             if (!empty($forum_id)) {
                 // Delete the forum
                 wp_delete_post($forum_id, true);
                 // Delete meta values
                 groups_delete_groupmeta(bp_get_new_group_id(), 'forum_id');
                 groups_delete_groupmeta(bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id);
                 // Toggle forum off
                 $this->toggle_group_forum(bp_get_new_group_id(), false);
             }
             break;
     }
 }
Example #23
0
/**
 * Output a select box allowing to pick which forum/topic a new
 * topic/reply belongs in.
 *
 * @since bbPress (r2746)
 *
 * @param mixed $args The function supports these args:
 *  - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum)
 *  - selected: Selected ID, to not have any value as selected, pass
 *               anything smaller than 0 (due to the nature of select
 *               box, the first value would of course be selected -
 *               though you can have that as none (pass 'show_none' arg))
 *  - sort_column: Sort by? Defaults to 'menu_order, post_title'
 *  - child_of: Child of. Defaults to 0
 *  - post_status: Which all post_statuses to find in? Can be an array
 *                  or CSV of publish, category, closed, private, spam,
 *                  trash (based on post type) - if not set, these are
 *                  automatically determined based on the post_type
 *  - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get
 *                     all posts
 *  - walker: Which walker to use? Defaults to
 *             {@link BBP_Walker_Dropdown}
 *  - select_id: ID of the select box. Defaults to 'bbp_forum_id'
 *  - tab: Tabindex value. False or integer
 *  - options_only: Show only <options>? No <select>?
 *  - show_none: False or something like __( '(No Forum)', 'bbpress' ),
 *                will have value=""
 *  - none_found: False or something like
 *                 __( 'No forums to post to!', 'bbpress' )
 *  - disable_categories: Disable forum categories and closed forums?
 *                         Defaults to true. Only for forums and when
 *                         the category option is displayed.
 * @uses BBP_Walker_Dropdown() As the default walker to generate the
 *                              dropdown
 * @uses current_user_can() To check if the current user can read
 *                           private forums
 * @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 walk_page_dropdown_tree() To generate the dropdown using the
 *                                  walker
 * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown
 *                        and args
 * @return string The dropdown
 */
function bbp_get_dropdown($args = '')
{
    /** Arguments *********************************************************/
    $defaults = array('post_type' => bbp_get_forum_post_type(), 'selected' => 0, 'sort_column' => 'menu_order', 'child_of' => '0', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'walker' => '', 'select_id' => 'bbp_forum_id', 'tab' => bbp_get_tab_index(), 'options_only' => false, 'show_none' => false, 'none_found' => false, 'disable_categories' => true);
    $r = bbp_parse_args($args, $defaults, 'get_dropdown');
    if (empty($r['walker'])) {
        $r['walker'] = new BBP_Walker_Dropdown();
        $r['walker']->tree_type = $r['post_type'];
    }
    // Force 0
    if (is_numeric($r['selected']) && $r['selected'] < 0) {
        $r['selected'] = 0;
    }
    extract($r);
    // Unset the args not needed for WP_Query to avoid any possible conflicts.
    // Note: walker and disable_categories are not unset
    unset($r['select_id'], $r['tab'], $r['options_only'], $r['show_none'], $r['none_found']);
    /** Post Status *******************************************************/
    // Define local variable(s)
    $post_stati = array();
    // Public
    $post_stati[] = bbp_get_public_status_id();
    // Forums
    if (bbp_get_forum_post_type() == $post_type) {
        // Private forums
        if (current_user_can('read_private_forums')) {
            $post_stati[] = bbp_get_private_status_id();
        }
        // Hidden forums
        if (current_user_can('read_hidden_forums')) {
            $post_stati[] = bbp_get_hidden_status_id();
        }
    }
    // Setup the post statuses
    $r['post_status'] = implode(',', $post_stati);
    /** Setup variables ***************************************************/
    $name = esc_attr($select_id);
    $select_id = $name;
    $tab = (int) $tab;
    $retval = '';
    $posts = get_posts($r);
    /** Drop Down *********************************************************/
    // Items found
    if (!empty($posts)) {
        if (empty($options_only)) {
            $tab = !empty($tab) ? ' tabindex="' . $tab . '"' : '';
            $retval .= '<select name="' . $name . '" id="' . $select_id . '"' . $tab . '>' . "\n";
        }
        $retval .= !empty($show_none) ? "\t<option value=\"\" class=\"level-0\">" . $show_none . '</option>' : '';
        $retval .= walk_page_dropdown_tree($posts, 0, $r);
        if (empty($options_only)) {
            $retval .= '</select>';
        }
        // No items found - Display feedback if no custom message was passed
    } elseif (empty($none_found)) {
        // Switch the response based on post type
        switch ($post_type) {
            // Topics
            case bbp_get_topic_post_type():
                $retval = __('No topics available', 'bbpress');
                break;
                // Forums
            // Forums
            case bbp_get_forum_post_type():
                $retval = __('No forums available', 'bbpress');
                break;
                // Any other
            // Any other
            default:
                $retval = __('None available', 'bbpress');
                break;
        }
    }
    return apply_filters('bbp_get_dropdown', $retval, $args);
}
Example #24
0
/**
 * Adjusts topic and reply queries to exclude items that might be contained
 * inside hidden or private forums that the user does not have the capability
 * to view.
 *
 * @since bbPress (r3291)
 *
 * @param WP_Query $posts_query
 *
 * @uses apply_filters()
 * @uses bbp_exclude_forum_ids()
 * @uses bbp_get_topic_post_type()
 * @uses bbp_get_reply_post_type()
 * @return WP_Query
 */
function bbp_pre_get_posts_exclude_forums($posts_query)
{
    // Bail if all forums are explicitly allowed
    if (true === apply_filters('bbp_include_all_forums', $posts_query)) {
        return;
    }
    // Bail if $posts_query is not an object or of incorrect class
    if (!is_object($posts_query) || !is_a($posts_query, 'WP_Query')) {
        return;
    }
    // Bail if filters are suppressed on this query
    if (true == $posts_query->get('suppress_filters')) {
        return;
    }
    // Only exclude forums on bbPress queries
    switch ($posts_query->get('post_type')) {
        // Forums
        case bbp_get_forum_post_type():
            // Prevent accidental wp-admin post_row override
            if (is_admin() && isset($_REQUEST['post_status'])) {
                break;
            }
            // Define local variable
            $status = array();
            // All users can see published forums
            $status[] = bbp_get_public_status_id();
            // Add bbp_get_private_status_id() if user is capable
            if (current_user_can('read_private_forums')) {
                $status[] = bbp_get_private_status_id();
            }
            // Add bbp_get_hidden_status_id() if user is capable
            if (current_user_can('read_hidden_forums')) {
                $status[] = bbp_get_hidden_status_id();
            }
            // Implode and add the statuses
            $posts_query->set('post_status', implode(',', $status));
            break;
            // Topics
        // Topics
        case bbp_get_topic_post_type():
            // Replies
        // Replies
        case bbp_get_reply_post_type():
            // Get forums to exclude
            $forum_ids = bbp_exclude_forum_ids('meta_query');
            // Bail if no forums to exclude
            if (empty($forum_ids)) {
                return;
            }
            // Get any existing meta queries
            $meta_query = $posts_query->get('meta_query');
            // Add our meta query to existing
            $meta_query[] = $forum_ids;
            // Set the meta_query var
            $posts_query->set('meta_query', $meta_query);
            break;
    }
}
Example #25
0
/**
 * Is the topic private?
 *
 * @since 2.6.0 bbPress (r5504)
 *
 * @param int $topic_id Optional. Topic id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic_status() To get the topic status
 * @uses apply_filters() Calls 'bbp_is_topic_private' with the topic id
 * @return bool True if private, false if not.
 */
function bbp_is_topic_private($topic_id = 0)
{
    $topic_id = bbp_get_topic_id($topic_id);
    $status = bbp_get_private_status_id();
    $topic_status = bbp_get_topic_status($topic_id) === $status;
    return (bool) apply_filters('bbp_is_topic_private', (bool) $topic_status, $topic_id);
}
/**
 * The main topic loop. WordPress makes this easy for us
 *
 * @since bbPress (r2485)
 *
 * @param mixed $args All the arguments supported by {@link WP_Query}
 * @uses current_user_can() To check if the current user can edit other's topics
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses WP_Query To make query and get the topics
 * @uses is_page() To check if it's a page
 * @uses bbp_is_single_forum() To check if it's a forum
 * @uses bbp_get_forum_id() To get the forum id
 * @uses bbp_get_paged() To get the current page value
 * @uses bbp_get_super_stickies() To get the super stickies
 * @uses bbp_get_stickies() To get the forum stickies
 * @uses wpdb::get_results() To execute our query and get the results
 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks
 * @uses get_permalink() To get the permalink
 * @uses add_query_arg() To add custom args to the url
 * @uses apply_filters() Calls 'bbp_topics_pagination' with the pagination args
 * @uses paginate_links() To paginate the links
 * @uses apply_filters() Calls 'bbp_has_topics' with
 *                        bbPres::topic_query::have_posts()
 *                        and bbPres::topic_query
 * @return object Multidimensional array of topic information
 */
function 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);
    // 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
    $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);
                // 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('bbp_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query);
}