mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 03:14:27 +02:00
- make scope of {counter} and {cycle} tags again global as in Smarty2
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
27/05/2010
|
||||
- bugfix on object chaining using variable properties
|
||||
- make scope of {counter} and {cycle} tags again global as in Smarty2
|
||||
|
||||
26/05/2010
|
||||
- bugfix removed decrepated register_resource call in smarty_internal_template.php
|
||||
|
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
* @subpackage plugins
|
||||
*/
|
||||
|
||||
|
||||
@@ -15,24 +15,24 @@
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
|
||||
* (Smarty online manual)
|
||||
* @param array $params parameters
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @param array parameters
|
||||
* @param Smarty
|
||||
* @return string|null
|
||||
*/
|
||||
function smarty_function_counter($params, $smarty, $template)
|
||||
function smarty_function_counter($params, $smarty)
|
||||
{
|
||||
static $counters = array();
|
||||
|
||||
$name = (isset($params['name'])) ? $params['name'] : 'default';
|
||||
if (!isset($template->plugin_data['counter'][$name])) {
|
||||
$template->plugin_data['counter'][$name] = array(
|
||||
if (!isset($counters[$name])) {
|
||||
$counters[$name] = array(
|
||||
'start'=>1,
|
||||
'skip'=>1,
|
||||
'direction'=>'up',
|
||||
'count'=>1
|
||||
);
|
||||
}
|
||||
$counter = &$template->plugin_data['counter'][$name];
|
||||
$counter =& $counters[$name];
|
||||
|
||||
if (isset($params['start'])) {
|
||||
$counter['start'] = $counter['count'] = (int)$params['start'];
|
||||
@@ -43,7 +43,7 @@ function smarty_function_counter($params, $smarty, $template)
|
||||
}
|
||||
|
||||
if (isset($counter['assign'])) {
|
||||
$template->assign($counter['assign'], $counter['count']);
|
||||
$smarty->assign($counter['assign'], $counter['count']);
|
||||
}
|
||||
|
||||
if (isset($params['print'])) {
|
||||
@@ -75,4 +75,6 @@ function smarty_function_counter($params, $smarty, $template)
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage PluginsFunction
|
||||
* @subpackage plugins
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -12,6 +12,17 @@
|
||||
* Name: cycle<br>
|
||||
* Date: May 3, 2002<br>
|
||||
* Purpose: cycle through given values<br>
|
||||
* Input:
|
||||
* - name = name of cycle (optional)
|
||||
* - values = comma separated list of values to cycle,
|
||||
* or an array of values to cycle
|
||||
* (this can be left out for subsequent calls)
|
||||
* - reset = boolean - resets given var to true
|
||||
* - print = boolean - print var or not. default is true
|
||||
* - advance = boolean - whether or not to advance the cycle
|
||||
* - delimiter = the value delimiter, default is ","
|
||||
* - assign = boolean, assigns to template var instead of
|
||||
* printed.
|
||||
*
|
||||
* Examples:<br>
|
||||
* <pre>
|
||||
@@ -25,77 +36,71 @@
|
||||
* @author credit to Mark Priatel <mpriatel@rogers.com>
|
||||
* @author credit to Gerard <gerard@interfold.com>
|
||||
* @author credit to Jason Sweat <jsweat_php@yahoo.com>
|
||||
* @param array $params parameters
|
||||
* Input:
|
||||
* - name = name of cycle (optional)
|
||||
* - values = comma separated list of values to cycle,
|
||||
* or an array of values to cycle
|
||||
* (this can be left out for subsequent calls)
|
||||
* - reset = boolean - resets given var to true
|
||||
* - print = boolean - print var or not. default is true
|
||||
* - advance = boolean - whether or not to advance the cycle
|
||||
* - delimiter = the value delimiter, default is ","
|
||||
* - assign = boolean, assigns to template var instead of
|
||||
* printed.
|
||||
* @param object $smarty Smarty object
|
||||
* @param object $template template object
|
||||
* @version 1.3
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string|null
|
||||
*/
|
||||
function smarty_function_cycle($params, $smarty, $template)
|
||||
function smarty_function_cycle($params, $smarty)
|
||||
{
|
||||
static $cycle_vars;
|
||||
|
||||
$name = (empty($params['name'])) ? 'default' : $params['name'];
|
||||
$print = (isset($params['print'])) ? (bool)$params['print'] : true;
|
||||
$advance = (isset($params['advance'])) ? (bool)$params['advance'] : true;
|
||||
$reset = (isset($params['reset'])) ? (bool)$params['reset'] : false;
|
||||
|
||||
if (!in_array('values', array_keys($params))) {
|
||||
if(!isset($template->plugin_data['cycle'][$name]['values'])) {
|
||||
trigger_error("cycle: missing 'values' parameter",E_USER_WARNING);
|
||||
if(!isset($cycle_vars[$name]['values'])) {
|
||||
$smarty->trigger_error("cycle: missing 'values' parameter");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if(isset($template->plugin_data['cycle'][$name]['values'])
|
||||
&& $template->plugin_data['cycle'][$name]['values'] != $params['values'] ) {
|
||||
$template->plugin_data['cycle'][$name]['index'] = 0;
|
||||
if(isset($cycle_vars[$name]['values'])
|
||||
&& $cycle_vars[$name]['values'] != $params['values'] ) {
|
||||
$cycle_vars[$name]['index'] = 0;
|
||||
}
|
||||
$template->plugin_data['cycle'][$name]['values'] = $params['values'];
|
||||
$cycle_vars[$name]['values'] = $params['values'];
|
||||
}
|
||||
|
||||
if (isset($params['delimiter'])) {
|
||||
$template->plugin_data['cycle'][$name]['delimiter'] = $params['delimiter'];
|
||||
} elseif (!isset($template->plugin_data['cycle'][$name]['delimiter'])) {
|
||||
$template->plugin_data['cycle'][$name]['delimiter'] = ',';
|
||||
$cycle_vars[$name]['delimiter'] = $params['delimiter'];
|
||||
} elseif (!isset($cycle_vars[$name]['delimiter'])) {
|
||||
$cycle_vars[$name]['delimiter'] = ',';
|
||||
}
|
||||
|
||||
if(is_array($template->plugin_data['cycle'][$name]['values'])) {
|
||||
$cycle_array = $template->plugin_data['cycle'][$name]['values'];
|
||||
if(is_array($cycle_vars[$name]['values'])) {
|
||||
$cycle_array = $cycle_vars[$name]['values'];
|
||||
} else {
|
||||
$cycle_array = explode($template->plugin_data['cycle'][$name]['delimiter'],$template->plugin_data['cycle'][$name]['values']);
|
||||
$cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']);
|
||||
}
|
||||
|
||||
if(!isset($template->plugin_data['cycle'][$name]['index']) || $reset ) {
|
||||
$template->plugin_data['cycle'][$name]['index'] = 0;
|
||||
if(!isset($cycle_vars[$name]['index']) || $reset ) {
|
||||
$cycle_vars[$name]['index'] = 0;
|
||||
}
|
||||
|
||||
if (isset($params['assign'])) {
|
||||
$print = false;
|
||||
$template->assign($params['assign'], $cycle_array[$template->plugin_data['cycle'][$name]['index']]);
|
||||
$smarty->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]);
|
||||
}
|
||||
|
||||
if($print) {
|
||||
$retval = $cycle_array[$template->plugin_data['cycle'][$name]['index']];
|
||||
$retval = $cycle_array[$cycle_vars[$name]['index']];
|
||||
} else {
|
||||
$retval = null;
|
||||
}
|
||||
|
||||
if($advance) {
|
||||
if ( $template->plugin_data['cycle'][$name]['index'] >= count($cycle_array) -1 ) {
|
||||
$template->plugin_data['cycle'][$name]['index'] = 0;
|
||||
if ( $cycle_vars[$name]['index'] >= count($cycle_array) -1 ) {
|
||||
$cycle_vars[$name]['index'] = 0;
|
||||
} else {
|
||||
$template->plugin_data['cycle'][$name]['index']++;
|
||||
$cycle_vars[$name]['index']++;
|
||||
}
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
?>
|
||||
|
||||
/* vim: set expandtab: */
|
||||
|
||||
?>
|
Reference in New Issue
Block a user