1: <?php
2: 3: 4: 5: 6: 7:
8:
9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: function smarty_function_counter($params, $template)
25: {
26: static $counters = array();
27:
28: $name = (isset($params['name'])) ? $params['name'] : 'default';
29: if (!isset($counters[$name])) {
30: $counters[$name] = array(
31: 'start' => 1,
32: 'skip' => 1,
33: 'direction' => 'up',
34: 'count' => 1
35: );
36: }
37: $counter =& $counters[$name];
38:
39: if (isset($params['start'])) {
40: $counter['start'] = $counter['count'] = (int) $params['start'];
41: }
42:
43: if (!empty($params['assign'])) {
44: $counter['assign'] = $params['assign'];
45: }
46:
47: if (isset($counter['assign'])) {
48: $template->assign($counter['assign'], $counter['count']);
49: }
50:
51: if (isset($params['print'])) {
52: $print = (bool) $params['print'];
53: } else {
54: $print = empty($counter['assign']);
55: }
56:
57: if ($print) {
58: $retval = $counter['count'];
59: } else {
60: $retval = null;
61: }
62:
63: if (isset($params['skip'])) {
64: $counter['skip'] = $params['skip'];
65: }
66:
67: if (isset($params['direction'])) {
68: $counter['direction'] = $params['direction'];
69: }
70:
71: if ($counter['direction'] == "down") {
72: $counter['count'] -= $counter['skip'];
73: } else {
74: $counter['count'] += $counter['skip'];
75: }
76:
77: return $retval;
78: }
79: