Updated to Smarty 2.6.26 (June 18th, 2009), we should update to Smarty 3.x (current...
[mirrors/Kyberia-bloodline.git] / wwwroot / smarty / libs / plugins / function.counter.php
CommitLineData
51ff3226 1<?php
2/**
3 * Smarty plugin
4 * @package Smarty
5 * @subpackage plugins
6 */
7
8
9/**
10 * Smarty {counter} function plugin
11 *
12 * Type: function<br>
13 * Name: counter<br>
14 * Purpose: print out a counter value
9b7c11be 15 * @author Monte Ohrt <monte at ohrt dot com>
51ff3226 16 * @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
17 * (Smarty online manual)
18 * @param array parameters
19 * @param Smarty
20 * @return string|null
21 */
22function smarty_function_counter($params, &$smarty)
23{
24 static $counters = array();
25
26 $name = (isset($params['name'])) ? $params['name'] : 'default';
27 if (!isset($counters[$name])) {
28 $counters[$name] = array(
29 'start'=>1,
30 'skip'=>1,
31 'direction'=>'up',
32 'count'=>1
33 );
34 }
35 $counter =& $counters[$name];
36
37 if (isset($params['start'])) {
38 $counter['start'] = $counter['count'] = (int)$params['start'];
39 }
40
41 if (!empty($params['assign'])) {
42 $counter['assign'] = $params['assign'];
43 }
44
45 if (isset($counter['assign'])) {
46 $smarty->assign($counter['assign'], $counter['count']);
47 }
9b7c11be 48
51ff3226 49 if (isset($params['print'])) {
50 $print = (bool)$params['print'];
51 } else {
52 $print = empty($counter['assign']);
53 }
54
55 if ($print) {
56 $retval = $counter['count'];
57 } else {
58 $retval = null;
59 }
60
61 if (isset($params['skip'])) {
62 $counter['skip'] = $params['skip'];
63 }
9b7c11be 64
51ff3226 65 if (isset($params['direction'])) {
66 $counter['direction'] = $params['direction'];
67 }
68
69 if ($counter['direction'] == "down")
70 $counter['count'] -= $counter['skip'];
71 else
72 $counter['count'] += $counter['skip'];
9b7c11be 73
51ff3226 74 return $retval;
9b7c11be 75
51ff3226 76}
77
78/* vim: set expandtab: */
79
80?>
This page took 0.227587 seconds and 4 git commands to generate.