/** * @group canonical * @covers ::bbp_insert_forum */ public function test_bbp_insert_forum() { $f = $this->factory->forum->create(array('post_title' => 'Forum 1', 'post_content' => 'Content of Forum 1')); $now = time(); $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100); $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f))); $r = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Get the forum. $forum = bbp_get_forum($f); // Forum post. $this->assertSame('Forum 1', bbp_get_forum_title($f)); $this->assertSame('Content of Forum 1', bbp_get_forum_content($f)); $this->assertSame('open', bbp_get_forum_status($f)); $this->assertSame('forum', bbp_get_forum_type($f)); $this->assertTrue(bbp_is_forum_public($f)); $this->assertSame(0, bbp_get_forum_parent_id($f)); $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $forum->post_name, $forum->guid); // Forum meta. $this->assertSame(0, bbp_get_forum_subforum_count($f, true)); $this->assertSame(1, bbp_get_forum_topic_count($f, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($f, true, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($f, true)); $this->assertSame(1, bbp_get_forum_reply_count($f, false, true)); $this->assertSame(1, bbp_get_forum_reply_count($f, true, true)); $this->assertSame(2, bbp_get_forum_post_count($f, false, true)); $this->assertSame(2, bbp_get_forum_post_count($f, true, true)); $this->assertSame($t, bbp_get_forum_last_topic_id($f)); $this->assertSame($r, bbp_get_forum_last_reply_id($f)); $this->assertSame($r, bbp_get_forum_last_active_id($f)); $this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($f)); }
/** * @covers ::bbp_forum_subforum_count * @covers ::bbp_get_forum_subforum_count */ public function test_bbp_get_forum_subforum_count() { $f1 = $this->factory->forum->create(); $int_value = 3; $formatted_value = bbp_number_format($int_value); $this->factory->forum->create_many($int_value, array('post_parent' => $f1)); bbp_update_forum_subforum_count($f1); // Output. $count = bbp_get_forum_subforum_count($f1, false); $this->expectOutputString($formatted_value); bbp_forum_subforum_count($f1); // Formatted string. $count = bbp_get_forum_subforum_count($f1, false); $this->assertSame($formatted_value, $count); // Integer. $count = bbp_get_forum_subforum_count($f1, true); $this->assertSame($int_value, $count); // Direct query. $count = count(bbp_forum_query_subforum_ids($f1)); $this->assertSame($int_value, $count); }
<?php } else { ?> <?php //bbp_single_forum_description(); ?> <div class="bbp-forum-content panel panel-default"><div class="panel-body"><?php bbp_forum_content(); ?> </div></div> <?php if (bbp_get_forum_subforum_count() && bbp_has_forums()) { ?> <?php bbp_get_template_part('loop', 'forums'); ?> <?php } ?> <?php if (!bbp_is_forum_category() && bbp_has_topics()) { ?> <?php
<?php /** * Apocrypha Theme Forums Archive * Andrew Clayton * Version 2.0 * 5-10-2014 */ ?> <?php // Top level categories if (bbp_get_forum_subforum_count()) { ?> <?php apoc_loop_subforums(); ?> <?php // Single non-category forums } else { ?> <header class="forum-header"> <div class="forum-content"><h2>Forum</h2></div> <div class="forum-count">Topics</div> <div class="forum-freshness">Latest Post</div> </header> <ol class="forums category <?php bbp_forum_status(); ?> ">
/** * Return the row class of a forum * * @since bbPress (r2667) * * @param int $forum_id Optional. Forum ID * @uses bbp_get_forum_id() To validate the forum id * @uses bbp_is_forum_category() To see if forum is a category * @uses bbp_get_forum_status() To get the forum status * @uses bbp_get_forum_visibility() To get the forum visibility * @uses bbp_get_forum_parent_id() To get the forum parent id * @uses get_post_class() To get all the classes including ours * @uses apply_filters() Calls 'bbp_get_forum_class' with the classes * @return string Row class of the forum */ function bbp_get_forum_class($forum_id = 0) { $bbp = bbpress(); $forum_id = bbp_get_forum_id($forum_id); $count = isset($bbp->forum_query->current_post) ? $bbp->forum_query->current_post : 1; $classes = array(); // Get some classes $classes[] = 'loop-item-' . $count; $classes[] = (int) $count % 2 ? 'even' : 'odd'; $classes[] = bbp_is_forum_category($forum_id) ? 'status-category' : ''; $classes[] = bbp_get_forum_subforum_count($forum_id) ? 'bbp-has-subforums' : ''; $classes[] = bbp_get_forum_parent_id($forum_id) ? 'bbp-parent-forum-' . bbp_get_forum_parent_id($forum_id) : ''; $classes[] = 'bbp-forum-status-' . bbp_get_forum_status($forum_id); $classes[] = 'bbp-forum-visibility-' . bbp_get_forum_visibility($forum_id); // Ditch the empties $classes = array_filter($classes); $classes = get_post_class($classes, $forum_id); // Filter the results $classes = apply_filters('bbp_get_forum_class', $classes, $forum_id); $retval = 'class="' . join(' ', $classes) . '"'; return $retval; }
function st_bbp_list_forums($args = '') { // Define used variables $output = $sub_forums = $topic_count = $reply_count = $counts = ''; $i = 0; $count = array(); // Defaults and arguments $defaults = array('before' => '<ul class="bbp-forums-list">', 'after' => '</ul>', 'link_before' => '<li class="bbp-forum">', 'link_after' => '</li>', 'count_before' => ' (', 'count_after' => ')', 'count_sep' => ', ', 'separator' => ', ', 'forum_id' => '', 'show_topic_count' => true, 'show_reply_count' => true, 'show_freshness_link' => true); $r = bbp_parse_args($args, $defaults, 'list_forums'); extract($r, EXTR_SKIP); // Bail if there are no subforums if (!bbp_get_forum_subforum_count($forum_id)) { return; } // Loop through forums and create a list $sub_forums = bbp_forum_get_subforums($forum_id); if (!empty($sub_forums)) { // Total count (for separator) $total_subs = count($sub_forums); foreach ($sub_forums as $sub_forum) { $i++; // Separator count // Get forum details $count = array(); $show_sep = $total_subs > $i ? $separator : ''; $permalink = bbp_get_forum_permalink($sub_forum->ID); $title = bbp_get_forum_title($sub_forum->ID); $description = bbp_get_forum_content($sub_forum->ID); // Show topic count if (!empty($show_topic_count) && !bbp_is_forum_category($sub_forum->ID)) { $count['topic'] = bbp_get_forum_topic_count($sub_forum->ID); } // Show reply count if (!empty($show_reply_count) && !bbp_is_forum_category($sub_forum->ID)) { $count['reply'] = bbp_get_forum_reply_count($sub_forum->ID); } // Counts to show if (!empty($count)) { $counts = $count_before . implode($count_sep, $count) . $count_after; } if (!empty($show_freshness_link)) { $freshness_link = "<div class='freshness-forum-link'>" . st_get_last_poster_block($sub_forum->ID) . "</div>"; } // Build this sub forums link if ($i % 2) { $class = "odd-forum-row"; } else { $class = "even-forum-row"; } $output .= "<li class='{$class}'><ul>" . $link_before . '<div class="bbp-forum-title-container"><a href="' . $permalink . '" class="bbp-forum-link">' . $title . '</a><p class="bbp-forum-description">' . $description . '</p></div>' . $counts . $freshness_link . $link_after . "</ul></li>"; } // Output the list echo apply_filters('bbp_list_forums', $before . $output . $after, $args); } }
/** * @group canonical * @covers ::bbp_create_initial_content */ public function test_bbp_create_initial_content() { $category_id = $this->factory->forum->create(array('forum_meta' => array('_bbp_forum_type' => 'category', '_bbp_status' => 'open'))); bbp_create_initial_content(array('forum_parent' => $category_id)); $forum_id = bbp_forum_query_subforum_ids($category_id); $forum_id = (int) $forum_id[0]; $topic_id = bbp_get_forum_last_topic_id($forum_id); $reply_id = bbp_get_forum_last_reply_id($forum_id); // Forum post $this->assertSame('General', bbp_get_forum_title($forum_id)); $this->assertSame('General chit-chat', bbp_get_forum_content($forum_id)); $this->assertSame('open', bbp_get_forum_status($forum_id)); $this->assertTrue(bbp_is_forum_public($forum_id)); $this->assertSame($category_id, bbp_get_forum_parent_id($forum_id)); // Topic post $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame('Hello World!', bbp_get_topic_title($topic_id)); remove_all_filters('bbp_get_topic_content'); $topic_content = "I am the first topic in your new forums."; $this->assertSame($topic_content, bbp_get_topic_content($topic_id)); $this->assertSame('publish', bbp_get_topic_status($topic_id)); $this->assertTrue(bbp_is_topic_published($topic_id)); // Reply post $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame('Reply To: Hello World!', bbp_get_reply_title($reply_id)); $this->assertSame($reply_id, bbp_get_reply_title_fallback($reply_id)); remove_all_filters('bbp_get_reply_content'); $reply_content = "Oh, and this is what a reply looks like."; $this->assertSame($reply_content, bbp_get_reply_content($reply_id)); $this->assertSame('publish', bbp_get_reply_status($reply_id)); $this->assertTrue(bbp_is_reply_published($reply_id)); // Category meta $this->assertSame(1, bbp_get_forum_subforum_count($category_id, true)); $this->assertSame(0, bbp_get_forum_topic_count($category_id, false, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($category_id, true)); $this->assertSame(0, bbp_get_forum_reply_count($category_id, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($category_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($category_id, true, true)); $this->assertSame(0, bbp_get_forum_post_count($category_id, false, true)); $this->assertSame(2, bbp_get_forum_post_count($category_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($category_id)); $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($category_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($category_id)); $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($category_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($category_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($category_id)); // Forum meta $this->assertSame(0, bbp_get_forum_subforum_count($forum_id, true)); $this->assertSame(1, bbp_get_forum_topic_count($forum_id, false, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($forum_id, true)); $this->assertSame(1, bbp_get_forum_reply_count($forum_id, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($forum_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($forum_id, true, true)); $this->assertSame(2, bbp_get_forum_post_count($forum_id, false, true)); $this->assertSame(2, bbp_get_forum_post_count($forum_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($forum_id)); $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($forum_id)); $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($forum_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($forum_id)); // Topic meta $this->assertSame('127.0.0.1', bbp_current_author_ip($topic_id)); $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true)); $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true)); $this->assertSame(0, bbp_get_topic_reply_count_hidden($topic_id, true)); $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id)); $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_topic_last_active_time($topic_id)); // Reply Meta $this->assertSame('127.0.0.1', bbp_current_author_ip($reply_id)); $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id)); }
<?php do_action('bbp_theme_before_forum_description'); ?> <div class="bbp-forum-content"><?php the_content(); ?> </div> <?php do_action('bbp_theme_after_forum_description'); ?> <?php if (!bbp_get_forum_subforum_count(bbp_get_forum_id())) { echo '<div class="topic-reply-counts">' . "\n"; echo '<i class="fa fa-list-ul"></i>' . bbp_get_forum_topic_count(bbp_get_forum_id()) . '<br />' . "\n"; echo '<i class="fa fa fa-comments-o"></i>' . bbp_get_forum_reply_count(bbp_get_forum_id()) . "\n"; echo '</div>'; } ?> <?php } ?> <?php } else { ?>
/** * @covers ::bbp_update_forum_subforum_count */ public function test_bbp_update_forum_subforum_count() { $f1 = $this->factory->forum->create(); $f2 = $this->factory->forum->create_many(3, array('post_parent' => $f1)); $count = bbp_get_forum_subforum_count($f1, true); $this->assertSame(0, $count); bbp_update_forum_subforum_count($f1); $count = bbp_get_forum_subforum_count($f1, true); $this->assertSame(3, $count); }