Changeset 2162 in subversion
- Timestamp:
- Dec 16, 2008 12:14:09 PM (4 years ago)
- Location:
- branches/release-0.2-beta
- Files:
-
- 3 edited
-
bin/html2text.php (modified) (1 diff)
-
bin/quotaimg.php (modified) (6 diffs)
-
program/lib/html2text.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/release-0.2-beta/bin/html2text.php
r1764 r2162 1 1 <?php 2 /* 2 3 3 define('INSTALL_PATH', realpath('./../') . '/'); 4 +-----------------------------------------------------------------------+ 5 | bin/html2text.php | 6 | | 7 | This file is part of the RoundCube Webmail client | 8 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland | 9 | Licensed under the GNU GPL | 10 | | 11 | PURPOSE: | 12 | Convert HTML message to plain text | 13 | | 14 +-----------------------------------------------------------------------+ 15 | Author: Thomas Bruederli <roundcube@gmail.com> | 16 +-----------------------------------------------------------------------+ 17 18 $Id: html2text.php 2070 2008-11-20 10:29:34Z alec $ 19 20 */ 21 22 define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/'); 4 23 require INSTALL_PATH.'program/include/iniset.php'; 5 24 6 $converter = new html2text( html_entity_decode($HTTP_RAW_POST_DATA, ENT_COMPAT, 'UTF-8'));25 $converter = new html2text($HTTP_RAW_POST_DATA); 7 26 8 27 header('Content-Type: text/plain; charset=UTF-8'); -
branches/release-0.2-beta/bin/quotaimg.php
r1776 r2162 2 2 /* 3 3 +-----------------------------------------------------------------------+ 4 | program/bin/quotaimg.php|4 | bin/quotaimg.php | 5 5 | | 6 6 | This file is part of the RoundCube Webmail client | 7 | Copyright (C) 2005-200 7, RoundCube Dev. - Switzerland |7 | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland | 8 8 | Licensed under the GNU GPL | 9 9 | | … … 15 15 +-----------------------------------------------------------------------+ 16 16 17 $Id :$17 $Id$ 18 18 19 19 */ 20 20 21 $used = ((isset($_GET['u']) && !empty($_GET['u'])) || $_GET['u']=='0')?(int)$_GET['u']:'??';22 $quota = ((isset($_GET['q']) && !empty($_GET['q'])) || $_GET['q']=='0')?(int)$_GET['q']:'??';23 $width = empty($_GET['w']) ? 100 : (int)$_GET['w'];24 $height = empty($_GET['h']) ? 14 : (int)$_GET['h'];21 $used = isset($_GET['u']) ? intval($_GET['u']) : '??'; 22 $quota = isset($_GET['q']) ? intval($_GET['q']) : '??'; 23 $width = empty($_GET['w']) ? 100 : min(300, intval($_GET['w'])); 24 $height = empty($_GET['h']) ? 14 : min(50, intval($_GET['h'])); 25 25 26 26 /** … … 97 97 if (ereg("^[^0-9?]*$", $used) || ereg("^[^0-9?]*$", $total)) { 98 98 return false; 99 }99 } 100 100 101 if (strpos($used, '?') !== false || strpos($total, '?') !== false 102 && $used != 0) { 101 if (strpos($used, '?') !== false || strpos($total, '?') !== false && $used != 0) { 103 102 $unknown = true; 104 }103 } 105 104 106 105 $im = imagecreate($width, $height); … … 154 153 $fill = imagecolorallocate($im, $r, $g, $b); 155 154 } else { 156 // if($quota >= $limit['low'])155 // if($quota >= $limit['low']) 157 156 list($r, $g, $b) = explode(',', $color['fill']['low']); 158 157 $fill = imagecolorallocate($im, $r, $g, $b); … … 164 163 $string = $quota . '%'; 165 164 $mid = floor(($width-(strlen($string)*imagefontwidth($font)))/2)+1; 166 // Print percent in black165 // Print percent in black 167 166 imagestring($im, $font, $mid, $padding, $string, $text); 168 167 } 169 168 170 169 header('Content-Type: image/gif'); 171 172 // @todo is harcoding GMT necessary? 173 header('Expires: ' . gmdate('D, d M Y H:i:s', mktime()+86400) . ' GMT');174 header(' Cache-Control:');175 header(' Pragma: ');170 171 // cache for 1 hour 172 $maxage = 3600; 173 header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$maxage). ' GMT'); 174 header('Cache-Control: max-age=' . $maxage); 176 175 177 176 imagegif($im); … … 179 178 } 180 179 181 genQuota($used, $quota, $width, $height); 180 if ($width > 1 && $height > 1) { 181 genQuota($used, $quota, $width, $height); 182 } 183 else { 184 header("HTTP/1.0 404 Not Found"); 185 } 186 182 187 exit; 183 188 ?> -
branches/release-0.2-beta/program/lib/html2text.php
r1711 r2162 150 150 '/<style[^>]*>.*?<\/style>/i', // <style>s -- which strip_tags supposedly has problems with 151 151 //'/<!-- .* -->/', // Comments -- which strip_tags might have problem a with 152 '/<h[123][^>]*>(.*?)<\/h[123]>/ie', // H1 - H3153 '/<h[456][^>]*>(.*?)<\/h[456]>/ie', // H4 - H6154 152 '/<p[^>]*>/i', // <P> 155 153 '/<br[^>]*>/i', // <br> 156 '/<b[^>]*>(.*?)<\/b>/ie', // <b>157 '/<strong[^>]*>(.*?)<\/strong>/ie', // <strong>158 154 '/<i[^>]*>(.*?)<\/i>/i', // <i> 159 155 '/<em[^>]*>(.*?)<\/em>/i', // <em> … … 162 158 '/<li[^>]*>(.*?)<\/li>/i', // <li> and </li> 163 159 '/<li[^>]*>/i', // <li> 164 '/<a [^>]*href=("|\')([^"\']+)\1[^>]*>(.*?)<\/a>/ie',165 // <a href="">166 160 '/<hr[^>]*>/i', // <hr> 167 161 '/(<table[^>]*>|<\/table>)/i', // <table> and </table> 168 162 '/(<tr[^>]*>|<\/tr>)/i', // <tr> and </tr> 169 163 '/<td[^>]*>(.*?)<\/td>/i', // <td> and </td> 170 '/<th[^>]*>(.*?)<\/th>/ie', // <th> and </th>171 164 '/&(nbsp|#160);/i', // Non-breaking space 172 165 '/&(quot|rdquo|ldquo|#8220|#8221|#147|#148);/i', … … 202 195 '', // <style>s -- which strip_tags supposedly has problems with 203 196 //'', // Comments -- which strip_tags might have problem a with 204 "strtoupper(\"\n\n\\1\n\n\")", // H1 - H3205 "ucwords(\"\n\n\\1\n\")", // H4 - H6206 197 "\n\n", // <P> 207 198 "\n", // <br> 208 'strtoupper("\\1")', // <b>209 'strtoupper("\\1")', // <strong>210 199 '_\\1_', // <i> 211 200 '_\\1_', // <em> … … 214 203 "\t* \\1\n", // <li> and </li> 215 204 "\n\t* ", // <li> 216 '$this->_build_link_list("\\2", "\\3")',217 // <a href="">218 205 "\n-------------------------\n", // <hr> 219 206 "\n\n", // <table> and </table> 220 207 "\n", // <tr> and </tr> 221 208 "\t\t\\1\n", // <td> and </td> 222 "strtoupper(\"\t\t\\1\n\")", // <th> and </th>223 209 ' ', // Non-breaking space 224 210 '"', // Double quotes … … 233 219 '-', 234 220 '*', 235 ' £',221 '£', 236 222 'EUR', // Euro sign. ? 237 223 '', // Unknown/unhandled entities 238 224 ' ' // Runs of spaces, post-handling 225 ); 226 227 /** 228 * List of preg* regular expression patterns to search for 229 * and replace using callback function. 230 * 231 * @var array $callback_search 232 * @access public 233 */ 234 var $callback_search = array( 235 '/<(h)[123456][^>]*>(.*?)<\/h[123456]>/i', // H1 - H3 236 '/<(b)[^>]*>(.*?)<\/b>/i', // <b> 237 '/<(strong)[^>]*>(.*?)<\/strong>/i', // <strong> 238 '/<(a) [^>]*href=("|\')([^"\']+)\2[^>]*>(.*?)<\/a>/i', 239 // <a href=""> 240 '/<(th)[^>]*>(.*?)<\/th>/i', // <th> and </th> 239 241 ); 240 242 … … 466 468 // Convert <PRE> 467 469 $this->_convert_pre($text); 468 470 471 // Replace known html entities 472 $text = html_entity_decode($text, ENT_COMPAT, 'UTF-8'); 473 469 474 // Run our defined search-and-replace 470 475 $text = preg_replace($this->search, $this->replace, $text); 476 $text = preg_replace_callback($this->callback_search, array('html2text', '_preg_callback'), $text); 471 477 472 478 // Strip any other HTML tags … … 544 550 { 545 551 $result = preg_replace($this->pre_search, $this->pre_replace, $matches[1]); 546 $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text );552 $text = preg_replace('/<pre[^>]*>.*<\/pre>/ismU', '<div><br>' . $result . '<br></div>', $text, 1); 547 553 } 548 554 } 555 556 /** 557 * Callback function for preg_replace_callback use. 558 * 559 * @param array PREG matches 560 * @return string 561 * @access private 562 */ 563 function _preg_callback($matches) 564 { 565 switch($matches[1]) 566 { 567 case 'b': 568 case 'strong': 569 return $this->_strtoupper($matches[2]); 570 case 'hr': 571 return $this->_strtoupper("\t\t". $matches[2] ."\n"); 572 case 'h': 573 return $this->_strtoupper("\n\n". $matches[2] ."\n\n"); 574 case 'a': 575 return $this->_build_link_list($matches[3], $matches[4]); 576 } 577 } 578 579 /** 580 * Strtoupper multibyte wrapper function 581 * 582 * @param string 583 * @return string 584 * @access private 585 */ 586 function _strtoupper($str) 587 { 588 if (function_exists('mb_strtoupper')) 589 return mb_strtoupper($str); 590 else 591 return strtoupper($str); 592 } 549 593 } 550 594
Note: See TracChangeset
for help on using the changeset viewer.
