Ticket #511: patch-#511.diff
| File patch-#511.diff, 2.0 kB (added by bastnic, 7 months ago) |
|---|
-
lib/jelix/plugins/tpl/common/modifier.truncate.php
old new 5 5 * @subpackage jtpl_plugin 6 6 * @author 7 7 * @contributor Laurent Jouanneau (utf8 compliance) 8 * @contributor Yannick Le Guédart 8 9 * @copyright 2001-2003 ispi of Lincoln, Inc., 2007 Laurent Jouanneau 10 * @copyright 2008 Yannick Le Guédart 9 11 * @link http://smarty.php.net/ 10 12 * @link http://jelix.org/ 11 13 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html … … 28 30 * @return string 29 31 */ 30 32 function jtpl_modifier_common_truncate($string, $length = 80, $etc = '...', 31 $break_words = false)33 $break_words = false) 32 34 { 33 if ($length == 0) 35 if (function_exists ('mb_strlen')) { 36 $f_strlen = 'mb_strlen'; 37 } 38 else { 39 $f_strlen = 'iconv_strlen'; 40 } 41 42 if (function_exists ('mb_substr')) { 43 $f_substr = 'mb_substr'; 44 } 45 else { 46 $f_substr = 'iconv_substr'; 47 } 48 49 if($length == 0) 34 50 return ''; 35 51 $charset = jTpl::getEncoding(); 36 if (iconv_strlen($string,$charset) > $length) {37 $length -= iconv_strlen($etc,$charset);38 if (!$break_words)39 $string = preg_replace('/\s+?(\S+)?$/', '', iconv_substr($string, 0, $length+1,$charset));40 52 41 return iconv_substr($string, 0, $length,$charset).$etc; 53 if($f_strlen ($string,$charset) > $length) { 54 $length -= $f_strlen($etc,$charset); 55 if(!$break_words) 56 $string = preg_replace('/\s+?(\S+)?$/', '', $f_substr($string, 0, $length+1,$charset)); 57 return $f_substr($string, 0, $length,$charset).$etc; 42 58 } else 43 59 return $string; 44 60 } 61 45 62 ?>
