- new feature multiple indices on file: resource

This commit is contained in:
Uwe Tews
2015-07-07 18:18:19 +02:00
parent 1e4f28da54
commit 40f0dda0e6
4 changed files with 50 additions and 28 deletions

View File

@@ -4,6 +4,20 @@ This file contains a brief description of new features which have been added to
Smarty 3.1.28
Modifier regex_replace
======================
An optional limit parameter was added
fetch() and display()
=====================
The fetch() and display() methods of the template object accept now optionally the same paramter
as the corresponding Smarty methods the get tne content of another template.
File: resource
==============
Multiple template_dir entries can now be selected by a comma separated list of indices.
The template_dir array is searched in the order of the indices. (could be used to change the default search order)
Filter support
==============
Optional filter names

View File

@@ -2,6 +2,8 @@
07.07.2015
- improvement allow fetch() or display() called on a template object to get output from other template
like $template->fetch('foo.tpl') https://github.com/smarty-php/smarty/issues/70
- improvement Added $limit parameter to regex_replace modifier #71
- new feature multiple indices on file: resource
06.07.2015
- optimize {block} compilation

View File

@@ -111,7 +111,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.28-dev/25';
const SMARTY_VERSION = '3.1.28-dev/26';
/**
* define variable scopes
@@ -1396,8 +1396,10 @@ class Smarty extends Smarty_Internal_TemplateBase
if ($realpath !== null && $path[0] !== '/' && $path[1] !== ':') {
$path = getcwd() . DS . $path;
}
while (preg_match(isset($pattern) ? $pattern : $pattern = '#([\\\/][.]+[\\\/])|[' . (DS == '/' ? '\\\\' : '/') . ']|[\\\/]{2,}#', $path)) {
$path = preg_replace(isset($pattern2) ? $pattern2 : $pattern2 = '#([\\\/]+([.][\\\/]+)+)|([\\\/]+([^\\\/]+[\\\/]+){2}([.][.][\\\/]+){2})|([\\\/]+[^\\\/]+[\\\/]+[.][.][\\\/]+)|[\\\/]{2,}|[' . (DS == '/' ? '\\\\' : '/') . ']+#', DS, $path);
while (preg_match(isset($pattern) ? $pattern : $pattern = '#([\\\/][.]+[\\\/])|[' . (DS == '/' ? '\\\\' : '/') .
']|[\\\/]{2,}#', $path)) {
$path = preg_replace(isset($pattern2) ? $pattern2 : $pattern2 = '#([\\\/]+([.][\\\/]+)+)|([\\\/]+([^\\\/]+[\\\/]+){2}([.][.][\\\/]+){2})|([\\\/]+[^\\\/]+[\\\/]+[.][.][\\\/]+)|[\\\/]{2,}|[' .
(DS == '/' ? '\\\\' : '/') . ']+#', DS, $path);
}
if ($realpath === false && ($path[0] == '/' || $path[1] == ':')) {
$path = str_ireplace(getcwd(), '.', $path);

View File

@@ -53,31 +53,33 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
$_directories = $source->smarty->getTemplateDir(null, $source->isConfig);
// template_dir index?
if ($file[0] == '[' && preg_match('#^\[([^\]]+)\](.+)$#', $file, $fileMatch)) {
$index = $fileMatch[1];
$_directory = null;
// try string indexes
if (isset($_directories[$index])) {
$_directory = $_directories[$index];
} elseif (is_numeric($index)) {
// try numeric index
$index = (int) $index;
$file = $fileMatch[2];
$_indices = explode(',', $fileMatch[1]);
$_index_dirs = array();
foreach ($_indices as $index) {
$index = trim($index);
// try string indexes
if (isset($_directories[$index])) {
$_directory = $_directories[$index];
} else {
// try at location index
$keys = array_keys($_directories);
$_directory = $_directories[$keys[$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 ($_directory) {
$path = $_directory . $fileMatch[2];
$path = $source->smarty->_realpath($path);
if (is_file($path)) {
return $path;
}
} else {
if (empty($_index_dirs)) {
// index not found
return false;
} else {
$_directories = $_index_dirs;
}
}
@@ -85,13 +87,15 @@ class Smarty_Internal_Resource_File extends Smarty_Resource
foreach ($_directories as $_directory) {
$path = $_directory . $file;
if (is_file($path)) {
return $source->smarty->_realpath($path, true);
return $source->smarty->_realpath($path);
}
}
// Could be relative to cwd
$path = $source->smarty->_realpath($file);
if (is_file($path)) {
return $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) {