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

62 lines
1.3 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 $id = "default";
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($id))
$id = "default";
if (isset($start))
$count[$id] = $start;
else if (!isset($count[$id]))
$count[$id]=1;
if (!isset($print))
$printval[$id]=true;
else
$printval[$id]=$print;
if (!empty($assign)) {
$printval[$id] = false;
2002-02-20 22:24:32 +00:00
$smarty->assign($assign, $count[$id]);
2002-01-31 20:49:40 +00:00
}
if ($printval[$id])
echo $count[$id];
if (isset($skip))
$skipval[$id] = $skip;
else if (empty($skipval[$id]))
$skipval[$id] = 1;
if (isset($direction))
$dir[$id] = $direction;
else if (!isset($dir[$id]))
$dir[$id] = "up";
if ($dir[$id] == "down")
$count[$id] -= $skipval[$id];
else
$count[$id] += $skipval[$id];
}
/* vim: set expandtab: */
?>