Source for file section.php
Documentation is available at section.php
* Compatibility plugin for smarty templates, do not use otherwise, this is deprecated.
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
public function init($name, $loop, $start =
null, $step =
null, $max =
null, $show =
true)
public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
$output =
Dwoo_Compiler::PHP_OPEN;
$params =
$compiler->getCompiledParams($params);
$start =
$params['start'];
$output .=
'$this->globals[\'section\']['.
$name.
'] = array();'.
"\n".
'$_section'.
$cnt.
' =& $this->globals[\'section\']['.
$name.
'];'.
"\n";
$output .=
'$_section'.
$cnt.
'[\'loop\'] = is_array($tmp = '.
$loop.
') ? count($tmp) : max(0, (int) $tmp);'.
"\n";
$output .=
'$_section'.
$cnt.
'[\'loop\'] = 1;'.
"\n";
$output .=
'$_section'.
$cnt.
'[\'show\'] = '.
$show.
";\n";
$output .=
'$_section'.
$cnt.
'[\'show\'] = true;'.
"\n";
$output .=
'$_section'.
$cnt.
'[\'name\'] = '.
$name.
";\n";
$output .=
'$_section'.
$cnt.
'[\'name\'] = true;'.
"\n";
$output .=
'$_section'.
$cnt.
'[\'max\'] = (int)'.
$max.
";\n".
'if($_section'.
$cnt.
'[\'max\'] < 0) { $_section'.
$cnt.
'[\'max\'] = $_section'.
$cnt.
'[\'loop\']; }'.
"\n";
$output .=
'$_section'.
$cnt.
'[\'max\'] = $_section'.
$cnt.
'[\'loop\'];'.
"\n";
$output .=
'$_section'.
$cnt.
'[\'step\'] = (int)'.
$step.
' == 0 ? 1 : (int) '.
$step.
";\n";
$output .=
'$_section'.
$cnt.
'[\'step\'] = 1;'.
"\n";
$output .=
'$_section'.
$cnt.
'[\'start\'] = (int)'.
$start.
";\n";
$output .=
'$_section'.
$cnt.
'[\'start\'] = $_section'.
$cnt.
'[\'step\'] > 0 ? 0 : $_section'.
$cnt.
'[\'loop\'] - 1;'.
"\n".
'if ($_section'.
$cnt.
'[\'start\'] < 0) { $_section'.
$cnt.
'[\'start\'] = max($_section'.
$cnt.
'[\'step\'] > 0 ? 0 : -1, $_section'.
$cnt.
'[\'loop\'] + $_section'.
$cnt.
'[\'start\']); } '.
"\n".
'else { $_section'.
$cnt.
'[\'start\'] = min($_section'.
$cnt.
'[\'start\'], $_section'.
$cnt.
'[\'step\'] > 0 ? $_section'.
$cnt.
'[\'loop\'] : $_section'.
$cnt.
'[\'loop\'] -1); }'.
"\n";
$output .= "\n".'$this->globals["section"]['.$name.'] = array'."\n(";
if ($usesIndex) $output .="\n\t".'"index" => 0,';
if ($usesIteration) $output .="\n\t".'"iteration" => 1,';
if ($usesFirst) $output .="\n\t".'"first" => null,';
if ($usesLast) $output .="\n\t".'"last" => null,';
if ($usesShow) $output .="\n\t".'"show" => ($this->isArray($_for'.$cnt.'_from, true)) || (is_numeric($_for'.$cnt.'_from) && $_for'.$cnt.'_from != $_for'.$cnt.'_to),';
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),';
$out.="\n);\n".'$_section'.$cnt.'[\'glob\'] =& $this->globals["section"]['.$name.'];'."\n\n";
$output .=
'if ($_section'.
$cnt.
'[\'show\']) {'.
"\n";
if ($start ===
'null' &&
$step ===
'null' &&
$max ===
'null') {
$output .=
' $_section'.
$cnt.
'[\'total\'] = $_section'.
$cnt.
'[\'loop\'];'.
"\n";
$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";
$output .=
' if ($_section'.
$cnt.
'[\'total\'] == 0) {'.
"\n".
' $_section'.
$cnt.
'[\'show\'] = false;'.
"\n".
' $_section'.
$cnt.
'[\'total\'] = 0;'.
"\n}\n";
$output .=
'if ($_section'.
$cnt.
'[\'show\']) {'.
"\n";
$output .=
"\t".
'for ($this->scope['.
$name.
'] = $_section'.
$cnt.
'[\'start\'], $_section'.
$cnt.
'[\'iteration\'] = 1; '.
'$_section'.
$cnt.
'[\'iteration\'] <= $_section'.
$cnt.
'[\'total\']; '.
'$this->scope['.
$name.
'] += $_section'.
$cnt.
'[\'step\'], $_section'.
$cnt.
'[\'iteration\']++) {'.
"\n";
$output .=
"\t\t".
'$_section'.
$cnt.
'[\'rownum\'] = $_section'.
$cnt.
'[\'iteration\'];'.
"\n";
$output .=
"\t\t".
'$_section'.
$cnt.
'[\'index_prev\'] = $this->scope['.
$name.
'] - $_section'.
$cnt.
'[\'step\'];'.
"\n";
$output .=
"\t\t".
'$_section'.
$cnt.
'[\'index_next\'] = $this->scope['.
$name.
'] + $_section'.
$cnt.
'[\'step\'];'.
"\n";
$output .=
"\t\t".
'$_section'.
$cnt.
'[\'first\'] = ($_section'.
$cnt.
'[\'iteration\'] == 1);'.
"\n";
$output .=
"\t\t".
'$_section'.
$cnt.
'[\'last\'] = ($_section'.
$cnt.
'[\'iteration\'] == $_section'.
$cnt.
'[\'total\']);'.
"\n";
if (isset
($params['hasElse'])) {
$output .=
$params['hasElse'];
Documentation generated on Sat, 18 Jul 2009 21:05:19 +0200 by phpDocumentor 1.4.0