1: <?php
  2:   3:   4:   5:   6:   7:   8:   9: 
 10: 
 11:  12:  13:  14:  15:  16: 
 17: class Smarty_Internal_Compile_Private_Print_Expression extends Smarty_Internal_CompileBase
 18: {
 19:      20:  21:  22:  23:  24: 
 25:     public $optional_attributes = array('assign');
 26:      27:  28:  29:  30:  31: 
 32:     public $option_flags = array('nocache', 'nofilter');
 33: 
 34:      35:  36:  37:  38:  39:  40:  41:  42:  43: 
 44:     public function compile($args, $compiler, $parameter)
 45:     {
 46:         
 47:         $_attr = $this->getAttributes($compiler, $args);
 48:         
 49:         if ($_attr['nocache'] === true) {
 50:             $compiler->tag_nocache = true;
 51:         }
 52:         if (isset($_attr['assign'])) {
 53:             
 54:             $output = "<?php \$_smarty_tpl->assign({$_attr['assign']},{$parameter['value']});?>";
 55:         } else {
 56:             
 57:             $output = $parameter['value'];
 58:             
 59:             if (!empty($parameter['modifierlist'])) {
 60:                 $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => $parameter['modifierlist'], 'value' => $output));
 61:             }
 62:             if (!$_attr['nofilter']) {
 63:                 
 64:                 if (!empty($compiler->smarty->default_modifiers)) {
 65:                     if (empty($compiler->default_modifier_list)) {
 66:                         $modifierlist = array();
 67:                         foreach ($compiler->smarty->default_modifiers as $key => $single_default_modifier) {
 68:                             preg_match_all('/(\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'|"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"|:|[^:]+)/', $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(), array('modifierlist' => $compiler->default_modifier_list, 'value' => $output));
 78:                 }
 79:                 
 80:                 if ($compiler->template->smarty->escape_html) {
 81:                     $output = "htmlspecialchars({$output}, ENT_QUOTES, '" . addslashes(Smarty::$_CHARSET) . "')";
 82:                 }
 83:                 
 84:                 if (!empty($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE])) {
 85:                     foreach ($compiler->template->smarty->registered_filters[Smarty::FILTER_VARIABLE] as $key => $function) {
 86:                         if (!is_array($function)) {
 87:                             $output = "{$function}({$output},\$_smarty_tpl)";
 88:                         } elseif (is_object($function[0])) {
 89:                             $output = "\$_smarty_tpl->smarty->registered_filters[Smarty::FILTER_VARIABLE]['{$key}'][0]->{$function[1]}({$output},\$_smarty_tpl)";
 90:                         } else {
 91:                             $output = "{$function[0]}::{$function[1]}({$output},\$_smarty_tpl)";
 92:                         }
 93:                     }
 94:                 }
 95:                 
 96:                 if (isset($compiler->smarty->autoload_filters[Smarty::FILTER_VARIABLE])) {
 97:                     foreach ((array) $compiler->template->smarty->autoload_filters[Smarty::FILTER_VARIABLE] as $name) {
 98:                         $result = $this->compile_output_filter($compiler, $name, $output);
 99:                         if ($result !== false) {
100:                             $output = $result;
101:                         } else {
102:                             
103:                             throw new SmartyException("Unable to load filter '{$name}'");
104:                         }
105:                     }
106:                 }
107:                 if (isset($compiler->template->variable_filters)) {
108:                     foreach ($compiler->template->variable_filters as $filter) {
109:                         if (count($filter) == 1 && ($result = $this->compile_output_filter($compiler, $filter[0], $output)) !== false) {
110:                             $output = $result;
111:                         } else {
112:                             $output = $compiler->compileTag('private_modifier', array(), array('modifierlist' => array($filter), 'value' => $output));
113:                         }
114:                     }
115:                 }
116:             }
117: 
118:             $compiler->has_output = true;
119:             $output = "<?php echo {$output};?>";
120:         }
121: 
122:         return $output;
123:     }
124: 
125:     126: 127: 128: 129: 130: 131: 
132:     private function compile_output_filter($compiler, $name, $output)
133:     {
134:         $plugin_name = "smarty_variablefilter_{$name}";
135:         $path = $compiler->smarty->loadPlugin($plugin_name, false);
136:         if ($path) {
137:             if ($compiler->template->caching) {
138:                 $compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
139:                 $compiler->template->required_plugins['nocache'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
140:             } else {
141:                 $compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['file'] = $path;
142:                 $compiler->template->required_plugins['compiled'][$name][Smarty::FILTER_VARIABLE]['function'] = $plugin_name;
143:             }
144:         } else {
145:             
146:             return false;
147:         }
148: 
149:         return "{$plugin_name}({$output},\$_smarty_tpl)";
150:     }
151: }
152: