Ejemplo n.º 1
0
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;
    }
}
Ejemplo n.º 2
0
/**
 * 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);
}
Ejemplo n.º 3
0
 /**
  * @covers ::bbp_get_topic_freshness_link
  */
 public function test_bbp_get_topic_freshness_link_with_unpublished_replies()
 {
     if (is_multisite()) {
         $this->markTestSkipped('Skipping URL tests in multiste for now.');
     }
     $now = time();
     $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 20);
     // 2o hours ago
     $post_date_r1 = date('Y-m-d H:i:s', $now - 60 * 60 * 18);
     // 18 hours ago
     $post_date_r2 = date('Y-m-d H:i:s', $now - 60 * 60 * 16);
     // 16 hours ago
     $post_date_r3 = date('Y-m-d H:i:s', $now - 60 * 60 * 14);
     // 14 hours ago
     $post_date_r4 = date('Y-m-d H:i:s', $now - 60 * 60 * 12);
     // 12 hours ago
     $post_date_r5 = date('Y-m-d H:i:s', $now - 60 * 60 * 10);
     // 1o hours ago
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_title' => 'Topic 1', 'post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f)));
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1" title="">20 hours ago</a>', $link);
     $r1 = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date_r1, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r1) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">18 hours ago</a>', $link);
     $r2 = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date_r2, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r2) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">16 hours ago</a>', $link);
     bbp_spam_reply($r2);
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r1) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">18 hours ago</a>', $link);
     $r3 = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date_r3, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r3) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">14 hours ago</a>', $link);
     // Todo: Use bbp_trash_reply() and not wp_trash_post()
     wp_trash_post($r3);
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r1) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">18 hours ago</a>', $link);
     $r4 = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date_r4, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r4) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">12 hours ago</a>', $link);
     bbp_unapprove_reply($r4);
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r1) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">18 hours ago</a>', $link);
     bbp_unspam_reply($r2);
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r2) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">16 hours ago</a>', $link);
     // Todo: Use bbp_untrash_reply() and not wp_untrash_post()
     wp_untrash_post($r3);
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r3) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">14 hours ago</a>', $link);
     bbp_approve_reply($r4);
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r4) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">12 hours ago</a>', $link);
     $r5 = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date_r5, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $link = bbp_get_topic_freshness_link($t);
     $this->assertSame('<a href="http://' . WP_TESTS_DOMAIN . '/?topic=topic-1/#post-' . bbp_get_reply_id($r5) . '" title="Reply To: ' . bbp_get_topic_title($t) . '">10 hours ago</a>', $link);
 }