4 * Smarty Internal Plugin Compile Modifier
5 * Compiles code for modifier execution
13 * Smarty Internal Plugin Compile Modifier Class
16 * @subpackage Compiler
18 class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase
21 * Compiles code for modifier execution
23 * @param array $args array with attributes from parser
24 * @param object $compiler compiler object
25 * @param array $parameter array with compilation parameter
27 * @return string compiled code
29 public function compile($args, $compiler, $parameter)
31 // check and get attributes
32 $_attr = $this->getAttributes($compiler, $args);
33 $output = $parameter['value'];
34 // loop over list of modifiers
35 foreach ($parameter['modifierlist'] as $single_modifier) {
36 $modifier = $single_modifier[0];
37 $single_modifier[0] = $output;
38 $params = implode(',', $single_modifier);
39 // check if we know already the type of modifier
40 if (isset($compiler->known_modifier_type[$modifier])) {
41 $modifier_types = array($compiler->known_modifier_type[$modifier]);
43 $modifier_types = array(1, 2, 3, 4, 5, 6);
45 foreach ($modifier_types as $type) {
48 // registered modifier
49 if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier])) {
50 $function = $compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
51 if (!is_array($function)) {
52 $output = "{$function}({$params})";
54 if (is_object($function[0])) {
55 $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
57 $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
60 $compiler->known_modifier_type[$modifier] = $type;
65 // registered modifier compiler
66 if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0])) {
67 $output = call_user_func($compiler->smarty->registered_plugins[Smarty::PLUGIN_MODIFIERCOMPILER][$modifier][0], $single_modifier, $compiler->smarty);
68 $compiler->known_modifier_type[$modifier] = $type;
73 // modifiercompiler plugin
74 if ($compiler->smarty->loadPlugin('smarty_modifiercompiler_' . $modifier)) {
75 // check if modifier allowed
76 if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
77 $plugin = 'smarty_modifiercompiler_' . $modifier;
78 $output = $plugin($single_modifier, $compiler);
80 $compiler->known_modifier_type[$modifier] = $type;
86 if ($function = $compiler->getPlugin($modifier, Smarty::PLUGIN_MODIFIER)) {
87 // check if modifier allowed
88 if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
89 $output = "{$function}({$params})";
91 $compiler->known_modifier_type[$modifier] = $type;
97 if (is_callable($modifier)) {
98 // check if modifier allowed
99 if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) {
100 $output = "{$modifier}({$params})";
102 $compiler->known_modifier_type[$modifier] = $type;
107 // default plugin handler
108 if (isset($compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier]) || (is_callable($compiler->smarty->default_plugin_handler_func) && $compiler->getPluginFromDefaultHandler($modifier, Smarty::PLUGIN_MODIFIER))) {
109 $function = $compiler->default_handler_plugins[Smarty::PLUGIN_MODIFIER][$modifier][0];
110 // check if modifier allowed
111 if (!is_object($compiler->smarty->security_policy) || $compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
112 if (!is_array($function)) {
113 $output = "{$function}({$params})";
115 if (is_object($function[0])) {
116 $output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' . $modifier . '\'][0][0]->' . $function[1] . '(' . $params . ')';
118 $output = $function[0] . '::' . $function[1] . '(' . $params . ')';
122 if (isset($compiler->template->required_plugins['nocache'][$modifier][Smarty::PLUGIN_MODIFIER]['file']) || isset($compiler->template->required_plugins['compiled'][$modifier][Smarty::PLUGIN_MODIFIER]['file'])) {
124 $compiler->known_modifier_type[$modifier] = 4;
126 $compiler->known_modifier_type[$modifier] = $type;
132 if (!isset($compiler->known_modifier_type[$modifier])) {
133 $compiler->trigger_template_error("unknown modifier \"" . $modifier . "\"", $compiler->lex->taglineno);