/** * @covers ::bbp_topic_last_active_time * @covers ::bbp_get_topic_last_active_time */ public function test_bbp_get_topic_last_active_time() { $f = $this->factory->forum->create(); $now = time(); $post_date_topic = date('Y-m-d H:i:s', $now - 60 * 60 * 100); $post_date_reply = date('Y-m-d H:i:s', $now - 60 * 60 * 80); $topic_time = '4 days, 4 hours ago'; $reply_time = '3 days, 8 hours ago'; $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date_topic, 'topic_meta' => array('forum_id' => $f))); // Output. $this->expectOutputString($topic_time); bbp_topic_last_active_time($t); // Topic time. $datetime = bbp_get_topic_last_active_time($t); $this->assertSame($topic_time, $datetime); $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date_reply, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Reply time. $datetime = bbp_get_topic_last_active_time($t); $this->assertSame('3 days, 8 hours ago', $datetime); }
bbp_forum_topic_count(); ?> </div> <div class="forum-freshness"> <?php echo apoc_get_avatar(array('user_id' => bbp_get_forum_last_reply_author_id(), 'link' => true, 'size' => 50)); ?> <div class="freshest-meta"> <a class="freshest-title" href="<?php echo $link; ?> " title=""><?php bbp_forum_last_topic_title(); ?> </a> <span class="freshest-author">By <?php bbp_author_link(array('post_id' => bbp_get_forum_last_topic_id(), 'type' => 'name')); ?> </span> <span class="freshest-time"><?php bbp_topic_last_active_time(bbp_get_forum_last_topic_id()); ?> </span> </div> </div> </li> </ol> <?php }
/** * Displays the output, the topic list * * @since bbPress (r2653) * * @param mixed $args * @param array $instance * @uses apply_filters() Calls 'bbp_topic_widget_title' with the title * @uses bbp_topic_permalink() To display the topic permalink * @uses bbp_topic_title() To display the topic title * @uses bbp_get_topic_last_active_time() To get the topic last active * time * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_topic_reply_count() To get the topic reply count */ public function widget($args, $instance) { extract($args); $title = apply_filters('bbp_topic_widget_title', $instance['title']); $max_shown = !empty($instance['max_shown']) ? (int) $instance['max_shown'] : 5; $show_date = !empty($instance['show_date']) ? 'on' : false; $show_user = !empty($instance['show_user']) ? 'on' : false; $parent_forum = !empty($instance['parent_forum']) ? $instance['parent_forum'] : 'any'; $order_by = !empty($instance['order_by']) ? $instance['order_by'] : false; // How do we want to order our results? switch ($order_by) { // Order by most recent replies case 'freshness': $topics_query = array('author' => 0, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $parent_forum, 'posts_per_page' => $max_shown, 'post_status' => join(',', array(bbp_get_public_status_id(), bbp_get_closed_status_id())), 'show_stickes' => false, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC', 'meta_query' => array(bbp_exclude_forum_ids('meta_query'))); break; // Order by total number of replies // Order by total number of replies case 'popular': $topics_query = array('author' => 0, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $parent_forum, 'posts_per_page' => $max_shown, 'post_status' => join(',', array(bbp_get_public_status_id(), bbp_get_closed_status_id())), 'show_stickes' => false, 'meta_key' => '_bbp_reply_count', 'orderby' => 'meta_value', 'order' => 'DESC', 'meta_query' => array(bbp_exclude_forum_ids('meta_query'))); break; // Order by which topic was created most recently // Order by which topic was created most recently case 'newness': default: $topics_query = array('author' => 0, 'post_type' => bbp_get_topic_post_type(), 'post_parent' => $parent_forum, 'posts_per_page' => $max_shown, 'post_status' => join(',', array(bbp_get_public_status_id(), bbp_get_closed_status_id())), 'show_stickes' => false, 'order' => 'DESC', 'meta_query' => array(bbp_exclude_forum_ids('meta_query'))); break; } // Note: private and hidden forums will be excluded via the // bbp_pre_get_posts_exclude_forums filter and function. $widget_query = new WP_Query($topics_query); // Topics exist if ($widget_query->have_posts()) { echo $before_widget; echo $before_title . $title . $after_title; ?> <ul> <?php while ($widget_query->have_posts()) { $widget_query->the_post(); $topic_id = bbp_get_topic_id($widget_query->post->ID); $author_link = bbp_get_topic_author_link(array('post_id' => $topic_id, 'type' => 'both', 'size' => 14)); ?> <li> <a class="bbp-forum-title" href="<?php bbp_topic_permalink($topic_id); ?> " title="<?php bbp_topic_title($topic_id); ?> "><?php bbp_topic_title($topic_id); ?> </a> <?php if ('on' == $show_user) { ?> <?php printf(_x('by %1$s', 'widgets', 'bbpress'), '<span class="topic-author">' . $author_link . '</span>'); ?> <?php } ?> <?php if ('on' == $show_date) { ?> <div><?php bbp_topic_last_active_time($topic_id); ?> </div> <?php } ?> </li> <?php } ?> </ul> <?php echo $after_widget; // Reset the $post global wp_reset_postdata(); } }
/** * Displays the output, the topic list * * @since bbPress (r2653) * * @param mixed $args * @param array $instance * @uses apply_filters() Calls 'bbp_topic_widget_title' with the title * @uses bbp_topic_permalink() To display the topic permalink * @uses bbp_topic_title() To display the topic title * @uses bbp_get_topic_last_active_time() To get the topic last active * time * @uses bbp_get_topic_id() To get the topic id */ public function widget($args = array(), $instance = array()) { // Get widget settings $settings = $this->parse_settings($instance); // Typical WordPress filter $settings['title'] = apply_filters('widget_title', $settings['title'], $instance, $this->id_base); // bbPress filter $settings['title'] = apply_filters('bbp_topic_widget_title', $settings['title'], $instance, $this->id_base); // How do we want to order our results? switch ($settings['order_by']) { // Order by most recent replies case 'freshness': $topics_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $settings['parent_forum'], 'posts_per_page' => (int) $settings['max_shown'], 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'order' => 'DESC'); break; // Order by total number of replies // Order by total number of replies case 'popular': $topics_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $settings['parent_forum'], 'posts_per_page' => (int) $settings['max_shown'], 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'meta_key' => '_bbp_reply_count', 'orderby' => 'meta_value', 'order' => 'DESC'); break; // Order by which topic was created most recently // Order by which topic was created most recently case 'newness': default: $topics_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $settings['parent_forum'], 'posts_per_page' => (int) $settings['max_shown'], 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'order' => 'DESC'); break; } // Note: private and hidden forums will be excluded via the // bbp_pre_get_posts_normalize_forum_visibility action and function. $widget_query = new WP_Query($topics_query); // Bail if no topics are found if (!$widget_query->have_posts()) { return; } echo $args['before_widget']; if (!empty($settings['title'])) { echo $args['before_title'] . $settings['title'] . $args['after_title']; } ?> <ul> <?php while ($widget_query->have_posts()) { $widget_query->the_post(); $topic_id = bbp_get_topic_id($widget_query->post->ID); $author_link = ''; // Maybe get the topic author if (!empty($settings['show_user'])) { $author_link = bbp_get_topic_author_link(array('post_id' => $topic_id, 'type' => 'both', 'size' => 14)); } ?> <li> <a class="bbp-forum-title" href="<?php bbp_topic_permalink($topic_id); ?> "><?php bbp_topic_title($topic_id); ?> </a> <?php if (!empty($author_link)) { ?> <?php printf(_x('by %1$s', 'widgets', 'bbpress'), '<span class="topic-author">' . $author_link . '</span>'); ?> <?php } ?> <?php if (!empty($settings['show_date'])) { ?> <div><?php bbp_topic_last_active_time($topic_id); ?> </div> <?php } ?> </li> <?php } ?> </ul> <?php echo $args['after_widget']; // Reset the $post global wp_reset_postdata(); }
bbp_forum_title(bbp_get_topic_forum_id()); ?> </a> <?php } ?> </p> </div> <div class="forum-count"> <?php bbp_topic_post_count(); ?> </div> <div class="forum-freshness"> <?php echo apoc_get_avatar(array('user_id' => bbp_get_reply_author_id(bbp_get_topic_last_active_id()), 'link' => true, 'size' => 50)); ?> <div class="freshest-meta"> <span class="freshest-author">By <?php bbp_author_link(array('post_id' => bbp_get_topic_last_active_id(), 'type' => 'name')); ?> </span> <span class="freshest-time"><?php bbp_topic_last_active_time(); ?> </span> </div> </div> </li>
/** * Display nested subforums with a hierarchical structure using their parent category * @version 2.0 */ function apoc_loop_subforums() { // Exclude private forums $private = apoc_private_forum_ids(); // Check for subforums $subs = bbp_forum_get_subforums(array('post__not_in' => $private)); if (empty($subs)) { return; } // Buffer output ob_start(); // Print a header ?> <header class="forum-header"> <div class="forum-content"><h2><?php bbp_forum_title(); ?> </h2></div> <div class="forum-count">Topics</div> <div class="forum-freshness">Latest Post</div> </header> <ol class="forums category <?php bbp_forum_status(); ?> "><?php // Loop over forums foreach ($subs as $count => $sub) { // Get forum details $sub_id = $sub->ID; $title = $sub->post_title; $desc = $sub->post_content; $permalink = bbp_get_forum_permalink($sub_id); // Get topic counts $topics = bbp_get_forum_topic_count($sub_id, false); // Get the most recent reply and its topic $reply_id = bbp_get_forum_last_reply_id($sub_id); $topic_id = bbp_is_reply($reply_id) ? bbp_get_reply_topic_id($reply_id) : $reply_id; $topic_title = bbp_get_topic_title($topic_id); $link = bbp_get_reply_url($reply_id); // Get the author avatar $user_id = bbp_get_reply_author_id($reply_id); $avatar = apoc_get_avatar(array('user_id' => $user_id, 'link' => true, 'size' => 50)); // Toggle html class $class = $count % 2 ? 'odd' : 'even'; // Print output ?> <li id="forum-<?php echo $sub_id; ?> " class="forum <?php echo $class; ?> "> <div class="forum-content"> <h3 class="forum-title"><a href="<?php echo $permalink; ?> " title="Browse <?php echo $title; ?> "><?php echo $title; ?> </a></h3> <p class="forum-description"><?php echo $desc; ?> </p> </div> <div class="forum-count"> <?php echo $topics; ?> </div> <div class="forum-freshness"> <?php echo $avatar; ?> <div class="freshest-meta"> <a class="freshest-title" href="<?php echo $link; ?> " title="<?php echo $topic_title; ?> "><?php echo $topic_title; ?> </a> <span class="freshest-author">By <?php bbp_author_link(array('post_id' => $reply_id, 'type' => 'name')); ?> </span> <span class="freshest-time"><?php bbp_topic_last_active_time($topic_id); ?> </span> </div> </div> </li> <?php } ?> </ol> <?php // Retrieve from buffer $output = ob_get_contents(); ob_end_clean(); echo $output; }
<td><?php bbp_forum_post_count( $sub_id, true ); ?></td> <td><p class="bbp-topic-meta"> <?php do_action( 'bbp_theme_before_topic_author' ); ?> <a class="freshest-title" href="<?php echo $link; ?>" title="<?php echo $topic_title; ?>"><?php echo $topic_title; ?></a> <span class="bbp-topic-freshness-author">By <?php bbp_author_link( array( 'post_id' => bbp_get_forum_last_active_id(), 'size' => 14 ) ); ?></span> <?php do_action( 'bbp_theme_after_topic_author' ); ?> </p> <?php do_action( 'bbp_theme_before_forum_freshness_link' ); ?> <span class="freshest-time"><?php bbp_topic_last_active_time( $topic_id ); ?></span> <?php do_action( 'bbp_theme_after_forum_freshness_link' ); ?></td> </tr> <?php endforeach; ?> <?php // Retrieve from buffer $output = ob_get_contents(); ob_end_clean(); echo $output; } else { ?> <tr> <th colspan="4">No Boards</th> </tr>
?> <div class="topic-avatar"> <?php printf(_x('%1$s', 'widgets', 'bbpress'), '<div class="topic-author">' . $author_link . '</div>'); ?> </div> <?php } ?> <div class="topic-content"> <h4><a class="bbp-forum-title" href="<?php bbp_topic_permalink($topic_id); ?> "><?php bbp_topic_title($topic_id); ?> </a></h4> <?php bbp_topic_last_active_time($topic_id); ?> </div> </div> <?php } ?> </div> <?php wp_reset_postdata();