Make WordPress Core

Ticket #6387: post-taxonomy-ui-r7493-3.patch

File post-taxonomy-ui-r7493-3.patch, 10.0 KB (added by tellyworth, 17 years ago)

save and fetch code added

  • wp-includes/taxonomy.php

     
    18991899        }
    19001900}
    19011901
     1902// FIXME: testing only, to be removed
     1903register_taxonomy( 'post_keyword', 'post' );
     1904register_taxonomy( 'post_place', 'post' );
     1905
     1906
     1907
    19021908?>
  • wp-includes/post.php

     
    13011301        }
    13021302
    13031303        wp_set_post_categories( $post_ID, $post_category );
    1304         wp_set_post_tags( $post_ID, $tags_input );
     1304        // old-style tags_input
     1305        if ( !empty($tags_input) )
     1306                wp_set_post_tags( $post_ID, $tags_input );
     1307        // new-style support for all tag-like taxonomies
     1308        if ( !empty($tax_input) ) {
     1309                foreach ( $tax_input as $taxonomy => $tags ) {
     1310                        wp_set_post_tax( $post_ID, $taxonomy, $tags );                 
     1311                }
     1312        }
    13051313
    13061314        $current_guid = get_post_field( 'guid', $post_ID );
    13071315
     
    14551463}
    14561464
    14571465function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
     1466        return wp_set_post_tax( $post_id, 'post_tag', $tags, $append);
     1467}
     1468
     1469function wp_set_post_tax( $post_id = 0, $taxonomy='post_tag', $tags = '', $append = false ) {
    14581470        /* $append - true = don't delete existing tags, just add on, false = replace the tags with the new tags */
    14591471
    14601472        $post_id = (int) $post_id;
     
    14651477        if ( empty($tags) )
    14661478                $tags = array();
    14671479        $tags = (is_array($tags)) ? $tags : explode( ',', trim($tags, " \n\t\r\0\x0B,") );
    1468         wp_set_object_terms($post_id, $tags, 'post_tag', $append);
     1480        wp_set_object_terms($post_id, $tags, $taxonomy, $append);
    14691481}
    14701482
    14711483/**
  • wp-admin/admin-ajax.php

     
    465465
    466466        $_POST['post_status'] = 'draft';
    467467        $_POST['post_category'] = explode(",", $_POST['catslist']);
    468         $_POST['tags_input'] = explode(",", $_POST['tags_input']);
     468        #$_POST['tags_input'] = explode(",", $_POST['tags_input']);
    469469        if($_POST['post_type'] == 'page' || empty($_POST['post_category']))
    470470                unset($_POST['post_category']);
    471471
  • 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

     
    22
    33function new_tag_remove_tag() {
    44        var id = jQuery( this ).attr( 'id' );
    5         var num = id.substr( 10 );
    6         var current_tags = jQuery( '#tags-input' ).val().split(',');
     5        var num = id.split('-check-num-')[1];
     6        var obj = jQuery(this).parents('.tagsdiv');
     7        var current_tags = jQuery(obj).find( '.tags-input' ).val().split(',');
    78        delete current_tags[num];
    89        var new_tags = [];
    910        jQuery.each( current_tags, function( key, val ) {
     
    1112                        new_tags = new_tags.concat( val );
    1213                }
    1314        });
    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();
     15        jQuery( obj ).find( '.tags-input' ).val( new_tags.join( ',' ).replace( /\s*,+\s*/, ',' ).replace( /,+/, ',' ).replace( /,+\s+,+/, ',' ).replace( /,+\s*$/, '' ).replace( /^\s*,+/, '' ) );
     16        tag_update_quickclicks(obj);
     17        jQuery( obj ).find('input.newtag').focus();
    1718        return false;
    1819}
    1920
    20 function tag_update_quickclicks() {
    21         var current_tags = jQuery( '#tags-input' ).val().split(',');
    22         jQuery( '#tagchecklist' ).empty();
     21function tag_update_quickclicks(obj) {
     22        var current_tags = jQuery(obj).find('.tags-input').val().split(',');
     23        jQuery(obj).find( '.tagchecklist' ).empty();
    2324        shown = false;
    2425//      jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, need something to array_unique
    2526        jQuery.each( current_tags, function( key, val ) {
    2627                val = val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim
    2728                if ( !val.match(/^\s+$/) && '' != val ) {
    28                         txt = '<span><a id="tag-check-' + key + '" class="ntdelbutton">X</a>&nbsp;' + val + '</span> ';
    29                         jQuery( '#tagchecklist' ).append( txt );
    30                         jQuery( '#tag-check-' + key ).click( new_tag_remove_tag );
     29                        var button_id = jQuery(obj).attr('id') + '-check-num-' + key;
     30                        txt = '<span><a id="' + button_id + '" class="ntdelbutton">X</a>&nbsp;' + val + '</span> ';
     31                        jQuery(obj).find( '.tagchecklist' ).append( txt );
     32                        jQuery( '#' + button_id ).click( new_tag_remove_tag );
    3133                        shown = true;
    3234                }
    3335        });
    3436        if ( shown )
    35                 jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
     37                jQuery(obj).find( '.tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
    3638}
    3739
    3840function tag_flush_to_text() {
    39         var newtags = jQuery('#tags-input').val() + ',' + jQuery('#newtag').val();
     41        obj = jQuery(this).parents('.tagsdiv');
     42       
     43        var newtags = jQuery(obj).find('.tags-input').val() + ',' + jQuery(obj).find('input.newtag').val();
    4044        // massage
    4145        newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' );
    42         jQuery('#tags-input').val( newtags );
    43         tag_update_quickclicks();
    44         jQuery('#newtag').val('');
    45         jQuery('#newtag').focus();
     46        jQuery(obj).find('.tags-input').val( newtags );
     47        tag_update_quickclicks(obj);
     48        jQuery(obj).find('input.newtag').val('');
     49        jQuery(obj).find('input.newtag').focus();
    4650        return false;
    4751}
    4852
    4953function tag_save_on_publish() {
    50         if ( jQuery('#newtag').val() != postL10n.addTag )
    51                 tag_flush_to_text();
     54        jQuery('.tagsdiv').each( function(i) {
     55                if ( jQuery(this).find('input.newtag').val() != postL10n.addTag )
     56                        tag_flush_to_text();
     57                } );
    5258}
    5359
    5460function tag_press_key( e ) {
     
    5864        }
    5965}
    6066
    61 jQuery(document).ready( function() {
    62         // postboxes
    63         add_postbox_toggles('post');
    64 
    65         // Editable slugs
    66         make_slugedit_clickable();
    67 
    68         // hide advanced slug field
    69         jQuery('#slugdiv').hide();
    70 
    71         jQuery('#tags-input').hide();
    72         tag_update_quickclicks();
     67function tag_init() {
     68        jQuery('.ajaxtag').show();
     69        jQuery('.tags-input').hide();
     70        jQuery('.tagsdiv').each( function(i) {
     71                        tag_update_quickclicks(this);
     72                } );
     73               
    7374        // add the quickadd form
    74         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>');
    75         jQuery('#tagadd').click( tag_flush_to_text );
    76         jQuery('#newtag').focus(function() {
     75        jQuery('.ajaxtag input.tagadd').click( tag_flush_to_text );
     76        jQuery('.ajaxtag input.newtag').focus(function() {
    7777                if ( this.value == postL10n.addTag )
    7878                        jQuery(this).val( '' ).removeClass( 'form-input-tip' );
    7979        });
    80         jQuery('#newtag').blur(function() {
     80        jQuery('.ajaxtag input.newtag').blur(function() {
    8181                if ( this.value == '' )
    8282                        jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
    8383        });
     
    8686        jQuery('#publish').click( tag_save_on_publish );
    8787        jQuery('#save-post').click( tag_save_on_publish );
    8888
     89}
     90
     91
     92jQuery(document).ready( function() {
     93        // postboxes
     94        add_postbox_toggles('post');
     95
     96        // Editable slugs
     97        make_slugedit_clickable();
     98
     99        // hide advanced slug field
     100        jQuery('#slugdiv').hide();
     101       
     102        // prepare the tag UI
     103        tag_init();
     104
    89105        jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
    90106
    91107        // auto-suggest stuff
  • wp-admin/edit-form-advanced.php

     
    204204<?php echo $form_pingback ?>
    205205<?php echo $form_prevstatus ?>
    206206
    207 <div id="tagsdiv" class="postbox <?php echo postbox_classes('tagsdiv', 'post'); ?>">
    208 <h3><?php _e('Tags'); ?></h3>
     207<?php
     208
     209// all tag-style post taxonomies
     210foreach ( get_object_taxonomies('post') as $_tax ) {
     211        if ( !is_taxonomy_hierarchical($_tax) ) {
     212                $tags_to_edit = get_tax_to_edit( $post_ID, $_tax );
     213
     214                ?>
     215<div id="tagsdiv-<?php echo $_tax; ?>" class="postbox tagsdiv <?php echo postbox_classes('tagsdiv-'.$_tax, 'post'); ?>">
     216<h3><?php _e($_tax); ?></h3>
    209217<div class="inside">
    210 <p id="jaxtag"><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>
    211 <div id="tagchecklist"></div>
     218<p class="jaxtag"><input type="text" name="<?php echo "tax_input[{$_tax}]"; ?>" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo $tags_to_edit; ?>" />
     219
     220<span class="ajaxtag" style="display:none;"><input type="text" name="newtag[]" 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 _e('Separate tags with commas'); ?></span></span>
     221       
     222        </p>
     223<div class="tagchecklist"></div>
    212224</div>
    213225</div>
     226                <?
     227        }
     228}
    214229
     230?>
     231
    215232<div id="categorydiv" class="postbox <?php echo postbox_classes('categorydiv', 'post'); ?>">
    216233<h3><?php _e('Categories') ?></h3>
    217234<div class="inside">