replace {} string access with equivalent substr() to avoid E_STRICT warnings in PHP 5.1

This commit is contained in:
boots
2005-11-23 20:36:05 +00:00
parent 3741b9d6c5
commit fdb25e363f
8 changed files with 31 additions and 29 deletions

4
NEWS
View File

@@ -1,3 +1,5 @@
- replace {} string access with equivalent substr() to avoid E_STRICT
warnings in PHP 5.1 (boots)
- return valid reference in get_config_vars() when given var is - return valid reference in get_config_vars() when given var is
non-existant (Thomas Schulz, boots) non-existant (Thomas Schulz, boots)
- plugin html_image: fix incorrect secure_dir error when - plugin html_image: fix incorrect secure_dir error when
@@ -8,7 +10,7 @@
- return valid reference in get_template_vars() when given var is - return valid reference in get_template_vars() when given var is
non-existant (monte) non-existant (monte)
- add escape type "urlpathinfo" to escape modifier (monte) - add escape type "urlpathinfo" to escape modifier (monte)
Version 2.6.10 (Aug 5, 2005) Version 2.6.10 (Aug 5, 2005)
---------------------------- ----------------------------

View File

@@ -285,9 +285,9 @@ class Config_File {
$line = $lines[$i]; $line = $lines[$i];
if (empty($line)) continue; if (empty($line)) continue;
if ( $line{0} == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) { if ( substr($line, 0, 1) == '[' && preg_match('!^\[(.*?)\]!', $line, $match) ) {
/* section found */ /* section found */
if ($match[1]{0} == '.') { if (substr($match[1], 0, 1) == '.') {
/* hidden section */ /* hidden section */
if ($this->read_hidden) { if ($this->read_hidden) {
$section_name = substr($match[1], 1); $section_name = substr($match[1], 1);
@@ -347,7 +347,7 @@ class Config_File {
*/ */
function _set_config_var(&$container, $var_name, $var_value, $booleanize) function _set_config_var(&$container, $var_name, $var_value, $booleanize)
{ {
if ($var_name{0} == '.') { if (substr($var_name, 0, 1) == '.') {
if (!$this->read_hidden) if (!$this->read_hidden)
return; return;
else else

View File

@@ -1698,8 +1698,8 @@ class Smarty
*/ */
function _dequote($string) function _dequote($string)
{ {
if (($string{0} == "'" || $string{0} == '"') && if ((substr($string, 0, 1) == "'" || substr($string, 0, 1) == '"') &&
$string{strlen($string)-1} == $string{0}) substr($string, -1) == substr($string, 0, 1))
return substr($string, 1, -1); return substr($string, 1, -1);
else else
return $string; return $string;

View File

@@ -361,7 +361,7 @@ class Smarty_Compiler extends Smarty {
$compiled_content .= $text_blocks[$i]; $compiled_content .= $text_blocks[$i];
// remove \n from the end of the file, if any // remove \n from the end of the file, if any
if (($_len=strlen($compiled_content)) && ($compiled_content{$_len - 1} == "\n" )) { if (strlen($compiled_content) && (substr($compiled_content, -1) == "\n") ) {
$compiled_content = substr($compiled_content, 0, -1); $compiled_content = substr($compiled_content, 0, -1);
} }
@@ -425,7 +425,7 @@ class Smarty_Compiler extends Smarty {
function _compile_tag($template_tag) function _compile_tag($template_tag)
{ {
/* Matched comment. */ /* Matched comment. */
if ($template_tag{0} == '*' && $template_tag{strlen($template_tag) - 1} == '*') if (substr($template_tag, 0, 1) == '*' && substr($template_tag, -1) == '*')
return ''; return '';
/* Split tag into two three parts: command, command modifiers and the arguments. */ /* Split tag into two three parts: command, command modifiers and the arguments. */
@@ -529,7 +529,7 @@ class Smarty_Compiler extends Smarty {
case 'strip': case 'strip':
case '/strip': case '/strip':
if ($tag_command{0}=='/') { if (substr($tag_command, 0, 1)=='/') {
$this->_pop_tag('strip'); $this->_pop_tag('strip');
if (--$this->_strip_depth==0) { /* outermost closing {/strip} */ if (--$this->_strip_depth==0) { /* outermost closing {/strip} */
$this->_additional_newline = "\n"; $this->_additional_newline = "\n";
@@ -664,7 +664,7 @@ class Smarty_Compiler extends Smarty {
*/ */
function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output) function _compile_block_tag($tag_command, $tag_args, $tag_modifier, &$output)
{ {
if ($tag_command{0} == '/') { if (substr($tag_command, 0, 1) == '/') {
$start_tag = false; $start_tag = false;
$tag_command = substr($tag_command, 1); $tag_command = substr($tag_command, 1);
} else } else
@@ -826,7 +826,7 @@ class Smarty_Compiler extends Smarty {
*/ */
function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier) function _compile_registered_object_tag($tag_command, $attrs, $tag_modifier)
{ {
if ($tag_command{0} == '/') { if (substr($tag_command, 0, 1) == '/') {
$start_tag = false; $start_tag = false;
$tag_command = substr($tag_command, 1); $tag_command = substr($tag_command, 1);
} else { } else {
@@ -1730,7 +1730,7 @@ class Smarty_Compiler extends Smarty {
} }
// prevent cutting of first digit in the number (we _definitly_ got a number if the first char is a digit) // prevent cutting of first digit in the number (we _definitly_ got a number if the first char is a digit)
if(is_numeric($var_expr{0})) if(is_numeric(substr($var_expr, 0, 1)))
$_var_ref = $var_expr; $_var_ref = $var_expr;
else else
$_var_ref = substr($var_expr, 1); $_var_ref = substr($var_expr, 1);
@@ -1756,7 +1756,7 @@ class Smarty_Compiler extends Smarty {
$_var_name = substr(array_shift($_indexes), 1); $_var_name = substr(array_shift($_indexes), 1);
$_output = "\$this->_smarty_vars['$_var_name']"; $_output = "\$this->_smarty_vars['$_var_name']";
} }
} elseif(is_numeric($_var_name) && is_numeric($var_expr{0})) { } elseif(is_numeric($_var_name) && is_numeric(substr($var_expr, 0, 1))) {
// because . is the operator for accessing arrays thru inidizes we need to put it together again for floating point numbers // because . is the operator for accessing arrays thru inidizes we need to put it together again for floating point numbers
if(count($_indexes) > 0) if(count($_indexes) > 0)
{ {
@@ -1769,11 +1769,11 @@ class Smarty_Compiler extends Smarty {
} }
foreach ($_indexes as $_index) { foreach ($_indexes as $_index) {
if ($_index{0} == '[') { if (substr($_index, 0, 1) == '[') {
$_index = substr($_index, 1, -1); $_index = substr($_index, 1, -1);
if (is_numeric($_index)) { if (is_numeric($_index)) {
$_output .= "[$_index]"; $_output .= "[$_index]";
} elseif ($_index{0} == '$') { } elseif (substr($_index, 0, 1) == '$') {
if (strpos($_index, '.') !== false) { if (strpos($_index, '.') !== false) {
$_output .= '[' . $this->_parse_var($_index) . ']'; $_output .= '[' . $this->_parse_var($_index) . ']';
} else { } else {
@@ -1785,8 +1785,8 @@ class Smarty_Compiler extends Smarty {
$_var_section_prop = isset($_var_parts[1]) ? $_var_parts[1] : 'index'; $_var_section_prop = isset($_var_parts[1]) ? $_var_parts[1] : 'index';
$_output .= "[\$this->_sections['$_var_section']['$_var_section_prop']]"; $_output .= "[\$this->_sections['$_var_section']['$_var_section_prop']]";
} }
} else if ($_index{0} == '.') { } else if (substr($_index, 0, 1) == '.') {
if ($_index{1} == '$') if (substr($_index, 1, 1) == '$')
$_output .= "[\$this->_tpl_vars['" . substr($_index, 2) . "']]"; $_output .= "[\$this->_tpl_vars['" . substr($_index, 2) . "']]";
else else
$_output .= "['" . substr($_index, 1) . "']"; $_output .= "['" . substr($_index, 1) . "']";
@@ -1795,7 +1795,7 @@ class Smarty_Compiler extends Smarty {
$this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__); $this->_syntax_error('call to internal object members is not allowed', E_USER_ERROR, __FILE__, __LINE__);
} elseif($this->security && substr($_index, 2, 1) == '_') { } elseif($this->security && substr($_index, 2, 1) == '_') {
$this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); $this->_syntax_error('(secure) call to private object member is not allowed', E_USER_ERROR, __FILE__, __LINE__);
} elseif ($_index{2} == '$') { } elseif (substr($_index, 2, 1) == '$') {
if ($this->security) { if ($this->security) {
$this->_syntax_error('(secure) call to dynamic object member is not allowed', E_USER_ERROR, __FILE__, __LINE__); $this->_syntax_error('(secure) call to dynamic object member is not allowed', E_USER_ERROR, __FILE__, __LINE__);
} else { } else {
@@ -1804,7 +1804,7 @@ class Smarty_Compiler extends Smarty {
} else { } else {
$_output .= $_index; $_output .= $_index;
} }
} elseif ($_index{0} == '(') { } elseif (substr($_index, 0, 1) == '(') {
$_index = $this->_parse_parenth_args($_index); $_index = $this->_parse_parenth_args($_index);
$_output .= $_index; $_output .= $_index;
} else { } else {
@@ -1901,7 +1901,7 @@ class Smarty_Compiler extends Smarty {
preg_match_all('~:(' . $this->_qstr_regexp . '|[^:]+)~', $modifier_arg_strings[$_i], $_match); preg_match_all('~:(' . $this->_qstr_regexp . '|[^:]+)~', $modifier_arg_strings[$_i], $_match);
$_modifier_args = $_match[1]; $_modifier_args = $_match[1];
if ($_modifier_name{0} == '@') { if (substr($_modifier_name, 0, 1) == '@') {
$_map_array = false; $_map_array = false;
$_modifier_name = substr($_modifier_name, 1); $_modifier_name = substr($_modifier_name, 1);
} else { } else {
@@ -1923,10 +1923,10 @@ class Smarty_Compiler extends Smarty {
if($_modifier_name == 'default') { if($_modifier_name == 'default') {
// supress notifications of default modifier vars and args // supress notifications of default modifier vars and args
if($output{0} == '$') { if(substr($output, 0, 1) == '$') {
$output = '@' . $output; $output = '@' . $output;
} }
if(isset($_modifier_args[0]) && $_modifier_args[0]{0} == '$') { if(isset($_modifier_args[0]) && substr($_modifier_args[0], 0, 1) == '$') {
$_modifier_args[0] = '@' . $_modifier_args[0]; $_modifier_args[0] = '@' . $_modifier_args[0];
} }
} }
@@ -1978,7 +1978,7 @@ class Smarty_Compiler extends Smarty {
/* Extract the reference name. */ /* Extract the reference name. */
$_ref = substr($indexes[0], 1); $_ref = substr($indexes[0], 1);
foreach($indexes as $_index_no=>$_index) { foreach($indexes as $_index_no=>$_index) {
if ($_index{0} != '.' && $_index_no<2 || !preg_match('~^(\.|\[|->)~', $_index)) { if (substr($_index, 0, 1) != '.' && $_index_no<2 || !preg_match('~^(\.|\[|->)~', $_index)) {
$this->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__); $this->_syntax_error('$smarty' . implode('', array_slice($indexes, 0, 2)) . ' is an invalid reference', E_USER_ERROR, __FILE__, __LINE__);
} }
} }

View File

@@ -22,7 +22,7 @@ function smarty_core_create_dir_structure($params, &$smarty)
/* unix-style paths */ /* unix-style paths */
$_dir = $params['dir']; $_dir = $params['dir'];
$_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY); $_dir_parts = preg_split('!/+!', $_dir, -1, PREG_SPLIT_NO_EMPTY);
$_new_dir = ($_dir{0}=='/') ? '/' : getcwd().'/'; $_new_dir = (substr($_dir, 0, 1)=='/') ? '/' : getcwd().'/';
if($_use_open_basedir = !empty($_open_basedir_ini)) { if($_use_open_basedir = !empty($_open_basedir_ini)) {
$_open_basedirs = explode(':', $_open_basedir_ini); $_open_basedirs = explode(':', $_open_basedir_ini);
} }

View File

@@ -27,7 +27,7 @@ function smarty_core_is_secure($params, &$smarty)
foreach ((array)$params['resource_base_path'] as $curr_dir) { foreach ((array)$params['resource_base_path'] as $curr_dir) {
if ( ($_cd = realpath($curr_dir)) !== false && if ( ($_cd = realpath($curr_dir)) !== false &&
strncmp($_rp, $_cd, strlen($_cd)) == 0 && strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
$_rp{strlen($_cd)} == DIRECTORY_SEPARATOR ) { substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) {
return true; return true;
} }
} }
@@ -38,7 +38,7 @@ function smarty_core_is_secure($params, &$smarty)
if($_cd == $_rp) { if($_cd == $_rp) {
return true; return true;
} elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 && } elseif (strncmp($_rp, $_cd, strlen($_cd)) == 0 &&
$_rp{strlen($_cd)} == DIRECTORY_SEPARATOR) { substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR) {
return true; return true;
} }
} }

View File

@@ -25,7 +25,7 @@ function smarty_core_is_trusted($params, &$smarty)
if (!empty($curr_dir) && is_readable ($curr_dir)) { if (!empty($curr_dir) && is_readable ($curr_dir)) {
$_cd = realpath($curr_dir); $_cd = realpath($curr_dir);
if (strncmp($_rp, $_cd, strlen($_cd)) == 0 if (strncmp($_rp, $_cd, strlen($_cd)) == 0
&& $_rp{strlen($_cd)} == DIRECTORY_SEPARATOR ) { && substr($_rp, strlen($_cd), 1) == DIRECTORY_SEPARATOR ) {
$_smarty_trusted = true; $_smarty_trusted = true;
break; break;
} }

View File

@@ -72,13 +72,13 @@ function smarty_modifier_escape($string, $esc_type = 'html', $char_set = 'ISO-88
// escape non-standard chars, such as ms document quotes // escape non-standard chars, such as ms document quotes
$_res = ''; $_res = '';
for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) { for($_i = 0, $_len = strlen($string); $_i < $_len; $_i++) {
$_ord = ord($string{$_i}); $_ord = ord(substr($string, $_i, 1));
// non-standard char, escape it // non-standard char, escape it
if($_ord >= 126){ if($_ord >= 126){
$_res .= '&#' . $_ord . ';'; $_res .= '&#' . $_ord . ';';
} }
else { else {
$_res .= $string{$_i}; $_res .= substr($string, $_i, 1);
} }
} }
return $_res; return $_res;