Changeset 9473
- Timestamp:
- 11/02/2008 01:56:32 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/post.php
r9469 r9473 1003 1003 function post_preview() { 1004 1004 1005 $_POST['post_category'] = explode(",", $_POST['catslist']); 1006 $_POST['tags_input'] = explode(",", $_POST['tags_input']); 1007 if($_POST['post_type'] == 'page' || empty($_POST['post_category'])) 1005 $post_ID = (int) $_POST['post_ID']; 1006 if ( $post_ID < 1 ) 1007 wp_die( __('Preview not available. Please save as draft first.') ); 1008 1009 if ( isset($_POST['catslist']) ) 1010 $_POST['post_category'] = explode(",", $_POST['catslist']); 1011 1012 if ( isset($_POST['tags_input']) ) 1013 $_POST['tags_input'] = explode(",", $_POST['tags_input']); 1014 1015 if ( $_POST['post_type'] == 'page' || empty($_POST['post_category']) ) 1008 1016 unset($_POST['post_category']); 1009 1017 1010 if($_POST['post_ID'] < 0) { 1011 $_POST['post_status'] = 'draft'; 1012 $_POST['temp_ID'] = $_POST['post_ID']; 1013 $id = wp_write_post(); 1018 $_POST['ID'] = $post_ID; 1019 $post = get_post($post_ID); 1020 1021 if ( 'page' == $post->post_type ) { 1022 if ( !current_user_can('edit_page', $post_ID) ) 1023 wp_die(__('You are not allowed to edit this page.')); 1014 1024 } else { 1015 $post_ID = (int) $_POST['post_ID']; 1016 $_POST['ID'] = $post_ID; 1017 $post = get_post($post_ID); 1018 1019 if ( 'page' == $post->post_type ) { 1020 if ( !current_user_can('edit_page', $post_ID) ) 1021 die(__('You are not allowed to edit this page.')); 1022 } else { 1023 if ( !current_user_can('edit_post', $post_ID) ) 1024 die(__('You are not allowed to edit this post.')); 1025 } 1026 1027 if ( 'draft' == $post->post_status ) { 1028 $id = edit_post(); 1029 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. 1030 wp_create_post_autosave( $post->ID ); 1025 if ( !current_user_can('edit_post', $post_ID) ) 1026 wp_die(__('You are not allowed to edit this post.')); 1027 } 1028 1029 if ( 'draft' == $post->post_status ) { 1030 $id = edit_post(); 1031 } else { // Non drafts are not overwritten. The autosave is stored in a special post revision. 1032 $id = wp_create_post_autosave( $post->ID ); 1033 if ( ! is_wp_error($id) ) 1031 1034 $id = $post->ID; 1032 }1033 1035 } 1034 1036 -
trunk/wp-admin/js/page.js
r9451 r9473 109 109 // preview 110 110 $('#post-preview').click(function(e){ 111 if ( 1 > $('#post_ID').val() && autosaveFirst ) { 112 autosaveDelayPreview = true; 113 autosave(); 114 return false; 115 } 116 111 117 $('input#wp-preview').val('dopreview'); 112 118 $('form#post').attr('target', 'wp-preview').submit().attr('target', ''); 113 119 $('input#wp-preview').val(''); 120 return false; 114 121 }); 115 122 }); -
trunk/wp-admin/js/post.js
r9451 r9473 264 264 // preview 265 265 $('#post-preview').click(function(e){ 266 if ( 1 > $('#post_ID').val() && autosaveFirst ) { 267 autosaveDelayPreview = true; 268 autosave(); 269 return false; 270 } 271 266 272 $('input#wp-preview').val('dopreview'); 267 273 $('form#post').attr('target', 'wp-preview').submit().attr('target', ''); 268 274 $('input#wp-preview').val(''); 275 return false; 269 276 }); 270 277 -
trunk/wp-admin/page.php
r9468 r9473 177 177 check_admin_referer( 'autosave', 'autosavenonce' ); 178 178 179 if ( empty($_POST['post_title']) )180 wp_die( __('Please enter a title before previewing this page.') );181 182 179 $id = post_preview(); 183 180 … … 185 182 wp_die( $id->get_error_message() ); 186 183 187 if ( $_POST['post_status'] == 'publish' ) { 184 if ( $_POST['post_status'] == 'draft' ) { 185 $url = get_option('home') . '/?page_id=' . $id . '&preview=true'; 186 } else { 188 187 $nonce = wp_create_nonce('post_preview_' . $id); 189 $url = site_url('?wp_preview=' . $id . '&preview_nonce=' . $nonce); 190 } else { 191 $url = site_url('?page_id=' . $id . '&preview=true'); 188 $url = get_option('home') . '/?wp_preview=' . $id . '&preview_nonce=' . $nonce; 192 189 } 193 190 -
trunk/wp-admin/post.php
r9453 r9473 224 224 check_admin_referer( 'autosave', 'autosavenonce' ); 225 225 226 if ( empty($_POST['post_title']) )227 wp_die( __('Please enter a title before previewing this post.') );228 229 226 $id = post_preview(); 230 227 … … 232 229 wp_die( $id->get_error_message() ); 233 230 234 if ( $_POST['post_status'] == 'publish' ) { 231 if ( $_POST['post_status'] == 'draft' ) { 232 $url = get_option('home') . '/?p=' . $id . '&preview=true'; 233 } else { 235 234 $nonce = wp_create_nonce('post_preview_' . $id); 236 235 $url = get_option('home') . '/?wp_preview=' . $id . '&preview_nonce=' . $nonce; 237 } else {238 $url = get_option('home') . '/?p=' . $id . '&preview=true';239 236 } 240 237 -
trunk/wp-includes/js/autosave.js
r8691 r9473 2 2 var autosavePeriodical; 3 3 var autosaveOldMessage = ''; 4 var autosaveDelay URL = null;5 var previewwin;4 var autosaveDelayPreview = false; 5 var autosaveFirst = true; 6 6 7 7 jQuery(function($) { … … 11 11 //Disable autosave after the form has been submitted 12 12 $("#post").submit(function() { $.cancel(autosavePeriodical); }); 13 14 // Autosave when the preview button is clicked.15 $('#previewview a').click(function(e) {16 autosave();17 autosaveDelayURL = this.href;18 previewwin = window.open('','_blank');19 20 e.preventDefault();21 return false;22 });23 13 }); 24 14 … … 42 32 } 43 33 44 // if no errors: add preview link andslug UI34 // if no errors: add slug UI 45 35 if ( !res.errors ) { 46 36 var postID = parseInt( res.responses[0].id ); 47 37 if ( !isNaN(postID) && postID > 0 ) { 48 autosave_update_preview_link(postID);49 38 autosave_update_slug(postID); 50 39 } … … 70 59 var postID = parseInt( res.responses[0].id ); 71 60 autosave_update_post_ID( postID ); // disabled form buttons are re-enabled here 72 if ( tempID < 0 && postID > 0 ) // update media buttons61 if ( tempID < 0 && postID > 0 ) // update media buttons 73 62 jQuery('#media-buttons a').each(function(){ 74 63 this.href = this.href.replace(tempID, postID); 75 64 }); 65 // activate preview 66 autosaveFirst = false; 67 if ( autosaveDelayPreview ) 68 jQuery('#post-preview').click(); 76 69 } else { 77 70 autosave_enable_buttons(); // re-enable disabled form buttons … … 98 91 } 99 92 100 function autosave_update_preview_link(post_id) {101 // Add preview button if not already there102 if ( !jQuery('#previewview > *').size() ) {103 var post_type = jQuery('#post_type').val();104 var previewText = 'page' == post_type ? autosaveL10n.previewPageText : autosaveL10n.previewPostText;105 jQuery.post(autosaveL10n.requestFile, {106 action: "get-permalink",107 post_id: post_id,108 getpermalinknonce: jQuery('#getpermalinknonce').val()109 }, function(permalink) {110 jQuery('#previewview').html('<a class="button" target="_blank" href="'+permalink+'" tabindex="4">'+previewText+'</a>');111 112 // Autosave when the preview button is clicked.113 jQuery('#previewview a').click(function(e) {114 autosave();115 autosaveDelayURL = this.href;116 previewwin = window.open('','_blank');117 118 e.preventDefault();119 return false;120 });121 });122 }123 }124 125 93 function autosave_update_slug(post_id) { 126 94 // create slug area only if not already there … … 148 116 function autosave_enable_buttons() { 149 117 jQuery("#submitpost :button:disabled, #submitpost :submit:disabled").attr('disabled', ''); 150 if ( autosaveDelayURL ) {151 previewwin.location = autosaveDelayURL;152 autosaveDelayURL = null;153 }154 118 } 155 119 … … 224 188 if(parseInt(post_data["post_ID"]) < 1) { 225 189 post_data["temp_ID"] = post_data["post_ID"]; 226 var successCallback = autosave_saved_new; ;// new post190 var successCallback = autosave_saved_new; // new post 227 191 } else { 228 192 var successCallback = autosave_saved; // pre-existing post -
trunk/wp-includes/script-loader.php
r9465 r9473 76 76 ) ); 77 77 78 $scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '2008 0701' );78 $scripts->add( 'autosave', '/wp-includes/js/autosave.js', array('schedule', 'wp-ajax-response'), '20081102' ); 79 79 80 80 $scripts->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('wp-ajax-response'), '20080729' ); … … 177 177 'cancel' => __('Cancel'), 178 178 ) ); 179 $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug', 'settings-box'), '20081 031' );179 $scripts->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug', 'settings-box'), '20081102' ); 180 180 $scripts->localize( 'post', 'postL10n', array( 181 181 'tagsUsed' => __('Tags used on this post:'), … … 196 196 'saveDraft' => __('Save Draft') 197 197 ) ); 198 $scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox', 'settings-box'), '20081 031' );198 $scripts->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox', 'settings-box'), '20081102' ); 199 199 $scripts->localize( 'page', 'postL10n', array( 200 200 'cancel' => __('Cancel'),
Note: See TracChangeset
for help on using the changeset viewer.