annotate Smarty/plugins/function.counter.php @ 1:f5a9f0eb4858

deleted: LICENSE.ja
author Sushi-k <epgrec@park.mda.or.jp>
date Wed, 08 Jul 2009 11:44:50 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
1 <?php
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
2 /**
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
3 * Smarty plugin
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
4 * @package Smarty
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
5 * @subpackage plugins
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
6 */
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
7
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
8
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
9 /**
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
10 * Smarty {counter} function plugin
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
11 *
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
12 * Type: function<br>
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
13 * Name: counter<br>
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
14 * Purpose: print out a counter value
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
15 * @author Monte Ohrt <monte at ohrt dot com>
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
16 * @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
17 * (Smarty online manual)
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
18 * @param array parameters
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
19 * @param Smarty
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
20 * @return string|null
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
21 */
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
22 function smarty_function_counter($params, &$smarty)
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
23 {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
24 static $counters = array();
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
25
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
26 $name = (isset($params['name'])) ? $params['name'] : 'default';
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
27 if (!isset($counters[$name])) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
28 $counters[$name] = array(
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
29 'start'=>1,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
30 'skip'=>1,
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
31 'direction'=>'up',
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
32 'count'=>1
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
33 );
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
34 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
35 $counter =& $counters[$name];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
36
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
37 if (isset($params['start'])) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
38 $counter['start'] = $counter['count'] = (int)$params['start'];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
39 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
40
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
41 if (!empty($params['assign'])) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
42 $counter['assign'] = $params['assign'];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
43 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
44
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
45 if (isset($counter['assign'])) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
46 $smarty->assign($counter['assign'], $counter['count']);
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
47 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
48
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
49 if (isset($params['print'])) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
50 $print = (bool)$params['print'];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
51 } else {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
52 $print = empty($counter['assign']);
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
53 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
54
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
55 if ($print) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
56 $retval = $counter['count'];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
57 } else {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
58 $retval = null;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
59 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
60
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
61 if (isset($params['skip'])) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
62 $counter['skip'] = $params['skip'];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
63 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
64
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
65 if (isset($params['direction'])) {
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
66 $counter['direction'] = $params['direction'];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
67 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
68
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
69 if ($counter['direction'] == "down")
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
70 $counter['count'] -= $counter['skip'];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
71 else
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
72 $counter['count'] += $counter['skip'];
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
73
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
74 return $retval;
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
75
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
76 }
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
77
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
78 /* vim: set expandtab: */
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
79
f5a9f0eb4858 deleted: LICENSE.ja
Sushi-k <epgrec@park.mda.or.jp>
parents:
diff changeset
80 ?>