public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) { $params = $compiler->getCompiledParams($params); $func = $params['__funcname']; $pluginType = $params['__functype']; $params = $params['*']; if ($pluginType & Core::CUSTOM_PLUGIN) { $customPlugins = $compiler->getCore()->getCustomPlugins(); $callback = $customPlugins[$func]['callback']; if (is_array($callback)) { if (is_object($callback[0])) { $callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '('; } else { $callback = '' . $callback[0] . '::' . $callback[1] . '('; } } else { $callback = $callback . '('; } } else { $callback = 'smarty_block_' . $func . '('; } $paramsOut = ''; foreach ($params as $i => $p) { $paramsOut .= var_export($i, true) . ' => ' . $p . ','; } $curBlock =& $compiler->getCurrentBlock(); $curBlock['params']['postOut'] = Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Compiler::PHP_CLOSE; return Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Compiler::PHP_CLOSE; }
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) { $params = $compiler->getCompiledParams($params); $parsedParams = array(); if (!isset($params['*'])) { $params['*'] = array(); } foreach ($params['*'] as $param => $defValue) { if (is_numeric($param)) { $param = $defValue; $defValue = null; } $param = trim($param, '\'"'); if (!preg_match('#^[a-z0-9_]+$#i', $param)) { throw new CompilationException($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _'); } $parsedParams[$param] = $defValue; } $params['name'] = substr($params['name'], 1, -1); $params['*'] = $parsedParams; $params['uuid'] = uniqid(); $compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']); $currentBlock =& $compiler->getCurrentBlock(); $currentBlock['params'] = $params; return ''; }
public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) { $params = $compiler->getCompiledParams($params); switch (strtolower(trim((string) $params['enabled'], '"\''))) { case 'on': case 'true': case 'enabled': case 'enable': case '1': $enable = true; break; case 'off': case 'false': case 'disabled': case 'disable': case '0': $enable = false; break; default: throw new CompilationException($compiler, 'Auto_Escape : Invalid parameter (' . $params['enabled'] . '), valid parameters are "enable"/true or "disable"/false'); } self::$stack[] = $compiler->getAutoEscape(); $compiler->setAutoEscape($enable); return ''; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $rparams = $compiler->getRealParams($params); $cparams = $compiler->getCompiledParams($params); $compiler->setScope($rparams['var']); $pre = Compiler::PHP_OPEN . 'if (' . $cparams['var'] . ')' . "\n{\n" . '$_with' . self::$cnt . ' = $this->setScope("' . $rparams['var'] . '");' . "\n/* -- start with output */\n" . Compiler::PHP_CLOSE; $post = Compiler::PHP_OPEN . "\n/* -- end with output */\n" . '$this->setScope($_with' . self::$cnt++ . ', true);' . "\n}\n" . Compiler::PHP_CLOSE; if (isset($params['hasElse'])) { $post .= $params['hasElse']; } return $pre . $content . $post; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $params = $compiler->getCompiledParams($params); $mode = trim($params['mode'], '"\''); switch ($mode) { case 'js': case 'javascript': $content = preg_replace('#(?<!:)//\\s[^\\r\\n]*|/\\*.*?\\*/#s', '', $content); case 'default': default: } $content = preg_replace(array("/\n/", "/\r/", '/(<\\?(?:php)?|<%)\\s*/'), array('', '', '$1 '), preg_replace('#^\\s*(.+?)\\s*$#m', '$1', $content)); return $content; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $params = $compiler->getCompiledParams($params); $out = $content . Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();'; if ($params['trim'] !== 'false' && $params['trim'] !== 0) { $out .= "\n" . '$tmp = trim($tmp);'; } if ($params['cat'] === 'true' || $params['cat'] === 1) { $out .= "\n" . '$tmp = $this->readVar(\'dwoo.capture.\'.' . $params['name'] . ') . $tmp;'; } if ($params['assign'] !== 'null') { $out .= "\n" . '$this->scope[' . $params['assign'] . '] = $tmp;'; } return $out . "\n" . '$this->globals[\'capture\'][' . $params['name'] . '] = $tmp;' . $append . Compiler::PHP_CLOSE; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $p = $compiler->getCompiledParams($params); // no content was provided so use the url as display text if ($content == "") { // merge </a> into the href if href is a string if (substr($p['href'], -1) === '"' || substr($p['href'], -1) === '\'') { return Compiler::PHP_OPEN . 'echo ' . substr($p['href'], 0, -1) . '</a>' . substr($p['href'], -1) . ';' . Compiler::PHP_CLOSE; } // otherwise append return Compiler::PHP_OPEN . 'echo ' . $p['href'] . '.\'</a>\';' . Compiler::PHP_CLOSE; } // return content return $content . '</a>'; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { if (!isset($params['initialized'])) { return ''; } $tokens = $compiler->getParamTokens($params); $params = $compiler->getCompiledParams($params); $pre = Compiler::PHP_OPEN . "else if (" . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; if (isset($params['hasElse'])) { $post .= $params['hasElse']; } $block =& $compiler->getCurrentBlock(); $block['params']['hasElse'] = $pre . $content . $post; return ''; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $params = $compiler->getCompiledParams($params); $out = $content . Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();'; return $out . "\n" . 'if (!class_exists(\'\\Dwoo\\Plugins\\Blocks\\BlockScriptCapture\', false)) { $this->getLoader()->loadPlugin(\'script_capture\'); }' . "\n" . '\\Dwoo\\Plugins\\Blocks\\BlockScriptCapture::addScript(' . $params['name'] . ',$tmp);' . $append . Compiler::PHP_CLOSE; }
/** * called at compile time to define what the block should output in the compiled template code, happens when the block is declared * basically this will replace the {block arg arg arg} tag in the template * @param Compiler $compiler the compiler instance that calls this function * @param array $params an array containing original and compiled parameters * @param string $prepend that is just meant to allow a child class to call * parent::postProcessing($compiler, $params, "foo();") to add a command before the * default commands are executed * @param string $append that is just meant to allow a child class to call * parent::postProcessing($compiler, $params, null, "foo();") to add a command after the * default commands are executed * @param string $type the type is the plugin class name used * * @return string */ public static function preProcessing(Compiler $compiler, array $params, $prepend, $append, $type) { return Compiler::PHP_OPEN . $prepend . '$this->addStack("' . $type . '", array(' . Compiler::implode_r($compiler->getCompiledParams($params)) . '));' . $append . Compiler::PHP_CLOSE; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $params = $compiler->getCompiledParams($params); $tpl = $compiler->getTemplateSource($params['tplPointer']); // assigns params $src = $params['from']; if ($params['item'] !== 'null') { if ($params['key'] !== 'null') { $key = $params['key']; } $val = $params['item']; } elseif ($params['key'] !== 'null') { $val = $params['key']; } else { throw new CompilationException($compiler, 'Foreach <em>item</em> parameter missing'); } $name = $params['name']; if (substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { throw new CompilationException($compiler, 'Foreach <em>item</em> parameter must be of type string'); } if (isset($key) && substr($val, 0, 1) !== '"' && substr($val, 0, 1) !== '\'') { throw new CompilationException($compiler, 'Foreach <em>key</em> parameter must be of type string'); } // evaluates which global variables have to be computed $varName = '$dwoo.foreach.' . trim($name, '"\'') . '.'; $shortVarName = '$.foreach.' . trim($name, '"\'') . '.'; $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; if (strpos($name, '$this->scope[') !== false) { $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; } // override globals vars if implode is used if ($params['implode'] !== 'null') { $implode = $params['implode']; $usesAny = true; $usesLast = true; $usesIteration = true; $usesTotal = true; } // gets foreach id $cnt = self::$cnt++; // build pre content output $pre = Compiler::PHP_OPEN . "\n" . '$_fh' . $cnt . '_data = ' . $src . ';'; // adds foreach properties if ($usesAny) { $pre .= "\n" . '$this->globals["foreach"][' . $name . '] = array' . "\n("; if ($usesIndex) { $pre .= "\n\t" . '"index" => 0,'; } if ($usesIteration) { $pre .= "\n\t" . '"iteration" => 1,'; } if ($usesFirst) { $pre .= "\n\t" . '"first" => null,'; } if ($usesLast) { $pre .= "\n\t" . '"last" => null,'; } if ($usesShow) { $pre .= "\n\t" . '"show" => $this->isArray($_fh' . $cnt . '_data, true),'; } if ($usesTotal) { $pre .= "\n\t" . '"total" => $this->count($_fh' . $cnt . '_data),'; } $pre .= "\n);\n" . '$_fh' . $cnt . '_glob =& $this->globals["foreach"][' . $name . '];'; } // checks if foreach must be looped $pre .= "\n" . 'if ($this->isTraversable($_fh' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{"; // iterates over keys $pre .= "\n\t" . 'foreach ($_fh' . $cnt . '_data as ' . (isset($key) ? '$this->scope[' . $key . ']=>' : '') . '$this->scope[' . $val . '])' . "\n\t{"; // updates properties if ($usesFirst) { $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["first"] = (string) ($_fh' . $cnt . '_glob["index"] === 0);'; } if ($usesLast) { $pre .= "\n\t\t" . '$_fh' . $cnt . '_glob["last"] = (string) ($_fh' . $cnt . '_glob["iteration"] === $_fh' . $cnt . '_glob["total"]);'; } $pre .= "\n/* -- foreach start output */\n" . Compiler::PHP_CLOSE; // build post content output $post = Compiler::PHP_OPEN . "\n"; if (isset($implode)) { $post .= '/* -- implode */' . "\n" . 'if (!$_fh' . $cnt . '_glob["last"]) {' . "\n\t" . 'echo ' . $implode . ";\n}\n"; } $post .= '/* -- foreach end output */'; // update properties if ($usesIndex) { $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["index"]+=1;'; } if ($usesIteration) { $post .= "\n\t\t" . '$_fh' . $cnt . '_glob["iteration"]+=1;'; } // end loop $post .= "\n\t}\n}" . Compiler::PHP_CLOSE; if (isset($params['hasElse'])) { $post .= $params['hasElse']; } return $pre . $content . $post; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $params = $compiler->getCompiledParams($params); $tpl = $compiler->getTemplateSource($params['tplPointer']); // assigns params $src = $params['from']; $name = $params['name']; // evaluates which global variables have to be computed $varName = '$dwoo.loop.' . trim($name, '"\'') . '.'; $shortVarName = '$.loop.' . trim($name, '"\'') . '.'; $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; $usesIndex = $usesFirst || strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; $usesIteration = $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; if (strpos($name, '$this->scope[') !== false) { $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; } // gets foreach id $cnt = self::$cnt++; // builds pre processing output $pre = Compiler::PHP_OPEN . "\n" . '$_loop' . $cnt . '_data = ' . $src . ';'; // adds foreach properties if ($usesAny) { $pre .= "\n" . '$this->globals["loop"][' . $name . '] = array' . "\n("; if ($usesIndex) { $pre .= "\n\t" . '"index" => 0,'; } if ($usesIteration) { $pre .= "\n\t" . '"iteration" => 1,'; } if ($usesFirst) { $pre .= "\n\t" . '"first" => null,'; } if ($usesLast) { $pre .= "\n\t" . '"last" => null,'; } if ($usesShow) { $pre .= "\n\t" . '"show" => $this->isTraversable($_loop' . $cnt . '_data, true),'; } if ($usesTotal) { $pre .= "\n\t" . '"total" => $this->count($_loop' . $cnt . '_data),'; } $pre .= "\n);\n" . '$_loop' . $cnt . '_glob =& $this->globals["loop"][' . $name . '];'; } // checks if the loop must be looped $pre .= "\n" . 'if ($this->isTraversable($_loop' . $cnt . '_data' . (isset($params['hasElse']) ? ', true' : '') . ') == true)' . "\n{"; // iterates over keys $pre .= "\n\t" . 'foreach ($_loop' . $cnt . '_data as $tmp_key => $this->scope["-loop-"])' . "\n\t{"; // updates properties if ($usesFirst) { $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["first"] = (string) ($_loop' . $cnt . '_glob["index"] === 0);'; } if ($usesLast) { $pre .= "\n\t\t" . '$_loop' . $cnt . '_glob["last"] = (string) ($_loop' . $cnt . '_glob["iteration"] === $_loop' . $cnt . '_glob["total"]);'; } $pre .= "\n\t\t" . '$_loop' . $cnt . '_scope = $this->setScope(array("-loop-"));' . "\n/* -- loop start output */\n" . Compiler::PHP_CLOSE; // build post processing output and cache it $post = Compiler::PHP_OPEN . "\n" . '/* -- loop end output */' . "\n\t\t" . '$this->setScope($_loop' . $cnt . '_scope, true);'; // update properties if ($usesIndex) { $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["index"]+=1;'; } if ($usesIteration) { $post .= "\n\t\t" . '$_loop' . $cnt . '_glob["iteration"]+=1;'; } // end loop $post .= "\n\t}\n}\n" . Compiler::PHP_CLOSE; if (isset($params['hasElse'])) { $post .= $params['hasElse']; } return $pre . $content . $post; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $params = $compiler->getCompiledParams($params); $tpl = $compiler->getTemplateSource($params['tplPointer']); // assigns params $from = $params['from']; $name = $params['name']; $step = $params['step']; $to = $params['to']; // evaluates which global variables have to be computed $varName = '$dwoo.for.' . trim($name, '"\'') . '.'; $shortVarName = '$.for.' . trim($name, '"\'') . '.'; $usesAny = strpos($tpl, $varName) !== false || strpos($tpl, $shortVarName) !== false; $usesFirst = strpos($tpl, $varName . 'first') !== false || strpos($tpl, $shortVarName . 'first') !== false; $usesLast = strpos($tpl, $varName . 'last') !== false || strpos($tpl, $shortVarName . 'last') !== false; $usesIndex = strpos($tpl, $varName . 'index') !== false || strpos($tpl, $shortVarName . 'index') !== false; $usesIteration = $usesFirst || $usesLast || strpos($tpl, $varName . 'iteration') !== false || strpos($tpl, $shortVarName . 'iteration') !== false; $usesShow = strpos($tpl, $varName . 'show') !== false || strpos($tpl, $shortVarName . 'show') !== false; $usesTotal = $usesLast || strpos($tpl, $varName . 'total') !== false || strpos($tpl, $shortVarName . 'total') !== false; if (strpos($name, '$this->scope[') !== false) { $usesAny = $usesFirst = $usesLast = $usesIndex = $usesIteration = $usesShow = $usesTotal = true; } // gets foreach id $cnt = self::$cnt++; // builds pre processing output for $out = Compiler::PHP_OPEN . "\n" . '$_for' . $cnt . '_from = ' . $from . ';' . "\n" . '$_for' . $cnt . '_to = ' . $to . ';' . "\n" . '$_for' . $cnt . '_step = abs(' . $step . ');' . "\n" . 'if (is_numeric($_for' . $cnt . '_from) && !is_numeric($_for' . $cnt . '_to)) { $this->triggerError(\'For requires the <em>to</em> parameter when using a numerical <em>from</em>\'); }' . "\n" . '$tmp_shows = $this->isArray($_for' . $cnt . '_from, true) || (is_numeric($_for' . $cnt . '_from) && (abs(($_for' . $cnt . '_from - $_for' . $cnt . '_to)/$_for' . $cnt . '_step) !== 0 || $_for' . $cnt . '_from == $_for' . $cnt . '_to));'; // adds for properties if ($usesAny) { $out .= "\n" . '$this->globals["for"][' . $name . '] = array' . "\n("; if ($usesIndex) { $out .= "\n\t" . '"index" => 0,'; } if ($usesIteration) { $out .= "\n\t" . '"iteration" => 1,'; } if ($usesFirst) { $out .= "\n\t" . '"first" => null,'; } if ($usesLast) { $out .= "\n\t" . '"last" => null,'; } if ($usesShow) { $out .= "\n\t" . '"show" => $tmp_shows,'; } if ($usesTotal) { $out .= "\n\t" . '"total" => $this->isArray($_for' . $cnt . '_from) ? floor($this->count($_for' . $cnt . '_from) / $_for' . $cnt . '_step) : (is_numeric($_for' . $cnt . '_from) ? abs(($_for' . $cnt . '_to + 1 - $_for' . $cnt . '_from)/$_for' . $cnt . '_step) : 0),'; } $out .= "\n);\n" . '$_for' . $cnt . '_glob =& $this->globals["for"][' . $name . '];'; } // checks if for must be looped $out .= "\n" . 'if ($tmp_shows)' . "\n{"; // set from/to to correct values if an array was given $out .= "\n\t" . 'if ($this->isArray($_for' . $cnt . '_from' . (isset($params['hasElse']) ? ', true' : '') . ') == true) { $_for' . $cnt . '_to = is_numeric($_for' . $cnt . '_to) ? $_for' . $cnt . '_to - $_for' . $cnt . '_step : $this->count($_for' . $cnt . '_from) - 1; $_for' . $cnt . '_from = 0; }'; // if input are pure numbers it shouldn't reorder them, if it's variables it gets too messy though so in that case a counter should be used $reverse = false; $condition = '<='; $incrementer = '+'; if (preg_match('{^(["\']?)([0-9]+)\\1$}', $from, $mN1) && preg_match('{^(["\']?)([0-9]+)\\1$}', $to, $mN2)) { $from = (int) $mN1[2]; $to = (int) $mN2[2]; if ($from > $to) { $reverse = true; $condition = '>='; $incrementer = '-'; } } // reverse from and to if needed if (!$reverse) { $out .= "\n\t" . 'if ($_for' . $cnt . '_from > $_for' . $cnt . '_to) { $tmp = $_for' . $cnt . '_from; $_for' . $cnt . '_from = $_for' . $cnt . '_to; $_for' . $cnt . '_to = $tmp; }'; } $out .= "\n\t" . 'for ($this->scope[' . $name . '] = $_for' . $cnt . '_from; $this->scope[' . $name . '] ' . $condition . ' $_for' . $cnt . '_to; $this->scope[' . $name . '] ' . $incrementer . '= $_for' . $cnt . '_step)' . "\n\t{"; // updates properties if ($usesIndex) { $out .= "\n\t\t" . '$_for' . $cnt . '_glob["index"] = $this->scope[' . $name . '];'; } if ($usesFirst) { $out .= "\n\t\t" . '$_for' . $cnt . '_glob["first"] = (string) ($_for' . $cnt . '_glob["iteration"] === 1);'; } if ($usesLast) { $out .= "\n\t\t" . '$_for' . $cnt . '_glob["last"] = (string) ($_for' . $cnt . '_glob["iteration"] === $_for' . $cnt . '_glob["total"]);'; } $out .= "\n/* -- for start output */\n" . Compiler::PHP_CLOSE; // build post processing output and cache it $postOut = Compiler::PHP_OPEN . '/* -- for end output */'; // update properties if ($usesIteration) { $postOut .= "\n\t\t" . '$_for' . $cnt . '_glob["iteration"]+=1;'; } // end loop $postOut .= "\n\t}\n}\n" . Compiler::PHP_CLOSE; if (isset($params['hasElse'])) { $postOut .= $params['hasElse']; } return $out . $content . $postOut; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $tokens = $compiler->getParamTokens($params); $params = $compiler->getCompiledParams($params); $pre = Compiler::PHP_OPEN . 'if (' . implode(' ', self::replaceKeywords($params['*'], $tokens['*'], $compiler)) . ") {\n" . Compiler::PHP_CLOSE; $post = Compiler::PHP_OPEN . "\n}" . Compiler::PHP_CLOSE; if (isset($params['hasElse'])) { $post .= $params['hasElse']; } return $pre . $content . $post; }
public static function postProcessing(Compiler $compiler, array $params, $prepend, $append, $content) { $output = Compiler::PHP_OPEN; $params = $compiler->getCompiledParams($params); // assigns params $loop = $params['loop']; $start = $params['start']; $max = $params['max']; $name = $params['name']; $step = $params['step']; $show = $params['show']; // gets unique id $cnt = self::$cnt++; $output .= '$this->globals[\'section\'][' . $name . '] = array();' . "\n" . '$_section' . $cnt . ' =& $this->globals[\'section\'][' . $name . '];' . "\n"; if ($loop !== 'null') { $output .= '$_section' . $cnt . '[\'loop\'] = is_array($tmp = ' . $loop . ') ? count($tmp) : max(0, (int) $tmp);' . "\n"; } else { $output .= '$_section' . $cnt . '[\'loop\'] = 1;' . "\n"; } if ($show !== 'null') { $output .= '$_section' . $cnt . '[\'show\'] = ' . $show . ";\n"; } else { $output .= '$_section' . $cnt . '[\'show\'] = true;' . "\n"; } if ($name !== 'null') { $output .= '$_section' . $cnt . '[\'name\'] = ' . $name . ";\n"; } else { $output .= '$_section' . $cnt . '[\'name\'] = true;' . "\n"; } if ($max !== 'null') { $output .= '$_section' . $cnt . '[\'max\'] = (int)' . $max . ";\n" . 'if($_section' . $cnt . '[\'max\'] < 0) { $_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\']; }' . "\n"; } else { $output .= '$_section' . $cnt . '[\'max\'] = $_section' . $cnt . '[\'loop\'];' . "\n"; } if ($step !== 'null') { $output .= '$_section' . $cnt . '[\'step\'] = (int)' . $step . ' == 0 ? 1 : (int) ' . $step . ";\n"; } else { $output .= '$_section' . $cnt . '[\'step\'] = 1;' . "\n"; } if ($start !== 'null') { $output .= '$_section' . $cnt . '[\'start\'] = (int)' . $start . ";\n"; } else { $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 .= 'if ($_section' . $cnt . '[\'show\']) {' . "\n"; if ($start === 'null' && $step === 'null' && $max === 'null') { $output .= ' $_section' . $cnt . '[\'total\'] = $_section' . $cnt . '[\'loop\'];' . "\n"; } else { $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" . ' }' . "\n" . '} else {' . "\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"; $output .= Compiler::PHP_CLOSE . $content . Compiler::PHP_OPEN; $output .= "\n\t}\n} " . Compiler::PHP_CLOSE; if (isset($params['hasElse'])) { $output .= $params['hasElse']; } return $output; }