2012-07-04 07:23:08 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Smarty Resource Plugin
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @package Smarty
|
2012-07-04 07:23:08 +02:00
|
|
|
* @subpackage TemplateResources
|
2014-09-07 13:38:28 +02:00
|
|
|
* @author Rodney Rehm
|
2012-07-04 07:23:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Smarty Resource Plugin
|
|
|
|
* Wrapper Implementation for custom resource plugins
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @package Smarty
|
2012-07-04 07:23:08 +02:00
|
|
|
* @subpackage TemplateResources
|
|
|
|
*/
|
2014-09-07 13:38:28 +02:00
|
|
|
abstract class Smarty_Resource_Custom extends Smarty_Resource
|
|
|
|
{
|
2012-07-04 07:23:08 +02:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
*/
|
2014-09-07 13:38:28 +02:00
|
|
|
abstract protected function fetch($name, &$source, &$mtime);
|
2012-07-04 07:23:08 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.}}
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @param string $name template name
|
|
|
|
*
|
2012-07-04 07:23:08 +02:00
|
|
|
* @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
|
|
|
|
*/
|
2014-09-07 13:38:28 +02:00
|
|
|
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
2012-07-04 07:23:08 +02:00
|
|
|
{
|
2014-09-07 13:38:28 +02:00
|
|
|
$source->filepath = $source->type . ':' . $source->name;
|
2012-07-04 07:23:08 +02:00
|
|
|
$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;
|
2014-09-07 13:38:28 +02:00
|
|
|
if (isset($content)) {
|
2012-07-04 07:23:08 +02:00
|
|
|
$source->content = $content;
|
2014-09-07 13:38:28 +02:00
|
|
|
}
|
2012-07-04 07:23:08 +02:00
|
|
|
}
|
|
|
|
$source->exists = !!$source->timestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load template's source into current template object
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @param Smarty_Template_Source $source source object
|
|
|
|
*
|
|
|
|
* @return string template source
|
|
|
|
* @throws SmartyException if source cannot be loaded
|
2012-07-04 07:23:08 +02:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*
|
2014-09-07 13:38:28 +02:00
|
|
|
* @param Smarty_Template_Source $source source object
|
|
|
|
*
|
|
|
|
* @return string resource's basename
|
2012-07-04 07:23:08 +02:00
|
|
|
*/
|
|
|
|
protected function getBasename(Smarty_Template_Source $source)
|
|
|
|
{
|
|
|
|
return basename($source->name);
|
|
|
|
}
|
|
|
|
}
|