XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
function.counter.php
Go to the documentation of this file.
1 <?php
22 function 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  }
48 
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  }
64 
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'];
73 
74  return $retval;
75 
76 }
77 
78 /* vim: set expandtab: */
79 
80 ?>