Make WordPress Core

Ticket #6387: taxonomies-ui.r10210.patch

File taxonomies-ui.r10210.patch, 20.0 KB (added by noel, 16 years ago)

post taxonomies ui patched against r10210

  • wp-includes/taxonomy.php

     
    1717 * @global array $wp_taxonomies
    1818 */
    1919$wp_taxonomies = array();
    20 $wp_taxonomies['category'] = (object) array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count');
    21 $wp_taxonomies['post_tag'] = (object) array('name' => 'post_tag', 'object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count');
     20$wp_taxonomies['category'] = (object) array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'label' => __('Categories'));
     21$wp_taxonomies['post_tag'] = (object) array('name' => 'post_tag', 'object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count', 'label' => __('Tags'));
    2222$wp_taxonomies['link_category'] = (object) array('name' => 'link_category', 'object_type' => 'link', 'hierarchical' => false);
    2323
    2424/**
  • wp-includes/post.php

     
    14931493        }
    14941494
    14951495        wp_set_post_categories( $post_ID, $post_category );
    1496         wp_set_post_tags( $post_ID, $tags_input );
     1496        // old-style tags_input
     1497        if ( !empty($tags_input) )
     1498                wp_set_post_tags( $post_ID, $tags_input );
     1499        // new-style support for all tag-like taxonomies
     1500        if ( !empty($tax_input) ) {
     1501                foreach ( $tax_input as $taxonomy => $tags ) {
     1502                        wp_set_post_tax( $post_ID, $taxonomy, $tags );                 
     1503                }
     1504        }
    14971505
    14981506        $current_guid = get_post_field( 'guid', $post_ID );
    14991507
     
    16801688 * @return bool|null Will return false if $post_id is not an integer or is 0. Will return null otherwise
    16811689 */
    16821690function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
     1691        return wp_set_post_tax( $post_id, 'post_tag', $tags, $append);
     1692}
    16831693
     1694function wp_set_post_tax( $post_id = 0, $taxonomy='post_tag', $tags = '', $append = false ) {
    16841695        $post_id = (int) $post_id;
    16851696
    16861697        if ( !$post_id )
     
    16891700        if ( empty($tags) )
    16901701                $tags = array();
    16911702        $tags = (is_array($tags)) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
    1692         wp_set_object_terms($post_id, $tags, 'post_tag', $append);
     1703        wp_set_object_terms($post_id, $tags, $taxonomy, $append);
    16931704}
    16941705
    16951706/**
  • wp-includes/js/autosave.js

     
    130130                post_ID:  jQuery("#post_ID").val() || 0,
    131131                post_title: jQuery("#title").val() || "",
    132132                autosavenonce: jQuery('#autosavenonce').val(),
    133                 tags_input: jQuery("#tags-input").val() || "",
     133                //tags_input: jQuery("#tags-input").val() || "",
    134134                post_type: jQuery('#post_type').val() || "",
    135135                autosave: 1
    136136        };
     137       
     138        jQuery('.tags-input').each( function() {
     139                post_data[this.name] = this.value;
     140        } );
    137141
    138142        // We always send the ajax request in order to keep the post lock fresh.
    139143        // This (bool) tells whether or not to write the post to the DB during the ajax request.
  • wp-content/themes/default/functions.php

     
    44 * @subpackage Default_Theme
    55 */
    66
     7// FIXME: testing only, to be removed
     8//function add_test_taxonomies_alex() {
     9//register_taxonomy(
     10//'people',
     11//array('attachment:image', 'attachment:video', 'attachment:audio', 'post', 'page'),
     12//array(
     13//'label' => __('People'),
     14//'template' => __('People: %l.'),
     15//'helps' => __('Separate people with commas.'),
     16//'sort' => true,
     17//'args' => array('orderby' => 'term_order'),
     18//'rewrite' => array('slug' => 'person'),
     19//)
     20//);
     21//        register_taxonomy( 'post_place', 'post' );
     22//}
     23 
     24//add_action('init', 'add_test_taxonomies_alex');
     25 
     26
    727if ( function_exists('register_sidebar') )
    828    register_sidebar(array(
    929        'before_widget' => '<li id="%1$s" class="widget %2$s">',
  • wp-admin/admin-ajax.php

     
    776776        global $current_user;
    777777
    778778        $_POST['post_category'] = explode(",", $_POST['catslist']);
    779         $_POST['tags_input'] = explode(",", $_POST['tags_input']);
    780779        if($_POST['post_type'] == 'page' || empty($_POST['post_category']))
    781780                unset($_POST['post_category']);
    782781
  • wp-admin/wp-admin.css

     
    13551355        display: none;
    13561356}
    13571357
    1358 #post-body #tagsdiv #newtag {
     1358#post-body .tagsdiv #newtag {
    13591359        margin-right: 5px;
    13601360        width: 16em;
    13611361}
     
    13641364        width: 94%
    13651365}
    13661366
    1367 #side-info-column #tagsdiv #newtag {
     1367#side-info-column .tagsdiv #newtag {
    13681368        width: 68%;
    13691369}
    13701370
     
    14211421        padding: 5px 0;
    14221422}
    14231423
    1424 #tagchecklist {
     1424.tagchecklist {
    14251425        margin-left: 10px;
    14261426        font-size: 12px;
    14271427        overflow: auto;
    14281428}
    14291429
    1430 #tagchecklist strong {
     1430.tagchecklist strong {
    14311431        margin-left: -8px;
    14321432        position: absolute;
    14331433}
    14341434
    1435 #tagchecklist span {
     1435.tagchecklist span {
    14361436        margin-right: 25px;
    14371437        display: block;
    14381438        float: left;
     
    14421442        cursor: default;
    14431443}
    14441444
    1445 #tagchecklist span a {
     1445.tagchecklist span a {
    14461446        margin: 6px 0pt 0pt -9px;
    14471447        cursor: pointer;
    14481448        width: 10px;
     
    28302830        margin-top: 8px;
    28312831}
    28322832
    2833 #tagsdiv #the-tagcloud {
     2833.tagsdiv #the-tagcloud {
    28342834        margin: 5px 5px 10px;
    28352835        padding: 8px;
    28362836        border-width: 1px;
  • wp-admin/includes/taxonomy.php

     
    239239        return wp_insert_term($tag_name, 'post_tag');
    240240}
    241241
     242//
     243// Other
     244//
     245
     246// equivalent to get_tags_to_edit(), but for any tag-like taxonomy
     247function get_tax_to_edit( $post_id, $taxonomy ) {
     248        $post_id = (int) $post_id;
     249        if ( !$post_id )
     250                return false;
     251
     252        $tags = wp_get_object_terms( $post_id, $taxonomy, array('fields'=>'names') );
     253        if ( !$tags )
     254                return false;
     255       
     256        $tags_to_edit = join( ', ', $tags );
     257        $tags_to_edit = attribute_escape( $tags_to_edit );
     258        $tags_to_edit = apply_filters( 'tax_to_edit', $tags_to_edit, $taxonomy );
     259        return $tags_to_edit;
     260}
     261
    242262?>
  • wp-admin/includes/template.php

     
    26952695 * @param string $context The context within the page where the boxes should show ('normal', 'advanced').
    26962696 * @param string $priority The priority within the context where the boxes should show ('high', 'low').
    26972697 */
    2698 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default') {
     2698function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
    26992699        global $wp_meta_boxes;
    27002700
    27012701        if ( !isset($wp_meta_boxes) )
     
    27422742        if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
    27432743                $wp_meta_boxes[$page][$context][$priority] = array();
    27442744
    2745         $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
     2745        $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
    27462746}
    27472747
    27482748/**
  • wp-admin/js/post.js

     
    11// this file contains all the scripts used in the post/edit page
    22
     3// return an array with any duplicate, whitespace or values removed
     4function array_unique_noempty(a) {
     5        out = [];
     6        jQuery.each( a, function( key, val ) {
     7                val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim
     8                if ( val && !val.match(/\s+$/) && jQuery.inArray(val, out) == -1 )
     9                        out.push(val);
     10                } );
     11        return out;
     12}
     13
    314function new_tag_remove_tag() {
    415        var id = jQuery( this ).attr( 'id' );
    5         var num = id.substr( 10 );
    6         var current_tags = jQuery( '#tags-input' ).val().split(',');
     16        var num = id.split('-check-num-')[1];
     17        var taxbox = jQuery(this).parents('.tagsdiv');
     18        var current_tags = taxbox.find( '.tags-input' ).val().split(',');
    719        delete current_tags[num];
    820        var new_tags = [];
    921        jQuery.each( current_tags, function( key, val ) {
     
    1123                        new_tags = new_tags.concat( val );
    1224                }
    1325        });
    14         jQuery( '#tags-input' ).val( new_tags.join( ',' ).replace( /\s*,+\s*/, ',' ).replace( /,+/, ',' ).replace( /,+\s+,+/, ',' ).replace( /,+\s*$/, '' ).replace( /^\s*,+/, '' ) );
     26        taxbox.find( '.tags-input' ).val( new_tags.join( ',' ).replace( /\s*,+\s*/, ',' ).replace( /,+/, ',' ).replace( /,+\s+,+/, ',' ).replace( /,+\s*$/, '' ).replace( /^\s*,+/, '' ) );
    1527        tag_update_quickclicks();
    16         jQuery('#newtag').focus();
     28        taxbox.find('input.newtag').focus();
    1729        return false;
    1830}
    1931
    20 function tag_update_quickclicks() {
    21         if ( jQuery( '#tags-input' ).length == 0 )
     32function tag_update_quickclicks(taxbox) {
     33        if ( jQuery(taxbox).find('.tags-input').length == 0 )
    2234                return;
    23         var current_tags = jQuery( '#tags-input' ).val().split(',');
    24         jQuery( '#tagchecklist' ).empty();
     35        var current_tags = jQuery(taxbox).find('.tags-input').val().split(',');
     36        jQuery(taxbox).find( '.tagchecklist' ).empty();
    2537        shown = false;
    2638//      jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, need something to array_unique
    2739        jQuery.each( current_tags, function( key, val ) {
    2840                val = val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim
    2941                if ( !val.match(/^\s+$/) && '' != val ) {
    30                         txt = '<span><a id="tag-check-' + key + '" class="ntdelbutton">X</a>&nbsp;' + val + '</span> ';
    31                         jQuery( '#tagchecklist' ).append( txt );
    32                         jQuery( '#tag-check-' + key ).click( new_tag_remove_tag );
    33                         shown = true;
     42                        var button_id = jQuery(taxbox).attr('id') + '-check-num-' + key;
     43                        txt = '<span><a id="' + button_id + '" class="ntdelbutton">X</a>&nbsp;' + val + '</span> ';
     44                        jQuery(taxbox).find( '.tagchecklist' ).append( txt );
     45                        jQuery( '#' + button_id ).click( new_tag_remove_tag );
    3446                }
    3547        });
    3648        if ( shown )
    37                 jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
     49                jQuery(taxbox).find( '.tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
    3850}
    3951
    4052function tag_flush_to_text(e,a) {
    4153        a = a || false;
    4254        var text = a ? jQuery(a).text() : jQuery('#newtag').val();
    43         var newtags = jQuery('#tags-input').val();
    44 
    45         var t = text.replace( /\s*([^,]+).*/, '$1,' );
    46         newtags += ','
    47 
    48         if ( newtags.indexOf(t) != -1 )
     55        taxbox = jQuery(e.target).parents('.tagsdiv');
     56        // is the input box empty (i.e. showing the 'Add new tag' tip)?
     57        if ( taxbox.find('input.newtag').hasClass('form-input-tip') )
    4958                return false;
    50 
    51         newtags += text;
    52 
     59        var newtags = taxbox.find('.tags-input').val() + ',' + taxbox.find('input.newtag').val();
    5360        // massage
    5461        newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' );
    55         jQuery('#tags-input').val( newtags );
    56         tag_update_quickclicks();
    57         if ( ! a ) {
    58                 jQuery('#newtag').val('');
    59                 jQuery('#newtag').focus();
    60         }
     62        newtags = array_unique_noempty(newtags.split(',')).join(',');
     63        taxbox.find('.tags-input').val( newtags );
     64        tag_update_quickclicks(taxbox);
     65        taxbox.find('input.newtag').val('');
     66        taxbox.find('input.newtag').focus();
    6167        return false;
    6268}
    6369
    6470function tag_save_on_publish() {
    65         if ( jQuery('#newtag').val() != postL10n.addTag )
    66                 tag_flush_to_text();
     71        jQuery('.tagsdiv').each( function(i) {
     72                if ( !jQuery(this).find('input.newtag').hasClass('form-input-tip') )
     73                tag_flush_to_text(this);
     74                } );
    6775}
    6876
    6977function tag_press_key( e ) {
    70         if ( 13 == e.keyCode ) {
    71                 tag_flush_to_text();
     78        keycode = e.which;
     79        if ( 13 == e.which ) {
     80                tag_flush_to_text(e);
    7281                return false;
    7382        }
    7483};
     84function tag_init() {
     85        jQuery('.ajaxtag').show();
     86        jQuery('.tagsdiv').each( function(i) {
     87                        tag_update_quickclicks(this);
     88                } );
     89                 
     90        // add the quickadd form
     91        jQuery('.ajaxtag input.tagadd').click( tag_flush_to_text );
     92        jQuery('.ajaxtag input.newtag').focus(function() {
     93                if ( this.value == postL10n.addTag ) {
     94                        jQuery(this).val( '' ).removeClass( 'form-input-tip' );
     95                }
     96        });
     97        jQuery('.ajaxtag input.newtag').blur(function() {
     98                if ( this.value == '' ) {
     99                        jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
     100                }
     101        });
     102 
     103        // auto-save tags on post save/publish
     104        jQuery('#publish').click( tag_save_on_publish );
     105        jQuery('#save-post').click( tag_save_on_publish );
     106 
     107        // catch the enter key
     108        jQuery('.ajaxtag input.newtag').keypress( tag_press_key );
     109}
    75110
    76111(function($){
    77112        tagCloud = {
     
    107142        // Editable slugs
    108143        make_slugedit_clickable();
    109144
    110         jQuery('#tags-input').hide();
    111         tag_update_quickclicks();
    112         // add the quickadd form
    113         jQuery('#jaxtag').prepend('<span id="ajaxtag"><input type="text" name="newtag" id="newtag" class="form-input-tip" size="16" autocomplete="off" value="'+postL10n.addTag+'" /><input type="button" class="button" id="tagadd" value="' + postL10n.add + '" tabindex="3" /><input type="hidden"/><input type="hidden"/><span class="howto">'+postL10n.separate+'</span></span>');
    114         jQuery('#tagadd').click( tag_flush_to_text );
    115         jQuery('#newtag').focus(function() {
    116                 if ( this.value == postL10n.addTag )
    117                         jQuery(this).val( '' ).removeClass( 'form-input-tip' );
    118         });
    119         jQuery('#newtag').blur(function() {
    120                 if ( this.value == '' )
    121                         jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
    122         });
     145        // prepare the tag UI
     146        tag_init();
    123147
    124         // auto-save tags on post save/publish
    125         jQuery('#publish').click( tag_save_on_publish );
    126         jQuery('#save-post').click( tag_save_on_publish );
    127 
    128148        jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
    129149
    130150        // auto-suggest stuff
    131         jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
    132         jQuery('#newtag').keypress( tag_press_key );
     151        jQuery('.newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
    133152
    134153        // category tabs
    135154        var categoryTabs =jQuery('#category-tabs').tabs();
  • wp-admin/rtl.css

     
    211211#normal-sortables .postbox .submit {
    212212        float: left;
    213213}
    214 #post-body #tagsdiv #newtag {
     214#post-body .tagsdiv #newtag {
    215215        margin-right: 0;
    216216        margin-left: 5px;
    217217}
     
    221221#comment-status-radio input {
    222222        margin: 2px 0 5px 3px;
    223223}
    224 #tagchecklist {
     224.tagchecklist {
    225225        margin-left: 0;
    226226        margin-right: 10px;
    227227}
    228 #tagchecklist strong {
     228.tagchecklist strong {
    229229        margin-left: 0;
    230230        margin-right: -8px;
    231231}
    232 #tagchecklist span {
     232.tagchecklist span {
    233233        float: right;
    234234}
    235 #tagchecklist span a {
     235.tagchecklist span a {
    236236        margin: 6px -9px 0 0;
    237237        float: right;
    238238}
  • wp-admin/edit-form-advanced.php

     
    263263 *
    264264 * @param object $post
    265265 */
    266 function post_tags_meta_box($post) {
     266function post_tags_meta_box($post, $box) {
     267        $taxonomy = $box['args']['taxonomy'];
     268        $helps    = $box['args']['helps'];
    267269?>
    268 <p id="jaxtag"><label class="hidden" for="newtag"><?php _e('Tags'); ?></label><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" /></p>
    269 <div id="tagchecklist"></div>
     270<div class="tagsdiv">
     271        <p class="jaxtag">
     272                <label class="hidden" for="newtag"><?php _e( $box['title'] ); ?></label>
     273                <input type="hidden" name="<?php echo "tax_input[$taxonomy]"; ?>" class="tags-input" id="tax-input[<?php echo $taxonomy; ?>]" size="40" tabindex="3" value="<?php echo get_tax_to_edit( $post->ID, $taxonomy ); ?>" />
     274         
     275        <span class="ajaxtag" style="display:none;">
     276                <input type="text" name="newtag[<?php echo $taxonomy; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" value="<?php _e('Add new tag'); ?>" />
     277                <input type="button" class="button tagadd" value="<?php _e('Add'); ?>" tabindex="3" />
     278                <input type="hidden"/><input type="hidden"/>
     279                <span class="howto"><?php echo $helps; ?></span>
     280        </span>
     281        </p>
     282        <div class="tagchecklist"></div>
     283</div>
    270284<p id="tagcloud-link" class="hide-if-no-js"><a href='#'><?php _e( 'Choose from the most popular tags' ); ?></a></p>
    271285<?php
    272286}
    273 add_meta_box('tagsdiv', __('Tags'), 'post_tags_meta_box', 'post', 'side', 'core');
    274287
     288// all tag-style post taxonomies
     289foreach ( get_object_taxonomies('post') as $_tax ) {
     290        if ( !is_taxonomy_hierarchical($_tax) ) {
     291                $taxonomy = get_taxonomy($_tax);
     292               
     293                $label = ( isset($taxonomy->label) ? $taxonomy->label : $_tax );
     294                $helps = ( isset($taxonomy->helps) ? $taxonomy->helps : '' );
     295               
     296                $tags_to_edit = get_tax_to_edit( $post_ID, $_tax );
     297               
     298                add_meta_box('tagsdiv-'.$_tax, $label, 'post_tags_meta_box', 'post', 'side', 'core', array('taxonomy' => $_tax, 'helps' => $helps ) );
     299        }
     300}
     301       
    275302/**
    276303 * Display post categories form fields.
    277304 *
  • wp-admin/css/ie-rtl.css

     
    4444        padding-right: 0;
    4545        padding-left: 1px;
    4646}
    47 #tagchecklist span a {
     47.tagchecklist span a {
    4848        margin: 4px -9px 0 0;
    4949}
    5050.widefat th input {
  • wp-admin/css/ie.css

     
    245245li.widget-list-control-item h4,
    246246.widget-sortable,
    247247.widget-control-actions,
    248 #tagchecklist,
     248.tagchecklist,
    249249#col-container,
    250250#col-left,
    251251#col-right {
     
    296296        padding-right: 1px;
    297297}
    298298
    299 #tagchecklist span, #tagchecklist span a {
     299.tagchecklist span, .tagchecklist span a {
    300300        display: inline-block;
    301301        display: block;
    302302}
    303303
    304 #tagchecklist span a {
     304.tagchecklist span a {
    305305        margin: 4px 0 0 -9px;
    306306}
    307307
  • wp-admin/css/colors-fresh.css

     
    682682        color: #448abd;
    683683}
    684684
    685 #tagchecklist span a,
     685.tagchecklist span a,
    686686#bulk-titles div a {
    687687        background: url(../images/xit.gif) no-repeat;
    688688}
    689689
    690 #tagchecklist span a:hover,
     690.tagchecklist span a:hover,
    691691#bulk-titles div a:hover {
    692692        background: url(../images/xit.gif) no-repeat -10px 0;
    693693}
     
    10071007
    10081008#timestampdiv input,
    10091009#namediv input,
    1010 #tagsdiv #the-tagcloud {
     1010.tagsdiv #the-tagcloud {
    10111011        border-color: #ddd;
    10121012}
    10131013
  • wp-admin/css/colors-classic.css

     
    682682        color: #448abd;
    683683}
    684684
    685 #tagchecklist span a,
     685.tagchecklist span a,
    686686#bulk-titles div a {
    687687        background: url(../images/xit.gif) no-repeat;
    688688}
    689689
    690 #tagchecklist span a:hover,
     690.tagchecklist span a:hover,
    691691#bulk-titles div a:hover {
    692692        background: url(../images/xit.gif) no-repeat -10px 0;
    693693}
     
    10071007
    10081008#timestampdiv input,
    10091009#namediv input,
    1010 #tagsdiv #the-tagcloud {
     1010.tagsdiv #the-tagcloud {
    10111011        border-color: #ddd;
    10121012}
    10131013