/** * Return a fancy description of the current topic, including total topics, * total replies, and last activity. * * @since 2.0.0 bbPress (r2860) * * @param array $args This function supports these arguments: * - topic_id: Topic id * - before: Before the text * - after: After the text * - size: Size of the avatar * @uses bbp_get_topic_id() To get the topic id * @uses bbp_get_topic_voice_count() To get the topic voice count * @uses bbp_get_topic_reply_count() To get the topic reply count * @uses bbp_get_topic_freshness_link() To get the topic freshness link * @uses bbp_get_topic_last_active_id() To get the topic last active id * @uses bbp_get_reply_author_link() To get the reply author link * @uses apply_filters() Calls 'bbp_get_single_topic_description' with * the description and args * @return string Filtered topic description */ function bbp_get_single_topic_description($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('topic_id' => 0, 'before' => '<div class="bbp-template-notice info"><ul><li class="bbp-topic-description">', 'after' => '</li></ul></div>', 'size' => 14), 'get_single_topic_description'); // Validate topic_id $topic_id = bbp_get_topic_id($r['topic_id']); // Unhook the 'view all' query var adder remove_filter('bbp_get_topic_permalink', 'bbp_add_view_all'); // Build the topic description $vc_int = bbp_get_topic_voice_count($topic_id, true); $voice_count = bbp_get_topic_voice_count($topic_id, false); $reply_count = bbp_get_topic_replies_link($topic_id); $time_since = bbp_get_topic_freshness_link($topic_id); // Singular/Plural $voice_count = sprintf(_n('%s voice', '%s voices', $vc_int, 'bbpress'), $voice_count); // Topic has replies $last_reply = bbp_get_topic_last_reply_id($topic_id); if (!empty($last_reply)) { $last_updated_by = bbp_get_author_link(array('post_id' => $last_reply, 'size' => $r['size'])); $retstr = sprintf(esc_html__('This topic contains %1$s, has %2$s, and was last updated by %3$s %4$s.', 'bbpress'), $reply_count, $voice_count, $last_updated_by, $time_since); // Topic has no replies } elseif (!empty($voice_count) && !empty($reply_count)) { $retstr = sprintf(esc_html__('This topic contains %1$s and has %2$s.', 'bbpress'), $voice_count, $reply_count); // Topic has no replies and no voices } elseif (empty($voice_count) && empty($reply_count)) { $retstr = sprintf(esc_html__('This topic has no replies.', 'bbpress'), $voice_count, $reply_count); } // Add the 'view all' filter back add_filter('bbp_get_topic_permalink', 'bbp_add_view_all'); // Combine the elements together $retstr = $r['before'] . $retstr . $r['after']; // Return filtered result return apply_filters('bbp_get_single_topic_description', $retstr, $r, $args); }
function avia_bbpress_add_topic_class($classes) { $voices = bbp_get_topic_voice_count() > 1 ? "multi" : "single"; $classes[] = 'topic-voices-' . $voices; return $classes; }
/** * @covers ::bbp_move_topic_handler */ public function test_bbp_move_topic_handler() { $old_current_user = 0; $this->old_current_user = get_current_user_id(); $this->set_current_user($this->factory->user->create(array('role' => 'administrator'))); $this->keymaster_id = get_current_user_id(); bbp_set_user_role($this->keymaster_id, bbp_get_keymaster_role()); $old_forum_id = $this->factory->forum->create(); $topic_id = $this->factory->topic->create(array('post_parent' => $old_forum_id, 'topic_meta' => array('forum_id' => $old_forum_id))); $reply_id = $this->factory->reply->create(array('post_parent' => $topic_id, 'reply_meta' => array('forum_id' => $old_forum_id, 'topic_id' => $topic_id))); // Topic post parent $topic_parent = wp_get_post_parent_id($topic_id); $this->assertSame($old_forum_id, $topic_parent); // Forum meta $this->assertSame(1, bbp_get_forum_topic_count($old_forum_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($old_forum_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($old_forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($old_forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($old_forum_id)); // Topic meta $this->assertSame($old_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($reply_id, bbp_get_topic_last_reply_id($topic_id)); $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id)); // Reply Meta $this->assertSame($old_forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id)); // Create a new forum $new_forum_id = $this->factory->forum->create(); // Move the topic into the new forum bbp_move_topic_handler($topic_id, $old_forum_id, $new_forum_id); // Topic post parent $topic_parent = wp_get_post_parent_id($topic_id); $this->assertSame($new_forum_id, $topic_parent); // Forum meta $this->assertSame(1, bbp_get_forum_topic_count($new_forum_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($new_forum_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($new_forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($new_forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($new_forum_id)); // Topic meta $this->assertSame($new_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($reply_id, bbp_get_topic_last_reply_id($topic_id)); $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id)); // Reply Meta $this->assertSame($new_forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id)); // Retore the user $this->set_current_user($this->old_current_user); }
/** * @covers ::bbp_admin_repair_topic_voice_count */ public function test_bbp_admin_repair_topic_voice_count() { $u = $this->factory->user->create_many(2); $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $r = $this->factory->reply->create(array('post_author' => $u[0], 'post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $r = $this->factory->reply->create(array('post_author' => $u[1], 'post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $count = bbp_get_topic_voice_count($t); $this->assertSame('3', $count); // Delete the topic _bbp_voice_count meta key. $this->assertTrue(delete_post_meta_by_key('_bbp_voice_count')); $count = bbp_get_topic_voice_count($t); $this->assertSame('0', $count); // Repair the topic voice count meta. bbp_admin_repair_topic_voice_count(); bbp_clean_post_cache($t); $count = bbp_get_topic_voice_count($t); $this->assertSame('3', $count); }
/** * @covers ::bbp_update_topic_voice_count */ public function test_bbp_update_topic_voice_count() { $u = $this->factory->user->create_many(2); $t = $this->factory->topic->create(); $count = bbp_get_topic_voice_count($t); $this->assertSame('1', $count); $r = $this->factory->reply->create(array('post_author' => $u[0], 'post_parent' => $t)); bbp_update_topic_voice_count($t); $count = bbp_get_topic_voice_count($t); $this->assertSame('2', $count); $count = bbp_update_topic_voice_count($t); $this->assertSame(2, $count); $r = $this->factory->reply->create(array('post_author' => $u[1], 'post_parent' => $t)); bbp_update_topic_voice_count($t); $count = bbp_get_topic_voice_count($t); $this->assertSame('3', $count); }
/** * @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)); }
/** * Get the data being exported * * @access public * @since 1.0 * @return array $data Data for Export */ public function get_data() { $topics = get_posts(array('post_parent' => $this->forum_id, 'nopaging' => true, 'post_type' => bbp_get_topic_post_type())); foreach ($topics as $topic) { $topic_anonymous = bbp_is_topic_anonymous($topic->ID); if ($topic_anonymous) { $email = get_post_meta($topic->ID, '_bbp_anonymous_email', true); } else { $email = get_the_author_meta('email', $topic->post_author); } $data[] = array('post_type' => bbp_get_topic_post_type(), 'post_author' => $email, 'user_login' => get_the_author_meta('user_login', $topic->post_author), 'post_parent' => $topic->post_parent, 'post_content' => htmlentities($topic->post_content), 'post_title' => $topic->post_title, 'post_date_gmt' => $topic->post_date_gmt, 'post_date' => $topic->post_date, 'anonymous' => $topic_anonymous ? '1' : '0', 'voices' => bbp_get_topic_voice_count($topic->ID), 'reply_count' => bbp_get_topic_post_count($topic->ID), 'resolved' => function_exists('bbps_topic_resolved') && bbps_topic_resolved($topic->ID) ? '1' : 0); $replies = get_posts(array('post_parent' => $topic->ID, 'nopaging' => true, 'post_type' => bbp_get_reply_post_type())); if ($replies) { foreach ($replies as $reply) { $reply_anonymous = bbp_is_reply_anonymous($reply->ID); if ($reply_anonymous) { $reply_email = get_post_meta($topic->ID, '_bbp_anonymous_email', true); } else { $reply_email = get_the_author_meta('email', $reply->post_author); } $data[] = array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_email, 'user_login' => get_the_author_meta('user_login', $reply->post_author), 'post_parent' => $reply->post_parent, 'post_content' => htmlentities($reply->post_content), 'post_title' => $reply->post_title, 'post_date_gmt' => $reply->post_date_gmt, 'post_date' => $reply->post_date, 'anonymous' => $reply_anonymous ? '1' : '0', 'voices' => '0', 'reply_count' => '0', 'resolved' => '0'); } } } $data = apply_filters('bbp_export_get_data', $data); return $data; }
function apoc_topic_byline($args = '') { // Default arguments $defaults = array('topic_id' => 0, 'before' => '<p class="post-byline">', 'after' => '</p>', 'size' => 50, 'echo' => true); $args = wp_parse_args($args, $defaults); // Validate topic_id $topic_id = bbp_get_topic_id($args['topic_id']); // Get the author avatar $avatar = apoc_get_avatar(array('user_id' => bbp_get_topic_author_id(), 'size' => $args['size'])); // Build the topic description $voice_count = bbp_get_topic_voice_count($topic_id); $reply_count = bbp_get_topic_reply_count($topic_id, true) + 1; $time_since = bbp_get_topic_freshness_link($topic_id); $author = bbp_get_author_link(array('post_id' => $topic_id, 'type' => 'name')); // Singular/Plural $reply_count = sprintf(_n('%d posts', '%d posts', $reply_count), $reply_count); $voice_count = sprintf(_n('%s member', '%s members', $voice_count), $voice_count); // Topic has replies $last_reply = bbp_get_topic_last_active_id($topic_id); if (!empty($last_reply)) { $last_updated_by = bbp_get_author_link(array('post_id' => $last_reply, 'type' => 'name')); $retstr = sprintf('This topic by %1$s contains %2$s by %3$s, and was last updated by %4$s, %5$s.', $author, $reply_count, $voice_count, $last_updated_by, $time_since); // Topic has no replies } elseif (!empty($voice_count) && !empty($reply_count)) { $retstr = sprintf('This topic contains %1$s by %2$s.', $reply_count, $voice_count); // Topic has no replies and no voices } elseif (empty($voice_count) && empty($reply_count)) { $retstr = sprintf('This topic has no replies yet.'); } // Combine the elements together $retstr = $args['before'] . $avatar . '<span>' . $retstr . '</span>' . $args['after']; // Return filtered result if (true == $args['echo']) { echo $retstr; } else { return $retstr; } }
/** * @covers ::bbp_topic_voice_count * @covers ::bbp_get_topic_voice_count */ public function test_bbp_get_topic_voice_count_with_pending_reply() { $u = $this->factory->user->create_many(2); $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $this->factory->reply->create(array('post_parent' => $t, 'post_author' => $u[0], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $count = bbp_get_topic_voice_count($t, true); $this->assertSame(2, $count); $r2 = $this->factory->reply->create(array('post_parent' => $t, 'post_author' => $u[1], 'post_status' => bbp_get_pending_status_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $count = bbp_get_topic_voice_count($t, true); $this->assertSame(2, $count); bbp_approve_reply($r2); $count = bbp_get_topic_voice_count($t, true); $this->assertSame(3, $count); }
function wm_bbp_additional_class($classes) { //Helper variables $voices_count = bbp_get_topic_voice_count(); $replies_count = bbp_show_lead_topic() ? bbp_get_topic_reply_count() : bbp_get_topic_post_count(); if (bbp_get_forum_post_type() == get_post_type()) { $voices_count = bbp_get_forum_topic_count(); $replies_count = bbp_show_lead_topic() ? bbp_get_forum_reply_count() : bbp_get_forum_post_count(); } //Preparing output $classes[] = 1 < $voices_count ? 'multi-voices' : 'single-voice'; $classes[] = 1 < $replies_count ? 'multi-replies' : 'single-reply'; //Output return apply_filters('wmhook_wm_bbp_additional_class_output', $classes); }