3 * Smarty Internal Plugin Compile Print Expression
4 * Compiles any tag which will output an expression or variable
12 * Smarty Internal Plugin Compile Print Expression Class
15 * @subpackage Compiler
17 class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_CompileBase
20 * Attribute definition: Overwrites base class.
23 * @see Smarty_Internal_CompileBase
25 public $optional_attributes = array('assign');
28 * Attribute definition: Overwrites base class.
31 * @see Smarty_Internal_CompileBase
33 public $option_flags = array('nocache', 'nofilter');
36 * Compiles code for generating output from any expression
38 * @param array $args array with attributes from parser
39 * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
40 * @param array $parameter array with compilation parameter
43 * @throws \SmartyException
45 public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
47 // check and get attributes
48 $_attr = $this->getAttributes($compiler, $args);
49 $output = $parameter[ 'value' ];
51 if (!empty($parameter[ 'modifierlist' ])) {
52 $output = $compiler->compileTag('private_modifier', array(),
53 array('modifierlist' => $parameter[ 'modifierlist' ],
56 if (isset($_attr[ 'assign' ])) {
57 // assign output to variable
58 return "<?php \$_smarty_tpl->assign({$_attr['assign']},{$output});?>";
61 if (!$_attr[ 'nofilter' ]) {
63 if (!empty($compiler->smarty->default_modifiers)) {
64 if (empty($compiler->default_modifier_list)) {
65 $modifierlist = array();
66 foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
67 preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/',
68 $single_default_modifier, $mod_array);
69 for ($i = 0, $count = count($mod_array[ 0 ]); $i < $count; $i ++) {
70 if ($mod_array[ 0 ][ $i ] != ':') {
71 $modifierlist[ $key ][] = $mod_array[ 0 ][ $i ];
75 $compiler->default_modifier_list = $modifierlist;
77 $output = $compiler->compileTag('private_modifier', array(),
78 array('modifierlist' => $compiler->default_modifier_list,
82 if ($compiler->template->smarty->escape_html) {
83 $output = "htmlspecialchars({$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
85 // loop over registered filters
86 if (!empty($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ])) {
87 foreach ($compiler->template->smarty->registered_filters[ Smarty::FILTER_VARIABLE ] as $key =>
89 if (!is_array($function)) {
90 $output = "{$function}({$output},\$_smarty_tpl)";
91 } elseif (is_object($function[ 0 ])) {
93 "\$_smarty_tpl->smarty->registered_filters[Smarty::FILTER_VARIABLE]['{$key}'][0]->{$function[1]}({$output},\$_smarty_tpl)";
95 $output = "{$function[0]}::{$function[1]}({$output},\$_smarty_tpl)";
99 // auto loaded filters
100 if (isset($compiler->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ])) {
101 foreach ((array) $compiler->template->smarty->autoload_filters[ Smarty::FILTER_VARIABLE ] as $name)
103 $result = $this->compile_output_filter($compiler, $name, $output);
104 if ($result !== false) {
107 // not found, throw exception
108 throw new SmartyException("Unable to load filter '{$name}'");
112 foreach ($compiler->variable_filters as $filter) {
113 if (count($filter) == 1 &&
114 ($result = $this->compile_output_filter($compiler, $filter[ 0 ], $output)) !== false
118 $output = $compiler->compileTag('private_modifier', array(),
119 array('modifierlist' => array($filter), 'value' => $output));
124 $compiler->has_output = true;
125 $output = "<?php echo {$output};?>";
132 * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
133 * @param string $name name of variable filter
134 * @param string $output embedded output
138 private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
140 $plugin_name = "smarty_variablefilter_{$name}";
141 $path = $compiler->smarty->loadPlugin($plugin_name);
144 if ($compiler->template->caching) {
145 $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'file' ] =
147 $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'function' ] =
150 $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'file' ] =
152 $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'function' ] =
156 return "{$plugin_name}({$output},\$_smarty_tpl)";