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