| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-05-05 19:48:42 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Insert | 
					
						
							|  |  |  |  * Compiles the {insert} tag | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @package    Smarty | 
					
						
							| 
									
										
										
										
											2010-05-05 19:48:42 +00:00
										 |  |  |  * @subpackage Compiler | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |  * @author     Uwe Tews | 
					
						
							| 
									
										
										
										
											2010-05-05 19:48:42 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-08-17 15:39:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2010-05-05 19:48:42 +00:00
										 |  |  |  * Smarty Internal Plugin Compile Insert 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-05 19:48:42 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-07-14 22:15:45 +00:00
										 |  |  | class Smarty_Internal_Compile_Insert 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'); | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Attribute definition: Overwrites base class. | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var array | 
					
						
							|  |  |  |      * @see Smarty_Internal_CompileBase | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $shorttag_order = array('name'); | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-03-22 16:09:05 +00:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2010-05-05 19:48:42 +00:00
										 |  |  |      * Compiles code for the {insert} tag | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param array                                 $args     array with attributes from parser | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2010-05-05 19:48:42 +00:00
										 |  |  |      * @return string compiled code | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |      * @throws \SmartyCompilerException | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @throws \SmartyException | 
					
						
							| 
									
										
										
										
											2010-05-05 19:48:42 +00:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler) | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |         // check and get attributes
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $_attr = $this->getAttributes($compiler, $args); | 
					
						
							| 
									
										
										
										
											2015-04-23 02:34:28 +02:00
										 |  |  |         $nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache); | 
					
						
							|  |  |  |         if (!$nocacheParam) { | 
					
						
							|  |  |  |             // do not compile as nocache code
 | 
					
						
							|  |  |  |             $compiler->suppressNocacheProcessing = true; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $compiler->tag_nocache = true; | 
					
						
							| 
									
										
										
										
											2010-01-11 20:22:41 +00:00
										 |  |  |         $_smarty_tpl = $compiler->template; | 
					
						
							| 
									
										
										
										
											2010-08-23 14:40:10 +00:00
										 |  |  |         $_name = null; | 
					
						
							|  |  |  |         $_script = null; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         $_output = '<?php '; | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |         // save possible attributes
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         eval('$_name = @' . $_attr[ 'name' ] . ';'); | 
					
						
							|  |  |  |         if (isset($_attr[ 'assign' ])) { | 
					
						
							| 
									
										
										
										
											2010-11-11 21:34:36 +00:00
										 |  |  |             // output will be stored in a smarty variable instead of being displayed
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $_assign = $_attr[ 'assign' ]; | 
					
						
							| 
									
										
										
										
											2014-06-06 02:40:04 +00:00
										 |  |  |             // create variable to make sure that the compiler knows about its nocache status
 | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |             $var = trim($_attr[ 'assign' ], '\''); | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             if (isset($compiler->template->tpl_vars[ $var ])) { | 
					
						
							|  |  |  |                 $compiler->template->tpl_vars[ $var ]->nocache = true; | 
					
						
							| 
									
										
										
										
											2015-05-19 22:47:04 +02:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 $compiler->template->tpl_vars[ $var ] = new Smarty_Variable(null, true); | 
					
						
							| 
									
										
										
										
											2015-05-19 22:47:04 +02:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         if (isset($_attr[ 'script' ])) { | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             // script which must be included
 | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |             $_function = "smarty_insert_{$_name}"; | 
					
						
							| 
									
										
										
										
											2009-11-12 17:20:42 +00:00
										 |  |  |             $_smarty_tpl = $compiler->template; | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |             $_filepath = false; | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             eval('$_script = @' . $_attr[ 'script' ] . ';'); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             if (!isset($compiler->smarty->security_policy) && file_exists($_script)) { | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |                 $_filepath = $_script; | 
					
						
							|  |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 if (isset($compiler->smarty->security_policy)) { | 
					
						
							|  |  |  |                     $_dir = $compiler->smarty->security_policy->trusted_dir; | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2015-12-27 08:11:31 +01:00
										 |  |  |                     $_dir = $compiler->smarty instanceof SmartyBC ? $compiler->smarty->trusted_dir : null; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |                 if (!empty($_dir)) { | 
					
						
							| 
									
										
										
										
											2017-10-26 05:27:25 +02:00
										 |  |  |                     foreach ((array)$_dir as $_script_dir) { | 
					
						
							|  |  |  |                         $_script_dir = rtrim($_script_dir, '/\\') . DIRECTORY_SEPARATOR; | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |                         if (file_exists($_script_dir . $_script)) { | 
					
						
							|  |  |  |                             $_filepath = $_script_dir . $_script; | 
					
						
							|  |  |  |                             break; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |             if ($_filepath === false) { | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |                 $compiler->trigger_template_error("{insert} missing script file '{$_script}'", null, true); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |             // code for script file loading
 | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |             $_output .= "require_once '{$_filepath}' ;"; | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |             include_once $_filepath; | 
					
						
							| 
									
										
										
										
											2010-01-11 20:22:41 +00:00
										 |  |  |             if (!is_callable($_function)) { | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                 $compiler->trigger_template_error( | 
					
						
							|  |  |  |                     " {insert} function '{$_function}' is not callable in script file '{$_script}'", | 
					
						
							|  |  |  |                     null, | 
					
						
							|  |  |  |                     true | 
					
						
							|  |  |  |                 ); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |             $_filepath = 'null'; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             $_function = "insert_{$_name}"; | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |             // function in PHP script ?
 | 
					
						
							| 
									
										
										
										
											2010-01-11 20:22:41 +00:00
										 |  |  |             if (!is_callable($_function)) { | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |                 // try plugin
 | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 if (!$_function = $compiler->getPlugin($_name, 'insert')) { | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |                     $compiler->trigger_template_error( | 
					
						
							|  |  |  |                         "{insert} no function or plugin found for '{$_name}'", | 
					
						
							|  |  |  |                         null, | 
					
						
							|  |  |  |                         true | 
					
						
							|  |  |  |                     ); | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // delete {insert} standard attributes
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |         unset($_attr[ 'name' ], $_attr[ 'assign' ], $_attr[ 'script' ], $_attr[ 'nocache' ]); | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // convert attributes into parameter array string
 | 
					
						
							|  |  |  |         $_paramsArray = array(); | 
					
						
							|  |  |  |         foreach ($_attr as $_key => $_value) { | 
					
						
							| 
									
										
										
										
											2015-08-06 01:19:11 +02:00
										 |  |  |             $_paramsArray[] = "'$_key' => $_value"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |         $_params = 'array(' . implode(", ", $_paramsArray) . ')'; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         // call insert
 | 
					
						
							|  |  |  |         if (isset($_assign)) { | 
					
						
							| 
									
										
										
										
											2015-04-23 02:34:28 +02:00
										 |  |  |             if ($_smarty_tpl->caching && !$nocacheParam) { | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |                 $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}',{$_assign});?>"; | 
					
						
							| 
									
										
										
										
											2010-05-05 19:48:42 +00:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2010-11-12 23:42:32 +00:00
										 |  |  |                 $_output .= "\$_smarty_tpl->assign({$_assign} , {$_function} ({$_params},\$_smarty_tpl), true);?>"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2015-04-23 02:34:28 +02:00
										 |  |  |             if ($_smarty_tpl->caching && !$nocacheParam) { | 
					
						
							| 
									
										
										
										
											2010-07-07 22:08:10 +00:00
										 |  |  |                 $_output .= "echo Smarty_Internal_Nocache_Insert::compile ('{$_function}',{$_params}, \$_smarty_tpl, '{$_filepath}');?>"; | 
					
						
							| 
									
										
										
										
											2010-05-05 19:48:42 +00:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2010-11-12 23:42:32 +00:00
										 |  |  |                 $_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>"; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-10-11 06:56:22 +02:00
										 |  |  |         $compiler->template->compiled->has_nocache_code = true; | 
					
						
							| 
									
										
										
										
											2009-03-22 16:09:05 +00:00
										 |  |  |         return $_output; | 
					
						
							| 
									
										
										
										
											2011-09-16 14:19:56 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |