mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
- optimization of template/config file normalization
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
===== 3.1.28-dev===== (xx.xx.2015)
|
===== 3.1.28-dev===== (xx.xx.2015)
|
||||||
|
21.06.2015
|
||||||
|
- optimization of template/config file normalization
|
||||||
|
|
||||||
19.06.2015
|
19.06.2015
|
||||||
- improvement allow closures as callback at $smarty->registerFilter() https://github.com/smarty-php/smarty/issues/59
|
- improvement allow closures as callback at $smarty->registerFilter() https://github.com/smarty-php/smarty/issues/59
|
||||||
|
|
||||||
|
@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.28-dev/1';
|
const SMARTY_VERSION = '3.1.28-dev/2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -17,6 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
class Smarty_Internal_Resource_File extends Smarty_Resource
|
class Smarty_Internal_Resource_File extends Smarty_Resource
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Inverse DS
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $invDS = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* build template filepath by traversing the template_dir array
|
* build template filepath by traversing the template_dir array
|
||||||
*
|
*
|
||||||
@@ -29,7 +36,8 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
|||||||
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
|
||||||
{
|
{
|
||||||
$file = $source->name;
|
$file = $source->name;
|
||||||
preg_match('#^(?P<absolute>[\\\/]|[a-zA-Z]:[\\\/])|(\[(?P<index>[^\]]+)\])|(?P<rel>\.[\\\/])#', $file, $fileMatch);
|
$this->invDS = (DS == '/') ? '\\' : '/';
|
||||||
|
preg_match('#(^(?P<absolute>[\\\/]|[a-zA-Z]:[\\\/])|(\[(?P<index>[^\]]+)\])|(?P<rel>\.[\\\/]))|((?P<rel2>\.[\\\/])|(?P<ds>[' . $this->invDS . ']))#', $file, $fileMatch);
|
||||||
// save basename
|
// save basename
|
||||||
if (!empty($fileMatch['absolute'])) {
|
if (!empty($fileMatch['absolute'])) {
|
||||||
$file = $this->normalizePath($file);
|
$file = $this->normalizePath($file);
|
||||||
@@ -83,10 +91,11 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$normalize = !empty($fileMatch['rel']) || !empty($fileMatch['rel2']) || !empty($fileMatch['ds']);
|
||||||
// relative file name?
|
// relative file name?
|
||||||
foreach ($_directories as $_directory) {
|
foreach ($_directories as $_directory) {
|
||||||
$_filepath = $_directory . $file;
|
$_filepath = $_directory . $file;
|
||||||
$path = $this->normalizePath($_filepath);
|
$path = $normalize ? $this->normalizePath($_filepath) : $_filepath;
|
||||||
if (is_file($path)) {
|
if (is_file($path)) {
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
@@ -124,9 +133,10 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
|||||||
if ($path[0] == '.') {
|
if ($path[0] == '.') {
|
||||||
$path = getcwd() . DS . $path;
|
$path = getcwd() . DS . $path;
|
||||||
}
|
}
|
||||||
$path = preg_replace('#[\\\/]+([.][\\\/]+)*#', DS, $path);
|
$first = true;
|
||||||
while (strrpos($path, '.' . DS) !== false) {
|
while (strrpos($path, '.' . DS) !== false || ($first && strrpos($path, $this->invDS) !== false)) {
|
||||||
$path = preg_replace('#([\\\/]([^\\\/]+[\\\/]){2}([.][.][\\\/]){2})|([\\\/][^\\\/]+[\\\/][.][.][\\\/])#', DS, $path);
|
$path = preg_replace('#([\\\/]+([.][\\\/]+)+)|([\\\/]+([^\\\/]+[\\\/]+){2}([.][.][\\\/]+){2})|([\\\/]+[^\\\/]+[\\\/]+[.][.][\\\/]+)|[' . $this->invDS . ']+#', DS, $path);
|
||||||
|
$first = false;
|
||||||
}
|
}
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
@@ -196,7 +206,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
|
|||||||
if ($source->timestamp) {
|
if ($source->timestamp) {
|
||||||
return file_get_contents($source->filepath);
|
return file_get_contents($source->filepath);
|
||||||
}
|
}
|
||||||
if ($source instanceof Smarty_Config_Source) {
|
if ($source instanceof Smarty_Template_Config) {
|
||||||
throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
|
throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
|
||||||
}
|
}
|
||||||
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
|
||||||
|
Reference in New Issue
Block a user