fixed assign for {counter}

This commit is contained in:
messju
2003-06-02 15:13:18 +00:00
parent 3cf833352f
commit 2e9424d567
2 changed files with 42 additions and 30 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- fixed assign for {counter} (messju)
- added params vdir, hdir and inner to html_table to allow looping - added params vdir, hdir and inner to html_table to allow looping
over the data in various directions (messju) over the data in various directions (messju)
- allow spaces in literal tags (Paul Lockaby, Monte) - allow spaces in literal tags (Paul Lockaby, Monte)

View File

@@ -20,11 +20,7 @@
*/ */
function smarty_function_counter($params, &$smarty) function smarty_function_counter($params, &$smarty)
{ {
static $count = array(); static $counters = array();
static $skipval = array();
static $dir = array();
static $name = "default";
static $printval = array();
extract($params); extract($params);
@@ -36,41 +32,56 @@ function smarty_function_counter($params, &$smarty)
} }
} }
if (isset($start)) if (!isset($counters[$name])) {
$count[$name] = $start; $counters[$name] = array(
else if (!isset($count[$name])) 'start'=>1,
$count[$name]=1; 'skip'=>1,
'assign'=>null,
'direction'=>'up'
);
}
$counter =& $counters[$name];
if (!isset($print))
$printval[$name]=true; if (isset($start))
else $counter['start'] = $start;
$printval[$name]=$print; else if (!isset($counter['start']))
$counter['start'] = 1;
if (!isset($counter['count']))
$counter['count'] = $counter['start'];
if (!empty($assign)) { if (!empty($assign)) {
if (!isset($print)) $printval[$name] = false; $counter['assign'] = $assign;
$smarty->assign_by_ref($assign, $count[$name]);
} }
if ($printval[$name]) { if (!empty($counter['assign'])) {
$retval = $count[$name]; $smarty->assign($counter['assign'], $counter['count']);
}
if (!isset($print))
$print = empty($counter['assign']);
else
$print = (bool)$print;
if (isset($skip)) {
$counter['skip'] = $skip;
}
if ($print) {
$retval = $counter['count'];
} else { } else {
$retval = null; $retval = null;
} }
if (isset($skip)) if (isset($direction)) {
$skipval[$name] = $skip; $counter['direction'] = $direction;
else if (empty($skipval[$name])) }
$skipval[$name] = 1;
if (isset($direction)) if ($counter['direction'] == "down")
$dir[$name] = $direction; $counter['count'] -= $counter['skip'];
else if (!isset($dir[$name]))
$dir[$name] = "up";
if ($dir[$name] == "down")
$count[$name] -= $skipval[$name];
else else
$count[$name] += $skipval[$name]; $counter['count'] += $counter['skip'];
return $retval; return $retval;