| 1 |
<?php |
<?php |
| 2 |
|
/** |
|
/* |
|
| 3 |
* Smarty plugin |
* Smarty plugin |
| 4 |
* ------------------------------------------------------------- |
* @package Smarty |
| 5 |
* Type: function |
* @subpackage plugins |
| 6 |
* Name: counter |
*/ |
| 7 |
|
|
| 8 |
|
|
| 9 |
|
/** |
| 10 |
|
* Smarty {counter} function plugin |
| 11 |
|
* |
| 12 |
|
* Type: function<br> |
| 13 |
|
* Name: counter<br> |
| 14 |
* Purpose: print out a counter value |
* 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) |
function smarty_function_counter($params, &$smarty) |
| 22 |
{ |
{ |
| 23 |
static $count = array(); |
static $counters = array(); |
|
static $skipval = array(); |
|
|
static $dir = array(); |
|
|
static $name = "default"; |
|
|
static $printval = array(); |
|
|
static $assign = ""; |
|
|
|
|
|
extract($params); |
|
|
|
|
|
if (!isset($name)) { |
|
|
if(isset($id)) { |
|
|
$name = $id; |
|
|
} else { |
|
|
$name = "default"; |
|
|
} |
|
|
} |
|
|
|
|
|
if (isset($start)) |
|
|
$count[$name] = $start; |
|
|
else if (!isset($count[$name])) |
|
|
$count[$name]=1; |
|
| 24 |
|
|
| 25 |
if (!isset($print)) |
$name = (isset($params['name'])) ? $params['name'] : 'default'; |
| 26 |
$printval[$name]=true; |
if (!isset($counters[$name])) { |
| 27 |
else |
$counters[$name] = array( |
| 28 |
$printval[$name]=$print; |
'start'=>1, |
| 29 |
|
'skip'=>1, |
| 30 |
|
'direction'=>'up', |
| 31 |
|
'count'=>1 |
| 32 |
|
); |
| 33 |
|
} |
| 34 |
|
$counter =& $counters[$name]; |
| 35 |
|
|
| 36 |
|
if (isset($params['start'])) { |
| 37 |
|
$counter['start'] = $counter['count'] = (int)$params['start']; |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
if (!empty($params['assign'])) { |
| 41 |
|
$counter['assign'] = $params['assign']; |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
if (isset($counter['assign'])) { |
| 45 |
|
$smarty->assign($counter['assign'], $counter['count']); |
| 46 |
|
} |
| 47 |
|
|
| 48 |
if (!empty($assign)) { |
if (isset($params['print'])) { |
| 49 |
$printval[$name] = false; |
$print = (bool)$params['print']; |
| 50 |
$smarty->assign($assign, $count[$name]); |
} else { |
| 51 |
|
$print = empty($counter['assign']); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
if ($print) { |
| 55 |
|
$retval = $counter['count']; |
| 56 |
|
} else { |
| 57 |
|
$retval = null; |
| 58 |
} |
} |
| 59 |
|
|
| 60 |
if ($printval[$name]) |
if (isset($params['skip'])) { |
| 61 |
echo $count[$name]; |
$counter['skip'] = $params['skip']; |
| 62 |
|
} |
|
if (isset($skip)) |
|
|
$skipval[$name] = $skip; |
|
|
else if (empty($skipval[$name])) |
|
|
$skipval[$name] = 1; |
|
| 63 |
|
|
| 64 |
if (isset($direction)) |
if (isset($params['direction'])) { |
| 65 |
$dir[$name] = $direction; |
$counter['direction'] = $params['direction']; |
| 66 |
else if (!isset($dir[$name])) |
} |
|
$dir[$name] = "up"; |
|
| 67 |
|
|
| 68 |
if ($dir[$name] == "down") |
if ($counter['direction'] == "down") |
| 69 |
$count[$name] -= $skipval[$name]; |
$counter['count'] -= $counter['skip']; |
| 70 |
else |
else |
| 71 |
$count[$name] += $skipval[$name]; |
$counter['count'] += $counter['skip']; |
| 72 |
|
|
| 73 |
|
return $retval; |
| 74 |
|
|
| 75 |
} |
} |
| 76 |
|
|
| 77 |
/* vim: set expandtab: */ |
/* vim: set expandtab: */ |