| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Function
 | 
					
						
							|  |  |  |  * Compiles the {function} {/function} tags | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Function Class | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Compile_Function extends Smarty_Internal_CompileBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public $required_attributes = array('name'); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public $shorttag_order = array('name'); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $optional_attributes = array('_any'); | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |      * Compiles code for the {function} tag | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  array  $args      array with attributes from parser | 
					
						
							|  |  |  |      * @param  object $compiler  compiler object | 
					
						
							|  |  |  |      * @param  array  $parameter array with compilation parameter | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * @return boolean true | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public function compile($args, $compiler, $parameter) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         // check and get attributes
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $_attr = $this->getAttributes($compiler, $args); | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if ($_attr['nocache'] === true) { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno); | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         unset($_attr['nocache']); | 
					
						
							| 
									
										
										
										
											2010-07-14 22:47:37 +00:00
										 |  |  |         $save = array($_attr, $compiler->parser->current_buffer, | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |                       $compiler->template->has_nocache_code, $compiler->template->required_plugins); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $this->openTag($compiler, 'function', $save); | 
					
						
							| 
									
										
										
										
											2010-01-12 20:37:05 +00:00
										 |  |  |         $_name = trim($_attr['name'], "'\""); | 
					
						
							| 
									
										
										
										
											2009-12-27 15:06:49 +00:00
										 |  |  |         unset($_attr['name']); | 
					
						
							| 
									
										
										
										
											2011-09-28 15:56:01 +00:00
										 |  |  |         // set flag that we are compiling a template function
 | 
					
						
							|  |  |  |         $compiler->compiles_template_function = true; | 
					
						
							| 
									
										
										
										
											2010-06-03 14:33:51 +00:00
										 |  |  |         $compiler->template->properties['function'][$_name]['parameter'] = array(); | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         /** @var Smarty_Internal_Template $_smarty_tpl | 
					
						
							|  |  |  |          * used in evaluated code | 
					
						
							|  |  |  |          */ | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $_smarty_tpl = $compiler->template; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         foreach ($_attr as $_key => $_data) { | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |             eval ('$tmp=' . $_data . ';'); | 
					
						
							| 
									
										
										
										
											2010-12-14 03:55:31 +00:00
										 |  |  |             $compiler->template->properties['function'][$_name]['parameter'][$_key] = $tmp; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-06-03 14:33:51 +00:00
										 |  |  |         $compiler->smarty->template_functions[$_name]['parameter'] = $compiler->template->properties['function'][$_name]['parameter']; | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |         if ($compiler->template->caching) { | 
					
						
							|  |  |  |             $output = ''; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $output = "<?php if (!function_exists('smarty_template_function_{$_name}')) {
 | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |     function smarty_template_function_{$_name}(\$_smarty_tpl,\$params) { | 
					
						
							|  |  |  |     \$saved_tpl_vars = \$_smarty_tpl->tpl_vars; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     foreach (\$_smarty_tpl->smarty->template_functions['{$_name}']['parameter'] as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}; | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  |     foreach (\$params as \$key => \$value) {\$_smarty_tpl->tpl_vars[\$key] = new Smarty_variable(\$value);}?>";
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         // Init temporary context
 | 
					
						
							| 
									
										
										
										
											2010-03-25 20:43:56 +00:00
										 |  |  |         $compiler->template->required_plugins = array('compiled' => array(), 'nocache' => array()); | 
					
						
							| 
									
										
										
										
											2010-07-14 22:47:37 +00:00
										 |  |  |         $compiler->parser->current_buffer = new _smarty_template_buffer($compiler->parser); | 
					
						
							|  |  |  |         $compiler->parser->current_buffer->append_subtree(new _smarty_tag($compiler->parser, $output)); | 
					
						
							| 
									
										
										
										
											2009-12-29 20:12:11 +00:00
										 |  |  |         $compiler->template->has_nocache_code = false; | 
					
						
							| 
									
										
										
										
											2010-01-09 19:23:35 +00:00
										 |  |  |         $compiler->has_code = false; | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |         $compiler->template->properties['function'][$_name]['compiled'] = ''; | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Functionclose Class | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Compile_Functionclose extends Smarty_Internal_CompileBase | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |      * Compiles code for the {/function} tag | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * @param  array  $args      array with attributes from parser | 
					
						
							|  |  |  |      * @param  object $compiler  compiler object | 
					
						
							|  |  |  |      * @param  array  $parameter array with compilation parameter | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |      * @return boolean true | 
					
						
							|  |  |  |      */ | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |     public function compile($args, $compiler, $parameter) | 
					
						
							| 
									
										
										
										
											2009-11-06 14:35:00 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $_attr = $this->getAttributes($compiler, $args); | 
					
						
							|  |  |  |         $saved_data = $this->closeTag($compiler, array('function')); | 
					
						
							|  |  |  |         $_name = trim($saved_data[0]['name'], "'\""); | 
					
						
							| 
									
										
										
										
											2009-12-31 16:38:12 +00:00
										 |  |  |         // build plugin include code
 | 
					
						
							|  |  |  |         $plugins_string = ''; | 
					
						
							|  |  |  |         if (!empty($compiler->template->required_plugins['compiled'])) { | 
					
						
							|  |  |  |             $plugins_string = '<?php '; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |             foreach ($compiler->template->required_plugins['compiled'] as $tmp) { | 
					
						
							|  |  |  |                 foreach ($tmp as $data) { | 
					
						
							| 
									
										
										
										
											2010-02-05 17:03:22 +00:00
										 |  |  |                     $plugins_string .= "if (!is_callable('{$data['function']}')) include '{$data['file']}';\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-12-31 16:38:12 +00:00
										 |  |  |             $plugins_string .= '?>'; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-03-25 20:43:56 +00:00
										 |  |  |         if (!empty($compiler->template->required_plugins['nocache'])) { | 
					
						
							| 
									
										
										
										
											2009-12-31 16:38:12 +00:00
										 |  |  |             $plugins_string .= "<?php echo '/*%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/<?php "; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  |             foreach ($compiler->template->required_plugins['nocache'] as $tmp) { | 
					
						
							|  |  |  |                 foreach ($tmp as $data) { | 
					
						
							| 
									
										
										
										
											2010-03-25 20:43:56 +00:00
										 |  |  |                     $plugins_string .= "if (!is_callable(\'{$data['function']}\')) include \'{$data['file']}\';\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-12-31 16:38:12 +00:00
										 |  |  |             $plugins_string .= "?>/*/%%SmartyNocache:{$compiler->template->properties['nocache_hash']}%%*/';?>\n"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         // remove last line break from function definition
 | 
					
						
							|  |  |  |         $last = count($compiler->parser->current_buffer->subtrees) - 1; | 
					
						
							|  |  |  |         if ($compiler->parser->current_buffer->subtrees[$last] instanceof _smarty_linebreak) { | 
					
						
							|  |  |  |             unset($compiler->parser->current_buffer->subtrees[$last]); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |         // if caching save template function for possible nocache call
 | 
					
						
							|  |  |  |         if ($compiler->template->caching) { | 
					
						
							|  |  |  |             $compiler->template->properties['function'][$_name]['compiled'] .= $plugins_string | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |                 . $compiler->parser->current_buffer->to_smarty_php(); | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |             $compiler->template->properties['function'][$_name]['nocache_hash'] = $compiler->template->properties['nocache_hash']; | 
					
						
							|  |  |  |             $compiler->template->properties['function'][$_name]['has_nocache_code'] = $compiler->template->has_nocache_code; | 
					
						
							| 
									
										
										
										
											2011-09-28 15:56:01 +00:00
										 |  |  |             $compiler->template->properties['function'][$_name]['called_functions'] = $compiler->called_functions; | 
					
						
							|  |  |  |             $compiler->called_functions = array(); | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |             $compiler->smarty->template_functions[$_name] = $compiler->template->properties['function'][$_name]; | 
					
						
							|  |  |  |             $compiler->has_code = false; | 
					
						
							|  |  |  |             $output = true; | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2012-11-26 20:11:10 +00:00
										 |  |  |             $output = $plugins_string . $compiler->parser->current_buffer->to_smarty_php() . "<?php \$_smarty_tpl->tpl_vars = \$saved_tpl_vars;
 | 
					
						
							|  |  |  | foreach (Smarty::\$global_tpl_vars as \$key => \$value) if(!isset(\$_smarty_tpl->tpl_vars[\$key])) \$_smarty_tpl->tpl_vars[\$key] = \$value;}}?>\n";
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-28 15:56:01 +00:00
										 |  |  |         // reset flag that we are compiling a template function
 | 
					
						
							|  |  |  |         $compiler->compiles_template_function = false; | 
					
						
							| 
									
										
										
										
											2009-12-31 16:38:12 +00:00
										 |  |  |         // restore old compiler status
 | 
					
						
							| 
									
										
										
										
											2010-07-14 22:47:37 +00:00
										 |  |  |         $compiler->parser->current_buffer = $saved_data[1]; | 
					
						
							|  |  |  |         $compiler->template->has_nocache_code = $compiler->template->has_nocache_code | $saved_data[2]; | 
					
						
							|  |  |  |         $compiler->template->required_plugins = $saved_data[3]; | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-25 19:33:55 +00:00
										 |  |  |         return $output; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |