Exemple #1
0
/**
 * Saves an already existing post as a post revision.
 *
 * Typically used immediately prior to post updates.
 *
 * @package NXTClass
 * @subpackage Post_Revisions
 * @since 2.6.0
 *
 * @uses _nxt_put_post_revision()
 *
 * @param int $post_id The ID of the post to save as a revision.
 * @return mixed Null or 0 if error, new revision ID, if success.
 */
function nxt_save_post_revision($post_id)
{
    // We do autosaves manually with nxt_create_post_autosave()
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    // nxt_POST_REVISIONS = 0, false
    if (!nxt_POST_REVISIONS) {
        return;
    }
    if (!($post = get_post($post_id, ARRAY_A))) {
        return;
    }
    if (!post_type_supports($post['post_type'], 'revisions')) {
        return;
    }
    $return = _nxt_put_post_revision($post);
    // nxt_POST_REVISIONS = true (default), -1
    if (!is_numeric(nxt_POST_REVISIONS) || nxt_POST_REVISIONS < 0) {
        return $return;
    }
    // all revisions and (possibly) one autosave
    $revisions = nxt_get_post_revisions($post_id, array('order' => 'ASC'));
    // nxt_POST_REVISIONS = (int) (# of autosaves to save)
    $delete = count($revisions) - nxt_POST_REVISIONS;
    if ($delete < 1) {
        return $return;
    }
    $revisions = array_slice($revisions, 0, $delete);
    for ($i = 0; isset($revisions[$i]); $i++) {
        if (false !== strpos($revisions[$i]->post_name, 'autosave')) {
            continue;
        }
        nxt_delete_post_revision($revisions[$i]->ID);
    }
    return $return;
}
do_action('dbx_post_advanced');
if (post_type_supports($post_type, 'comments')) {
    add_meta_box('commentstatusdiv', __('Discussion'), 'post_comment_status_meta_box', null, 'normal', 'core');
}
if (('publish' == $post->post_status || 'private' == $post->post_status) && post_type_supports($post_type, 'comments')) {
    add_meta_box('commentsdiv', __('Comments'), 'post_comment_meta_box', null, 'normal', 'core');
}
if (!('pending' == $post->post_status && !current_user_can($post_type_object->cap->publish_posts))) {
    add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', null, 'normal', 'core');
}
if (post_type_supports($post_type, 'author')) {
    if (is_super_admin() || current_user_can($post_type_object->cap->edit_others_posts)) {
        add_meta_box('authordiv', __('Author'), 'post_author_meta_box', null, 'normal', 'core');
    }
}
if (post_type_supports($post_type, 'revisions') && 0 < $post_ID && nxt_get_post_revisions($post_ID)) {
    add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core');
}
do_action('add_meta_boxes', $post_type, $post);
do_action('add_meta_boxes_' . $post_type, $post);
do_action('do_meta_boxes', $post_type, 'normal', $post);
do_action('do_meta_boxes', $post_type, 'advanced', $post);
do_action('do_meta_boxes', $post_type, 'side', $post);
add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
if ('post' == $post_type) {
    $customize_display = '<p>' . __('The title field and the big Post Editing Area are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Excerpt, Send Trackbacks, Custom Fields, Discussion, Slug, Author) or to choose a 1- or 2-column layout for this screen.') . '</p>';
    get_current_screen()->add_help_tab(array('id' => 'customize-display', 'title' => __('Customizing This Display'), 'content' => $customize_display));
    $title_and_editor = '<p>' . __('<strong>Title</strong> - Enter a title for your post. After you enter a title, you&#8217;ll see the permalink below, which you can edit.') . '</p>';
    $title_and_editor .= '<p>' . __('<strong>Post editor</strong> - Enter the text for your post. There are two modes of editing: Visual and HTML. Choose the mode by clicking on the appropriate tab. Visual mode gives you a WYSIWYG editor. Click the last icon in the row to get a second row of controls. The HTML mode allows you to enter raw HTML along with your post text. You can insert media files by clicking the icons above the post editor and following the directions. You can go to the distraction-free writing screen via the Fullscreen icon in Visual mode (second to last in the top row) or the Fullscreen button in HTML mode (last in the row). Once there, you can make buttons visible by hovering over the top area. Exit Fullscreen back to the regular post editor.') . '</p>';
    get_current_screen()->add_help_tab(array('id' => 'title-post-editor', 'title' => __('Title and Post Editor'), 'content' => $title_and_editor));
    $publish_box = '<p>' . __('<strong>Publish</strong> - You can set the terms of publishing your post in the Publish box. For Status, Visibility, and Publish (immediately), click on the Edit link to reveal more options. Visibility includes options for password-protecting a post or making it stay at the top of your blog indefinitely (sticky). Publish (immediately) allows you to set a future or past date and time, so you can schedule a post to be published in the future or backdate a post.') . '</p>';
Exemple #3
0
/**
 * 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>";
    }
}