Example #1
0
 /**
  * @group canonical
  * @covers ::bbp_insert_topic
  */
 public function test_bbp_insert_topic()
 {
     $f = $this->factory->forum->create();
     $now = time();
     $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100);
     $t = $this->factory->topic->create(array('post_title' => 'Topic 1', 'post_content' => 'Content for Topic 1', 'post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f)));
     $r = $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Get the topic.
     $topic = bbp_get_topic($t);
     remove_all_filters('bbp_get_topic_content');
     // Topic post.
     $this->assertSame('Topic 1', bbp_get_topic_title($t));
     $this->assertSame('Content for Topic 1', bbp_get_topic_content($t));
     $this->assertSame('publish', bbp_get_topic_status($t));
     $this->assertSame($f, wp_get_post_parent_id($t));
     $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?topic=' . $topic->post_name, $topic->guid);
     // Topic meta.
     $this->assertSame($f, bbp_get_topic_forum_id($t));
     $this->assertSame(1, bbp_get_topic_reply_count($t, true));
     $this->assertSame(0, bbp_get_topic_reply_count_hidden($t, true));
     $this->assertSame(1, bbp_get_topic_voice_count($t, true));
     $this->assertSame($r, bbp_get_topic_last_reply_id($t));
     $this->assertSame($r, bbp_get_topic_last_active_id($t));
     $this->assertSame('4 days, 4 hours ago', bbp_get_topic_last_active_time($t));
 }
 /**
  * @covers ::bbp_update_topic_last_active_time
  */
 public function test_bbp_update_topic_last_active_time()
 {
     $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)));
     $r1_time_raw = get_post_field('post_date', $r1);
     $r1_time_formatted = bbp_get_time_since(bbp_convert_date($r1_time_raw));
     $time = bbp_update_topic_last_active_time($t, $r1_time_raw);
     $this->assertSame($r1_time_raw, $time);
     $time = bbp_get_topic_last_active_time($t);
     $this->assertSame($r1_time_formatted, $time);
     $r2 = $this->factory->reply->create_many(2, array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $r2_time_raw = get_post_field('post_date', $r2[1]);
     $r2_time_formatted = bbp_get_time_since(bbp_convert_date($r2_time_raw));
     bbp_update_topic_last_active_time($t);
     $time = bbp_get_topic_last_active_time($t);
     $this->assertSame($r2_time_formatted, $time);
 }
Example #3
0
 /**
  * @covers ::bbp_topic_last_active_time
  * @covers ::bbp_get_topic_last_active_time
  */
 public function test_bbp_get_topic_last_active_time()
 {
     $f = $this->factory->forum->create();
     $now = time();
     $post_date_topic = date('Y-m-d H:i:s', $now - 60 * 60 * 100);
     $post_date_reply = date('Y-m-d H:i:s', $now - 60 * 60 * 80);
     $topic_time = '4 days, 4 hours ago';
     $reply_time = '3 days, 8 hours ago';
     $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date_topic, 'topic_meta' => array('forum_id' => $f)));
     // Output.
     $this->expectOutputString($topic_time);
     bbp_topic_last_active_time($t);
     // Topic time.
     $datetime = bbp_get_topic_last_active_time($t);
     $this->assertSame($topic_time, $datetime);
     $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date_reply, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     // Reply time.
     $datetime = bbp_get_topic_last_active_time($t);
     $this->assertSame('3 days, 8 hours ago', $datetime);
 }
/**
 * this function changes the bbp freshness data (time since) into a last post date for forums
 * @return string Formatted date-time
 */
function change_freshness_forum()
{
    // Verify forum and get last active meta
    $forum_id = bbp_get_forum_id($forum_id);
    $last_active = get_post_meta($forum_id, '_bbp_last_active_time', true);
    if (empty($last_active)) {
        $reply_id = bbp_get_forum_last_reply_id($forum_id);
        if (!empty($reply_id)) {
            $last_active = get_post_field('post_date', $reply_id);
        } else {
            $topic_id = bbp_get_forum_last_topic_id($forum_id);
            if (!empty($topic_id)) {
                $last_active = bbp_get_topic_last_active_time($topic_id);
            }
        }
    }
    $last_active = bbp_convert_date($last_active);
    $date_format = get_option('date_format');
    $time_format = get_option('time_format');
    $date = date_i18n("{$date_format}", $last_active);
    $time = date_i18n("{$time_format}", $last_active);
    $active_time = sprintf(_x('%1$s, %2$s', 'date at time', 'bbp-last-post'), $date, $time);
    return $active_time;
}
Example #5
0
/**
 * Returns link to the most recent activity inside a topic, complete
 * with link attributes and content.
 *
 * @since 2.0.0 bbPress (r2625)
 *
 * @param int $topic_id Optional. Topic id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic_last_reply_url() To get the topic last reply url
 * @uses bbp_get_topic_last_reply_title() To get the reply title
 * @uses bbp_get_topic_last_active_time() To get the topic freshness
 * @uses apply_filters() Calls 'bbp_get_topic_freshness_link' with the
 *                        link and topic id
 * @return string Topic freshness link
 */
function bbp_get_topic_freshness_link($topic_id = 0)
{
    $topic_id = bbp_get_topic_id($topic_id);
    $link_url = bbp_get_topic_last_reply_url($topic_id);
    $title = bbp_get_topic_last_reply_title($topic_id);
    $time_since = bbp_get_topic_last_active_time($topic_id);
    if (!empty($time_since)) {
        $anchor = '<a href="' . esc_url($link_url) . '" title="' . esc_attr($title) . '">' . esc_html($time_since) . '</a>';
    } else {
        $anchor = esc_html__('No Replies', 'bbpress');
    }
    return apply_filters('bbp_get_topic_freshness_link', $anchor, $topic_id, $time_since, $link_url, $title);
}
Example #6
0
/**
 * Return the forums last update date/time (aka freshness)
 *
 * @since bbPress (r2464)
 *
 * @param int $forum_id Optional. Forum id
 * @uses bbp_get_forum_id() To get the forum id
 * @uses get_post_meta() To retrieve forum last active meta
 * @uses bbp_get_forum_last_reply_id() To get forum's last reply id
 * @uses get_post_field() To get the post date of the reply
 * @uses bbp_get_forum_last_topic_id() To get forum's last topic id
 * @uses bbp_get_topic_last_active_time() To get time when the topic was
 *                                    last active
 * @uses bbp_convert_date() To convert the date
 * @uses bbp_get_time_since() To get time in since format
 * @uses apply_filters() Calls 'bbp_get_forum_last_active' with last
 *                        active time and forum id
 * @return string Forum last update date/time (freshness)
 */
function bbp_get_forum_last_active_time($forum_id = 0)
{
    $forum_id = bbp_get_forum_id($forum_id);
    $last_active = get_post_meta($forum_id, '_bbp_last_active_time', true);
    if (empty($last_active)) {
        $reply_id = bbp_get_forum_last_reply_id($forum_id);
        if (!empty($reply_id)) {
            $last_active = get_post_field('post_date', $reply_id);
        } else {
            $topic_id = bbp_get_forum_last_topic_id($forum_id);
            if (!empty($topic_id)) {
                $last_active = bbp_get_topic_last_active_time($topic_id);
            }
        }
    }
    $last_active = !empty($last_active) ? bbp_get_time_since(bbp_convert_date($last_active)) : '';
    return apply_filters('bbp_get_forum_last_active', $last_active, $forum_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;
}
Example #8
0
 /**
  * Print extra columns for the topics page
  *
  * @since 2.0.0 bbPress (r2485)
  *
  * @param string $column Column
  * @param int $topic_id Topic id
  * @uses bbp_get_topic_forum_id() To get the forum id of the topic
  * @uses bbp_forum_title() To output the topic's forum title
  * @uses apply_filters() Calls 'topic_forum_row_actions' with an array
  *                        of topic forum actions
  * @uses bbp_get_forum_permalink() To get the forum permalink
  * @uses admin_url() To get the admin url of post.php
  * @uses bbp_topic_reply_count() To output the topic reply count
  * @uses bbp_topic_voice_count() To output the topic voice count
  * @uses bbp_topic_author_display_name() To output the topic author name
  * @uses get_the_date() Get the topic creation date
  * @uses get_the_time() Get the topic creation time
  * @uses esc_attr() To sanitize the topic creation time
  * @uses bbp_get_topic_last_active_time() To get the time when the topic was
  *                                    last active
  * @uses do_action() Calls 'bbp_admin_topics_column_data' with the
  *                    column and topic id
  */
 public function column_data($column, $topic_id)
 {
     if ($this->bail()) {
         return;
     }
     // Get topic forum ID
     $forum_id = bbp_get_topic_forum_id($topic_id);
     // Populate column data
     switch ($column) {
         // Forum
         case 'bbp_topic_forum':
             // Output forum name
             if (!empty($forum_id)) {
                 // Forum Title
                 $forum_title = bbp_get_forum_title($forum_id);
                 if (empty($forum_title)) {
                     $forum_title = esc_html__('No Forum', 'bbpress');
                 }
                 // Output the title
                 echo $forum_title;
             } else {
                 esc_html_e('&mdash; No forum &mdash;', 'bbpress');
             }
             break;
             // Reply Count
         // Reply Count
         case 'bbp_topic_reply_count':
             bbp_topic_reply_count($topic_id);
             break;
             // Reply Count
         // Reply Count
         case 'bbp_topic_voice_count':
             bbp_topic_voice_count($topic_id);
             break;
             // Author
         // Author
         case 'bbp_topic_author':
             bbp_topic_author_display_name($topic_id);
             break;
             // Freshness
         // Freshness
         case 'bbp_topic_created':
             printf('%1$s <br /> %2$s', get_the_date(), esc_attr(get_the_time()));
             break;
             // Freshness
         // Freshness
         case 'bbp_topic_freshness':
             $last_active = bbp_get_topic_last_active_time($topic_id, false);
             if (!empty($last_active)) {
                 echo esc_html($last_active);
             } else {
                 esc_html_e('No Replies', 'bbpress');
                 // This should never happen
             }
             break;
             // Do an action for anything else
         // Do an action for anything else
         default:
             do_action('bbp_admin_topics_column_data', $column, $topic_id);
             break;
     }
 }
Example #9
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);
 }
Example #10
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));
 }
Example #11
0
    public function single_row($level = 0)
    {
        global $mode, $post;
        static $alternate;
        $edit_link = '#';
        get_edit_post_link($post->ID);
        $title = get_the_title();
        $post_type_object = get_post_type_object($post->post_type);
        $can_edit_post = false;
        // current_user_can( 'edit_post', $post->ID );
        $alternate = 'alternate' == $alternate ? '' : 'alternate';
        $classes = array($alternate, 'level-0');
        ?>
		<tr id="topic-row-<?php 
        echo $post->ID;
        ?>
" <?php 
        bbp_topic_class($post->ID, $classes);
        ?>
>
	<?php 
        $forum_id = bbp_get_topic_forum_id($post->ID);
        $topic_id = $post->ID;
        list($columns, $hidden) = $this->get_column_info();
        foreach ($columns as $column_name => $column_display_name) {
            $class = "class=\"column-{$column_name}\"";
            $style = '';
            if (in_array($column_name, $hidden)) {
                $style = ' style="display:none;"';
            }
            $attributes = "{$class}{$style}";
            switch ($column_name) {
                case 'no':
                    ?>
			<td <?php 
                    echo $attributes;
                    ?>
>
			<?php 
                    bbp_the_no();
                    ?>
			</td>
			<?php 
                    break;
                case 'title':
                    $pad = str_repeat('&#8212; ', $level);
                    $title = '<a class="bbp-topic-permalink row-title" href="' . bbp_get_topic_permalink() . '">' . $title . '</a>';
                    echo "<td {$attributes}>";
                    do_action('bbp_theme_before_topic_title');
                    echo $pad . $title;
                    do_action('bbp_theme_after_topic_title');
                    echo '</td>';
                    break;
                    // Forum
                // Forum
                case 'forum':
                    // Output forum name
                    if (!empty($forum_id)) {
                        // Forum Title
                        $forum_title = bbp_get_forum_title($forum_id);
                        if (empty($forum_title)) {
                            $forum_title = esc_html__('No Forum', 'bbpress');
                        }
                        // Output the title
                        echo $forum_title;
                    } else {
                        esc_html_e('(No Forum)', 'bbpress');
                    }
                    break;
                    // Reply Count
                // Reply Count
                case 'reply_count':
                    echo "<td {$attributes}>";
                    echo '<div class="post-com-count-wrapper"><a class="post-com-count" href="#"><span class="comment-count">';
                    bbp_topic_reply_count($topic_id);
                    echo '</span></a></div>';
                    echo "</td>";
                    break;
                    // Reply Count
                // Reply Count
                case 'voice_count':
                    echo "<td {$attributes}>";
                    bbp_topic_voice_count($topic_id);
                    break;
                    // Author
                // Author
                case 'author':
                    echo "<td {$attributes}>";
                    bbp_topic_author_display_name($topic_id);
                    echo "</td>";
                    break;
                    // Freshness
                // Freshness
                case 'date':
                    echo "<td {$attributes}>";
                    echo get_the_date('Y.m.d');
                    echo "</td>";
                    break;
                    // Freshness
                // Freshness
                case 'freshness':
                    echo "<td {$attributes}>";
                    $last_active = bbp_get_topic_last_active_time($topic_id, false);
                    if (!empty($last_active)) {
                        echo esc_html($last_active);
                    } else {
                        esc_html_e('No Replies', 'bbpress');
                        // This should never happen
                    }
                    echo "</td>";
                    break;
                default:
                    ?>
			<td <?php 
                    echo $attributes;
                    ?>
><?php 
                    do_action("bbpkr_{$post->post_type}_list_custom_column", $column_name, $post->ID);
                    ?>
</td>
			<?php 
                    break;
            }
        }
        ?>
		</tr>
	<?php 
    }
Example #12
0
function firmasite_social_bbp_get_topic_freshness_link($topic_id = 0)
{
    $topic_id = bbp_get_topic_id($topic_id);
    $link_url = bbp_get_topic_last_reply_url($topic_id);
    $title = bbp_get_topic_last_reply_title($topic_id);
    $time_since = bbp_get_topic_last_active_time($topic_id);
    if (!empty($time_since)) {
        $anchor = '<a href="' . $link_url . '" data-toggle="popover" data-rel="popover" data-placement="left" data-trigger="hover" data-html="true" data-original-title="' . __('Freshness', 'firmasite') . '" data-content="' . esc_attr($time_since) . '"><i class="icon-time"></i></a>';
    } else {
        $anchor = __('No Replies', 'firmasite');
    }
    return apply_filters('bbp_get_topic_freshness_link', $anchor, $topic_id);
}