Update Smarty Switch plugin for >3.1 support

This commit is contained in:
2012-05-19 02:23:42 +01:00
parent 488a225183
commit 746f8f6a39

View File

@@ -32,6 +32,8 @@
* Fixed a bug when chaining multiple {case} statements without a {break}. * Fixed a bug when chaining multiple {case} statements without a {break}.
* Version 3.5: * Version 3.5:
* Updated to work with Smarty 3.0 release. (Tested and working with 3.0.5, no longer compatible with 3.0rcx releases.) * Updated to work with Smarty 3.0 release. (Tested and working with 3.0.5, no longer compatible with 3.0rcx releases.)
* Version 3.6:
* Updated to work with Smarty 3.1 release. (Tested and working on 3.1.3, No longer compatible with 3.0 releases.)
* *
* - Bugs/Notes: * - Bugs/Notes:
* *
@@ -112,10 +114,10 @@ class Smarty_Compiler_Switch extends Smarty_Internal_CompileBase {
*/ */
public function compile($args, $compiler){ public function compile($args, $compiler){
$this->compiler = $compiler; $this->compiler = $compiler;
$attr = $this->_get_attributes($args); $attr = $this->getAttributes($compiler, $args);
$_output = ''; $_output = '';
$this->_open_tag('switch',array($compiler->tag_nocache)); $this->openTag($compiler, 'switch',array($compiler->tag_nocache));
if (is_array($attr['var'])) { if (is_array($attr['var'])) {
$_output .= "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$attr['var']['var']."])) \$_smarty_tpl->tpl_vars[".$attr['var']['var']."] = new Smarty_Variable;"; $_output .= "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$attr['var']['var']."])) \$_smarty_tpl->tpl_vars[".$attr['var']['var']."] = new Smarty_Variable;";
@@ -144,18 +146,18 @@ class Smarty_Compiler_Case extends Smarty_Internal_CompileBase {
*/ */
public function compile($args, $compiler){ public function compile($args, $compiler){
$this->compiler = $compiler; $this->compiler = $compiler;
$attr = $this->_get_attributes($args); $attr = $this->getAttributes($compiler, $args);
$_output = ''; $_output = '';
list($last_tag, $last_attr) = $this->compiler->_tag_stack[count($this->compiler->_tag_stack) - 1]; list($last_tag, $last_attr) = $this->compiler->_tag_stack[count($this->compiler->_tag_stack) - 1];
if($last_tag == 'case') if($last_tag == 'case')
{ {
list($break, $compiler->tag_nocache) = $this->_close_tag(array('case')); list($break, $compiler->tag_nocache) = $this->closeTag($compiler, array('case'));
if($last_attr[0]) if($last_attr[0])
$_output .= '<?php break;?>'; $_output .= '<?php break;?>';
} }
$this->_open_tag('case', array(isset($attr['break']) ? $attr['break'] : false, $compiler->tag_nocache)); $this->openTag($compiler, 'case', array(isset($attr['break']) ? $attr['break'] : false, $compiler->tag_nocache));
if (is_array($attr['value'])) { if (is_array($attr['value'])) {
$_output .= "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$attr['value']['var']."])) \$_smarty_tpl->tpl_vars[".$attr['value']['var']."] = new Smarty_Variable;"; $_output .= "<?php if (!isset(\$_smarty_tpl->tpl_vars[".$attr['value']['var']."])) \$_smarty_tpl->tpl_vars[".$attr['value']['var']."] = new Smarty_Variable;";
@@ -183,17 +185,17 @@ class Smarty_Compiler_Default extends Smarty_Internal_CompileBase {
*/ */
public function compile($args, $compiler){ public function compile($args, $compiler){
$this->compiler = $compiler; $this->compiler = $compiler;
$attr = $this->_get_attributes($args); $attr = $this->getAttributes($compiler, $args);
$_output = ''; $_output = '';
list($last_tag, $last_attr) = $this->compiler->_tag_stack[count($this->compiler->_tag_stack) - 1]; list($last_tag, $last_attr) = $this->compiler->_tag_stack[count($this->compiler->_tag_stack) - 1];
if($last_tag == 'case') if($last_tag == 'case')
{ {
list($break, $compiler->tag_nocache) = $this->_close_tag(array('case')); list($break, $compiler->tag_nocache) = $this->closeTag($compiler, array('case'));
if($last_attr[0]) if($last_attr[0])
$_output .= '<?php break;?>'; $_output .= '<?php break;?>';
} }
$this->_open_tag('case', array(isset($attr['break']) ? $attr['break'] : false, $compiler->tag_nocache)); $this->openTag($compiler, 'case', array(isset($attr['break']) ? $attr['break'] : false, $compiler->tag_nocache));
$_output .= '<?php default:?>'; $_output .= '<?php default:?>';
@@ -218,9 +220,9 @@ class Smarty_Compiler_Break extends Smarty_Internal_CompileBase {
public function compile($args, $compiler){ public function compile($args, $compiler){
$this->compiler = $compiler; $this->compiler = $compiler;
$attr = $this->_get_attributes($args); $attr = $this->getAttributes($compiler, $args);
list($break, $compiler->tag_nocache) = $this->_close_tag(array('case')); list($break, $compiler->tag_nocache) = $this->closeTag($compiler, array('case'));
return '<?php break;?>'; return '<?php break;?>';
} }
@@ -242,9 +244,9 @@ class Smarty_Compiler_Caseclose extends Smarty_Internal_CompileBase {
public function compile($args, $compiler){ public function compile($args, $compiler){
$this->compiler = $compiler; $this->compiler = $compiler;
$attr = $this->_get_attributes($args); $attr = $this->getAttributes($compiler, $args);
list($break, $compiler->tag_nocache) = $this->_close_tag(array('case')); list($break, $compiler->tag_nocache) = $this->closeTag($compiler, array('case'));
return '<?php break;?>'; return '<?php break;?>';
} }
@@ -265,12 +267,12 @@ class Smarty_Compiler_Switchclose extends Smarty_Internal_CompileBase {
public function compile($args, $compiler){ public function compile($args, $compiler){
$this->compiler = $compiler; $this->compiler = $compiler;
$attr = $this->_get_attributes($args); $attr = $this->getAttributes($compiler, $args);
list($last_tag, $last_attr) = $this->compiler->_tag_stack[count($this->compiler->_tag_stack) - 1]; list($last_tag, $last_attr) = $this->compiler->_tag_stack[count($this->compiler->_tag_stack) - 1];
if(($last_tag == 'case' || $last_tag == 'default')) if(($last_tag == 'case' || $last_tag == 'default'))
list($break, $compiler->tag_nocache) = $this->_close_tag(array('case')); list($break, $compiler->tag_nocache) = $this->closeTag($compiler, array('case'));
list($compiler->tag_nocache) = $this->_close_tag(array('switch')); list($compiler->tag_nocache) = $this->closeTag($compiler, array('switch'));
return '<?php }?>'; return '<?php }?>';
} }
@@ -289,4 +291,4 @@ function smarty_postfilter_switch($compiled, &$smarty) {
// Remove the extra spaces after the start of the switch tag and before the first case statement. // Remove the extra spaces after the start of the switch tag and before the first case statement.
return preg_replace('/({ ?\?>)\s+(<\?php case)/', "$1\n$2", $compiled); return preg_replace('/({ ?\?>)\s+(<\?php case)/', "$1\n$2", $compiled);
} }
?> ?>