• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List

E:/E/GEAMP/www/openbiz/openbiz/others/Smarty/libs/plugins/function.counter.php

00001 <?php
00021 function smarty_function_counter($params, &$smarty)
00022 {
00023     static $counters = array();
00024 
00025     $name = (isset($params['name'])) ? $params['name'] : 'default';
00026     if (!isset($counters[$name])) {
00027         $counters[$name] = array(
00028             'start'=>1,
00029             'skip'=>1,
00030             'direction'=>'up',
00031             'count'=>1
00032             );
00033     }
00034     $counter =& $counters[$name];
00035 
00036     if (isset($params['start'])) {
00037         $counter['start'] = $counter['count'] = (int)$params['start'];
00038     }
00039 
00040     if (!empty($params['assign'])) {
00041         $counter['assign'] = $params['assign'];
00042     }
00043 
00044     if (isset($counter['assign'])) {
00045         $smarty->assign($counter['assign'], $counter['count']);
00046     }
00047     
00048     if (isset($params['print'])) {
00049         $print = (bool)$params['print'];
00050     } else {
00051         $print = empty($counter['assign']);
00052     }
00053 
00054     if ($print) {
00055         $retval = $counter['count'];
00056     } else {
00057         $retval = null;
00058     }
00059 
00060     if (isset($params['skip'])) {
00061         $counter['skip'] = $params['skip'];
00062     }
00063     
00064     if (isset($params['direction'])) {
00065         $counter['direction'] = $params['direction'];
00066     }
00067 
00068     if ($counter['direction'] == "down")
00069         $counter['count'] -= $counter['skip'];
00070     else
00071         $counter['count'] += $counter['skip'];
00072     
00073     return $retval;
00074     
00075 }
00076 
00077 /* vim: set expandtab: */
00078 
00079 ?>

Generated on Thu Apr 19 2012 17:01:16 for openbiz by  doxygen 1.7.2