mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +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
|
- 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)
|
||||||
|
@@ -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($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 (!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))
|
|
||||||
$dir[$name] = $direction;
|
|
||||||
else if (!isset($dir[$name]))
|
|
||||||
$dir[$name] = "up";
|
|
||||||
|
|
||||||
if ($dir[$name] == "down")
|
if ($counter['direction'] == "down")
|
||||||
$count[$name] -= $skipval[$name];
|
$counter['count'] -= $counter['skip'];
|
||||||
else
|
else
|
||||||
$count[$name] += $skipval[$name];
|
$counter['count'] += $counter['skip'];
|
||||||
|
|
||||||
return $retval;
|
return $retval;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user