cvs: smarty /plugins function.cycle.php

From: Date: Fri, 03 May 2002 14:39:49 +0000
Subject: cvs: smarty /plugins function.cycle.php
Groups: php.smarty.cvs 
Request: Send a blank email to php-smarty-cvs+get-99@lists.php.net to get a copy of this message
mohrt Fri May 3 10:39:49 2002 EDT Modified files: /smarty/plugins function.cycle.php Log: update cycle function to allow blank values parameter after initialized Index: smarty/plugins/function.cycle.php diff -u smarty/plugins/function.cycle.php:1.4 smarty/plugins/function.cycle.php:1.5 --- smarty/plugins/function.cycle.php:1.4 Fri May 3 09:33:10 2002 +++ smarty/plugins/function.cycle.php Fri May 3 10:39:49 2002 @@ -5,13 +5,15 @@ * ------------------------------------------------------------- * Type: function * Name: cycle - * Version: 1.1 + * Version: 1.2 + * Date: May 3, 2002 * Author: Monte Ohrt <monte@ispi.net> * Credits: Mark Priatel <mpriatel@rogers.com> * Gerard <gerard@interfold.com> * 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 @@ } 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']++; } } }

« previous php.smarty.cvs (#99) next »