mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
update cycle function to allow blank values parameter after initialized
This commit is contained in:
@@ -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 @@ function smarty_function_cycle($params, &$smarty)
|
||||
}
|
||||
|
||||
if (!in_array('values', array_keys($params))) {
|
||||
$smarty->trigger_error("cycle: missing 'values' parameter");
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
static $cycle_vars;
|
||||
$cycle_array = explode($delimiter,$cycle_vars[$id]['values']);
|
||||
|
||||
$cycle_array = explode($delimiter,$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']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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 @@ function smarty_function_cycle($params, &$smarty)
|
||||
}
|
||||
|
||||
if (!in_array('values', array_keys($params))) {
|
||||
$smarty->trigger_error("cycle: missing 'values' parameter");
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
static $cycle_vars;
|
||||
$cycle_array = explode($delimiter,$cycle_vars[$id]['values']);
|
||||
|
||||
$cycle_array = explode($delimiter,$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']++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user