Skip to content

Commit

Permalink
- bugfix modifier on plugins like {plugin|modifier ... } did fail whe…
Browse files Browse the repository at this point in the history
…n the plugin does return an array #228
  • Loading branch information
uwetews committed Jul 18, 2016
1 parent 79a4fdc commit 92945ea
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 171 deletions.
1 change: 1 addition & 0 deletions change_log.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)
18.07.2016
- bugfix {foreach} if key variable and item@key attribute have been used both the key variable was not updated https://github.com/smarty-php/smarty/issues/254
- bugfix modifier on plugins like {plugin|modifier ... } did fail when the plugin does return an array https://github.com/smarty-php/smarty/issues/228

14.07.2016
- bugfix wrong parameter on compileAllTemplates() and compileAllConfig() https://github.com/smarty-php/smarty/issues/231
Expand Down
6 changes: 2 additions & 4 deletions lexer/smarty_internal_templateparser.y
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ tag(res) ::= LDEL ID(i) modifierlist(l)attributes(a). {
}
res = $this->compiler->compileTag('private_print_expression',a,array('value'=>i, 'modifierlist'=>l));
} else {
res = '<?php ob_start();?>'.$this->compiler->compileTag(i,a).'<?php echo ';
res .= $this->compiler->compileTag('private_modifier',array(),array('modifierlist'=>l,'value'=>'ob_get_clean()')).';?>';
res = $this->compiler->compileTag(i,a, array('modifierlist'=>l));
}
}

Expand All @@ -449,8 +448,7 @@ tag(res) ::= LDEL ID(i) PTR ID(m) attributes(a). {

// registered object tag with modifiers
tag(res) ::= LDEL ID(i) PTR ID(me) modifierlist(l) attributes(a). {
res = '<?php ob_start();?>'.$this->compiler->compileTag(i,a,array('object_method'=>me)).'<?php echo ';
res .= $this->compiler->compileTag('private_modifier',array(),array('modifierlist'=>l,'value'=>'ob_get_clean()')).';?>';
res = $this->compiler->compileTag(i,a,array('modifierlist'=>l, 'object_method'=>me));
}

// nocache tag
Expand Down
2 changes: 1 addition & 1 deletion libs/Smarty.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.30-dev/81';
const SMARTY_VERSION = '3.1.30-dev/82';

/**
* define variable scopes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;

unset($_attr[ 'nocache' ]);
// convert attributes into parameter array string
Expand All @@ -62,8 +60,15 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
}
$_params = 'array(' . implode(",", $_paramsArray) . ')';
// compile code
$output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";

$output = "{$function}({$_params},\$_smarty_tpl)";
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
$output = "<?php " . ($compiler->has_output ? "echo " : '') . "{$output};?>\n";
return $output;
}
}
4 changes: 1 addition & 3 deletions libs/sysplugins/smarty_internal_compile_private_modifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
$output = "{$function}({$params})";
} else {
if (is_object($function[ 0 ])) {
$output =
'$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
$modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')';
$output = $function[ 0 ] . '->'. $function[ 1 ] . '(' . $params . ')';
} else {
$output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,26 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
}
}
$_params = 'array(' . implode(",", $_paramsArray) . ')';
$return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
} else {
$_params = implode(",", $_attr);
$return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
}
} else {
// object property
$return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
$output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
}
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output));
}
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;

if (empty($_assign)) {
$output = "<?php echo {$return};?>\n";
return "<?php echo {$output};?>\n";
} else {
$output = "<?php \$_smarty_tpl->assign({$_assign},{$return});?>\n";
return "<?php \$_smarty_tpl->assign({$_assign},{$output});?>\n";
}

return $output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
$output = $parameter[ 'value' ];
// tag modifier
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
if (isset($_attr[ 'assign' ])) {
// assign output to variable
$output = "<?php \$_smarty_tpl->assign({$_attr['assign']},{$parameter['value']});?>";
return "<?php \$_smarty_tpl->assign({$_attr['assign']},{$output});?>";
} else {
// display value
$output = $parameter[ 'value' ];
// tag modifier
if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
if (!$_attr[ 'nofilter' ]) {
// default modifier
if (!empty($compiler->smarty->default_modifiers)) {
Expand Down Expand Up @@ -138,8 +138,9 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
{
$plugin_name = "smarty_variablefilter_{$name}";
$path = $compiler->smarty->loadPlugin($plugin_name, false);
$path = $compiler->smarty->loadPlugin($plugin_name);
if ($path) {
/**
if ($compiler->template->caching) {
$compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'file' ] =
$path;
Expand All @@ -151,11 +152,11 @@ private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $com
$compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'function' ] =
$plugin_name;
}
* */
return "{$plugin_name}({$output},\$_smarty_tpl)";
} else {
// not found
return false;
}

return "{$plugin_name}({$output},\$_smarty_tpl)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
{
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;

unset($_attr[ 'nocache' ]);
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ])) {
$tag_info = $compiler->smarty->registered_plugins[ Smarty::PLUGIN_FUNCTION ][ $tag ];
Expand All @@ -65,14 +62,21 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $
$function = $tag_info[ 0 ];
// compile code
if (!is_array($function)) {
$output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";
$output = "{$function}({$_params},\$_smarty_tpl)";
} elseif (is_object($function[ 0 ])) {
$output =
"<?php echo \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl);?>\n";
"\$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl)";
} else {
$output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl);?>\n";
$output = "{$function[0]}::{$function[1]}({$_params},\$_smarty_tpl)";
}

if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ],
'value' => $output));
}
//Does tag create output
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
$output = "<?php " . ($compiler->has_output ? "echo " : '') . "{$output};?>\n";
return $output;
}
}
Loading

0 comments on commit 92945ea

Please sign in to comment.