/[cvs]/nfo/php/libs/net.php.smarty/plugins/function.cycle.php
ViewVC logotype

Annotation of /nfo/php/libs/net.php.smarty/plugins/function.cycle.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Wed Oct 9 00:53:36 2002 UTC (21 years, 10 months ago) by cvsjoko
Branch: MAIN
no message

1 cvsjoko 1.1 <?php
2    
3     /*
4     * Smarty plugin
5     * -------------------------------------------------------------
6     * Type: function
7     * Name: cycle
8     * Version: 1.3
9     * Date: May 3, 2002
10     * Author: Monte Ohrt <monte@ispi.net>
11     * Credits: Mark Priatel <mpriatel@rogers.com>
12     * Gerard <gerard@interfold.com>
13     * Jason Sweat <jsweat_php@yahoo.com>
14     * Purpose: cycle through given values
15     * Input: name = name of cycle (optional)
16     * values = comma separated list of values to cycle,
17     * or an array of values to cycle
18     * (this can be left out for subsequent calls)
19     *
20     * reset = boolean - resets given var to true
21     * print = boolean - print var or not. default is true
22     * advance = boolean - whether or not to advance the cycle
23     * delimiter = the value delimiter, default is ","
24     * assign = boolean, assigns to template var instead of
25     * printed.
26     *
27     * Examples: {cycle values="#eeeeee,#d0d0d0d"}
28     * {cycle name=row values="one,two,three" reset=true}
29     * {cycle name=row}
30     * -------------------------------------------------------------
31     */
32     function smarty_function_cycle($params, &$smarty)
33     {
34     static $cycle_vars;
35    
36     extract($params);
37    
38     if (empty($name)) {
39     $name = 'default';
40     }
41    
42     if (!isset($print)) {
43     $print = true;
44     }
45    
46     if (!isset($advance)) {
47     $advance = true;
48     }
49    
50     if (!isset($reset)) {
51     $reset = false;
52     }
53    
54     if (!in_array('values', array_keys($params))) {
55     if(!isset($cycle_vars[$name]['values'])) {
56     $smarty->trigger_error("cycle: missing 'values' parameter");
57     return;
58     }
59     } else {
60     if(isset($cycle_vars[$name]['values'])
61     && $cycle_vars[$name]['values'] != $values ) {
62     $cycle_vars[$name]['index'] = 0;
63     }
64     $cycle_vars[$name]['values'] = $values;
65     }
66    
67     if (isset($delimiter)) {
68     $cycle_vars[$name]['delimiter'] = $delimiter;
69     } elseif (!isset($cycle_vars[$name]['delimiter'])) {
70     $cycle_vars[$name]['delimiter'] = ',';
71     }
72    
73     if(!is_array($cycle_vars[$name]['values'])) {
74     $cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']);
75     } else {
76     $cycle_array = $cycle_vars[$name]['values'];
77     }
78    
79     if(!isset($cycle_vars[$name]['index']) || $reset ) {
80     $cycle_vars[$name]['index'] = 0;
81     }
82    
83     if (isset($assign)) {
84     $print = false;
85     $smarty->assign($assign, $cycle_array[$cycle_vars[$name]['index']]);
86     }
87    
88     if($print) {
89     echo $cycle_array[$cycle_vars[$name]['index']];
90     }
91    
92     if($advance) {
93     if ( $cycle_vars[$name]['index'] >= count($cycle_array) -1 ) {
94     $cycle_vars[$name]['index'] = 0;
95     } else {
96     $cycle_vars[$name]['index']++;
97     }
98     }
99     }
100    
101     /* vim: set expandtab: */
102    
103     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed