From e91ee4c5ec4acb32df0f29360a82c04810e8939c Mon Sep 17 00:00:00 2001 From: rodneyrehm Date: Mon, 6 Feb 2012 20:45:10 +0000 Subject: [PATCH] improved include_path resolving --- libs/Smarty.class.php | 10 +++++++- libs/sysplugins/smarty_internal_utility.php | 26 ++++++++++++++++++--- libs/sysplugins/smarty_resource.php | 10 +++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index b129aa97..e65f4920 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1277,6 +1277,8 @@ class Smarty extends Smarty_Internal_TemplateBase { } // plugin filename is expected to be: [type].[name].php $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php"; + + $_stream_resolve_include_path = function_exists('stream_resolve_include_path'); // loop through plugin dirs and find the plugin foreach($this->getPluginsDir() as $_plugin_dir) { @@ -1291,7 +1293,13 @@ class Smarty extends Smarty_Internal_TemplateBase { } if ($this->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) { // try PHP include_path - if (($file = Smarty_Internal_Get_Include_Path::getIncludePath($file)) !== false) { + if ($_stream_resolve_include_path) { + $file = stream_resolve_include_path($file); + } else { + $file = Smarty_Internal_Get_Include_Path::getIncludePath($file); + } + + if ($file !== false) { require_once($file); return $file; } diff --git a/libs/sysplugins/smarty_internal_utility.php b/libs/sysplugins/smarty_internal_utility.php index 5e742034..c8c2b6dc 100644 --- a/libs/sysplugins/smarty_internal_utility.php +++ b/libs/sysplugins/smarty_internal_utility.php @@ -299,6 +299,8 @@ class Smarty_Internal_Utility { echo "Smarty Installation test...\n"; echo "Testing template directory...\n"; } + + $_stream_resolve_include_path = function_exists('stream_resolve_include_path'); // test if all registered template_dir are accessible foreach($smarty->getTemplateDir() as $template_dir) { @@ -308,7 +310,13 @@ class Smarty_Internal_Utility { if (!$template_dir) { if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) { // try PHP include_path - if (($template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir)) !== false) { + if ($_stream_resolve_include_path) { + $template_dir = stream_resolve_include_path($_template_dir); + } else { + $template_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_template_dir); + } + + if ($template_dir !== false) { if ($errors === null) { echo "$template_dir is OK.\n"; } @@ -423,7 +431,13 @@ class Smarty_Internal_Utility { if (!$plugin_dir) { if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) { // try PHP include_path - if (($plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir)) !== false) { + if ($_stream_resolve_include_path) { + $plugin_dir = stream_resolve_include_path($_plugin_dir); + } else { + $plugin_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_plugin_dir); + } + + if ($plugin_dir !== false) { if ($errors === null) { echo "$plugin_dir is OK.\n"; } @@ -549,7 +563,13 @@ class Smarty_Internal_Utility { if (!$config_dir) { if ($smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_config_dir)) { // try PHP include_path - if (($config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir)) !== false) { + if ($_stream_resolve_include_path) { + $config_dir = stream_resolve_include_path($_config_dir); + } else { + $config_dir = Smarty_Internal_Get_Include_Path::getIncludePath($_config_dir); + } + + if ($config_dir !== false) { if ($errors === null) { echo "$config_dir is OK.\n"; } diff --git a/libs/sysplugins/smarty_resource.php b/libs/sysplugins/smarty_resource.php index f8285e62..7c1cea13 100644 --- a/libs/sysplugins/smarty_resource.php +++ b/libs/sysplugins/smarty_resource.php @@ -254,6 +254,8 @@ abstract class Smarty_Resource { } } } + + $_stream_resolve_include_path = function_exists('stream_resolve_include_path'); // relative file name? if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) { @@ -264,7 +266,13 @@ abstract class Smarty_Resource { } if ($source->smarty->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_directory)) { // try PHP include_path - if (($_filepath = Smarty_Internal_Get_Include_Path::getIncludePath($_filepath)) !== false) { + if ($_stream_resolve_include_path) { + $_filepath = stream_resolve_include_path($_filepath); + } else { + $_filepath = Smarty_Internal_Get_Include_Path::getIncludePath($_filepath); + } + + if ($_filepath !== false) { if ($this->fileExists($source, $_filepath)) { return $_filepath; }