]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_private_print_expression.php
Merge pull request #4234 from annando/participation-2
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_compile_private_print_expression.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile Print Expression
4  * Compiles any tag which will output an expression or variable
5  *
6  * @package    Smarty
7  * @subpackage Compiler
8  * @author     Uwe Tews
9  */
10
11 /**
12  * Smarty Internal Plugin Compile Print Expression Class
13  *
14  * @package    Smarty
15  * @subpackage Compiler
16  */
17 class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_CompileBase
18 {
19     /**
20      * Attribute definition: Overwrites base class.
21      *
22      * @var array
23      * @see Smarty_Internal_CompileBase
24      */
25     public $optional_attributes = array('assign');
26
27     /**
28      * Attribute definition: Overwrites base class.
29      *
30      * @var array
31      * @see Smarty_Internal_CompileBase
32      */
33     public $option_flags = array('nocache', 'nofilter');
34
35     /**
36      * Compiles code for generating output from any expression
37      *
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
41      *
42      * @return string
43      * @throws \SmartyException
44      */
45     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
46     {
47         // check and get attributes
48         $_attr = $this->getAttributes($compiler, $args);
49         $output = $parameter[ 'value' ];
50         // tag modifier
51         if (!empty($parameter[ 'modifierlist' ])) {
52             $output = $compiler->compileTag('private_modifier', array(),
53                                             array('modifierlist' => $parameter[ 'modifierlist' ],
54                                                   'value' => $output));
55         }
56         if (isset($_attr[ 'assign' ])) {
57             // assign output to variable
58             return "<?php \$_smarty_tpl->assign({$_attr['assign']},{$output});?>";
59         } else {
60             // display value
61             if (!$_attr[ 'nofilter' ]) {
62                 // default modifier
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 ];
72                                 }
73                             }
74                         }
75                         $compiler->default_modifier_list = $modifierlist;
76                     }
77                     $output = $compiler->compileTag('private_modifier', array(),
78                                                     array('modifierlist' => $compiler->default_modifier_list,
79                                                           'value' => $output));
80                 }
81                 // autoescape html
82                 if ($compiler->template->smarty->escape_html) {
83                     $output = "htmlspecialchars({$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
84                 }
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 =>
88                              $function) {
89                         if (!is_array($function)) {
90                             $output = "{$function}({$output},\$_smarty_tpl)";
91                         } elseif (is_object($function[ 0 ])) {
92                             $output =
93                                 "\$_smarty_tpl->smarty->registered_filters[Smarty::FILTER_VARIABLE]['{$key}'][0]->{$function[1]}({$output},\$_smarty_tpl)";
94                         } else {
95                             $output = "{$function[0]}::{$function[1]}({$output},\$_smarty_tpl)";
96                         }
97                     }
98                 }
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)
102                     {
103                         $result = $this->compile_output_filter($compiler, $name, $output);
104                         if ($result !== false) {
105                             $output = $result;
106                         } else {
107                             // not found, throw exception
108                             throw new SmartyException("Unable to load filter '{$name}'");
109                         }
110                     }
111                 }
112                 foreach ($compiler->variable_filters as $filter) {
113                     if (count($filter) == 1 &&
114                         ($result = $this->compile_output_filter($compiler, $filter[ 0 ], $output)) !== false
115                     ) {
116                         $output = $result;
117                     } else {
118                         $output = $compiler->compileTag('private_modifier', array(),
119                                                         array('modifierlist' => array($filter), 'value' => $output));
120                     }
121                 }
122             }
123
124             $compiler->has_output = true;
125             $output = "<?php echo {$output};?>";
126         }
127
128         return $output;
129     }
130
131     /**
132      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
133      * @param string                                $name     name of variable filter
134      * @param string                                $output   embedded output
135      *
136      * @return string
137      */
138     private function compile_output_filter(Smarty_Internal_TemplateCompilerBase $compiler, $name, $output)
139     {
140         $plugin_name = "smarty_variablefilter_{$name}";
141         $path = $compiler->smarty->loadPlugin($plugin_name);
142         if ($path) {
143             /**
144             if ($compiler->template->caching) {
145                 $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'file' ] =
146                     $path;
147                 $compiler->parent_compiler->template->compiled->required_plugins[ 'nocache' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'function' ] =
148                     $plugin_name;
149             } else {
150                 $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'file' ] =
151                     $path;
152                 $compiler->parent_compiler->template->compiled->required_plugins[ 'compiled' ][ $name ][ Smarty::FILTER_VARIABLE ][ 'function' ] =
153                     $plugin_name;
154             }
155              * */
156             return "{$plugin_name}({$output},\$_smarty_tpl)";
157         } else {
158             // not found
159             return false;
160         }
161     }
162 }