/** * @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)); }
/** * @covers ::bbp_update_forum_last_reply_id */ public function test_bbp_update_forum_last_reply_id() { $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))); $t2 = $this->factory->topic->create(array('post_parent' => $f2, 'topic_meta' => array('forum_id' => $f2))); $r1 = $this->factory->reply->create(array('post_parent' => $t1, 'reply_meta' => array('forum_id' => $f1, 'topic_id' => $t1))); $id = bbp_update_forum_last_reply_id($f1, $r1); $this->assertSame($r1, $id); $id = bbp_get_forum_last_reply_id($f1); $this->assertSame($r1, $id); $r2 = $this->factory->reply->create(array('post_parent' => $t2, 'reply_meta' => array('forum_id' => $f2, 'topic_id' => $t2))); bbp_update_forum_last_reply_id($f2); $id = bbp_get_forum_last_reply_id($f2); $this->assertSame($r2, $id); bbp_update_forum_last_reply_id($f1); $id = bbp_get_forum_last_reply_id($f1); $this->assertSame($r2, $id); }
/** * @covers ::bbp_forum_query_last_reply_id */ public function test_bbp_forum_query_last_reply_id() { $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'))); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Get the forums last reply id. $query_last_reply_f = bbp_forum_query_last_reply_id($f); $this->assertSame($query_last_reply_f, bbp_get_forum_last_reply_id($f)); // Get the categories last reply id. $query_last_reply_c = bbp_forum_query_last_reply_id($c); $this->assertSame($query_last_reply_c, bbp_get_forum_last_reply_id($c)); $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Get the forums last reply id. $query_last_reply_f = bbp_forum_query_last_reply_id($f); $this->assertSame($query_last_reply_f, bbp_get_forum_last_reply_id($f)); // Get the categories last reply id. $query_last_reply_c = bbp_forum_query_last_reply_id($c); $this->assertSame($query_last_reply_c, bbp_get_forum_last_reply_id($c)); }
/** * 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; }
/** * @covers ::bbp_forum_last_topic_id * @covers ::bbp_get_forum_last_topic_id * @covers ::bbp_forum_last_reply_id * @covers ::bbp_get_forum_last_reply_id * @covers ::bbp_topic_last_reply_id * @covers ::bbp_get_topic_last_reply_id */ public function test_bbp_get_forum_and_topic_last_topic_id_and_last_reply_id() { $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'))); // Get the forums last topic id _bbp_last_topic_id. $this->assertSame(0, bbp_get_forum_last_topic_id($f)); // Get the category last topic id _bbp_last_topic_id. $this->assertSame(0, bbp_get_forum_last_topic_id($c)); // Get the forums last reply id _bbp_last_reply_id. $this->assertSame(0, bbp_get_forum_last_reply_id($f)); // Get the category last reply id _bbp_last_reply_id. $this->assertSame(0, bbp_get_forum_last_reply_id($c)); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); // Get the forums last topic id _bbp_last_topic_id. $this->assertSame($t, bbp_get_forum_last_topic_id($f)); // Get the category last topic id _bbp_last_topic_id. $this->assertSame($t, bbp_get_forum_last_topic_id($c)); // Create another reply. $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Get the forums last reply id _bbp_last_reply_id. $this->assertSame($r, bbp_get_forum_last_reply_id($f)); // Get the category last reply id _bbp_last_reply_id. $this->assertSame($r, bbp_get_forum_last_reply_id($c)); // Get the topics last reply id _bbp_last_reply_id. $this->assertSame($r, bbp_get_topic_last_reply_id($t)); }
/** * @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); }
/** * Return author ID of last reply of forum * * @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_reply_author_id() To get the forum's last * reply's author id * @uses bbp_get_reply_author_id() To get the reply's author id * @uses apply_filters() Calls 'bbp_get_forum_last_reply_author_id' with * the author id and forum id * @return int Forum's last reply author id */ function bbp_get_forum_last_reply_author_id($forum_id = 0) { $forum_id = bbp_get_forum_id($forum_id); $author_id = bbp_get_reply_author_id(bbp_get_forum_last_reply_id($forum_id)); return apply_filters('bbp_get_forum_last_reply_author_id', $author_id, $forum_id); }
/** * @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); }
/** * @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)); }
</li> <li class="bbp-forum-freshness"> <div class="author-avatar"> <?php bbp_reply_author_avatar(bbp_get_forum_last_reply_id(), 50); ?> </div> <div class="topic-desc"> <?php do_action('bbp_theme_before_topic_freshness_author'); ?> <span class="bbp-topic-freshness-author"><?php echo bbp_get_reply_author_link(bbp_get_forum_last_reply_id(), 50); ?> </span> <?php do_action('bbp_theme_after_topic_freshness_author'); ?> <?php do_action('bbp_theme_before_topic_freshness_link'); ?> <p><?php bbp_forum_freshness_link(); ?> </p>
/** * Display nested subforums with a hierarchical structure using their parent category * @version 2.0 */ function apoc_loop_subforums() { // Exclude private forums $private = apoc_private_forum_ids(); // Check for subforums $subs = bbp_forum_get_subforums(array('post__not_in' => $private)); if (empty($subs)) { return; } // Buffer output ob_start(); // Print a header ?> <header class="forum-header"> <div class="forum-content"><h2><?php bbp_forum_title(); ?> </h2></div> <div class="forum-count">Topics</div> <div class="forum-freshness">Latest Post</div> </header> <ol class="forums category <?php bbp_forum_status(); ?> "><?php // Loop over forums foreach ($subs as $count => $sub) { // Get forum details $sub_id = $sub->ID; $title = $sub->post_title; $desc = $sub->post_content; $permalink = bbp_get_forum_permalink($sub_id); // Get topic counts $topics = bbp_get_forum_topic_count($sub_id, false); // Get the most recent reply and its topic $reply_id = bbp_get_forum_last_reply_id($sub_id); $topic_id = bbp_is_reply($reply_id) ? bbp_get_reply_topic_id($reply_id) : $reply_id; $topic_title = bbp_get_topic_title($topic_id); $link = bbp_get_reply_url($reply_id); // Get the author avatar $user_id = bbp_get_reply_author_id($reply_id); $avatar = apoc_get_avatar(array('user_id' => $user_id, 'link' => true, 'size' => 50)); // Toggle html class $class = $count % 2 ? 'odd' : 'even'; // Print output ?> <li id="forum-<?php echo $sub_id; ?> " class="forum <?php echo $class; ?> "> <div class="forum-content"> <h3 class="forum-title"><a href="<?php echo $permalink; ?> " title="Browse <?php echo $title; ?> "><?php echo $title; ?> </a></h3> <p class="forum-description"><?php echo $desc; ?> </p> </div> <div class="forum-count"> <?php echo $topics; ?> </div> <div class="forum-freshness"> <?php echo $avatar; ?> <div class="freshest-meta"> <a class="freshest-title" href="<?php echo $link; ?> " title="<?php echo $topic_title; ?> "><?php echo $topic_title; ?> </a> <span class="freshest-author">By <?php bbp_author_link(array('post_id' => $reply_id, 'type' => 'name')); ?> </span> <span class="freshest-time"><?php bbp_topic_last_active_time($topic_id); ?> </span> </div> </div> </li> <?php } ?> </ol> <?php // Retrieve from buffer $output = ob_get_contents(); ob_end_clean(); echo $output; }
ob_start(); // Loop over forums foreach ( $subs as $count => $sub ) : // Get forum details $sub_id = $sub->ID; $title = $sub->post_title; $desc = $sub->post_content; $permalink = bbp_get_forum_permalink( $sub_id ); // Get topic counts $topics = bbp_get_forum_topic_count( $sub_id , true ); // Get the most recent reply and its topic $reply_id = bbp_get_forum_last_reply_id( $sub_id ); $topic_id = bbp_is_reply( $reply_id ) ? bbp_get_reply_topic_id( $reply_id ) : $reply_id; $topic_title = bbp_get_topic_title( $topic_id ); $link = bbp_get_reply_url( $reply_id ); // Get the author $user_id = bbp_get_reply_author_id( $reply_id ); // Toggle html class?> <tr> <td><a class="bbp-forum-title" href="<?php echo $permalink; ?>"><?php echo $title; ?></a></td> <td><?php echo $topics; ?></td> <td><?php bbp_forum_post_count( $sub_id, true ); ?></td> <td><p class="bbp-topic-meta">
<li class="bbp-topic-voice-count"><?php bbp_topic_voice_count(); ?> </li> <li class="bbp-topic-reply-count"><?php bbp_show_lead_topic() ? bbp_topic_reply_count() : bbp_topic_post_count(); ?> </li> <li class="bbp-topic-freshness"> <div class="author-avatar"> <?php $last_reply_avatar = bbp_get_reply_author_avatar(bbp_get_forum_last_reply_id(bbp_get_topic_last_active_id()), 50); if ($last_reply_avatar != '') { echo $last_reply_avatar; } else { echo bbp_get_topic_author_avatar(bbp_get_topic_last_active_id(), 50); } ?> </div> <div class="topic-desc"> <?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));
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; }
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); }
if ($last_reply_avatar != '') { echo $last_reply_avatar; } else { echo bbp_get_topic_author_avatar($sub_forum->ID, 50); } ?> </div> <div class="topic-desc"> <?php do_action('bbp_theme_before_topic_freshness_author'); ?> <span class="bbp-topic-freshness-author"><?php $last_reply_link = bbp_get_reply_author_link(bbp_get_forum_last_reply_id($sub_forum->ID), 50); if ($last_reply_link != '') { echo $last_reply_link; } else { echo bbp_get_topic_author_link($sub_forum->ID, 50); } //echo bbp_get_reply_author_link(bbp_get_forum_last_reply_id($sub_forum->ID), 50); ?> </span> <!-- <span class="bbp-topic-freshness-author">--><?php //echo bbp_get_author_link( array( 'post_id' => $sub_forum->ID, 'size' => 14 ) ); ?> <!--</span>--> <?php do_action('bbp_theme_after_topic_freshness_author');