diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 1c052aba27..2aeec0815b 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -170,11 +170,17 @@ switch ( $post->post_status ) { + + + + +
diff --git a/wp-admin/edit-page-form.php b/wp-admin/edit-page-form.php index ed51fba268..4a873aa310 100644 --- a/wp-admin/edit-page-form.php +++ b/wp-admin/edit-page-form.php @@ -160,11 +160,17 @@ switch ( $post->post_status ) { + + + + +
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index bdb1229f17..52ae4d40d5 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -987,7 +987,56 @@ function wp_create_post_autosave( $post_id ) { } /** - * wp_tiny_mce() - adds the TinyMCE editor used on the Write and Edit screens. + * Save draft or manually autosave for showing preview. + * + * @package WordPress + * @since 2.7 + * + * @uses wp_write_post() + * @uses edit_post() + * @uses get_post() + * @uses current_user_can() + * @uses wp_create_post_autosave() + * + * @return int|object the saved post id or wp_error object + */ +function post_preview() { + + $_POST['post_category'] = explode(",", $_POST['catslist']); + $_POST['tags_input'] = explode(",", $_POST['tags_input']); + if($_POST['post_type'] == 'page' || empty($_POST['post_category'])) + unset($_POST['post_category']); + + if($_POST['post_ID'] < 0) { + $_POST['post_status'] = 'draft'; + $_POST['temp_ID'] = $_POST['post_ID']; + $id = wp_write_post(); + } else { + $post_ID = (int) $_POST['post_ID']; + $_POST['ID'] = $post_ID; + $post = get_post($post_ID); + + if ( 'page' == $post->post_type ) { + if ( !current_user_can('edit_page', $post_ID) ) + die(__('You are not allowed to edit this page.')); + } else { + if ( !current_user_can('edit_post', $post_ID) ) + die(__('You are not allowed to edit this post.')); + } + + if ( 'draft' == $post->post_status ) { + $id = edit_post(); + } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. + wp_create_post_autosave( $post->ID ); + $id = $post->ID; + } + } + + return $id; +} + +/** + * Adds the TinyMCE editor used on the Write and Edit screens. * * Has option to output a trimmed down version used in Press This. * diff --git a/wp-admin/js/editor.js b/wp-admin/js/editor.js index ac4f58a919..845cf8cc6a 100644 --- a/wp-admin/js/editor.js +++ b/wp-admin/js/editor.js @@ -24,7 +24,6 @@ switchEditors = { saveCallback : function(el, content, body) { - this.I(el).style.color = '#fff'; if ( tinyMCE.activeEditor.isHidden() ) content = this.I(el).value; else diff --git a/wp-admin/js/page.js b/wp-admin/js/page.js index 77ddcdddf9..0c99b3c958 100644 --- a/wp-admin/js/page.js +++ b/wp-admin/js/page.js @@ -105,4 +105,11 @@ jQuery(document).ready( function($) { return false; }); + + // preview + $('#post-preview').click(function(e){ + $('input#wp-preview').val('dopreview'); + $('form#post').attr('target', 'wp-preview').submit().attr('target', ''); + $('input#wp-preview').val(''); + }); }); diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index 1bd76a4a28..005b3dfdb0 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -260,6 +260,14 @@ jQuery(document).ready( function($) { return s; } }); + + // preview + $('#post-preview').click(function(e){ + $('input#wp-preview').val('dopreview'); + $('form#post').attr('target', 'wp-preview').submit().attr('target', ''); + $('input#wp-preview').val(''); + }); + }); (function($){ @@ -314,7 +322,7 @@ jQuery(document).ready( function($) { return false; } - } - + }; + })(jQuery); diff --git a/wp-admin/page.php b/wp-admin/page.php index f1fe56263a..6d943de897 100644 --- a/wp-admin/page.php +++ b/wp-admin/page.php @@ -67,9 +67,10 @@ function redirect_page($page_ID) { wp_redirect($location); } -if (isset($_POST['deletepost'])) { -$action = "delete"; -} +if (isset($_POST['deletepost'])) + $action = "delete"; +elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) + $action = 'preview'; switch($action) { case 'post': @@ -172,6 +173,28 @@ case 'delete': exit(); break; +case 'preview': + check_admin_referer( 'autosave', 'autosavenonce' ); + + if ( empty($_POST['post_title']) ) + wp_die( __('Please enter a title before previewing this page.') ); + + $id = post_preview(); + + if ( is_wp_error($id) ) + wp_die( $id->get_error_message() ); + + if ( $_POST['post_status'] == 'publish' ) { + $nonce = wp_create_nonce('post_preview_' . $id); + $url = site_url('?wp_preview=' . $id . '&preview_nonce=' . $nonce); + } else { + $url = site_url('?page_id=' . $id . '&preview=true'); + } + + wp_redirect($url); + exit(); + break; + default: wp_redirect('edit-pages.php'); exit(); diff --git a/wp-admin/post.php b/wp-admin/post.php index a2e0730175..5a903bd7d7 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -80,6 +80,8 @@ function redirect_post($post_ID = '') { if ( isset( $_POST['deletepost'] ) ) $action = 'delete'; +elseif ( isset($_POST['wp-preview']) && 'dopreview' == $_POST['wp-preview'] ) + $action = 'preview'; switch($action) { case 'postajaxpost': @@ -218,6 +220,28 @@ case 'delete': exit(); break; +case 'preview': + check_admin_referer( 'autosave', 'autosavenonce' ); + + if ( empty($_POST['post_title']) ) + wp_die( __('Please enter a title before previewing this post.') ); + + $id = post_preview(); + + if ( is_wp_error($id) ) + wp_die( $id->get_error_message() ); + + if ( $_POST['post_status'] == 'publish' ) { + $nonce = wp_create_nonce('post_preview_' . $id); + $url = site_url('?wp_preview=' . $id . '&preview_nonce=' . $nonce); + } else { + $url = site_url('?p=' . $id . '&preview=true'); + } + + wp_redirect($url); + exit(); + break; + default: wp_redirect('edit.php'); exit(); diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index ec47e8ad90..187f80f0f4 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -197,5 +197,6 @@ add_action('template_redirect', 'wp_old_slug_redirect'); add_action('edit_post', 'wp_check_for_changed_slugs'); add_action('edit_form_advanced', 'wp_remember_old_slug'); add_action('init', 'wp_user_settings', 9); +add_action('init', '_show_post_preview'); ?> diff --git a/wp-includes/post.php b/wp-includes/post.php index 6bd4eea69d..68b2c90564 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -3551,3 +3551,25 @@ function wp_get_post_revisions( $post_id = 0, $args = null ) { return array(); return $revisions; } + +function _show_post_preview() { + + if ( isset($_GET['wp_preview']) && isset($_GET['preview_nonce']) ) { + $post_ID = (int) $_GET['wp_preview']; + + if ( false == wp_verify_nonce( $_GET['preview_nonce'], 'post_preview_' . $post_ID ) ) + wp_die( __('You do not have permission to preview drafts.') ); + + $q = array( + 'name' => "{$post_ID}-autosave", + 'post_parent' => $post_ID, + 'post_type' => 'revision', + 'post_status' => 'inherit' + ); + + add_action( 'parse_query', '_wp_get_post_autosave_hack' ); + query_posts($q); + remove_action( 'parse_query', '_wp_get_post_autosave_hack' ); + + } +} diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 3f0760a589..41f29ad8bd 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -176,7 +176,7 @@ function wp_default_scripts( &$scripts ) { 'save' => __('Save'), 'cancel' => __('Cancel'), ) ); - $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug', 'settings-box'), '20081018' ); + $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug', 'settings-box'), '20081031' ); $scripts->localize( 'post', 'postL10n', array( 'tagsUsed' => __('Tags used on this post:'), 'add' => attribute_escape(__('Add')), @@ -195,7 +195,7 @@ function wp_default_scripts( &$scripts ) { 'savePending' => __('Save Pending'), 'saveDraft' => __('Save Draft') ) ); - $scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox', 'settings-box'), '20080925' ); + $scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox', 'settings-box'), '20081031' ); $scripts->localize( 'page', 'postL10n', array( 'cancel' => __('Cancel'), 'edit' => __('Edit'),