mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-01 04:41:37 +01:00
Implemented plugin architecture.
This commit is contained in:
63
libs/plugins/function.counter.php
Normal file
63
libs/plugins/function.counter.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Smarty plugin
|
||||
* -------------------------------------------------------------
|
||||
* Type: function
|
||||
* Name: counter
|
||||
* Purpose: print out a counter value
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
function smarty_function_counter($args, &$smarty_obj)
|
||||
{
|
||||
static $count = array();
|
||||
static $skipval = array();
|
||||
static $dir = array();
|
||||
static $id = "default";
|
||||
static $printval = array();
|
||||
static $assign = "";
|
||||
|
||||
extract($args);
|
||||
|
||||
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;
|
||||
$smarty_obj->assign($assign, $count[$id]);
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user