Ticket #14691: tags-with-commas.diff
File tags-with-commas.diff, 8.2 KB (added by , 11 years ago) |
---|
-
src/wp-admin/includes/taxonomy.php
229 229 if ( is_wp_error($tags) ) 230 230 return $tags; 231 231 232 foreach ( $tags as $tag ) 233 $tag_names[] = $tag->name; 232 foreach ( $tags as $tag ) { 233 if ( strpos( $tag->name, ',' ) !== false ) 234 $tag_names[] = '"' . $tag->name . '"'; 235 else 236 $tag_names[] = $tag->name; 237 } 238 234 239 $tags_to_edit = join( ',', $tag_names ); 235 240 $tags_to_edit = esc_attr( $tags_to_edit ); 236 241 $tags_to_edit = apply_filters( 'terms_to_edit', $tags_to_edit, $taxonomy ); -
src/wp-admin/includes/meta-boxes.php
364 364 <div class="jaxtag"> 365 365 <div class="nojs-tags hide-if-js"> 366 366 <p><?php echo $taxonomy->labels->add_or_remove_items; ?></p> 367 <textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php disabled( ! $user_can_assign_terms ); ?>><?php echo str_replace( ',', $comma . ' ', get_terms_to_edit( $post->ID, $tax_name )); // textarea_escaped by esc_attr() ?></textarea></div>367 <textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php disabled( ! $user_can_assign_terms ); ?>><?php echo get_terms_to_edit( $post->ID, $tax_name ); // textarea_escaped by esc_attr() ?></textarea></div> 368 368 <?php if ( $user_can_assign_terms ) : ?> 369 369 <div class="ajaxtag hide-if-no-js"> 370 370 <label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $box['title']; ?></label> -
src/wp-admin/js/post.js
14 14 (function($){ 15 15 16 16 tagBox = { 17 clean : function(tags) {18 var comma = postL10n.comma;19 if ( ',' !== comma )20 tags = tags.replace(new RegExp(comma, 'g'), ',');21 tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');22 if ( ',' !== comma )23 tags = tags.replace(/,/g, comma);24 return tags;25 },26 17 27 parseTags : function(el) { 28 var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'), 29 thetags = taxbox.find('.the-tags'), comma = postL10n.comma, 30 current_tags = thetags.val().split(comma), new_tags = []; 31 delete current_tags[num]; 18 quickClicks : function(el) { 19 20 var thetags = $('.the-tags', el); 21 var current_tags = this.getTagsFromString( thetags.val(), postL10n.comma ); 32 22 33 $.each( current_tags, function(key, val) { 34 val = $.trim(val); 35 if ( val ) { 36 new_tags.push(val); 37 } 38 }); 23 thetags.html(''); 24 $(el).data( 'tags',[]); 39 25 40 thetags.val( this.clean( new_tags.join(comma) ) ); 41 42 this.quickClicks(taxbox); 43 return false; 26 for (var i = current_tags.length - 1; i >= 0; i--) { 27 this.addTag( $(el), current_tags[i] ); 28 } 44 29 }, 45 30 46 quickClicks : function(el) { 47 var thetags = $('.the-tags', el), 48 tagchecklist = $('.tagchecklist', el), 49 id = $(el).attr('id'), 50 current_tags, disabled; 31 addTag: function( el, tag ) { 32 var span, xbutton, thetags = $('.the-tags', el), disabled, t = this; 51 33 52 if ( !thetags.length ) 34 tag = $.trim(tag) 35 36 if ( el.data( 'tags' ).indexOf( tag ) > -1 ) 53 37 return; 54 38 39 el.data( 'tags' ).push( tag ) 55 40 disabled = thetags.prop('disabled'); 56 41 57 current_tags = thetags.val().split(postL10n.comma); 58 tagchecklist.empty(); 42 // Create a new span, and ensure the text is properly escaped. 43 span = $('<span />').text( tag ); 44 span.append( jQuery( '<input type="hidden" name="' + thetags.attr('name') + '[]" />' ).val( tag ) ) 59 45 60 $.each( current_tags, function( key, val ) { 61 var span, xbutton; 46 // If tags editing isn't disabled, create the X button. 47 if ( ! disabled ) { 48 xbutton = $( '<a class="ntdelbutton">X</a>' ); 49 xbutton.click( function() { 50 span.remove(); 51 t.removeTag(el, tag); 52 }); 62 53 63 val = $.trim( val ); 54 span.prepend(' ').prepend( xbutton ); 55 } 64 56 65 if ( ! val ) 66 return; 57 el.find('.tagchecklist').append(span); 67 58 68 // Create a new span, and ensure the text is properly escaped. 69 span = $('<span />').text( val ); 59 }, 70 60 71 // If tags editing isn't disabled, create the X button. 72 if ( ! disabled ) { 73 xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' ); 74 xbutton.click( function(){ tagBox.parseTags(this); }); 75 span.prepend(' ').prepend( xbutton ); 76 } 77 78 // Append the span to the tag list. 79 tagchecklist.append( span ); 80 }); 61 removeTag: function( el, tag ) { 62 delete el.data('tags')[el.data('tags').indexOf(tag)] 81 63 }, 82 64 83 flushTags : function(el, a, f) { 84 a = a || false; 85 var tags = $('.the-tags', el), 86 newtag = $('input.newtag', el), 87 comma = postL10n.comma, 88 newtags, text; 65 getTagsFromString: function(tags_string, comma) { 89 66 90 text = a ? $(a).text() : newtag.val(); 91 tagsval = tags.val(); 92 newtags = tagsval ? tagsval + comma + text : text; 67 // pull out all quoted strings 68 var quoted_tags = tags_string.match( /("|')(.+?)\1/g ); 93 69 94 newtags = this.clean( newtags ); 95 newtags = array_unique_noempty( newtags.split(comma) ).join(comma); 96 tags.val(newtags); 97 this.quickClicks(el); 70 if ( quoted_tags ) { 71 for (var i = quoted_tags.length - 1; i >= 0; i--) { 72 tags_string = tags_string.replace( quoted_tags[i], '' ); 73 quoted_tags[i] = quoted_tags[i].substr( 1, quoted_tags[i].length - 2 ); 74 }; 75 } 98 76 99 if ( !a ) 100 newtag.val(''); 101 if ( 'undefined' == typeof(f) ) 102 newtag.focus(); 77 var tags = tags_string.split(comma); 103 78 104 return false; 79 if ( quoted_tags ) 80 return array_unique_noempty( quoted_tags.concat(tags) ); 81 82 return array_unique_noempty( tags ); 105 83 }, 106 84 85 submitAddTag: function(el) { 86 87 var newtag = $('input.newtag', el), 88 new_tags = this.getTagsFromString( newtag.val(), postL10n.comma ) 89 90 newtag.val(''); 91 92 for (var i = new_tags.length - 1; i >= 0; i--) { 93 this.addTag( $(el), new_tags[i] ); 94 } 95 }, 96 107 97 get : function(id) { 108 var tax = id.substr(id.indexOf('-')+1) ;98 var tax = id.substr(id.indexOf('-')+1), t = this; 109 99 110 100 $.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) { 111 101 if ( 0 == r || 'success' != stat ) … … 113 103 114 104 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>'); 115 105 $('a', r).click(function(){ 116 t agBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this);106 t.addTag( $(this).closest('.inside').children('.tagsdiv'), $(this).text() ) 117 107 return false; 118 108 }); 119 109 … … 129 119 }); 130 120 131 121 $('input.tagadd', ajaxtag).click(function(){ 132 t. flushTags( $(this).closest('.tagsdiv') );122 t.submitAddTag( $(this).closest('.tagsdiv') ); 133 123 }); 134 124 135 125 $('div.taghint', ajaxtag).click(function(){ … … 143 133 $(this).parent().siblings('.taghint').css('visibility', 'hidden'); 144 134 }).keyup(function(e){ 145 135 if ( 13 == e.which ) { 146 tagBox. flushTags( $(this).closest('.tagsdiv') );136 tagBox.submitAddTag( $(this).closest('.tagsdiv') ); 147 137 return false; 148 138 } 149 139 }).keypress(function(e){ … … 159 149 // save tags on post save/publish 160 150 $('#post').submit(function(){ 161 151 $('div.tagsdiv').each( function() { 162 t agBox.flushTags(this, false, 1);152 t.submitAddTag($(this)); 163 153 }); 164 154 }); 165 155 -
src/wp-includes/js/jquery/suggest.js
244 244 } else { 245 245 $currentVal = ""; 246 246 } 247 $input.val( $currentVal + $currentResult.text() + options.multipleSep); 247 248 if ( $currentResult.text().match( jQuery.trim( options.multipleSep ) ) ) 249 $input.val( $currentVal + '"' + $currentResult.text() + '"' + options.multipleSep); 250 else 251 $input.val( $currentVal + $currentResult.text() + options.multipleSep); 248 252 $input.focus(); 249 253 } else { 250 254 $input.val($currentResult.text());