Esempio n. 1
0
 /**
  * @covers ::bbp_topic_last_active_id
  * @covers ::bbp_get_topic_last_active_id
  */
 public function test_bbp_get_topic_last_active_id()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $topic_last_active_id = bbp_get_topic_last_active_id($t);
     $this->assertSame($t, $topic_last_active_id);
     $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $topic_last_active_id = bbp_get_topic_last_active_id($t);
     $this->assertSame($r, $topic_last_active_id);
 }
Esempio n. 2
0
 /**
  * @covers ::bbp_update_topic_last_active_id
  */
 public function test_bbp_update_topic_last_active_id()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r1 = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $id = bbp_update_topic_last_active_id($t, $r1);
     $this->assertSame($r1, $id);
     $id = bbp_get_topic_last_active_id($t);
     $this->assertSame($r1, $id);
     $r2 = $this->factory->reply->create_many(2, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     bbp_update_topic_last_active_id($t, $r2[1]);
     $id = bbp_get_topic_last_active_id($t);
     $this->assertSame($r2[1], $id);
 }
 /**
  * @covers ::bbp_update_topic_last_active_id
  */
 public function test_bbp_update_topic_last_active_id()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $r1 = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Pass both the topic id and reply id to bbp_update_topic_last_active_id().
     bbp_update_topic_last_active_id($t, $r1);
     $last_active_id = bbp_get_topic_last_active_id($t);
     $this->assertSame($r1, $last_active_id);
     $r2 = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Pass the topic id to bbp_update_topic_last_active_id().
     bbp_update_topic_last_active_id($t);
     $last_active_id = bbp_get_topic_last_active_id($t);
     $this->assertSame($r2, $last_active_id);
     // Create a couple of replies.
     $r3 = $this->factory->reply->create_many(2, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Pass both the topic id and reply id of the array.
     bbp_update_topic_last_active_id($t, $r3[1]);
     $last_active_id = bbp_get_topic_last_active_id($t);
     $this->assertSame($r3[1], $last_active_id);
 }
/**
 * Walk up the ancestor tree from the current reply, and update all the counts
 *
 * @since bbPress (r2884)
 *
 * @param int $reply_id Optional. Reply id
 * @param string $last_active_time Optional. Last active time
 * @param int $forum_id Optional. Forum id
 * @param int $topic_id Optional. Topic id
 * @param bool $refresh If set to true, unsets all the previous parameters.
 *                       Defaults to true
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_reply_forum_id() To get the reply forum id
 * @uses get_post_ancestors() To get the ancestors of the reply
 * @uses bbp_is_reply() To check if the ancestor is a reply
 * @uses bbp_is_topic() To check if the ancestor is a topic
 * @uses bbp_update_topic_last_reply_id() To update the topic last reply id
 * @uses bbp_update_topic_last_active_id() To update the topic last active id
 * @uses bbp_get_topic_last_active_id() To get the topic last active id
 * @uses get_post_field() To get the post date of the last active id
 * @uses bbp_update_topic_last_active_time() To update the last active topic meta
 * @uses bbp_update_topic_voice_count() To update the topic voice count
 * @uses bbp_update_topic_reply_count() To update the topic reply count
 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
 *                                              count
 * @uses bbp_is_forum() To check if the ancestor is a forum
 * @uses bbp_update_forum_last_topic_id() To update the last topic id forum meta
 * @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
 * @uses bbp_update_forum_last_active_id() To update the forum last active id
 * @uses bbp_get_forum_last_active_id() To get the forum last active id
 * @uses bbp_update_forum_last_active_time() To update the forum last active time
 * @uses bbp_update_forum_reply_count() To update the forum reply count
 */
function bbp_update_reply_walker($reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true)
{
    // Verify the reply ID
    $reply_id = bbp_get_reply_id($reply_id);
    // Reply was passed
    if (!empty($reply_id)) {
        // Get the topic ID if none was passed
        if (empty($topic_id)) {
            $topic_id = bbp_get_reply_topic_id($reply_id);
        }
        // Get the forum ID if none was passed
        if (empty($forum_id)) {
            $forum_id = bbp_get_reply_forum_id($reply_id);
        }
    }
    // Set the active_id based on topic_id/reply_id
    $active_id = empty($reply_id) ? $topic_id : $reply_id;
    // Setup ancestors array to walk up
    $ancestors = array_values(array_unique(array_merge(array($topic_id, $forum_id), (array) get_post_ancestors($topic_id))));
    // If we want a full refresh, unset any of the possibly passed variables
    if (true === $refresh) {
        $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
    }
    // Walk up ancestors
    if (!empty($ancestors)) {
        foreach ($ancestors as $ancestor) {
            // Reply meta relating to most recent reply
            if (bbp_is_reply($ancestor)) {
                // @todo - hierarchical replies
                // Topic meta relating to most recent reply
            } elseif (bbp_is_topic($ancestor)) {
                // Last reply and active ID's
                bbp_update_topic_last_reply_id($ancestor, $reply_id);
                bbp_update_topic_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $topic_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $topic_last_active_time = get_post_field('post_date', bbp_get_topic_last_active_id($ancestor));
                }
                // Only update if reply is published
                if (bbp_is_reply_published($reply_id)) {
                    bbp_update_topic_last_active_time($ancestor, $topic_last_active_time);
                }
                // Counts
                bbp_update_topic_voice_count($ancestor);
                bbp_update_topic_reply_count($ancestor);
                bbp_update_topic_reply_count_hidden($ancestor);
                // Forum meta relating to most recent topic
            } elseif (bbp_is_forum($ancestor)) {
                // Last topic and reply ID's
                bbp_update_forum_last_topic_id($ancestor, $topic_id);
                bbp_update_forum_last_reply_id($ancestor, $reply_id);
                // Last Active
                bbp_update_forum_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $forum_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $forum_last_active_time = get_post_field('post_date', bbp_get_forum_last_active_id($ancestor));
                }
                // Only update if reply is published
                if (bbp_is_reply_published($reply_id)) {
                    bbp_update_forum_last_active_time($ancestor, $forum_last_active_time);
                }
                // Counts
                bbp_update_forum_reply_count($ancestor);
            }
        }
    }
}
Esempio n. 5
0
 /**
  * @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);
 }
			<?php 
bbp_topic_row_actions();
?>

		</div>

	</li>

	<li class="bbp-topic-last-poster">

			<?php 
do_action('bbp_theme_before_topic_freshness_author');
?>
			<span class="bbp-topic-freshness-author"><?php 
echo aq_get_author(bbp_get_topic_last_active_id());
?>
</span>

			<?php 
do_action('bbp_theme_after_topic_freshness_author');
?>

	</li>

        <li class="bbp-topic-reply-count"><div class="as-topic-reply-count"><?php 
bbp_show_lead_topic() ? bbp_topic_reply_count() : bbp_topic_post_count();
?>
</div></li>

	<li class="bbp-topic-freshness">
		<li class="bbp-topic-freshness col-md-2 text-right small">
			<?php 
do_action('bbp_theme_before_topic_freshness_link');
?>
			<?php 
bbp_topic_freshness_link();
?>
			<?php 
do_action('bbp_theme_after_topic_freshness_link');
?>
			<!-- <hr /> -->
			<p class="bbp-topic-meta">
				<?php 
do_action('bbp_theme_before_topic_freshness_author');
?>
				<span class="bbp-topic-freshness-author"><?php 
bbp_author_link(array('post_id' => bbp_get_topic_last_active_id(), 'size' => 20, 'link_title' => ''));
?>
</span>
				<?php 
do_action('bbp_theme_after_topic_freshness_author');
?>
			</p>
		</li>

	</ul><!-- #bbp-topic-<?php 
bbp_topic_id();
?>
 -->
</li>
Esempio n. 8
0
		<?php 
bbp_topic_freshness_link();
?>

		<?php 
do_action('bbp_theme_after_topic_freshness_link');
?>

		<!--<p class="bbp-topic-meta">

			<?php 
do_action('bbp_theme_before_topic_freshness_author');
?>

			<span class="bbp-topic-freshness-author"><?php 
bbp_author_link(array('post_id' => bbp_get_topic_last_active_id(), 'size' => 14));
?>
</span>

			<?php 
do_action('bbp_theme_after_topic_freshness_author');
?>

		</p>-->
	</li>

</ul><!-- #bbp-topic-<?php 
bbp_topic_id();
?>
 -->
function teamop_get_last_poster_block_topics()
{
    $output .= "<div class='last-posted-topic-user'>";
    $output .= bbp_get_reply_author_link(array('post_id' => bbp_get_topic_last_active_id(), 'size' => '14'));
    $output .= "</div>";
    $output .= "<div class='last-posted-topic-time'>";
    $output .= bbp_get_topic_last_active_time(bbp_get_topic_last_active_id());
    $output .= "</div>";
    return $output;
}
Esempio n. 10
0
            bbp_user_profile_url($topic->post_author);
            ?>
"><?php 
            bbp_topic_author_display_name();
            ?>
</a>
                            </div>
                            <div class="td-topics-title-details">
                                <?php 
            //bbp_get_reply_author_link(array('post_id' => ));
            ?>
                                Last reply by <a href="<?php 
            bbp_reply_author_url(bbp_get_topic_last_active_id());
            ?>
"><?php 
            echo bbp_get_topic_author_display_name(bbp_get_topic_last_active_id());
            ?>
</a>

                                <?php 
            bbp_topic_last_active_time();
            ?>
                            </div>

                        </li><li class="td-forum-topics-replies">
                            <?php 
            bbp_topic_reply_count();
            ?>
                        </li>
                    </ul>
                        <?php 
Esempio n. 11
0
 /**
  * @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));
 }
Esempio n. 12
0
function ipt_kb_bbp_forum_freshness_in_list($forum_id = 0)
{
    $og_forum_last_topic_id = bbp_get_forum_last_topic_id($forum_id);
    $og_last_topic_id = bbp_get_topic_last_active_id($og_forum_last_topic_id);
    $author_link = bbp_get_author_link(array('post_id' => $og_last_topic_id, 'type' => 'name'));
    $freshness = bbp_get_author_link(array('post_id' => $og_last_topic_id, 'size' => 32, 'type' => 'avatar'));
    if (!empty($freshness)) {
        ?>
<span class="pull-left thumbnail">
        <?php 
        echo $freshness;
        ?>
</span>
<?php 
    }
    do_action('bbp_theme_before_forum_freshness_link');
    ?>
<ul class="list-unstyled ipt_kb_forum_freshness_meta">
        <li class="bbp-topic-freshness-link"><?php 
    echo bbp_topic_freshness_link($og_forum_last_topic_id);
    ?>
  </li>
        <li class="bbp-topic-freshness-author">
                <?php 
    do_action('bbp_theme_before_topic_author');
    ?>
                <?php 
    if (!empty($author_link)) {
        printf(__('by %s', 'ipt_kb'), $author_link);
    }
    ?>
                <?php 
    do_action('bbp_theme_after_topic_author');
    ?>
        </li>
</ul>
<?php 
    do_action('bbp_theme_after_forum_freshness_link');
    ?>
        <?php 
}
Esempio n. 13
0
/**
 * Return a fancy description of the current topic, including total topics,
 * total replies, and last activity.
 *
 * @since bbPress (r2860)
 *
 * @param mixed $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 = '')
{
    // Default arguments
    $defaults = array('topic_id' => 0, 'before' => '<div class="bbp-template-notice info"><p class="bbp-topic-description">', 'after' => '</p></div>', 'size' => 14);
    $r = bbp_parse_args($args, $defaults, 'get_single_topic_description');
    extract($r);
    // Validate topic_id
    $topic_id = bbp_get_topic_id($topic_id);
    // Unhook the 'view all' query var adder
    remove_filter('bbp_get_topic_permalink', 'bbp_add_view_all');
    // Build the topic description
    $voice_count = bbp_get_topic_voice_count($topic_id);
    $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', $voice_count, 'bbpress'), $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, 'size' => $size));
        $retstr = sprintf(__('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(__('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(__('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 = $before . $retstr . $after;
    // Return filtered result
    return apply_filters('bbp_get_single_topic_description', $retstr, $args);
}
Esempio n. 14
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;
    }
}
Esempio n. 15
0
/**
 * Walk up the ancestor tree from the current reply, and update all the counts
 *
 * @since 2.0.0 bbPress (r2884)
 *
 * @param int $reply_id Optional. Reply id
 * @param string $last_active_time Optional. Last active time
 * @param int $forum_id Optional. Forum id
 * @param int $topic_id Optional. Topic id
 * @param bool $refresh If set to true, unsets all the previous parameters.
 *                       Defaults to true
 * @uses bbp_get_reply_id() To get the reply id
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_reply_forum_id() To get the reply forum id
 * @uses get_post_ancestors() To get the ancestors of the reply
 * @uses bbp_is_reply() To check if the ancestor is a reply
 * @uses bbp_is_topic() To check if the ancestor is a topic
 * @uses bbp_update_topic_last_reply_id() To update the topic last reply id
 * @uses bbp_update_topic_last_active_id() To update the topic last active id
 * @uses bbp_get_topic_last_active_id() To get the topic last active id
 * @uses get_post_field() To get the post date of the last active id
 * @uses bbp_update_topic_last_active_time() To update the last active topic meta
 * @uses bbp_update_topic_voice_count() To update the topic voice count
 * @uses bbp_update_topic_reply_count() To update the topic reply count
 * @uses bbp_update_topic_reply_count_hidden() To update the topic hidden reply
 *                                              count
 * @uses bbp_is_forum() To check if the ancestor is a forum
 * @uses bbp_update_forum_last_topic_id() To update the last topic id forum meta
 * @uses bbp_update_forum_last_reply_id() To update the last reply id forum meta
 * @uses bbp_update_forum_last_active_id() To update the forum last active id
 * @uses bbp_get_forum_last_active_id() To get the forum last active id
 * @uses bbp_update_forum_last_active_time() To update the forum last active time
 * @uses bbp_update_forum_reply_count() To update the forum reply count
 */
function bbp_update_reply_walker($reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true)
{
    // Verify the reply ID
    $reply_id = bbp_get_reply_id($reply_id);
    // Reply was passed
    if (!empty($reply_id)) {
        // Get the topic ID if none was passed
        if (empty($topic_id)) {
            $topic_id = bbp_get_reply_topic_id($reply_id);
            // Make every effort to get topic id
            // https://bbpress.trac.wordpress.org/ticket/2529
            if (empty($topic_id) && current_filter() === 'bbp_deleted_reply') {
                $topic_id = get_post_field('post_parent', $reply_id);
            }
        }
        // Get the forum ID if none was passed
        if (empty($forum_id)) {
            $forum_id = bbp_get_reply_forum_id($reply_id);
        }
    }
    // Set the active_id based on topic_id/reply_id
    $active_id = empty($reply_id) ? $topic_id : $reply_id;
    // Setup ancestors array to walk up
    $ancestors = array_values(array_unique(array_merge(array($topic_id, $forum_id), (array) get_post_ancestors($topic_id))));
    // If we want a full refresh, unset any of the possibly passed variables
    if (true === $refresh) {
        $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
    }
    // Walk up ancestors
    if (!empty($ancestors)) {
        foreach ($ancestors as $ancestor) {
            // Reply meta relating to most recent reply
            if (bbp_is_reply($ancestor)) {
                // @todo - hierarchical replies
                // Topic meta relating to most recent reply
            } elseif (bbp_is_topic($ancestor)) {
                // Last reply and active ID's
                bbp_update_topic_last_reply_id($ancestor, $reply_id);
                bbp_update_topic_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $topic_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $topic_last_active_time = get_post_field('post_date', bbp_get_topic_last_active_id($ancestor));
                }
                // Update the topic last active time regardless of reply status.
                // See https://bbpress.trac.wordpress.org/ticket/2838
                bbp_update_topic_last_active_time($ancestor, $topic_last_active_time);
                // Counts
                bbp_update_topic_voice_count($ancestor);
                // Only update reply count if we're deleting a reply, or in the dashboard.
                if (in_array(current_filter(), array('bbp_deleted_reply', 'save_post'), true)) {
                    bbp_update_topic_reply_count($ancestor);
                    bbp_update_topic_reply_count_hidden($ancestor);
                }
                // Forum meta relating to most recent topic
            } elseif (bbp_is_forum($ancestor)) {
                // Last topic and reply ID's
                bbp_update_forum_last_topic_id($ancestor, $topic_id);
                bbp_update_forum_last_reply_id($ancestor, $reply_id);
                // Last Active
                bbp_update_forum_last_active_id($ancestor, $active_id);
                // Get the last active time if none was passed
                $forum_last_active_time = $last_active_time;
                if (empty($last_active_time)) {
                    $forum_last_active_time = get_post_field('post_date', bbp_get_forum_last_active_id($ancestor));
                }
                // Only update if reply is published
                if (bbp_is_reply_published($reply_id)) {
                    bbp_update_forum_last_active_time($ancestor, $forum_last_active_time);
                }
                // Counts
                // Only update reply count if we're deleting a reply, or in the dashboard.
                if (in_array(current_filter(), array('bbp_deleted_reply', 'save_post'), true)) {
                    bbp_update_forum_reply_count($ancestor);
                }
            }
        }
    }
}
Esempio n. 16
0
/**
 * Output the topics last active ID
 *
 * @since 2.0.0 bbPress (r2860)
 *
 * @param int $topic_id Optional. Forum id
 * @uses bbp_get_topic_last_active_id() To get the topic's last active id
 */
function bbp_topic_last_active_id($topic_id = 0)
{
    echo bbp_get_topic_last_active_id($topic_id);
}
Esempio n. 17
0
		<?php 
bbp_topic_freshness_link();
?>

		<?php 
do_action('bbp_theme_after_topic_freshness_link');
?>

		<p class="bbp-topic-meta">

			<?php 
do_action('bbp_theme_before_topic_freshness_author');
?>

			<span class="bbp-topic-freshness-author"><?php 
bbp_author_link(array('post_id' => bbp_get_topic_last_active_id(), 'type' => 'name'));
?>
</span>

			<?php 
do_action('bbp_theme_after_topic_freshness_author');
?>

		</p>
	</li>

</ul><!-- #bbp-topic-<?php 
bbp_topic_id();
?>
 -->
Esempio n. 18
0
 /**
  * @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);
 }