123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
-
-
- class Smarty_Internal_Method_ConfigLoad
- {
-
-
- public $objMap = 7;
-
-
-
- public function configLoad(Smarty_Internal_Data $data, $config_file, $sections = null)
- {
- $this->_loadConfigFile($data, $config_file, $sections, 0);
- return $data;
- }
-
-
-
- public function _loadConfigFile(Smarty_Internal_Data $data, $config_file, $sections = null, $scope = 0)
- {
-
- $smarty = isset($data->smarty) ? $data->smarty : $data;
-
- $confObj = new Smarty_Internal_Template($config_file, $smarty, $data);
- $confObj->caching = Smarty::CACHING_OFF;
- $confObj->source = Smarty_Template_Config::load($confObj);
- $confObj->source->config_sections = $sections;
- $confObj->source->scope = $scope;
- $confObj->compiled = Smarty_Template_Compiled::load($confObj);
- $confObj->compiled->render($confObj);
- if ($data->_objType == 2) {
- $data->compiled->file_dependency[$confObj->source->uid] =
- array($confObj->source->filepath, $confObj->source->getTimeStamp(), $confObj->source->type);
- }
- }
-
-
-
- public function _loadConfigVars(Smarty_Internal_Template $tpl, $_config_vars)
- {
- $this->_assignConfigVars($tpl->parent, $tpl, $_config_vars);
- $scope = $tpl->source->scope;
- if (!$scope && !$tpl->scope) {
- return;
- }
- foreach (array($scope, $tpl->scope) as $s) {
- $s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s;
- if ($bubble_up && $s) {
- $ptr = $tpl->parent->parent;
- if (isset($ptr)) {
- $this->_assignConfigVars($ptr, $tpl, $_config_vars);
- $ptr = $ptr->parent;
- }
- if ($s == Smarty::SCOPE_PARENT) {
- continue;
- }
- while (isset($ptr) && $ptr->_objType == 2) {
- $this->_assignConfigVars($ptr, $tpl, $_config_vars);
- $ptr = $ptr->parent;
- }
- if ($s == Smarty::SCOPE_TPL_ROOT) {
- continue;
- } elseif ($s == Smarty::SCOPE_SMARTY) {
- $this->_assignConfigVars($tpl->smarty, $tpl, $_config_vars);
- } elseif ($s == Smarty::SCOPE_GLOBAL) {
- $this->_assignConfigVars($tpl->smarty, $tpl, $_config_vars);
- } elseif ($s == Smarty::SCOPE_ROOT) {
- while (isset($ptr->parent)) {
- $ptr = $ptr->parent;
- }
- $this->_assignConfigVars($ptr, $tpl, $_config_vars);
- }
- }
- }
- }
-
-
-
- public function _assignConfigVars(Smarty_Internal_Data $scope_ptr, Smarty_Internal_Template $tpl, $_config_vars)
- {
-
- foreach ($_config_vars['vars'] as $variable => $value) {
- if ($tpl->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
- $scope_ptr->config_vars[$variable] = $value;
- } else {
- $scope_ptr->config_vars[$variable] =
- array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
- }
- }
-
- $sections = $tpl->source->config_sections;
- if (!empty($sections)) {
- foreach ((array) $sections as $tpl_section) {
- if (isset($_config_vars['sections'][$tpl_section])) {
- foreach ($_config_vars['sections'][$tpl_section]['vars'] as $variable => $value) {
- if ($tpl->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
- $scope_ptr->config_vars[$variable] = $value;
- } else {
- $scope_ptr->config_vars[$variable] =
- array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
- }
- }
- }
- }
- }
- }
-
-
-
- public function _getConfigVariable(Smarty_Internal_Template $tpl, $varName, $errorEnable = true)
- {
- $_ptr = $tpl;
- while ($_ptr !== null) {
- if (isset($_ptr->config_vars[$varName])) {
-
- return $_ptr->config_vars[$varName];
- }
-
- $_ptr = $_ptr->parent;
- }
- if ($tpl->smarty->error_unassigned && $errorEnable) {
-
- $x = $$varName;
- }
- return null;
- }
- }
|