Files
smarty/libs/plugins/function.counter.php

73 lines
1.4 KiB
PHP
Raw Normal View History

2002-01-31 20:49:40 +00:00
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: counter
* Purpose: print out a counter value
* -------------------------------------------------------------
*/
2002-02-20 22:24:32 +00:00
function smarty_function_counter($params, &$smarty)
2002-01-31 20:49:40 +00:00
{
static $count = array();
static $skipval = array();
static $dir = array();
static $name = "default";
2002-01-31 20:49:40 +00:00
static $printval = array();
static $assign = "";
2002-02-20 22:24:32 +00:00
extract($params);
2002-01-31 20:49:40 +00:00
if (!isset($name)) {
if(isset($id)) {
$name = $id;
} else {
$name = "default";
}
}
2002-01-31 20:49:40 +00:00
if (isset($start))
$count[$name] = $start;
else if (!isset($count[$name]))
$count[$name]=1;
2002-01-31 20:49:40 +00:00
if (!isset($print))
$printval[$name]=true;
2002-01-31 20:49:40 +00:00
else
$printval[$name]=$print;
2002-01-31 20:49:40 +00:00
if (!empty($assign)) {
$printval[$name] = false;
$smarty->assign($assign, $count[$name]);
2002-01-31 20:49:40 +00:00
}
if ($printval[$name]) {
$retval = $count[$name];
} else {
$retval = null;
}
2002-01-31 20:49:40 +00:00
if (isset($skip))
$skipval[$name] = $skip;
else if (empty($skipval[$name]))
$skipval[$name] = 1;
2002-01-31 20:49:40 +00:00
if (isset($direction))
$dir[$name] = $direction;
else if (!isset($dir[$name]))
$dir[$name] = "up";
2002-01-31 20:49:40 +00:00
if ($dir[$name] == "down")
$count[$name] -= $skipval[$name];
2002-01-31 20:49:40 +00:00
else
$count[$name] += $skipval[$name];
return $retval;
2002-01-31 20:49:40 +00:00
}
/* vim: set expandtab: */
?>