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  
    55 * @subpackage jtpl_plugin 
    66 * @author 
    77 * @contributor Laurent Jouanneau (utf8 compliance) 
     8 * @contributor Yannick Le Guédart 
    89 * @copyright  2001-2003 ispi of Lincoln, Inc., 2007 Laurent Jouanneau 
     10 * @copyright 2008 Yannick Le Guédart 
    911 * @link http://smarty.php.net/ 
    1012 * @link http://jelix.org/ 
    1113 * @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 
     
    2830 * @return string 
    2931 */ 
    3032function jtpl_modifier_common_truncate($string, $length = 80, $etc = '...', 
    31                                   $break_words = false) 
     33                                                                  $break_words = false) 
    3234{ 
    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) 
    3450        return ''; 
    3551    $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)); 
    4052 
    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; 
    4258    } else 
    4359        return $string; 
    4460} 
     61 
    4562?> 
Download in other formats: Original Format