mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
- optimization replace internal Smarty::$ds property by DIRECTORY_SEPARATOR
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
===== 3.1.32 - dev ===
|
||||
26.10.2017 3.1.32-dev-28
|
||||
- bugfix Smarty version was not filled in header comment of compiled and cached files
|
||||
- optimization replace internal Smarty::$ds property by DIRECTORY_SEPARATOR
|
||||
|
||||
21.10.2017
|
||||
- bugfix custom delimiters could fail since modification of version 3.1.32-dev-23
|
||||
|
@@ -100,7 +100,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '3.1.32-dev-27';
|
||||
const SMARTY_VERSION = '3.1.32-dev-28';
|
||||
/**
|
||||
* define variable scopes
|
||||
*/
|
||||
@@ -166,14 +166,6 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
* assigned global tpl vars
|
||||
*/
|
||||
public static $global_tpl_vars = array();
|
||||
/**
|
||||
* error handler returned by set_error_handler() in Smarty::muteExpectedErrors()
|
||||
*/
|
||||
public static $_previous_error_handler = null;
|
||||
/**
|
||||
* contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors()
|
||||
*/
|
||||
public static $_muted_directories = array();
|
||||
/**
|
||||
* Flag denoting if Multibyte String functions are available
|
||||
*/
|
||||
@@ -544,12 +536,6 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
* @var Smarty_Internal_Debug
|
||||
*/
|
||||
public $_debug = null;
|
||||
/**
|
||||
* Directory separator
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $ds = DIRECTORY_SEPARATOR;
|
||||
/**
|
||||
* template directory
|
||||
*
|
||||
@@ -631,99 +617,21 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Error Handler to mute expected messages
|
||||
*
|
||||
* @link http://php.net/set_error_handler
|
||||
*
|
||||
* @param integer $errno Error level
|
||||
* @param $errstr
|
||||
* @param $errfile
|
||||
* @param $errline
|
||||
* @param $errcontext
|
||||
*
|
||||
* @return bool|void
|
||||
*/
|
||||
public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
|
||||
{
|
||||
$_is_muted_directory = false;
|
||||
// add the SMARTY_DIR to the list of muted directories
|
||||
if (!isset(Smarty::$_muted_directories[ SMARTY_DIR ])) {
|
||||
$smarty_dir = realpath(SMARTY_DIR);
|
||||
if ($smarty_dir !== false) {
|
||||
Smarty::$_muted_directories[ SMARTY_DIR ] =
|
||||
array('file' => $smarty_dir, 'length' => strlen($smarty_dir),);
|
||||
}
|
||||
}
|
||||
// walk the muted directories and test against $errfile
|
||||
foreach (Smarty::$_muted_directories as $key => &$dir) {
|
||||
if (!$dir) {
|
||||
// resolve directory and length for speedy comparisons
|
||||
$file = realpath($key);
|
||||
if ($file === false) {
|
||||
// this directory does not exist, remove and skip it
|
||||
unset(Smarty::$_muted_directories[ $key ]);
|
||||
continue;
|
||||
}
|
||||
$dir = array('file' => $file, 'length' => strlen($file),);
|
||||
}
|
||||
if (!strncmp($errfile, $dir[ 'file' ], $dir[ 'length' ])) {
|
||||
$_is_muted_directory = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// pass to next error handler if this error did not occur inside SMARTY_DIR
|
||||
// or the error was within smarty but masked to be ignored
|
||||
if (!$_is_muted_directory || ($errno && $errno & error_reporting())) {
|
||||
if (Smarty::$_previous_error_handler) {
|
||||
return call_user_func(Smarty::$_previous_error_handler,
|
||||
$errno,
|
||||
$errstr,
|
||||
$errfile,
|
||||
$errline,
|
||||
$errcontext);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable error handler to mute expected messages
|
||||
*
|
||||
* @return void
|
||||
* @deprecated
|
||||
*/
|
||||
public static function muteExpectedErrors()
|
||||
{
|
||||
/*
|
||||
error muting is done because some people implemented custom error_handlers using
|
||||
http://php.net/set_error_handler and for some reason did not understand the following paragraph:
|
||||
|
||||
It is important to remember that the standard PHP error handler is completely bypassed for the
|
||||
error types specified by error_types unless the callback function returns FALSE.
|
||||
error_reporting() settings will have no effect and your error handler will be called regardless -
|
||||
however you are still able to read the current value of error_reporting and act appropriately.
|
||||
Of particular note is that this value will be 0 if the statement that caused the error was
|
||||
prepended by the @ error-control operator.
|
||||
|
||||
Smarty deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include
|
||||
- @filemtime() is almost twice as fast as using an additional file_exists()
|
||||
- between file_exists() and filemtime() a possible race condition is opened,
|
||||
which does not exist using the simple @filemtime() approach.
|
||||
*/
|
||||
$error_handler = array('Smarty', 'mutingErrorHandler');
|
||||
$previous = set_error_handler($error_handler);
|
||||
// avoid dead loops
|
||||
if ($previous !== $error_handler) {
|
||||
Smarty::$_previous_error_handler = $previous;
|
||||
}
|
||||
return Smarty_Internal_ErrorHandler::muteExpectedErrors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable error handler muting expected messages
|
||||
*
|
||||
* @return void
|
||||
* @deprecated
|
||||
*/
|
||||
public static function unmuteExpectedErrors()
|
||||
{
|
||||
@@ -769,27 +677,6 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set template directory
|
||||
*
|
||||
* @param string|array $template_dir directory(s) of template sources
|
||||
* @param bool $isConfig true for config_dir
|
||||
*
|
||||
* @return \Smarty current Smarty instance for chaining
|
||||
*/
|
||||
public function setTemplateDir($template_dir, $isConfig = false)
|
||||
{
|
||||
if ($isConfig) {
|
||||
$this->config_dir = array();
|
||||
$this->_processedConfigDir = array();
|
||||
} else {
|
||||
$this->template_dir = array();
|
||||
$this->_processedTemplateDir = array();
|
||||
}
|
||||
$this->addTemplateDir($template_dir, null, $isConfig);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add template directory(s)
|
||||
*
|
||||
@@ -859,15 +746,24 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Set config directory
|
||||
* Set template directory
|
||||
*
|
||||
* @param $config_dir
|
||||
* @param string|array $template_dir directory(s) of template sources
|
||||
* @param bool $isConfig true for config_dir
|
||||
*
|
||||
* @return Smarty current Smarty instance for chaining
|
||||
* @return \Smarty current Smarty instance for chaining
|
||||
*/
|
||||
public function setConfigDir($config_dir)
|
||||
public function setTemplateDir($template_dir, $isConfig = false)
|
||||
{
|
||||
return $this->setTemplateDir($config_dir, true);
|
||||
if ($isConfig) {
|
||||
$this->config_dir = array();
|
||||
$this->_processedConfigDir = array();
|
||||
} else {
|
||||
$this->template_dir = array();
|
||||
$this->_processedTemplateDir = array();
|
||||
}
|
||||
$this->addTemplateDir($template_dir, null, $isConfig);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -896,17 +792,15 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Set plugins directory
|
||||
* Set config directory
|
||||
*
|
||||
* @param string|array $plugins_dir directory(s) of plugins
|
||||
* @param $config_dir
|
||||
*
|
||||
* @return Smarty current Smarty instance for chaining
|
||||
*/
|
||||
public function setPluginsDir($plugins_dir)
|
||||
public function setConfigDir($config_dir)
|
||||
{
|
||||
$this->plugins_dir = (array)$plugins_dir;
|
||||
$this->_pluginsDirNormalized = false;
|
||||
return $this;
|
||||
return $this->setTemplateDir($config_dir, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -942,7 +836,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
$this->plugins_dir = (array)$this->plugins_dir;
|
||||
}
|
||||
foreach ($this->plugins_dir as $k => $v) {
|
||||
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . $this->ds, true);
|
||||
$this->plugins_dir[ $k ] = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true);
|
||||
}
|
||||
$this->_cache[ 'plugin_files' ] = array();
|
||||
$this->_pluginsDirNormalized = true;
|
||||
@@ -951,15 +845,16 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Set plugins directory
|
||||
*
|
||||
* @param string $compile_dir directory to store compiled templates in
|
||||
* @param string|array $plugins_dir directory(s) of plugins
|
||||
*
|
||||
* @return Smarty current Smarty instance for chaining
|
||||
*/
|
||||
public function setCompileDir($compile_dir)
|
||||
public function setPluginsDir($plugins_dir)
|
||||
{
|
||||
$this->_normalizeDir('compile_dir', $compile_dir);
|
||||
$this->_compileDirNormalized = true;
|
||||
$this->plugins_dir = (array)$plugins_dir;
|
||||
$this->_pluginsDirNormalized = false;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -978,16 +873,15 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cache directory
|
||||
*
|
||||
* @param string $cache_dir directory to store cached templates in
|
||||
* @param string $compile_dir directory to store compiled templates in
|
||||
*
|
||||
* @return Smarty current Smarty instance for chaining
|
||||
*/
|
||||
public function setCacheDir($cache_dir)
|
||||
public function setCompileDir($compile_dir)
|
||||
{
|
||||
$this->_normalizeDir('cache_dir', $cache_dir);
|
||||
$this->_cacheDirNormalized = true;
|
||||
$this->_normalizeDir('compile_dir', $compile_dir);
|
||||
$this->_compileDirNormalized = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -1005,6 +899,20 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
return $this->cache_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set cache directory
|
||||
*
|
||||
* @param string $cache_dir directory to store cached templates in
|
||||
*
|
||||
* @return Smarty current Smarty instance for chaining
|
||||
*/
|
||||
public function setCacheDir($cache_dir)
|
||||
{
|
||||
$this->_normalizeDir('cache_dir', $cache_dir);
|
||||
$this->_cacheDirNormalized = true;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a template object
|
||||
*
|
||||
@@ -1133,24 +1041,24 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
*/
|
||||
public function _realpath($path, $realpath = null)
|
||||
{
|
||||
$nds = $this->ds == '/' ? '\\' : '/';
|
||||
// normalize $this->ds
|
||||
$path = str_replace($nds, $this->ds, $path);
|
||||
$nds = DIRECTORY_SEPARATOR === '/' ? '\\' : '/';
|
||||
// normalize DIRECTORY_SEPARATOR
|
||||
$path = str_replace($nds, DIRECTORY_SEPARATOR, $path);
|
||||
preg_match('%^(?<root>(?:[[:alpha:]]:[\\\\]|/|[\\\\]{2}[[:alpha:]]+|[[:print:]]{2,}:[/]{2}|[\\\\])?)(?<path>(.*))$%u',
|
||||
$path,
|
||||
$parts);
|
||||
$path = $parts[ 'path' ];
|
||||
if ($parts[ 'root' ] == '\\') {
|
||||
if ($parts[ 'root' ] === '\\') {
|
||||
$parts[ 'root' ] = substr(getcwd(), 0, 2) . $parts[ 'root' ];
|
||||
} else {
|
||||
if ($realpath !== null && !$parts[ 'root' ]) {
|
||||
$path = getcwd() . $this->ds . $path;
|
||||
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
|
||||
}
|
||||
}
|
||||
// remove noop 'DIRECTORY_SEPARATOR DIRECTORY_SEPARATOR' and 'DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR' patterns
|
||||
$path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#u', $this->ds, $path);
|
||||
$path = preg_replace('#([\\\\/]([.]?[\\\\/])+)#u', DIRECTORY_SEPARATOR, $path);
|
||||
// resolve '..DIRECTORY_SEPARATOR' pattern, smallest first
|
||||
if (strpos($path, '..' . $this->ds) != false &&
|
||||
if (strpos($path, '..' . DIRECTORY_SEPARATOR) !== false &&
|
||||
preg_match_all('#(([.]?[\\\\/])*([.][.])[\\\\/]([.]?[\\\\/])*)+#u', $path, $match)
|
||||
) {
|
||||
$counts = array();
|
||||
@@ -1161,7 +1069,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
foreach ($counts as $count) {
|
||||
$path = preg_replace('#(([\\\\/]([.]?[\\\\/])*[^\\\\/.]+){' . $count .
|
||||
'}[\\\\/]([.]?[\\\\/])*([.][.][\\\\/]([.]?[\\\\/])*){' . $count . '})(?=[^.])#u',
|
||||
$this->ds,
|
||||
DIRECTORY_SEPARATOR,
|
||||
$path);
|
||||
}
|
||||
}
|
||||
@@ -1209,16 +1117,6 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
$this->escape_html = $escape_html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set auto_literal flag
|
||||
*
|
||||
* @param boolean $auto_literal
|
||||
*/
|
||||
public function setAutoLiteral($auto_literal = true)
|
||||
{
|
||||
$this->auto_literal = $auto_literal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return auto_literal flag
|
||||
*
|
||||
@@ -1229,6 +1127,16 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
return $this->auto_literal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set auto_literal flag
|
||||
*
|
||||
* @param boolean $auto_literal
|
||||
*/
|
||||
public function setAutoLiteral($auto_literal = true)
|
||||
{
|
||||
$this->auto_literal = $auto_literal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $force_compile
|
||||
*/
|
||||
@@ -1245,16 +1153,6 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
$this->merge_compiled_includes = $merge_compiled_includes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set left delimiter
|
||||
*
|
||||
* @param string $left_delimiter
|
||||
*/
|
||||
public function setLeftDelimiter($left_delimiter)
|
||||
{
|
||||
$this->left_delimiter = $left_delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get left delimiter
|
||||
*
|
||||
@@ -1266,13 +1164,13 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Set right delimiter
|
||||
* Set left delimiter
|
||||
*
|
||||
* @param string
|
||||
* @param string $left_delimiter
|
||||
*/
|
||||
public function setRightDelimiter($right_delimiter)
|
||||
public function setLeftDelimiter($left_delimiter)
|
||||
{
|
||||
$this->right_delimiter = $right_delimiter;
|
||||
$this->left_delimiter = $left_delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1285,6 +1183,16 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
return $this->right_delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set right delimiter
|
||||
*
|
||||
* @param string
|
||||
*/
|
||||
public function setRightDelimiter($right_delimiter)
|
||||
{
|
||||
$this->right_delimiter = $right_delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $debugging
|
||||
*/
|
||||
@@ -1407,9 +1315,11 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
*/
|
||||
private function _normalizeDir($dirName, $dir)
|
||||
{
|
||||
$this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . $this->ds, true);
|
||||
if (!isset(Smarty::$_muted_directories[ $this->{$dirName} ])) {
|
||||
Smarty::$_muted_directories[ $this->{$dirName} ] = null;
|
||||
$this->{$dirName} = $this->_realpath(rtrim($dir, "/\\") . DIRECTORY_SEPARATOR, true);
|
||||
if (class_exists('Smarty_Internal_ErrorHandler', false)) {
|
||||
if (!isset(Smarty_Internal_ErrorHandler::$mutedDirectories[ $this->{$dirName} ])) {
|
||||
Smarty_Internal_ErrorHandler::$mutedDirectories[ $this->{$dirName} ] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1433,7 +1343,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
||||
}
|
||||
foreach ($dir as $k => $v) {
|
||||
if (!isset($processed[ $k ])) {
|
||||
$dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . $this->ds, true);
|
||||
$dir[ $k ] = $v = $this->_realpath(rtrim($v, "/\\") . DIRECTORY_SEPARATOR, true);
|
||||
$processed[ $k ] = true;
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* caching mode to create nocache code but no cache file
|
||||
*/
|
||||
const CACHING_NOCACHE_CODE = 9999;
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -28,7 +27,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -36,7 +34,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('file');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -44,7 +41,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $option_flags = array('nocache', 'inline', 'caching');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -52,7 +48,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $optional_attributes = array('_any');
|
||||
|
||||
/**
|
||||
* Valid scope names
|
||||
*
|
||||
@@ -77,7 +72,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$uid = $t_hash = null;
|
||||
// check and get attributes
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
|
||||
$fullResourceName = $source_resource = $_attr[ 'file' ];
|
||||
$variable_template = false;
|
||||
$cache_tpl = false;
|
||||
@@ -90,7 +84,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$variable_template = true;
|
||||
}
|
||||
if (!$variable_template) {
|
||||
if ($type != 'string') {
|
||||
if ($type !== 'string') {
|
||||
$fullResourceName = "{$type}:{$name}";
|
||||
$compiled = $compiler->parent_compiler->template->compiled;
|
||||
if (isset($compiled->includes[ $fullResourceName ])) {
|
||||
@@ -116,10 +110,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
} else {
|
||||
$variable_template = true;
|
||||
}
|
||||
|
||||
// scope setup
|
||||
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
|
||||
|
||||
// set flag to cache subtemplate object when called within loop or template name is variable.
|
||||
if ($cache_tpl || $variable_template || $compiler->loopNesting > 0) {
|
||||
$_cache_tpl = 'true';
|
||||
@@ -128,18 +120,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
}
|
||||
// assume caching is off
|
||||
$_caching = Smarty::CACHING_OFF;
|
||||
|
||||
$call_nocache = $compiler->tag_nocache || $compiler->nocache;
|
||||
|
||||
// caching was on and {include} is not in nocache mode
|
||||
if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) {
|
||||
$_caching = self::CACHING_NOCACHE_CODE;
|
||||
}
|
||||
|
||||
// flag if included template code should be merged into caller
|
||||
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || $_attr[ 'inline' ] === true) &&
|
||||
!$compiler->template->source->handler->recompiled;
|
||||
|
||||
if ($merge_compiled_includes) {
|
||||
// variable template name ?
|
||||
if ($variable_template) {
|
||||
@@ -150,7 +138,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$merge_compiled_includes = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* if the {include} tag provides individual parameter for caching or compile_id
|
||||
* the subtemplate must not be included into the common cache file and is treated like
|
||||
@@ -182,7 +169,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
} else {
|
||||
$_compile_id = '$_smarty_tpl->compile_id';
|
||||
}
|
||||
|
||||
// if subtemplate will be called in nocache mode do not merge
|
||||
if ($compiler->template->caching && $call_nocache) {
|
||||
$merge_compiled_includes = false;
|
||||
@@ -200,7 +186,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$_assign = $_attr[ 'assign' ];
|
||||
}
|
||||
}
|
||||
|
||||
$has_compiled_template = false;
|
||||
if ($merge_compiled_includes) {
|
||||
$c_id = isset($_attr[ 'compile_id' ]) ? $_attr[ 'compile_id' ] : $compiler->template->compile_id;
|
||||
@@ -232,13 +217,13 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$_vars = 'array(' . join(',', $_pairs) . ')';
|
||||
}
|
||||
$update_compile_id = $compiler->template->caching && !$compiler->tag_nocache && !$compiler->nocache &&
|
||||
$_compile_id != '$_smarty_tpl->compile_id';
|
||||
$_compile_id !== '$_smarty_tpl->compile_id';
|
||||
if ($has_compiled_template && !$call_nocache) {
|
||||
$_output = "<?php\n";
|
||||
if ($update_compile_id) {
|
||||
$_output .= $compiler->makeNocacheCode("\$_compile_id_save[] = \$_smarty_tpl->compile_id;\n\$_smarty_tpl->compile_id = {$_compile_id};\n");
|
||||
}
|
||||
if (!empty($_attr) && $_caching == 9999 && $compiler->template->caching) {
|
||||
if (!empty($_attr) && $_caching === 9999 && $compiler->template->caching) {
|
||||
$_vars_nc = "foreach ($_vars as \$ik => \$iv) {\n";
|
||||
$_vars_nc .= "\$_smarty_tpl->tpl_vars[\$ik] = new Smarty_Variable(\$iv);\n";
|
||||
$_vars_nc .= "}\n";
|
||||
@@ -255,10 +240,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$_output .= $compiler->makeNocacheCode("\$_smarty_tpl->compile_id = array_pop(\$_compile_id_save);\n");
|
||||
}
|
||||
$_output .= "?>\n";
|
||||
|
||||
return $_output;
|
||||
}
|
||||
|
||||
if ($call_nocache) {
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
@@ -291,7 +274,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
* @return bool
|
||||
*/
|
||||
public function compileInlineTemplate(Smarty_Internal_SmartyTemplateCompiler $compiler,
|
||||
Smarty_Internal_Template $tpl, $t_hash)
|
||||
Smarty_Internal_Template $tpl,
|
||||
$t_hash)
|
||||
{
|
||||
$uid = $tpl->source->type . $tpl->source->uid;
|
||||
if (!($tpl->source->handler->uncompiled) && $tpl->source->exists) {
|
||||
@@ -309,7 +293,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
$tpl->mustCompile = true;
|
||||
$compiler->parent_compiler->mergedSubTemplatesData[ $uid ][ $t_hash ][ 'nocache_hash' ] =
|
||||
$tpl->compiled->nocache_hash;
|
||||
if ($compiler->template->source->type == 'file') {
|
||||
if ($compiler->template->source->type === 'file') {
|
||||
$sourceInfo = $compiler->template->source->filepath;
|
||||
} else {
|
||||
$basename = $compiler->template->source->handler->getBasename($compiler->template->source);
|
||||
@@ -331,7 +315,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|
||||
if ($tpl->compiled->has_nocache_code) {
|
||||
// replace nocache_hash
|
||||
$compiled_code =
|
||||
str_replace("{$tpl->compiled->nocache_hash}", $compiler->template->compiled->nocache_hash,
|
||||
str_replace("{$tpl->compiled->nocache_hash}",
|
||||
$compiler->template->compiled->nocache_hash,
|
||||
$compiled_code);
|
||||
$compiler->template->compiled->has_nocache_code = true;
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Insert
|
||||
* Compiles the {insert} tag
|
||||
@@ -24,7 +23,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $required_attributes = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -32,7 +30,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
* @see Smarty_Internal_CompileBase
|
||||
*/
|
||||
public $shorttag_order = array('name');
|
||||
|
||||
/**
|
||||
* Attribute definition: Overwrites base class.
|
||||
*
|
||||
@@ -56,7 +53,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
$_attr = $this->getAttributes($compiler, $args);
|
||||
//Does tag create output
|
||||
$compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
|
||||
|
||||
$nocacheParam = $compiler->template->caching && ($compiler->tag_nocache || $compiler->nocache);
|
||||
if (!$nocacheParam) {
|
||||
// do not compile as nocache code
|
||||
@@ -66,7 +62,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
$_smarty_tpl = $compiler->template;
|
||||
$_name = null;
|
||||
$_script = null;
|
||||
|
||||
$_output = '<?php ';
|
||||
// save possible attributes
|
||||
eval('$_name = @' . $_attr[ 'name' ] . ';');
|
||||
@@ -97,7 +92,7 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
}
|
||||
if (!empty($_dir)) {
|
||||
foreach ((array)$_dir as $_script_dir) {
|
||||
$_script_dir = rtrim($_script_dir, '/\\') . $compiler->smarty->ds;
|
||||
$_script_dir = rtrim($_script_dir, '/\\') . DIRECTORY_SEPARATOR;
|
||||
if (file_exists($_script_dir . $_script)) {
|
||||
$_filepath = $_script_dir . $_script;
|
||||
break;
|
||||
@@ -113,7 +108,8 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
require_once $_filepath;
|
||||
if (!is_callable($_function)) {
|
||||
$compiler->trigger_template_error(" {insert} function '{$_function}' is not callable in script file '{$_script}'",
|
||||
null, true);
|
||||
null,
|
||||
true);
|
||||
}
|
||||
} else {
|
||||
$_filepath = 'null';
|
||||
@@ -122,7 +118,8 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
if (!is_callable($_function)) {
|
||||
// try plugin
|
||||
if (!$_function = $compiler->getPlugin($_name, 'insert')) {
|
||||
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'", null,
|
||||
$compiler->trigger_template_error("{insert} no function or plugin found for '{$_name}'",
|
||||
null,
|
||||
true);
|
||||
}
|
||||
}
|
||||
@@ -149,7 +146,6 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase
|
||||
$_output .= "echo {$_function}({$_params},\$_smarty_tpl);?>";
|
||||
}
|
||||
}
|
||||
|
||||
return $_output;
|
||||
}
|
||||
}
|
||||
|
@@ -35,13 +35,12 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
{
|
||||
// clear template objects cache
|
||||
$smarty->_clearTemplateCache();
|
||||
|
||||
$_compile_dir = $smarty->getCompileDir();
|
||||
if ($_compile_dir == '/') { //We should never want to delete this!
|
||||
if ($_compile_dir === '/') { //We should never want to delete this!
|
||||
return 0;
|
||||
}
|
||||
$_compile_id = isset($compile_id) ? preg_replace('![^\w]+!', '_', $compile_id) : null;
|
||||
$_dir_sep = $smarty->use_sub_dirs ? $smarty->ds : '^';
|
||||
$_dir_sep = $smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^';
|
||||
if (isset($resource_name)) {
|
||||
$_save_stat = $smarty->caching;
|
||||
$smarty->caching = false;
|
||||
@@ -49,7 +48,7 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
$tpl = $smarty->createTemplate($resource_name);
|
||||
$smarty->caching = $_save_stat;
|
||||
if (!$tpl->source->handler->uncompiled && !$tpl->source->handler->recompiled && $tpl->source->exists) {
|
||||
$_resource_part_1 = basename(str_replace('^', $smarty->ds, $tpl->compiled->filepath));
|
||||
$_resource_part_1 = basename(str_replace('^', DIRECTORY_SEPARATOR, $tpl->compiled->filepath));
|
||||
$_resource_part_1_length = strlen($_resource_part_1);
|
||||
} else {
|
||||
return 0;
|
||||
@@ -75,7 +74,7 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
}
|
||||
$_compile = new RecursiveIteratorIterator($_compileDirs, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($_compile as $_file) {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) == '.') {
|
||||
if (substr(basename($_file->getPathname()), 0, 1) === '.') {
|
||||
continue;
|
||||
}
|
||||
$_filepath = (string)$_file;
|
||||
@@ -93,12 +92,15 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
if ((!isset($_compile_id) || (isset($_filepath[ $_compile_id_part_length ]) && $a =
|
||||
!strncmp($_filepath, $_compile_id_part, $_compile_id_part_length))) &&
|
||||
(!isset($resource_name) || (isset($_filepath[ $_resource_part_1_length ]) &&
|
||||
substr_compare($_filepath, $_resource_part_1,
|
||||
- $_resource_part_1_length, $_resource_part_1_length) ==
|
||||
substr_compare($_filepath,
|
||||
$_resource_part_1,
|
||||
-$_resource_part_1_length,
|
||||
$_resource_part_1_length) ===
|
||||
0) || (isset($_filepath[ $_resource_part_2_length ]) &&
|
||||
substr_compare($_filepath, $_resource_part_2,
|
||||
substr_compare($_filepath,
|
||||
$_resource_part_2,
|
||||
-$_resource_part_2_length,
|
||||
$_resource_part_2_length) == 0))
|
||||
$_resource_part_2_length) === 0))
|
||||
) {
|
||||
if (isset($exp_time)) {
|
||||
if (is_file($_filepath) && time() - @filemtime($_filepath) >= $exp_time) {
|
||||
@@ -108,7 +110,6 @@ class Smarty_Internal_Method_ClearCompiledTemplate
|
||||
$unlink = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($unlink && is_file($_filepath) && @unlink($_filepath)) {
|
||||
$_count++;
|
||||
if (function_exists('opcache_invalidate')
|
||||
|
@@ -30,32 +30,32 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
{
|
||||
$file = $source->name;
|
||||
// absolute file ?
|
||||
if ($file[ 0 ] == '/' || $file[ 1 ] == ':') {
|
||||
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() &&
|
||||
if ($file[ 0 ] === '.' && $_template && $_template->_isSubTpl() &&
|
||||
preg_match('#^[.]{1,2}[\\\/]#', $file)
|
||||
) {
|
||||
if ($_template->parent->source->type != 'file' && $_template->parent->source->type != 'extends' &&
|
||||
if ($_template->parent->source->type !== 'file' && $_template->parent->source->type !== 'extends' &&
|
||||
!isset($_template->parent->_cache[ 'allow_relative_path' ])
|
||||
) {
|
||||
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) . $source->smarty->ds . $file);
|
||||
$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 $source->smarty->ds
|
||||
if (strpos($file, $source->smarty->ds == '/' ? '\\' : '/') !== false) {
|
||||
$file = str_replace($source->smarty->ds == '/' ? '\\' : '/', $source->smarty->ds, $file);
|
||||
// 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)) {
|
||||
if ($file[ 0 ] === '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) {
|
||||
$file = $fileMatch[ 2 ];
|
||||
$_indices = explode(',', $fileMatch[ 1 ]);
|
||||
$_index_dirs = array();
|
||||
@@ -90,7 +90,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||
foreach ($_directories as $_directory) {
|
||||
$path = $_directory . $file;
|
||||
if (is_file($path)) {
|
||||
return (strpos($path, '.' . $source->smarty->ds) !== false) ? $source->smarty->_realpath($path) : $path;
|
||||
return (strpos($path, '.' . DIRECTORY_SEPARATOR) !== false) ? $source->smarty->_realpath($path) : $path;
|
||||
}
|
||||
}
|
||||
if (!isset($_index_dirs)) {
|
||||
|
@@ -21,49 +21,42 @@ class Smarty_Internal_Runtime_GetIncludePath
|
||||
* @var string
|
||||
*/
|
||||
public $_include_path = '';
|
||||
|
||||
/**
|
||||
* include path directory cache
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_include_dirs = array();
|
||||
|
||||
/**
|
||||
* include path directory cache
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $_user_dirs = array();
|
||||
|
||||
/**
|
||||
* stream cache
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $isFile = array();
|
||||
|
||||
/**
|
||||
* stream cache
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public $isPath = array();
|
||||
|
||||
/**
|
||||
* stream cache
|
||||
*
|
||||
* @var int[]
|
||||
*/
|
||||
public $number = array();
|
||||
|
||||
/**
|
||||
* status cache
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $_has_stream_include = null;
|
||||
|
||||
/**
|
||||
* Number for array index
|
||||
*
|
||||
@@ -81,13 +74,13 @@ class Smarty_Internal_Runtime_GetIncludePath
|
||||
public function isNewIncludePath(Smarty $smarty)
|
||||
{
|
||||
$_i_path = get_include_path();
|
||||
if ($this->_include_path != $_i_path) {
|
||||
if ($this->_include_path !== $_i_path) {
|
||||
$this->_include_dirs = array();
|
||||
$this->_include_path = $_i_path;
|
||||
$_dirs = (array)explode(PATH_SEPARATOR, $_i_path);
|
||||
foreach ($_dirs as $_path) {
|
||||
if (is_dir($_path)) {
|
||||
$this->_include_dirs[] = $smarty->_realpath($_path . $smarty->ds, true);
|
||||
$this->_include_dirs[] = $smarty->_realpath($_path . DIRECTORY_SEPARATOR, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -143,9 +136,9 @@ class Smarty_Internal_Runtime_GetIncludePath
|
||||
$dir = $this->_user_dirs[ $dir_n ];
|
||||
}
|
||||
} else {
|
||||
if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') {
|
||||
if ($dir[ 0 ] === '/' || $dir[ 1 ] === ':') {
|
||||
$dir = str_ireplace(getcwd(), '.', $dir);
|
||||
if ($dir[ 0 ] == '/' || $dir[ 1 ] == ':') {
|
||||
if ($dir[ 0 ] === '/' || $dir[ 1 ] === ':') {
|
||||
$this->_user_dirs[ $dir_n ] = false;
|
||||
continue;
|
||||
}
|
||||
|
@@ -20,20 +20,6 @@
|
||||
*/
|
||||
abstract class Smarty_Resource
|
||||
{
|
||||
/**
|
||||
* Source is bypassing compiler
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $uncompiled = false;
|
||||
|
||||
/**
|
||||
* Source must be recompiled on every occasion
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $recompiled = false;
|
||||
|
||||
/**
|
||||
* resource types provided by the core
|
||||
*
|
||||
@@ -45,7 +31,18 @@ abstract class Smarty_Resource
|
||||
'stream' => 'smarty_internal_resource_stream.php',
|
||||
'eval' => 'smarty_internal_resource_eval.php',
|
||||
'php' => 'smarty_internal_resource_php.php');
|
||||
|
||||
/**
|
||||
* Source is bypassing compiler
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $uncompiled = false;
|
||||
/**
|
||||
* Source must be recompiled on every occasion
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $recompiled = false;
|
||||
/**
|
||||
* Flag if resource does implement populateCompiledFilepath() method
|
||||
*
|
||||
@@ -53,6 +50,124 @@ abstract class Smarty_Resource
|
||||
*/
|
||||
public $hasCompiledHandler = false;
|
||||
|
||||
/**
|
||||
* Load Resource Handler
|
||||
*
|
||||
* @param Smarty $smarty smarty object
|
||||
* @param string $type name of the resource
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return Smarty_Resource Resource Handler
|
||||
*/
|
||||
public static function load(Smarty $smarty, $type)
|
||||
{
|
||||
// try smarty's cache
|
||||
if (isset($smarty->_cache[ 'resource_handlers' ][ $type ])) {
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ];
|
||||
}
|
||||
// try registered resource
|
||||
if (isset($smarty->registered_resources[ $type ])) {
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] =
|
||||
$smarty->registered_resources[ $type ] instanceof Smarty_Resource ?
|
||||
$smarty->registered_resources[ $type ] : new Smarty_Internal_Resource_Registered();
|
||||
}
|
||||
// try sysplugins dir
|
||||
if (isset(self::$sysplugins[ $type ])) {
|
||||
$_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
|
||||
}
|
||||
// try plugins dir
|
||||
$_resource_class = 'Smarty_Resource_' . ucfirst($type);
|
||||
if ($smarty->loadPlugin($_resource_class)) {
|
||||
if (class_exists($_resource_class, false)) {
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
|
||||
} else {
|
||||
$smarty->registerResource($type,
|
||||
array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
|
||||
"smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
|
||||
// give it another try, now that the resource is registered properly
|
||||
return self::load($smarty, $type);
|
||||
}
|
||||
}
|
||||
// try streams
|
||||
$_known_stream = stream_get_wrappers();
|
||||
if (in_array($type, $_known_stream)) {
|
||||
// is known stream
|
||||
if (is_object($smarty->security_policy)) {
|
||||
$smarty->security_policy->isTrustedStream($type);
|
||||
}
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new Smarty_Internal_Resource_Stream();
|
||||
}
|
||||
// TODO: try default_(template|config)_handler
|
||||
// give up
|
||||
throw new SmartyException("Unknown resource type '{$type}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* extract resource_type and resource_name from template_resource and config_resource
|
||||
* @note "C:/foo.tpl" was forced to file resource up till Smarty 3.1.3 (including).
|
||||
*
|
||||
* @param string $resource_name template_resource or config_resource to parse
|
||||
* @param string $default_resource the default resource_type defined in $smarty
|
||||
*
|
||||
* @return array with parsed resource name and type
|
||||
*/
|
||||
public static function parseResourceName($resource_name, $default_resource)
|
||||
{
|
||||
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) {
|
||||
$type = $match[ 1 ];
|
||||
$name = substr($resource_name, strlen($match[ 0 ]));
|
||||
} else {
|
||||
// no resource given, use default
|
||||
// or single character before the colon is not a resource type, but part of the filepath
|
||||
$type = $default_resource;
|
||||
$name = $resource_name;
|
||||
}
|
||||
return array($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* modify template_resource according to resource handlers specifications
|
||||
*
|
||||
* @param \Smarty_Internal_Template|\Smarty $obj Smarty instance
|
||||
* @param string $template_resource template_resource to extract resource handler and name of
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public static function getUniqueTemplateName($obj, $template_resource)
|
||||
{
|
||||
$smarty = $obj->_getSmartyObj();
|
||||
list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
|
||||
// TODO: optimize for Smarty's internal resource types
|
||||
$resource = Smarty_Resource::load($smarty, $type);
|
||||
// go relative to a given template?
|
||||
$_file_is_dotted = $name[ 0 ] === '.' && ($name[ 1 ] === '.' || $name[ 1 ] === '/');
|
||||
if ($obj->_isTplObj() && $_file_is_dotted &&
|
||||
($obj->source->type === 'file' || $obj->parent->source->type === 'extends')
|
||||
) {
|
||||
$name = $smarty->_realpath(dirname($obj->parent->source->filepath) . DIRECTORY_SEPARATOR . $name);
|
||||
}
|
||||
return $resource->buildUniqueResourceName($smarty, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize Source Object for given resource
|
||||
* wrapper for backward compatibility to versions < 3.1.22
|
||||
* Either [$_template] or [$smarty, $template_resource] must be specified
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty $smarty smarty object
|
||||
* @param string $template_resource resource identifier
|
||||
*
|
||||
* @return Smarty_Template_Source Source Object
|
||||
*/
|
||||
public static function source(Smarty_Internal_Template $_template = null,
|
||||
Smarty $smarty = null,
|
||||
$template_resource = null)
|
||||
{
|
||||
return Smarty_Template_Source::load($_template, $smarty, $template_resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load template's source into current template object
|
||||
*
|
||||
@@ -105,6 +220,13 @@ abstract class Smarty_Resource
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if resource must check time stamps when when loading complied or cached templates.
|
||||
* Resources like 'extends' which use source components my disable timestamp checks on own resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
/**
|
||||
* Determine basename for compiled filename
|
||||
*
|
||||
@@ -117,138 +239,9 @@ abstract class Smarty_Resource
|
||||
return basename(preg_replace('![^\w]+!', '_', $source->name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Resource Handler
|
||||
*
|
||||
* @param Smarty $smarty smarty object
|
||||
* @param string $type name of the resource
|
||||
*
|
||||
* @throws SmartyException
|
||||
* @return Smarty_Resource Resource Handler
|
||||
*/
|
||||
public static function load(Smarty $smarty, $type)
|
||||
{
|
||||
// try smarty's cache
|
||||
if (isset($smarty->_cache[ 'resource_handlers' ][ $type ])) {
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ];
|
||||
}
|
||||
|
||||
// try registered resource
|
||||
if (isset($smarty->registered_resources[ $type ])) {
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] =
|
||||
$smarty->registered_resources[ $type ] instanceof Smarty_Resource ?
|
||||
$smarty->registered_resources[ $type ] : new Smarty_Internal_Resource_Registered();
|
||||
}
|
||||
|
||||
// try sysplugins dir
|
||||
if (isset(self::$sysplugins[ $type ])) {
|
||||
$_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
|
||||
}
|
||||
|
||||
// try plugins dir
|
||||
$_resource_class = 'Smarty_Resource_' . ucfirst($type);
|
||||
if ($smarty->loadPlugin($_resource_class)) {
|
||||
if (class_exists($_resource_class, false)) {
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new $_resource_class();
|
||||
} else {
|
||||
$smarty->registerResource($type,
|
||||
array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
|
||||
"smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
|
||||
// give it another try, now that the resource is registered properly
|
||||
return self::load($smarty, $type);
|
||||
}
|
||||
}
|
||||
|
||||
// try streams
|
||||
$_known_stream = stream_get_wrappers();
|
||||
if (in_array($type, $_known_stream)) {
|
||||
// is known stream
|
||||
if (is_object($smarty->security_policy)) {
|
||||
$smarty->security_policy->isTrustedStream($type);
|
||||
}
|
||||
return $smarty->_cache[ 'resource_handlers' ][ $type ] = new Smarty_Internal_Resource_Stream();
|
||||
}
|
||||
|
||||
// TODO: try default_(template|config)_handler
|
||||
|
||||
// give up
|
||||
throw new SmartyException("Unknown resource type '{$type}'");
|
||||
}
|
||||
|
||||
/**
|
||||
* extract resource_type and resource_name from template_resource and config_resource
|
||||
* @note "C:/foo.tpl" was forced to file resource up till Smarty 3.1.3 (including).
|
||||
*
|
||||
* @param string $resource_name template_resource or config_resource to parse
|
||||
* @param string $default_resource the default resource_type defined in $smarty
|
||||
*
|
||||
* @return array with parsed resource name and type
|
||||
*/
|
||||
public static function parseResourceName($resource_name, $default_resource)
|
||||
{
|
||||
if (preg_match('/^([A-Za-z0-9_\-]{2,})[:]/', $resource_name, $match)) {
|
||||
$type = $match[ 1 ];
|
||||
$name = substr($resource_name, strlen($match[ 0 ]));
|
||||
} else {
|
||||
// no resource given, use default
|
||||
// or single character before the colon is not a resource type, but part of the filepath
|
||||
$type = $default_resource;
|
||||
$name = $resource_name;
|
||||
}
|
||||
return array($name, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* modify template_resource according to resource handlers specifications
|
||||
*
|
||||
* @param \Smarty_Internal_Template|\Smarty $obj Smarty instance
|
||||
* @param string $template_resource template_resource to extract resource handler and name of
|
||||
*
|
||||
* @return string unique resource name
|
||||
*/
|
||||
public static function getUniqueTemplateName($obj, $template_resource)
|
||||
{
|
||||
$smarty = $obj->_getSmartyObj();
|
||||
list($name, $type) = self::parseResourceName($template_resource, $smarty->default_resource_type);
|
||||
// TODO: optimize for Smarty's internal resource types
|
||||
$resource = Smarty_Resource::load($smarty, $type);
|
||||
// go relative to a given template?
|
||||
$_file_is_dotted = $name[ 0 ] == '.' && ($name[ 1 ] == '.' || $name[ 1 ] == '/');
|
||||
if ($obj->_isTplObj() && $_file_is_dotted &&
|
||||
($obj->source->type == 'file' || $obj->parent->source->type == 'extends')
|
||||
) {
|
||||
$name = $smarty->_realpath(dirname($obj->parent->source->filepath) . $smarty->ds . $name);
|
||||
}
|
||||
return $resource->buildUniqueResourceName($smarty, $name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if resource must check time stamps when when loading complied or cached templates.
|
||||
* Resources like 'extends' which use source components my disable timestamp checks on own resource.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkTimestamps()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* initialize Source Object for given resource
|
||||
* wrapper for backward compatibility to versions < 3.1.22
|
||||
* Either [$_template] or [$smarty, $template_resource] must be specified
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
* @param Smarty $smarty smarty object
|
||||
* @param string $template_resource resource identifier
|
||||
*
|
||||
* @return Smarty_Template_Source Source Object
|
||||
*/
|
||||
public static function source(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
|
||||
$template_resource = null)
|
||||
{
|
||||
return Smarty_Template_Source::load($_template, $smarty, $template_resource);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -11,7 +11,6 @@
|
||||
*/
|
||||
class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
{
|
||||
|
||||
/**
|
||||
* nocache hash
|
||||
*
|
||||
@@ -49,12 +48,13 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
$this->filepath = $smarty->getCompileDir();
|
||||
if (isset($_template->compile_id)) {
|
||||
$this->filepath .= preg_replace('![^\w]+!', '_', $_template->compile_id) .
|
||||
($smarty->use_sub_dirs ? $smarty->ds : '^');
|
||||
($smarty->use_sub_dirs ? DIRECTORY_SEPARATOR : '^');
|
||||
}
|
||||
// if use_sub_dirs, break file into directories
|
||||
if ($smarty->use_sub_dirs) {
|
||||
$this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . $smarty->ds . $source->uid[ 2 ] .
|
||||
$source->uid[ 3 ] . $smarty->ds . $source->uid[ 4 ] . $source->uid[ 5 ] . $smarty->ds;
|
||||
$this->filepath .= $source->uid[ 0 ] . $source->uid[ 1 ] . DIRECTORY_SEPARATOR . $source->uid[ 2 ] .
|
||||
$source->uid[ 3 ] . DIRECTORY_SEPARATOR . $source->uid[ 4 ] . $source->uid[ 5 ] .
|
||||
DIRECTORY_SEPARATOR;
|
||||
}
|
||||
$this->filepath .= $source->uid . '_';
|
||||
if ($source->isConfig) {
|
||||
@@ -218,6 +218,21 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read compiled content from handler
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function read(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if (!$_template->source->handler->recompiled) {
|
||||
return file_get_contents($this->filepath);
|
||||
}
|
||||
return isset($this->content) ? $this->content : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load fresh compiled template by including the PHP file
|
||||
* HHVM requires a work around because of a PHP incompatibility
|
||||
@@ -239,19 +254,4 @@ class Smarty_Template_Compiled extends Smarty_Template_Resource_Base
|
||||
include($this->filepath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read compiled content from handler
|
||||
*
|
||||
* @param Smarty_Internal_Template $_template template object
|
||||
*
|
||||
* @return string content
|
||||
*/
|
||||
public function read(Smarty_Internal_Template $_template)
|
||||
{
|
||||
if (!$_template->source->handler->recompiled) {
|
||||
return file_get_contents($this->filepath);
|
||||
}
|
||||
return isset($this->content) ? $this->content : false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user