5 * @subpackage PluginsFunction
9 * Smarty {counter} function plugin
13 * Purpose: print out a counter value
14 * @author Monte Ohrt <monte at ohrt dot com>
15 * @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
16 * (Smarty online manual)
17 * @param array parameters
19 * @param object $template template object
22 function smarty_function_counter($params, $template)
24 static $counters = array();
26 $name = (isset($params['name'])) ? $params['name'] : 'default';
27 if (!isset($counters[$name])) {
28 $counters[$name] = array(
35 $counter =& $counters[$name];
37 if (isset($params['start'])) {
38 $counter['start'] = $counter['count'] = (int)$params['start'];
41 if (!empty($params['assign'])) {
42 $counter['assign'] = $params['assign'];
45 if (isset($counter['assign'])) {
46 $template->assign($counter['assign'], $counter['count']);
49 if (isset($params['print'])) {
50 $print = (bool)$params['print'];
52 $print = empty($counter['assign']);
56 $retval = $counter['count'];
61 if (isset($params['skip'])) {
62 $counter['skip'] = $params['skip'];
65 if (isset($params['direction'])) {
66 $counter['direction'] = $params['direction'];
69 if ($counter['direction'] == "down")
70 $counter['count'] -= $counter['skip'];
72 $counter['count'] += $counter['skip'];