1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/piwigo_ynh.git synced 2024-09-03 20:06:03 +02:00
piwigo_ynh/sources/include/smarty/libs/plugins/function.counter.php

79 lines
1.8 KiB
PHP
Raw Normal View History

2014-07-06 13:21:10 +02:00
<?php
/**
* Smarty plugin
2016-08-27 21:53:29 +02:00
*
* @package Smarty
2014-07-06 13:21:10 +02:00
* @subpackage PluginsFunction
*/
/**
* Smarty {counter} function plugin
* Type: function<br>
* Name: counter<br>
* Purpose: print out a counter value
*
* @author Monte Ohrt <monte at ohrt dot com>
2016-08-27 21:53:29 +02:00
* @link http://www.smarty.net/manual/en/language.function.counter.php {counter}
* (Smarty online manual)
*
2014-07-06 13:21:10 +02:00
* @param array $params parameters
* @param Smarty_Internal_Template $template template object
2016-08-27 21:53:29 +02:00
*
2014-07-06 13:21:10 +02:00
* @return string|null
*/
function smarty_function_counter($params, $template)
{
static $counters = array();
$name = (isset($params['name'])) ? $params['name'] : 'default';
if (!isset($counters[$name])) {
$counters[$name] = array(
2016-08-27 21:53:29 +02:00
'start' => 1,
'skip' => 1,
'direction' => 'up',
'count' => 1
);
2014-07-06 13:21:10 +02:00
}
$counter =& $counters[$name];
if (isset($params['start'])) {
2016-08-27 21:53:29 +02:00
$counter['start'] = $counter['count'] = (int) $params['start'];
2014-07-06 13:21:10 +02:00
}
if (!empty($params['assign'])) {
$counter['assign'] = $params['assign'];
}
if (isset($counter['assign'])) {
$template->assign($counter['assign'], $counter['count']);
}
2016-08-27 21:53:29 +02:00
2014-07-06 13:21:10 +02:00
if (isset($params['print'])) {
2016-08-27 21:53:29 +02:00
$print = (bool) $params['print'];
2014-07-06 13:21:10 +02:00
} else {
$print = empty($counter['assign']);
}
if ($print) {
$retval = $counter['count'];
} else {
$retval = null;
}
if (isset($params['skip'])) {
$counter['skip'] = $params['skip'];
}
2016-08-27 21:53:29 +02:00
2014-07-06 13:21:10 +02:00
if (isset($params['direction'])) {
$counter['direction'] = $params['direction'];
}
2016-08-27 21:53:29 +02:00
if ($counter['direction'] == "down") {
2014-07-06 13:21:10 +02:00
$counter['count'] -= $counter['skip'];
2016-08-27 21:53:29 +02:00
} else {
2014-07-06 13:21:10 +02:00
$counter['count'] += $counter['skip'];
2016-08-27 21:53:29 +02:00
}
2014-07-06 13:21:10 +02:00
return $retval;
}