mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-02 17:34:26 +02:00
smarty_internal_resource_* to PSR-4
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
* @package Resource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
|
||||
class Smarty_Resource_Extendsall extends \Smarty\Resource\ExtendsPlugin
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
@@ -25,7 +25,7 @@ class Smarty_Resource_Extendsall extends Smarty_Internal_Resource_Extends
|
||||
$timestamp = 0;
|
||||
foreach ($source->smarty->getTemplateDir() as $key => $directory) {
|
||||
try {
|
||||
$s = Smarty_Resource::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name);
|
||||
$s = Smarty\Resource\BasePlugin::source(null, $source->smarty, 'file:' . '[' . $key . ']' . $source->name);
|
||||
if (!$s->exists) {
|
||||
continue;
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Smarty\Resource\CustomPlugin;
|
||||
|
||||
/**
|
||||
* MySQL Resource
|
||||
* Resource Implementation based on the Custom API to use
|
||||
@@ -19,7 +21,7 @@
|
||||
* @package Resource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Resource_Mysql extends Smarty_Resource_Custom
|
||||
class _MysqlPlugin extends CustomPlugin
|
||||
{
|
||||
/**
|
||||
* PDO instance
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Smarty\Resource\CustomPlugin;
|
||||
|
||||
/**
|
||||
* MySQL Resource
|
||||
* Resource Implementation based on the Custom API to use
|
||||
@@ -21,7 +23,7 @@
|
||||
* @package Resource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Resource_Mysqls extends Smarty_Resource_Custom
|
||||
class _MysqlsPlugin extends CustomPlugin
|
||||
{
|
||||
/**
|
||||
* PDO instance
|
||||
|
@@ -26,7 +26,7 @@ class Assign extends CompileBase
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $option_flags = array('nocache', 'noscope');
|
||||
|
||||
|
@@ -23,7 +23,7 @@ class Block extends Inheritance {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
public $required_attributes = ['name'];
|
||||
|
||||
@@ -31,7 +31,7 @@ class Block extends Inheritance {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
public $shorttag_order = ['name'];
|
||||
|
||||
@@ -39,7 +39,7 @@ class Block extends Inheritance {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $option_flags = ['hide', 'nocache'];
|
||||
|
||||
@@ -47,7 +47,7 @@ class Block extends Inheritance {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
public $optional_attributes = ['assign'];
|
||||
|
||||
|
@@ -22,7 +22,7 @@ class BreakTag extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $optional_attributes = ['levels'];
|
||||
|
||||
@@ -30,7 +30,7 @@ class BreakTag extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $shorttag_order = ['levels'];
|
||||
|
||||
|
@@ -14,7 +14,7 @@ class Capture extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
public $shorttag_order = ['name'];
|
||||
|
||||
@@ -22,7 +22,7 @@ class Capture extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
public $optional_attributes = ['name', 'assign', 'append'];
|
||||
|
||||
|
@@ -23,7 +23,7 @@ class Child extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $optional_attributes = ['assign'];
|
||||
|
||||
|
@@ -25,7 +25,7 @@ class ConfigLoad extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $required_attributes = ['file'];
|
||||
|
||||
@@ -33,7 +33,7 @@ class ConfigLoad extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $shorttag_order = ['file', 'section'];
|
||||
|
||||
@@ -41,7 +41,7 @@ class ConfigLoad extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $optional_attributes = ['section', 'scope'];
|
||||
|
||||
@@ -49,7 +49,7 @@ class ConfigLoad extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $option_flags = ['nocache', 'noscope'];
|
||||
|
||||
|
@@ -25,7 +25,7 @@ class ExtendsTag extends Inheritance {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $required_attributes = ['file'];
|
||||
|
||||
@@ -41,7 +41,7 @@ class ExtendsTag extends Inheritance {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $shorttag_order = ['file'];
|
||||
|
||||
|
@@ -16,7 +16,7 @@ class ForeachTag extends ForeachSection {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $required_attributes = ['from', 'item'];
|
||||
|
||||
@@ -24,7 +24,7 @@ class ForeachTag extends ForeachSection {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $optional_attributes = ['name', 'key', 'properties'];
|
||||
|
||||
@@ -32,7 +32,7 @@ class ForeachTag extends ForeachSection {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $shorttag_order = ['from', 'item', 'key', 'name'];
|
||||
|
||||
|
@@ -16,7 +16,7 @@ class FunctionTag extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $required_attributes = ['name'];
|
||||
|
||||
@@ -24,7 +24,7 @@ class FunctionTag extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $shorttag_order = ['name'];
|
||||
|
||||
@@ -32,7 +32,7 @@ class FunctionTag extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $optional_attributes = ['_any'];
|
||||
|
||||
|
@@ -13,8 +13,7 @@ namespace Smarty\Compile;
|
||||
use Smarty\Compiler\Template;
|
||||
use Smarty\Smarty;
|
||||
use Smarty_Internal_Template;
|
||||
use Smarty\Compiler\Template;
|
||||
use Smarty_Resource;
|
||||
use Smarty\Compile\Base;
|
||||
use Smarty_Template_Compiled;
|
||||
|
||||
/**
|
||||
@@ -95,7 +94,7 @@ class IncludeTag extends Base {
|
||||
if (preg_match('/^([\'"])(([A-Za-z0-9_\-]{2,})[:])?(([^$()]+)|(.+))\1$/', $source_resource, $match)) {
|
||||
$type = !empty($match[3]) ? $match[3] : $compiler->template->smarty->default_resource_type;
|
||||
$name = !empty($match[5]) ? $match[5] : $match[6];
|
||||
$handler = Smarty_Resource::load($compiler->smarty, $type);
|
||||
$handler = \Smarty\Resource\BasePlugin::load($compiler->smarty, $type);
|
||||
if ($handler->recompiled || $handler->uncompiled) {
|
||||
$variable_template = true;
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ class Insert extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $required_attributes = ['name'];
|
||||
|
||||
@@ -33,7 +33,7 @@ class Insert extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $shorttag_order = ['name'];
|
||||
|
||||
@@ -41,7 +41,7 @@ class Insert extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $optional_attributes = ['_any'];
|
||||
|
||||
|
@@ -24,7 +24,7 @@ class PrivateBlockPlugin extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $optional_attributes = ['_any'];
|
||||
|
||||
|
@@ -24,7 +24,7 @@ class PrivateObjectFunction extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $optional_attributes = ['_any'];
|
||||
|
||||
|
@@ -25,7 +25,7 @@ class PrivateRegisteredFunction extends Base {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
public $optional_attributes = ['_any'];
|
||||
|
||||
|
@@ -16,7 +16,7 @@ class Section extends ForeachSection {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $required_attributes = ['name', 'loop'];
|
||||
|
||||
@@ -24,7 +24,7 @@ class Section extends ForeachSection {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $shorttag_order = ['name', 'loop'];
|
||||
|
||||
@@ -32,7 +32,7 @@ class Section extends ForeachSection {
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
* @var array
|
||||
* @see Base
|
||||
* @see BasePlugin
|
||||
*/
|
||||
protected $optional_attributes = ['start', 'step', 'max', 'show', 'properties'];
|
||||
|
||||
|
@@ -21,7 +21,7 @@ namespace Smarty\Resource;
|
||||
* @method populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
* @method process(Smarty_Internal_Template $_smarty_tpl)
|
||||
*/
|
||||
abstract class Base
|
||||
abstract class BasePlugin
|
||||
{
|
||||
/**
|
||||
* resource types provided by the core
|
||||
@@ -31,7 +31,7 @@ abstract class Base
|
||||
public static $sysplugins = array(
|
||||
'file' => File::class,
|
||||
'string' => String::class,
|
||||
'extends' => Extending::class,
|
||||
'extends' => ExtendsPlugin::class,
|
||||
'stream' => Stream::class,
|
||||
'eval' => StringEval::class,
|
||||
'php' => Php::class,
|
||||
@@ -65,7 +65,7 @@ abstract class Base
|
||||
* @param string $type name of the resource
|
||||
*
|
||||
* @throws \SmartyException
|
||||
* @return Base Resource Handler
|
||||
* @return BasePlugin Resource Handler
|
||||
*/
|
||||
public static function load(\Smarty $smarty, $type)
|
||||
{
|
||||
@@ -148,9 +148,9 @@ abstract class Base
|
||||
public static function getUniqueTemplateName($obj, $template_resource)
|
||||
{
|
||||
$smarty = $obj->_getSmartyObj();
|
||||
list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
|
||||
[$name, $type] = self::parseResourceName($template_resource, $smarty->default_resource_type);
|
||||
// TODO: optimize for Smarty's internal resource types
|
||||
$resource = Base::load($smarty, $type);
|
||||
$resource = BasePlugin::load($smarty, $type);
|
||||
// go relative to a given template?
|
||||
$_file_is_dotted = $name[ 0 ] === '.' && ($name[ 1 ] === '.' || $name[ 1 ] === '/');
|
||||
if ($obj->_isTplObj() && $_file_is_dotted
|
106
src/Resource/CustomPlugin.php
Normal file
106
src/Resource/CustomPlugin.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
namespace Smarty\Resource;
|
||||
use Smarty;
|
||||
use Smarty_Internal_Template;
|
||||
use Smarty_Template_Source;
|
||||
use SmartyException;
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Wrapper Implementation for custom resource plugins
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
abstract class CustomPlugin extends Smarty\Resource\BasePlugin {
|
||||
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
abstract protected function fetch($name, &$source, &$mtime);
|
||||
|
||||
/**
|
||||
* 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.}}
|
||||
*
|
||||
* @param string $name template name
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
||||
$source->filepath = $source->type . ':' . $this->generateSafeName($source->name);
|
||||
$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;
|
||||
if (isset($content)) {
|
||||
$source->content = $content;
|
||||
}
|
||||
}
|
||||
$source->exists = !!$source->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source) {
|
||||
return basename($this->generateSafeName($source->name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes special characters from $name and limits its length to 127 characters.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateSafeName($name): string {
|
||||
return substr(preg_replace('/[^A-Za-z0-9._]/', '', (string)$name), 0, 127);
|
||||
}
|
||||
}
|
@@ -18,7 +18,7 @@ namespace Smarty\Resource;
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class Extending extends Base
|
||||
class ExtendsPlugin extends BasePlugin
|
||||
{
|
||||
|
||||
/**
|
179
src/Resource/FilePlugin.php
Normal file
179
src/Resource/FilePlugin.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource File
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
namespace Smarty\Resource;
|
||||
use Smarty;
|
||||
use Smarty_Internal_Template;
|
||||
use Smarty_Template_Source;
|
||||
use SmartyException;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource File
|
||||
* Implements the file system as resource for Smarty templates
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class FilePlugin extends Smarty\Resource\BasePlugin {
|
||||
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
||||
$source->filepath = $this->buildFilepath($source, $_template);
|
||||
if ($source->filepath !== false) {
|
||||
if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) {
|
||||
$source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig);
|
||||
}
|
||||
$source->exists = true;
|
||||
$source->uid = sha1(
|
||||
$source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir :
|
||||
$source->smarty->_joined_template_dir)
|
||||
);
|
||||
$source->timestamp = filemtime($source->filepath);
|
||||
} else {
|
||||
$source->timestamp = $source->exists = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Source Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Source $source) {
|
||||
if (!$source->exists) {
|
||||
$source->timestamp = $source->exists = is_file($source->filepath);
|
||||
}
|
||||
if ($source->exists) {
|
||||
$source->timestamp = filemtime($source->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from file into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source) {
|
||||
if ($source->exists) {
|
||||
return file_get_contents($source->filepath);
|
||||
}
|
||||
throw new SmartyException(
|
||||
'Unable to read ' . ($source->isConfig ? 'config' : 'template') .
|
||||
" {$source->type} '{$source->name}'"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source) {
|
||||
return basename($source->filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
* build template filepath by traversing the template_dir array
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string fully qualified filepath
|
||||
* @throws SmartyException
|
||||
*/
|
||||
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
||||
$file = $source->name;
|
||||
// absolute file ?
|
||||
if ($file[0] === '/' || $file[1] === ':') {
|
||||
$file = $source->smarty->_realpath($file, true);
|
||||
return is_file($file) ? $file : false;
|
||||
}
|
||||
// go relative to a given template?
|
||||
if ($file[0] === '.' && $_template && $_template->_isSubTpl()
|
||||
&& preg_match('#^[.]{1,2}[\\\/]#', $file)
|
||||
) {
|
||||
if ($_template->parent->source->type !== 'file' && $_template->parent->source->type !== 'extends') {
|
||||
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
|
||||
}
|
||||
// normalize path
|
||||
$path =
|
||||
$source->smarty->_realpath(dirname($_template->parent->source->filepath) . DIRECTORY_SEPARATOR . $file);
|
||||
// files relative to a template only get one shot
|
||||
return is_file($path) ? $path : false;
|
||||
}
|
||||
// normalize DIRECTORY_SEPARATOR
|
||||
if (strpos($file, DIRECTORY_SEPARATOR === '/' ? '\\' : '/') !== false) {
|
||||
$file = str_replace(DIRECTORY_SEPARATOR === '/' ? '\\' : '/', DIRECTORY_SEPARATOR, $file);
|
||||
}
|
||||
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
|
||||
// template_dir index?
|
||||
if ($file[0] === '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) {
|
||||
$file = $fileMatch[2];
|
||||
$_indices = explode(',', $fileMatch[1]);
|
||||
$_index_dirs = [];
|
||||
foreach ($_indices as $index) {
|
||||
$index = trim($index);
|
||||
// try string indexes
|
||||
if (isset($_directories[$index])) {
|
||||
$_index_dirs[] = $_directories[$index];
|
||||
} elseif (is_numeric($index)) {
|
||||
// try numeric index
|
||||
$index = (int)$index;
|
||||
if (isset($_directories[$index])) {
|
||||
$_index_dirs[] = $_directories[$index];
|
||||
} else {
|
||||
// try at location index
|
||||
$keys = array_keys($_directories);
|
||||
if (isset($_directories[$keys[$index]])) {
|
||||
$_index_dirs[] = $_directories[$keys[$index]];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($_index_dirs)) {
|
||||
// index not found
|
||||
return false;
|
||||
} else {
|
||||
$_directories = $_index_dirs;
|
||||
}
|
||||
}
|
||||
// relative file name?
|
||||
foreach ($_directories as $_directory) {
|
||||
$path = $_directory . $file;
|
||||
if (is_file($path)) {
|
||||
return (strpos($path, '.' . DIRECTORY_SEPARATOR) !== false) ? $source->smarty->_realpath($path) : $path;
|
||||
}
|
||||
}
|
||||
if (!isset($_index_dirs)) {
|
||||
// Could be relative to cwd
|
||||
$path = $source->smarty->_realpath($file, true);
|
||||
if (is_file($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
// Use include path ?
|
||||
if ($source->smarty->use_include_path) {
|
||||
return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
119
src/Resource/PhpPlugin.php
Normal file
119
src/Resource/PhpPlugin.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Smarty\Resource;
|
||||
|
||||
use Smarty_Internal_Template;
|
||||
use Smarty_Template_Compiled;
|
||||
use Smarty_Template_Source;
|
||||
use SmartyException;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource PHP
|
||||
* Implements the file system as resource for PHP templates
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class PhpPlugin extends FilePlugin {
|
||||
|
||||
/**
|
||||
* Flag that it's an uncompiled resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $uncompiled = true;
|
||||
|
||||
/**
|
||||
* Resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = true;
|
||||
|
||||
/**
|
||||
* container for short_open_tag directive's value before executing PHP templates
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $short_open_tag;
|
||||
|
||||
/**
|
||||
* Create a new PHP Resource
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->short_open_tag = function_exists('ini_get') ? ini_get('short_open_tag') : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from file into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source) {
|
||||
if ($source->exists) {
|
||||
return '';
|
||||
}
|
||||
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* populate compiled object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object (is ignored)
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) {
|
||||
$compiled->filepath = $_template->source->filepath;
|
||||
$compiled->timestamp = $_template->source->timestamp;
|
||||
$compiled->exists = $_template->source->exists;
|
||||
$compiled->file_dependency[$_template->source->uid] =
|
||||
[
|
||||
$compiled->filepath,
|
||||
$compiled->timestamp,
|
||||
$_template->source->type,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render and output the template (without using the compiler)
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
* @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
|
||||
*/
|
||||
public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template) {
|
||||
if (!$source->smarty->allow_php_templates) {
|
||||
throw new SmartyException('PHP templates are disabled');
|
||||
}
|
||||
if (!$source->exists) {
|
||||
throw new SmartyException(
|
||||
"Unable to load template '{$source->type}:{$source->name}'" .
|
||||
($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : '')
|
||||
);
|
||||
}
|
||||
// prepare variables
|
||||
extract($_template->getTemplateVars());
|
||||
// include PHP template with short open tags enabled
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('short_open_tag', '1');
|
||||
}
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var Smarty_Internal_Template $_smarty_template
|
||||
* used in included file
|
||||
*/
|
||||
$_smarty_template = $_template;
|
||||
include $source->filepath;
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('short_open_tag', $this->short_open_tag);
|
||||
}
|
||||
}
|
||||
}
|
97
src/Resource/RecompiledPlugin.php
Normal file
97
src/Resource/RecompiledPlugin.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
namespace Smarty\Resource;
|
||||
|
||||
use Smarty;
|
||||
use Smarty_Internal_Template;
|
||||
use Smarty_Template_Compiled;
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Base implementation for resource plugins that don't compile cache
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
abstract class RecompiledPlugin extends BasePlugin {
|
||||
|
||||
/**
|
||||
* Flag that it's an recompiled resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $recompiled = true;
|
||||
|
||||
/**
|
||||
* Resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = true;
|
||||
|
||||
/**
|
||||
* compile template from source
|
||||
*
|
||||
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_smarty_tpl) {
|
||||
$compiled = &$_smarty_tpl->compiled;
|
||||
$compiled->file_dependency = [];
|
||||
$compiled->includes = [];
|
||||
$compiled->nocache_hash = null;
|
||||
$compiled->unifunc = null;
|
||||
$level = ob_get_level();
|
||||
ob_start();
|
||||
$_smarty_tpl->loadCompiler();
|
||||
// call compiler
|
||||
try {
|
||||
eval('?>' . $_smarty_tpl->compiler->compileTemplate($_smarty_tpl));
|
||||
} catch (Exception $e) {
|
||||
unset($_smarty_tpl->compiler);
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
// release compiler object to free memory
|
||||
unset($_smarty_tpl->compiler);
|
||||
ob_get_clean();
|
||||
$compiled->timestamp = time();
|
||||
$compiled->exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Compiled Object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) {
|
||||
$compiled->filepath = false;
|
||||
$compiled->timestamp = false;
|
||||
$compiled->exists = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable timestamp checks for recompiled resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function checkTimestamps() {
|
||||
return false;
|
||||
}
|
||||
}
|
81
src/Resource/StreamPlugin.php
Normal file
81
src/Resource/StreamPlugin.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Stream
|
||||
* Implements the streams as resource for Smarty template
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
namespace Smarty\Resource;
|
||||
|
||||
use Smarty;
|
||||
use Smarty_Internal_Template;
|
||||
use Smarty_Template_Source;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Stream
|
||||
* Implements the streams as resource for Smarty template
|
||||
*
|
||||
* @link https://php.net/streams
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class StreamPlugin extends RecompiledPlugin {
|
||||
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
||||
if (strpos($source->resource, '://') !== false) {
|
||||
$source->filepath = $source->resource;
|
||||
} else {
|
||||
$source->filepath = str_replace(':', '://', $source->resource);
|
||||
}
|
||||
$source->uid = false;
|
||||
$source->content = $this->getContent($source);
|
||||
$source->timestamp = $source->exists = !!$source->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from stream into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source) {
|
||||
$t = '';
|
||||
// the availability of the stream has already been checked in Smarty\Resource\Base::fetch()
|
||||
$fp = fopen($source->filepath, 'r+');
|
||||
if ($fp) {
|
||||
while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
|
||||
$t .= $current_line;
|
||||
}
|
||||
fclose($fp);
|
||||
return $t;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* modify resource_name according to resource handlers specifications
|
||||
*
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param string $resource_name resource_name to make unique
|
||||
* @param boolean $isConfig flag for config resource
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) {
|
||||
return get_class($this) . '#' . $resource_name;
|
||||
}
|
||||
}
|
107
src/Resource/StringPlugin.php
Normal file
107
src/Resource/StringPlugin.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource String
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
namespace Smarty\Resource;
|
||||
use Smarty;
|
||||
use Smarty_Internal_Template;
|
||||
use Smarty_Template_Source;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource String
|
||||
* Implements the strings as resource for Smarty template
|
||||
* {@internal unlike eval-resources the compiled state of string-resources is saved for subsequent access}}
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class StringPlugin extends Smarty\Resource\BasePlugin {
|
||||
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
||||
$source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir);
|
||||
$source->timestamp = $source->exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from $resource_name into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @uses decode() to decode base64 and urlencoded template_resources
|
||||
*
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source) {
|
||||
return $this->decode($source->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* decode base64 and urlencode
|
||||
*
|
||||
* @param string $string template_resource to decode
|
||||
*
|
||||
* @return string decoded template_resource
|
||||
*/
|
||||
protected function decode($string) {
|
||||
// decode if specified
|
||||
if (($pos = strpos($string, ':')) !== false) {
|
||||
if (!strncmp($string, 'base64', 6)) {
|
||||
return base64_decode(substr($string, 7));
|
||||
} elseif (!strncmp($string, 'urlencode', 9)) {
|
||||
return urldecode(substr($string, 10));
|
||||
}
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* modify resource_name according to resource handlers specifications
|
||||
*
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param string $resource_name resource_name to make unique
|
||||
* @param boolean $isConfig flag for config resource
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false) {
|
||||
return get_class($this) . '#' . $this->decode($resource_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
* Always returns an empty string.
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source) {
|
||||
return '';
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable timestamp checks for string resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function checkTimestamps() {
|
||||
return false;
|
||||
}
|
||||
}
|
54
src/Resource/UncompiledPlugin.php
Normal file
54
src/Resource/UncompiledPlugin.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
namespace Smarty\Resource;
|
||||
|
||||
use Smarty;
|
||||
use Smarty_Internal_Template;
|
||||
use Smarty_Template_Compiled;
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Base implementation for resource plugins that don't use the compiler
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
abstract class UncompiledPlugin extends asePlugin {
|
||||
|
||||
/**
|
||||
* Flag that it's an uncompiled resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $uncompiled = true;
|
||||
|
||||
/**
|
||||
* Resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = true;
|
||||
|
||||
/**
|
||||
* populate compiled object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template) {
|
||||
$compiled->filepath = $_template->source->filepath;
|
||||
$compiled->timestamp = $_template->source->timestamp;
|
||||
$compiled->exists = $_template->source->exists;
|
||||
if ($_template->smarty->merge_compiled_includes || $_template->source->handler->checkTimestamps()) {
|
||||
$compiled->file_dependency[$_template->source->uid] =
|
||||
[$compiled->filepath, $compiled->timestamp, $_template->source->type,];
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,178 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource File
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource File
|
||||
* Implements the file system as resource for Smarty templates
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @throws \SmartyException
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$source->filepath = $this->buildFilepath($source, $_template);
|
||||
if ($source->filepath !== false) {
|
||||
if (isset($source->smarty->security_policy) && is_object($source->smarty->security_policy)) {
|
||||
$source->smarty->security_policy->isTrustedResourceDir($source->filepath, $source->isConfig);
|
||||
}
|
||||
$source->exists = true;
|
||||
$source->uid = sha1(
|
||||
$source->filepath . ($source->isConfig ? $source->smarty->_joined_config_dir :
|
||||
$source->smarty->_joined_template_dir)
|
||||
);
|
||||
$source->timestamp = filemtime($source->filepath);
|
||||
} else {
|
||||
$source->timestamp = $source->exists = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Source Object with timestamp and exists from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*/
|
||||
public function populateTimestamp(Smarty_Template_Source $source)
|
||||
{
|
||||
if (!$source->exists) {
|
||||
$source->timestamp = $source->exists = is_file($source->filepath);
|
||||
}
|
||||
if ($source->exists) {
|
||||
$source->timestamp = filemtime($source->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from file into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
if ($source->exists) {
|
||||
return file_get_contents($source->filepath);
|
||||
}
|
||||
throw new SmartyException(
|
||||
'Unable to read ' . ($source->isConfig ? 'config' : 'template') .
|
||||
" {$source->type} '{$source->name}'"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return basename($source->filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
* build template filepath by traversing the template_dir array
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string fully qualified filepath
|
||||
* @throws SmartyException
|
||||
*/
|
||||
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$file = $source->name;
|
||||
// absolute file ?
|
||||
if ($file[ 0 ] === '/' || $file[ 1 ] === ':') {
|
||||
$file = $source->smarty->_realpath($file, true);
|
||||
return is_file($file) ? $file : false;
|
||||
}
|
||||
// go relative to a given template?
|
||||
if ($file[ 0 ] === '.' && $_template && $_template->_isSubTpl()
|
||||
&& preg_match('#^[.]{1,2}[\\\/]#', $file)
|
||||
) {
|
||||
if ($_template->parent->source->type !== 'file' && $_template->parent->source->type !== 'extends') {
|
||||
throw new SmartyException("Template '{$file}' cannot be relative to template of resource type '{$_template->parent->source->type}'");
|
||||
}
|
||||
// normalize path
|
||||
$path =
|
||||
$source->smarty->_realpath(dirname($_template->parent->source->filepath) . DIRECTORY_SEPARATOR . $file);
|
||||
// files relative to a template only get one shot
|
||||
return is_file($path) ? $path : false;
|
||||
}
|
||||
// normalize DIRECTORY_SEPARATOR
|
||||
if (strpos($file, DIRECTORY_SEPARATOR === '/' ? '\\' : '/') !== false) {
|
||||
$file = str_replace(DIRECTORY_SEPARATOR === '/' ? '\\' : '/', DIRECTORY_SEPARATOR, $file);
|
||||
}
|
||||
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
|
||||
// template_dir index?
|
||||
if ($file[ 0 ] === '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) {
|
||||
$file = $fileMatch[ 2 ];
|
||||
$_indices = explode(',', $fileMatch[ 1 ]);
|
||||
$_index_dirs = array();
|
||||
foreach ($_indices as $index) {
|
||||
$index = trim($index);
|
||||
// try string indexes
|
||||
if (isset($_directories[ $index ])) {
|
||||
$_index_dirs[] = $_directories[ $index ];
|
||||
} elseif (is_numeric($index)) {
|
||||
// try numeric index
|
||||
$index = (int)$index;
|
||||
if (isset($_directories[ $index ])) {
|
||||
$_index_dirs[] = $_directories[ $index ];
|
||||
} else {
|
||||
// try at location index
|
||||
$keys = array_keys($_directories);
|
||||
if (isset($_directories[ $keys[ $index ] ])) {
|
||||
$_index_dirs[] = $_directories[ $keys[ $index ] ];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($_index_dirs)) {
|
||||
// index not found
|
||||
return false;
|
||||
} else {
|
||||
$_directories = $_index_dirs;
|
||||
}
|
||||
}
|
||||
// relative file name?
|
||||
foreach ($_directories as $_directory) {
|
||||
$path = $_directory . $file;
|
||||
if (is_file($path)) {
|
||||
return (strpos($path, '.' . DIRECTORY_SEPARATOR) !== false) ? $source->smarty->_realpath($path) : $path;
|
||||
}
|
||||
}
|
||||
if (!isset($_index_dirs)) {
|
||||
// Could be relative to cwd
|
||||
$path = $source->smarty->_realpath($file, true);
|
||||
if (is_file($path)) {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
// Use include path ?
|
||||
if ($source->smarty->use_include_path) {
|
||||
return $source->smarty->ext->_getIncludePath->getIncludePath($_directories, $file, $source->smarty);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,116 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource PHP
|
||||
* Implements the file system as resource for PHP templates
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File
|
||||
{
|
||||
/**
|
||||
* Flag that it's an uncompiled resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $uncompiled = true;
|
||||
|
||||
/**
|
||||
* Resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = true;
|
||||
|
||||
/**
|
||||
* container for short_open_tag directive's value before executing PHP templates
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $short_open_tag;
|
||||
|
||||
/**
|
||||
* Create a new PHP Resource
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->short_open_tag = function_exists('ini_get') ? ini_get('short_open_tag') : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from file into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
if ($source->exists) {
|
||||
return '';
|
||||
}
|
||||
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* populate compiled object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object (is ignored)
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$compiled->filepath = $_template->source->filepath;
|
||||
$compiled->timestamp = $_template->source->timestamp;
|
||||
$compiled->exists = $_template->source->exists;
|
||||
$compiled->file_dependency[ $_template->source->uid ] =
|
||||
array(
|
||||
$compiled->filepath,
|
||||
$compiled->timestamp,
|
||||
$_template->source->type,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render and output the template (without using the compiler)
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
* @throws SmartyException if template cannot be loaded or allow_php_templates is disabled
|
||||
*/
|
||||
public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal_Template $_template)
|
||||
{
|
||||
if (!$source->smarty->allow_php_templates) {
|
||||
throw new SmartyException('PHP templates are disabled');
|
||||
}
|
||||
if (!$source->exists) {
|
||||
throw new SmartyException(
|
||||
"Unable to load template '{$source->type}:{$source->name}'" .
|
||||
($_template->_isSubTpl() ? " in '{$_template->parent->template_resource}'" : '')
|
||||
);
|
||||
}
|
||||
// prepare variables
|
||||
extract($_template->getTemplateVars());
|
||||
// include PHP template with short open tags enabled
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('short_open_tag', '1');
|
||||
}
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @var Smarty_Internal_Template $_smarty_template
|
||||
* used in included file
|
||||
*/
|
||||
$_smarty_template = $_template;
|
||||
include $source->filepath;
|
||||
if (function_exists('ini_set')) {
|
||||
ini_set('short_open_tag', $this->short_open_tag);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Stream
|
||||
* Implements the streams as resource for Smarty template
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource Stream
|
||||
* Implements the streams as resource for Smarty template
|
||||
*
|
||||
* @link https://php.net/streams
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class Smarty_Internal_Resource_Stream extends Smarty_Resource_Recompiled
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
if (strpos($source->resource, '://') !== false) {
|
||||
$source->filepath = $source->resource;
|
||||
} else {
|
||||
$source->filepath = str_replace(':', '://', $source->resource);
|
||||
}
|
||||
$source->uid = false;
|
||||
$source->content = $this->getContent($source);
|
||||
$source->timestamp = $source->exists = !!$source->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from stream into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
$t = '';
|
||||
// the availability of the stream has already been checked in Smarty_Resource::fetch()
|
||||
$fp = fopen($source->filepath, 'r+');
|
||||
if ($fp) {
|
||||
while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
|
||||
$t .= $current_line;
|
||||
}
|
||||
fclose($fp);
|
||||
return $t;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* modify resource_name according to resource handlers specifications
|
||||
*
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param string $resource_name resource_name to make unique
|
||||
* @param boolean $isConfig flag for config resource
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
|
||||
{
|
||||
return get_class($this) . '#' . $resource_name;
|
||||
}
|
||||
}
|
@@ -1,108 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Resource String
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Uwe Tews
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Resource String
|
||||
* Implements the strings as resource for Smarty template
|
||||
* {@internal unlike eval-resources the compiled state of string-resources is saved for subsequent access}}
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
class Smarty_Internal_Resource_String extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir);
|
||||
$source->timestamp = $source->exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source from $resource_name into current template object
|
||||
*
|
||||
* @uses decode() to decode base64 and urlencoded template_resources
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
*/
|
||||
public function getContent(Smarty_Template_Source $source)
|
||||
{
|
||||
return $this->decode($source->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* decode base64 and urlencode
|
||||
*
|
||||
* @param string $string template_resource to decode
|
||||
*
|
||||
* @return string decoded template_resource
|
||||
*/
|
||||
protected function decode($string)
|
||||
{
|
||||
// decode if specified
|
||||
if (($pos = strpos($string, ':')) !== false) {
|
||||
if (!strncmp($string, 'base64', 6)) {
|
||||
return base64_decode(substr($string, 7));
|
||||
} elseif (!strncmp($string, 'urlencode', 9)) {
|
||||
return urldecode(substr($string, 10));
|
||||
}
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* modify resource_name according to resource handlers specifications
|
||||
*
|
||||
* @param Smarty $smarty Smarty instance
|
||||
* @param string $resource_name resource_name to make unique
|
||||
* @param boolean $isConfig flag for config resource
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
|
||||
{
|
||||
return get_class($this) . '#' . $this->decode($resource_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
* Always returns an empty string.
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable timestamp checks for string resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function checkTimestamps()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Wrapper Implementation for custom resource plugins
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
abstract class Smarty_Resource_Custom extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
abstract protected function fetch($name, &$source, &$mtime);
|
||||
|
||||
/**
|
||||
* 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.}}
|
||||
*
|
||||
* @param string $name template name
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
$source->filepath = $source->type . ':' . $this->generateSafeName($source->name);
|
||||
$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;
|
||||
if (isset($content)) {
|
||||
$source->content = $content;
|
||||
}
|
||||
}
|
||||
$source->exists = !!$source->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source into current template object
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string template source
|
||||
* @throws SmartyException if source cannot be loaded
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param Smarty_Template_Source $source source object
|
||||
*
|
||||
* @return string resource's basename
|
||||
*/
|
||||
public function getBasename(Smarty_Template_Source $source)
|
||||
{
|
||||
return basename($this->generateSafeName($source->name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes special characters from $name and limits its length to 127 characters.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function generateSafeName($name): string {
|
||||
return substr(preg_replace('/[^A-Za-z0-9._]/', '', (string) $name), 0, 127);
|
||||
}
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Base implementation for resource plugins that don't compile cache
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
abstract class Smarty_Resource_Recompiled extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* Flag that it's an recompiled resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $recompiled = true;
|
||||
|
||||
/**
|
||||
* Resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = true;
|
||||
|
||||
/**
|
||||
* compile template from source
|
||||
*
|
||||
* @param Smarty_Internal_Template $_smarty_tpl do not change variable name, is used by compiled template
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function process(Smarty_Internal_Template $_smarty_tpl)
|
||||
{
|
||||
$compiled = &$_smarty_tpl->compiled;
|
||||
$compiled->file_dependency = array();
|
||||
$compiled->includes = array();
|
||||
$compiled->nocache_hash = null;
|
||||
$compiled->unifunc = null;
|
||||
$level = ob_get_level();
|
||||
ob_start();
|
||||
$_smarty_tpl->loadCompiler();
|
||||
// call compiler
|
||||
try {
|
||||
eval('?>' . $_smarty_tpl->compiler->compileTemplate($_smarty_tpl));
|
||||
} catch (Exception $e) {
|
||||
unset($_smarty_tpl->compiler);
|
||||
while (ob_get_level() > $level) {
|
||||
ob_end_clean();
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
// release compiler object to free memory
|
||||
unset($_smarty_tpl->compiler);
|
||||
ob_get_clean();
|
||||
$compiled->timestamp = time();
|
||||
$compiled->exists = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* populate Compiled Object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$compiled->filepath = false;
|
||||
$compiled->timestamp = false;
|
||||
$compiled->exists = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Disable timestamp checks for recompiled resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function checkTimestamps()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smarty Resource Plugin
|
||||
* Base implementation for resource plugins that don't use the compiler
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage TemplateResources
|
||||
*/
|
||||
abstract class Smarty_Resource_Uncompiled extends Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* Flag that it's an uncompiled resource
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $uncompiled = true;
|
||||
|
||||
/**
|
||||
* Resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $hasCompiledHandler = true;
|
||||
|
||||
/**
|
||||
* populate compiled object with compiled filepath
|
||||
*
|
||||
* @param Smarty_Template_Compiled $compiled compiled object
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*/
|
||||
public function populateCompiledFilepath(Smarty_Template_Compiled $compiled, Smarty_Internal_Template $_template)
|
||||
{
|
||||
$compiled->filepath = $_template->source->filepath;
|
||||
$compiled->timestamp = $_template->source->timestamp;
|
||||
$compiled->exists = $_template->source->exists;
|
||||
if ($_template->smarty->merge_compiled_includes || $_template->source->handler->checkTimestamps()) {
|
||||
$compiled->file_dependency[ $_template->source->uid ] =
|
||||
array($compiled->filepath, $compiled->timestamp, $_template->source->type,);
|
||||
}
|
||||
}
|
||||
}
|
@@ -919,7 +919,7 @@ class Smarty extends \Smarty_Internal_TemplateBase
|
||||
$caching = (int)($caching === null ? $this->caching : $caching);
|
||||
if ((isset($template) && strpos($template_name, ':.') !== false) || $this->allow_ambiguous_resources) {
|
||||
$_templateId =
|
||||
\Smarty_Resource::getUniqueTemplateName((isset($template) ? $template : $this), $template_name) .
|
||||
\Smarty\Resource\BasePlugin::getUniqueTemplateName((isset($template) ? $template : $this), $template_name) .
|
||||
"#{$cache_id}#{$compile_id}#{$caching}";
|
||||
} else {
|
||||
$_templateId = $this->_joined_template_dir . "#{$template_name}#{$cache_id}#{$compile_id}#{$caching}";
|
||||
|
@@ -84,7 +84,7 @@ class Smarty_Template_Config extends Smarty_Template_Source
|
||||
throw new SmartyException('Source: Missing name');
|
||||
}
|
||||
// parse resource_name, load resource handler
|
||||
list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type);
|
||||
list($name, $type) = Smarty\Resource\BasePlugin::parseResourceName($template_resource, $smarty->default_config_type);
|
||||
// make sure configs are not loaded via anything smarty can't handle
|
||||
if (isset($_incompatible_resources[ $type ])) {
|
||||
throw new SmartyException("Unable to use resource '{$type}' for config");
|
||||
|
@@ -76,7 +76,7 @@ class Smarty_Template_Source
|
||||
/**
|
||||
* Resource Handler
|
||||
*
|
||||
* @var \Smarty_Resource
|
||||
* @var \Smarty\Resource\BasePlugin
|
||||
*/
|
||||
public $handler = null;
|
||||
|
||||
@@ -131,11 +131,11 @@ class Smarty_Template_Source
|
||||
* @param string $name resource name
|
||||
*
|
||||
* @throws \SmartyException
|
||||
* @internal param \Smarty_Resource $handler Resource Handler this source object communicates with
|
||||
* @internal param \Smarty\Resource\Base $handler Resource Handler this source object communicates with
|
||||
*/
|
||||
public function __construct(Smarty $smarty, $resource, $type, $name)
|
||||
{
|
||||
$this->handler = Smarty_Resource::load($smarty, $type);
|
||||
$this->handler = Smarty\Resource\BasePlugin::load($smarty, $type);
|
||||
|
||||
$this->smarty = $smarty;
|
||||
$this->resource = $resource;
|
||||
@@ -239,7 +239,7 @@ class Smarty_Template_Source
|
||||
$this->content = $_content;
|
||||
$this->exists = true;
|
||||
$this->uid = $this->name = sha1($_content);
|
||||
$this->handler = Smarty_Resource::load($this->smarty, 'eval');
|
||||
$this->handler = Smarty\Resource\BasePlugin::load($this->smarty, 'eval');
|
||||
} else {
|
||||
$this->exists = false;
|
||||
throw new SmartyException(
|
||||
|
@@ -463,7 +463,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
|
||||
$mtime = is_file($_file_to_check[ 0 ]) ? filemtime($_file_to_check[ 0 ]) : false;
|
||||
}
|
||||
} else {
|
||||
$handler = Smarty_Resource::load($tpl->smarty, $_file_to_check[ 2 ]);
|
||||
$handler = Smarty\Resource\BasePlugin::load($tpl->smarty, $_file_to_check[ 2 ]);
|
||||
if ($handler->checkTimestamps()) {
|
||||
$source = Smarty_Template_Source::load($tpl, $tpl->smarty, $_file_to_check[ 0 ]);
|
||||
$mtime = $source->getTimeStamp();
|
||||
|
@@ -857,11 +857,11 @@ abstract class Smarty_Internal_TemplateBase extends Data
|
||||
* @link https://www.smarty.net/docs/en/api.register.resource.tpl
|
||||
*
|
||||
* @param string $name name of resource type
|
||||
* @param Smarty_Resource $resource_handler instance of Smarty_Resource
|
||||
* @param Smarty\Resource\Base $resource_handler instance of Smarty\Resource\Base
|
||||
*
|
||||
* @return \Smarty|\Smarty_Internal_Template
|
||||
*/
|
||||
public function registerResource($name, Smarty_Resource $resource_handler)
|
||||
public function registerResource($name, Smarty\Resource\Base $resource_handler)
|
||||
{
|
||||
$smarty = $this->_getSmartyObj();
|
||||
$smarty->registered_resources[ $name ] = $resource_handler;
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
class Smarty_Resource_Filetest extends Smarty_Internal_Resource_File
|
||||
use Smarty\Resource\FilePlugin;
|
||||
|
||||
class Smarty_Resource_FiletestPlugin extends FilePlugin
|
||||
{
|
||||
/**
|
||||
* populate Source Object with meta data from Resource
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class Smarty_Resource_Db4 extends Smarty_Resource
|
||||
class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
|
||||
{
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
|
@@ -46,7 +46,7 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty
|
||||
|
||||
public function testNone()
|
||||
{
|
||||
$resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/');
|
||||
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
|
||||
$this->smarty->registerResource('ambiguous', $resource_handler);
|
||||
$this->smarty->setDefaultResourceType('ambiguous');
|
||||
$this->smarty->setAllowAmbiguousResources(true);
|
||||
@@ -63,7 +63,7 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testCase1()
|
||||
{
|
||||
$resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/');
|
||||
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
|
||||
$this->smarty->registerResource('ambiguous', $resource_handler);
|
||||
$this->smarty->setDefaultResourceType('ambiguous');
|
||||
$this->smarty->setAllowAmbiguousResources(true);
|
||||
@@ -83,7 +83,7 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testCase2()
|
||||
{
|
||||
$resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/');
|
||||
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
|
||||
$this->smarty->registerResource('ambiguous', $resource_handler);
|
||||
$this->smarty->setDefaultResourceType('ambiguous');
|
||||
$this->smarty->setAllowAmbiguousResources(true);
|
||||
@@ -103,7 +103,7 @@ class CustomResourceAmbiguousTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testCaseSwitching()
|
||||
{
|
||||
$resource_handler = new Smarty_Resource_Ambiguous(__DIR__ . '/templates/ambiguous/');
|
||||
$resource_handler = new Smarty_Resource_AmbiguousPlugin(__DIR__ . '/templates/ambiguous/');
|
||||
$this->smarty->registerResource('ambiguous', $resource_handler);
|
||||
$this->smarty->setDefaultResourceType('ambiguous');
|
||||
$this->smarty->setAllowAmbiguousResources(true);
|
||||
|
@@ -1,12 +1,14 @@
|
||||
<?php
|
||||
|
||||
use Smarty\Resource\FilePlugin;
|
||||
|
||||
/**
|
||||
* Ambiguous Filename Custom Resource Example
|
||||
*
|
||||
* @package Resource-examples
|
||||
* @author Rodney Rehm
|
||||
*/
|
||||
class Smarty_Resource_Ambiguous extends Smarty_Internal_Resource_File
|
||||
class Smarty_Resource_AmbiguousPlugin extends FilePlugin
|
||||
{
|
||||
protected $directory;
|
||||
protected $segment;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require_once SMARTY_DIR . '../demo/plugins/resource.mysqls.php';
|
||||
|
||||
class Smarty_Resource_Mysqlstest extends Smarty_Resource_Mysqls
|
||||
class Smarty_Resource_Mysqlstest extends _MysqlsPlugin
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require_once SMARTY_DIR . '../demo/plugins/resource.mysql.php';
|
||||
|
||||
class Smarty_Resource_Mysqltest extends Smarty_Resource_Mysql
|
||||
class Smarty_Resource_Mysqltest extends _MysqlPlugin
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
|
@@ -6,6 +6,8 @@
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
use Smarty\Resource\CustomPlugin;
|
||||
|
||||
/**
|
||||
* class for register->resource tests
|
||||
*
|
||||
@@ -20,7 +22,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty
|
||||
{
|
||||
$this->setUpSmarty(__DIR__);
|
||||
|
||||
$this->smarty->registerResource("rr", new RegisteredResourceTest_Resource1());
|
||||
$this->smarty->registerResource("rr", new RegisteredResourceTest_Resource1Plugin());
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +58,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty
|
||||
*/
|
||||
public function testResourceCompileIdChange()
|
||||
{
|
||||
$this->smarty->registerResource('myresource', new RegisteredResourceTest_Resource2());
|
||||
$this->smarty->registerResource('myresource', new RegisteredResourceTest_Resource2Plugin());
|
||||
$this->smarty->compile_id = 'a';
|
||||
$this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some'));
|
||||
$this->assertEquals('this is template 1', $this->smarty->fetch('myresource:some'));
|
||||
@@ -69,7 +71,7 @@ class RegisteredResourceTest extends PHPUnit_Smarty
|
||||
*
|
||||
*/
|
||||
public function testSmartyTemplate() {
|
||||
$this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource3());
|
||||
$this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource3Plugin());
|
||||
$this->assertEquals('template = mytpl:foo', $this->smarty->fetch('mytpl:foo'));
|
||||
}
|
||||
/**
|
||||
@@ -77,12 +79,12 @@ class RegisteredResourceTest extends PHPUnit_Smarty
|
||||
*
|
||||
*/
|
||||
public function testSmartyCurrentDir() {
|
||||
$this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource4());
|
||||
$this->smarty->registerResource('mytpl', new RegisteredResourceTest_Resource4Plugin());
|
||||
$this->assertEquals('current_dir = .', $this->smarty->fetch('mytpl:bar'));
|
||||
}
|
||||
}
|
||||
|
||||
class RegisteredResourceTest_Resource1 extends Smarty_Resource_Custom {
|
||||
class RegisteredResourceTest_Resource1Plugin extends CustomPlugin {
|
||||
|
||||
protected function fetch($name, &$source, &$mtime) {
|
||||
$source = '{$x="hello world"}{$x}';
|
||||
@@ -91,7 +93,7 @@ class RegisteredResourceTest_Resource1 extends Smarty_Resource_Custom {
|
||||
|
||||
}
|
||||
|
||||
class RegisteredResourceTest_Resource2 extends Smarty_Resource_Custom {
|
||||
class RegisteredResourceTest_Resource2Plugin extends CustomPlugin {
|
||||
|
||||
protected function fetch($name, &$source, &$mtime) {
|
||||
|
||||
@@ -112,7 +114,7 @@ class RegisteredResourceTest_Resource2 extends Smarty_Resource_Custom {
|
||||
|
||||
}
|
||||
|
||||
class RegisteredResourceTest_Resource3 extends Smarty_Resource_Custom {
|
||||
class RegisteredResourceTest_Resource3Plugin extends CustomPlugin {
|
||||
|
||||
protected function fetch($name, &$source, &$mtime) {
|
||||
$source = 'template = {$smarty.template}';
|
||||
@@ -121,7 +123,7 @@ class RegisteredResourceTest_Resource3 extends Smarty_Resource_Custom {
|
||||
|
||||
}
|
||||
|
||||
class RegisteredResourceTest_Resource4 extends Smarty_Resource_Custom {
|
||||
class RegisteredResourceTest_Resource4Plugin extends CustomPlugin {
|
||||
|
||||
protected function fetch($name, &$source, &$mtime) {
|
||||
$source = 'current_dir = {$smarty.current_dir}';
|
||||
|
@@ -10,7 +10,9 @@
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class Smarty_Resource_Db extends Smarty_Resource_Recompiled {
|
||||
use Smarty\Resource\RecompiledPlugin;
|
||||
|
||||
class _DbPlugin extends RecompiledPlugin {
|
||||
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null) {
|
||||
$source->filepath = 'db:';
|
||||
|
@@ -10,7 +10,9 @@
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class Smarty_Resource_Db2 extends Smarty_Resource_Recompiled
|
||||
use Smarty\Resource\RecompiledPlugin;
|
||||
|
||||
class _Db2Plugin extends RecompiledPlugin
|
||||
{
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class Smarty_Resource_Db3 extends Smarty_Resource
|
||||
class Smarty_Resource_Db3 extends Smarty\Resource\BasePlugin
|
||||
{
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* -------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class Smarty_Resource_Db4 extends Smarty_Resource
|
||||
class Smarty_Resource_Db4 extends Smarty\Resource\BasePlugin
|
||||
{
|
||||
public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||
{
|
||||
|
@@ -49,8 +49,8 @@ class ResourcePluginTest extends PHPUnit_Smarty
|
||||
public function testResourcePluginRegisteredInstance()
|
||||
{
|
||||
$this->smarty->addPluginsDir("./PHPunitplugins/");
|
||||
$this->smarty->loadPlugin('Smarty_Resource_Db2');
|
||||
$this->smarty->registerResource('db2a', new Smarty_Resource_Db2('db2a'));
|
||||
$this->smarty->loadPlugin('_Db2Plugin');
|
||||
$this->smarty->registerResource('db2a', new _Db2Plugin('db2a'));
|
||||
$this->assertEquals('hello world', $this->smarty->fetch('db2a:test'));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user