Make WordPress Core

Ticket #6387: post-taxonomy-ui-r8339-2.patch

File post-taxonomy-ui-r8339-2.patch, 17.1 KB (added by tellyworth, 15 years ago)

patch against r8339 plus improvements

  • wp-includes/taxonomy.php

     
    1515 * @global array $wp_taxonomies
    1616 */
    1717$wp_taxonomies = array();
    18 $wp_taxonomies['category'] = (object) array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count');
    19 $wp_taxonomies['post_tag'] = (object) array('name' => 'post_tag', 'object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count');
     18$wp_taxonomies['category'] = (object) array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count', 'label' => __('Categories'));
     19$wp_taxonomies['post_tag'] = (object) array('name' => 'post_tag', 'object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count', 'label' => __('Tags'));
    2020$wp_taxonomies['link_category'] = (object) array('name' => 'link_category', 'object_type' => 'link', 'hierarchical' => false);
    2121
    2222/**
     
    21322132        return get_object_taxonomies($post);
    21332133}
    21342134
     2135// FIXME: testing only, to be removed
     2136function add_test_taxonomies_alex() {
     2137register_taxonomy(
     2138'people',
     2139array('attachment:image', 'attachment:video', 'attachment:audio', 'post', 'page'),
     2140array(
     2141'label' => __('People'),
     2142'template' => __('People: %l.'),
     2143'helps' => __('Separate people with commas.'),
     2144'sort' => true,
     2145'args' => array('orderby' => 'term_order'),
     2146'rewrite' => array('slug' => 'person'),
     2147)
     2148);
     2149        register_taxonomy( 'post_place', 'post' );
     2150}
     2151
     2152add_action('init', 'add_test_taxonomies_alex');
     2153
    21352154?>
     2155 No newline at end of file
  • wp-includes/post.php

     
    13771377        }
    13781378
    13791379        wp_set_post_categories( $post_ID, $post_category );
    1380         wp_set_post_tags( $post_ID, $tags_input );
     1380        // old-style tags_input
     1381        if ( !empty($tags_input) )
     1382                wp_set_post_tags( $post_ID, $tags_input );
     1383        // new-style support for all tag-like taxonomies
     1384        if ( !empty($tax_input) ) {
     1385                foreach ( $tax_input as $taxonomy => $tags ) {
     1386                        wp_set_post_tax( $post_ID, $taxonomy, $tags );                 
     1387                }
     1388        }
    13811389
    13821390        $current_guid = get_post_field( 'guid', $post_ID );
    13831391
     
    15681576 * @return bool|null Will return false if $post_id is not an integer or is 0. Will return null otherwise
    15691577 */
    15701578function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
     1579        return wp_set_post_tax( $post_id, 'post_tag', $tags, $append);
     1580}
    15711581
     1582function wp_set_post_tax( $post_id = 0, $taxonomy='post_tag', $tags = '', $append = false ) {
    15721583        $post_id = (int) $post_id;
    15731584
    15741585        if ( !$post_id )
     
    15771588        if ( empty($tags) )
    15781589                $tags = array();
    15791590        $tags = (is_array($tags)) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
    1580         wp_set_object_terms($post_id, $tags, 'post_tag', $append);
     1591        wp_set_object_terms($post_id, $tags, $taxonomy, $append);
    15811592}
    15821593
    15831594/**
  • wp-includes/js/autosave.js

     
    166166                post_ID:  jQuery("#post_ID").val() || 0,
    167167                post_title: jQuery("#title").val() || "",
    168168                autosavenonce: jQuery('#autosavenonce').val(),
    169                 tags_input: jQuery("#tags-input").val() || "",
     169                //tags_input: jQuery("#tags-input").val() || "",
    170170                post_type: jQuery('#post_type').val() || "",
    171171                autosave: 1
    172172        };
     173       
     174        jQuery('.tags-input').each( function() {
     175                post_data[this.name] = this.value;
     176        } );
    173177
    174178        // We always send the ajax request in order to keep the post lock fresh.
    175179        // This (bool) tells whether or not to write the post to the DB during the ajax request.
  • wp-admin/admin-ajax.php

     
    508508        global $current_user;
    509509
    510510        $_POST['post_category'] = explode(",", $_POST['catslist']);
    511         $_POST['tags_input'] = explode(",", $_POST['tags_input']);
    512511        if($_POST['post_type'] == 'page' || empty($_POST['post_category']))
    513512                unset($_POST['post_category']);
    514513
  • wp-admin/wp-admin.css

     
    947947
    948948/* Post Screen */
    949949
    950 #tagsdiv #newtag {
     950.tagsdiv .newtag {
    951951        margin-right: 5px;
    952952        width: 16em;
    953953}
    954954
    955 #tagchecklist {
     955.tagchecklist {
    956956        margin-left: 10px;
    957957
    958958        font-size: 12px;
    959959        overflow: auto;
    960960}
    961961
    962 #tagchecklist strong {
     962.tagchecklist strong {
    963963        margin-left: -8px;
    964964        position: absolute;
    965965}
    966966
    967 #tagchecklist span {
     967.tagchecklist span {
    968968        margin-right: 25px;
    969969        display: block;
    970970        float: left;
     
    974974        cursor: default;
    975975}
    976976
    977 #tagchecklist span a {
     977.tagchecklist span a {
    978978        margin: 6px 0pt 0pt -9px;
    979979        cursor: pointer;
    980980        width: 10px;
  • wp-admin/includes/template.php

     
    11571157 * @param string $page The type of edit page on which to show the box (post, page, link)
    11581158 * @param string $context The context within the page where the boxes should show ('normal', 'advanced')
    11591159 * @param string $priority The priority within the context where the boxes should show ('high', 'low')
     1160 * @param mixed $callback_args Additional arguments for the callback function.  Optional, type as required by the callback.
    11601161 */
    1161 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default') {
     1162function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) {
    11621163        global $wp_meta_boxes;
    11631164
    11641165       
     
    11981199        if ( !isset($wp_meta_boxes[$page][$context][$priority]) )
    11991200                $wp_meta_boxes[$page][$context][$priority] = array();
    12001201
    1201         $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback);
     1202        $wp_meta_boxes[$page][$context][$priority][$id] = array('id' => $id, 'title' => $title, 'callback' => $callback, 'args' => $callback_args);
    12021203}
    12031204
    12041205function do_meta_boxes($page, $context, $object) {
  • wp-admin/includes/taxonomy.php

     
    150150        return wp_insert_term($tag_name, 'post_tag');
    151151}
    152152
     153//
     154// Other
     155//
     156
     157// equivalent to get_tags_to_edit(), but for any tag-like taxonomy
     158function get_tax_to_edit( $post_id, $taxonomy ) {
     159        $post_id = (int) $post_id;
     160        if ( !$post_id )
     161                return false;
     162
     163        $tags = wp_get_object_terms( $post_id, $taxonomy, array('fields'=>'names') );
     164        if ( !$tags )
     165                return false;
     166       
     167        $tags_to_edit = join( ', ', $tags );
     168        $tags_to_edit = attribute_escape( $tags_to_edit );
     169        $tags_to_edit = apply_filters( 'tax_to_edit', $tags_to_edit, $taxonomy );
     170        return $tags_to_edit;
     171}
     172
    153173?>
  • 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*,+/, '' ) );
    15         tag_update_quickclicks();
    16         jQuery('#newtag').focus();
     26        taxbox.find( '.tags-input' ).val( new_tags.join( ',' ).replace( /\s*,+\s*/, ',' ).replace( /,+/, ',' ).replace( /,+\s+,+/, ',' ).replace( /,+\s*$/, '' ).replace( /^\s*,+/, '' ) );
     27        tag_update_quickclicks(taxbox);
     28        taxbox.find('input.newtag').focus();
     29       
    1730        return false;
    1831}
    1932
    20 function tag_update_quickclicks() {
    21         if ( jQuery( '#tags-input' ).length == 0 )
     33function tag_update_quickclicks( taxbox ) {
     34        if ( jQuery(taxbox).find('.tags-input').length == 0 )
    2235                return;
    23         var current_tags = jQuery( '#tags-input' ).val().split(',');
    24         jQuery( '#tagchecklist' ).empty();
     36        var current_tags = jQuery(taxbox).find('.tags-input').val().split(',');
     37        jQuery(taxbox).find( '.tagchecklist' ).empty();
    2538        shown = false;
    26 //      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
    40 function tag_flush_to_text() {
    41         var newtags = jQuery('#tags-input').val() + ',' + jQuery('#newtag').val();
     52function tag_flush_to_text( e ) {
     53        taxbox = jQuery(e.target).parents('.tagsdiv');
     54       
     55        // is the input box empty (i.e. showing the 'Add new tag' tip)?
     56        if ( taxbox.find('input.newtag').hasClass('form-input-tip') )
     57                return false;
     58       
     59        var newtags = taxbox.find('.tags-input').val() + ',' + taxbox.find('input.newtag').val();
    4260        // massage
    4361        newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' );
    44         jQuery('#tags-input').val( newtags );
    45         tag_update_quickclicks();
    46         jQuery('#newtag').val('');
    47         jQuery('#newtag').focus();
     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();
    4867        return false;
    4968}
    5069
    5170function tag_save_on_publish() {
    52         if ( jQuery('#newtag').val() != postL10n.addTag )
    53                 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                } );
     75               
    5476}
    5577
    5678function tag_press_key( e ) {
    57         if ( 13 == e.keyCode ) {
    58                 tag_flush_to_text();
     79        keycode = e.which;
     80        if ( 13 == e.which ) {
     81                tag_flush_to_text(e);
    5982                return false;
    6083        }
    6184}
    6285
     86function tag_init() {
     87        jQuery('.ajaxtag').show();
     88        jQuery('.tagsdiv').each( function(i) {
     89                        tag_update_quickclicks(this);
     90                } );
     91               
     92        // add the quickadd form
     93        jQuery('.ajaxtag input.tagadd').click( tag_flush_to_text );
     94        jQuery('.ajaxtag input.newtag').focus(function() {
     95                if ( this.value == postL10n.addTag ) {
     96                        jQuery(this).val( '' ).removeClass( 'form-input-tip' );
     97                }
     98        });
     99        jQuery('.ajaxtag input.newtag').blur(function() {
     100                if ( this.value == '' ) {
     101                        jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
     102                }
     103        });
     104
     105        // auto-save tags on post save/publish
     106        jQuery('#publish').click( tag_save_on_publish );
     107        jQuery('#save-post').click( tag_save_on_publish );
     108
     109        // catch the enter key
     110        jQuery('.ajaxtag input.newtag').keypress( tag_press_key );
     111}
     112
     113
     114
    63115jQuery(document).ready( function() {
    64116        // close postboxes that should be closed
    65117        jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
     
    77129        // hide advanced slug field
    78130        jQuery('#slugdiv').hide();
    79131
    80         jQuery('#tags-input').hide();
    81         tag_update_quickclicks();
    82         // add the quickadd form
    83         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>');
    84         jQuery('#tagadd').click( tag_flush_to_text );
    85         jQuery('#newtag').focus(function() {
    86                 if ( this.value == postL10n.addTag )
    87                         jQuery(this).val( '' ).removeClass( 'form-input-tip' );
    88         });
    89         jQuery('#newtag').blur(function() {
    90                 if ( this.value == '' )
    91                         jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
    92         });
     132        // prepare the tag UI
     133        tag_init();
    93134
    94         // auto-save tags on post save/publish
    95         jQuery('#publish').click( tag_save_on_publish );
    96         jQuery('#save-post').click( tag_save_on_publish );
    97 
    98135        jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
    99136
    100137        // auto-suggest stuff
    101         jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
    102         jQuery('#newtag').keypress( tag_press_key );
     138        jQuery('.newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
    103139
    104140        // category tabs
    105141        var categoryTabs =jQuery('#category-tabs').tabs();
  • wp-admin/edit-form-advanced.php

     
    227227<?php echo $form_prevstatus ?>
    228228
    229229<?php
    230 function post_tags_meta_box($post) {
     230function post_tags_meta_box($post, $box) {
     231        $taxonomy = $box['args']['taxonomy'];
     232        $helps    = $box['args']['helps'];
    231233?>
    232 <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>
    233 <div id="tagchecklist"></div>
     234<div class="tagsdiv">
     235<p class="jaxtag"><label class="hidden" for="newtag"><?php _e( $box['title'] ); ?></label><input type="text" 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 ); ?>" />
     236
     237<span class="ajaxtag" style="display:none;"><input type="text" name="newtag[<?php echo $taxonomy; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" value="<?php _e('Add new tag'); ?>" /><input type="button" class="button tagadd" value="<?php _e('Add'); ?>" tabindex="3" /><input type="hidden"/><input type="hidden"/><span class="howto"><?php echo $helps; ?></span></span>
     238       
     239        </p>
     240<div class="tagchecklist"></div>
     241</div>
     242
    234243<?php
    235244}
    236 add_meta_box('tagsdiv', __('Tags'), 'post_tags_meta_box', 'post', 'normal', 'core');
     245//add_meta_box('tagsdiv', __('Tags'), 'post_tags_meta_box', 'post', 'normal', 'core');
    237246
     247// all tag-style post taxonomies
     248foreach ( get_object_taxonomies('post') as $_tax ) {
     249        if ( !is_taxonomy_hierarchical($_tax) ) {
     250                $taxonomy = get_taxonomy($_tax);
     251
     252                $label = ( isset($taxonomy->label) ? $taxonomy->label : $_tax );
     253                $helps = ( isset($taxonomy->helps) ? $taxonomy->helps : '' );
     254               
     255                $tags_to_edit = get_tax_to_edit( $post_ID, $_tax );
     256
     257                add_meta_box('tagsdiv-'.$_tax, $label, 'post_tags_meta_box', 'post', 'normal', 'core', array('taxonomy' => $_tax, 'helps' => $helps ) );
     258        }
     259}
     260
    238261function post_categories_meta_box($post) {
    239262?>
    240263<div id="category-adder" class="wp-hidden-children">
  • wp-admin/css/colors-fresh.css

     
    439439        border-top-color: #e4f2fd;
    440440}
    441441
    442 #tagchecklist span a {
     442.tagchecklist span a {
    443443        background: url(../images/xit.gif) no-repeat;
    444444}
    445445
    446 #tagchecklist span a:hover {
     446.tagchecklist span a:hover {
    447447        background: url(../images/xit.gif) no-repeat -10px 0;
    448448}
    449449
  • wp-admin/css/colors-classic.css

     
    471471        color: #cfebf6;
    472472}
    473473
    474 #tagchecklist span a {
     474.tagchecklist span a {
    475475        background: url(../images/xit.gif) no-repeat;
    476476}
    477477
    478 #tagchecklist span a:hover {
     478.tagchecklist span a:hover {
    479479        background: url(../images/xit.gif) no-repeat -10px 0;
    480480}
    481481