diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index da24e51c1..eb30df1fe 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -473,6 +473,11 @@ case 'closed-postboxes' : $current_user = wp_get_current_user(); update_usermeta($current_user->ID, 'closedpostboxes', $closed); break; +case 'sample-permalink': + check_ajax_referer( $action ); + $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0; + die(get_sample_permalink_html($post_id, $_POST['new_slug'])); +break; default : do_action( 'wp_ajax_' . $_POST['action'] ); die('0'); diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 3af9324bf..69c8e8266 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -70,7 +70,21 @@ addLoadEvent(focusit);

-
+
+ +ID); + if ($post->ID && $sample_permalink_html): +?> +
+ + + +
+ +
@@ -126,7 +140,7 @@ else

- + post_status, array('publish', 'future') ) || 0 == $post_ID ) { ?> diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 2c2819264..5251aa3f1 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -524,4 +524,40 @@ function postbox_classes( $id ) { } } +function get_sample_permalink($id, $name = null) { + $post = &get_post($id); + $original_status = $post->post_status; + $original_date = $post->post_date; + $original_name = $post->post_name; + if (in_array($post->post_status, array('draft', 'pending'))) { + $post->post_status = 'publish'; + $post->post_date = date('Y-m-d H:i:s'); + $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID); + } + if (!is_null($name)) { + $post->post_name = sanitize_title($name, $post->ID); + } + $permalink = get_permalink($post, true); + $permalink = array($permalink, $post->post_name); + $post->post_status = $original_status; + $post->post_date = $original_date; + $post->post_name = $original_name; + return $permalink; +} + +function get_sample_permalink_html($id, $new_slug=null) { + $post = &get_post($id); + list($permalink, $post_name) = get_sample_permalink($post->ID, $new_slug); + if (false === strpos($permalink, '%postname%')) { + return ''; + } + $title = __('You can edit this part of the permalink using the Edit button on the right'); + if (strlen($post_name) > 30) { + $post_name = substr($post_name, 0, 14). '…' . substr($post_name, -14); + } + $post_name_html = ''.$post_name.''; + $display_link = str_replace('%postname%', $post_name_html, $permalink); + return $display_link; +} + ?> diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index 110560905..1525ef494 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -65,6 +65,42 @@ function save_postboxes_state() { cookie: document.cookie}); } +function edit_permalink(post_id) { + var e = jQuery('#editable-post-name'); + var revert_e = e.html(); + var real_slug = jQuery('#post_name'); + var b = jQuery('#edit-slug-buttons'); + var revert_b = b.html(); + var old_slug = e.children('span').html(); + + b.html(''+postL10n.save+' '+postL10n.cancel+''); + b.children('.save').click(function() { + var new_slug = e.children('input').attr('value'); + jQuery.post(postL10n.requestFile, { + action: 'sample-permalink', + post_id: post_id, + new_slug: new_slug, + cookie: document.cookie}, function(data) { + jQuery('#sample-permalink').html(data); + b.html(revert_b); + real_slug.attr('value', new_slug); + }); + return false; + }); + jQuery('#edit-slug-buttons .cancel').click(function() { + e.html(revert_e); + b.html(revert_b); + real_slug.attr('value', revert_e); + return false; + }); + e.html('').children('input').keypress(function(e){ + var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; + // on enter, just save the new slug, don't save the post + if (13 == key) {b.children('.save').click();return false;} + if (27 == key) {b.children('.cancel').click();return false;} + real_slug.attr('value', this.value)}).focus(); +} + addLoadEvent( function() { jQuery('#tags-input').hide(); tag_update_quickclicks(); @@ -136,4 +172,6 @@ addLoadEvent( function() { return false; } ); jQuery('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change(); + + jQuery('#editable-post-name').click(function() {jQuery('#edit-slug-buttons').children('.edit-slug').click()}); }); diff --git a/wp-admin/wp-admin.css b/wp-admin/wp-admin.css index e7e6c9556..2fae77c08 100644 --- a/wp-admin/wp-admin.css +++ b/wp-admin/wp-admin.css @@ -1178,6 +1178,19 @@ html, body { padding: 4px 3px; width: 98%; } +#edit-slug-box { + margin-top: 8px; + color: #999; +} +#edit-slug-box strong {color: #777;} +#editable-post-name {background-color: #FFFBCC;} +#editable-post-name input {width: 16em;} +#edit-slug-buttons a.save { + background-color: #ebebeb; + -moz-border-raduis: 5px; + padding: 6px; +} +#edit-slug-buttons a.cancel {font-size: 80%;} #poststuff #editor-toolbar { position: relative; @@ -1331,3 +1344,4 @@ ul.categorychecklist li { .ui-tabs-hide { display: none; } .form-input-tip { color: #999; } + diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 24bd239af..f7c7278e2 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -43,7 +43,7 @@ function permalink_anchor($mode = 'id') { } -function get_permalink($id = 0) { +function get_permalink($id = 0, $leavename=false) { $rewritecode = array( '%year%', '%monthnum%', @@ -51,11 +51,11 @@ function get_permalink($id = 0) { '%hour%', '%minute%', '%second%', - '%postname%', + $leavename? '' : '%postname%', '%post_id%', '%category%', '%author%', - '%pagename%' + $leavename? '' : '%pagename%', ); $post = &get_post($id); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 130450c45..97273f9cf 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -114,6 +114,8 @@ class WP_Scripts { 'add' => attribute_escape(__('Add')), 'addTag' => attribute_escape(__('Add new tag')), 'separate' => __('Separate tags with commas'), + 'save' => __('Save'), + 'cancel' => __('Cancel'), 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', ) ); $this->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080109' );