Files
smarty/libs/plugins/function.counter.php

89 lines
1.6 KiB
PHP
Raw Normal View History

2002-01-31 20:49:40 +00:00
<?php
2003-04-20 21:18:26 +00:00
/**
2002-01-31 20:49:40 +00:00
* Smarty plugin
2003-04-20 21:18:26 +00:00
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {counter} function plugin
*
* Type: function<br>
* Name: counter<br>
2002-01-31 20:49:40 +00:00
* Purpose: print out a counter value
2003-04-20 21:18:26 +00:00
* @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
* (Smarty online manual)
* @param array parameters
* @param Smarty
* @return string|null
2002-01-31 20:49:40 +00:00
*/
2002-02-20 22:24:32 +00:00
function smarty_function_counter($params, &$smarty)
2002-01-31 20:49:40 +00:00
{
2003-06-02 15:13:18 +00:00
static $counters = array();
2002-01-31 20:49:40 +00:00
2002-02-20 22:24:32 +00:00
extract($params);
2002-01-31 20:49:40 +00:00
if (!isset($name)) {
if(isset($id)) {
$name = $id;
} else {
$name = "default";
}
}
2002-01-31 20:49:40 +00:00
2003-06-02 15:13:18 +00:00
if (!isset($counters[$name])) {
$counters[$name] = array(
'start'=>1,
'skip'=>1,
'direction'=>'up',
'count'=>1
2003-06-02 15:13:18 +00:00
);
}
$counter =& $counters[$name];
if (isset($start)) {
$counter['start'] = $counter['count'] = $start;
}
2002-01-31 20:49:40 +00:00
if (!empty($assign)) {
2003-06-02 15:13:18 +00:00
$counter['assign'] = $assign;
}
if (isset($counter['assign'])) {
2003-06-02 15:13:18 +00:00
$smarty->assign($counter['assign'], $counter['count']);
2002-01-31 20:49:40 +00:00
}
2003-06-02 15:13:18 +00:00
if (isset($print)) {
2003-06-02 15:13:18 +00:00
$print = (bool)$print;
} else {
$print = empty($counter['assign']);
2003-06-02 15:13:18 +00:00
}
2003-06-02 15:13:18 +00:00
if ($print) {
$retval = $counter['count'];
} else {
$retval = null;
}
2002-01-31 20:49:40 +00:00
if (isset($skip)) {
$counter['skip'] = $skip;
}
2003-06-02 15:13:18 +00:00
if (isset($direction)) {
$counter['direction'] = $direction;
}
2002-01-31 20:49:40 +00:00
2003-06-02 15:13:18 +00:00
if ($counter['direction'] == "down")
$counter['count'] -= $counter['skip'];
2002-01-31 20:49:40 +00:00
else
2003-06-02 15:13:18 +00:00
$counter['count'] += $counter['skip'];
return $retval;
2002-01-31 20:49:40 +00:00
}
/* vim: set expandtab: */
?>