- bugfix {$smarty.template} in child template did not return right content

- bugfix Smarty3 did not search the PHP include_path for template files
This commit is contained in:
uwe.tews@googlemail.com
2010-12-13 22:05:27 +00:00
parent 73bd60cad5
commit f0c95ab79c
4 changed files with 70 additions and 12 deletions

View File

@@ -1,5 +1,9 @@
===== SVN trunk ===== ===== SVN trunk =====
13/12/2010
- bugfix {$smarty.template} in child template did not return right content
- bugfix Smarty3 did not search the PHP include_path for template files
===== Smarty 3.0.6 ===== ===== Smarty 3.0.6 =====
12/12/2010 12/12/2010

View File

@@ -56,7 +56,7 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C
break; break;
case 'template': case 'template':
$_template_name = $compiler->template->template_resource; $_template_name = basename($compiler->template->getTemplateFilepath());
return "'$_template_name'"; return "'$_template_name'";
case 'current_dir': case 'current_dir':

View File

@@ -0,0 +1,44 @@
<?php
/**
* Smarty read include path plugin
*
* @package Smarty
* @subpackage PluginsInternal
* @author Monte Ohrt
*/
/**
* Smarty Internal Read Include Path Class
*/
class Smarty_Internal_Get_Include_Path {
/**
* Return full file path from PHP include_path
*
* @param string $filepath filepath
* @return mixed full filepath or false
*/
public static function getIncludePath($filepath)
{
static $_path_array = null;
if(!isset($_path_array)) {
$_ini_include_path = ini_get('include_path');
if(strstr($_ini_include_path,';')) {
// windows pathnames
$_path_array = explode(';',$_ini_include_path);
} else {
$_path_array = explode(':',$_ini_include_path);
}
}
foreach ($_path_array as $_include_path) {
if (file_exists($_include_path . DS . $filepath)) {
return $_include_path . DS . $filepath;
}
}
return false;
}
}
?>

View File

@@ -593,17 +593,27 @@ class Smarty_Internal_Template extends Smarty_Internal_Data {
{ {
if ($file == null) { if ($file == null) {
$file = $this->resource_name; $file = $this->resource_name;
} }
foreach((array)$this->smarty->template_dir as $_template_dir) { // relative file name?
if (strpos('/\\', substr($_template_dir, -1)) === false) { if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $file)) {
$_template_dir .= DS; foreach((array)$this->smarty->template_dir as $_template_dir) {
} if (strpos('/\\', substr($_template_dir, -1)) === false) {
$_template_dir .= DS;
$_filepath = $_template_dir . $file; }
if (file_exists($_filepath)) $_filepath = $_template_dir . $file;
return $_filepath; if (file_exists($_filepath)) {
} return $_filepath;
if (file_exists($file)) return $file; }
if (!preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_template_dir)) {
// try PHP include_path
if (($_filepath = Smarty_Internal_Get_Include_Path::getIncludePath($_filepath)) !== false) {
return $_filepath;
}
}
}
}
// try absolute filepath
if (file_exists($file)) return $file;
// no tpl file found // no tpl file found
if (!empty($this->smarty->default_template_handler_func)) { if (!empty($this->smarty->default_template_handler_func)) {
if (!is_callable($this->smarty->default_template_handler_func)) { if (!is_callable($this->smarty->default_template_handler_func)) {