1<?php 2/* 3 * template_lite plugin 4 * ------------------------------------------------------------- 5 * Type: function 6 * Name: counter 7 * Purpose: print out a counter value 8 * Credit: Taken from the original Smarty 9 * http://smarty.php.net 10 * ------------------------------------------------------------- 11 */ 12function tpl_function_counter($params, &$tpl) 13{ 14 static $count = array(); 15 static $skipval = array(); 16 static $dir = array(); 17 static $name = "default"; 18 static $printval = array(); 19 static $assign = ""; 20 21 extract($params); 22 23 if (!isset($name)) 24 { 25 if(isset($id)) 26 { 27 $name = $id; 28 } 29 else 30 { 31 $name = "default"; 32 } 33 } 34 35 if (isset($start)) 36 { 37 $count[$name] = $start; 38 } 39 elseif (!isset($count[$name])) 40 { 41 $count[$name]=1; 42 } 43 44 if (!isset($print)) 45 { 46 $printval[$name]=true; 47 } 48 else 49 { 50 $printval[$name]=$print; 51 } 52 53 if (!empty($assign)) 54 { 55 $printval[$name] = false; 56 $tpl->assign($assign, $count[$name]); 57 } 58 59 if ($printval[$name]) 60 { 61 $retval = $count[$name]; 62 } 63 else 64 { 65 $retval = null; 66 } 67 68 if (isset($skip)) 69 { 70 $skipval[$name] = $skip; 71 } 72 elseif (empty($skipval[$name])) 73 { 74 $skipval[$name] = 1; 75 } 76 77 if (isset($direction)) 78 { 79 $dir[$name] = $direction; 80 } 81 elseif (!isset($dir[$name])) 82 { 83 $dir[$name] = "up"; 84 } 85 86 if ($dir[$name] == "down") 87 { 88 $count[$name] -= $skipval[$name]; 89 } 90 else 91 { 92 $count[$name] += $skipval[$name]; 93 } 94 95 return $retval; 96} 97?>