Changeset 5497 in subversion
- Timestamp:
- Nov 28, 2011 3:10:44 AM (18 months ago)
- Location:
- trunk/roundcubemail
- Files:
-
- 3 edited
-
CHANGELOG (modified) (1 diff)
-
program/js/app.js (modified) (1 diff)
-
program/lib/html2text.php (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/CHANGELOG
r5496 r5497 2 2 =========================== 3 3 4 - Fix handling HTML entities when converting HTML to text (#1488212) 4 5 - Fix fit_string_to_size() renders browser and ui unresponsive (#1488207) 5 6 - Fix handling of invalid characters in request (#1488124) -
trunk/roundcubemail/program/js/app.js
r5488 r5497 5766 5766 }; 5767 5767 5768 this.plain2html = function(plain Text, id)5768 this.plain2html = function(plain, id) 5769 5769 { 5770 5770 var lock = this.set_busy(true, 'converting'); 5771 $('#'+id).val(plainText ? '<pre>'+plainText+'</pre>' : ''); 5771 5772 plain = plain.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); 5773 $('#'+id).val(plain ? '<pre>'+plain+'</pre>' : ''); 5774 5772 5775 this.set_busy(false, null, lock); 5773 5776 }; -
trunk/roundcubemail/program/lib/html2text.php
r4722 r5497 146 146 "/\r/", // Non-legal carriage return 147 147 "/[\n\t]+/", // Newlines and tabs 148 '/[ ]{2,}/', // Runs of spaces, pre-handling149 148 '/<script[^>]*>.*?<\/script>/i', // <script>s -- which strip_tags supposedly has problems with 150 149 '/<style[^>]*>.*?<\/style>/i', // <style>s -- which strip_tags supposedly has problems with … … 162 161 '/(<tr[^>]*>|<\/tr>)/i', // <tr> and </tr> 163 162 '/<td[^>]*>(.*?)<\/td>/i', // <td> and </td> 163 ); 164 165 /** 166 * List of pattern replacements corresponding to patterns searched. 167 * 168 * @var array $replace 169 * @access public 170 * @see $search 171 */ 172 var $replace = array( 173 '', // Non-legal carriage return 174 ' ', // Newlines and tabs 175 '', // <script>s -- which strip_tags supposedly has problems with 176 '', // <style>s -- which strip_tags supposedly has problems with 177 "\n\n", // <P> 178 "\n", // <br> 179 '_\\1_', // <i> 180 '_\\1_', // <em> 181 "\n\n", // <ul> and </ul> 182 "\n\n", // <ol> and </ol> 183 "\t* \\1\n", // <li> and </li> 184 "\n\t* ", // <li> 185 "\n-------------------------\n", // <hr> 186 "<div>\n", // <div> 187 "\n\n", // <table> and </table> 188 "\n", // <tr> and </tr> 189 "\t\t\\1\n", // <td> and </td> 190 ); 191 192 /** 193 * List of preg* regular expression patterns to search for, 194 * used in conjunction with $ent_replace. 195 * 196 * @var array $ent_search 197 * @access public 198 * @see $ent_replace 199 */ 200 var $ent_search = array( 164 201 '/&(nbsp|#160);/i', // Non-breaking space 165 202 '/&(quot|rdquo|ldquo|#8220|#8221|#147|#148);/i', … … 177 214 '/&(euro|#8364);/i', // Euro sign 178 215 '/&(amp|#38);/i', // Ampersand: see _converter() 179 '/[ ]{2,}/' // Runs of spaces, post-handling216 '/[ ]{2,}/', // Runs of spaces, post-handling 180 217 ); 181 218 … … 183 220 * List of pattern replacements corresponding to patterns searched. 184 221 * 185 * @var array $replace 186 * @access public 187 * @see $search 188 */ 189 var $replace = array( 190 '', // Non-legal carriage return 191 ' ', // Newlines and tabs 192 ' ', // Runs of spaces, pre-handling 193 '', // <script>s -- which strip_tags supposedly has problems with 194 '', // <style>s -- which strip_tags supposedly has problems with 195 "\n\n", // <P> 196 "\n", // <br> 197 '_\\1_', // <i> 198 '_\\1_', // <em> 199 "\n\n", // <ul> and </ul> 200 "\n\n", // <ol> and </ol> 201 "\t* \\1\n", // <li> and </li> 202 "\n\t* ", // <li> 203 "\n-------------------------\n", // <hr> 204 "<div>\n", // <div> 205 "\n\n", // <table> and </table> 206 "\n", // <tr> and </tr> 207 "\t\t\\1\n", // <td> and </td> 222 * @var array $ent_replace 223 * @access public 224 * @see $ent_search 225 */ 226 var $ent_replace = array( 208 227 ' ', // Non-breaking space 209 228 '"', // Double quotes … … 220 239 'EUR', // Euro sign. ? 221 240 '|+|amp|+|', // Ampersand: see _converter() 222 ' ' // Runs of spaces, post-handling241 ' ', // Runs of spaces, post-handling 223 242 ); 224 243 … … 304 323 */ 305 324 var $_link_list = ''; 306 325 307 326 /** 308 327 * Number of valid links detected in the text, used for plain text … … 315 334 var $_link_count = 0; 316 335 317 /** 318 * Boolean flag, true if a table of link URLs should be listed after the text. 319 * 320 * @var boolean $_do_links 321 * @access private 322 * @see html2text() 336 /** 337 * Boolean flag, true if a table of link URLs should be listed after the text. 338 * 339 * @var boolean $_do_links 340 * @access private 341 * @see html2text() 323 342 */ 324 343 var $_do_links = true; 325 344 326 345 /** 327 346 * Constructor. … … 493 512 $this->_convert_pre($text); 494 513 495 // Run our defined search-and-replace514 // Run our defined tags search-and-replace 496 515 $text = preg_replace($this->search, $this->replace, $text); 516 517 // Run our defined tags search-and-replace with callback 518 $text = preg_replace_callback($this->callback_search, array('html2text', '_preg_callback'), $text); 519 520 // Strip any other HTML tags 521 $text = strip_tags($text, $this->allowed_tags); 522 523 // Run our defined entities/characters search-and-replace 524 $text = preg_replace($this->ent_search, $this->ent_replace, $text); 497 525 498 526 // Replace known html entities 499 527 $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); 500 501 // Run our defined search-and-replace with callback502 $text = preg_replace_callback($this->callback_search, array('html2text', '_preg_callback'), $text);503 528 504 529 // Remove unknown/unhandled entities (this cannot be done in search-and-replace block) … … 509 534 $text = str_replace('|+|amp|+|', '&', $text); 510 535 511 // Strip any other HTML tags512 $text = strip_tags($text, $this->allowed_tags);513 514 536 // Bring down number of empty lines to 2 max 515 537 $text = preg_replace("/\n\s+\n/", "\n\n", $text); … … 517 539 518 540 // remove leading empty lines (can be produced by eg. P tag on the beginning) 519 $text = preg_replace('/^\n+/', '', $text);541 $text = ltrim($text, "\n"); 520 542 521 543 // Wrap the text to a readable format … … 545 567 return $display; 546 568 547 if ( substr($link, 0, 7) == 'http://' || substr($link, 0, 8) == 'https://' || 548 substr($link, 0, 7) == 'mailto:' 549 ) { 569 if ( preg_match('!^(https?://|mailto:)!', $link) ) { 550 570 $this->_link_count++; 551 571 $this->_link_list .= '[' . $this->_link_count . "] $link\n";
Note: See TracChangeset
for help on using the changeset viewer.
