Example #1
0
 /**
  * @covers ::bbp_current_user_id
  * @covers ::bbp_get_current_user_id
  */
 public function test_bbp_get_current_user_id()
 {
     $int_value = $this->keymaster_userdata->ID;
     $formatted_value = bbp_number_format($int_value);
     // Integer.
     $user_id = bbp_get_current_user_id();
     $this->assertSame($this->keymaster_id, $user_id);
     // Output.
     $this->expectOutputString($formatted_value);
     bbp_current_user_id($this->keymaster_id);
 }
Example #2
0
/**
 * This repair tool will map each user of the current site to their respective
 * forums role. By default, Admins will be Key Masters, and every other role
 * will be the default role defined in Settings > Forums (Participant).
 *
 * @since 2.2.0 bbPress (r4340)
 *
 * @uses bbp_get_user_role_map() To get the map of user roles
 * @uses bbp_get_default_role() To get the default bbPress user role
 * @uses bbp_get_blog_roles() To get the current WordPress roles
 * @uses get_users() To get the users of each role (limited to ID field)
 * @uses bbp_set_user_role() To set each user's forums role
 */
function bbp_admin_repair_user_roles()
{
    $statement = __('Remapping forum role for each user on this site… %s', 'bbpress');
    $changed = 0;
    $role_map = bbp_get_user_role_map();
    $default_role = bbp_get_default_role();
    // Bail if no role map exists
    if (empty($role_map)) {
        return array(1, sprintf($statement, __('Failed!', 'bbpress')));
    }
    // Iterate through each role...
    foreach (array_keys(bbp_get_blog_roles()) as $role) {
        // Reset the offset
        $offset = 0;
        // If no role map exists, give the default forum role (bbp-participant)
        $new_role = isset($role_map[$role]) ? $role_map[$role] : $default_role;
        // Get users of this site, limited to 1000
        while ($users = get_users(array('role' => $role, 'fields' => 'ID', 'number' => 1000, 'offset' => $offset))) {
            // Iterate through each user of $role and try to set it
            foreach ((array) $users as $user_id) {
                if (bbp_set_user_role($user_id, $new_role)) {
                    ++$changed;
                    // Keep a count to display at the end
                }
            }
            // Bump the offset for the next query iteration
            $offset = $offset + 1000;
        }
    }
    $result = sprintf(__('Complete! %s users updated.', 'bbpress'), bbp_number_format($changed));
    return array(0, sprintf($statement, $result));
}
Example #3
0
/**
 * Return the pagination count
 *
 * @since 2.0.0 bbPress (r2519)
 *
 * @uses bbp_number_format() To format the number value
 * @uses apply_filters() Calls 'bbp_get_forum_pagination_count' with the
 *                        pagination count
 * @return string Forum Pagintion count
 */
function bbp_get_forum_pagination_count()
{
    $bbp = bbpress();
    if (empty($bbp->topic_query)) {
        return false;
    }
    // Set pagination values
    $start_num = intval(($bbp->topic_query->paged - 1) * $bbp->topic_query->posts_per_page) + 1;
    $from_num = bbp_number_format($start_num);
    $to_num = bbp_number_format($start_num + ($bbp->topic_query->posts_per_page - 1) > $bbp->topic_query->found_posts ? $bbp->topic_query->found_posts : $start_num + ($bbp->topic_query->posts_per_page - 1));
    $total_int = (int) (!empty($bbp->topic_query->found_posts)) ? $bbp->topic_query->found_posts : $bbp->topic_query->post_count;
    $total = bbp_number_format($total_int);
    // Several topics in a forum with a single page
    if (empty($to_num)) {
        $retstr = sprintf(_n('Viewing %1$s topic', 'Viewing %1$s topics', $total_int, 'bbpress'), $total);
        // Several topics in a forum with several pages
    } else {
        $retstr = sprintf(_n('Viewing topic %2$s (of %4$s total)', 'Viewing %1$s topics - %2$s through %3$s (of %4$s total)', $total_int, 'bbpress'), $bbp->topic_query->post_count, $from_num, $to_num, $total);
    }
    // Filter and return
    return apply_filters('bbp_get_forum_pagination_count', $retstr);
}
Example #4
0
/**
 * Return the topic pagination count
 *
 * @since bbPress (r2519)
 *
 * @uses bbp_number_format() To format the number value
 * @uses bbp_show_lead_topic() Are we showing the topic as a lead?
 * @uses apply_filters() Calls 'bbp_get_topic_pagination_count' with the
 *                        pagination count
 * @return string Topic pagination count
 */
function bbp_get_topic_pagination_count()
{
    $bbp = bbpress();
    // Define local variable(s)
    $retstr = '';
    // Set pagination values
    $start_num = intval(($bbp->reply_query->paged - 1) * $bbp->reply_query->posts_per_page) + 1;
    $from_num = bbp_number_format($start_num);
    $to_num = bbp_number_format($start_num + ($bbp->reply_query->posts_per_page - 1) > $bbp->reply_query->found_posts ? $bbp->reply_query->found_posts : $start_num + ($bbp->reply_query->posts_per_page - 1));
    $total_int = (int) $bbp->reply_query->found_posts;
    $total = bbp_number_format($total_int);
    // We are threading replies
    if (bbp_thread_replies() && bbp_is_single_topic()) {
        return;
        $walker = new BBP_Walker_Reply();
        $threads = (int) $walker->get_number_of_root_elements($bbp->reply_query->posts);
        // Adjust for topic
        $threads--;
        $retstr = sprintf(_n('Viewing %1$s reply thread', 'Viewing %1$s reply threads', $threads, 'bbbpress'), bbp_number_format($threads));
        // We are not including the lead topic
    } elseif (bbp_show_lead_topic()) {
        // Several replies in a topic with a single page
        if (empty($to_num)) {
            $retstr = sprintf(_n('Viewing %1$s reply', 'Viewing %1$s replies', $total_int, 'bbpress'), $total);
            // Several replies in a topic with several pages
        } else {
            $retstr = sprintf(_n('Viewing %2$s replies (of %4$s total)', 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress'), $bbp->reply_query->post_count, $from_num, $to_num, $total);
        }
        // We are including the lead topic
    } else {
        // Several posts in a topic with a single page
        if (empty($to_num)) {
            $retstr = sprintf(_n('Viewing %1$s post', 'Viewing %1$s posts', $total_int, 'bbpress'), $total);
            // Several posts in a topic with several pages
        } else {
            $retstr = sprintf(_n('Viewing %2$s post (of %4$s total)', 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress'), $bbp->reply_query->post_count, $from_num, $to_num, $total);
        }
    }
    // Filter and return
    return apply_filters('bbp_get_topic_pagination_count', esc_html($retstr));
}
Example #5
0
/**
 * Return the search results pagination count
 *
 * @since bbPress (r4579)
 *
 * @uses bbp_number_format() To format the number value
 * @uses apply_filters() Calls 'bbp_get_search_pagination_count' with the
 *                        pagination count
 * @return string Search pagination count
 */
function bbp_get_search_pagination_count()
{
    $bbp = bbpress();
    // Define local variable(s)
    $retstr = '';
    // Set pagination values
    $start_num = intval(($bbp->search_query->paged - 1) * $bbp->search_query->posts_per_page) + 1;
    $from_num = bbp_number_format($start_num);
    $to_num = bbp_number_format($start_num + ($bbp->search_query->posts_per_page - 1) > $bbp->search_query->found_posts ? $bbp->search_query->found_posts : $start_num + ($bbp->search_query->posts_per_page - 1));
    $total_int = (int) $bbp->search_query->found_posts;
    $total = bbp_number_format($total_int);
    // Single page of results
    if (empty($to_num)) {
        $retstr = sprintf(_n('Viewing %1$s result', 'Viewing %1$s results', $total_int, 'bbpress'), $total);
        // Several pages of results
    } else {
        $retstr = sprintf(_n('Viewing %2$s results (of %4$s total)', 'Viewing %1$s results - %2$s through %3$s (of %4$s total)', $bbp->search_query->post_count, 'bbpress'), $bbp->search_query->post_count, $from_num, $to_num, $total);
    }
    // Filter and return
    return apply_filters('bbp_get_search_pagination_count', esc_html($retstr));
}
Example #6
0
 /**
  * @covers ::bbp_user_post_count
  * @covers ::bbp_get_user_post_count
  */
 function test_bbp_get_user_post_count()
 {
     $u = $this->factory->user->create();
     $int_value = 3;
     $integer = true;
     // Add reply count
     bbp_update_user_reply_count($u, $int_value);
     // Count
     $count = bbp_get_user_post_count($u, $integer);
     $this->assertSame($int_value, $count);
     // Add topic count
     bbp_update_user_topic_count($u, $int_value);
     $double_value = $int_value * 2;
     // Count + Count
     $double_count = bbp_get_user_post_count($u, true);
     $this->assertSame($double_value, $double_count);
     // Output
     $double_formatted_value = bbp_number_format($double_value);
     $this->expectOutputString($double_formatted_value);
     bbp_user_post_count($u);
 }
Example #7
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 #8
0
 /**
  * @covers ::bbp_topic_voice_count
  * @covers ::bbp_get_topic_voice_count
  */
 public function test_bbp_get_topic_voice_count()
 {
     $u = $this->factory->user->create_many(2);
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'post_author' => $u[0], 'topic_meta' => array('forum_id' => $f)));
     $int_value = 2;
     $formatted_value = bbp_number_format($int_value);
     $this->factory->reply->create_many(3, array('post_parent' => $t, 'post_author' => $u[0], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $this->factory->reply->create_many(3, array('post_parent' => $t, 'post_author' => $u[1], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     bbp_update_topic_voice_count($t);
     // Output
     $this->expectOutputString($formatted_value);
     bbp_topic_voice_count($t);
     // Formatted string
     $count = bbp_get_topic_voice_count($t, false);
     $this->assertSame($formatted_value, $count);
     // Integer
     $count = bbp_get_topic_voice_count($t, true);
     $this->assertSame($int_value, $count);
 }
Example #9
0
/**
 * Return the topic pagination count
 *
 * @since bbPress (r2519)
 *
 * @uses bbp_number_format() To format the number value
 * @uses bbp_show_lead_topic() Are we showing the topic as a lead?
 * @uses apply_filters() Calls 'bbp_get_topic_pagination_count' with the
 *                        pagination count
 * @return string Topic pagination count
 */
function bbp_get_topic_pagination_count()
{
    $bbp = bbpress();
    // Define local variable(s)
    $retstr = '';
    // Set pagination values
    $start_num = intval(($bbp->reply_query->paged - 1) * $bbp->reply_query->posts_per_page) + 1;
    $from_num = bbp_number_format($start_num);
    $to_num = bbp_number_format($start_num + ($bbp->reply_query->posts_per_page - 1) > $bbp->reply_query->found_posts ? $bbp->reply_query->found_posts : $start_num + ($bbp->reply_query->posts_per_page - 1));
    $total_int = (int) $bbp->reply_query->found_posts;
    $total = bbp_number_format($total_int);
    // We are not including the lead topic
    if (bbp_show_lead_topic()) {
        // Several replies in a topic with a single page
        if (empty($to_num)) {
            $retstr = sprintf(_n('Viewing %1$s reply', 'Viewing %1$s replies', $total_int, 'bbpress'), $total);
            // Several replies in a topic with several pages
        } else {
            $retstr = sprintf(_n('Viewing %2$s replies (of %4$s total)', 'Viewing %1$s replies - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress'), $bbp->reply_query->post_count, $from_num, $to_num, $total);
        }
        // We are including the lead topic
    } else {
        // Several posts in a topic with a single page
        if (empty($to_num)) {
            $retstr = sprintf(_n('Viewing %1$s post', 'Viewing %1$s posts', $total_int, 'bbpress'), $total);
            // Several posts in a topic with several pages
        } else {
            $retstr = sprintf(_n('Viewing %2$s post (of %4$s total)', 'Viewing %1$s posts - %2$s through %3$s (of %4$s total)', $bbp->reply_query->post_count, 'bbpress'), $bbp->reply_query->post_count, $from_num, $to_num, $total);
        }
    }
    // Filter and return
    return apply_filters('bbp_get_topic_pagination_count', $retstr);
}
Example #10
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);
 }