update buildFilepath()

This commit is contained in:
Uwe Tews
2015-01-02 06:26:04 +01:00
parent 296a88b557
commit c55367d1f6

View File

@@ -45,7 +45,7 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $path)) { if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $path)) {
// the path gained from the parent template is relative to the current working directory // the path gained from the parent template is relative to the current working directory
// as expansions (like include_path) have already been done // as expansions (like include_path) have already been done
$path = getcwd() . '/' . $path; $path = str_replace('\\', '/', getcwd()) . '/' . $path;
} }
// normalize path // normalize path
$path = str_replace(array('\\', './'), array('/', ''), $path); $path = str_replace(array('\\', './'), array('/', ''), $path);
@@ -92,13 +92,15 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
// relative file name? // relative file name?
if (empty($fileMatch['absolute'])) { if (empty($fileMatch['absolute'])) {
foreach ($_directories as $_directory) { foreach ($_directories as $_directory) {
if (!empty($fileMatch['rel2'])) { if (empty($fileMatch['rel2'])) {
$_filepath = $_directory . $fileMatch['file'];
} else if (false === strpos($_directory, '..')) {
for ($i = 1; $i <= substr_count($fileMatch['rel2'], '../') + 1; $i ++) { for ($i = 1; $i <= substr_count($fileMatch['rel2'], '../') + 1; $i ++) {
$_directory = substr($_directory, 0, strrpos($_directory, '/')); $_directory = substr($_directory, 0, strrpos($_directory, '/'));
} }
$_filepath = $_directory . '/' . $fileMatch['file']; $_filepath = $_directory . '/' . $fileMatch['file'];
} else { } else {
$_filepath = $_directory . $fileMatch['file']; $_filepath = $_directory . $file;
} }
if ($this->fileExists($source, $_filepath)) { if ($this->fileExists($source, $_filepath)) {
return $_filepath; return $_filepath;
@@ -125,10 +127,10 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
} }
} }
// Could be relative to cwd // Could be relative to cwd
if (empty($fileMatch['rel1'])) { $path = str_replace('\\', '/', getcwd());
$file = getcwd() . '/' . $fileMatch['file']; if (empty($fileMatch['rel2'])) {
$file = $path . '/' . $fileMatch['file'];
} else { } else {
$path = getcwd();
for ($i = 1; $i <= substr_count($fileMatch['rel2'], '../'); $i ++) { for ($i = 1; $i <= substr_count($fileMatch['rel2'], '../'); $i ++) {
$path = substr($path, 0, strrpos($path, '/')); $path = substr($path, 0, strrpos($path, '/'));
} }
@@ -139,7 +141,8 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
} }
// give up // give up
return false; $source->timestamp = false;
return $source->exists = false;
} }
/** /**
@@ -152,8 +155,11 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
*/ */
protected function fileExists(Smarty_Template_Source $source, $file) protected function fileExists(Smarty_Template_Source $source, $file)
{ {
$source->timestamp = is_file($file) ? @filemtime($file) : false; if (is_file($file)) {
return $source->exists = !!$source->timestamp; $source->timestamp = filemtime($file);
return $source->exists = true;
}
return false;
} }
/** /**