From 6913351af7c6ca1688a1db0888acd657d8764990 Mon Sep 17 00:00:00 2001 From: dougk_ff7 Date: Sun, 6 Oct 2002 00:47:46 +0000 Subject: [PATCH] This is an attempt to remove problems with "file_exists()" calls in later versions of PHP. From what I can tell, PHP requires a full path to file_exists() in newer versions, and realpath() will fix it. I noticed that file_exists() doesn't need to have a full path passed to it in older versions, so I just made a fake function, realpath() that will only define itself if realpath() isn't defined. It may or may not work, it seems to work here on PHP 4.2.3, but if it breaks older versions, please *LET ME KNOW* or change it. Because I changed this so quickly, I don't know if everything works exactly. Really, PM or email me if it doesn't. Cross your fingers! :D Thanks! dougk_ff7 dougk_ff7@phpbb.com git-svn-id: file:///svn/phpbb/branches/phpBB-2_0_0@2935 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/admin/admin_styles.php | 2 +- phpBB/admin/admin_users.php | 12 ++++++------ phpBB/includes/emailer.php | 3 ++- phpBB/includes/functions.php | 23 +++++++++++++++++++---- phpBB/includes/template.php | 2 +- phpBB/includes/usercp_avatar.php | 8 ++++---- phpBB/includes/usercp_register.php | 6 +++--- phpBB/install.php | 2 +- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/phpBB/admin/admin_styles.php b/phpBB/admin/admin_styles.php index d175bb2ef0..4986b86ec0 100644 --- a/phpBB/admin/admin_styles.php +++ b/phpBB/admin/admin_styles.php @@ -136,7 +136,7 @@ switch( $mode ) { if( !is_file($phpbb_root_path . 'templates/' .$sub_dir) && !is_link($phpbb_root_path . 'templates/' .$sub_dir) && $sub_dir != "." && $sub_dir != ".." && $sub_dir != "CVS" ) { - if( @file_exists($phpbb_root_path. "templates/" . $sub_dir . "/theme_info.cfg") ) + if( @file_exists(@realpath($phpbb_root_path. "templates/" . $sub_dir . "/theme_info.cfg")) ) { include($phpbb_root_path. "templates/" . $sub_dir . "/theme_info.cfg"); diff --git a/phpBB/admin/admin_users.php b/phpBB/admin/admin_users.php index c57b6a97ff..fd1dcc0ba8 100644 --- a/phpBB/admin/admin_users.php +++ b/phpBB/admin/admin_users.php @@ -231,7 +231,7 @@ if( $mode == 'edit' || $mode == 'save' && ( isset($HTTP_POST_VARS['username']) | { if( $this_userdata['user_avatar_type'] == USER_AVATAR_UPLOAD && $this_userdata['user_avatar'] != "" ) { - if( @file_exists("./" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']) ) + if( @file_exists(@realpath("./" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) ) { @unlink("./" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']); } @@ -256,7 +256,7 @@ if( $mode == 'edit' || $mode == 'save' && ( isset($HTTP_POST_VARS['username']) | if( $user_avatar_loc != "" ) { - if( file_exists($user_avatar_loc) && ereg(".jpg$|.gif$|.png$", $user_avatar_name) ) + if( file_exists(@realpath($user_avatar_loc)) && ereg(".jpg$|.gif$|.png$", $user_avatar_name) ) { if( $user_avatar_size <= $board_config['avatar_filesize'] && $avatar_size > 0) { @@ -299,7 +299,7 @@ if( $mode == 'edit' || $mode == 'save' && ( isset($HTTP_POST_VARS['username']) | if( $this_userdata['user_avatar_type'] == USER_AVATAR_UPLOAD && $this_userdata['user_avatar'] != "" ) { - if( @file_exists("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']) ) + if( @file_exists(@realpath("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) ) { @unlink("./../" . $board_config['avatar_path'] . "/". $this_userdata['user_avatar']); } @@ -408,7 +408,7 @@ if( $mode == 'edit' || $mode == 'save' && ( isset($HTTP_POST_VARS['username']) | if( $this_userdata['user_avatar_type'] == USER_AVATAR_UPLOAD && $this_userdata['user_avatar'] != "") { - if( file_exists("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']) ) + if( file_exists(@realpath("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar'])) ) { @unlink("./../" . $board_config['avatar_path'] . "/" . $this_userdata['user_avatar']); } @@ -1108,7 +1108,7 @@ if( $mode == 'edit' || $mode == 'save' && ( isset($HTTP_POST_VARS['username']) | 'S_PROFILE_ACTION' => append_sid("admin_users.$phpEx")) ); - if( file_exists('./../' . $board_config['avatar_path'] ) && ($board_config['allow_avatar_upload'] == TRUE) ) + if( file_exists(@realpath('./../' . $board_config['avatar_path'])) && ($board_config['allow_avatar_upload'] == TRUE) ) { if ( $form_enctype != '' ) { @@ -1117,7 +1117,7 @@ if( $mode == 'edit' || $mode == 'save' && ( isset($HTTP_POST_VARS['username']) | $template->assign_block_vars('avatar_remote_upload', array() ); } - if( file_exists('./../' . $board_config['avatar_gallery_path'] ) && ($board_config['allow_avatar_local'] == TRUE) ) + if( file_exists(@realpath('./../' . $board_config['avatar_gallery_path'])) && ($board_config['allow_avatar_local'] == TRUE) ) { $template->assign_block_vars('avatar_local_gallery', array() ); } diff --git a/phpBB/includes/emailer.php b/phpBB/includes/emailer.php index ff99e338e8..12bc0a8732 100755 --- a/phpBB/includes/emailer.php +++ b/phpBB/includes/emailer.php @@ -88,7 +88,8 @@ class emailer $template_lang = $board_config['default_lang']; } - $this->tpl_file = $phpbb_root_path . 'language/lang_' . $template_lang . '/email/' . $template_file . '.tpl'; + $this->tpl_file = realpath($phpbb_root_path . 'language/lang_' . $template_lang . '/email/' . $template_file . '.tpl'); + if ( !file_exists($this->tpl_file) ) { message_die(GENERAL_ERROR, 'Could not find email template file ' . $template_file, '', __LINE__, __FILE__); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index c088dec2d9..35f01039bd 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -220,7 +220,7 @@ function init_userprefs($userdata) } } - if ( !file_exists($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.'.$phpEx) ) + if ( !file_exists(@realpath($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_main.'.$phpEx)) ) { $board_config['default_lang'] = 'english'; } @@ -229,7 +229,7 @@ function init_userprefs($userdata) if ( defined('IN_ADMIN') ) { - if( !file_exists($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.'.$phpEx) ) + if( !file_exists(@realpath($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin.'.$phpEx)) ) { $board_config['default_lang'] = 'english'; } @@ -288,7 +288,7 @@ function setup_style($style) message_die(CRITICAL_ERROR, "Could not open $template_name template config file", '', __LINE__, __FILE__); } - $img_lang = ( file_exists($current_template_path . '/images/lang_' . $board_config['default_lang']) ) ? $board_config['default_lang'] : 'english'; + $img_lang = ( file_exists(@realpath($current_template_path . '/images/lang_' . $board_config['default_lang'])) ) ? $board_config['default_lang'] : 'english'; while( list($key, $value) = @each($images) ) { @@ -675,4 +675,19 @@ function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', exit; } -?> \ No newline at end of file + +// +// This function is for compatibility with PHP 4.x's realpath() +// function. In later versions of PHP, it needs to be called +// to do checks with some functions. Older versions of PHP don't +// seem to need this, so we'll just return the original value. +// +// dougk_ff7 +if ( !function_exists(realpath) ) +{ + function realpath($path) + { + return $path; + } +} +?> diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php index d27a3e4259..85802ea932 100644 --- a/phpBB/includes/template.php +++ b/phpBB/includes/template.php @@ -230,7 +230,7 @@ class Template { // Check if it's an absolute or relative path. if (substr($filename, 0, 1) != '/') { - $filename = $this->root . '/' . $filename; + $filename = realpath($this->root . '/' . $filename); } if (!file_exists($filename)) diff --git a/phpBB/includes/usercp_avatar.php b/phpBB/includes/usercp_avatar.php index 740d60db95..349b9e4717 100644 --- a/phpBB/includes/usercp_avatar.php +++ b/phpBB/includes/usercp_avatar.php @@ -53,7 +53,7 @@ function user_avatar_delete($avatar_type, $avatar_file) if ( $avatar_type == USER_AVATAR_UPLOAD && $avatar_file != '' ) { - if ( @file_exists('./' . $board_config['avatar_path'] . '/' . $avatar_file) ) + if ( @file_exists(@realpath('./' . $board_config['avatar_path'] . '/' . $avatar_file)) ) { @unlink('./' . $board_config['avatar_path'] . '/' . $avatar_file); } @@ -65,7 +65,7 @@ function user_avatar_delete($avatar_type, $avatar_file) function user_avatar_gallery($mode, &$error, &$error_msg, $avatar_filename) { global $board_config; - if ( file_exists($board_config['avatar_gallery_path'] . '/' . $avatar_filename) && ($mode == 'editprofile') ) + if ( file_exists(@realpath($board_config['avatar_gallery_path'] . '/' . $avatar_filename)) && ($mode == 'editprofile') ) { $return = ", user_avatar = '" . str_replace("\'", "''", $avatar_filename) . "', user_avatar_type = " . USER_AVATAR_GALLERY; } @@ -167,7 +167,7 @@ function user_avatar_upload($mode, $avatar_mode, &$current_avatar, &$current_typ $error_msg = ( !empty($error_msg) ) ? $error_msg . '
' . $l_avatar_size : $l_avatar_size; } } - else if ( $avatar_mode == 'local' && file_exists($avatar_filename) && preg_match('/\.(jpg|jpeg|gif|png)$/i', $avatar_realname) ) + else if ( file_exists(@realpath($avatar_filename)) ) && preg_match('/\.(jpg|jpeg|gif|png)$/i', $avatar_realname) ) { if ( $avatar_filesize <= $board_config['avatar_filesize'] && $avatar_filesize > 0 ) { @@ -197,7 +197,7 @@ function user_avatar_upload($mode, $avatar_mode, &$current_avatar, &$current_typ if ( $mode == 'editprofile' && $current_type == USER_AVATAR_UPLOAD && $current_avatar != '' ) { - if ( file_exists('./' . $board_config['avatar_path'] . '/' . $current_avatar) ) + if ( file_exists(@realpath('./' . $board_config['avatar_path'] . '/' . $current_avatar)) ) { @unlink('./' . $board_config['avatar_path'] . '/' . $current_avatar); } diff --git a/phpBB/includes/usercp_register.php b/phpBB/includes/usercp_register.php index 0e2e7cec5f..a36090f947 100644 --- a/phpBB/includes/usercp_register.php +++ b/phpBB/includes/usercp_register.php @@ -201,7 +201,7 @@ if ( $user_avatar = $user_avatar_local; $user_avatar_type = USER_AVATAR_GALLERY; - if ( $userdata['user_avatar_type'] == USER_AVATAR_UPLOAD && @file_exists('./' . $board_config['avatar_path'] . '/' . $userdata['user_avatar']) ) + if ( $userdata['user_avatar_type'] == USER_AVATAR_UPLOAD && @file_exists(@realpath('./' . $board_config['avatar_path'] . '/' . $userdata['user_avatar'])) ) { @unlink('./' . $board_config['avatar_path'] . '/' . $userdata['user_avatar']); } @@ -920,7 +920,7 @@ else { $template->assign_block_vars('switch_avatar_block', array() ); - if ( $board_config['allow_avatar_upload'] && file_exists('./' . $board_config['avatar_path']) ) + if ( $board_config['allow_avatar_upload'] && file_exists(@realpath('./' . $board_config['avatar_path'])) ) { if ( $form_enctype != '' ) { @@ -934,7 +934,7 @@ else $template->assign_block_vars('switch_avatar_block.switch_avatar_remote_link', array() ); } - if ( $board_config['allow_avatar_local'] && file_exists('./' . $board_config['avatar_gallery_path']) ) + if ( $board_config['allow_avatar_local'] && file_exists(@realpath('./' . $board_config['avatar_gallery_path'])) ) { $template->assign_block_vars('switch_avatar_block.switch_avatar_local_gallery', array() ); } diff --git a/phpBB/install.php b/phpBB/install.php index cf46049762..a1d69c4436 100644 --- a/phpBB/install.php +++ b/phpBB/install.php @@ -237,7 +237,7 @@ $server_port = ( !empty($HTTP_POST_VARS['server_port']) ) ? $HTTP_POST_VARS['ser $board_email = ( !empty($HTTP_POST_VARS['board_email']) ) ? $HTTP_POST_VARS['board_email'] : ""; $script_path = ( !empty($HTTP_POST_VARS['script_path']) ) ? $HTTP_POST_VARS['script_path'] : ""; -if( @file_exists('config.'.$phpEx) ) +if( @file_exists(@realpath('config.'.$phpEx)) ) { include('config.'.$phpEx); }