Changeset 23384 for trunk/include/smarty/libs/plugins/function.cycle.php
- Timestamp:
- Jun 20, 2013, 5:38:47 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/smarty/libs/plugins/function.cycle.php
r3282 r23384 2 2 /** 3 3 * Smarty plugin 4 * 4 5 * @package Smarty 5 * @subpackage plugins6 * @subpackage PluginsFunction 6 7 */ 7 8 … … 13 14 * Date: May 3, 2002<br> 14 15 * Purpose: cycle through given values<br> 15 * Input: 16 * - name = name of cycle (optional) 17 * - values = comma separated list of values to cycle, 18 * or an array of values to cycle 19 * (this can be left out for subsequent calls) 20 * - reset = boolean - resets given var to true 21 * - print = boolean - print var or not. default is true 22 * - advance = boolean - whether or not to advance the cycle 23 * - delimiter = the value delimiter, default is "," 24 * - assign = boolean, assigns to template var instead of 25 * printed. 26 * 16 * Params: 17 * <pre> 18 * - name - name of cycle (optional) 19 * - values - comma separated list of values to cycle, or an array of values to cycle 20 * (this can be left out for subsequent calls) 21 * - reset - boolean - resets given var to true 22 * - print - boolean - print var or not. default is true 23 * - advance - boolean - whether or not to advance the cycle 24 * - delimiter - the value delimiter, default is "," 25 * - assign - boolean, assigns to template var instead of printed. 26 * </pre> 27 27 * Examples:<br> 28 28 * <pre> … … 31 31 * {cycle name=row} 32 32 * </pre> 33 * @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle} 33 * 34 * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} 34 35 * (Smarty online manual) 35 36 * @author Monte Ohrt <monte at ohrt dot com> … … 38 39 * @author credit to Jason Sweat <jsweat_php@yahoo.com> 39 40 * @version 1.3 40 * @param array 41 * @param Smarty 41 * @param array $params parameters 42 * @param Smarty_Internal_Template $template template object 42 43 * @return string|null 43 44 */ 44 function smarty_function_cycle($params, &$smarty) 45 46 function smarty_function_cycle($params, $template) 45 47 { 46 48 static $cycle_vars; 47 49 48 50 $name = (empty($params['name'])) ? 'default' : $params['name']; 49 51 $print = (isset($params['print'])) ? (bool)$params['print'] : true; 50 52 $advance = (isset($params['advance'])) ? (bool)$params['advance'] : true; 51 53 $reset = (isset($params['reset'])) ? (bool)$params['reset'] : false; 52 53 if (!i n_array('values', array_keys($params))) {54 55 if (!isset($params['values'])) { 54 56 if(!isset($cycle_vars[$name]['values'])) { 55 $smarty->trigger_error("cycle: missing 'values' parameter");57 trigger_error("cycle: missing 'values' parameter"); 56 58 return; 57 59 } … … 64 66 } 65 67 66 $cycle_vars[$name]['delimiter'] = (isset($params['delimiter'])) ? $params['delimiter'] : ','; 67 68 if (isset($params['delimiter'])) { 69 $cycle_vars[$name]['delimiter'] = $params['delimiter']; 70 } elseif (!isset($cycle_vars[$name]['delimiter'])) { 71 $cycle_vars[$name]['delimiter'] = ','; 72 } 73 68 74 if(is_array($cycle_vars[$name]['values'])) { 69 75 $cycle_array = $cycle_vars[$name]['values']; … … 71 77 $cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']); 72 78 } 73 79 74 80 if(!isset($cycle_vars[$name]['index']) || $reset ) { 75 81 $cycle_vars[$name]['index'] = 0; 76 82 } 77 83 78 84 if (isset($params['assign'])) { 79 85 $print = false; 80 $ smarty->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]);86 $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); 81 87 } 82 88 83 89 if($print) { 84 90 $retval = $cycle_array[$cycle_vars[$name]['index']]; … … 94 100 } 95 101 } 96 102 97 103 return $retval; 98 104 } 99 105 100 /* vim: set expandtab: */101 102 106 ?>
Note: See TracChangeset
for help on using the changeset viewer.