1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/piwigo_ynh.git synced 2024-09-03 20:06:03 +02:00
piwigo_ynh/sources/include/smarty/libs/sysplugins/smarty_internal_templatebase.php

317 lines
11 KiB
PHP
Raw Normal View History

2014-07-06 13:21:10 +02:00
<?php
/**
* Smarty Internal Plugin Smarty Template Base
2016-08-27 21:53:29 +02:00
* This file contains the basic shared methods for template handling
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @package Smarty
2014-07-06 13:21:10 +02:00
* @subpackage Template
2016-08-27 21:53:29 +02:00
* @author Uwe Tews
2014-07-06 13:21:10 +02:00
*/
/**
2016-08-27 21:53:29 +02:00
* Class with shared template methods
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @package Smarty
* @subpackage Template
*
* @property Smarty $smarty
* @method Smarty_Internal_TemplateBase setAutoloadFilters(mixed $filters, string $type = null)
* @method Smarty_Internal_TemplateBase addAutoloadFilters(mixed $filters, string $type = null)
* @method array getAutoloadFilters(string $type = null)
* @local_method Smarty_Internal_TemplateBase registerFilter(string $type, callback $callback, string $name = null)
* @method Smarty_Internal_TemplateBase unregisterFilter(string $type, mixed $callback)
* @method Smarty_Internal_TemplateBase unloadFilter(string $type, string $name)
* @method string getDebugTemplate()
* @method Smarty_Internal_TemplateBase setDebugTemplate(string $tpl_name)
* @method Smarty_Internal_TemplateBase setDefaultModifier(mixed $modifiers)
* @method Smarty_Internal_TemplateBase addDefaultModifier(mixed $modifiers)
* @method array getDefaultModifier()
* @method Smarty_Internal_TemplateBase registerDefaultPluginHandler(callback $callback)
* @method Smarty_Internal_TemplateBase registerResource(string $name, Smarty_Resource $resource_handler)
* @method Smarty_Internal_TemplateBase unregisterResource(string $name)
* @method Smarty_Internal_TemplateBase registerCacheResource(string $name, Smarty_CacheResource $resource_handler)
* @method Smarty_Internal_TemplateBase unregisterCacheResource(string $name)
* @method Smarty_Internal_TemplateBase unregisterPlugin(string $type, string $name)
* @method Smarty_Internal_TemplateBase unregisterObject(string $object_name)
* @method object getRegisteredObject(string $object_name)
* @method Smarty_Internal_TemplateBase registerClass(string $class_name, string $class_impl)
* @method Smarty_Internal_TemplateBase createData(Smarty_Internal_Data $parent = null, string $name = null)
* @method array getTags(mixed $template = null)
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data
{
2014-07-06 13:21:10 +02:00
/**
2016-08-27 21:53:29 +02:00
* Set this if you want different sets of cache files for the same
* templates.
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @var string
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public $cache_id = null;
2014-07-06 13:21:10 +02:00
/**
2016-08-27 21:53:29 +02:00
* Set this if you want different sets of compiled files for the same
* templates.
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @var string
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public $compile_id = null;
2014-07-06 13:21:10 +02:00
/**
2016-08-27 21:53:29 +02:00
* caching enabled
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @var boolean
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public $caching = false;
2014-07-06 13:21:10 +02:00
/**
2016-08-27 21:53:29 +02:00
* cache lifetime in seconds
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @var integer
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public $cache_lifetime = 3600;
2014-07-06 13:21:10 +02:00
/**
2016-08-27 21:53:29 +02:00
* universal cache
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @var array()
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public $_cache = array();
2014-07-06 13:21:10 +02:00
/**
2016-08-27 21:53:29 +02:00
* fetches a rendered Smarty template
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @throws Exception
* @throws SmartyException
* @return string rendered template output
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function fetch($template = null, $cache_id = null, $compile_id = null, $parent = null)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
$result = $this->_execute($template, $cache_id, $compile_id, $parent, 0);
return $result === null ? ob_get_clean() : $result;
2014-07-06 13:21:10 +02:00
}
/**
2016-08-27 21:53:29 +02:00
* displays a Smarty template
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function display($template = null, $cache_id = null, $compile_id = null, $parent = null)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
// display template
$this->_execute($template, $cache_id, $compile_id, $parent, 1);
2014-07-06 13:21:10 +02:00
}
/**
2016-08-27 21:53:29 +02:00
* test if cache is valid
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @api Smarty::isCached()
* @link http://www.smarty.net/docs/en/api.is.cached.tpl
*
* @param null|string|\Smarty_Internal_Template $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @return boolean cache status
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function isCached($template = null, $cache_id = null, $compile_id = null, $parent = null)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
return $this->_execute($template, $cache_id, $compile_id, $parent, 2);
2014-07-06 13:21:10 +02:00
}
/**
2016-08-27 21:53:29 +02:00
* fetches a rendered Smarty template
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @param string $template the resource handle of the template file or template object
* @param mixed $cache_id cache id to be used with this template
* @param mixed $compile_id compile id to be used with this template
* @param object $parent next higher level of Smarty variables
* @param string $function function type 0 = fetch, 1 = display, 2 = isCache
*
* @return mixed
* @throws \Exception
* @throws \SmartyException
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
private function _execute($template, $cache_id, $compile_id, $parent, $function)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
$smarty = $this->_objType == 1 ? $this : $this->smarty;
if ($template === null) {
if ($this->_objType != 2) {
throw new SmartyException($function . '():Missing \'$template\' parameter');
} else {
$template = clone $this;
}
} elseif (is_object($template)) {
if (!isset($template->_objType) || $template->_objType != 2) {
throw new SmartyException($function . '():Template object expected');
} else {
/* @var Smarty_Internal_Template $template */
$template = clone $template;
}
} else {
// get template object
/* @var Smarty_Internal_Template $template */
$template = $smarty->createTemplate($template, $cache_id, $compile_id, $parent, false);
if ($this->_objType == 1) {
// set caching in template object
$template->caching = $this->caching;
2014-07-06 13:21:10 +02:00
}
}
2016-08-27 21:53:29 +02:00
// fetch template content
$level = ob_get_level();
try {
$_smarty_old_error_level =
($this->_objType == 1 && isset($smarty->error_reporting)) ? error_reporting($smarty->error_reporting) :
null;
if ($function == 2) {
if ($template->caching) {
// return cache status of template
if (!isset($template->cached)) {
$template->loadCached();
}
$result = $template->cached->isCached($template);
$template->smarty->_cache['isCached'][$template->_getTemplateId()] = $template;
} else {
return false;
}
} else {
ob_start();
$template->_mergeVars();
if (!empty(Smarty::$global_tpl_vars)) {
$template->tpl_vars = array_merge(Smarty::$global_tpl_vars, $template->tpl_vars);
2014-07-06 13:21:10 +02:00
}
2016-08-27 21:53:29 +02:00
$result = $template->render(false, $function);
2014-07-06 13:21:10 +02:00
}
2016-08-27 21:53:29 +02:00
if (isset($_smarty_old_error_level)) {
error_reporting($_smarty_old_error_level);
}
return $result;
2014-07-06 13:21:10 +02:00
}
2016-08-27 21:53:29 +02:00
catch (Exception $e) {
while (ob_get_level() > $level) {
ob_end_clean();
}
throw $e;
2014-07-06 13:21:10 +02:00
}
}
/**
2016-08-27 21:53:29 +02:00
* Registers plugin to be used in templates
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @api Smarty::registerPlugin()
* @link http://www.smarty.net/docs/en/api.register.plugin.tpl
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @param string $type plugin type
* @param string $name name of template tag
* @param callback $callback PHP callback to register
* @param bool $cacheable if true (default) this function is cache able
* @param mixed $cache_attr caching attributes if any
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @return \Smarty|\Smarty_Internal_Template
* @throws SmartyException when the plugin tag is invalid
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function registerPlugin($type, $name, $callback, $cacheable = true, $cache_attr = null)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
return $this->ext->registerPlugin->registerPlugin($this, $type, $name, $callback, $cacheable, $cache_attr);
2014-07-06 13:21:10 +02:00
}
/**
2016-08-27 21:53:29 +02:00
* load a filter of specified type and name
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @api Smarty::loadFilter()
* @link http://www.smarty.net/docs/en/api.load.filter.tpl
*
* @param string $type filter type
* @param string $name filter name
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @return bool
* @throws SmartyException if filter could not be loaded
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function loadFilter($type, $name)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
return $this->ext->loadFilter->loadFilter($this, $type, $name);
2014-07-06 13:21:10 +02:00
}
/**
* Registers a filter function
*
2016-08-27 21:53:29 +02:00
* @api Smarty::registerFilter()
* @link http://www.smarty.net/docs/en/api.register.filter.tpl
*
* @param string $type filter type
* @param callback $callback
* @param string|null $name optional filter name
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function registerFilter($type, $callback, $name = null)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
return $this->ext->registerFilter->registerFilter($this, $type, $callback, $name);
2014-07-06 13:21:10 +02:00
}
/**
2016-08-27 21:53:29 +02:00
* Registers object to be used in templates
2014-07-06 13:21:10 +02:00
*
2016-08-27 21:53:29 +02:00
* @api Smarty::registerObject()
* @link http://www.smarty.net/docs/en/api.register.object.tpl
*
* @param string $object_name
* @param object $object the referenced PHP object to register
* @param array $allowed_methods_properties list of allowed methods (empty = all)
* @param bool $format smarty argument format, else traditional
* @param array $block_methods list of block-methods
*
* @return \Smarty|\Smarty_Internal_Template
* @throws \SmartyException
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function registerObject($object_name, $object, $allowed_methods_properties = array(), $format = true,
$block_methods = array())
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
return $this->ext->registerObject->registerObject($this, $object_name, $object, $allowed_methods_properties,
$format, $block_methods);
2014-07-06 13:21:10 +02:00
}
/**
2016-08-27 21:53:29 +02:00
* @param boolean $caching
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function setCaching($caching)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
$this->caching = $caching;
2014-07-06 13:21:10 +02:00
}
/**
2016-08-27 21:53:29 +02:00
* @param int $cache_lifetime
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function setCacheLifetime($cache_lifetime)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
$this->cache_lifetime = $cache_lifetime;
2014-07-06 13:21:10 +02:00
}
/**
2016-08-27 21:53:29 +02:00
* @param string $compile_id
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function setCompileId($compile_id)
{
$this->compile_id = $compile_id;
2014-07-06 13:21:10 +02:00
}
/**
2016-08-27 21:53:29 +02:00
* @param string $cache_id
2014-07-06 13:21:10 +02:00
*/
2016-08-27 21:53:29 +02:00
public function setCacheId($cache_id)
2014-07-06 13:21:10 +02:00
{
2016-08-27 21:53:29 +02:00
$this->cache_id = $cache_id;
2014-07-06 13:21:10 +02:00
}
}