function post_revisions() { global $post, $current_user, $role; if ($this->WikiHelper->is_wiki('front_end_check')) { $nxtw_options = get_option('nxtw_options'); $revisions = get_posts('post_status=any&post_type=revision&post_parent=' . $post->ID . '&numberposts=' . $nxtw_options['number_of_revisions']); //Most recent revision $date = date(__('m/d/y g:i a'), mktime($post->post_modified)); $author = $this->WikiHelper->get_author($post); $latest_revision = sprintf(__('Latest revision (@ %1s by %2s)'), $post->post_modified, $author); $output = '<a href="' . get_permalink($post->ID) . '">' . $latest_revision . '</a><br />'; //If we have revisions... if ($revisions) { //Loop through them! $count = 0; foreach ($revisions as $revision) { if (@nxt_get_post_autosave($post->ID)->ID != $revision->ID) { $author = $this->WikiHelper->get_author($revision); $date = date(__('m/d/y g:i a'), mktime($revision->post_modified)); $revision_title = sprintf(__('Revision @ %1s by %2s'), $date, $author); $output .= '<a href="' . get_permalink($post->ID) . '?revision=' . $revision->ID . '">' . $revision_title . '</a><br />'; $count++; } } } return $output; } }
if (isset($messages[$post_type][$_GET['message']])) { $message = $messages[$post_type][$_GET['message']]; } elseif (!isset($messages[$post_type]) && isset($messages['post'][$_GET['message']])) { $message = $messages['post'][$_GET['message']]; } } $notice = false; $form_extra = ''; if ('auto-draft' == $post->post_status) { if ('edit' == $action) { $post->post_title = ''; } $autosave = false; $form_extra .= "<input type='hidden' id='auto_draft' name='auto_draft' value='1' />"; } else { $autosave = nxt_get_post_autosave($post_ID); } $form_action = 'editpost'; $nonce_action = 'update-' . $post_type . '_' . $post_ID; $form_extra .= "<input type='hidden' id='post_ID' name='post_ID' value='" . esc_attr($post_ID) . "' />"; // Detect if there exists an autosave newer than the post and if that autosave is different than the post if ($autosave && mysql2date('U', $autosave->post_modified_gmt, false) > mysql2date('U', $post->post_modified_gmt, false)) { foreach (_nxt_post_revision_fields() as $autosave_field => $_autosave_field) { if (normalize_whitespace($autosave->{$autosave_field}) != normalize_whitespace($post->{$autosave_field})) { $notice = sprintf(__('There is an autosave of this post that is more recent than the version below. <a href="%s">View the autosave</a>'), get_edit_post_link($autosave->ID)); break; } } unset($autosave_field, $_autosave_field); } $post_type_object = get_post_type_object($post_type);
function _set_preview($post) { if (!is_object($post)) { return $post; } $preview = nxt_get_post_autosave($post->ID); if (!is_object($preview)) { return $post; } $preview = sanitize_post($preview); $post->post_content = $preview->post_content; $post->post_title = $preview->post_title; $post->post_excerpt = $preview->post_excerpt; return $post; }
/** * Display list of a post's revisions. * * Can output either a UL with edit links or a TABLE with diff interface, and * restore action links. * * Second argument controls parameters: * (bool) parent : include the parent (the "Current Revision") in the list. * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table' * outputs TABLE with UI. * (int) right : what revision is currently being viewed - used in * form-table format. * (int) left : what revision is currently being diffed against right - * used in form-table format. * * @package NXTClass * @subpackage Post_Revisions * @since 2.6.0 * * @uses nxt_get_post_revisions() * @uses nxt_post_revision_title() * @uses get_edit_post_link() * @uses get_the_author_meta() * * @todo split into two functions (list, form-table) ? * * @param int|object $post_id Post ID or post object. * @param string|array $args See description {@link nxt_parse_args()}. * @return null */ function nxt_list_post_revisions($post_id = 0, $args = null) { if (!($post = get_post($post_id))) { return; } $defaults = array('parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all'); extract(nxt_parse_args($args, $defaults), EXTR_SKIP); switch ($type) { case 'autosave': if (!($autosave = nxt_get_post_autosave($post->ID))) { return; } $revisions = array($autosave); break; case 'revision': // just revisions - remove autosave later // just revisions - remove autosave later case 'all': default: if (!($revisions = nxt_get_post_revisions($post->ID))) { return; } break; } /* translators: post revision: 1: when, 2: author name */ $titlef = _x('%1$s by %2$s', 'post revision'); if ($parent) { array_unshift($revisions, $post); } $rows = $right_checked = ''; $class = false; $can_edit_post = current_user_can('edit_post', $post->ID); foreach ($revisions as $revision) { if (!current_user_can('read_post', $revision->ID)) { continue; } if ('revision' === $type && nxt_is_post_autosave($revision)) { continue; } $date = nxt_post_revision_title($revision); $name = get_the_author_meta('display_name', $revision->post_author); if ('form-table' == $format) { if ($left) { $left_checked = $left == $revision->ID ? ' checked="checked"' : ''; } else { $left_checked = $right_checked ? ' checked="checked"' : ''; } // [sic] (the next one) $right_checked = $right == $revision->ID ? ' checked="checked"' : ''; $class = $class ? '' : " class='alternate'"; if ($post->ID != $revision->ID && $can_edit_post) { $actions = '<a href="' . nxt_nonce_url(add_query_arg(array('revision' => $revision->ID, 'action' => 'restore')), "restore-post_{$post->ID}|{$revision->ID}") . '">' . __('Restore') . '</a>'; } else { $actions = ''; } $rows .= "<tr{$class}>\n"; $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='{$revision->ID}'{$left_checked} /></th>\n"; $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='{$revision->ID}'{$right_checked} /></th>\n"; $rows .= "\t<td>{$date}</td>\n"; $rows .= "\t<td>{$name}</td>\n"; $rows .= "\t<td class='action-links'>{$actions}</td>\n"; $rows .= "</tr>\n"; } else { $title = sprintf($titlef, $date, $name); $rows .= "\t<li>{$title}</li>\n"; } } if ('form-table' == $format) { ?> <form action="revision.php" method="get"> <div class="tablenav"> <div class="alignleft"> <input type="submit" class="button-secondary" value="<?php esc_attr_e('Compare Revisions'); ?> " /> <input type="hidden" name="action" value="diff" /> <input type="hidden" name="post_type" value="<?php echo esc_attr($post->post_type); ?> " /> </div> </div> <br class="clear" /> <table class="widefat post-revisions" cellspacing="0" id="post-revisions"> <col /> <col /> <col style="width: 33%" /> <col style="width: 33%" /> <col style="width: 33%" /> <thead> <tr> <th scope="col"><?php /* translators: column name in revisons */ _ex('Old', 'revisions column name'); ?> </th> <th scope="col"><?php /* translators: column name in revisons */ _ex('New', 'revisions column name'); ?> </th> <th scope="col"><?php /* translators: column name in revisons */ _ex('Date Created', 'revisions column name'); ?> </th> <th scope="col"><?php _e('Author'); ?> </th> <th scope="col" class="action-links"><?php _e('Actions'); ?> </th> </tr> </thead> <tbody> <?php echo $rows; ?> </tbody> </table> </form> <?php } else { echo "<ul class='post-revisions'>\n"; echo $rows; echo "</ul>"; } }
/** * Creates autosave data for the specified post from $_POST data. * * @package NXTClass * @subpackage Post_Revisions * @since 2.6.0 * * @uses _nxt_translate_postdata() * @uses _nxt_post_revision_fields() * * @return unknown */ function nxt_create_post_autosave($post_id) { $translated = _nxt_translate_postdata(true); if (is_nxt_error($translated)) { return $translated; } // Only store one autosave. If there is already an autosave, overwrite it. if ($old_autosave = nxt_get_post_autosave($post_id)) { $new_autosave = _nxt_post_revision_fields($_POST, true); $new_autosave['ID'] = $old_autosave->ID; $new_autosave['post_author'] = get_current_user_id(); return nxt_update_post($new_autosave); } // _nxt_put_post_revision() expects unescaped. $_POST = stripslashes_deep($_POST); // Otherwise create the new autosave as a special post revision return _nxt_put_post_revision($_POST, true); }