Ticket #6387: post-taxonomy-ui-r8339-2.patch
File post-taxonomy-ui-r8339-2.patch, 17.1 KB (added by , 15 years ago) |
---|
-
wp-includes/taxonomy.php
15 15 * @global array $wp_taxonomies 16 16 */ 17 17 $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')); 20 20 $wp_taxonomies['link_category'] = (object) array('name' => 'link_category', 'object_type' => 'link', 'hierarchical' => false); 21 21 22 22 /** … … 2132 2132 return get_object_taxonomies($post); 2133 2133 } 2134 2134 2135 // FIXME: testing only, to be removed 2136 function add_test_taxonomies_alex() { 2137 register_taxonomy( 2138 'people', 2139 array('attachment:image', 'attachment:video', 'attachment:audio', 'post', 'page'), 2140 array( 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 2152 add_action('init', 'add_test_taxonomies_alex'); 2153 2135 2154 ?> 2155 No newline at end of file -
wp-includes/post.php
1377 1377 } 1378 1378 1379 1379 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 } 1381 1389 1382 1390 $current_guid = get_post_field( 'guid', $post_ID ); 1383 1391 … … 1568 1576 * @return bool|null Will return false if $post_id is not an integer or is 0. Will return null otherwise 1569 1577 */ 1570 1578 function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) { 1579 return wp_set_post_tax( $post_id, 'post_tag', $tags, $append); 1580 } 1571 1581 1582 function wp_set_post_tax( $post_id = 0, $taxonomy='post_tag', $tags = '', $append = false ) { 1572 1583 $post_id = (int) $post_id; 1573 1584 1574 1585 if ( !$post_id ) … … 1577 1588 if ( empty($tags) ) 1578 1589 $tags = array(); 1579 1590 $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); 1581 1592 } 1582 1593 1583 1594 /** -
wp-includes/js/autosave.js
166 166 post_ID: jQuery("#post_ID").val() || 0, 167 167 post_title: jQuery("#title").val() || "", 168 168 autosavenonce: jQuery('#autosavenonce').val(), 169 tags_input: jQuery("#tags-input").val() || "",169 //tags_input: jQuery("#tags-input").val() || "", 170 170 post_type: jQuery('#post_type').val() || "", 171 171 autosave: 1 172 172 }; 173 174 jQuery('.tags-input').each( function() { 175 post_data[this.name] = this.value; 176 } ); 173 177 174 178 // We always send the ajax request in order to keep the post lock fresh. 175 179 // This (bool) tells whether or not to write the post to the DB during the ajax request. -
wp-admin/admin-ajax.php
508 508 global $current_user; 509 509 510 510 $_POST['post_category'] = explode(",", $_POST['catslist']); 511 $_POST['tags_input'] = explode(",", $_POST['tags_input']);512 511 if($_POST['post_type'] == 'page' || empty($_POST['post_category'])) 513 512 unset($_POST['post_category']); 514 513 -
wp-admin/wp-admin.css
947 947 948 948 /* Post Screen */ 949 949 950 #tagsdiv #newtag {950 .tagsdiv .newtag { 951 951 margin-right: 5px; 952 952 width: 16em; 953 953 } 954 954 955 #tagchecklist {955 .tagchecklist { 956 956 margin-left: 10px; 957 957 958 958 font-size: 12px; 959 959 overflow: auto; 960 960 } 961 961 962 #tagchecklist strong {962 .tagchecklist strong { 963 963 margin-left: -8px; 964 964 position: absolute; 965 965 } 966 966 967 #tagchecklist span {967 .tagchecklist span { 968 968 margin-right: 25px; 969 969 display: block; 970 970 float: left; … … 974 974 cursor: default; 975 975 } 976 976 977 #tagchecklist span a {977 .tagchecklist span a { 978 978 margin: 6px 0pt 0pt -9px; 979 979 cursor: pointer; 980 980 width: 10px; -
wp-admin/includes/template.php
1157 1157 * @param string $page The type of edit page on which to show the box (post, page, link) 1158 1158 * @param string $context The context within the page where the boxes should show ('normal', 'advanced') 1159 1159 * @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. 1160 1161 */ 1161 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default' ) {1162 function add_meta_box($id, $title, $callback, $page, $context = 'advanced', $priority = 'default', $callback_args=null) { 1162 1163 global $wp_meta_boxes; 1163 1164 1164 1165 … … 1198 1199 if ( !isset($wp_meta_boxes[$page][$context][$priority]) ) 1199 1200 $wp_meta_boxes[$page][$context][$priority] = array(); 1200 1201 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); 1202 1203 } 1203 1204 1204 1205 function do_meta_boxes($page, $context, $object) { -
wp-admin/includes/taxonomy.php
150 150 return wp_insert_term($tag_name, 'post_tag'); 151 151 } 152 152 153 // 154 // Other 155 // 156 157 // equivalent to get_tags_to_edit(), but for any tag-like taxonomy 158 function 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 153 173 ?> -
wp-admin/js/post.js
1 1 // this file contains all the scripts used in the post/edit page 2 2 3 // return an array with any duplicate, whitespace or values removed 4 function 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 3 14 function new_tag_remove_tag() { 4 15 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(','); 7 19 delete current_tags[num]; 8 20 var new_tags = []; 9 21 jQuery.each( current_tags, function( key, val ) { … … 11 23 new_tags = new_tags.concat( val ); 12 24 } 13 25 }); 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 17 30 return false; 18 31 } 19 32 20 function tag_update_quickclicks( ) {21 if ( jQuery( '#tags-input').length == 0 )33 function tag_update_quickclicks( taxbox ) { 34 if ( jQuery(taxbox).find('.tags-input').length == 0 ) 22 35 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(); 25 38 shown = false; 26 // jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, need something to array_unique27 39 jQuery.each( current_tags, function( key, val ) { 28 40 val = val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim 29 41 if ( !val.match(/^\s+$/) && '' != val ) { 30 txt = '<span><a id="tag-check-' + key + '" class="ntdelbutton">X</a> ' + 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> ' + val + '</span> '; 44 jQuery(taxbox).find( '.tagchecklist' ).append( txt ); 45 jQuery( '#' + button_id ).click( new_tag_remove_tag ); 34 46 } 35 47 }); 36 48 if ( shown ) 37 jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );49 jQuery(taxbox).find( '.tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' ); 38 50 } 39 51 40 function tag_flush_to_text() { 41 var newtags = jQuery('#tags-input').val() + ',' + jQuery('#newtag').val(); 52 function 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(); 42 60 // massage 43 61 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(); 48 67 return false; 49 68 } 50 69 51 70 function 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 54 76 } 55 77 56 78 function 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); 59 82 return false; 60 83 } 61 84 } 62 85 86 function 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 63 115 jQuery(document).ready( function() { 64 116 // close postboxes that should be closed 65 117 jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed'); … … 77 129 // hide advanced slug field 78 130 jQuery('#slugdiv').hide(); 79 131 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(); 93 134 94 // auto-save tags on post save/publish95 jQuery('#publish').click( tag_save_on_publish );96 jQuery('#save-post').click( tag_save_on_publish );97 98 135 jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } ); 99 136 100 137 // 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: ", " } ); 103 139 104 140 // category tabs 105 141 var categoryTabs =jQuery('#category-tabs').tabs(); -
wp-admin/edit-form-advanced.php
227 227 <?php echo $form_prevstatus ?> 228 228 229 229 <?php 230 function post_tags_meta_box($post) { 230 function post_tags_meta_box($post, $box) { 231 $taxonomy = $box['args']['taxonomy']; 232 $helps = $box['args']['helps']; 231 233 ?> 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 234 243 <?php 235 244 } 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'); 237 246 247 // all tag-style post taxonomies 248 foreach ( 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 238 261 function post_categories_meta_box($post) { 239 262 ?> 240 263 <div id="category-adder" class="wp-hidden-children"> -
wp-admin/css/colors-fresh.css
439 439 border-top-color: #e4f2fd; 440 440 } 441 441 442 #tagchecklist span a {442 .tagchecklist span a { 443 443 background: url(../images/xit.gif) no-repeat; 444 444 } 445 445 446 #tagchecklist span a:hover {446 .tagchecklist span a:hover { 447 447 background: url(../images/xit.gif) no-repeat -10px 0; 448 448 } 449 449 -
wp-admin/css/colors-classic.css
471 471 color: #cfebf6; 472 472 } 473 473 474 #tagchecklist span a {474 .tagchecklist span a { 475 475 background: url(../images/xit.gif) no-repeat; 476 476 } 477 477 478 #tagchecklist span a:hover {478 .tagchecklist span a:hover { 479 479 background: url(../images/xit.gif) no-repeat -10px 0; 480 480 } 481 481