/**
 * Update the revision log of the topic
 *
 * @since bbPress (r2782)
 *
 * @param mixed $args Supports these args:
 *  - topic_id: Topic id
 *  - author_id: Author id
 *  - reason: Reason for editing
 *  - revision_id: Revision id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_format_revision_reason() To format the reason
 * @uses bbp_get_topic_raw_revision_log() To get the raw topic revision log
 * @uses update_post_meta() To update the topic revision log meta
 * @return mixed False on failure, true on success
 */
function bbp_update_topic_revision_log($args = '')
{
    // Parse arguments against default values
    $r = bbp_parse_args($args, array('reason' => '', 'topic_id' => 0, 'author_id' => 0, 'revision_id' => 0), 'update_topic_revision_log');
    // Populate the variables
    $r['reason'] = bbp_format_revision_reason($r['reason']);
    $r['topic_id'] = bbp_get_topic_id($r['topic_id']);
    $r['author_id'] = bbp_get_user_id($r['author_id'], false, true);
    $r['revision_id'] = (int) $r['revision_id'];
    // Get the logs and append the new one to those
    $revision_log = bbp_get_topic_raw_revision_log($r['topic_id']);
    $revision_log[$r['revision_id']] = array('author' => $r['author_id'], 'reason' => $r['reason']);
    // Finally, update
    return update_post_meta($r['topic_id'], '_bbp_revision_log', $revision_log);
}
Exemple #2
0
/**
 * Return the formatted revision log of the topic
 *
 * @since 2.0.0 bbPress (r2782)
 *
 * @param int $topic_id Optional. Topic id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_topic_revisions() To get the topic revisions
 * @uses bbp_get_topic_raw_revision_log() To get the raw revision log
 * @uses bbp_get_topic_author_display_name() To get the topic author
 * @uses bbp_get_author_link() To get the topic 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_topic_revision_log' with the
 *                        log and topic id
 * @return string Revision log of the topic
 */
function bbp_get_topic_revision_log($topic_id = 0)
{
    // Create necessary variables
    $topic_id = bbp_get_topic_id($topic_id);
    $revision_log = bbp_get_topic_raw_revision_log($topic_id);
    if (empty($topic_id) || empty($revision_log) || !is_array($revision_log)) {
        return false;
    }
    $revisions = bbp_get_topic_revisions($topic_id);
    if (empty($revisions)) {
        return false;
    }
    $retval = "\n\n" . '<ul id="bbp-topic-revision-log-' . esc_attr($topic_id) . '" class="bbp-topic-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_topic_author_display_name($revision->ID), 'post_id' => $revision->ID));
        $since = bbp_get_time_since(bbp_convert_date($revision->post_modified));
        $retval .= "\t" . '<li id="bbp-topic-revision-log-' . esc_attr($topic_id) . '-item-' . esc_attr($revision->ID) . '" class="bbp-topic-revision-log-item">' . "\n";
        if (!empty($reason)) {
            $retval .= "\t\t" . sprintf(__('This topic was modified %1$s by %2$s. Reason: %3$s', 'bbpress'), esc_html($since), $author, esc_html($reason)) . "\n";
        } else {
            $retval .= "\t\t" . sprintf(__('This topic was modified %1$s by %2$s.', 'bbpress'), esc_html($since), $author) . "\n";
        }
        $retval .= "\t" . '</li>' . "\n";
    }
    $retval .= "\n" . '</ul>' . "\n\n";
    return apply_filters('bbp_get_topic_revision_log', $retval, $topic_id);
}
/**
 * Update the revision log of the topic
 *
 * @since bbPress (r2782)
 *
 * @param mixed $args Supports these args:
 *  - topic_id: Topic id
 *  - author_id: Author id
 *  - reason: Reason for editing
 *  - revision_id: Revision id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_user_id() To get the user id
 * @uses bbp_format_revision_reason() To format the reason
 * @uses bbp_get_topic_raw_revision_log() To get the raw topic revision log
 * @uses update_post_meta() To update the topic revision log meta
 * @return mixed False on failure, true on success
 */
function bbp_update_topic_revision_log($args = '')
{
    $defaults = array('reason' => '', 'topic_id' => 0, 'author_id' => 0, 'revision_id' => 0);
    $r = bbp_parse_args($args, $defaults, 'update_topic_revision_log');
    extract($r);
    // Populate the variables
    $reason = bbp_format_revision_reason($reason);
    $topic_id = bbp_get_topic_id($topic_id);
    $author_id = bbp_get_user_id($author_id, false, true);
    $revision_id = (int) $revision_id;
    // Get the logs and append the new one to those
    $revision_log = bbp_get_topic_raw_revision_log($topic_id);
    $revision_log[$revision_id] = array('author' => $author_id, 'reason' => $reason);
    // Finally, update
    return update_post_meta($topic_id, '_bbp_revision_log', $revision_log);
}