Changeset 20679
- Timestamp:
- 05/02/2012 01:14:52 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/media.php
r20544 r20679 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 ); … … 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 ); … … 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 ); 173 } 174 175 /** 176 * Private preg_replace callback used in _cleanup_image_add_caption() 177 * 178 * @access private 179 * @since 3.4.0 180 */ 181 function _cleanup_image_add_caption_callback( $matches ) { 182 return str_replace( "'", ''', $matches[0] ); 169 return preg_replace( '/[\r\n\t]+/', ' ', $matches[0] ); 183 170 } 184 171 … … 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 } ?> … … 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; -
trunk/wp-admin/js/editor.dev.js
r20174 r20679 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 } … … 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 ) { … … 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>'); 160 }); 161 } 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 />'); 158 175 }); 159 176 } … … 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'); 208 209 if ( preserve_br ) 210 pee = pee.replace(/<wp-temp-br([^>]*)>/g, '<br$1>'); 190 211 191 212 return pee; -
trunk/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js
r20174 r20679 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=['"]([^'"]*)['"] ?/); … … 151 151 b = b.replace(w[0], ''); 152 152 153 cap = tinymce.trim(b).replace(/caption=['"]/, '').replace(/['"]$/, ''); 153 c = trim(c); 154 img = c.match(/((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)([\s\S]*)/i); 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 } 154 164 155 165 id = ( id && id[1] ) ? id[1] : ''; … … 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 }, … … 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, '"'); 197 198 return '[caption id="'+id+'" align="'+cls+'" width="'+w+'" caption="'+cap+'"]'+c+'[/caption]'; 204 // convert remaining line breaks to <br> 205 cap = cap.replace(/\s*\n\s*/g, '<br />'); 206 207 return '[caption id="'+id+'" align="'+cls+'" width="'+w+'"]'+c+' '+cap+'[/caption]'; 199 208 }); 200 209 -
trunk/wp-includes/js/tinymce/plugins/wpeditimage/js/editimage.dev.js
r20341 r20679 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 ) { -
trunk/wp-includes/media.php
r20562 r20679 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 if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) { 730 $content = $matches[1]; 731 $attr['caption'] = trim( $matches[2] ); 732 } 733 } 727 734 728 735 // Allow plugins/themes to override the default caption template.
Note: See TracChangeset
for help on using the changeset viewer.