X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=wwwroot%2Finc%2Fsmarty%2Fnode_methodz%2Ffunction.counter.php;fp=wwwroot%2Finc%2Fsmarty%2Fnode_methodz%2Ffunction.counter.php;h=80f5721ea698267400a3ef93eb19df1ea7173dca;hb=51ff32267c4949bad6a8dddc502cbc01ed56edc8;hp=0000000000000000000000000000000000000000;hpb=dcee763368a1e3f380d07320a5254d91a09304e6;p=mirrors%2FKyberia-bloodline.git diff --git a/wwwroot/inc/smarty/node_methodz/function.counter.php b/wwwroot/inc/smarty/node_methodz/function.counter.php new file mode 100644 index 0000000..80f5721 --- /dev/null +++ b/wwwroot/inc/smarty/node_methodz/function.counter.php @@ -0,0 +1,88 @@ + + * Name: counter
+ * Purpose: print out a counter value + * @link http://smarty.php.net/manual/en/language.function.counter.php {counter} + * (Smarty online manual) + * @param array parameters + * @param Smarty + * @return string|null + */ +function smarty_function_counter($params, &$smarty) +{ + static $counters = array(); + + extract($params); + + if (!isset($name)) { + if(isset($id)) { + $name = $id; + } else { + $name = "default"; + } + } + + if (!isset($counters[$name])) { + $counters[$name] = array( + 'start'=>1, + 'skip'=>1, + 'direction'=>'up', + 'count'=>1 + ); + } + $counter =& $counters[$name]; + + if (isset($start)) { + $counter['start'] = $counter['count'] = $start; + } + + if (!empty($assign)) { + $counter['assign'] = $assign; + } + + if (isset($counter['assign'])) { + $smarty->assign($counter['assign'], $counter['count']); + } + + if (isset($print)) { + $print = (bool)$print; + } else { + $print = empty($counter['assign']); + } + + if ($print) { + $retval = $counter['count']; + } else { + $retval = null; + } + + if (isset($skip)) { + $counter['skip'] = $skip; + } + + if (isset($direction)) { + $counter['direction'] = $direction; + } + + if ($counter['direction'] == "down") + $counter['count'] -= $counter['skip']; + else + $counter['count'] += $counter['skip']; + + return $retval; + +} + +/* vim: set expandtab: */ + +?>