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
over the data in various directions (messju)
- allow spaces in literal tags (Paul Lockaby, Monte)

View File

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