diff --git a/libs/plugins/function.cycle.php b/libs/plugins/function.cycle.php index 25e66113..fe60dbdf 100644 --- a/libs/plugins/function.cycle.php +++ b/libs/plugins/function.cycle.php @@ -5,13 +5,15 @@ * ------------------------------------------------------------- * Type: function * Name: cycle - * Version: 1.1 + * Version: 1.2 + * Date: May 3, 2002 * Author: Monte Ohrt * Credits: Mark Priatel * Gerard * Purpose: cycle through given values * Input: id = id of cycle (optional) * values = comma separated list of values to cycle + * (this can be left out for subsequent calls) * reset = boolean - resets given var to true * print = boolean - print var or not. default is true * advance = boolean - whether or not to advance the cycle @@ -21,10 +23,13 @@ * * Examples: {cycle values="#eeeeee,#d0d0d0d"} * {cycle id=row values="one,two,three" reset=true} + * {cycle id=row} * ------------------------------------------------------------- */ function smarty_function_cycle($params, &$smarty) { + static $cycle_vars; + extract($params); if (empty($id)) { @@ -44,32 +49,38 @@ function smarty_function_cycle($params, &$smarty) } if (!in_array('values', array_keys($params))) { - $smarty->trigger_error("cycle: missing 'values' parameter"); - return; - } - - static $cycle_vars; + if(!isset($cycle_vars[$id]['values'])) { + $smarty->trigger_error("cycle: missing 'values' parameter"); + return; + } + } else { + if(isset($cycle_vars[$id]['values']) + && $cycle_vars[$id]['values'] != $values ) { + $cycle_vars[$id]['index'] = 0; + } + $cycle_vars[$id]['values'] = $values; + } - $cycle_array = explode($delimiter,$values); + $cycle_array = explode($delimiter,$cycle_vars[$id]['values']); - if(!isset($cycle_vars[$id]) || $reset ) { - $cycle_vars[$id] = 0; + if(!isset($cycle_vars[$id]['index']) || $reset ) { + $cycle_vars[$id]['index'] = 0; } if (isset($assign)) { $print = false; - $smarty->assign($assign, $cycle_array[$cycle_vars[$id]]); + $smarty->assign($assign, $cycle_array[$cycle_vars[$id]['index']]); } if($print) { - echo $cycle_array[$cycle_vars[$id]]."\n"; + echo $cycle_array[$cycle_vars[$id]['index']]."\n"; } if($advance) { - if ( $cycle_vars[$id] >= count($cycle_array) -1 ) { - $cycle_vars[$id] = 0; + if ( $cycle_vars[$id]['index'] >= count($cycle_array) -1 ) { + $cycle_vars[$id]['index'] = 0; } else { - $cycle_vars[$id]++; + $cycle_vars[$id]['index']++; } } } diff --git a/plugins/function.cycle.php b/plugins/function.cycle.php index 25e66113..fe60dbdf 100644 --- a/plugins/function.cycle.php +++ b/plugins/function.cycle.php @@ -5,13 +5,15 @@ * ------------------------------------------------------------- * Type: function * Name: cycle - * Version: 1.1 + * Version: 1.2 + * Date: May 3, 2002 * Author: Monte Ohrt * Credits: Mark Priatel * Gerard * Purpose: cycle through given values * Input: id = id of cycle (optional) * values = comma separated list of values to cycle + * (this can be left out for subsequent calls) * reset = boolean - resets given var to true * print = boolean - print var or not. default is true * advance = boolean - whether or not to advance the cycle @@ -21,10 +23,13 @@ * * Examples: {cycle values="#eeeeee,#d0d0d0d"} * {cycle id=row values="one,two,three" reset=true} + * {cycle id=row} * ------------------------------------------------------------- */ function smarty_function_cycle($params, &$smarty) { + static $cycle_vars; + extract($params); if (empty($id)) { @@ -44,32 +49,38 @@ function smarty_function_cycle($params, &$smarty) } if (!in_array('values', array_keys($params))) { - $smarty->trigger_error("cycle: missing 'values' parameter"); - return; - } - - static $cycle_vars; + if(!isset($cycle_vars[$id]['values'])) { + $smarty->trigger_error("cycle: missing 'values' parameter"); + return; + } + } else { + if(isset($cycle_vars[$id]['values']) + && $cycle_vars[$id]['values'] != $values ) { + $cycle_vars[$id]['index'] = 0; + } + $cycle_vars[$id]['values'] = $values; + } - $cycle_array = explode($delimiter,$values); + $cycle_array = explode($delimiter,$cycle_vars[$id]['values']); - if(!isset($cycle_vars[$id]) || $reset ) { - $cycle_vars[$id] = 0; + if(!isset($cycle_vars[$id]['index']) || $reset ) { + $cycle_vars[$id]['index'] = 0; } if (isset($assign)) { $print = false; - $smarty->assign($assign, $cycle_array[$cycle_vars[$id]]); + $smarty->assign($assign, $cycle_array[$cycle_vars[$id]['index']]); } if($print) { - echo $cycle_array[$cycle_vars[$id]]."\n"; + echo $cycle_array[$cycle_vars[$id]['index']]."\n"; } if($advance) { - if ( $cycle_vars[$id] >= count($cycle_array) -1 ) { - $cycle_vars[$id] = 0; + if ( $cycle_vars[$id]['index'] >= count($cycle_array) -1 ) { + $cycle_vars[$id]['index'] = 0; } else { - $cycle_vars[$id]++; + $cycle_vars[$id]['index']++; } } }