Source for file section.php

Documentation is available at section.php

  1. <?php
  2.  
  3. /**
  4.  * Compatibility plugin for smarty templates, do not use otherwise, this is deprecated.
  5.  *
  6.  * This software is provided 'as-is', without any express or implied warranty.
  7.  * In no event will the authors be held liable for any damages arising from the use of this software.
  8.  *
  9.  * @author     Jordi Boggiano <j.boggiano@seld.be>
  10.  * @copyright  Copyright (c) 2008, Jordi Boggiano
  11.  * @license    http://dwoo.org/LICENSE   Modified BSD License
  12.  * @link       http://dwoo.org/
  13.  * @version    1.0.0
  14.  * @date       2008-10-23
  15.  * @package    Dwoo
  16.  */
  17. {
  18.     public static $cnt=0;
  19.  
  20.     public function init($name$loop$start null$step null$max null$show true)
  21.     {
  22.     }
  23.  
  24.     public static function preProcessing(Dwoo_Compiler $compilerarray $params$prepend$append$type)
  25.     {
  26.         return '';
  27.     }
  28.  
  29.     public static function postProcessing(Dwoo_Compiler $compilerarray $params$prepend$append$content)
  30.     {
  31.         $output Dwoo_Compiler::PHP_OPEN;
  32.         $params $compiler->getCompiledParams($params);
  33.  
  34.         // assigns params
  35.         $loop $params['loop'];
  36.         $start $params['start'];
  37.         $max $params['max'];
  38.         $name $params['name'];
  39.         $step $params['step'];
  40.         $show $params['show'];
  41.  
  42.         // gets unique id
  43.         $cnt self::$cnt++;
  44.  
  45.         $output .= '$this->globals[\'section\']['.$name.'] = array();'."\n".
  46.         '$_section'.$cnt.' =& $this->globals[\'section\']['.$name.'];'."\n";
  47.  
  48.         if ($loop !== 'null'{
  49.             $output .= '$_section'.$cnt.'[\'loop\'] = is_array($tmp = '.$loop.') ? count($tmp) : max(0, (int) $tmp);'."\n";
  50.         else {
  51.             $output .= '$_section'.$cnt.'[\'loop\'] = 1;'."\n";
  52.         }
  53.  
  54.         if ($show !== 'null'{
  55.             $output .= '$_section'.$cnt.'[\'show\'] = '.$show.";\n";
  56.         else {
  57.             $output .= '$_section'.$cnt.'[\'show\'] = true;'."\n";
  58.         }
  59.  
  60.         if ($name !== 'null'{
  61.             $output .= '$_section'.$cnt.'[\'name\'] = '.$name.";\n";
  62.         else {
  63.             $output .= '$_section'.$cnt.'[\'name\'] = true;'."\n";
  64.         }
  65.  
  66.         if ($max !== 'null'{
  67.             $output .= '$_section'.$cnt.'[\'max\'] = (int)'.$max.";\n".
  68.                         'if($_section'.$cnt.'[\'max\'] < 0) { $_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\']; }'."\n";
  69.         else {
  70.             $output .= '$_section'.$cnt.'[\'max\'] = $_section'.$cnt.'[\'loop\'];'."\n";
  71.         }
  72.  
  73.         if ($step !== 'null'{
  74.             $output .= '$_section'.$cnt.'[\'step\'] = (int)'.$step.' == 0 ? 1 : (int) '.$step.";\n";
  75.         else {
  76.             $output .= '$_section'.$cnt.'[\'step\'] = 1;'."\n";
  77.         }
  78.  
  79.         if ($start !== 'null'{
  80.             $output .= '$_section'.$cnt.'[\'start\'] = (int)'.$start.";\n";
  81.         else {
  82.             $output .= '$_section'.$cnt.'[\'start\'] = $_section'.$cnt.'[\'step\'] > 0 ? 0 : $_section'.$cnt.'[\'loop\'] - 1;'."\n".
  83.                         'if ($_section'.$cnt.'[\'start\'] < 0) { $_section'.$cnt.'[\'start\'] = max($_section'.$cnt.'[\'step\'] > 0 ? 0 : -1, $_section'.$cnt.'[\'loop\'] + $_section'.$cnt.'[\'start\']); } '."\n".
  84.                         'else { $_section'.$cnt.'[\'start\'] = min($_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] : $_section'.$cnt.'[\'loop\'] -1); }'."\n";
  85.         }
  86.  
  87. /*        if ($usesAny) {
  88.             $output .= "\n".'$this->globals["section"]['.$name.'] = array'."\n(";
  89.             if ($usesIndex) $output .="\n\t".'"index"        => 0,';
  90.             if ($usesIteration) $output .="\n\t".'"iteration"        => 1,';
  91.             if ($usesFirst) $output .="\n\t".'"first"        => null,';
  92.             if ($usesLast) $output .="\n\t".'"last"        => null,';
  93.             if ($usesShow) $output .="\n\t".'"show"        => ($this->isArray($_for'.$cnt.'_from, true)) || (is_numeric($_for'.$cnt.'_from) && $_for'.$cnt.'_from != $_for'.$cnt.'_to),';
  94.             if ($usesTotal) $output .="\n\t".'"total"        => $this->isArray($_for'.$cnt.'_from) ? count($_for'.$cnt.'_from) - $_for'.$cnt.'_skip : (is_numeric($_for'.$cnt.'_from) ? abs(($_for'.$cnt.'_to + 1 - $_for'.$cnt.'_from)/$_for'.$cnt.'_step) : 0),';
  95.             $out.="\n);\n".'$_section'.$cnt.'[\'glob\'] =& $this->globals["section"]['.$name.'];'."\n\n";
  96.         }
  97. */
  98.  
  99.         $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n";
  100.         if ($start === 'null' && $step === 'null' && $max === 'null'{
  101.             $output .= '    $_section'.$cnt.'[\'total\'] = $_section'.$cnt.'[\'loop\'];'."\n";
  102.         else {
  103.             $output .= '    $_section'.$cnt.'[\'total\'] = min(ceil(($_section'.$cnt.'[\'step\'] > 0 ? $_section'.$cnt.'[\'loop\'] - $_section'.$cnt.'[\'start\'] : $_section'.$cnt.'[\'start\'] + 1) / abs($_section'.$cnt.'[\'step\'])), $_section'.$cnt.'[\'max\']);'."\n";
  104.         }
  105.         $output .= '    if ($_section'.$cnt.'[\'total\'] == 0) {'."\n".
  106.                    '        $_section'.$cnt.'[\'show\'] = false;'."\n".
  107.                    '    }'."\n".
  108.                    '} else {'."\n".
  109.                    '    $_section'.$cnt.'[\'total\'] = 0;'."\n}\n";
  110.         $output .= 'if ($_section'.$cnt.'[\'show\']) {'."\n";
  111.         $output .= "\t".'for ($this->scope['.$name.'] = $_section'.$cnt.'[\'start\'], $_section'.$cnt.'[\'iteration\'] = 1; '.
  112.                      '$_section'.$cnt.'[\'iteration\'] <= $_section'.$cnt.'[\'total\']; '.
  113.                      '$this->scope['.$name.'] += $_section'.$cnt.'[\'step\'], $_section'.$cnt.'[\'iteration\']++) {'."\n";
  114.         $output .= "\t\t".'$_section'.$cnt.'[\'rownum\'] = $_section'.$cnt.'[\'iteration\'];'."\n";
  115.         $output .= "\t\t".'$_section'.$cnt.'[\'index_prev\'] = $this->scope['.$name.'] - $_section'.$cnt.'[\'step\'];'."\n";
  116.         $output .= "\t\t".'$_section'.$cnt.'[\'index_next\'] = $this->scope['.$name.'] + $_section'.$cnt.'[\'step\'];'."\n";
  117.         $output .= "\t\t".'$_section'.$cnt.'[\'first\']      = ($_section'.$cnt.'[\'iteration\'] == 1);'."\n";
  118.         $output .= "\t\t".'$_section'.$cnt.'[\'last\']       = ($_section'.$cnt.'[\'iteration\'] == $_section'.$cnt.'[\'total\']);'."\n";
  119.  
  120.         $output .= Dwoo_Compiler::PHP_CLOSE $content Dwoo_Compiler::PHP_OPEN;
  121.  
  122.         $output .= "\n\t}\n} " Dwoo_Compiler::PHP_CLOSE;
  123.  
  124.         if (isset($params['hasElse'])) {
  125.             $output .= $params['hasElse'];
  126.         }
  127.  
  128.         return $output;
  129.     }
  130. }

Documentation generated on Sat, 18 Jul 2009 21:05:19 +0200 by phpDocumentor 1.4.0