| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
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 <rafacouto@yahoo.com> 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 <rafacouto@yahoo.com> 31 */ 32 class patTemplate_Modifier_Truncate extends patTemplate_Modifier 33 { 34 35 /** 36 * modify the value 37 * 38 * @access public 39 * @param string value 40 * @return string modified value 41 */ 42 function modify($value, $params = array()) 43 { 44 // length 45 if (!isset( $params['length'])) { 46 return $value; 47 } 48 settype($params['length'], 'integer'); 49 50 $decode = isset( $params['htmlsafe'] ); 51 if (function_exists( 'html_entity_decode' ) && $decode) { 52 $value = html_entity_decode( $value ); 53 } 54 55 // start 56 if (isset($params['start'])) { 57 settype( $params['start'], 'integer' ); 58 } else { 59 $params['start'] = 0; 60 } 61 62 // prefix 63 if (isset($params['prefix'])) { 64 $prefix = ($params['start'] == 0 ? '' : $params['prefix']); 65 } else { 66 $prefix = ''; 67 } 68 69 // suffix 70 if (isset($params['suffix'])) { 71 $suffix = $params['suffix']; 72 } else { 73 $suffix = ''; 74 } 75 76 $initial_len = strlen($value); 77 $value = substr($value, $params['start'], $params['length']); 78 79 if ($initial_len <= strlen($value)) { 80 $suffix = ''; 81 } 82 83 $value = $prefix.$value.$suffix; 84 85 return $decode ? htmlspecialchars( $value, ENT_QUOTES ) : $value; 86 } 87 } 88 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |