2009-11-06 14:35:00 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2011-09-16 14:19:56 +00:00
|
|
|
* Smarty Internal Plugin Compile While
|
|
|
|
* Compiles the {while} tag
|
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2011-09-16 14:19:56 +00:00
|
|
|
* @subpackage Compiler
|
2014-06-06 02:40:04 +00:00
|
|
|
* @author Uwe Tews
|
2011-09-16 14:19:56 +00:00
|
|
|
*/
|
2010-08-17 15:39:51 +00:00
|
|
|
|
2009-11-06 14:35:00 +00:00
|
|
|
/**
|
2011-09-16 14:19:56 +00:00
|
|
|
* Smarty Internal Plugin Compile While Class
|
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2011-09-16 14:19:56 +00:00
|
|
|
* @subpackage Compiler
|
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2009-11-06 14:35:00 +00:00
|
|
|
/**
|
2011-09-16 14:19:56 +00:00
|
|
|
* Compiles code for the {while} tag
|
|
|
|
*
|
2015-08-06 01:19:11 +02:00
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
|
|
|
* @param array $parameter array with compilation parameter
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2011-09-16 14:19:56 +00:00
|
|
|
* @return string compiled code
|
2015-08-06 01:19:11 +02:00
|
|
|
* @throws \SmartyCompilerException
|
2011-09-16 14:19:56 +00:00
|
|
|
*/
|
2015-08-06 01:19:11 +02:00
|
|
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
|
2009-11-06 14:35:00 +00:00
|
|
|
{
|
2015-08-10 21:57:06 +02:00
|
|
|
$compiler->loopNesting++;
|
2009-11-06 14:35:00 +00:00
|
|
|
// check and get attributes
|
2011-09-16 14:19:56 +00:00
|
|
|
$_attr = $this->getAttributes($compiler, $args);
|
|
|
|
$this->openTag($compiler, 'while', $compiler->nocache);
|
2009-11-06 14:35:00 +00:00
|
|
|
|
2014-06-06 02:40:04 +00:00
|
|
|
if (!array_key_exists("if condition", $parameter)) {
|
2015-08-06 01:19:11 +02:00
|
|
|
$compiler->trigger_template_error("missing while condition", null, true);
|
2011-11-01 20:27:53 +00:00
|
|
|
}
|
|
|
|
|
2009-11-06 14:35:00 +00:00
|
|
|
// maybe nocache because of nocache variables
|
2011-09-16 14:19:56 +00:00
|
|
|
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
2015-08-10 21:57:06 +02:00
|
|
|
$_output = "<?php\n";
|
2010-11-11 21:34:36 +00:00
|
|
|
if (is_array($parameter['if condition'])) {
|
2011-09-16 14:19:56 +00:00
|
|
|
if ($compiler->nocache) {
|
|
|
|
$_nocache = ',true';
|
|
|
|
// create nocache var to make it know for further compiling
|
|
|
|
if (is_array($parameter['if condition']['var'])) {
|
2015-05-19 22:47:04 +02:00
|
|
|
$var = trim($parameter['if condition']['var']['var'], "'");
|
2011-09-16 14:19:56 +00:00
|
|
|
} else {
|
2015-05-19 22:47:04 +02:00
|
|
|
$var = trim($parameter['if condition']['var'], "'");
|
|
|
|
}
|
|
|
|
if (isset($compiler->template->tpl_vars[$var])) {
|
|
|
|
$compiler->template->tpl_vars[$var]->nocache = true;
|
|
|
|
} else {
|
|
|
|
$compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true);
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$_nocache = '';
|
|
|
|
}
|
2010-11-24 19:38:45 +00:00
|
|
|
if (is_array($parameter['if condition']['var'])) {
|
2015-08-10 21:57:06 +02:00
|
|
|
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
2015-08-06 01:19:11 +02:00
|
|
|
"]) || !is_array(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] .
|
2015-12-31 02:20:47 +01:00
|
|
|
"]->value)) \$_smarty_tpl->_createLocalArrayVariable(" . $parameter['if condition']['var']['var'] .
|
2015-08-06 01:19:11 +02:00
|
|
|
"$_nocache);\n";
|
|
|
|
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var']['var'] . "]->value" .
|
|
|
|
$parameter['if condition']['var']['smarty_internal_index'] . " = " .
|
|
|
|
$parameter['if condition']['value'] . ") {?>";
|
2010-11-24 19:38:45 +00:00
|
|
|
} else {
|
2015-08-10 21:57:06 +02:00
|
|
|
$_output .= "if (!isset(\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
|
2015-08-06 01:19:11 +02:00
|
|
|
"])) \$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] .
|
|
|
|
"] = new Smarty_Variable(null{$_nocache});";
|
|
|
|
$_output .= "while (\$_smarty_tpl->tpl_vars[" . $parameter['if condition']['var'] . "]->value = " .
|
|
|
|
$parameter['if condition']['value'] . ") {?>";
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
2009-11-06 14:35:00 +00:00
|
|
|
} else {
|
2015-08-10 21:57:06 +02:00
|
|
|
$_output .= "while ({$parameter['if condition']}) {?>";
|
|
|
|
}
|
|
|
|
return $_output;
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-06 14:35:00 +00:00
|
|
|
|
|
|
|
/**
|
2011-09-16 14:19:56 +00:00
|
|
|
* Smarty Internal Plugin Compile Whileclose Class
|
|
|
|
*
|
2014-06-06 02:40:04 +00:00
|
|
|
* @package Smarty
|
2011-09-16 14:19:56 +00:00
|
|
|
* @subpackage Compiler
|
|
|
|
*/
|
2013-07-14 22:15:45 +00:00
|
|
|
class Smarty_Internal_Compile_Whileclose extends Smarty_Internal_CompileBase
|
|
|
|
{
|
2009-11-06 14:35:00 +00:00
|
|
|
/**
|
2011-09-16 14:19:56 +00:00
|
|
|
* Compiles code for the {/while} tag
|
|
|
|
*
|
2015-08-06 01:19:11 +02:00
|
|
|
* @param array $args array with attributes from parser
|
|
|
|
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
|
2014-06-06 02:40:04 +00:00
|
|
|
*
|
2011-09-16 14:19:56 +00:00
|
|
|
* @return string compiled code
|
|
|
|
*/
|
2015-08-06 01:19:11 +02:00
|
|
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
|
2009-11-06 14:35:00 +00:00
|
|
|
{
|
2015-08-10 21:57:06 +02:00
|
|
|
$compiler->loopNesting--;
|
2010-08-17 15:39:51 +00:00
|
|
|
// must endblock be nocache?
|
2011-09-16 14:19:56 +00:00
|
|
|
if ($compiler->nocache) {
|
|
|
|
$compiler->tag_nocache = true;
|
2009-11-06 14:35:00 +00:00
|
|
|
}
|
2011-09-16 14:19:56 +00:00
|
|
|
$compiler->nocache = $this->closeTag($compiler, array('while'));
|
2015-08-10 21:57:06 +02:00
|
|
|
return "<?php }?>\n";
|
2011-09-16 14:19:56 +00:00
|
|
|
}
|
|
|
|
}
|