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.
129 lines
3.6 KiB
PHTML
129 lines
3.6 KiB
PHTML
14 years ago
|
<?php
|
||
|
/**
|
||
11 years ago
|
* Smarty Internal Plugin Resource Extends
|
||
|
*
|
||
10 years ago
|
* @package Smarty
|
||
11 years ago
|
* @subpackage TemplateResources
|
||
10 years ago
|
* @author Uwe Tews
|
||
|
* @author Rodney Rehm
|
||
11 years ago
|
*/
|
||
14 years ago
|
|
||
|
/**
|
||
11 years ago
|
* Smarty Internal Plugin Resource Extends
|
||
|
* Implements the file system as resource for Smarty which {extend}s a chain of template files templates
|
||
|
*
|
||
10 years ago
|
* @package Smarty
|
||
11 years ago
|
* @subpackage TemplateResources
|
||
|
*/
|
||
|
class Smarty_Internal_Resource_Extends extends Smarty_Resource
|
||
|
{
|
||
|
/**
|
||
|
* mbstring.overload flag
|
||
|
*
|
||
|
* @var int
|
||
|
*/
|
||
|
public $mbstring_overload = 0;
|
||
14 years ago
|
|
||
|
/**
|
||
11 years ago
|
* populate Source Object with meta data from Resource
|
||
|
*
|
||
10 years ago
|
* @param Smarty_Template_Source $source source object
|
||
11 years ago
|
* @param Smarty_Internal_Template $_template template object
|
||
10 years ago
|
*
|
||
|
* @throws SmartyException
|
||
11 years ago
|
*/
|
||
|
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||
14 years ago
|
{
|
||
13 years ago
|
$uid = '';
|
||
|
$sources = array();
|
||
|
$components = explode('|', $source->name);
|
||
7 years ago
|
$smarty = &$source->smarty;
|
||
13 years ago
|
$exists = true;
|
||
|
foreach ($components as $component) {
|
||
9 years ago
|
/* @var \Smarty_Template_Source $_s */
|
||
7 years ago
|
$_s = Smarty_Template_Source::load(null, $smarty, $component);
|
||
7 years ago
|
if ($_s->type === 'php') {
|
||
9 years ago
|
throw new SmartyException("Resource type {$_s->type} cannot be used with the extends resource type");
|
||
13 years ago
|
}
|
||
9 years ago
|
$sources[ $_s->uid ] = $_s;
|
||
|
$uid .= $_s->filepath;
|
||
|
if ($_template) {
|
||
|
$exists = $exists && $_s->exists;
|
||
13 years ago
|
}
|
||
14 years ago
|
}
|
||
13 years ago
|
$source->components = $sources;
|
||
9 years ago
|
$source->filepath = $_s->filepath;
|
||
7 years ago
|
$source->uid = sha1($uid . $source->smarty->_joined_template_dir);
|
||
9 years ago
|
$source->exists = $exists;
|
||
|
if ($_template) {
|
||
|
$source->timestamp = $_s->timestamp;
|
||
13 years ago
|
}
|
||
|
}
|
||
14 years ago
|
|
||
|
/**
|
||
11 years ago
|
* populate Source Object with timestamp and exists from Resource
|
||
|
*
|
||
|
* @param Smarty_Template_Source $source source object
|
||
|
*/
|
||
13 years ago
|
public function populateTimestamp(Smarty_Template_Source $source)
|
||
14 years ago
|
{
|
||
13 years ago
|
$source->exists = true;
|
||
9 years ago
|
/* @var \Smarty_Template_Source $_s */
|
||
|
foreach ($source->components as $_s) {
|
||
|
$source->exists = $source->exists && $_s->exists;
|
||
13 years ago
|
}
|
||
9 years ago
|
$source->timestamp = $source->exists ? $_s->getTimeStamp() : false;
|
||
13 years ago
|
}
|
||
14 years ago
|
|
||
|
/**
|
||
11 years ago
|
* Load template's source from files into current template object
|
||
|
*
|
||
|
* @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)
|
||
14 years ago
|
{
|
||
13 years ago
|
if (!$source->exists) {
|
||
7 years ago
|
throw new SmartyException("Unable to load template '{$source->type}:{$source->name}'");
|
||
13 years ago
|
}
|
||
|
|
||
|
$_components = array_reverse($source->components);
|
||
|
|
||
11 years ago
|
$_content = '';
|
||
9 years ago
|
/* @var \Smarty_Template_Source $_s */
|
||
|
foreach ($_components as $_s) {
|
||
13 years ago
|
// read content
|
||
9 years ago
|
$_content .= $_s->getContent();
|
||
13 years ago
|
}
|
||
11 years ago
|
return $_content;
|
||
14 years ago
|
}
|
||
|
|
||
|
/**
|
||
11 years ago
|
* Determine basename for compiled filename
|
||
|
*
|
||
|
* @param Smarty_Template_Source $source source object
|
||
10 years ago
|
*
|
||
11 years ago
|
* @return string resource's basename
|
||
|
*/
|
||
13 years ago
|
public function getBasename(Smarty_Template_Source $source)
|
||
14 years ago
|
{
|
||
13 years ago
|
return str_replace(':', '.', basename($source->filepath));
|
||
|
}
|
||
9 years ago
|
|
||
|
/*
|
||
|
* Disable timestamp checks for extends resource.
|
||
|
* The individual source components will be checked.
|
||
|
*
|
||
|
* @return bool
|
||
|
*/
|
||
7 years ago
|
/**
|
||
|
* @return bool
|
||
|
*/
|
||
9 years ago
|
public function checkTimestamps()
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
13 years ago
|
}
|