Files
smarty/libs/sysplugins/smarty_template_resource_base.php

153 lines
3.4 KiB
PHP
Raw Permalink Normal View History

<?php
/**
* Smarty Template Resource Base Object
*
* @package Smarty
* @subpackage TemplateResources
* @author Rodney Rehm
*/
abstract class Smarty_Template_Resource_Base
{
/**
* Compiled Filepath
*
* @var string
*/
public $filepath = null;
/**
* Compiled Timestamp
*
* @var integer|bool
*/
public $timestamp = false;
/**
* Compiled Existence
*
* @var boolean
*/
public $exists = false;
/**
* Template Compile Id (Smarty_Internal_Template::$compile_id)
*
* @var string
*/
public $compile_id = null;
/**
* Compiled Content Loaded
*
* @var boolean
*/
public $processed = false;
/**
* unique function name for compiled template code
*
* @var string
*/
public $unifunc = '';
/**
* flag if template does contain nocache code sections
*
* @var bool
*/
public $has_nocache_code = false;
/**
* resource file dependency
*
* @var array
*/
public $file_dependency = array();
/**
2015-08-15 18:25:06 +02:00
* Content buffer
*
2015-08-15 18:25:06 +02:00
* @var string
*/
2015-08-15 18:25:06 +02:00
public $content = null;
/**
* Included sub templates
* - index name
* - value use count
*
* @var int[]
*/
public $includes = array();
2016-03-10 22:22:46 +01:00
/**
* Flag if this is a cache resource
*
* @var bool
*/
public $isCache = false;
/**
* Process resource
*
* @param Smarty_Internal_Template $_template template object
*/
abstract public function process(Smarty_Internal_Template $_template);
2015-12-27 08:12:46 +01:00
/**
2015-08-23 01:25:57 +02:00
* get rendered template content by calling compiled or cached template code
*
2015-12-27 08:12:46 +01:00
* @param \Smarty_Internal_Template $_template
* @param string $unifunc function with template code
*
2015-08-23 01:25:57 +02:00
* @throws \Exception
*/
2015-08-23 01:25:57 +02:00
public function getRenderedTemplateCode(Smarty_Internal_Template $_template, $unifunc = null)
{
2016-03-10 22:22:46 +01:00
$smarty = &$_template->smarty;
$_template->isRenderingCache = $this->isCache;
2015-08-23 01:25:57 +02:00
$level = ob_get_level();
try {
2016-03-10 22:22:46 +01:00
if (!isset($unifunc)) {
$unifunc = $this->unifunc;
}
if (empty($unifunc) || !function_exists($unifunc)) {
2015-08-23 01:25:57 +02:00
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
}
if ($_template->startRenderCallbacks) {
foreach ($_template->startRenderCallbacks as $callback) {
call_user_func($callback, $_template);
}
}
2015-08-23 01:25:57 +02:00
$unifunc($_template);
foreach ($_template->endRenderCallbacks as $callback) {
call_user_func($callback, $_template);
2015-08-23 01:25:57 +02:00
}
$_template->isRenderingCache = false;
} catch (Exception $e) {
$_template->isRenderingCache = false;
2015-08-23 01:25:57 +02:00
while (ob_get_level() > $level) {
ob_end_clean();
}
2016-03-10 22:22:46 +01:00
if (isset($smarty->security_policy)) {
$smarty->security_policy->endTemplate();
2015-08-23 01:25:57 +02:00
}
throw $e;
}
}
/**
* Get compiled time stamp
*
* @return int
*/
public function getTimeStamp()
{
if ($this->exists && !$this->timestamp) {
2016-03-11 01:07:26 +01:00
$this->timestamp = filemtime($this->filepath);
}
return $this->timestamp;
}
}