home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / function.counter.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  1.7 KB  |  83 lines

  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 $count = array();
  24.     static $skipval = array();
  25.     static $dir = array();
  26.     static $name = "default";
  27.     static $printval = array();
  28.     static $assign = "";
  29.  
  30.     extract($params);
  31.  
  32.     if (!isset($name)) {
  33.         if(isset($id)) {
  34.             $name = $id;
  35.         } else {        
  36.             $name = "default";
  37.         }
  38.     }
  39.  
  40.     if (isset($start))
  41.         $count[$name] = $start;
  42.     else if (!isset($count[$name]))
  43.         $count[$name]=1;
  44.  
  45.     if (!isset($print))
  46.         $printval[$name]=true;
  47.     else
  48.         $printval[$name]=$print;
  49.     
  50.     if (!empty($assign)) {
  51.         $printval[$name] = false;
  52.         $smarty->assign($assign, $count[$name]);
  53.     }
  54.  
  55.     if ($printval[$name]) {
  56.         $retval = $count[$name];
  57.     } else {
  58.         $retval = null;
  59.     }
  60.  
  61.     if (isset($skip))
  62.         $skipval[$name] = $skip;
  63.     else if (empty($skipval[$name]))
  64.         $skipval[$name] = 1;
  65.     
  66.     if (isset($direction))
  67.         $dir[$name] = $direction;
  68.     else if (!isset($dir[$name]))
  69.         $dir[$name] = "up";
  70.  
  71.     if ($dir[$name] == "down")
  72.         $count[$name] -= $skipval[$name];
  73.     else
  74.         $count[$name] += $skipval[$name];
  75.     
  76.     return $retval;
  77.     
  78. }
  79.  
  80. /* vim: set expandtab: */
  81.  
  82. ?>
  83.