/** * @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); }
/** * this function changes the bbp freshness data (time since) into a last post date for topics */ function change_freshness_topic($last_active, $topic_id) { $topic_id = bbp_get_topic_id($topic_id); // Try to get the most accurate freshness time possible $last_active = get_post_meta($topic_id, '_bbp_last_active_time', true); if (empty($last_active)) { $reply_id = bbp_get_topic_last_reply_id($topic_id); if (!empty($reply_id)) { $last_active = get_post_field('post_date', $reply_id); } else { $last_active = get_post_field('post_date', $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; }
/** * Return the topics last update date/time (aka freshness) * * @since 2.0.0 bbPress (r2625) * * @param int $topic_id Optional. Topic id * @uses bbp_get_topic_id() To get topic id * @uses get_post_meta() To get the topic lst active meta * @uses bbp_get_topic_last_reply_id() To get topic last reply id * @uses get_post_field() To get the post date of topic/reply * @uses bbp_convert_date() To convert date * @uses bbp_get_time_since() To get time in since format * @uses apply_filters() Calls 'bbp_get_topic_last_active' with topic * freshness and topic id * @return string Topic freshness */ function bbp_get_topic_last_active_time($topic_id = 0) { $topic_id = bbp_get_topic_id($topic_id); // Try to get the most accurate freshness time possible $last_active = get_post_meta($topic_id, '_bbp_last_active_time', true); if (empty($last_active)) { $reply_id = bbp_get_topic_last_reply_id($topic_id); if (!empty($reply_id)) { $last_active = get_post_field('post_date', $reply_id); } else { $last_active = get_post_field('post_date', $topic_id); } } $last_active = !empty($last_active) ? bbp_get_time_since(bbp_convert_date($last_active)) : ''; // Return the time since return apply_filters('bbp_get_topic_last_active', $last_active, $topic_id); }
/** * Return the formatted revision log of the reply * * @since bbPress (r2782) * * @param int $reply_id Optional. Reply id * @uses bbp_get_reply_id() To get the reply id * @uses bbp_get_reply_revisions() To get the reply revisions * @uses bbp_get_reply_raw_revision_log() To get the raw revision log * @uses bbp_get_reply_author_display_name() To get the reply author * @uses bbp_get_reply_author_link() To get the reply author link * @uses bbp_convert_date() To convert the date * @uses bbp_get_time_since() To get the time in since format * @uses apply_filters() Calls 'bbp_get_reply_revision_log' with the * log and reply id * @return string Revision log of the reply */ function bbp_get_reply_revision_log($reply_id = 0) { // Create necessary variables $reply_id = bbp_get_reply_id($reply_id); // Show the topic reply log if this is a topic in a reply loop if (bbp_is_topic($reply_id)) { return bbp_get_topic_revision_log($reply_id); } // Get the reply revision log (out of post meta $revision_log = bbp_get_reply_raw_revision_log($reply_id); // Check reply and revision log exist if (empty($reply_id) || empty($revision_log) || !is_array($revision_log)) { return false; } // Get the actual revisions $revisions = bbp_get_reply_revisions($reply_id); if (empty($revisions)) { return false; } $r = "\n\n" . '<ul id="bbp-reply-revision-log-' . esc_attr($reply_id) . '" class="bbp-reply-revision-log">' . "\n\n"; // Loop through revisions foreach ((array) $revisions as $revision) { if (empty($revision_log[$revision->ID])) { $author_id = $revision->post_author; $reason = ''; } else { $author_id = $revision_log[$revision->ID]['author']; $reason = $revision_log[$revision->ID]['reason']; } $author = bbp_get_author_link(array('size' => 14, 'link_text' => bbp_get_reply_author_display_name($revision->ID), 'post_id' => $revision->ID)); $since = bbp_get_time_since(bbp_convert_date($revision->post_modified)); $r .= "\t" . '<li id="bbp-reply-revision-log-' . esc_attr($reply_id) . '-item-' . esc_attr($revision->ID) . '" class="bbp-reply-revision-log-item">' . "\n"; if (!empty($reason)) { $r .= "\t\t" . sprintf(esc_html__('This reply was modified %1$s by %2$s. Reason: %3$s', 'bbpress'), esc_html($since), $author, esc_html($reason)) . "\n"; } else { $r .= "\t\t" . sprintf(esc_html__('This reply was modified %1$s by %2$s.', 'bbpress'), esc_html($since), $author) . "\n"; } $r .= "\t" . '</li>' . "\n"; } $r .= "\n" . '</ul>' . "\n\n"; return apply_filters('bbp_get_reply_revision_log', $r, $reply_id); }
/** * 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); }