libs/sysplugins/smarty_internal_data.php Quellcode

smarty_internal_data.php
gehe zur Dokumentation dieser Datei
1 <?php
18 {
24  public $template_class = 'Smarty_Internal_Template';
30  public $tpl_vars = array();
36  public $parent = null;
42  public $config_vars = array();
43 
53  public function assign($tpl_var, $value = null, $nocache = false)
54  {
55  if (is_array($tpl_var)) {
56  foreach ($tpl_var as $_key => $_val) {
57  if ($_key != '') {
58  $this->tpl_vars[$_key] = new Smarty_Variable($_val, $nocache);
59  }
60  }
61  } else {
62  if ($tpl_var != '') {
63  $this->tpl_vars[$tpl_var] = new Smarty_Variable($value, $nocache);
64  }
65  }
66 
67  return $this;
68  }
69 
79  public function assignGlobal($varname, $value = null, $nocache = false)
80  {
81  if ($varname != '') {
82  Smarty::$global_tpl_vars[$varname] = new Smarty_Variable($value, $nocache);
83  $ptr = $this;
84  while ($ptr instanceof Smarty_Internal_Template) {
85  $ptr->tpl_vars[$varname] = clone Smarty::$global_tpl_vars[$varname];
86  $ptr = $ptr->parent;
87  }
88  }
89 
90  return $this;
91  }
92 
102  public function assignByRef($tpl_var, &$value, $nocache = false)
103  {
104  if ($tpl_var != '') {
105  $this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache);
106  $this->tpl_vars[$tpl_var]->value = &$value;
107  }
108 
109  return $this;
110  }
111 
122  public function append($tpl_var, $value = null, $merge = false, $nocache = false)
123  {
124  if (is_array($tpl_var)) {
125  // $tpl_var is an array, ignore $value
126  foreach ($tpl_var as $_key => $_val) {
127  if ($_key != '') {
128  if (!isset($this->tpl_vars[$_key])) {
129  $tpl_var_inst = $this->getVariable($_key, null, true, false);
130  if ($tpl_var_inst instanceof Smarty_Undefined_Variable) {
131  $this->tpl_vars[$_key] = new Smarty_Variable(null, $nocache);
132  } else {
133  $this->tpl_vars[$_key] = clone $tpl_var_inst;
134  }
135  }
136  if (!(is_array($this->tpl_vars[$_key]->value) || $this->tpl_vars[$_key]->value instanceof ArrayAccess)) {
137  settype($this->tpl_vars[$_key]->value, 'array');
138  }
139  if ($merge && is_array($_val)) {
140  foreach ($_val as $_mkey => $_mval) {
141  $this->tpl_vars[$_key]->value[$_mkey] = $_mval;
142  }
143  } else {
144  $this->tpl_vars[$_key]->value[] = $_val;
145  }
146  }
147  }
148  } else {
149  if ($tpl_var != '' && isset($value)) {
150  if (!isset($this->tpl_vars[$tpl_var])) {
151  $tpl_var_inst = $this->getVariable($tpl_var, null, true, false);
152  if ($tpl_var_inst instanceof Smarty_Undefined_Variable) {
153  $this->tpl_vars[$tpl_var] = new Smarty_Variable(null, $nocache);
154  } else {
155  $this->tpl_vars[$tpl_var] = clone $tpl_var_inst;
156  }
157  }
158  if (!(is_array($this->tpl_vars[$tpl_var]->value) || $this->tpl_vars[$tpl_var]->value instanceof ArrayAccess)) {
159  settype($this->tpl_vars[$tpl_var]->value, 'array');
160  }
161  if ($merge && is_array($value)) {
162  foreach ($value as $_mkey => $_mval) {
163  $this->tpl_vars[$tpl_var]->value[$_mkey] = $_mval;
164  }
165  } else {
166  $this->tpl_vars[$tpl_var]->value[] = $value;
167  }
168  }
169  }
170 
171  return $this;
172  }
173 
183  public function appendByRef($tpl_var, &$value, $merge = false)
184  {
185  if ($tpl_var != '' && isset($value)) {
186  if (!isset($this->tpl_vars[$tpl_var])) {
187  $this->tpl_vars[$tpl_var] = new Smarty_Variable();
188  }
189  if (!is_array($this->tpl_vars[$tpl_var]->value)) {
190  settype($this->tpl_vars[$tpl_var]->value, 'array');
191  }
192  if ($merge && is_array($value)) {
193  foreach ($value as $_key => $_val) {
194  $this->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key];
195  }
196  } else {
197  $this->tpl_vars[$tpl_var]->value[] = &$value;
198  }
199  }
200 
201  return $this;
202  }
203 
213  public function getTemplateVars($varname = null, $_ptr = null, $search_parents = true)
214  {
215  if (isset($varname)) {
216  $_var = $this->getVariable($varname, $_ptr, $search_parents, false);
217  if (is_object($_var)) {
218  return $_var->value;
219  } else {
220  return null;
221  }
222  } else {
223  $_result = array();
224  if ($_ptr === null) {
225  $_ptr = $this;
226  }
227  while ($_ptr !== null) {
228  foreach ($_ptr->tpl_vars AS $key => $var) {
229  if (!array_key_exists($key, $_result)) {
230  $_result[$key] = $var->value;
231  }
232  }
233  // not found, try at parent
234  if ($search_parents) {
235  $_ptr = $_ptr->parent;
236  } else {
237  $_ptr = null;
238  }
239  }
240  if ($search_parents && isset(Smarty::$global_tpl_vars)) {
241  foreach (Smarty::$global_tpl_vars AS $key => $var) {
242  if (!array_key_exists($key, $_result)) {
243  $_result[$key] = $var->value;
244  }
245  }
246  }
247 
248  return $_result;
249  }
250  }
251 
259  public function clearAssign($tpl_var)
260  {
261  if (is_array($tpl_var)) {
262  foreach ($tpl_var as $curr_var) {
263  unset($this->tpl_vars[$curr_var]);
264  }
265  } else {
266  unset($this->tpl_vars[$tpl_var]);
267  }
268 
269  return $this;
270  }
271 
277  public function clearAllAssign()
278  {
279  $this->tpl_vars = array();
280 
281  return $this;
282  }
283 
292  public function configLoad($config_file, $sections = null)
293  {
294  // load Config class
295  Smarty_Internal_Extension_Config::configLoad($this, $config_file, $sections);
296  return $this;
297  }
298 
309  public function getVariable($variable, $_ptr = null, $search_parents = true, $error_enable = true)
310  {
311  if ($_ptr === null) {
312  $_ptr = $this;
313  }
314  while ($_ptr !== null) {
315  if (isset($_ptr->tpl_vars[$variable])) {
316  // found it, return it
317  return $_ptr->tpl_vars[$variable];
318  }
319  // not found, try at parent
320  if ($search_parents) {
321  $_ptr = $_ptr->parent;
322  } else {
323  $_ptr = null;
324  }
325  }
326  if (isset(Smarty::$global_tpl_vars[$variable])) {
327  // found it, return it
328  return Smarty::$global_tpl_vars[$variable];
329  }
330  $smarty = isset($this->smarty) ? $this->smarty : $this;
331  if ($smarty->error_unassigned && $error_enable) {
332  // force a notice
333  $x = $$variable;
334  }
335 
336  return new Smarty_Undefined_Variable;
337  }
338 
347  public function getConfigVariable($variable, $error_enable = true)
348  {
349  return Smarty_Internal_Extension_Config::getConfigVariable($this, $variable, $error_enable = true);
350  }
351 
360  public function getConfigVars($varname = null, $search_parents = true)
361  {
362  return Smarty_Internal_Extension_Config::getConfigVars($this, $varname, $search_parents);
363  }
364 
372  public function clearConfig($varname = null)
373  {
374  return Smarty_Internal_Extension_Config::clearConfig($this, $varname);
375  }
376 
385  public function getStreamVariable($variable)
386  {
387  $_result = '';
388  $fp = fopen($variable, 'r+');
389  if ($fp) {
390  while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
391  $_result .= $current_line;
392  }
393  fclose($fp);
394 
395  return $_result;
396  }
397  $smarty = isset($this->smarty) ? $this->smarty : $this;
398  if ($smarty->error_unassigned) {
399  throw new SmartyException('Undefined stream variable "' . $variable . '"');
400  } else {
401  return null;
402  }
403  }
404 }




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.