aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2011-09-18 22:20:20 +0200
committerAndreas Fischer <bantu@phpbb.com>2011-09-18 22:24:14 +0200
commit9006984d5ab7478e9187d14c5ab331057b1af9a4 (patch)
tree2c450dc97cec16b95cbd3127fab1fc7d87b6032e /phpBB/includes
parent7b3f6cb219cac448ba470f016ed5068bdc7ffc56 (diff)
downloadforums-9006984d5ab7478e9187d14c5ab331057b1af9a4.tar
forums-9006984d5ab7478e9187d14c5ab331057b1af9a4.tar.gz
forums-9006984d5ab7478e9187d14c5ab331057b1af9a4.tar.bz2
forums-9006984d5ab7478e9187d14c5ab331057b1af9a4.tar.xz
forums-9006984d5ab7478e9187d14c5ab331057b1af9a4.zip
[ticket/10369] DRY code to remove phpbb path from errfile.
PHPBB3-10369
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/error_collector.php4
-rw-r--r--phpBB/includes/functions.php26
2 files changed, 24 insertions, 6 deletions
diff --git a/phpBB/includes/error_collector.php b/phpBB/includes/error_collector.php
index 534df27ece..040be4dd13 100644
--- a/phpBB/includes/error_collector.php
+++ b/phpBB/includes/error_collector.php
@@ -42,8 +42,6 @@ class phpbb_error_collector
function format_errors()
{
- $phpbb_root_path = phpbb_realpath(dirname(__FILE__) . '/../');
-
$text = '';
foreach ($this->errors as $error)
{
@@ -55,7 +53,7 @@ class phpbb_error_collector
list($errno, $msg_text, $errfile, $errline) = $error;
// Prevent leakage of local path to phpBB install
- $errfile = str_replace(array($phpbb_root_path, '\\'), array('', '/'), $errfile);
+ $errfile = phpbb_filter_errfile($errfile);
$text .= "Errno $errno: $msg_text at $errfile line $errline";
}
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 628f8ee123..4c1bfb4360 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -3816,9 +3816,8 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
if (strpos($errfile, 'cache') === false && strpos($errfile, 'template.') === false)
{
- // remove complete path to installation, with the risk of changing backslashes meant to be there
- $errfile = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $errfile);
- $msg_text = str_replace(array(phpbb_realpath($phpbb_root_path), '\\'), array('', '/'), $msg_text);
+ $errfile = phpbb_filter_errfile($errfile);
+ $msg_text = phpbb_filter_errfile($msg_text);
$error_name = ($errno === E_WARNING) ? 'PHP Warning' : 'PHP Notice';
echo '<b>[phpBB Debug] ' . $error_name . '</b>: in file <b>' . $errfile . '</b> on line <b>' . $errline . '</b>: <b>' . $msg_text . '</b><br />' . "\n";
@@ -3997,6 +3996,27 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
}
/**
+* Removes absolute path to phpBB root directory from error messages
+* and converts backslashes to forward slashes.
+*
+* @param string $errfile Absolute file path
+* (e.g. /var/www/phpbb3/phpBB/includes/functions.php)
+* @return string Relative file path
+* (e.g. /includes/functions.php)
+*/
+function phpbb_filter_errfile($errfile)
+{
+ static $root_path;
+
+ if (empty($root_path))
+ {
+ $root_path = phpbb_realpath(dirname(__FILE__) . '/../');
+ }
+
+ return str_replace(array($root_path, '\\'), array('', '/'), $errfile);
+}
+
+/**
* Queries the session table to get information about online guests
* @param int $item_id Limits the search to the item with this id
* @param string $item The name of the item which is stored in the session table as session_{$item}_id