function widget($args, $instance) { extract($args, EXTR_SKIP); $title = !empty($instance['title']) ? $instance['title'] : __('Recent Topics'); $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number = !empty($instance['number']) ? absint($instance['number']) : 5; $orderby = !empty($instance['number']) ? strip_tags($instance['order_by']) : 'newness'; if ($orderby == 'newness') { $cb_meta_key = $cb_order_by = NULL; } elseif ($orderby == 'popular') { $cb_meta_key = '_bbp_reply_count'; $cb_order_by = 'meta_value'; } elseif ($orderby == 'freshness') { $cb_meta_key = '_bbp_last_active_time'; $cb_order_by = 'meta_value'; } if (!$number) { $number = 5; } $cb_qry = new WP_Query(array('post_type' => bbp_get_topic_post_type(), 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'order' => 'DESC', 'posts_per_page' => $number, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'meta_key' => $cb_meta_key, 'orderby' => $cb_order_by)); echo $before_widget; echo $before_title . $title . $after_title; ?> <ul class="cb-bbp-recent-topics"> <?php while ($cb_qry->have_posts()) { $cb_qry->the_post(); ?> <li> <?php $cb_reply_id = bbp_get_reply_id($cb_qry->post->ID); $cb_reply_url = '<a class="bbp-reply-topic-title" href="' . esc_url(bbp_get_reply_url($cb_reply_id)) . '" title="' . esc_attr(bbp_get_reply_excerpt($cb_reply_id, 50)) . '">' . bbp_get_reply_topic_title($cb_reply_id) . '</a>'; $cb_number_replies = bbp_get_topic_reply_count($cb_reply_id); $cb_author_avatar = bbp_get_reply_author_link(array('post_id' => $cb_reply_id, 'type' => 'avatar', 'size' => 60)); $cb_author_name = bbp_get_reply_author_link(array('post_id' => $cb_reply_id, 'type' => 'name')); echo $cb_author_avatar . '<div class="cb-bbp-meta">' . $cb_reply_url . '<div class="cb-bbp-byline">' . __('Started by', 'cubell') . ' ' . $cb_author_name . ' <i class="icon-long-arrow-right"></i> ' . $cb_number_replies . ' replies</div></div>'; ?> </li> <?php } ?> </ul> <?php echo $after_widget; // Reset the $post global wp_reset_postdata(); }
/** * @covers ::bbp_topic_reply_count * @covers ::bbp_get_topic_reply_count */ public function test_bbp_get_topic_reply_count() { $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $int_value = 3; $formatted_value = bbp_number_format($int_value); $this->factory->reply->create_many($int_value, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); bbp_update_topic_reply_count($t); // Output $this->expectOutputString($formatted_value); bbp_topic_reply_count($t); // Formatted string $count = bbp_get_topic_reply_count($t, false); $this->assertSame($formatted_value, $count); // Integer $count = bbp_get_topic_reply_count($t, true); $this->assertSame($int_value, $count); }
/** * @covers ::bbp_update_topic_reply_count */ public function test_bbp_update_topic_reply_count() { // Create a forum $f = $this->factory->forum->create(); // Create a topic $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); // Start with zero $count = bbp_get_topic_reply_count($t); $this->assertSame('0', $count); // Create 3 replies $r1 = $this->factory->reply->create_many(3, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $count = bbp_get_topic_reply_count($t); $this->assertSame('3', $count); bbp_update_topic_reply_count($t); $count = bbp_get_topic_reply_count($t); $this->assertSame('3', $count); // Create another reply $r2 = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Test update using reply id bbp_update_topic_reply_count($r2); $count = bbp_get_topic_reply_count($t); $this->assertSame('4', $count); // Spam a reply bbp_spam_reply($r2); bbp_update_topic_reply_count($t); $count = bbp_get_topic_reply_count($t); $this->assertSame('3', $count); // Set the reply count manually bbp_update_topic_reply_count($t, 7); $count = bbp_get_topic_reply_count($t); $this->assertSame('7', $count); }
/** * @covers ::bbp_admin_repair_topic_hidden_reply_count */ public function test_bbp_admin_repair_topic_hidden_reply_count() { $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_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $count = bbp_get_topic_reply_count($t, true); $this->assertSame(1, $count); $r = $this->factory->reply->create_many(3, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); bbp_spam_reply($r[0]); bbp_unapprove_reply($r[2]); $count = bbp_get_topic_reply_count_hidden($t, true); $this->assertSame(2, $count); // Delete the topic _bbp_reply_count_hidden meta key. $this->assertTrue(delete_post_meta_by_key('_bbp_reply_count_hidden')); $count = bbp_get_topic_reply_count_hidden($t, true); $this->assertSame(0, $count); // Repair the topic hidden reply count meta. bbp_admin_repair_topic_hidden_reply_count(); bbp_clean_post_cache($t); $count = bbp_get_topic_reply_count_hidden($t, true); $this->assertSame(2, $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)); }
/** * @covers ::bbp_unapprove_reply */ public function test_bbp_unapprove_reply() { // Create a forum. $f = $this->factory->forum->create(); // Create a topic. $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); // Create some replies. $r1 = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $reply_post_status = bbp_get_reply_status($r1); $this->assertSame('publish', $reply_post_status); $topic_reply_count = bbp_get_topic_reply_count($t); $this->assertSame('1', $topic_reply_count); $r2 = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $reply_post_status = bbp_get_reply_status($r2); $this->assertSame('publish', $reply_post_status); $topic_reply_count = bbp_get_topic_reply_count($t); $this->assertSame('2', $topic_reply_count); bbp_unapprove_reply($r2); $reply_post_status = bbp_get_reply_status($r2); $this->assertSame('pending', $reply_post_status); $topic_reply_count = bbp_get_topic_reply_count($t); $this->assertSame('1', $topic_reply_count); }
/** * If a topic has been used for a post, give the number of replies in place of comment count */ function maybe_change_comments_number($number, $post_ID) { if (!function_exists('bbp_has_forums')) { return $number; } if (get_post_meta($post_ID, 'use_bbpress_discussion_topic', true)) { $topic_ID = get_post_meta($post_ID, 'bbpress_discussion_topic_id', true); return bbp_get_topic_reply_count($topic_ID); } return $number; }
/** * Output an RSS2 feed of topics, based on the query passed. * * @since bbPress (r3171) * * @uses bbp_version() * @uses bbp_is_single_topic() * @uses bbp_user_can_view_forum() * @uses bbp_get_topic_forum_id() * @uses bbp_show_load_topic() * @uses bbp_topic_permalink() * @uses bbp_topic_title() * @uses bbp_get_topic_reply_count() * @uses bbp_topic_content() * @uses bbp_has_topics() * @uses bbp_topics() * @uses bbp_the_topic() * @uses get_wp_title_rss() * @uses get_option() * @uses bloginfo_rss * @uses self_link() * @uses the_author() * @uses get_post_time() * @uses rss_enclosure() * @uses do_action() * @uses apply_filters() * * @param array $topics_query */ function bbp_display_topics_feed_rss2($topics_query = array()) { // User cannot access this forum if (bbp_is_single_forum() && !bbp_user_can_view_forum(array('forum_id' => bbp_get_forum_id()))) { return; } // Display the feed header('Content-Type: ' . feed_content_type('rss2') . '; charset=' . get_option('blog_charset'), true); header('Status: 200 OK'); echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>'; ?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" <?php do_action('bbp_feed'); ?> > <channel> <title><?php bloginfo_rss('name'); ?> » <?php _e('All Topics', 'bbpress'); ?> </title> <atom:link href="<?php self_link(); ?> " rel="self" type="application/rss+xml" /> <link><?php self_link(); ?> </link> <description><?php // ?> </description> <pubDate><?php echo mysql2date('D, d M Y H:i:s O', current_time('mysql'), false); ?> </pubDate> <generator>http://bbpress.org/?v=<?php bbp_version(); ?> </generator> <language><?php bloginfo_rss('language'); ?> </language> <?php do_action('bbp_feed_head'); ?> <?php if (bbp_has_topics($topics_query)) { ?> <?php while (bbp_topics()) { bbp_the_topic(); ?> <item> <guid><?php bbp_topic_permalink(); ?> </guid> <title><![CDATA[<?php bbp_topic_title(); ?> ]]></title> <link><?php bbp_topic_permalink(); ?> </link> <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_meta(bbp_get_topic_id(), '_bbp_last_active_time', true)); ?> </pubDate> <dc:creator><?php the_author(); ?> </dc:creator> <?php if (!post_password_required()) { ?> <description> <![CDATA[ <p><?php printf(esc_html__('Replies: %s', 'bbpress'), bbp_get_topic_reply_count()); ?> </p> <?php bbp_topic_content(); ?> ]]> </description> <?php rss_enclosure(); ?> <?php } ?> <?php do_action('bbp_feed_item'); ?> </item> <?php } ?> <?php } ?> <?php do_action('bbp_feed_footer'); ?> </channel> </rss> <?php exit; }
/** * @covers ::bbp_delete_topic_replies */ public function test_bbp_delete_topic_replies() { $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_many(2, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $this->assertSame(2, bbp_get_topic_reply_count($t, true)); bbp_delete_topic_replies($t); $count = count(bbp_get_all_child_ids($t, bbp_get_reply_post_type())); $this->assertSame(0, $count); }
/** * Post by email handler. * * For bbPress, the logic in this method is the same as {@link bbp_new_reply_handler()}. * It's duplicated because bbPress doesn't utilize hooks for verifying replies. * * @param bool $retval True by default. * @param array $data { * An array of arguments. * * @type array $headers Email headers. * @type string $content The email body content. * @type string $subject The email subject line. * @type int $user_id The user ID who sent the email. * @type bool $is_html Whether the email content is HTML or not. * @type int $i The email message number. * } * @param array $params Parsed paramaters from the email address querystring. * See {@link BP_Reply_By_Email_Parser::get_parameters()}. * @return array|object Array of the parsed item on success. WP_Error object * on failure. */ public function post($retval, $data, $params) { /** SETUP DATA ***************************************************/ // reset globals global $bp; if (empty($bp->rbe->temp)) { $bp->rbe = new stdClass(); $bp->rbe->temp = new stdClass(); } $i = $data['i']; $user_id = $data['user_id']; // get topic ID $topic_id = !empty($params[$this->secondary_item_id_param]) ? $params[$this->secondary_item_id_param] : false; // get reply post ID $reply_to = !empty($params[$this->reply_id_param]) ? $params[$this->reply_id_param] : 0; // current email is not a bbPress group reply if (empty($topic_id)) { // if current email is a bbPress new group topic, parse it if (!empty($params[$this->forum_id_param])) { $retval = $this->post_new_topic($data, $params); } return $retval; } /* current email is a bbPress group reply, let's proceed! */ // let RBE know that we're in the process of rendering a bbP reply // BuddyPress group forum reply if (!empty($params[$this->item_id_param])) { bp_rbe_log('Message #' . $i . ': this is a bbPress group forum reply'); // bbPress } else { bp_rbe_log('Message #' . $i . ': this is a bbPress forum reply'); } // other variables $reply_author = $user_id; $anonymous_data = 0; /** GROUP PERMISSIONS ********************************************/ // posting from a BP group if (!empty($params[$this->item_id_param])) { // set group ID and cache it in global for later use // $bp->rbe->temp->group_id gets passed to the set_group_id() method later on $group_id = $bp->rbe->temp->group_id = $params[$this->item_id_param]; // get all group member data for the user in one swoop! $group_member_data = bp_rbe_get_group_member_info($reply_author, $group_id); // user is not a member of the group anymore if (empty($group_member_data)) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_not_group_member' ); return new WP_Error('user_not_group_member', '', $data); } // user is banned from group if ((int) $group_member_data->is_banned == 1) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'user_banned_from_group' ); return new WP_Error('user_banned_from_group', '', $data); } // override groups_get_current_group() with our cached group ID add_filter('groups_get_current_group', array($this, 'set_group_id')); // make sure bbP doesn't send any emails as GES handles this add_filter('bbp_get_topic_subscribers', '__return_false'); // temporarily add some GES filters here add_filter('bp_ass_activity_notification_subject', 'wp_specialchars_decode'); add_filter('bp_ass_activity_notification_content', 'wp_specialchars_decode'); // bbPress-only forums } else { // Subscriptions - make sure the author stays subscribed to the thread // this is due to how bbp_update_reply() works $_POST['bbp_topic_subscription'] = 'bbp_subscribe'; } /** REPLY PERMISSIONS ********************************************/ // Allow member to pass default cap checks. // The reason why we keep the 'publish_replies' check below is b/c bbPress // plugins may disable cap access for a specific user if they have hooked into // the 'bbp_map_meta_caps' filter. add_filter('bbp_map_meta_caps', array($this, 'map_forum_meta_caps'), 5, 4); // User cannot create replies if (!user_can($reply_author, 'publish_replies')) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_permissions' ); return new WP_Error('bbp_reply_permissions', '', $data); } /** UNFILTERED HTML **********************************************/ // Remove wp_filter_kses filters from title and content for capable users if (user_can($user_id, 'unfiltered_html')) { remove_filter('bbp_new_reply_pre_title', 'wp_filter_kses'); remove_filter('bbp_new_reply_pre_content', 'wp_filter_kses'); } /** REPLY DATA ***************************************************/ // setup a dummy reply title b/c bbP requires it $reply_title = sprintf(__('Reply To: Topic ID %d', 'bp-rbe'), $topic_id); // Filter and sanitize $reply_content = apply_filters('bbp_new_reply_pre_content', $data['content']); /** REPLY MODERATION *********************************************/ // Reply Flooding if (!bbp_check_for_flood($anonymous_data, $reply_author)) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_flood' ); //bbp_add_error( 'bbp_reply_flood', __( '<strong>ERROR</strong>: Slow down; you move too fast.', 'bbpress' ) ); return new WP_Error('bbp_reply_flood', '', $data); } // Reply Duplicate if (!bbp_check_for_duplicate(array('post_type' => bbp_get_reply_post_type(), 'post_author' => $reply_author, 'post_content' => $reply_content, 'post_parent' => $topic_id, 'anonymous_data' => $anonymous_data))) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_duplicate' ); return new WP_Error('bbp_reply_duplicate', '', $data); } // Reply Blacklist if (!bbp_check_for_blacklist($anonymous_data, $reply_author, $reply_title, $reply_content)) { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_blacklist' ); return new WP_Error('bbp_reply_blacklist', '', $data); } // Reply Status // Maybe put into moderation if (!bbp_check_for_moderation($anonymous_data, $reply_author, $reply_title, $reply_content)) { $reply_status = bbp_get_pending_status_id(); // Default } else { $reply_status = bbp_get_public_status_id(); } /** POSTING TIME! ************************************************/ // get forum ID $forum_id = bbp_get_topic_forum_id($topic_id); // bbP hook before save do_action('bbp_new_reply_pre_extras', $topic_id, $forum_id); // Setup reply data $reply_data = apply_filters('bbp_new_reply_pre_insert', array('post_author' => $reply_author, 'post_title' => $reply_title, 'post_content' => $reply_content, 'post_status' => $reply_status, 'post_parent' => $topic_id, 'post_type' => bbp_get_reply_post_type(), 'comment_status' => 'closed', 'menu_order' => bbp_get_topic_reply_count($topic_id, false) + 1)); // Insert reply $reply_id = wp_insert_post($reply_data); // Reply posted! if (!is_wp_error($reply_id)) { // more internal logging bp_rbe_log('Message #' . $i . ': bbPress reply successfully posted!'); // Problem posting } else { //do_action( 'bp_rbe_imap_no_match', $connection, $i, $headers, 'bbp_reply_error' ); return new WP_Error('bbp_reply_error', '', $data); } /** AFTER POSTING ************************************************/ // stuff that needs to happen after a bbP reply is posted occurs here... bbP // should preferably do the following at the 'bbp_new_reply' hook, until then // do what bbP does inline. // Trash Check //////////////////////////////////////////////////// // If this reply starts as trash, add it to pre_trashed_replies // for the topic, so it is properly restored. if (bbp_is_topic_trash($topic_id) || $reply_data['post_status'] == bbp_get_trash_status_id()) { // Trash the reply wp_trash_post($reply_id); // Only add to pre-trashed array if topic is trashed if (bbp_is_topic_trash($topic_id)) { // Get pre_trashed_replies for topic $pre_trashed_replies = get_post_meta($topic_id, '_bbp_pre_trashed_replies', true); // Add this reply to the end of the existing replies $pre_trashed_replies[] = $reply_id; // Update the pre_trashed_reply post meta update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies); } // Spam Check ///////////////////////////////////////////////////// // If reply or topic are spam, officially spam this reply } elseif (bbp_is_topic_spam($topic_id) || $reply_data['post_status'] == bbp_get_spam_status_id()) { add_post_meta($reply_id, '_bbp_spam_meta_status', bbp_get_public_status_id()); // Only add to pre-spammed array if topic is spam if (bbp_is_topic_spam($topic_id)) { // Get pre_spammed_replies for topic $pre_spammed_replies = get_post_meta($topic_id, '_bbp_pre_spammed_replies', true); // Add this reply to the end of the existing replies $pre_spammed_replies[] = $reply_id; // Update the pre_spammed_replies post meta update_post_meta($topic_id, '_bbp_pre_spammed_replies', $pre_spammed_replies); } } // Reply By Email ///////////////////////////////////////////////// // Add a RBE marker to the post's meta // Could potentially show that post was made via email on the frontend add_post_meta($reply_id, 'bp_rbe', 1); /** POST HOOKS ***************************************************/ // RBE Custom Hooks /////////////////////////////////////////////// // change activity action add_filter('bbp_before_record_activity_parse_args', array($this, 'change_activity_action')); // add RBE's special activity hook add_action('bp_activity_after_save', array($this, 'activity_rbe_hook')); // bbPress Reply Hooks //////////////////////////////////////////// do_action('bbp_new_reply', $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author, false, $reply_to); do_action('bbp_new_reply_post_extras', $reply_id); return array('bbp_reply_id' => $reply_id); }
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); }
/** * Prepare the list-table items for display * * @since 2.6.0 bbPress (r5886) * * @uses $this->_column_headers * @uses $this->items * @uses $this->get_columns() * @uses $this->get_sortable_columns() * @uses $this->get_pagenum() * @uses $this->set_pagination_args() */ public function prepare_items($topic_id = 0) { // Sanitize the topic ID $topic_id = bbp_get_topic_id($topic_id); // Set column headers $this->_column_headers = array($this->get_columns(), array(), $this->get_sortable_columns()); // Handle bulk actions $this->process_bulk_action(); // Query parameters $per_page = 5; $current_page = $this->get_pagenum(); $orderby = !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'date'; $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'asc'; // Query for replies $reply_query = new WP_Query(array('post_type' => bbp_get_reply_post_type(), 'post_parent' => $topic_id, 'posts_per_page' => $per_page, 'paged' => $current_page, 'orderby' => $orderby, 'order' => ucwords($order), 'hierarchical' => false, 'ignore_sticky_posts' => true)); // Get the total number of replies, for pagination $total_items = bbp_get_topic_reply_count($topic_id); // Set list table items to queried posts $this->items = $reply_query->posts; // Set the pagination arguments $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page))); }
protected function get_comments() { return bbp_get_topic_reply_count($this->post->ID, true); }
/** * @covers ::bbp_unspam_topic_replies */ public function test_bbp_unspam_topic_replies() { $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))); $r = $this->factory->reply->create_many(2, array('post_parent' => $t, 'post_date' => $post_date_reply, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); bbp_spam_topic_replies($t); bbp_unspam_topic_replies($t); $this->assertEquals('', get_post_meta($t, '_bbp_pre_spammed_replies', true)); $this->assertEquals(array(), get_post_meta($t, '_bbp_pre_spammed_replies', false)); foreach ($r as $reply) { $reply_status = get_post_status($reply); $this->assertSame(bbp_get_public_status_id(), $reply_status); $this->assertEquals('', get_post_meta($reply, '_wp_trash_meta_status', true)); $this->assertEquals(array(), get_post_meta($reply, '_wp_trash_meta_status', false)); } $count = bbp_get_forum_reply_count($f, false, true); $this->assertSame(2, $count); $last_reply_id = bbp_get_forum_last_reply_id($f); $this->assertSame($r[1], $last_reply_id); $last_active_id = bbp_get_forum_last_active_id($f); $this->assertSame($r[1], $last_active_id); $last_active_time = bbp_get_forum_last_active_time($f); $this->assertSame($reply_time, $last_active_time); $count = bbp_get_topic_reply_count($t, true, true); $this->assertSame(2, $count); $count = bbp_get_topic_reply_count_hidden($t, true, true); $this->assertSame(0, $count); $last_reply_id = bbp_get_topic_last_reply_id($t); $this->assertSame($r[1], $last_reply_id); $last_active_id = bbp_get_topic_last_active_id($t); $this->assertSame($r[1], $last_active_id); $last_active_time = bbp_get_topic_last_active_time($t); $this->assertSame($reply_time, $last_active_time); }
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; } }
function aq_modify_before_title($title, $topic_id = 0) { $topic_id = bbp_get_topic_id($topic_id); $replies = bbp_get_topic_reply_count($topic_id); $statuses = array(1, 2, 3); $status_id = get_post_meta($topic_id, '_bbps_topic_status', true); // Let's not override default closed/sticky status if (bbp_is_topic_sticky()) { echo '<span class="topic-sticky"> [Sticky] </span>'; } elseif (!in_array($status_id, $statuses)) { if (get_post_type($topic_id) == bbp_get_topic_post_type() && bbp_is_topic_closed($topic_id)) { echo '<span class="resolved">[Resolved]</span>'; } else { if ($replies >= 1) { echo '<span class="in-progress"> [In Progress] </span>'; } else { echo '<span class="not-resolved"> [Not Resolved] </span>'; } } // Default Statuses } else { if ($status_id == 1) { // Not Resolved echo '<span class="not-resolved"> [Not Resolved] </span>'; } if ($status_id == 2) { // Not Resolved echo '<span class="resolved"> [Resolved] </span>'; } if ($status_id == 3) { // Not Support Question (mark as resolved) add_post_meta($topic_id, '_bbps_topic_status', 2); echo '<span class="resolved"> [Resolved] </span>'; } } }
/** * Output total reply count of a topic * * @since bbPress (r2485) * * @param int $topic_id Optional. Topic id * @uses bbp_get_topic_reply_count() To get the topic reply count */ function bbp_topic_reply_count($topic_id = 0) { echo bbp_get_topic_reply_count($topic_id); }
/** * Get the position of a reply by querying the DB directly for the replies * of a given topic. * * @since bbPress (r3933) * * @param int $reply_id * @param int $topic_id */ function bbp_get_reply_position_raw($reply_id = 0, $topic_id = 0) { // Get required data $reply_id = bbp_get_reply_id($reply_id); $topic_id = !empty($topic_id) ? bbp_get_topic_id($topic_id) : bbp_get_reply_topic_id($reply_id); $reply_position = 0; // If reply is actually the first post in a topic, return 0 if ($reply_id !== $topic_id) { // Make sure the topic has replies before running another query $reply_count = bbp_get_topic_reply_count($topic_id, false); if (!empty($reply_count)) { // Get reply id's $topic_replies = bbp_get_all_child_ids($topic_id, bbp_get_reply_post_type()); if (!empty($topic_replies)) { // Reverse replies array and search for current reply position $topic_replies = array_reverse($topic_replies); $reply_position = array_search((string) $reply_id, $topic_replies); // Bump the position to compensate for the lead topic post $reply_position++; } } } return (int) $reply_position; }
<?php bbp_topic_row_actions(); ?> <?php do_action('bbp_theme_after_topic_meta'); ?> </li> <li class="topic-activity"> <div class="stat"><span class="number"><?php bbp_topic_voice_count(); ?> </span> <?php _ex('Voices', 'bbPress', 'bunyad'); ?> </div> <div class="stat"><?php echo bbp_show_lead_topic() ? '<span class="number">' . bbp_get_topic_reply_count() . '</span> ' . _x('Replies', 'bbPress', 'bunyad') : '<span class="number">' . bbp_get_topic_post_count() . '</span> ' . _x('Posts', 'bbPress', 'bunyad'); ?> </div> </li> </ul><!-- #bbp-topic-<?php bbp_topic_id(); ?> -->
/** * Output total reply count of a topic * * @since 2.0.0 bbPress (r2485) * * @param int $topic_id Optional. Topic id * @param boolean $integer Optional. Whether or not to format the result * @uses bbp_get_topic_reply_count() To get the topic reply count */ function bbp_topic_reply_count($topic_id = 0, $integer = false) { echo bbp_get_topic_reply_count($topic_id, $integer); }
function firmasite_social_bbp_get_topic_pagination($args = '') { global $wp_rewrite; $defaults = array('topic_id' => bbp_get_topic_id(), 'before' => '<div class="makeit-pag-small">', 'after' => '</div>'); $r = bbp_parse_args($args, $defaults, 'get_topic_pagination'); extract($r); // If pretty permalinks are enabled, make our pagination pretty if ($wp_rewrite->using_permalinks()) { $base = trailingslashit(get_permalink($topic_id)) . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/'); } else { $base = add_query_arg('paged', '%#%', get_permalink($topic_id)); } // Get total and add 1 if topic is included in the reply loop $total = bbp_get_topic_reply_count($topic_id, true); // Bump if topic is in loop if (!bbp_show_lead_topic()) { $total++; } // Pagination settings $pagination = array('type' => 'list', 'base' => $base, 'format' => '', 'total' => ceil((int) $total / (int) bbp_get_replies_per_page()), 'current' => 0, 'prev_next' => false, 'mid_size' => 2, 'end_size' => 3, 'add_args' => bbp_get_view_all() ? array('view' => 'all') : false); // Add pagination to query object $pagination_links = paginate_links($pagination); if (!empty($pagination_links)) { // Remove first page from pagination if ($wp_rewrite->using_permalinks()) { $pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $pagination_links); } else { $pagination_links = str_replace('&paged=1', '', $pagination_links); } // Add before and after to pagination links $pagination_links = $before . $pagination_links . $after; } return apply_filters('bbp_get_topic_pagination', $pagination_links, $args); }