| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2017-11-11 07:11:33 +01:00
										 |  |  |  * Type:     function
 | 
					
						
							|  |  |  |  * Name:     counter | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |  * 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> | 
					
						
							| 
									
										
										
										
											2021-10-13 12:15:17 +02:00
										 |  |  |  * @link   https://www.smarty.net/manual/en/language.function.counter.php {counter} | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  *         (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(); | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |     $name = (isset($params[ 'name' ])) ? $params[ 'name' ] : 'default'; | 
					
						
							|  |  |  |     if (!isset($counters[ $name ])) { | 
					
						
							|  |  |  |         $counters[ $name ] = array('start' => 1, 'skip' => 1, 'direction' => 'up', 'count' => 1); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |     $counter =& $counters[ $name ]; | 
					
						
							|  |  |  |     if (isset($params[ 'start' ])) { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |         $counter[ 'start' ] = $counter[ 'count' ] = (int)$params[ 'start' ]; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |     if (!empty($params[ 'assign' ])) { | 
					
						
							|  |  |  |         $counter[ 'assign' ] = $params[ 'assign' ]; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |     if (isset($counter[ 'assign' ])) { | 
					
						
							|  |  |  |         $template->assign($counter[ 'assign' ], $counter[ 'count' ]); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |     if (isset($params[ 'print' ])) { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |         $print = (bool)$params[ 'print' ]; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         $print = empty($counter[ 'assign' ]); | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     if ($print) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         $retval = $counter[ 'count' ]; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         $retval = null; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |     if (isset($params[ 'skip' ])) { | 
					
						
							|  |  |  |         $counter[ 'skip' ] = $params[ 'skip' ]; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |     if (isset($params[ 'direction' ])) { | 
					
						
							|  |  |  |         $counter[ 'direction' ] = $params[ 'direction' ]; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |     if ($counter[ 'direction' ] === 'down') { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         $counter[ 'count' ] -= $counter[ 'skip' ]; | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         $counter[ 'count' ] += $counter[ 'skip' ]; | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     return $retval; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | } |