mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
fixed assign for {counter}
This commit is contained in:
1
NEWS
1
NEWS
@@ -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)
|
||||
|
@@ -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($start))
|
||||
$counter['start'] = $start;
|
||||
else if (!isset($counter['start']))
|
||||
$counter['start'] = 1;
|
||||
|
||||
if (!isset($counter['count']))
|
||||
$counter['count'] = $counter['start'];
|
||||
|
||||
if (!isset($print))
|
||||
$printval[$name]=true;
|
||||
else
|
||||
$printval[$name]=$print;
|
||||
|
||||
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))
|
||||
$dir[$name] = $direction;
|
||||
else if (!isset($dir[$name]))
|
||||
$dir[$name] = "up";
|
||||
if (isset($direction)) {
|
||||
$counter['direction'] = $direction;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
Reference in New Issue
Block a user