Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file modifier.truncate.php

Documentation is available at modifier.truncate.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8.  
  9. /**
  10.  * Smarty truncate modifier plugin
  11.  *
  12.  * Type:     modifier<br>
  13.  * Name:     truncate<br>
  14.  * Purpose:  Truncate a string to a certain length if necessary,
  15.  *           optionally splitting in the middle of a word, and
  16.  *           appending the $etc string.
  17.  * @link http://smarty.php.net/manual/en/language.modifier.truncate.php
  18.  *           truncate (Smarty online manual)
  19.  * @param string 
  20.  * @param integer 
  21.  * @param string 
  22.  * @param boolean 
  23.  * @param string 
  24.  * @return string 
  25.  */
  26. function smarty_modifier_truncate($string$length 80$etc '...'$break_words false$divId=''{
  27.     if ($length == 0)
  28.         return '';
  29.  
  30.     if (strlen($string$length{
  31.         $length -= strlen($etc);
  32.         if ($break_words// break the word
  33.             $fragment mb_substr($string0$length);
  34.         else {
  35.             $fragment mb_substr($string0$length 1);
  36.             $fragment preg_replace('/\s+(\S+)?$/'''$fragment);
  37.         }
  38.         if (!empty($divId)) {
  39.             $etc "<span  style='display:inline;' id='dyn_".$divId."_display'><a class='truncate' onclick='javascript:toggle_dynamic_var(\"$divId\");' title='".tra('Click to see the full text')."'>$etc</a></span>";
  40.             $etc .= "<span style='display:none;' id='dyn_".$divId."_edit'>".substr($stringstrlen($fragment))."</span>";
  41.         }
  42.         return $fragment.$etc;
  43.     else
  44.         return $string;
  45. }
  46.  
  47. /* vim: set expandtab: */
  48.  
  49. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:10 +0000 by phpDocumentor 1.5.0-lsces