Ticket #18311: 18311-6.patch
File 18311-6.patch, 9.5 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/media.php
145 145 146 146 $caption = str_replace( array("\r\n", "\r"), "\n", $caption); 147 147 $caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption ); 148 $caption = preg_replace( '/\n+/', '<br />', str_replace('"', '"', $caption) ); 148 // convert any remaining line breaks to <br> 149 $caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption ); 149 150 150 151 $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html ); 151 152 if ( empty($align) ) 152 153 $align = 'none'; 153 154 154 $shcode = '[caption id="' . $id . '" align="align' . $align 155 . '" width="' . $width . '" caption="' . $caption . '"]' . $html . '[/caption]'; 155 $shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]'; 156 156 157 157 return apply_filters( 'image_add_caption_shortcode', $shcode, $html ); 158 158 } … … 166 166 */ 167 167 function _cleanup_image_add_caption( $matches ) { 168 168 // remove any line breaks from inside the tags 169 $s = preg_replace( '/[\r\n\t]+/', ' ', $matches[0] ); 170 // look for single quotes inside html attributes (for example in title) 171 $s = preg_replace_callback( '/="[^"]+"/', '_cleanup_image_add_caption_callback', $s ); 172 return str_replace( '"', "'", $s ); 169 return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] ); 173 170 } 174 171 175 172 /** 176 * Private preg_replace callback used in _cleanup_image_add_caption()177 *178 * @access private179 * @since 3.4.0180 */181 function _cleanup_image_add_caption_callback( $matches ) {182 return str_replace( "'", ''', $matches[0] );183 }184 185 /**186 173 * {@internal Missing Short Description}} 187 174 * 188 175 * @since 2.5.0 … … 1541 1528 if ( f.caption.value ) { 1542 1529 caption = f.caption.value.replace(/\r\n|\r/g, '\n'); 1543 1530 caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ 1544 a = a.replace(/[\r\n\t]+/, ' ').replace(/="[^"]+"/, function(b){ 1545 return b.replace(/'/g, '''); 1546 }); 1547 return a.replace(/"/g, "'"); 1531 return a.replace(/[\r\n\t]+/, ' '); 1548 1532 }); 1549 1533 1550 caption = caption.replace(/\ n+/g, '<br />').replace(/"/g, '"');1534 caption = caption.replace(/\s*\n\s*/g, '<br />'); 1551 1535 } 1552 1536 <?php } ?> 1553 1537 … … 1561 1545 } 1562 1546 1563 1547 if ( caption ) 1564 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';1548 html = '[caption id="" align="'+t.align+'" width="'+t.width+'"]'+html+caption+'[/caption]'; 1565 1549 1566 1550 var win = window.dialogArguments || opener || parent || top; 1567 1551 win.send_to_editor(html); -
wp-admin/js/editor.dev.js
73 73 }); 74 74 } 75 75 76 // keep <br> tags inside captions 76 // keep <br> tags inside captions and remove line breaks 77 77 if ( content.indexOf('[caption') != -1 ) { 78 78 preserve_br = true; 79 content = content.replace(/\[caption[ ^\]]+\]/g, function(a) {80 return a.replace(/<br([^>]*)> [\r\n]*/g, '<wp-temp-br$1>');79 content = content.replace(/\[caption[\s\S]+?\[\/caption\]/g, function(a) { 80 return a.replace(/<br([^>]*)>/g, '<wp-temp-br$1>').replace(/[\r\n\t]+/, ''); 81 81 }); 82 82 } 83 83 … … 139 139 }, 140 140 141 141 _wp_Autop : function(pee) { 142 var blocklist = 'table|thead|tfoot|tbody|tr|td|th|caption|col|colgroup|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]|fieldset|legend|hr|noscript|menu|samp|header|footer|article|section|hgroup|nav|aside|details|summary'; 142 var preserve_linebreaks = false, preserve_br = false, 143 blocklist = 'table|thead|tfoot|tbody|tr|td|th|caption|col|colgroup|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]|fieldset|legend|hr|noscript|menu|samp|header|footer|article|section|hgroup|nav|aside|details|summary'; 143 144 144 145 if ( pee.indexOf('<object') != -1 ) { 145 146 pee = pee.replace(/<object[\s\S]+?<\/object>/g, function(a){ … … 153 154 154 155 // Protect pre|script tags 155 156 if ( pee.indexOf('<pre') != -1 || pee.indexOf('<script') != -1 ) { 157 preserve_linebreaks = true; 156 158 pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) { 157 return a.replace(/(\r\n|\n)/g, '<wp _temp_br>');159 return a.replace(/(\r\n|\n)/g, '<wp-temp-lb>'); 158 160 }); 159 161 } 160 162 163 // keep <br> tags inside captions and convert line breaks 164 if ( pee.indexOf('[caption') != -1 ) { 165 preserve_br = true; 166 pee = pee.replace(/\[caption[\s\S]+?\[\/caption\]/g, function(a) { 167 // keep existing <br> 168 a = a.replace(/<br([^>]*)>/g, '<wp-temp-br$1>'); 169 // no line breaks inside HTML tags 170 a = a.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(b){ 171 return b.replace(/[\r\n\t]+/, ' '); 172 }); 173 // convert remaining line breaks to <br> 174 return a.replace(/\s*\n\s*/g, '<wp-temp-br />'); 175 }); 176 } 177 161 178 pee = pee + '\n\n'; 162 179 pee = pee.replace(/<br \/>\s*<br \/>/gi, '\n\n'); 163 180 pee = pee.replace(new RegExp('(<(?:'+blocklist+')(?: [^>]*)?>)', 'gi'), '\n$1'); … … 186 203 }); 187 204 188 205 // put back the line breaks in pre|script 189 pee = pee.replace(/<wp_temp_br>/g, '\n'); 206 if ( preserve_linebreaks ) 207 pee = pee.replace(/<wp-temp-lb>/g, '\n'); 190 208 209 if ( preserve_br ) 210 pee = pee.replace(/<wp-temp-br([^>]*)>/g, '<br$1>'); 211 191 212 return pee; 192 213 }, 193 214 -
wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js
139 139 140 140 _do_shcode : function(content) { 141 141 return content.replace(/(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g, function(a,b,c){ 142 var id, cls, w, cap, div_cls ;142 var id, cls, w, cap, div_cls, img, trim = tinymce.trim; 143 143 144 144 id = b.match(/id=['"]([^'"]*)['"] ?/); 145 145 b = b.replace(id[0], ''); … … 150 150 w = b.match(/width=['"]([0-9]*)['"] ?/); 151 151 b = b.replace(w[0], ''); 152 152 153 cap = tinymce.trim(b).replace(/caption=['"]/, '').replace(/['"]$/, ''); 153 c = tinymce.trim(c); 154 img = c.match(/((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)([\s\S]*)/i); 154 155 156 if ( img && img[2] ) { 157 cap = trim( img[2] ); 158 img = trim( img[1] ); 159 } else { 160 // old captions shortcode style 161 cap = trim(b).replace(/caption=['"]/, '').replace(/['"]$/, ''); 162 img = c; 163 } 164 155 165 id = ( id && id[1] ) ? id[1] : ''; 156 166 cls = ( cls && cls[1] ) ? cls[1] : 'alignnone'; 157 167 w = ( w && w[1] ) ? w[1] : ''; … … 164 174 div_cls += ' mceIEcenter'; 165 175 166 176 return '<div class="'+div_cls+'"><dl id="'+id+'" class="wp-caption '+cls+'" style="width: '+( 10 + parseInt(w) )+ 167 'px"><dt class="wp-caption-dt">'+ c+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>';177 'px"><dt class="wp-caption-dt">'+img+'</dt><dd class="wp-caption-dd">'+cap+'</dd></dl></div>'; 168 178 }); 169 179 }, 170 180 … … 187 197 cls = cls.match(/align[a-z]+/) || 'alignnone'; 188 198 189 199 cap = cap.replace(/\r\n|\r/g, '\n').replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ 190 a = a.replace(/[\r\n\t]+/, ' ').replace(/="[^"]+"/, function(b){ 191 return b.replace(/'/g, '''); 192 }); 193 return a.replace(/"/g, "'"); 200 // no line breaks inside HTML tags 201 return a.replace(/[\r\n\t]+/, ' '); 194 202 }); 195 203 196 cap = cap.replace(/\n+/g, '<br />').replace(/"/g, '"'); 204 // convert remaining line breaks to <br> 205 cap = cap.replace(/\s*\n\s*/g, '<br />'); 197 206 198 return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]';207 return '[caption id="'+id+'" align="'+cls+'" width="'+w+'"]'+c+' '+cap+'[/caption]'; 199 208 }); 200 209 201 210 if ( ret.indexOf('[caption') !== 0 ) { -
wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.dev.js
419 419 caption = f.img_cap_text.value; 420 420 421 421 caption = caption.replace(/\r\n|\r/g, '\n').replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ 422 a = a.replace(/[\r\n\t]+/, ' ').replace(/="[^"]+"/, function(b){ 423 return b.replace(/'/g, '''); 424 }); 425 return a.replace(/"/g, "'"); 422 return a.replace(/[\r\n\t]+/, ' '); 426 423 }); 427 424 428 caption = caption.replace(/\ n+/g, '<br />').replace(/"/g, '"');425 caption = caption.replace(/\s*\n\s*/g, '<br />'); 429 426 430 427 if ( DL ) { 431 428 ed.dom.setAttribs(DL, { -
wp-includes/media.php
724 724 * @return string 725 725 */ 726 726 function img_caption_shortcode($attr, $content = null) { 727 // New-style shortcode with the caption inside the shortcode with the link and image tags. 728 if ( ! isset( $attr['caption'] ) ) { 729 preg_match( '#(<a\s.*?<img\s.*?</a>)(.*)#is', $content, $matches ) || preg_match( '#(<img\s.*?>)(.*)#is', $content, $matches ); 730 if ( $matches ) { 731 $content = $matches[1]; 732 $attr['caption'] = trim( $matches[2] ); 733 } 734 } 727 735 728 736 // Allow plugins/themes to override the default caption template. 729 737 $output = apply_filters('img_caption_shortcode', '', $attr, $content);