phpDocumentor Smarty
plugins
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file function.counter.php

Documentation is available at function.counter.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8.  
  9. /**
  10.  * Smarty {counter} function plugin
  11.  *
  12.  * Type:     function<br>
  13.  * Name:     counter<br>
  14.  * Purpose:  print out a counter value
  15.  * @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
  16.  *        (Smarty online manual)
  17.  * @param array parameters
  18.  * @param Smarty 
  19.  * @return string|null
  20.  */
  21. function smarty_function_counter($params&$smarty)
  22. {
  23.     static $counters array();
  24.  
  25.     extract($params);
  26.  
  27.     if (!isset($name)) {
  28.         if(isset($id)) {
  29.             $name $id;
  30.         else {        
  31.             $name "default";
  32.         }
  33.     }
  34.  
  35.     if (!isset($counters[$name])) {
  36.         $counters[$namearray(
  37.             'start'=>1,
  38.             'skip'=>1,
  39.             'direction'=>'up',
  40.             'count'=>1
  41.             );
  42.     }
  43.     $counter =$counters[$name];
  44.  
  45.     if (isset($start)) {
  46.         $counter['start'$counter['count'$start;
  47.     }
  48.  
  49.     if (!empty($assign)) {
  50.         $counter['assign'$assign;
  51.     }
  52.  
  53.     if (isset($counter['assign'])) {
  54.         $smarty->assign($counter['assign']$counter['count']);
  55.     }
  56.     
  57.     if (isset($print)) {
  58.         $print = (bool)$print;
  59.     else {
  60.         $print empty($counter['assign']);
  61.     }
  62.  
  63.     if ($print{
  64.         $retval $counter['count'];
  65.     else {
  66.         $retval null;
  67.     }
  68.  
  69.     if (isset($skip)) {
  70.         $counter['skip'$skip;
  71.     }
  72.     
  73.     if (isset($direction)) {
  74.         $counter['direction'$direction;
  75.     }
  76.  
  77.     if ($counter['direction'== "down")
  78.         $counter['count'-= $counter['skip'];
  79.     else
  80.         $counter['count'+= $counter['skip'];
  81.     
  82.     return $retval;
  83.     
  84. }
  85.  
  86. /* vim: set expandtab: */
  87.  
  88. ?>

Documentation generated on Tue, 24 Oct 2006 09:22:34 -0500 by phpDocumentor 1.3.1