libs/sysplugins/smarty_internal_templatebase.php Quellcode

smarty_internal_templatebase.php
gehe zur Dokumentation dieser Datei
1 <?php
18 {
25  public $cache_id = null;
32  public $compile_id = null;
38  public $caching = false;
44  public $cache_lifetime = 3600;
45 
56  public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
57  {
58  if ($template === null && $this instanceof $this->template_class) {
59  $template = $this;
60  } else {
61  if (!($template instanceof $this->template_class)) {
62  if ($parent === null) {
63  $parent = $this;
64  }
65  $smarty = isset($this->smarty) ? $this->smarty : $this;
66  $template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
67  }
68  }
69  // return cache status of template
70  if (!isset($template->cached)) {
71  $template->loadCached();
72  }
73  return $template->cached->isCached($template);
74  }
75 
84  public function createData($parent = null, $name = null)
85  {
86  $dataObj = new Smarty_Data($parent, $this, $name);
87  if ($this->debugging) {
89  }
90  return $dataObj;
91  }
92 
102  public function getTemplateId($template_name, $cache_id = null, $compile_id = null)
103  {
106  $smarty = isset($this->smarty) ? $this->smarty : $this;
107  if ($smarty->allow_ambiguous_resources) {
108  $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template_name) . "#{$cache_id}#{$compile_id}";
109  } else {
110  $_templateId = $smarty->joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}";
111  }
112  if (isset($_templateId[150])) {
113  $_templateId = sha1($_templateId);
114  }
115  return $_templateId;
116  }
117 
131  public function registerPlugin($type, $tag, $callback, $cacheable = true, $cache_attr = null)
132  {
133  $smarty = isset($this->smarty) ? $this->smarty : $this;
134  if (isset($smarty->registered_plugins[$type][$tag])) {
135  throw new SmartyException("Plugin tag \"{$tag}\" already registered");
136  } elseif (!is_callable($callback)) {
137  throw new SmartyException("Plugin \"{$tag}\" not callable");
138  } else {
139  $smarty->registered_plugins[$type][$tag] = array($callback, (bool) $cacheable, (array) $cache_attr);
140  }
141 
142  return $this;
143  }
144 
154  public function unregisterPlugin($type, $tag)
155  {
156  $smarty = isset($this->smarty) ? $this->smarty : $this;
157  if (isset($smarty->registered_plugins[$type][$tag])) {
158  unset($smarty->registered_plugins[$type][$tag]);
159  }
160 
161  return $this;
162  }
163 
174  public function registerResource($type, $callback)
175  {
176  $smarty = isset($this->smarty) ? $this->smarty : $this;
177  $smarty->registered_resources[$type] = $callback instanceof Smarty_Resource ? $callback : array($callback, false);
178 
179  return $this;
180  }
181 
190  public function unregisterResource($type)
191  {
192  $smarty = isset($this->smarty) ? $this->smarty : $this;
193  if (isset($smarty->registered_resources[$type])) {
194  unset($smarty->registered_resources[$type]);
195  }
196 
197  return $this;
198  }
199 
209  public function registerCacheResource($type, Smarty_CacheResource $callback)
210  {
211  $smarty = isset($this->smarty) ? $this->smarty : $this;
212  $smarty->registered_cache_resources[$type] = $callback;
213 
214  return $this;
215  }
216 
225  public function unregisterCacheResource($type)
226  {
227  $smarty = isset($this->smarty) ? $this->smarty : $this;
228  if (isset($smarty->registered_cache_resources[$type])) {
229  unset($smarty->registered_cache_resources[$type]);
230  }
231 
232  return $this;
233  }
234 
248  public function registerObject($object_name, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array())
249  {
250  // test if allowed methods callable
251  if (!empty($allowed)) {
252  foreach ((array) $allowed as $method) {
253  if (!is_callable(array($object_impl, $method)) && !property_exists($object_impl, $method)) {
254  throw new SmartyException("Undefined method or property '$method' in registered object");
255  }
256  }
257  }
258  // test if block methods callable
259  if (!empty($block_methods)) {
260  foreach ((array) $block_methods as $method) {
261  if (!is_callable(array($object_impl, $method))) {
262  throw new SmartyException("Undefined method '$method' in registered object");
263  }
264  }
265  }
266  // register the object
267  $smarty = isset($this->smarty) ? $this->smarty : $this;
268  $smarty->registered_objects[$object_name] =
269  array($object_impl, (array) $allowed, (boolean) $smarty_args, (array) $block_methods);
270 
271  return $this;
272  }
273 
282  public function getRegisteredObject($name)
283  {
284  $smarty = isset($this->smarty) ? $this->smarty : $this;
285  if (!isset($smarty->registered_objects[$name])) {
286  throw new SmartyException("'$name' is not a registered object");
287  }
288  if (!is_object($smarty->registered_objects[$name][0])) {
289  throw new SmartyException("registered '$name' is not an object");
290  }
291 
292  return $smarty->registered_objects[$name][0];
293  }
294 
303  public function unregisterObject($name)
304  {
305  $smarty = isset($this->smarty) ? $this->smarty : $this;
306  if (isset($smarty->registered_objects[$name])) {
307  unset($smarty->registered_objects[$name]);
308  }
309 
310  return $this;
311  }
312 
323  public function registerClass($class_name, $class_impl)
324  {
325  // test if exists
326  if (!class_exists($class_impl)) {
327  throw new SmartyException("Undefined class '$class_impl' in register template class");
328  }
329  // register the class
330  $smarty = isset($this->smarty) ? $this->smarty : $this;
331  $smarty->registered_classes[$class_name] = $class_impl;
332 
333  return $this;
334  }
335 
345  public function registerDefaultPluginHandler($callback)
346  {
347  $smarty = isset($this->smarty) ? $this->smarty : $this;
348  if (is_callable($callback)) {
349  $smarty->default_plugin_handler_func = $callback;
350  } else {
351  throw new SmartyException("Default plugin handler '$callback' not callable");
352  }
353 
354  return $this;
355  }
356 
366  public function registerDefaultTemplateHandler($callback)
367  {
369  return $this;
370  }
371 
381  public function registerDefaultConfigHandler($callback)
382  {
384  return $this;
385  }
386 
396  public function registerFilter($type, $callback)
397  {
398  $smarty = isset($this->smarty) ? $this->smarty : $this;
399  $smarty->registered_filters[$type][$this->_get_filter_name($callback)] = $callback;
400 
401  return $this;
402  }
403 
413  public function unregisterFilter($type, $callback)
414  {
415  $name = $this->_get_filter_name($callback);
416  $smarty = isset($this->smarty) ? $this->smarty : $this;
417  if (isset($smarty->registered_filters[$type][$name])) {
418  unset($smarty->registered_filters[$type][$name]);
419  }
420 
421  return $this;
422  }
423 
431  public function _get_filter_name($function_name)
432  {
433  if (is_array($function_name)) {
434  $_class_name = (is_object($function_name[0]) ?
435  get_class($function_name[0]) : $function_name[0]);
436 
437  return $_class_name . '_' . $function_name[1];
438  } else {
439  return $function_name;
440  }
441  }
442 
451  public function loadFilter($type, $name)
452  {
453  $smarty = isset($this->smarty) ? $this->smarty : $this;
454  $_plugin = "smarty_{$type}filter_{$name}";
455  $_filter_name = $_plugin;
456  if ($smarty->loadPlugin($_plugin)) {
457  if (class_exists($_plugin, false)) {
458  $_plugin = array($_plugin, 'execute');
459  }
460  if (is_callable($_plugin)) {
461  $smarty->registered_filters[$type][$_filter_name] = $_plugin;
462 
463  return true;
464  }
465  }
466  throw new SmartyException("{$type}filter \"{$name}\" not callable");
467  }
468 
478  public function unloadFilter($type, $name)
479  {
480  $smarty = isset($this->smarty) ? $this->smarty : $this;
481  $_filter_name = "smarty_{$type}filter_{$name}";
482  if (isset($smarty->registered_filters[$type][$_filter_name])) {
483  unset ($smarty->registered_filters[$type][$_filter_name]);
484  }
485 
486  return $this;
487  }
488 
496  private function replaceCamelcase($match)
497  {
498  return "_" . strtolower($match[1]);
499  }
500 
509  public function __call($name, $args)
510  {
511  static $_prefixes = array('set' => true, 'get' => true);
512  static $_resolved_property_name = array();
513  static $_resolved_property_source = array();
514 
515  // see if this is a set/get for a property
516  $first3 = strtolower(substr($name, 0, 3));
517  if (isset($_prefixes[$first3]) && isset($name[3]) && $name[3] !== '_') {
518  if (isset($_resolved_property_name[$name])) {
519  $property_name = $_resolved_property_name[$name];
520  } else {
521  // try to keep case correct for future PHP 6.0 case-sensitive class methods
522  // lcfirst() not available < PHP 5.3.0, so improvise
523  $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
524  // convert camel case to underscored name
525  $property_name = preg_replace_callback('/([A-Z])/', array($this, 'replaceCamelcase'), $property_name);
526  $_resolved_property_name[$name] = $property_name;
527  }
528  if (isset($_resolved_property_source[$property_name])) {
529  $status = $_resolved_property_source[$property_name];
530  } else {
531  $status = null;
532  if (property_exists($this, $property_name)) {
533  $status = true;
534  } elseif (property_exists($this->smarty, $property_name)) {
535  $status = false;
536  }
537  $_resolved_property_source[$property_name] = $status;
538  }
539  $smarty = null;
540  if ($status === true) {
541  $smarty = $this;
542  } elseif ($status === false) {
543  $smarty = $this->smarty;
544  }
545  if ($smarty) {
546  if ($first3 == 'get') {
547  return $smarty->$property_name;
548  } else {
549  return $smarty->$property_name = $args[0];
550  }
551  }
552  throw new SmartyException("property '$property_name' does not exist.");
553  }
554  throw new SmartyException("Call of unknown method '$name'.");
555  }
556 }
557 




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.