libs/sysplugins/smarty_internal_extension_config.php Quellcode

smarty_internal_extension_config.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
8 {
15  static function configLoad($obj, $config_file, $sections = null, $scope = 'local')
16  {
17  $smarty = isset($obj->smarty) ? $obj->smarty : $obj;
18  $confObj = new $smarty->template_class($config_file, $smarty, $obj);
19  $confObj->caching = Smarty::CACHING_OFF;
20  $confObj->source = Smarty_Template_Config::load($confObj);
21  $confObj->source->config_sections = $sections;
22  $confObj->source->scope = $scope;
23  $confObj->compiled = Smarty_Template_Compiled::load($confObj);
24  if ($confObj->smarty->debugging) {
26  }
27  $confObj->compiled->render($confObj);
28  if ($confObj->smarty->debugging) {
30  }
31  if ($obj instanceof Smarty_Internal_Template) {
32  $obj->properties['file_dependency'][$confObj->source->uid] = array($confObj->source->filepath, $confObj->source->timestamp, $confObj->source->type);
33  }
34  }
35 
44  static function loadConfigVars($_template, $_config_vars)
45  {
46  $scope = $_template->source->scope;
47  // pointer to scope (local scope is parent of template object
48  $scope_ptr = $_template->parent;
49  if ($scope == 'parent') {
50  if (isset($_template->parent->parent)) {
51  $scope_ptr = $_template->parent->parent;
52  }
53  } elseif ($scope == 'root' || $scope == 'global') {
54  while (isset($scope_ptr->parent)) {
55  $scope_ptr = $scope_ptr->parent;
56  }
57  }
58  // copy global config vars
59  foreach ($_config_vars['vars'] as $variable => $value) {
60  if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
61  $scope_ptr->config_vars[$variable] = $value;
62  } else {
63  $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
64  }
65  }
66  // scan sections
67  $sections = $_template->source->config_sections;
68  if (!empty($sections)) {
69  foreach ((array) $sections as $_template_section) {
70  if (isset($_config_vars['sections'][$_template_section])) {
71  foreach ($_config_vars['sections'][$_template_section]['vars'] as $variable => $value) {
72  if ($_template->smarty->config_overwrite || !isset($scope_ptr->config_vars[$variable])) {
73  $scope_ptr->config_vars[$variable] = $value;
74  } else {
75  $scope_ptr->config_vars[$variable] = array_merge((array) $scope_ptr->config_vars[$variable], (array) $value);
76  }
77  }
78  }
79  }
80  }
81  }
82 
91  static function getConfigVars($obj, $varname = null, $search_parents = true)
92  {
93  $_ptr = $obj;
94  $var_array = array();
95  while ($_ptr !== null) {
96  if (isset($varname)) {
97  if (isset($_ptr->config_vars[$varname])) {
98  return $_ptr->config_vars[$varname];
99  }
100  } else {
101  $var_array = array_merge($_ptr->config_vars, $var_array);
102  }
103  // not found, try at parent
104  if ($search_parents) {
105  $_ptr = $_ptr->parent;
106  } else {
107  $_ptr = null;
108  }
109  }
110  if (isset($varname)) {
111  return '';
112  } else {
113  return $var_array;
114  }
115  }
116 
125  static function getConfigVariable($obj, $variable, $error_enable = true)
126  {
127  $_ptr = $obj;
128  while ($_ptr !== null) {
129  if (isset($_ptr->config_vars[$variable])) {
130  // found it, return it
131  return $_ptr->config_vars[$variable];
132  }
133  // not found, try at parent
134  $_ptr = $_ptr->parent;
135  }
136  if ($obj->error_unassigned && $error_enable) {
137  // force a notice
138  $x = $$variable;
139  }
140 
141  return null;
142  }
143 
151  static function clearConfig($obj, $name = null)
152  {
153  if (isset($name)) {
154  unset($obj->config_vars[$name]);
155  } else {
156  $obj->config_vars = array();
157  }
158  return $obj;
159  }
160 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.