6 * @subpackage PluginsFunction
10 * Smarty {counter} function plugin
13 * Purpose: print out a counter value
15 * @author Monte Ohrt <monte at ohrt dot com>
16 * @link http://www.smarty.net/manual/en/language.function.counter.php {counter}
17 * (Smarty online manual)
19 * @param array $params parameters
20 * @param Smarty_Internal_Template $template template object
24 function smarty_function_counter($params, $template)
26 static $counters = array();
28 $name = (isset($params['name'])) ? $params['name'] : 'default';
29 if (!isset($counters[$name])) {
30 $counters[$name] = array(
37 $counter =& $counters[$name];
39 if (isset($params['start'])) {
40 $counter['start'] = $counter['count'] = (int) $params['start'];
43 if (!empty($params['assign'])) {
44 $counter['assign'] = $params['assign'];
47 if (isset($counter['assign'])) {
48 $template->assign($counter['assign'], $counter['count']);
51 if (isset($params['print'])) {
52 $print = (bool) $params['print'];
54 $print = empty($counter['assign']);
58 $retval = $counter['count'];
63 if (isset($params['skip'])) {
64 $counter['skip'] = $params['skip'];
67 if (isset($params['direction'])) {
68 $counter['direction'] = $params['direction'];
71 if ($counter['direction'] == "down") {
72 $counter['count'] -= $counter['skip'];
74 $counter['count'] += $counter['skip'];