| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Smarty Method ConfigLoad | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Smarty::configLoad() method | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @package    Smarty | 
					
						
							|  |  |  |  * @subpackage PluginsInternal | 
					
						
							|  |  |  |  * @author     Uwe Tews | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class Smarty_Internal_Method_ConfigLoad | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Valid for all objects | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @var int | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public $objMap = 7; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * load a config file, optionally load just selected sections | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @api  Smarty::configLoad() | 
					
						
							| 
									
										
										
										
											2021-10-13 12:15:17 +02:00
										 |  |  |      * @link https://www.smarty.net/docs/en/api.config.load.tpl | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param string                                                  $config_file filename | 
					
						
							|  |  |  |      * @param mixed                                                   $sections    array of section names, single | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |      *                                                                             section or null | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @return \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @throws \Exception | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |      */ | 
					
						
							|  |  |  |     public function configLoad(Smarty_Internal_Data $data, $config_file, $sections = null) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-02-09 23:27:07 +01:00
										 |  |  |         $this->_loadConfigFile($data, $config_file, $sections, null); | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |         return $data; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * load a config file, optionally load just selected sections | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @api  Smarty::configLoad() | 
					
						
							| 
									
										
										
										
											2021-10-13 12:15:17 +02:00
										 |  |  |      * @link https://www.smarty.net/docs/en/api.config.load.tpl | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |      * | 
					
						
							|  |  |  |      * @param \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template $data | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param string                                                  $config_file filename | 
					
						
							|  |  |  |      * @param mixed                                                   $sections    array of section names, single | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |      *                                                                             section or null | 
					
						
							|  |  |  |      * @param int                                                     $scope       scope into which config variables | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |      *                                                                             shall be loaded | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |      * @throws \Exception | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |     public function _loadConfigFile(Smarty_Internal_Data $data, $config_file, $sections = null, $scope = 0) | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |         /* @var \Smarty $smarty */ | 
					
						
							| 
									
										
										
										
											2016-09-11 05:41:16 +02:00
										 |  |  |         $smarty = $data->_getSmartyObj(); | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |         /* @var \Smarty_Internal_Template $confObj */ | 
					
						
							| 
									
										
										
										
											2016-09-11 05:41:16 +02:00
										 |  |  |         $confObj = new Smarty_Internal_Template($config_file, $smarty, $data, null, null, null, null, true); | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |         $confObj->caching = Smarty::CACHING_OFF; | 
					
						
							|  |  |  |         $confObj->source->config_sections = $sections; | 
					
						
							|  |  |  |         $confObj->source->scope = $scope; | 
					
						
							|  |  |  |         $confObj->compiled = Smarty_Template_Compiled::load($confObj); | 
					
						
							|  |  |  |         $confObj->compiled->render($confObj); | 
					
						
							| 
									
										
										
										
											2016-09-11 04:35:52 +02:00
										 |  |  |         if ($data->_isTplObj()) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             $data->compiled->file_dependency[ $confObj->source->uid ] = | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |                 array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type); | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * load config variables into template object | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |      * @param \Smarty_Internal_Template $tpl | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param array                     $new_config_vars | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |     public function _loadConfigVars(Smarty_Internal_Template $tpl, $new_config_vars) | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |         $this->_assignConfigVars($tpl->parent->config_vars, $tpl, $new_config_vars); | 
					
						
							|  |  |  |         $tagScope = $tpl->source->scope; | 
					
						
							|  |  |  |         if ($tagScope >= 0) { | 
					
						
							| 
									
										
										
										
											2017-11-06 01:02:56 +01:00
										 |  |  |             if ($tagScope === Smarty::SCOPE_LOCAL) { | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |                 $this->_updateVarStack($tpl, $new_config_vars); | 
					
						
							|  |  |  |                 $tagScope = 0; | 
					
						
							|  |  |  |                 if (!$tpl->scope) { | 
					
						
							|  |  |  |                     return; | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2016-09-11 04:35:52 +02:00
										 |  |  |             if ($tpl->parent->_isTplObj() && ($tagScope || $tpl->parent->scope)) { | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |                 $mergedScope = $tagScope | $tpl->scope; | 
					
						
							|  |  |  |                 if ($mergedScope) { | 
					
						
							|  |  |  |                     // update scopes
 | 
					
						
							| 
									
										
										
										
											2017-10-26 10:25:41 +02:00
										 |  |  |                     /* @var \Smarty_Internal_Template|\Smarty|\Smarty_Internal_Data $ptr */ | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |                     foreach ($tpl->smarty->ext->_updateScope->_getAffectedScopes($tpl->parent, $mergedScope) as $ptr) { | 
					
						
							|  |  |  |                         $this->_assignConfigVars($ptr->config_vars, $tpl, $new_config_vars); | 
					
						
							| 
									
										
										
										
											2016-09-11 04:35:52 +02:00
										 |  |  |                         if ($tagScope && $ptr->_isTplObj() && isset($tpl->_cache[ 'varStack' ])) { | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |                             $this->_updateVarStack($tpl, $new_config_vars); | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Assign all config variables in given scope | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-09-08 22:28:06 +02:00
										 |  |  |      * @param array                     $config_vars     config variables in scope | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |      * @param \Smarty_Internal_Template $tpl | 
					
						
							| 
									
										
										
										
											2018-06-12 09:58:15 +02:00
										 |  |  |      * @param array                     $new_config_vars loaded config variables | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |     public function _assignConfigVars(&$config_vars, Smarty_Internal_Template $tpl, $new_config_vars) | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |         // copy global config vars
 | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |         foreach ($new_config_vars[ 'vars' ] as $variable => $value) { | 
					
						
							|  |  |  |             if ($tpl->smarty->config_overwrite || !isset($config_vars[ $variable ])) { | 
					
						
							|  |  |  |                 $config_vars[ $variable ] = $value; | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |             } else { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |                 $config_vars[ $variable ] = array_merge((array)$config_vars[ $variable ], (array)$value); | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         // scan sections
 | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |         $sections = $tpl->source->config_sections; | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |         if (!empty($sections)) { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |             foreach ((array)$sections as $tpl_section) { | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |                 if (isset($new_config_vars[ 'sections' ][ $tpl_section ])) { | 
					
						
							|  |  |  |                     foreach ($new_config_vars[ 'sections' ][ $tpl_section ][ 'vars' ] as $variable => $value) { | 
					
						
							|  |  |  |                         if ($tpl->smarty->config_overwrite || !isset($config_vars[ $variable ])) { | 
					
						
							|  |  |  |                             $config_vars[ $variable ] = $value; | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |                         } else { | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |                             $config_vars[ $variable ] = array_merge((array)$config_vars[ $variable ], (array)$value); | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * Update config variables in template local variable stack | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param \Smarty_Internal_Template $tpl | 
					
						
							|  |  |  |      * @param array                     $config_vars | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function _updateVarStack(Smarty_Internal_Template $tpl, $config_vars) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $i = 0; | 
					
						
							|  |  |  |         while (isset($tpl->_cache[ 'varStack' ][ $i ])) { | 
					
						
							|  |  |  |             $this->_assignConfigVars($tpl->_cache[ 'varStack' ][ $i ][ 'config' ], $tpl, $config_vars); | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |             $i++; | 
					
						
							| 
									
										
										
										
											2016-03-09 01:01:32 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |     /** | 
					
						
							|  |  |  |      * gets  a config variable value | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-09-08 22:28:06 +02:00
										 |  |  |      * @param \Smarty|\Smarty_Internal_Data|\Smarty_Internal_Template $data | 
					
						
							| 
									
										
										
										
											2018-08-31 16:45:09 +02:00
										 |  |  |      * @param string                                                  $varName the name of the config variable | 
					
						
							| 
									
										
										
										
											2016-09-08 22:28:06 +02:00
										 |  |  |      * @param bool                                                    $errorEnable | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2016-09-08 22:28:06 +02:00
										 |  |  |      * @return null|string  the value of the config variable | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2016-09-08 22:28:06 +02:00
										 |  |  |     public function _getConfigVariable(Smarty_Internal_Data $data, $varName, $errorEnable = true) | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-09-08 22:28:06 +02:00
										 |  |  |         $_ptr = $data; | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |         while ($_ptr !== null) { | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |             if (isset($_ptr->config_vars[ $varName ])) { | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |                 // found it, return it
 | 
					
						
							| 
									
										
										
										
											2016-02-09 01:27:15 +01:00
										 |  |  |                 return $_ptr->config_vars[ $varName ]; | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             // not found, try at parent
 | 
					
						
							|  |  |  |             $_ptr = $_ptr->parent; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-09-08 22:28:06 +02:00
										 |  |  |         if ($data->smarty->error_unassigned && $errorEnable) { | 
					
						
							| 
									
										
										
										
											2015-11-01 02:58:27 +01:00
										 |  |  |             // force a notice
 | 
					
						
							|  |  |  |             $x = $$varName; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return null; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-08-17 21:52:32 +02:00
										 |  |  | } |