cvs: smarty / NEWS /libs/plugins function.counter.php

From: Date: Mon, 02 Jun 2003 15:13:18 +0000
Subject: cvs: smarty / NEWS /libs/plugins function.counter.php
Groups: php.smarty.cvs 
Request: Send a blank email to php-smarty-cvs+get-619@lists.php.net to get a copy of this message
messju Mon Jun 2 11:13:18 2003 EDT Modified files: /smarty NEWS /smarty/libs/plugins function.counter.php Log: fixed assign for {counter} Index: smarty/NEWS diff -u smarty/NEWS:1.365 smarty/NEWS:1.366 --- smarty/NEWS:1.365 Wed May 28 18:30:58 2003 +++ smarty/NEWS Mon Jun 2 11:13:17 2003 @@ -1,3 +1,4 @@ + - fixed assign for {counter} (messju) - added params vdir, hdir and inner to html_table to allow looping over the data in various directions (messju) - allow spaces in literal tags (Paul Lockaby, Monte) Index: smarty/libs/plugins/function.counter.php diff -u smarty/libs/plugins/function.counter.php:1.8 smarty/libs/plugins/function.counter.php:1.9 --- smarty/libs/plugins/function.counter.php:1.8 Fri May 2 18:33:15 2003 +++ smarty/libs/plugins/function.counter.php Mon Jun 2 11:13:18 2003 @@ -20,11 +20,7 @@ */ function smarty_function_counter($params, &$smarty) { - static $count = array(); - static $skipval = array(); - static $dir = array(); - static $name = "default"; - static $printval = array(); + static $counters = array(); extract($params); @@ -36,41 +32,56 @@ } } + if (!isset($counters[$name])) { + $counters[$name] = array( + 'start'=>1, + 'skip'=>1, + 'assign'=>null, + 'direction'=>'up' + ); + } + $counter =& $counters[$name]; + + if (isset($start)) - $count[$name] = $start; - else if (!isset($count[$name])) - $count[$name]=1; + $counter['start'] = $start; + else if (!isset($counter['start'])) + $counter['start'] = 1; + + if (!isset($counter['count'])) + $counter['count'] = $counter['start']; - if (!isset($print)) - $printval[$name]=true; - else - $printval[$name]=$print; - if (!empty($assign)) { - if (!isset($print)) $printval[$name] = false; - $smarty->assign_by_ref($assign, $count[$name]); + $counter['assign'] = $assign; + } + + if (!empty($counter['assign'])) { + $smarty->assign($counter['assign'], $counter['count']); } + + if (!isset($print)) + $print = empty($counter['assign']); + else + $print = (bool)$print; - if ($printval[$name]) { - $retval = $count[$name]; + if (isset($skip)) { + $counter['skip'] = $skip; + } + + if ($print) { + $retval = $counter['count']; } else { $retval = null; } - if (isset($skip)) - $skipval[$name] = $skip; - else if (empty($skipval[$name])) - $skipval[$name] = 1; - - if (isset($direction)) - $dir[$name] = $direction; - else if (!isset($dir[$name])) - $dir[$name] = "up"; + if (isset($direction)) { + $counter['direction'] = $direction; + } - if ($dir[$name] == "down") - $count[$name] -= $skipval[$name]; + if ($counter['direction'] == "down") + $counter['count'] -= $counter['skip']; else - $count[$name] += $skipval[$name]; + $counter['count'] += $counter['skip']; return $retval;

« previous php.smarty.cvs (#619) next »