Fixed directory separtor issue. Requiring PHP 4.0.6 now.

This commit is contained in:
andrei
2002-04-11 20:27:04 +00:00
parent f20a6be33d
commit dfd5ad93e9
9 changed files with 64 additions and 61 deletions

2
BUGS
View File

@@ -8,7 +8,7 @@ statements, you will need PHP 4.0.4 or later, which requires the use of
get_defined_vars() function. Some versions of Windows 2k have a problem with get_defined_vars() function. Some versions of Windows 2k have a problem with
flock(). Comment out the flock() command in _write_file to get around this. flock(). Comment out the flock() command in _write_file to get around this.
To be absolutely safe, use 4.0.4pl or later with Smarty. To be absolutely safe, use 4.0.6 or later with Smarty.
Smarty versions previous to 2.0 require the PEAR libraries. Be sure to include Smarty versions previous to 2.0 require the PEAR libraries. Be sure to include
the path to the PEAR libraries in your php include_path. Config_file.class.php the path to the PEAR libraries in your php include_path. Config_file.class.php

8
FAQ
View File

@@ -143,21 +143,21 @@ TROUBLESHOOTING
--------------- ---------------
Q: Smarty doesn't work. Q: Smarty doesn't work.
A: You must be using PHP 4.0.4pl1 or later to fix all known problems A: You must be using PHP 4.0.6 or later if you use any version of Smarty
Smarty has with PHP. Read the BUGS file for more info. past 2.0.1. Read the BUGS file for more info.
Q: I get the following error when running Smarty: Q: I get the following error when running Smarty:
Warning: Wrong parameter count for preg_replace() in Warning: Wrong parameter count for preg_replace() in
Smarty.class.php on line 371 Smarty.class.php on line 371
A: preg_replace had a parameter added in PHP 4.0.2 that Smarty A: preg_replace had a parameter added in PHP 4.0.2 that Smarty
requires. Upgrade to at least 4.0.4pl to fix all known PHP issues with requires. Upgrade to at least 4.0.6 to fix all known PHP issues with
Smarty. Smarty.
Q: I get this error when passing variables to {include}: Q: I get this error when passing variables to {include}:
Fatal error: Call to undefined function: get_defined_vars() in Fatal error: Call to undefined function: get_defined_vars() in
/path/to/Smarty/templates_c/index.tpl.php on line 8 /path/to/Smarty/templates_c/index.tpl.php on line 8
A: get_defined_vars() was added to PHP 4.0.4. If you plan on passing A: get_defined_vars() was added to PHP 4.0.4. If you plan on passing
variables to included templates, you will need PHP 4.0.4 or later. variables to included templates, you will need PHP 4.0.6 or later.
Q: I get PHP errors in my {if} tag logic. Q: I get PHP errors in my {if} tag logic.
A: All conditional qualifiers must be separated by spaces. This syntax will not A: All conditional qualifiers must be separated by spaces. This syntax will not

View File

@@ -1,8 +1,6 @@
REQUIREMENTS: REQUIREMENTS:
Smarty requires PHP 4.0.4pl1 or later to fix all known problems Smarty has with Smarty requires PHP 4.0.6 or later.
PHP. Smarty was developed and tested with PHP versions >= 4.0.4pl1. See the
BUGS file for more info.
INSTALLATION: INSTALLATION:

1
NEWS
View File

@@ -1,3 +1,4 @@
- fixed directory separator issue for Windows. (Andrei)
- added ability to use simple variables as array indices or - added ability to use simple variables as array indices or
object properties. (Andrei) object properties. (Andrei)
- added ability to unregister pre/postfilters plugins at - added ability to unregister pre/postfilters plugins at

View File

@@ -44,8 +44,10 @@
// set SMARTY_DIR to absolute path to Smarty library files. // set SMARTY_DIR to absolute path to Smarty library files.
// if not defined, include_path will be used. // if not defined, include_path will be used.
define('DIR_SEP', DIRECTORY_SEPARATOR);
if (!defined('SMARTY_DIR')) { if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', dirname(__FILE__) . '/'); define('SMARTY_DIR', dirname(__FILE__) . DIR_SEP);
} }
define('SMARTY_PHP_PASSTHRU', 0); define('SMARTY_PHP_PASSTHRU', 0);
@@ -62,9 +64,9 @@ class Smarty
/**************************************************************************/ /**************************************************************************/
// public vars // public vars
var $template_dir = './templates'; // name of directory for templates var $template_dir = 'templates'; // name of directory for templates
var $compile_dir = './templates_c'; // name of directory for compiled templates var $compile_dir = 'templates_c'; // name of directory for compiled templates
var $config_dir = './configs'; // directory where config files are located var $config_dir = 'configs'; // directory where config files are located
var $plugins_dir = 'plugins'; // directory where plugins are kept var $plugins_dir = 'plugins'; // directory where plugins are kept
// (relative to Smarty directory) // (relative to Smarty directory)
@@ -91,7 +93,7 @@ class Smarty
// overrides cache settings. default false. // overrides cache settings. default false.
var $caching = false; // enable caching. true/false default false. var $caching = false; // enable caching. true/false default false.
var $cache_dir = './cache'; // name of directory for template cache files var $cache_dir = 'cache'; // name of directory for template cache files
var $cache_lifetime = 3600; // number of seconds cached content will persist. var $cache_lifetime = 3600; // number of seconds cached content will persist.
// 0 = never expires. default is one hour (3600) // 0 = never expires. default is one hour (3600)
var $cache_handler_func = null; // function used for cached content. this is var $cache_handler_func = null; // function used for cached content. this is
@@ -113,7 +115,7 @@ class Smarty
var $security = false; // enable template security (default false) var $security = false; // enable template security (default false)
var $secure_dir = array('./templates'); // array of directories considered secure var $secure_dir = array('templates'); // array of directories considered secure
var $security_settings = array( var $security_settings = array(
'PHP_HANDLING' => false, 'PHP_HANDLING' => false,
'IF_FUNCS' => array('array', 'list', 'IF_FUNCS' => array('array', 'list',
@@ -873,8 +875,8 @@ function _generate_debug_output() {
// relative pathname to $file_base_path // relative pathname to $file_base_path
// use the first directory where the file is found // use the first directory where the file is found
foreach ((array)$file_base_path as $curr_path) { foreach ((array)$file_base_path as $curr_path) {
if (@is_file($curr_path.'/'.$resource_name)) { if (@is_file($curr_path.DIR_SEP.$resource_name)) {
$resource_name = $curr_path.'/'.$resource_name; $resource_name = $curr_path.DIR_SEP.$resource_name;
return true; return true;
} }
} }
@@ -1323,8 +1325,8 @@ function _run_insert_handler($args)
function _get_auto_filename($auto_base, $auto_source, $auto_id = null) function _get_auto_filename($auto_base, $auto_source, $auto_id = null)
{ {
$source_hash = str_replace('-','N',crc32($auto_source)); $source_hash = str_replace('-','N',crc32($auto_source));
$res = $auto_base . '/' . substr($source_hash, 0, 3) . '/' . $res = $auto_base . DIR_SEP . substr($source_hash, 0, 3) . DIR_SEP .
$source_hash . '/' . str_replace('-','N',crc32($auto_id)) . '.php'; $source_hash . DIR_SEP . str_replace('-','N',crc32($auto_id)) . '.php';
return $res; return $res;
} }
@@ -1346,7 +1348,7 @@ function _run_insert_handler($args)
$res = is_file($tname) && unlink( $tname); $res = is_file($tname) && unlink( $tname);
} else { } else {
$source_hash = str_replace('-','N',crc32($auto_source)); $source_hash = str_replace('-','N',crc32($auto_source));
$tname = $auto_base . '/' . substr($source_hash, 0, 3) . '/' . $source_hash; $tname = $auto_base . DIR_SEP . substr($source_hash, 0, 3) . DIR_SEP . $source_hash;
$res = $this->_rmdir($tname); $res = $this->_rmdir($tname);
} }
} }
@@ -1365,11 +1367,11 @@ function _run_insert_handler($args)
while ($entry = readdir($handle)) { while ($entry = readdir($handle)) {
if ($entry != '.' && $entry != '..') { if ($entry != '.' && $entry != '..') {
if (is_dir($dirname . '/' . $entry)) { if (is_dir($dirname . DIR_SEP . $entry)) {
$this->_rmdir($dirname . '/' . $entry, $level + 1); $this->_rmdir($dirname . DIR_SEP . $entry, $level + 1);
} }
else { else {
unlink($dirname . '/' . $entry); unlink($dirname . DIR_SEP . $entry);
} }
} }
} }
@@ -1389,15 +1391,15 @@ function _run_insert_handler($args)
function _create_dir_structure($dir) function _create_dir_structure($dir)
{ {
if (!file_exists($dir)) { if (!file_exists($dir)) {
$dir_parts = preg_split('!/+!', $dir, -1, PREG_SPLIT_NO_EMPTY); $dir_parts = preg_split('!\\'.DIR_SEP.'+!', $dir, -1, PREG_SPLIT_NO_EMPTY);
$new_dir = ($dir{0} == '/') ? '/' : ''; $new_dir = ($dir{0} == DIR_SEP) ? DIR_SEP : '';
foreach ($dir_parts as $dir_part) { foreach ($dir_parts as $dir_part) {
$new_dir .= $dir_part; $new_dir .= $dir_part;
if (!file_exists($new_dir) && !mkdir($new_dir, 0771)) { if (!file_exists($new_dir) && !mkdir($new_dir, 0771)) {
$this->trigger_error("problem creating directory \"$dir\""); $this->trigger_error("problem creating directory \"$dir\"");
return false; return false;
} }
$new_dir .= '/'; $new_dir .= DIR_SEP;
} }
} }
} }
@@ -1492,7 +1494,7 @@ function _run_insert_handler($args)
if (isset($this->_cache_info['config'])) { if (isset($this->_cache_info['config'])) {
foreach ($this->_cache_info['config'] as $config_dep) { foreach ($this->_cache_info['config'] as $config_dep) {
if ($this->_cache_info['timestamp'] < filemtime($this->config_dir.'/'.$config_dep)) { if ($this->_cache_info['timestamp'] < filemtime($this->config_dir.DIR_SEP.$config_dep)) {
// config file has changed, regenerate cache // config file has changed, regenerate cache
return false; return false;
} }
@@ -1552,7 +1554,7 @@ function _run_insert_handler($args)
$plugin_file = SMARTY_DIR . $plugin_file = SMARTY_DIR .
$this->plugins_dir . $this->plugins_dir .
'/' . DIR_SEP .
$type . $type .
'.' . '.' .
$name . $name .
@@ -1657,8 +1659,8 @@ function _run_insert_handler($args)
} }
$plugin_file = SMARTY_DIR . $plugin_file = SMARTY_DIR .
$this->plugins_dir . $this->plugins_dir . DIR_SEP .
'/resource.' . 'resource.' .
$type . $type .
'.php'; '.php';

View File

@@ -353,8 +353,8 @@ class Smarty_Compiler extends Smarty {
$have_function = true; $have_function = true;
$plugin_file = SMARTY_DIR . $plugin_file = SMARTY_DIR .
$this->plugins_dir . $this->plugins_dir . DIR_SEP .
'/compiler.' . 'compiler.' .
$tag_command . $tag_command .
'.php'; '.php';
@@ -423,8 +423,8 @@ class Smarty_Compiler extends Smarty {
$have_function = true; $have_function = true;
$plugin_file = SMARTY_DIR . $plugin_file = SMARTY_DIR .
$this->plugins_dir . $this->plugins_dir . DIR_SEP .
'/block.' . 'block.' .
$tag_command . $tag_command .
'.php'; '.php';
@@ -1375,7 +1375,7 @@ class Smarty_Compiler extends Smarty {
$this->_plugins[$parts[0]][$parts[1]] === false)) $this->_plugins[$parts[0]][$parts[1]] === false))
continue; continue;
$plugin_file = $plugins_dir . '/' . $entry; $plugin_file = $plugins_dir . DIR_SEP . $entry;
include_once $plugin_file; include_once $plugin_file;
$plugin_func = 'smarty_' . $parts[0] . '_' . $parts[1]; $plugin_func = 'smarty_' . $parts[0] . '_' . $parts[1];
if (!function_exists($plugin_func)) { if (!function_exists($plugin_func)) {

View File

@@ -108,7 +108,7 @@
<sect1 id="installation.requirements"> <sect1 id="installation.requirements">
<title>Requirements</title> <title>Requirements</title>
<para> <para>
Smarty requires PHP 4.0.4pl1 or later. See the Smarty requires PHP 4.0.6 or later. See the
<link linkend="bugs">BUGS</link> section for caveats. <link linkend="bugs">BUGS</link> section for caveats.
</para> </para>
</sect1> </sect1>

View File

@@ -44,8 +44,10 @@
// set SMARTY_DIR to absolute path to Smarty library files. // set SMARTY_DIR to absolute path to Smarty library files.
// if not defined, include_path will be used. // if not defined, include_path will be used.
define('DIR_SEP', DIRECTORY_SEPARATOR);
if (!defined('SMARTY_DIR')) { if (!defined('SMARTY_DIR')) {
define('SMARTY_DIR', dirname(__FILE__) . '/'); define('SMARTY_DIR', dirname(__FILE__) . DIR_SEP);
} }
define('SMARTY_PHP_PASSTHRU', 0); define('SMARTY_PHP_PASSTHRU', 0);
@@ -62,9 +64,9 @@ class Smarty
/**************************************************************************/ /**************************************************************************/
// public vars // public vars
var $template_dir = './templates'; // name of directory for templates var $template_dir = 'templates'; // name of directory for templates
var $compile_dir = './templates_c'; // name of directory for compiled templates var $compile_dir = 'templates_c'; // name of directory for compiled templates
var $config_dir = './configs'; // directory where config files are located var $config_dir = 'configs'; // directory where config files are located
var $plugins_dir = 'plugins'; // directory where plugins are kept var $plugins_dir = 'plugins'; // directory where plugins are kept
// (relative to Smarty directory) // (relative to Smarty directory)
@@ -91,7 +93,7 @@ class Smarty
// overrides cache settings. default false. // overrides cache settings. default false.
var $caching = false; // enable caching. true/false default false. var $caching = false; // enable caching. true/false default false.
var $cache_dir = './cache'; // name of directory for template cache files var $cache_dir = 'cache'; // name of directory for template cache files
var $cache_lifetime = 3600; // number of seconds cached content will persist. var $cache_lifetime = 3600; // number of seconds cached content will persist.
// 0 = never expires. default is one hour (3600) // 0 = never expires. default is one hour (3600)
var $cache_handler_func = null; // function used for cached content. this is var $cache_handler_func = null; // function used for cached content. this is
@@ -113,7 +115,7 @@ class Smarty
var $security = false; // enable template security (default false) var $security = false; // enable template security (default false)
var $secure_dir = array('./templates'); // array of directories considered secure var $secure_dir = array('templates'); // array of directories considered secure
var $security_settings = array( var $security_settings = array(
'PHP_HANDLING' => false, 'PHP_HANDLING' => false,
'IF_FUNCS' => array('array', 'list', 'IF_FUNCS' => array('array', 'list',
@@ -873,8 +875,8 @@ function _generate_debug_output() {
// relative pathname to $file_base_path // relative pathname to $file_base_path
// use the first directory where the file is found // use the first directory where the file is found
foreach ((array)$file_base_path as $curr_path) { foreach ((array)$file_base_path as $curr_path) {
if (@is_file($curr_path.'/'.$resource_name)) { if (@is_file($curr_path.DIR_SEP.$resource_name)) {
$resource_name = $curr_path.'/'.$resource_name; $resource_name = $curr_path.DIR_SEP.$resource_name;
return true; return true;
} }
} }
@@ -1323,8 +1325,8 @@ function _run_insert_handler($args)
function _get_auto_filename($auto_base, $auto_source, $auto_id = null) function _get_auto_filename($auto_base, $auto_source, $auto_id = null)
{ {
$source_hash = str_replace('-','N',crc32($auto_source)); $source_hash = str_replace('-','N',crc32($auto_source));
$res = $auto_base . '/' . substr($source_hash, 0, 3) . '/' . $res = $auto_base . DIR_SEP . substr($source_hash, 0, 3) . DIR_SEP .
$source_hash . '/' . str_replace('-','N',crc32($auto_id)) . '.php'; $source_hash . DIR_SEP . str_replace('-','N',crc32($auto_id)) . '.php';
return $res; return $res;
} }
@@ -1346,7 +1348,7 @@ function _run_insert_handler($args)
$res = is_file($tname) && unlink( $tname); $res = is_file($tname) && unlink( $tname);
} else { } else {
$source_hash = str_replace('-','N',crc32($auto_source)); $source_hash = str_replace('-','N',crc32($auto_source));
$tname = $auto_base . '/' . substr($source_hash, 0, 3) . '/' . $source_hash; $tname = $auto_base . DIR_SEP . substr($source_hash, 0, 3) . DIR_SEP . $source_hash;
$res = $this->_rmdir($tname); $res = $this->_rmdir($tname);
} }
} }
@@ -1365,11 +1367,11 @@ function _run_insert_handler($args)
while ($entry = readdir($handle)) { while ($entry = readdir($handle)) {
if ($entry != '.' && $entry != '..') { if ($entry != '.' && $entry != '..') {
if (is_dir($dirname . '/' . $entry)) { if (is_dir($dirname . DIR_SEP . $entry)) {
$this->_rmdir($dirname . '/' . $entry, $level + 1); $this->_rmdir($dirname . DIR_SEP . $entry, $level + 1);
} }
else { else {
unlink($dirname . '/' . $entry); unlink($dirname . DIR_SEP . $entry);
} }
} }
} }
@@ -1389,15 +1391,15 @@ function _run_insert_handler($args)
function _create_dir_structure($dir) function _create_dir_structure($dir)
{ {
if (!file_exists($dir)) { if (!file_exists($dir)) {
$dir_parts = preg_split('!/+!', $dir, -1, PREG_SPLIT_NO_EMPTY); $dir_parts = preg_split('!\\'.DIR_SEP.'+!', $dir, -1, PREG_SPLIT_NO_EMPTY);
$new_dir = ($dir{0} == '/') ? '/' : ''; $new_dir = ($dir{0} == DIR_SEP) ? DIR_SEP : '';
foreach ($dir_parts as $dir_part) { foreach ($dir_parts as $dir_part) {
$new_dir .= $dir_part; $new_dir .= $dir_part;
if (!file_exists($new_dir) && !mkdir($new_dir, 0771)) { if (!file_exists($new_dir) && !mkdir($new_dir, 0771)) {
$this->trigger_error("problem creating directory \"$dir\""); $this->trigger_error("problem creating directory \"$dir\"");
return false; return false;
} }
$new_dir .= '/'; $new_dir .= DIR_SEP;
} }
} }
} }
@@ -1492,7 +1494,7 @@ function _run_insert_handler($args)
if (isset($this->_cache_info['config'])) { if (isset($this->_cache_info['config'])) {
foreach ($this->_cache_info['config'] as $config_dep) { foreach ($this->_cache_info['config'] as $config_dep) {
if ($this->_cache_info['timestamp'] < filemtime($this->config_dir.'/'.$config_dep)) { if ($this->_cache_info['timestamp'] < filemtime($this->config_dir.DIR_SEP.$config_dep)) {
// config file has changed, regenerate cache // config file has changed, regenerate cache
return false; return false;
} }
@@ -1552,7 +1554,7 @@ function _run_insert_handler($args)
$plugin_file = SMARTY_DIR . $plugin_file = SMARTY_DIR .
$this->plugins_dir . $this->plugins_dir .
'/' . DIR_SEP .
$type . $type .
'.' . '.' .
$name . $name .
@@ -1657,8 +1659,8 @@ function _run_insert_handler($args)
} }
$plugin_file = SMARTY_DIR . $plugin_file = SMARTY_DIR .
$this->plugins_dir . $this->plugins_dir . DIR_SEP .
'/resource.' . 'resource.' .
$type . $type .
'.php'; '.php';

View File

@@ -353,8 +353,8 @@ class Smarty_Compiler extends Smarty {
$have_function = true; $have_function = true;
$plugin_file = SMARTY_DIR . $plugin_file = SMARTY_DIR .
$this->plugins_dir . $this->plugins_dir . DIR_SEP .
'/compiler.' . 'compiler.' .
$tag_command . $tag_command .
'.php'; '.php';
@@ -423,8 +423,8 @@ class Smarty_Compiler extends Smarty {
$have_function = true; $have_function = true;
$plugin_file = SMARTY_DIR . $plugin_file = SMARTY_DIR .
$this->plugins_dir . $this->plugins_dir . DIR_SEP .
'/block.' . 'block.' .
$tag_command . $tag_command .
'.php'; '.php';
@@ -1375,7 +1375,7 @@ class Smarty_Compiler extends Smarty {
$this->_plugins[$parts[0]][$parts[1]] === false)) $this->_plugins[$parts[0]][$parts[1]] === false))
continue; continue;
$plugin_file = $plugins_dir . '/' . $entry; $plugin_file = $plugins_dir . DIR_SEP . $entry;
include_once $plugin_file; include_once $plugin_file;
$plugin_func = 'smarty_' . $parts[0] . '_' . $parts[1]; $plugin_func = 'smarty_' . $parts[0] . '_' . $parts[1];
if (!function_exists($plugin_func)) { if (!function_exists($plugin_func)) {