Make WordPress Core

Changeset 6633


Ignore:
Timestamp:
01/17/2008 04:51:32 PM (19 years ago)
Author:
matt
Message:

Edit permalink in place. Fixes #5679. Hat tip: nbachiyski.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-ajax.php

    r6631 r6633  
    474474        update_usermeta($current_user->ID, 'closedpostboxes', $closed);
    475475break;
     476case 'sample-permalink':
     477        check_ajax_referer( $action );
     478        $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
     479        die(get_sample_permalink_html($post_id, $_POST['new_slug']));
     480break;
    476481default :
    477482        do_action( 'wp_ajax_' . $_POST['action'] );
  • trunk/wp-admin/edit-form-advanced.php

    r6625 r6633  
    7171<div id="titlediv">
    7272<h3><?php _e('Title') ?></h3>
    73 <div class="inside"><input type="text" name="post_title" size="30" tabindex="1" value="<?php echo attribute_escape($post->post_title); ?>" id="title" /></div>
     73<div class="inside">
     74        <input type="text" name="post_title" size="30" tabindex="1" value="<?php echo attribute_escape($post->post_title); ?>" id="title" />
     75<?php
     76        $sample_permalink_html = get_sample_permalink_html($post->ID);
     77        if ($post->ID && $sample_permalink_html):
     78?>
     79        <div id="edit-slug-box" style="display: <?php echo $post->ID? 'block' : 'none';?>">
     80                <strong><?php _e('Permalink:'); ?></strong>
     81                <span id="sample-permalink"><?php echo $sample_permalink_html; ?></span>
     82                <span id="edit-slug-buttons"><a href="#post_name" class="edit-slug" onclick="edit_permalink(<?php echo $post->ID; ?>);return false;"><?php _e('Edit');?></a></span>
     83        </div>
     84<?php
     85        endif;
     86        ?>
     87</div>
    7488</div>
    7589
     
    127141
    128142<p class="submit">
    129 <input type="submit" name="submit" value="<?php _e('Save'); ?>" style="font-weight: bold;" tabindex="4" />
     143<input type="submit" name="save" value="<?php _e('Save'); ?>" style="font-weight: bold;" tabindex="4" />
    130144<?php
    131145if ( !in_array( $post->post_status, array('publish', 'future') ) || 0 == $post_ID ) {
  • trunk/wp-admin/includes/post.php

    r6604 r6633  
    525525}
    526526
     527function get_sample_permalink($id, $name = null) {
     528        $post = &get_post($id);
     529        $original_status = $post->post_status;
     530        $original_date = $post->post_date;
     531        $original_name = $post->post_name;
     532        if (in_array($post->post_status, array('draft', 'pending'))) {
     533                $post->post_status = 'publish';
     534                $post->post_date = date('Y-m-d H:i:s');
     535                $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
     536        }
     537        if (!is_null($name)) {
     538                $post->post_name = sanitize_title($name, $post->ID);
     539        }
     540        $permalink = get_permalink($post, true);
     541        $permalink = array($permalink, $post->post_name);
     542        $post->post_status = $original_status;
     543        $post->post_date = $original_date;
     544        $post->post_name = $original_name;
     545        return $permalink;
     546}
     547
     548function get_sample_permalink_html($id, $new_slug=null) {
     549        $post = &get_post($id);
     550        list($permalink, $post_name) = get_sample_permalink($post->ID, $new_slug);
     551        if (false === strpos($permalink, '%postname%')) {
     552                return '';
     553        }
     554        $title = __('You can edit this part of the permalink using the Edit button on the right');
     555        if (strlen($post_name) > 30) {
     556                $post_name = substr($post_name, 0, 14). '&hellip;' . substr($post_name, -14);
     557        }
     558        $post_name_html = '<span id="editable-post-name" title="'.$title.'">'.$post_name.'</span>';
     559        $display_link = str_replace('%postname%', $post_name_html, $permalink);
     560        return $display_link;
     561}
     562
    527563?>
  • trunk/wp-admin/js/post.js

    r6602 r6633  
    6464                closed: closed,
    6565                cookie: document.cookie});
     66}
     67
     68function edit_permalink(post_id) {
     69        var e = jQuery('#editable-post-name');
     70        var revert_e = e.html();       
     71        var real_slug = jQuery('#post_name');
     72        var b = jQuery('#edit-slug-buttons');
     73        var revert_b = b.html();
     74        var old_slug = e.children('span').html();
     75
     76        b.html('<a href="" class="save">'+postL10n.save+'</a> <a class="cancel" href="">'+postL10n.cancel+'</a>');
     77        b.children('.save').click(function() {
     78                var new_slug = e.children('input').attr('value');
     79                jQuery.post(postL10n.requestFile, {
     80                        action: 'sample-permalink',
     81                        post_id: post_id,
     82                        new_slug: new_slug,
     83                        cookie: document.cookie}, function(data) {
     84                                jQuery('#sample-permalink').html(data);
     85                                b.html(revert_b);
     86                                real_slug.attr('value', new_slug);     
     87                        });
     88                return false;
     89        });
     90        jQuery('#edit-slug-buttons .cancel').click(function() {
     91                e.html(revert_e);
     92                b.html(revert_b);
     93                real_slug.attr('value', revert_e);
     94                return false;
     95        });
     96        e.html('<input type="text" id="new-post-slug" value="" />').children('input').keypress(function(e){
     97                var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
     98                // on enter, just save the new slug, don't save the post
     99                if (13 == key) {b.children('.save').click();return false;}
     100                if (27 == key) {b.children('.cancel').click();return false;}
     101                real_slug.attr('value', this.value)}).focus();
    66102}
    67103
     
    137173        } );
    138174        jQuery('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change();
     175
     176        jQuery('#editable-post-name').click(function() {jQuery('#edit-slug-buttons').children('.edit-slug').click()});
    139177});
  • trunk/wp-admin/wp-admin.css

    r6611 r6633  
    11791179        width: 98%;
    11801180}
     1181#edit-slug-box {
     1182        margin-top: 8px;
     1183        color: #999;
     1184}
     1185#edit-slug-box strong {color: #777;}
     1186#editable-post-name {background-color: #FFFBCC;}
     1187#editable-post-name input {width: 16em;}
     1188#edit-slug-buttons a.save {
     1189        background-color: #ebebeb;
     1190        -moz-border-raduis: 5px;
     1191        padding: 6px;
     1192}
     1193#edit-slug-buttons a.cancel {font-size: 80%;}
    11811194
    11821195#poststuff #editor-toolbar {
     
    13321345.form-input-tip { color: #999; }
    13331346
     1347
  • trunk/wp-includes/link-template.php

    r6592 r6633  
    4444
    4545
    46 function get_permalink($id = 0) {
     46function get_permalink($id = 0, $leavename=false) {
    4747        $rewritecode = array(
    4848                '%year%',
     
    5252                '%minute%',
    5353                '%second%',
    54                 '%postname%',
     54                $leavename? '' : '%postname%',
    5555                '%post_id%',
    5656                '%category%',
    5757                '%author%',
    58                 '%pagename%'
     58                $leavename? '' : '%pagename%',
    5959        );
    6060
  • trunk/wp-includes/script-loader.php

    r6618 r6633  
    115115                                'addTag' => attribute_escape(__('Add new tag')),
    116116                                'separate' => __('Separate tags with commas'),
     117                                'save' => __('Save'),
     118                                'cancel' => __('Cancel'),
    117119                                'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php',
    118120                        ) );
Note: See TracChangeset for help on using the changeset viewer.