/** * @covers ::bbp_forum_topic_count * @covers ::bbp_get_forum_topic_count */ public function test_bbp_get_forum_topic_count() { $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)); bbp_update_forum_topic_count($c); bbp_update_forum_topic_count($f); // Forum output. $count = bbp_get_forum_topic_count($f, true, false); $this->expectOutputString($formatted_value); bbp_forum_topic_count($f); // Forum formatted string. $count = bbp_get_forum_topic_count($f, true, false); $this->assertSame($formatted_value, $count); // Forum integer. $count = bbp_get_forum_topic_count($f, true, true); $this->assertSame($int_value, $count); // Category topic count. $count = bbp_get_forum_topic_count($c, false, true); $this->assertSame(0, $count); // Category total topic count. $count = bbp_get_forum_topic_count($c, true, true); $this->assertSame($int_value, $count); }
/** * @covers ::bbp_forum_topic_count * @covers ::bbp_get_forum_topic_count */ public function test_bbp_get_forum_topic_count() { $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)); bbp_update_forum_topic_count($f); // Output $count = bbp_get_forum_topic_count($f, true, false); $this->expectOutputString($formatted_value); bbp_forum_topic_count($f); // Formatted string $count = bbp_get_forum_topic_count($f, true, false); $this->assertSame($formatted_value, $count); // Integer $count = bbp_get_forum_topic_count($f, true, true); $this->assertSame($int_value, $count); }
<?php bbp_list_forums(); ?> <?php do_action('bbp_theme_after_forum_sub_forums'); ?> <?php bbp_forum_row_actions(); ?> </li> <li class="bbp-forum-topic-count"><?php bbp_forum_topic_count(); ?> </li> <li class="bbp-forum-reply-count"><?php bbp_show_lead_topic() ? bbp_forum_reply_count() : bbp_forum_post_count(); ?> </li> <li class="bbp-forum-freshness"> <?php do_action('bbp_theme_before_forum_freshness_link'); ?> <?php
/** * List subforums or forums * * Must be called within a loop or be assigned an forum id * * @param mixed $args The function supports these args: * - forum_id: Forum id. Defaults to '' * @uses bbp_forum_get_subforums() To check if the forum has subforums or not * @uses bbp_get_forum_permalink() To get forum permalink * @uses bbp_get_forum_title() To get forum title * @uses bbp_is_forum_category() To check if a forum is a category * @uses bbp_get_forum_topic_count() To get forum topic count * @uses bbp_get_forum_reply_count() To get forum reply count * @return void */ function ipt_kb_bbp_list_subforums($args = array()) { $r = bbp_parse_args($args, array('forum_id' => ''), 'ipt_kb_list_forums'); $sub_forums = bbp_forum_get_subforums($r['forum_id']); if (!empty($sub_forums)) { foreach ($sub_forums as $sub_forum) { ?> <li class="<?php if (bbp_is_forum_category($sub_forum->ID)) { echo 'bbp-forum-is-category'; } ?> list-group-item bbp-body ipt_kb_subforum_list"> <?php do_action('bbp_theme_before_forum_sub_forums'); ?> <ul id="bbp-forum-<?php bbp_forum_id($sub_forum->ID); ?> " <?php bbp_forum_class($sub_forum->ID); ?> > <li class="bbp-forum-info"> <span class="pull-left ipt_kb_bbpress_subforum_icon ipt_kb_bbpress_forum_icon"> <?php if (bbp_is_forum_category($sub_forum->ID)) { ?> <span class="glyphicon ipt-icomoon-folder-open"></span> <?php } else { ?> <span class="glyphicon ipt-icomoon-file4"></span> <?php } ?> </span> <?php ipt_kb_bbp_forum_title_in_list($sub_forum->ID); ?> <?php ipt_kb_bbp_forum_description_in_list($sub_forum->ID); ?> <?php bbp_forum_row_actions(); ?> </li> <li class="bbp-forum-topic-count"> <?php bbp_forum_topic_count($sub_forum->ID); ?> </li> <li class="bbp-forum-reply-count"> <?php bbp_show_lead_topic() ? bbp_forum_reply_count($sub_forum->ID) : bbp_forum_post_count($sub_forum->ID); ?> </li> <li class="bbp-forum-freshness"> <?php ipt_kb_bbp_forum_freshness_in_list($sub_forum->ID); ?> </li> </ul> <?php do_action('bbp_theme_after_forum_sub_forums'); ?> <div class="clearfix"></div> </li> <?php } } }
/** * Print extra columns for the forums page * * @since bbPress (r2485) * * @param string $column Column * @param int $forum_id Forum id * @uses bbp_forum_topic_count() To output the forum topic count * @uses bbp_forum_reply_count() To output the forum reply count * @uses get_the_date() Get the forum creation date * @uses get_the_time() Get the forum creation time * @uses esc_attr() To sanitize the forum creation time * @uses bbp_get_forum_last_active_time() To get the time when the forum was * last active * @uses do_action() Calls 'bbp_admin_forums_column_data' with the * column and forum id */ public function column_data($column, $forum_id) { if ($this->bail()) { return; } switch ($column) { case 'bbp_forum_topic_count': bbp_forum_topic_count($forum_id); break; case 'bbp_forum_reply_count': bbp_forum_reply_count($forum_id); break; case 'bbp_forum_created': printf(__('%1$s <br /> %2$s', 'bbpress'), get_the_date(), esc_attr(get_the_time())); break; case 'bbp_forum_freshness': $last_active = bbp_get_forum_last_active_time($forum_id, false); if (!empty($last_active)) { echo $last_active; } else { _e('No Topics', 'bbpress'); } break; default: do_action('bbp_admin_forums_column_data', $column, $forum_id); break; } }
/** * Displays the output, the forum list * * @since bbPress (r2653) * * @param mixed $args Arguments * @param array $instance Instance * @uses apply_filters() Calls 'bbp_forum_widget_title' with the title * @uses get_option() To get the forums per page option * @uses current_user_can() To check if the current user can read * private() To resety name * @uses bbp_has_forums() The main forum loop * @uses bbp_forums() To check whether there are more forums available * in the loop * @uses bbp_the_forum() Loads up the current forum in the loop * @uses bbp_forum_permalink() To display the forum permalink * @uses bbp_forum_title() To display the forum title */ public function widget($args, $instance) { extract($args); $title = apply_filters('bbp_forum_widget_title', $instance['title']); $parent_forum = !empty($instance['parent_forum']) ? $instance['parent_forum'] : '0'; // Note: private and hidden forums will be excluded via the // bbp_pre_get_posts_exclude_forums filter and function. $widget_query = new WP_Query(array('post_parent' => $parent_forum, 'post_type' => bbp_get_forum_post_type(), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'orderby' => 'menu_order', 'order' => 'ASC')); if ($widget_query->have_posts()) { echo $before_widget; echo $before_title . $title . $after_title; $current_forum_id = bbp_get_forum_id(); ?> <ul> <?php while ($widget_query->have_posts()) { $widget_query->the_post(); ?> <?php $current = $widget_query->post->ID == $current_forum_id ? 'current' : ''; ?> <li> <a class="bbp-forum-title <?php echo $current; ?> " href="<?php bbp_forum_permalink($widget_query->post->ID); ?> " title="<?php bbp_forum_title($widget_query->post->ID); ?> "> <?php bbp_forum_title($widget_query->post->ID); ?> </a> <span class="topic-count"><?php bbp_forum_topic_count($widget_query->post->ID); ?> </span> </li> <?php } ?> </ul> <?php echo $after_widget; // Reset the $post global wp_reset_postdata(); } }
/** * Print extra columns for the forums page * * @since 2.0.0 bbPress (r2485) * * @param string $column Column * @param int $forum_id Forum id * @uses bbp_forum_topic_count() To output the forum topic count * @uses bbp_forum_reply_count() To output the forum reply count * @uses get_the_date() Get the forum creation date * @uses get_the_time() Get the forum creation time * @uses esc_attr() To sanitize the forum creation time * @uses bbp_get_forum_last_active_time() To get the time when the forum was * last active * @uses do_action() Calls 'bbp_admin_forums_column_data' with the * column and forum id */ public function column_data($column, $forum_id) { if ($this->bail()) { return; } switch ($column) { case 'bbp_forum_topic_count': bbp_forum_topic_count($forum_id); break; case 'bbp_forum_reply_count': bbp_forum_reply_count($forum_id); break; case 'bbp_forum_mods': bbp_forum_mod_list($forum_id, array('before' => '', 'after' => '', 'none' => esc_html__('—', 'bbpress'))); break; case 'bbp_forum_created': printf('%1$s <br /> %2$s', get_the_date(), esc_attr(get_the_time())); break; case 'bbp_forum_freshness': $last_active = bbp_get_forum_last_active_time($forum_id, false); if (!empty($last_active)) { echo esc_html($last_active); } else { esc_html_e('No Topics', 'bbpress'); } break; default: do_action('bbp_admin_forums_column_data', $column, $forum_id); break; } }
/** * [g1_bbp_forums] shortcode callback function. * * @param array $atts * @param string $content * @return string */ function g1_bbp_forums_shortcode($atts, $content) { /* We need a static counter to trace a shortcode without the id attribute */ static $counter = 0; $counter++; extract(shortcode_atts(array('id' => '', 'class' => ''), $atts, 'g1_bbp_forums')); // Compose final HTML id attribute $final_id = strlen($id) ? $id : 'g1-bbp-forums-' . $counter; // Compose final HTML class attribute $final_class = array('g1-bbp-forums'); $final_class = array_merge($final_class, explode(' ', $class)); // Note: private and hidden forums will be excluded via the // bbp_pre_get_posts_normalize_forum_visibility action and function. $query = new WP_Query(array('post_type' => bbp_get_forum_post_type(), 'post_parent' => $settings['parent_forum'], 'post_status' => bbp_get_public_status_id(), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'orderby' => 'menu_order title', 'order' => 'ASC')); if (!$query->have_posts()) { return ''; } // Start output buffer ob_start(); ?> <div class="<?php echo implode(' ', array_map('sanitize_html_class', $final_class)); ?> "> <div class="g1-collection g1-collection--grid g1-collection--one-third g1-collection--simple"> <ul> <?php while ($query->have_posts()) { $query->the_post(); ?> <li class="g1-collection__item"> <article> <?php if (has_post_thumbnail()) { ?> <figure class="entry-featured-media"> <a href="<?php bbp_forum_permalink($query->post->ID); ?> "> <?php the_post_thumbnail('g1_one_third'); ?> </a> </figure> <?php } else { ?> <?php echo do_shortcode('[placeholder icon="camera" size="g1_one_third"]'); ?> <?php } ?> <div class="g1-nonmedia"> <div class="g1-inner"> <header class="entry-header"> <h3 class="entry-title"> <a href="<?php bbp_forum_permalink($query->post->ID); ?> "><?php bbp_forum_title($query->post->ID); ?> </a> </h3> <p class="entry-meta g1-meta"> <span><?php _e('Topics', 'bbpress'); ?> : <?php bbp_forum_topic_count($query->post->ID); ?> </span> <span><?php bbp_show_lead_topic() ? _e('Replies', 'bbpress') : _e('Posts', 'bbpress'); ?> : <?php bbp_show_lead_topic() ? bbp_forum_reply_count($query->post->ID) : bbp_forum_post_count($query->post->ID); ?> </span> </p> </header> <div class="entry-summary"> <?php the_excerpt(); ?> </div> </div> </div> </article> </li> <?php } ?> </ul> </div> </div> <?php // Reset the $post global wp_reset_postdata(); // Return and flush the output buffer return ob_get_clean(); }
/ <?php bp_group_member_count(); ?> </div> <div class="meta" id="mytopicpostcount"> <?php $my_group_id = bp_get_group_id(); $my_forum_ids = bbp_get_group_forum_ids($my_group_id); //echo "og grp: ".$my_group_id." og frm: ".print_r(my_forum_ids,true); // Taken from wp-content/plugins/bbpress/includes/extend/buddypress/groups.php //$forum_ids = bbp_get_group_forum_ids( $group_id ); $forum_id = null; // Get the first forum ID if (!empty($my_forum_ids)) { $forum_id = (int) is_array($my_forum_ids) ? $my_forum_ids[0] : $my_forum_ids; bbp_forum_topic_count($forum_id); echo " "; _e('Topics', 'bbpress'); echo " / "; bbp_show_lead_topic() ? bbp_forum_reply_count($forum_id) : bbp_forum_post_count($forum_id); echo " "; bbp_show_lead_topic() ? _e('Replies', 'bbpress') : _e('Posts', 'bbpress'); } else { echo "Group has no forum"; } ?> </div> </div> <div class="clear"></div>