Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- merging 3.1 patches into 3.2

git-svn-id: http://smarty-php.googlecode.com/svn/branches/Smarty_3_2_DEV@4575 9dce5a81-9a42-0410-99e4-3799d3902e7f
  • Loading branch information...
commit 1462d4439b519930c7ec2ec502005dfb09c22408 1 parent b513680
uwe.tews@googlemail.com authored
View
25 development/PHPunit/DefaultPluginHandlerTests.php
@@ -54,6 +54,16 @@ public function testDefaultBlockScript()
{
$this->assertEquals("scriptblock foo bar", $this->smarty->fetch('test_default_block_script.tpl'));
}
+ public function testDefaultModifierScript()
+ {
+ $this->smarty->assign('foo','bar');
+ $this->assertEquals("scriptmodifier default bar", $this->smarty->fetch('test_default_modifier_script.tpl'));
+ }
+ public function testDefaultModifier()
+ {
+ $this->smarty->assign('foo','bar');
+ $this->assertEquals("localmodifier bar", $this->smarty->fetch('test_default_modifier.tpl'));
+ }
}
@@ -95,6 +105,18 @@ function my_plugin_handler ($tag, $type, $template, &$callback, &$script, &$cach
default:
return false;
}
+ case Smarty::PLUGIN_MODIFIER:
+ switch ($tag) {
+ case 'scriptmodifier':
+ $script = './scripts/script_modifier.php';
+ $callback = 'default_script_modifier';
+ return true;
+ case 'mydefaultmodifier':
+ $callback = 'default_local_modifier';
+ return true;
+ default:
+ return false;
+ }
default:
return false;
}
@@ -102,4 +124,7 @@ function my_plugin_handler ($tag, $type, $template, &$callback, &$script, &$cach
function default_local_function_tag ($params, $template) {
return 'localfunction '.$params['value'];
}
+function default_local_modifier ($input) {
+ return 'localmodifier '.$input;
+}
?>
View
5 development/PHPunit/scripts/script_modifier.php
@@ -0,0 +1,5 @@
+<?php
+function default_script_modifier ($input, $text = null) {
+ return $text.$input;
+}
+?>
View
1  development/PHPunit/templates/test_default_modifier.tpl
@@ -0,0 +1 @@
+{$foo|mydefaultmodifier}
View
1  development/PHPunit/templates/test_default_modifier_script.tpl
@@ -0,0 +1 @@
+{$foo|scriptmodifier:'scriptmodifier default '}
View
7 distribution/change_log.txt
@@ -117,6 +117,13 @@
===== trunk =====
+03.03.2012
+- optimization of compiling speed when same modifier was used several times
+
+02.03.2012
+- enhancement the default plugin handler can now also resolve undefined modifier (Smarty::PLUGIN_MODIFIER)
+ (Issue 85)
+
===== Smarty-3.1.8 =====
19.02.2012
- bugfix {include} could result in a fatal error if used in appended or prepended nested {block} tags
View
2  distribution/libs/sysplugins/smarty_internal_compile_block.php
@@ -261,7 +261,7 @@ public function compile($args, $compiler) {
// reset flags
$compiler->parser->current_buffer = $saved_data[1];
$compiler->nocache = $saved_data[2];
- //$compiler->smarty->merge_compiled_includes = $saved_data[3];
+ $compiler->smarty->merge_compiled_includes = $saved_data[3];
// reset flag for {block} tag
$compiler->inheritance = false;
// update nocache line number trace back
View
145 distribution/libs/sysplugins/smarty_internal_compile_private_modifier.php
@@ -35,54 +35,107 @@ public function compile($args, $compiler, $parameter) {
$modifier = $single_modifier[0];
$single_modifier[0] = $output;
$params = implode(',', $single_modifier);
- // check for registered modifier
- if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) {
- $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
- $object = $this->testParameter($modifier, $function, $single_modifier, $compiler);
- if (!is_array($function)) {
- $output = "{$function}({$object}{$params})";
- } else {
- if (is_object($function[0])) {
- $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $object . $params . ')';
- } else {
- $output = $function[0] . '::' . $function[1] . '(' . $object . $params . ')';
- }
- }
- } else if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) {
- $output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty);
- // check for plugin modifiercompiler
- } else if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
- // check if modifier allowed
- if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
- $plugin = 'smarty_modifiercompiler_' . $modifier;
- if ($this->getNoOfRequiredParameter($plugin) == 0) {
- // NOTE: This covers the modifier like 'default' and 'cat' which can take any number of parameter
- $output = call_user_func_array($plugin, $single_modifier);
- } else {
- $object = $this->testParameter($modifier, $plugin, $single_modifier, $compiler);
- if ($object == '') {
- $output = call_user_func_array($plugin, $single_modifier);
- } else {
- array_unshift($single_modifier, $object);
- $output = call_user_func_array($plugin, $single_modifier);
+ // check if we know already the type of modifier
+ if (isset($compiler->known_modifier_type[$modifier])) {
+ $modifier_types = array($compiler->known_modifier_type[$modifier]);
+ } else {
+ $modifier_types = array(1, 2, 3, 4, 5, 6);
+ }
+ foreach ($modifier_types as $type) {
+ switch ($type) {
+ case 1:
+ // registered modifier
+ if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) {
+ $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
+ $object = $this->testParameter($modifier, $function, $single_modifier, $compiler);
+ if (!is_array($function)) {
+ $output = "{$function}({$object}{$params})";
+ } else {
+ if (is_object($function[0])) {
+ $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $object . $params . ')';
+ } else {
+ $output = $function[0] . '::' . $function[1] . '(' . $object . $params . ')';
+ }
+ }
+ $compiler->known_modifier_type[$modifier] = $type;
+ break 2;
+ }
+ break;
+ case 2:
+ // registered modifier compiler
+ if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) {
+ $output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty);
+ $compiler->known_modifier_type[$modifier] = $type;
+ break 2;
+ }
+ break;
+ case 3:
+ // modifiercompiler plugin
+ if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
+ // check if modifier allowed
+ if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
+ $plugin = 'smarty_modifiercompiler_' . $modifier;
+ if ($this->getNoOfRequiredParameter($plugin) == 0) {
+ // NOTE: This covers the modifier like 'default' and 'cat' which can take any number of parameter
+ $output = call_user_func_array($plugin, $single_modifier);
+ } else {
+ $object = $this->testParameter($modifier, $plugin, $single_modifier, $compiler);
+ if ($object == '') {
+ $output = call_user_func_array($plugin, $single_modifier);
+ } else {
+ array_unshift($single_modifier, $object);
+ $output = call_user_func_array($plugin, $single_modifier);
+ }
+ }
+ }
+ $compiler->known_modifier_type[$modifier] = $type;
+ break 2;
+ }
+ break;
+ case 4:
+ // modifier plugin
+ if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
+ $object = $this->testParameter($modifier, $function, $single_modifier, $compiler);
+ // check if modifier allowed
+ if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
+ $output = "{$function}({$object}{$params})";
+ }
+ $compiler->known_modifier_type[$modifier] = $type;
+ break 2;
+ }
+ break;
+ case 5:
+ // PHP function
+ if (is_callable($modifier)) {
+ $object = $this->testParameter($modifier, $modifier, $single_modifier, $compiler);
+ // check if modifier allowed
+ if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) {
+ $output = "{$modifier}({$object}{$params})";
+ }
+ $compiler->known_modifier_type[$modifier] = $type;
+ break 2;
+ }
+ break;
+ case 6:
+ // default plugin handler
+ if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) {
+ $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
+ $object = $this->testParameter($modifier, $function, $single_modifier, $compiler);
+ // check if modifier allowed
+ if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
+ $output = "{$function}({$object}{$params})";
+ }
+ if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) {
+ // was a plugin
+ $compiler->known_modifier_type[$modifier] = 4;
+ } else {
+ $compiler->known_modifier_type[$modifier] = $type;
+ }
+ break 2;
}
- }
- }
- // check for plugin modifier
- } else if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
- $object = $this->testParameter($modifier, $function, $single_modifier, $compiler);
- // check if modifier allowed
- if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
- $output = "{$function}({$object}{$params})";
- }
- // check if trusted PHP function
- } else if (is_callable($modifier)) {
- // check if modifier allowed
- if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) {
- $object = $this->testParameter($modifier, $modifier, $single_modifier, $compiler);
- $output = "{$modifier}({$object}{$params})";
}
- } else {
+ }
+ if (!isset($compiler->known_modifier_type[$modifier])) {
$compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno);
}
}
View
6 distribution/libs/sysplugins/smarty_internal_templatecompilerbase.php
@@ -156,6 +156,12 @@
public $modifier_plugins = array();
/**
+ * type of already compiled modifier
+ * @var array
+ */
+ public $known_modifier_type = array();
+
+ /**
* Initialize compiler
*/
public function __construct() {
Please sign in to comment.
Something went wrong with that request. Please try again.