Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: patTemplate

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /pattemplate/patTemplate/Modifier/Truncate.php

Documentation is available at Truncate.php

  1. <?php
  2. /**
  3.  * patTemplate modifier Truncate
  4.  *
  5.  * Truncate a string variable to fixed length and add a suffix if it was truncated.
  6.  * It can also start from an offset and add a prefix.
  7.  *
  8.  * @package     patTemplate
  9.  * @subpackage  Modifiers
  10.  * @author      Rafa Couto <[email protected]>
  11.  */
  12.  
  13. // Check to ensure this file is within the rest of the framework
  14. defined('JPATH_BASE'or die();
  15.  
  16. /**
  17.  * patTemplate modifier Truncate
  18.  *
  19.  * Truncate a string variable to fixed length and add a suffix if it was truncated.
  20.  * It can also start from an offset and add a prefix.
  21.  *
  22.  * Possible attributes are:
  23.  * - length (integer)
  24.  * - suffix (string)
  25.  * - start
  26.  * - prefix (string)
  27.  *
  28.  * @package     patTemplate
  29.  * @subpackage  Modifiers
  30.  * @author      Rafa Couto <[email protected]>
  31.  */
  32. {
  33.  
  34.    /**
  35.     * modify the value
  36.     *
  37.     * @access  public
  38.     * @param  string    value
  39.     * @return  string    modified value
  40.     */
  41.     function modify($value$params array())
  42.     {
  43.         // length
  44.         if (!isset$params['length'])) {
  45.             return $value;
  46.         }
  47.         settype($params['length']'integer');
  48.  
  49.         $decode = isset$params['htmlsafe');
  50.            if (function_exists'html_entity_decode' && $decode{
  51.             $value html_entity_decode$value );
  52.         }
  53.  
  54.         // start
  55.         if (isset($params['start'])) {
  56.             settype$params['start']'integer' );
  57.         else {
  58.             $params['start'0;
  59.         }
  60.  
  61.         // prefix
  62.         if (isset($params['prefix'])) {
  63.             $prefix ($params['start'== '' $params['prefix']);
  64.         else {
  65.             $prefix '';
  66.         }
  67.  
  68.         // suffix
  69.         if (isset($params['suffix'])) {
  70.             $suffix $params['suffix'];
  71.         else {
  72.             $suffix '';
  73.         }
  74.  
  75.         $initial_len strlen($value);
  76.         $value substr($value$params['start']$params['length']);
  77.  
  78.         if ($initial_len <= strlen($value)) {
  79.             $suffix '';
  80.         }
  81.  
  82.         $value $prefix.$value.$suffix;
  83.  
  84.         return $decode htmlspecialchars$valueENT_QUOTES $value;
  85.     }
  86. }
  87. ?>

Documentation generated on Mon, 05 Mar 2007 21:29:48 +0000 by phpDocumentor 1.3.1