Esempio n. 1
0
 /**
  * @param  \Box\Brainy\Compiler\TemplateCompiler $compiler A compiler reference
  * @param  array|null                            $args     Arguments
  * @return mixed
  */
 public static function compileOpen(\Box\Brainy\Compiler\TemplateCompiler $compiler, $args)
 {
     $output = self::getRequiredArg($args, 'value');
     $modifierlist = self::getRequiredArg($args, 'modifierlist');
     foreach ($modifierlist as $rawModifier) {
         $modifier = $rawModifier[0];
         $rawModifier[0] = $output;
         $modifierIsStatic = $output instanceof StaticWrapper;
         for ($i = 0; $i < count($rawModifier); $i++) {
             if ($rawModifier[$i] instanceof StaticWrapper) {
                 $rawModifier[$i] = (string) $rawModifier[$i];
             } elseif ($i > 0) {
                 $modifierIsStatic = false;
             }
         }
         $params = implode(', ', $rawModifier);
         if (isset($compiler->smarty->registered_plugins[Brainy::PLUGIN_MODIFIER][$modifier])) {
             $function = $compiler->smarty->registered_plugins[Brainy::PLUGIN_MODIFIER][$modifier];
             $output = "{$function}({$params})";
         } elseif (isset($compiler->smarty->registered_plugins[Brainy::PLUGIN_MODIFIERCOMPILER][$modifier])) {
             // This gets a copy of `$output` because $rawModifier[0] is set to $output above.
             $output = call_user_func($compiler->smarty->registered_plugins[Brainy::PLUGIN_MODIFIERCOMPILER][$modifier], $rawModifier, $compiler->smarty);
         } elseif (PluginLoader::loadPlugin(Brainy::PLUGIN_MODIFIERCOMPILER, $modifier, $compiler->smarty)) {
             if (is_object($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
                 $compiler->trigger_template_error('Could not use modifier "' . $modifier . '" in template due to security policy');
                 return null;
             }
             $func = PluginLoader::getPluginFunction(Brainy::PLUGIN_MODIFIERCOMPILER, $modifier);
             $output = call_user_func($func, $rawModifier, $compiler);
         } elseif (PluginLoader::loadPlugin(Brainy::PLUGIN_MODIFIER, $modifier, $compiler->smarty)) {
             if (is_object($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->isTrustedModifier($modifier, $compiler)) {
                 $compiler->trigger_template_error('Could not use modifier "' . $modifier . '" in template due to security policy');
                 return null;
             }
             $output = '(\\Box\\Brainy\\Runtime\\PluginLoader::loadPlugin(\\Box\\Brainy\\Brainy::PLUGIN_MODIFIER, ' . var_export($modifier, true) . ', $_smarty_tpl->smarty) ?';
             $func = PluginLoader::getPluginFunction(Brainy::PLUGIN_MODIFIER, $modifier);
             $output .= "{$func}({$params})";
             $output .= ' : null)';
         } elseif (is_callable($modifier)) {
             if (is_object($compiler->smarty->security_policy) && !$compiler->smarty->security_policy->isTrustedPhpModifier($modifier, $compiler)) {
                 $compiler->trigger_template_error('Could not use modifier "' . $modifier . '" in template due to security policy');
                 return null;
             }
             $output = "{$modifier}({$params})";
         } else {
             $compiler->trigger_template_error('Unknown modifier: "' . $modifier . '"');
             break;
         }
         if ($modifierIsStatic || in_array($modifier, Brainy::$enforce_expression_modifiers ?: array())) {
             $output = new StaticWrapper($output);
         }
     }
     return $output;
 }
Esempio n. 2
0
function smarty_function_chain2($params, $tpl)
{
    \Box\Brainy\Runtime\PluginLoader::loadPlugin(\Box\Brainy\Brainy::PLUGIN_FUNCTION, 'chain3', $tpl->smarty);
    return smarty_function_chain3($params, $tpl);
}
Esempio n. 3
0
 /**
  * @param  string $tag       tag name
  * @param  array  $args      array with tag attributes
  * @param  array  $parameter array with compilation parameter
  * @return string compiled   code
  */
 public function compileTag($tag, $args, $parameter = array())
 {
     // $args contains the attributes parsed and compiled by the lexer/parser
     // assume that tag does compile into code, but creates no HTML output
     $this->has_code = true;
     if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) {
         $this->trigger_template_error("Use of disallowed tag: \"{$tag}\"", $this->lex->taglineno);
         return;
         // unreachable
     }
     // map_named attributes
     if (isset($args['_attr'])) {
         foreach ($args['_attr'] as $key => $attribute) {
             if (!is_array($attribute)) {
                 continue;
             }
             $args = array_merge($args, $attribute);
         }
     }
     if (isset($this->smarty->registered_plugins[Brainy::PLUGIN_FUNCTION][$tag])) {
         $function = $this->smarty->registered_plugins[Brainy::PLUGIN_FUNCTION][$tag];
         return 'echo ' . $function . '(' . $this->formatStaticArgs($args, false) . ', $_smarty_tpl)' . ";\n";
     }
     if (\Box\Brainy\Runtime\PluginLoader::loadPlugin(Brainy::PLUGIN_FUNCTION, $tag, $this->smarty)) {
         return '\\Box\\Brainy\\Runtime\\PluginLoader::loadPlugin(\\Box\\Brainy\\Brainy::PLUGIN_FUNCTION, ' . var_export($tag, true) . ", \$_smarty_tpl->smarty);\n" . 'echo ' . \Box\Brainy\Runtime\PluginLoader::getPluginFunction(Brainy::PLUGIN_FUNCTION, $tag) . '(' . $this->formatStaticArgs($args, false) . ', $_smarty_tpl)' . ";\n";
     }
     if (isset($this->smarty->registered_plugins[Brainy::PLUGIN_COMPILER][$tag])) {
         $function = $this->smarty->registered_plugins[Brainy::PLUGIN_COMPILER][$tag];
         return call_user_func($function, $this->formatPluginArgs($args), $this);
     }
     if (\Box\Brainy\Runtime\PluginLoader::loadPlugin(Brainy::PLUGIN_COMPILER, $tag, $this->smarty)) {
         $plugin = \Box\Brainy\Runtime\PluginLoader::getPluginFunction(Brainy::PLUGIN_COMPILER, $tag);
         if (!is_callable($plugin)) {
             throw new \Box\Brainy\Exceptions\SmartyException("Plugin \"{$tag}\" not callable");
         }
         return call_user_func($plugin, $this->formatPluginArgs($args), $this);
     }
     // Try treating it as a call
     array_unshift($args, array('name' => var_export($tag, true)));
     return Constructs\ConstructCall::compileOpen($this, $args);
 }