| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty plugin | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-07-01 19:57:56 +00:00
										 |  |  |  * @subpackage PluginsFunction | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty {counter} function plugin | 
					
						
							|  |  |  |  * Type:     function<br> | 
					
						
							|  |  |  |  * Name:     counter<br> | 
					
						
							|  |  |  |  * Purpose:  print out a counter value | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |  * @author Monte Ohrt <monte at ohrt dot com> | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @link   http://www.smarty.net/manual/en/language.function.counter.php {counter} | 
					
						
							|  |  |  |  *         (Smarty online manual) | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @param array                    $params   parameters | 
					
						
							|  |  |  |  * @param Smarty_Internal_Template $template template object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |  * @return string|null | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-11-12 23:42:32 +00:00
										 |  |  | function smarty_function_counter($params, $template) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |     static $counters = array(); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $name = (isset($params['name'])) ? $params['name'] : 'default'; | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |     if (!isset($counters[$name])) { | 
					
						
							|  |  |  |         $counters[$name] = array( | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |             'start'     => 1, | 
					
						
							|  |  |  |             'skip'      => 1, | 
					
						
							|  |  |  |             'direction' => 'up', | 
					
						
							|  |  |  |             'count'     => 1 | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-05-27 19:56:39 +00:00
										 |  |  |     $counter =& $counters[$name]; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (isset($params['start'])) { | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         $counter['start'] = $counter['count'] = (int) $params['start']; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!empty($params['assign'])) { | 
					
						
							|  |  |  |         $counter['assign'] = $params['assign']; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (isset($counter['assign'])) { | 
					
						
							| 
									
										
										
										
											2010-09-07 16:24:34 +00:00
										 |  |  |         $template->assign($counter['assign'], $counter['count']); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     if (isset($params['print'])) { | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |         $print = (bool) $params['print']; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         $print = empty($counter['assign']); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($print) { | 
					
						
							|  |  |  |         $retval = $counter['count']; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $retval = null; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (isset($params['skip'])) { | 
					
						
							|  |  |  |         $counter['skip'] = $params['skip']; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     if (isset($params['direction'])) { | 
					
						
							|  |  |  |         $counter['direction'] = $params['direction']; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |     if ($counter['direction'] == "down") { | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         $counter['count'] -= $counter['skip']; | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         $counter['count'] += $counter['skip']; | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     return $retval; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | } |