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();
|
2002-05-03 18:22:41 +00:00
|
|
|
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
|
|
|
|
2002-05-03 18:22:41 +00:00
|
|
|
if (!isset($name)) {
|
|
|
|
if(isset($id)) {
|
|
|
|
$name = $id;
|
|
|
|
} else {
|
|
|
|
$name = "default";
|
|
|
|
}
|
|
|
|
}
|
2002-01-31 20:49:40 +00:00
|
|
|
|
|
|
|
if (isset($start))
|
2002-05-03 18:22:41 +00:00
|
|
|
$count[$name] = $start;
|
|
|
|
else if (!isset($count[$name]))
|
|
|
|
$count[$name]=1;
|
2002-01-31 20:49:40 +00:00
|
|
|
|
|
|
|
if (!isset($print))
|
2002-05-03 18:22:41 +00:00
|
|
|
$printval[$name]=true;
|
2002-01-31 20:49:40 +00:00
|
|
|
else
|
2002-05-03 18:22:41 +00:00
|
|
|
$printval[$name]=$print;
|
2002-01-31 20:49:40 +00:00
|
|
|
|
|
|
|
if (!empty($assign)) {
|
2002-05-03 18:22:41 +00:00
|
|
|
$printval[$name] = false;
|
|
|
|
$smarty->assign($assign, $count[$name]);
|
2002-01-31 20:49:40 +00:00
|
|
|
}
|
|
|
|
|
2003-01-08 17:34:45 +00:00
|
|
|
if ($printval[$name]) {
|
|
|
|
$retval = $count[$name];
|
|
|
|
} else {
|
|
|
|
$retval = null;
|
|
|
|
}
|
2002-01-31 20:49:40 +00:00
|
|
|
|
|
|
|
if (isset($skip))
|
2002-05-03 18:22:41 +00:00
|
|
|
$skipval[$name] = $skip;
|
|
|
|
else if (empty($skipval[$name]))
|
|
|
|
$skipval[$name] = 1;
|
2002-01-31 20:49:40 +00:00
|
|
|
|
|
|
|
if (isset($direction))
|
2002-05-03 18:22:41 +00:00
|
|
|
$dir[$name] = $direction;
|
|
|
|
else if (!isset($dir[$name]))
|
|
|
|
$dir[$name] = "up";
|
2002-01-31 20:49:40 +00:00
|
|
|
|
2002-05-03 18:22:41 +00:00
|
|
|
if ($dir[$name] == "down")
|
|
|
|
$count[$name] -= $skipval[$name];
|
2002-01-31 20:49:40 +00:00
|
|
|
else
|
2002-05-03 18:22:41 +00:00
|
|
|
$count[$name] += $skipval[$name];
|
2003-01-08 17:34:45 +00:00
|
|
|
|
|
|
|
return $retval;
|
|
|
|
|
2002-01-31 20:49:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set expandtab: */
|
|
|
|
|
|
|
|
?>
|