| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty plugin | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |  * @package Smarty | 
					
						
							| 
									
										
										
										
											2010-07-01 19:57:56 +00:00
										 |  |  |  * @subpackage PluginsFunction | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty {cycle} function plugin | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Type:     function<br> | 
					
						
							|  |  |  |  * Name:     cycle<br> | 
					
						
							|  |  |  |  * Date:     May 3, 2002<br> | 
					
						
							|  |  |  |  * Purpose:  cycle through given values<br> | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * Params: | 
					
						
							|  |  |  |  * <pre> | 
					
						
							|  |  |  |  * - name      - name of cycle (optional) | 
					
						
							|  |  |  |  * - values    - comma separated list of values to cycle, or an array of values to cycle | 
					
						
							|  |  |  |  *               (this can be left out for subsequent calls) | 
					
						
							|  |  |  |  * - reset     - boolean - resets given var to true | 
					
						
							|  |  |  |  * - print     - boolean - print var or not. default is true | 
					
						
							|  |  |  |  * - advance   - boolean - whether or not to advance the cycle | 
					
						
							|  |  |  |  * - delimiter - the value delimiter, default is "," | 
					
						
							|  |  |  |  * - assign    - boolean, assigns to template var instead of printed. | 
					
						
							|  |  |  |  * </pre> | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |  * Examples:<br> | 
					
						
							|  |  |  |  * <pre> | 
					
						
							|  |  |  |  * {cycle values="#eeeeee,#d0d0d0d"} | 
					
						
							|  |  |  |  * {cycle name=row values="one,two,three" reset=true} | 
					
						
							|  |  |  |  * {cycle name=row} | 
					
						
							|  |  |  |  * </pre> | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |  *       (Smarty online manual) | 
					
						
							|  |  |  |  * @author Monte Ohrt <monte at ohrt dot com> | 
					
						
							|  |  |  |  * @author credit to Mark Priatel <mpriatel@rogers.com> | 
					
						
							|  |  |  |  * @author credit to Gerard <gerard@interfold.com> | 
					
						
							|  |  |  |  * @author credit to Jason Sweat <jsweat_php@yahoo.com> | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |  * @version  1.3 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @param array                    $params   parameters | 
					
						
							|  |  |  |  * @param Smarty_Internal_Template $template template object | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |  * @return string|null | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-12 23:42:32 +00:00
										 |  |  | function smarty_function_cycle($params, $template) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |     static $cycle_vars; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     $name = (empty($params['name'])) ? 'default' : $params['name']; | 
					
						
							|  |  |  |     $print = (isset($params['print'])) ? (bool)$params['print'] : true; | 
					
						
							|  |  |  |     $advance = (isset($params['advance'])) ? (bool)$params['advance'] : true; | 
					
						
							|  |  |  |     $reset = (isset($params['reset'])) ? (bool)$params['reset'] : false; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-01 18:10:48 +00:00
										 |  |  |     if (!isset($params['values'])) { | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |         if(!isset($cycle_vars[$name]['values'])) { | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |             trigger_error("cycle: missing 'values' parameter"); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |         if(isset($cycle_vars[$name]['values']) | 
					
						
							|  |  |  |             && $cycle_vars[$name]['values'] != $params['values'] ) { | 
					
						
							|  |  |  |             $cycle_vars[$name]['index'] = 0; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |         $cycle_vars[$name]['values'] = $params['values']; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-17 01:31:44 +00:00
										 |  |  |     if (isset($params['delimiter'])) { | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |         $cycle_vars[$name]['delimiter'] = $params['delimiter']; | 
					
						
							|  |  |  |     } elseif (!isset($cycle_vars[$name]['delimiter'])) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $cycle_vars[$name]['delimiter'] = ','; | 
					
						
							| 
									
										
										
										
											2009-11-17 01:31:44 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |     if(is_array($cycle_vars[$name]['values'])) { | 
					
						
							|  |  |  |         $cycle_array = $cycle_vars[$name]['values']; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |         $cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |     if(!isset($cycle_vars[$name]['index']) || $reset ) { | 
					
						
							|  |  |  |         $cycle_vars[$name]['index'] = 0; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     if (isset($params['assign'])) { | 
					
						
							|  |  |  |         $print = false; | 
					
						
							| 
									
										
										
										
											2010-09-07 16:24:34 +00:00
										 |  |  |         $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     if($print) { | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |         $retval = $cycle_array[$cycle_vars[$name]['index']]; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         $retval = null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if($advance) { | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |         if ( $cycle_vars[$name]['index'] >= count($cycle_array) -1 ) { | 
					
						
							|  |  |  |             $cycle_vars[$name]['index'] = 0; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |             $cycle_vars[$name]['index']++; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     return $retval; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  | ?>
 |