You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
3.4 KiB
PHTML
154 lines
3.4 KiB
PHTML
9 years ago
|
<?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
|
||
|
*
|
||
7 years ago
|
* @var integer|bool
|
||
9 years ago
|
*/
|
||
7 years ago
|
public $timestamp = false;
|
||
9 years ago
|
|
||
|
/**
|
||
|
* 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();
|
||
|
|
||
|
/**
|
||
|
* Content buffer
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
public $content = null;
|
||
|
|
||
|
/**
|
||
7 years ago
|
* Included sub templates
|
||
|
* - index name
|
||
|
* - value use count
|
||
9 years ago
|
*
|
||
7 years ago
|
* @var int[]
|
||
9 years ago
|
*/
|
||
|
public $includes = array();
|
||
|
|
||
7 years ago
|
/**
|
||
|
* Flag if this is a cache resource
|
||
|
*
|
||
|
* @var bool
|
||
|
*/
|
||
|
public $isCache = false;
|
||
|
|
||
9 years ago
|
/**
|
||
|
* Process resource
|
||
|
*
|
||
|
* @param Smarty_Internal_Template $_template template object
|
||
|
*/
|
||
|
abstract public function process(Smarty_Internal_Template $_template);
|
||
|
|
||
7 years ago
|
/**
|
||
9 years ago
|
* get rendered template content by calling compiled or cached template code
|
||
|
*
|
||
7 years ago
|
* @param \Smarty_Internal_Template $_template
|
||
|
* @param string $unifunc function with template code
|
||
9 years ago
|
*
|
||
|
* @throws \Exception
|
||
|
*/
|
||
|
public function getRenderedTemplateCode(Smarty_Internal_Template $_template, $unifunc = null)
|
||
|
{
|
||
7 years ago
|
$smarty = &$_template->smarty;
|
||
|
$_template->isRenderingCache = $this->isCache;
|
||
9 years ago
|
$level = ob_get_level();
|
||
|
try {
|
||
7 years ago
|
if (!isset($unifunc)) {
|
||
|
$unifunc = $this->unifunc;
|
||
9 years ago
|
}
|
||
7 years ago
|
if (empty($unifunc) || !function_exists($unifunc)) {
|
||
|
throw new SmartyException("Invalid compiled template for '{$_template->template_resource}'");
|
||
9 years ago
|
}
|
||
7 years ago
|
if ($_template->startRenderCallbacks) {
|
||
|
foreach ($_template->startRenderCallbacks as $callback) {
|
||
|
call_user_func($callback, $_template);
|
||
|
}
|
||
9 years ago
|
}
|
||
|
$unifunc($_template);
|
||
7 years ago
|
foreach ($_template->endRenderCallbacks as $callback) {
|
||
|
call_user_func($callback, $_template);
|
||
9 years ago
|
}
|
||
7 years ago
|
$_template->isRenderingCache = false;
|
||
9 years ago
|
}
|
||
|
catch (Exception $e) {
|
||
7 years ago
|
$_template->isRenderingCache = false;
|
||
9 years ago
|
while (ob_get_level() > $level) {
|
||
|
ob_end_clean();
|
||
|
}
|
||
7 years ago
|
if (isset($smarty->security_policy)) {
|
||
|
$smarty->security_policy->endTemplate();
|
||
9 years ago
|
}
|
||
|
throw $e;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Get compiled time stamp
|
||
|
*
|
||
|
* @return int
|
||
|
*/
|
||
|
public function getTimeStamp()
|
||
|
{
|
||
7 years ago
|
if ($this->exists && !$this->timestamp) {
|
||
|
$this->timestamp = filemtime($this->filepath);
|
||
9 years ago
|
}
|
||
|
return $this->timestamp;
|
||
|
}
|
||
|
}
|