Ignore:
Timestamp:
Jun 20, 2013, 5:38:47 AM (11 years ago)
Author:
rvelices
Message:

smarty 3 - first pass for tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/smarty/libs/plugins/function.cycle.php

    r3282 r23384  
    22/**
    33 * Smarty plugin
     4 *
    45 * @package Smarty
    5  * @subpackage plugins
     6 * @subpackage PluginsFunction
    67 */
    78
     
    1314 * Date:     May 3, 2002<br>
    1415 * Purpose:  cycle through given values<br>
    15  * Input:
    16  *         - name = name of cycle (optional)
    17  *         - values = comma separated list of values to cycle,
    18  *                    or an array of values to cycle
    19  *                    (this can be left out for subsequent calls)
    20  *         - reset = boolean - resets given var to true
    21  *         - print = boolean - print var or not. default is true
    22  *         - advance = boolean - whether or not to advance the cycle
    23  *         - delimiter = the value delimiter, default is ","
    24  *         - assign = boolean, assigns to template var instead of
    25  *                    printed.
    26  *
     16 * Params:
     17 * <pre>
     18 * - name      - name of cycle (optional)
     19 * - values    - comma separated list of values to cycle, or an array of values to cycle
     20 *               (this can be left out for subsequent calls)
     21 * - reset     - boolean - resets given var to true
     22 * - print     - boolean - print var or not. default is true
     23 * - advance   - boolean - whether or not to advance the cycle
     24 * - delimiter - the value delimiter, default is ","
     25 * - assign    - boolean, assigns to template var instead of printed.
     26 * </pre>
    2727 * Examples:<br>
    2828 * <pre>
     
    3131 * {cycle name=row}
    3232 * </pre>
    33  * @link http://smarty.php.net/manual/en/language.function.cycle.php {cycle}
     33 *
     34 * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle}
    3435 *       (Smarty online manual)
    3536 * @author Monte Ohrt <monte at ohrt dot com>
     
    3839 * @author credit to Jason Sweat <jsweat_php@yahoo.com>
    3940 * @version  1.3
    40  * @param array
    41  * @param Smarty
     41 * @param array                    $params   parameters
     42 * @param Smarty_Internal_Template $template template object
    4243 * @return string|null
    4344 */
    44 function smarty_function_cycle($params, &$smarty)
     45
     46function smarty_function_cycle($params, $template)
    4547{
    4648    static $cycle_vars;
    47    
     49
    4850    $name = (empty($params['name'])) ? 'default' : $params['name'];
    4951    $print = (isset($params['print'])) ? (bool)$params['print'] : true;
    5052    $advance = (isset($params['advance'])) ? (bool)$params['advance'] : true;
    5153    $reset = (isset($params['reset'])) ? (bool)$params['reset'] : false;
    52            
    53     if (!in_array('values', array_keys($params))) {
     54
     55    if (!isset($params['values'])) {
    5456        if(!isset($cycle_vars[$name]['values'])) {
    55             $smarty->trigger_error("cycle: missing 'values' parameter");
     57            trigger_error("cycle: missing 'values' parameter");
    5658            return;
    5759        }
     
    6466    }
    6567
    66     $cycle_vars[$name]['delimiter'] = (isset($params['delimiter'])) ? $params['delimiter'] : ',';
    67    
     68    if (isset($params['delimiter'])) {
     69        $cycle_vars[$name]['delimiter'] = $params['delimiter'];
     70    } elseif (!isset($cycle_vars[$name]['delimiter'])) {
     71        $cycle_vars[$name]['delimiter'] = ',';
     72    }
     73
    6874    if(is_array($cycle_vars[$name]['values'])) {
    6975        $cycle_array = $cycle_vars[$name]['values'];
     
    7177        $cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']);
    7278    }
    73    
     79
    7480    if(!isset($cycle_vars[$name]['index']) || $reset ) {
    7581        $cycle_vars[$name]['index'] = 0;
    7682    }
    77    
     83
    7884    if (isset($params['assign'])) {
    7985        $print = false;
    80         $smarty->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]);
     86        $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]);
    8187    }
    82        
     88
    8389    if($print) {
    8490        $retval = $cycle_array[$cycle_vars[$name]['index']];
     
    94100        }
    95101    }
    96    
     102
    97103    return $retval;
    98104}
    99105
    100 /* vim: set expandtab: */
    101 
    102106?>
Note: See TracChangeset for help on using the changeset viewer.