diff --git a/change_log.txt b/change_log.txt index f8909b76..0ef8e749 100644 --- a/change_log.txt +++ b/change_log.txt @@ -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 diff --git a/libs/plugins/function.counter.php b/libs/plugins/function.counter.php index 88e49d80..24959cd6 100644 --- a/libs/plugins/function.counter.php +++ b/libs/plugins/function.counter.php @@ -2,7 +2,7 @@ /** * Smarty plugin * @package Smarty - * @subpackage PluginsFunction + * @subpackage plugins */ @@ -15,24 +15,24 @@ * @author Monte Ohrt * @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: */ + +?> \ No newline at end of file diff --git a/libs/plugins/function.cycle.php b/libs/plugins/function.cycle.php index f1cb46ba..65f1d5b2 100644 --- a/libs/plugins/function.cycle.php +++ b/libs/plugins/function.cycle.php @@ -2,7 +2,7 @@ /** * Smarty plugin * @package Smarty - * @subpackage PluginsFunction + * @subpackage plugins */ /** @@ -12,6 +12,17 @@ * Name: cycle
* Date: May 3, 2002
* Purpose: cycle through given values
+ * 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:
*
@@ -25,77 +36,71 @@
  * @author credit to Mark Priatel 
  * @author credit to Gerard 
  * @author credit to Jason Sweat 
- * @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: */
+
+?>
\ No newline at end of file