/** * @covers ::bbp_forum_last_reply_title * @covers ::bbp_get_forum_last_reply_title */ public function test_bbp_get_forum_last_reply_title() { $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_title' => 'Reply To: Topic 1', 'post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Get the forums last reply title. $forum = bbp_get_forum_last_reply_title($f); $this->assertSame('Reply To: Topic 1', $forum); // Get the categories last reply title. $category = bbp_get_forum_last_reply_title($c); $this->assertSame('Reply To: Topic 1', $category); }
/** * Output the title of the last reply inside a forum * * @param int $forum_id Optional. Forum id * @uses bbp_get_forum_last_reply_title() To get the forum's last reply's title */ function bbp_forum_last_reply_title($forum_id = 0) { echo bbp_get_forum_last_reply_title($forum_id); }
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; }
/** * @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)); }
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); }