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.
96 lines
2.9 KiB
PHTML
96 lines
2.9 KiB
PHTML
13 years ago
|
<?php
|
||
|
/**
|
||
|
* Smarty Resource Plugin
|
||
|
*
|
||
10 years ago
|
* @package Smarty
|
||
13 years ago
|
* @subpackage TemplateResources
|
||
10 years ago
|
* @author Rodney Rehm
|
||
13 years ago
|
*/
|
||
|
|
||
|
/**
|
||
|
* Smarty Resource Plugin
|
||
|
* Wrapper Implementation for custom resource plugins
|
||
|
*
|
||
10 years ago
|
* @package Smarty
|
||
13 years ago
|
* @subpackage TemplateResources
|
||
|
*/
|
||
11 years ago
|
abstract class Smarty_Resource_Custom extends Smarty_Resource
|
||
|
{
|
||
13 years ago
|
/**
|
||
|
* fetch template and its modification time from data source
|
||
|
*
|
||
|
* @param string $name template name
|
||
|
* @param string &$source template source
|
||
|
* @param integer &$mtime template modification timestamp (epoch)
|
||
|
*/
|
||
11 years ago
|
abstract protected function fetch($name, &$source, &$mtime);
|
||
13 years ago
|
|
||
|
/**
|
||
|
* Fetch template's modification timestamp from data source
|
||
|
* {@internal implementing this method is optional.
|
||
|
* Only implement it if modification times can be accessed faster than loading the complete template source.}}
|
||
|
*
|
||
10 years ago
|
* @param string $name template name
|
||
|
*
|
||
13 years ago
|
* @return integer|boolean timestamp (epoch) the template was modified, or false if not found
|
||
|
*/
|
||
|
protected function fetchTimestamp($name)
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* populate Source Object with meta data from Resource
|
||
|
*
|
||
|
* @param Smarty_Template_Source $source source object
|
||
|
* @param Smarty_Internal_Template $_template template object
|
||
|
*/
|
||
10 years ago
|
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||
13 years ago
|
{
|
||
7 years ago
|
$source->filepath = $source->type . ':' . substr(preg_replace('/[^A-Za-z0-9.]/','',$source->name),0,25);
|
||
13 years ago
|
$source->uid = sha1($source->type . ':' . $source->name);
|
||
|
|
||
|
$mtime = $this->fetchTimestamp($source->name);
|
||
|
if ($mtime !== null) {
|
||
|
$source->timestamp = $mtime;
|
||
|
} else {
|
||
|
$this->fetch($source->name, $content, $timestamp);
|
||
|
$source->timestamp = isset($timestamp) ? $timestamp : false;
|
||
10 years ago
|
if (isset($content)) {
|
||
13 years ago
|
$source->content = $content;
|
||
10 years ago
|
}
|
||
13 years ago
|
}
|
||
|
$source->exists = !!$source->timestamp;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Load template's source into current template object
|
||
|
*
|
||
11 years ago
|
* @param Smarty_Template_Source $source source object
|
||
10 years ago
|
*
|
||
11 years ago
|
* @return string template source
|
||
|
* @throws SmartyException if source cannot be loaded
|
||
13 years ago
|
*/
|
||
|
public function getContent(Smarty_Template_Source $source)
|
||
|
{
|
||
|
$this->fetch($source->name, $content, $timestamp);
|
||
|
if (isset($content)) {
|
||
|
return $content;
|
||
|
}
|
||
|
|
||
|
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Determine basename for compiled filename
|
||
|
*
|
||
11 years ago
|
* @param Smarty_Template_Source $source source object
|
||
10 years ago
|
*
|
||
11 years ago
|
* @return string resource's basename
|
||
13 years ago
|
*/
|
||
9 years ago
|
public function getBasename(Smarty_Template_Source $source)
|
||
13 years ago
|
{
|
||
7 years ago
|
return basename(substr(preg_replace('/[^A-Za-z0-9.]/','',$source->name),0,25));
|
||
13 years ago
|
}
|
||
|
}
|