/** * @group canonical * @covers ::bbp_insert_forum */ public function test_bbp_insert_forum() { $f = $this->factory->forum->create(array('post_title' => 'Forum 1', 'post_content' => 'Content of Forum 1')); $now = time(); $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100); $t = $this->factory->topic->create(array('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 forum. $forum = bbp_get_forum($f); // Forum post. $this->assertSame('Forum 1', bbp_get_forum_title($f)); $this->assertSame('Content of Forum 1', bbp_get_forum_content($f)); $this->assertSame('open', bbp_get_forum_status($f)); $this->assertSame('forum', bbp_get_forum_type($f)); $this->assertTrue(bbp_is_forum_public($f)); $this->assertSame(0, bbp_get_forum_parent_id($f)); $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?forum=' . $forum->post_name, $forum->guid); // Forum meta. $this->assertSame(0, bbp_get_forum_subforum_count($f, true)); $this->assertSame(1, bbp_get_forum_topic_count($f, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($f, true, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($f, true)); $this->assertSame(1, bbp_get_forum_reply_count($f, false, true)); $this->assertSame(1, bbp_get_forum_reply_count($f, true, true)); $this->assertSame(2, bbp_get_forum_post_count($f, false, true)); $this->assertSame(2, bbp_get_forum_post_count($f, true, true)); $this->assertSame($t, bbp_get_forum_last_topic_id($f)); $this->assertSame($r, bbp_get_forum_last_reply_id($f)); $this->assertSame($r, bbp_get_forum_last_active_id($f)); $this->assertSame('4 days, 4 hours ago', bbp_get_forum_last_active_time($f)); }
/** * Returns link to the most recent activity inside a forum. * * Returns a complete link with attributes and content. * * @since bbPress (r2625) * * @param int $forum_id Optional. Forum id * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_forum_last_active_id() To get the forum last active id * @uses bbp_get_forum_last_reply_id() To get the forum last reply id * @uses bbp_get_forum_last_topic_id() To get the forum last topic id * @uses bbp_get_forum_last_reply_url() To get the forum last reply url * @uses bbp_get_forum_last_reply_title() To get the forum last reply * title * @uses bbp_get_forum_last_topic_permalink() To get the forum last * topic permalink * @uses bbp_get_forum_last_topic_title() To get the forum last topic * title * @uses bbp_get_forum_last_active_time() To get the time when the forum * was last active * @uses apply_filters() Calls 'bbp_get_forum_freshness_link' with the * link and forum id */ function bbp_get_forum_freshness_link($forum_id = 0) { $forum_id = bbp_get_forum_id($forum_id); $active_id = bbp_get_forum_last_active_id($forum_id); if (empty($active_id)) { $active_id = bbp_get_forum_last_reply_id($forum_id); } if (empty($active_id)) { $active_id = bbp_get_forum_last_topic_id($forum_id); } if (bbp_is_topic($active_id)) { $link_url = bbp_get_forum_last_topic_permalink($forum_id); $title = bbp_get_forum_last_topic_title($forum_id); } elseif (bbp_is_reply($active_id)) { $link_url = bbp_get_forum_last_reply_url($forum_id); $title = bbp_get_forum_last_reply_title($forum_id); } $time_since = bbp_get_forum_last_active_time($forum_id); if (!empty($time_since) && !empty($link_url)) { $anchor = '<a href="' . $link_url . '" title="' . esc_attr($title) . '">' . $time_since . '</a>'; } else { $anchor = __('No Topics', 'bbpress'); } return apply_filters('bbp_get_forum_freshness_link', $anchor, $forum_id); }
/** * Print extra columns for the forums page * * @since bbPress (r2485) * * @param string $column Column * @param int $forum_id Forum id * @uses bbp_forum_topic_count() To output the forum topic count * @uses bbp_forum_reply_count() To output the forum reply count * @uses get_the_date() Get the forum creation date * @uses get_the_time() Get the forum creation time * @uses esc_attr() To sanitize the forum creation time * @uses bbp_get_forum_last_active_time() To get the time when the forum was * last active * @uses do_action() Calls 'bbp_admin_forums_column_data' with the * column and forum id */ public function column_data($column, $forum_id) { if ($this->bail()) { return; } switch ($column) { case 'bbp_forum_topic_count': bbp_forum_topic_count($forum_id); break; case 'bbp_forum_reply_count': bbp_forum_reply_count($forum_id); break; case 'bbp_forum_created': printf(__('%1$s <br /> %2$s', 'bbpress'), get_the_date(), esc_attr(get_the_time())); break; case 'bbp_forum_freshness': $last_active = bbp_get_forum_last_active_time($forum_id, false); if (!empty($last_active)) { echo $last_active; } else { _e('No Topics', 'bbpress'); } break; default: do_action('bbp_admin_forums_column_data', $column, $forum_id); break; } }
echo bbp_get_topic_last_reply_title(bbp_get_forum_last_active_id()); ?> </a> </div> <div class="last-posted-topic-user">av <span class="bbp-author-avatar"><?php echo get_avatar(bbp_get_forum_last_reply_author_id(), '14'); ?> </span> <?php echo bbp_get_user_profile_link(bbp_get_forum_last_reply_author_id()); ?> </div> <div class="last-posted-topic-time"> <?php echo bbp_get_forum_last_active_time(); ?> </div> </li> </div> <?php do_action('bbp_theme_before_forum_sub_forums'); ?> <?php BBP_Default::epicwebs_bbp_list_forums(array('before' => '<li class="forum-list">', 'after' => '</li>', 'link_before' => '', 'link_after' => '', 'count_before' => '<div class="topic-reply-counts">Ämnen: ', 'count_after' => '</div>', 'count_sep' => '</div><div class="topic-reply-counts">Inlägg: ', 'separator' => '', 'forum_id' => '', 'show_topic_count' => true, 'show_reply_count' => true, 'show_freshness_link' => true)); ?> <?php
/** * @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 st_get_last_poster_block($subforum_id = "") { if (!empty($subforum_id)) { // Main forum display with sub forums $st_forum_topic_count_two = bbp_get_forum_topic_count($subforum_id); if ($st_forum_topic_count_two == 0) { $output = "<div class='last-posted-topic-title no-topics'>"; $output .= "No Topics"; } else { $output = "<div class='last-posted-topic-title'>"; // Get and crop title lenth if needed $st_topic_last_reply_title = bbp_get_topic_last_reply_title(bbp_get_forum_last_active_id($subforum_id)); $st_topic_last_reply_title_print = strlen($st_topic_last_reply_title) > 50 ? substr($st_topic_last_reply_title, 0, 53) . '…' : $st_topic_last_reply_title; $output .= "<a href='" . bbp_get_forum_last_topic_permalink($subforum_id) . "'>" . $st_topic_last_reply_title_print . "</a>"; $output .= "</div>"; $output .= "<div class='last-posted-topic-time'>"; $output .= bbp_get_forum_last_active_time($subforum_id); } $output .= "</div>"; } else { // forum category display (no sub forums list) $st_forum_topic_count = bbp_get_forum_topic_count(); if ($st_forum_topic_count == 0) { $output = "<div class='last-posted-topic-title no-topics'>"; $output .= "No Topics"; } else { $output = "<div class='last-posted-topic-title'>"; // Get and crop title lenth if needed $st_topic_last_reply_title = bbp_get_topic_last_reply_title(bbp_get_forum_last_active_id($subforum_id)); $st_topic_last_reply_title_print = strlen($st_topic_last_reply_title) > 50 ? substr($st_topic_last_reply_title, 0, 53) . '…' : $st_topic_last_reply_title; $output .= "<a href='" . bbp_get_forum_last_topic_permalink() . "'>" . $st_topic_last_reply_title_print . "</a>"; $output .= "</div>"; $output .= "<div class='last-posted-topic-time'>"; $output .= bbp_get_forum_last_active_time(); } $output .= "</div>"; } return $output; }
/** * @covers ::bbp_update_forum_last_active_time */ public function test_bbp_update_forum_last_active_time() { $f1 = $this->factory->forum->create(); $f2 = $this->factory->forum->create(array('post_parent' => $f1)); $t1 = $this->factory->topic->create(array('post_parent' => $f1, 'topic_meta' => array('forum_id' => $f1))); $r1 = $this->factory->reply->create(array('post_parent' => $t1, 'reply_meta' => array('forum_id' => $f1, 'topic_id' => $t1))); $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_forum_last_active_time($f1, $r1_time_raw); $this->assertSame($r1_time_raw, $time); $time = bbp_get_forum_last_active_time($f1); $this->assertSame($r1_time_formatted, $time); $t2 = $this->factory->topic->create(array('post_parent' => $f2, 'topic_meta' => array('forum_id' => $f2))); $r2 = $this->factory->reply->create(array('post_parent' => $t2, 'reply_meta' => array('forum_id' => $f2, 'topic_id' => $t2))); $r2_time_raw = get_post_field('post_date', $r2); $r2_time_formatted = bbp_get_time_since(bbp_convert_date($r2_time_raw)); bbp_update_forum_last_active_time($f2); $time = bbp_get_forum_last_active_time($f2); $this->assertSame($r2_time_formatted, $time); bbp_update_forum_last_active_time($f1); $time = bbp_get_forum_last_active_time($f1); $this->assertSame($r2_time_formatted, $time); }
public function epicwebs_get_last_poster_block($subforum_id = "") { if (!empty($subforum_id)) { // Main forum display with sub forums $output = "<div class='last-posted-topic-title'>"; $output .= "<a href='" . bbp_get_forum_last_topic_permalink($subforum_id) . "'>" . bbp_get_topic_last_reply_title(bbp_get_forum_last_active_id($subforum_id)) . "</a>"; $output .= "</div>"; $output .= "<div class='last-posted-topic-user'>av "; $author_id = bbp_get_forum_last_reply_author_id($subforum_id); $output .= "<span class=\"bbp-author-avatar\">" . get_avatar($author_id, '14') . " </span>"; $output .= bbp_get_user_profile_link($author_id); $output .= "</div>"; $output .= "<div class='last-posted-topic-time'>"; $output .= bbp_get_forum_last_active_time($subforum_id); $output .= "</div>"; } else { // forum category display (no sub forums list) $output = "<div class='last-posted-topic-title'>"; $output .= "<a href='" . bbp_get_forum_last_topic_permalink() . "'>" . bbp_get_topic_last_reply_title(bbp_get_forum_last_active_id()) . "</a>"; $output .= "</div>"; $output .= "<div class='last-posted-topic-user'>av "; $output .= "<span class=\"bbp-author-avatar\">" . get_avatar(bbp_get_forum_last_reply_author_id(), '14') . " </span>"; $output .= bbp_get_user_profile_link(bbp_get_forum_last_reply_author_id()); $output .= "</div>"; $output .= "<div class='last-posted-topic-time'>"; $output .= bbp_get_forum_last_active_time(); $output .= "</div>"; } return $output; }
function wplms_bbpress_forum_freshness($anchor, $forum_id, $time_since, $link_url, $title, $active_id) { if (!empty($link_url)) { $time_since = bbp_get_forum_last_active_time($forum_id); $anchor = '<a href="' . $link_url . '">' . $title . '<span>' . $time_since . '</span></a>'; } return $anchor; }
/** * Print extra columns for the forums page * * @since 2.0.0 bbPress (r2485) * * @param string $column Column * @param int $forum_id Forum id * @uses bbp_forum_topic_count() To output the forum topic count * @uses bbp_forum_reply_count() To output the forum reply count * @uses get_the_date() Get the forum creation date * @uses get_the_time() Get the forum creation time * @uses esc_attr() To sanitize the forum creation time * @uses bbp_get_forum_last_active_time() To get the time when the forum was * last active * @uses do_action() Calls 'bbp_admin_forums_column_data' with the * column and forum id */ public function column_data($column, $forum_id) { if ($this->bail()) { return; } switch ($column) { case 'bbp_forum_topic_count': bbp_forum_topic_count($forum_id); break; case 'bbp_forum_reply_count': bbp_forum_reply_count($forum_id); break; case 'bbp_forum_mods': bbp_forum_mod_list($forum_id, array('before' => '', 'after' => '', 'none' => esc_html__('—', 'bbpress'))); break; case 'bbp_forum_created': printf('%1$s <br /> %2$s', get_the_date(), esc_attr(get_the_time())); break; case 'bbp_forum_freshness': $last_active = bbp_get_forum_last_active_time($forum_id, false); if (!empty($last_active)) { echo esc_html($last_active); } else { esc_html_e('No Topics', 'bbpress'); } break; default: do_action('bbp_admin_forums_column_data', $column, $forum_id); break; } }
function custom_freshness_link($forum_id = 0) { global $rpg_settingsf; $forum_id = bbp_get_forum_id($forum_id); $active_id = bbp_get_forum_last_active_id($forum_id); $link_url = $title = ''; $forum_title = bbp_get_forum_title($forum_id); if (empty($active_id)) { $active_id = bbp_get_forum_last_reply_id($forum_id); } if (empty($active_id)) { $active_id = bbp_get_forum_last_topic_id($forum_id); } if (bbp_is_topic($active_id)) { $link_url = bbp_get_forum_last_topic_permalink($forum_id); //$link_id added to get post_id and type to allow for later check $link_id = bbp_get_forum_last_topic_id($forum_id); $check = "topic"; $title = bbp_get_forum_last_topic_title($forum_id); $forum_id_last_active = bbp_get_topic_forum_id($active_id); } elseif (bbp_is_reply($active_id)) { $link_url = bbp_get_forum_last_reply_url($forum_id); //$link-id added to get post-id and type to allow for later check $link_id = bbp_get_forum_last_reply_id($forum_id); $check = "reply"; $title = bbp_get_forum_last_reply_title($forum_id); $forum_id_last_active = bbp_get_reply_forum_id($active_id); } $time_since = bbp_get_forum_last_active_time($forum_id); if (!empty($time_since) && !empty($link_url)) { //ADDITIONAL CODE to original bbp_get_forum_freshness_link function //test if user can see this post, and post link if they can $user_id = wp_get_current_user()->ID; //get the forum id for the post - that's the forum ID against which we check to see if it is in a group - no idea what forum group the stuff above produces, suspect post id of when last changed. $forum_id_check = private_groups_get_forum_id_from_post_id($link_id, $check); //now we can check if the user can view this, and if it's not private if (private_groups_can_user_view_post($user_id, $forum_id_check) && !bbp_is_forum_private($forum_id_last_active)) { $anchor = '<a href="' . esc_url($link_url) . '" title="' . esc_attr($title) . '">' . esc_html($time_since) . '</a>'; } elseif (private_groups_can_user_view_post($user_id, $forum_id_check) && bbp_is_forum_private($forum_id_last_active) && current_user_can('read_private_forums')) { $anchor = '<a href="' . esc_url($link_url) . '" title="' . esc_attr($title) . '">' . esc_html($time_since) . '</a>'; } else { //set up which link to send them to if (!is_user_logged_in()) { if ($rpg_settingsf['redirect_page2']) { $link = $rpg_settingsf['redirect_page2']; } else { $link = "/wp-login"; } } else { if ($rpg_settingsf['redirect_page1']) { $link = $rpg_settingsf['redirect_page1']; } else { $link = '/404'; } } //now see if there is a freshness message if ($rpg_settingsf['set_freshness_message']) { $title = $rpg_settingsf['freshness_message']; //and set up anchor $anchor = '<a href="' . esc_url($link) . '">' . $title . '</a>'; } else { $anchor = '<a href="' . esc_url($link) . '">' . esc_html($time_since) . '</a>'; } } } else { $anchor = esc_html__('No Topics', 'bbpress'); } return $anchor; }
<?php /** * Search Loop - Single Forum * * @package bbPress * @subpackage Theme */ ?> <div class="bbp-forum-header"> <div class="bbp-meta"> <span class="bbp-forum-post-date"><?php printf(__('Last updated %s', 'wpdance'), bbp_get_forum_last_active_time()); ?> </span> <a href="<?php bbp_forum_permalink(); ?> " class="bbp-forum-permalink">#<?php bbp_forum_id(); ?> </a> </div><!-- .bbp-meta --> <div class="bbp-forum-title">
<?php /** * Search Loop - Single Forum * * @package bbPress * @subpackage Theme */ ?> <div class="bbp-forum-header"> <div class="bbp-meta"> <span class="bbp-forum-post-date"><?php printf(esc_html__('Last updated %s', 'monsoon'), bbp_get_forum_last_active_time()); ?> </span> <a href="<?php bbp_forum_permalink(); ?> " class="bbp-forum-permalink">#<?php bbp_forum_id(); ?> </a> </div><!-- .bbp-meta --> <div class="bbp-forum-title">
<?php /* for PRO users! - * * Search Loop - Single Forum * * @package bbPress * @subpackage Dante */ ?> <div class="bbp-forum-header"> <div class="bbp-meta"> <span class="bbp-forum-post-date"><?php printf(__('Last updated %s', 'bbpress'), bbp_get_forum_last_active_time()); ?> </span> <a href="<?php bbp_forum_permalink(); ?> " class="bbp-forum-permalink">#<?php bbp_forum_id(); ?> </a> </div><!-- .bbp-meta --> <div class="bbp-forum-title">
/** * @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_forum_last_active_time * @covers ::bbp_get_forum_last_active_time */ public function test_bbp_get_forum_last_active_time() { $c = $this->factory->forum->create(array('forum_meta' => array('forum_type' => 'category', 'status' => 'open'))); $f = $this->factory->forum->create(array('post_parent' => $c, 'forum_meta' => array('forum_id' => $c, 'forum_type' => 'forum', 'status' => 'open'))); $now = time(); $post_date = date('Y-m-d H:i:s', $now - 60 * 60 * 100); // Get the forums last active time. $last_time = bbp_get_forum_last_active_time($f); $this->assertSame('', $last_time); // Get the categories last active time. $last_time = bbp_get_forum_last_active_time($c); $this->assertSame('', $last_time); $t = $this->factory->topic->create(array('post_parent' => $f, 'post_date' => $post_date, 'topic_meta' => array('forum_id' => $f))); bbp_update_forum_last_active_time($f); // Get the forums last active time. $last_time = bbp_get_forum_last_active_time($f); $this->assertSame('4 days, 4 hours ago', $last_time); // Get the categories last active time. $last_time = bbp_get_forum_last_active_time($c); $this->assertSame('4 days, 4 hours ago', $last_time); $this->factory->reply->create(array('post_parent' => $t, 'post_date' => $post_date, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); bbp_update_forum_last_active_time($f); // Get the forums last active time. $last_time = bbp_get_forum_last_active_time($f); $this->assertSame('4 days, 4 hours ago', $last_time); // Get the categories last active time. $last_time = bbp_get_forum_last_active_time($c); $this->assertSame('4 days, 4 hours ago', $last_time); }
function firmasite_social_bbp_get_forum_freshness_link($forum_id = 0) { $forum_id = bbp_get_forum_id($forum_id); $active_id = bbp_get_forum_last_active_id($forum_id); if (empty($active_id)) { $active_id = bbp_get_forum_last_reply_id($forum_id); } if (empty($active_id)) { $active_id = bbp_get_forum_last_topic_id($forum_id); } if (bbp_is_topic($active_id)) { $link_url = bbp_get_forum_last_topic_permalink($forum_id); $title = bbp_get_forum_last_topic_title($forum_id); } elseif (bbp_is_reply($active_id)) { $link_url = bbp_get_forum_last_reply_url($forum_id); $title = bbp_get_forum_last_reply_title($forum_id); } $time_since = bbp_get_forum_last_active_time($forum_id); if (!empty($time_since) && !empty($link_url)) { $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> ' . __('Freshness', 'firmasite') . ':'; } else { $anchor = __('No Topics', 'firmasite'); } return apply_filters('bbp_get_forum_freshness_link', $anchor, $forum_id); }