From d5896239068e1063970f398a12ffb5a0707fb286 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 7 Jul 2012 22:43:52 +0100 Subject: [PATCH 01/22] [ticket/10970] Paths of the form {FOO}/a/{BAR}/b parsed correctly A new method to handle this type of path was added and compile_tag_include, compile_tag_include_php and compile_tag_include_js were modified to use it appropriately. Tests were added for these three macros also. PHPBB3-10970 --- phpBB/includes/template/filter.php | 70 +++++++++++++++---- tests/template/includephp_test.php | 12 ++++ tests/template/template_includejs_test.php | 6 +- tests/template/template_test.php | 7 ++ .../template/templates/include_variables.html | 1 + tests/template/templates/includejs.html | 4 +- .../templates/includephp_variables.html | 2 + .../template/templates/subdir/parent_only.js | 0 .../templates/subdir/subsubdir/parent_only.js | 0 tests/template/templates/subdir/variable.html | 1 + 10 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 tests/template/templates/include_variables.html create mode 100644 tests/template/templates/includephp_variables.html create mode 100644 tests/template/templates/subdir/parent_only.js create mode 100644 tests/template/templates/subdir/subsubdir/parent_only.js create mode 100644 tests/template/templates/subdir/variable.html diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index ad2e35de6a..a8985a771c 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -361,6 +361,52 @@ class phpbb_template_filter extends php_user_filter return $text_blocks; } + /** + * Parse paths of the form {FOO}/a/{BAR}/b + * Note: this method assumes at least one variable in the path, this should + * be checked before this method is called. + * + * @param string $path The path to parse + * @param string $include_type The type of template function to call + * @return string An appropriately formatted string to include in the + * template + */ + private function parse_dynamic_path($path, $include_type) + { + $segments = explode('/', $path); + $is_expr = true; + $str = array(); + $vars = array(); + + foreach ($segments as $segment) + { + if ($segment[0] === '{') + { + $var = $this->get_varref($segment, $tmp_is_expr); + $is_expr = $is_expr && $tmp_is_expr; + $vars[] = "isset($var)"; + $str[] = "$var . '/'"; + } + else + { + $str[] = "'$segment/'"; + } + } + + // Remove trailing slash from last element + $last = array_pop($str); + $str[] = str_replace('/', '', $last); + + if (!$is_expr) + { + return ' if (' . implode(' && ', $vars) . ") { \$_template->$include_type(" . implode(' . ', $str) . ', true); }'; + } + else + { + return ''; + } + } + /** * Compile variables * @@ -774,15 +820,9 @@ class phpbb_template_filter extends php_user_filter private function compile_tag_include($tag_args) { // Process dynamic includes - if ($tag_args[0] == '{') + if (strpos($tag_args, '{') !== false) { - $var = $this->get_varref($tag_args, $is_expr); - - // Make sure someone didn't try to include S_FIRST_ROW or similar - if (!$is_expr) - { - return "if (isset($var)) { \$_template->_tpl_include($var); }"; - } + return $this->parse_dynamic_path($tag_args, '_tpl_include'); } return "\$_template->_tpl_include('$tag_args');"; @@ -796,6 +836,11 @@ class phpbb_template_filter extends php_user_filter */ private function compile_tag_include_php($tag_args) { + if (strpos($tag_args, '{') !== false) + { + return $this->parse_dynamic_path($tag_args, '_php_include'); + } + return "\$_template->_php_include('$tag_args');"; } @@ -883,14 +928,9 @@ class phpbb_template_filter extends php_user_filter private function compile_tag_include_js($tag_args) { // Process dynamic includes - if ($tag_args[0] == '{') + if (strpos($tag_args, '{') !== false) { - $var = $this->get_varref($tag_args, $is_expr); - if (!$is_expr) - { - return " \$_template->_js_include($var, true);"; - } - return ''; + return $this->parse_dynamic_path($tag_args, '_js_include'); } // Locate file diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php index 626735f15f..236621adec 100644 --- a/tests/template/includephp_test.php +++ b/tests/template/includephp_test.php @@ -23,6 +23,18 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case $this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); } + public function test_includephp_variables() + { + $this->setup_engine(array('tpl_allow_php' => true)); + + $cache_file = $this->template->cachepath . 'includephp_variables.html.php'; + + $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php", $cache_file); + + $this->template->set_filenames(array('test' => 'includephp_variables.html')); + $this->assertEquals("Path includes variables.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP"); + } + public function test_includephp_absolute() { $path_to_php = dirname(__FILE__) . '/templates/_dummy_include.php.inc'; diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index a8f9a9037f..d8c7170e94 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -20,11 +20,13 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes $scripts = array( '', '', - '' + '', + '', + '', ); // Run test $cache_file = $this->template->cachepath . 'includejs.html.php'; - $this->run_template('includejs.html', array('PARENT' => 'parent_only.js'), array(), array(), implode('', $scripts), $cache_file); + $this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir'), array(), array(), implode('', $scripts), $cache_file); } } diff --git a/tests/template/template_test.php b/tests/template/template_test.php index f8677ed913..83995cb4ac 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -183,6 +183,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case array(), 'value', ), + array( + 'include_variables.html', + array('SUBDIR' => 'subdir', 'VARIABLE' => 'value'), + array(), + array(), + 'value', + ), array( 'loop_vars.html', array(), diff --git a/tests/template/templates/include_variables.html b/tests/template/templates/include_variables.html new file mode 100644 index 0000000000..8371a061b5 --- /dev/null +++ b/tests/template/templates/include_variables.html @@ -0,0 +1 @@ + diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html index 8a2587d76b..dbcf6e04a8 100644 --- a/tests/template/templates/includejs.html +++ b/tests/template/templates/includejs.html @@ -2,4 +2,6 @@ -{SCRIPTS} \ No newline at end of file + + +{SCRIPTS} diff --git a/tests/template/templates/includephp_variables.html b/tests/template/templates/includephp_variables.html new file mode 100644 index 0000000000..6106efc86a --- /dev/null +++ b/tests/template/templates/includephp_variables.html @@ -0,0 +1,2 @@ +Path includes variables. + diff --git a/tests/template/templates/subdir/parent_only.js b/tests/template/templates/subdir/parent_only.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/template/templates/subdir/subsubdir/parent_only.js b/tests/template/templates/subdir/subsubdir/parent_only.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/template/templates/subdir/variable.html b/tests/template/templates/subdir/variable.html new file mode 100644 index 0000000000..f68f91597c --- /dev/null +++ b/tests/template/templates/subdir/variable.html @@ -0,0 +1 @@ +{VARIABLE} From d0cb5bb093d09a15f422f84e19d781a8260512a0 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 8 Jul 2012 15:12:08 +0100 Subject: [PATCH 02/22] [ticket/10970] Added support for forms such as {FOO}bar.{EXT} PHPBB3-10970 --- phpBB/includes/template/filter.php | 30 +++++++--------------- tests/template/template_includejs_test.php | 3 ++- tests/template/templates/includejs.html | 1 + 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index a8985a771c..568727be82 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -373,33 +373,21 @@ class phpbb_template_filter extends php_user_filter */ private function parse_dynamic_path($path, $include_type) { - $segments = explode('/', $path); - $is_expr = true; - $str = array(); - $vars = array(); + $matches = array(); + $replace = array(); - foreach ($segments as $segment) + preg_match_all('/{[^}]+}/', $path, $matches); + foreach ($matches[0] as $var_str) { - if ($segment[0] === '{') - { - $var = $this->get_varref($segment, $tmp_is_expr); - $is_expr = $is_expr && $tmp_is_expr; - $vars[] = "isset($var)"; - $str[] = "$var . '/'"; - } - else - { - $str[] = "'$segment/'"; - } + $var = $this->get_varref($var_str, $tmp_is_expr); + $is_expr = $is_expr && $tmp_is_expr; + $vars[] = "isset($var)"; + $replace[] = "' . $var . '"; } - // Remove trailing slash from last element - $last = array_pop($str); - $str[] = str_replace('/', '', $last); - if (!$is_expr) { - return ' if (' . implode(' && ', $vars) . ") { \$_template->$include_type(" . implode(' . ', $str) . ', true); }'; + return ' if (' . implode(' && ', $vars) . ") { \$_template->$include_type('" . str_replace($matches[0], $replace, $path) . "', true); }"; } else { diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php index d8c7170e94..22b020208b 100644 --- a/tests/template/template_includejs_test.php +++ b/tests/template/template_includejs_test.php @@ -23,10 +23,11 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes '', '', '', + '', ); // Run test $cache_file = $this->template->cachepath . 'includejs.html.php'; - $this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir'), array(), array(), implode('', $scripts), $cache_file); + $this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), array(), array(), implode('', $scripts), $cache_file); } } diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html index dbcf6e04a8..ef73700eeb 100644 --- a/tests/template/templates/includejs.html +++ b/tests/template/templates/includejs.html @@ -4,4 +4,5 @@ + {SCRIPTS} From 47c67b6d021c6488106bb0d327600b35e08bf94b Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 24 Jul 2012 11:54:46 +0100 Subject: [PATCH 03/22] [ticket/10970] Added missing initialisations and modified the regex Non-existent variables now become empty strings. PHPBB3-10970 --- phpBB/includes/template/filter.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 568727be82..596b83cc75 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -375,10 +375,13 @@ class phpbb_template_filter extends php_user_filter { $matches = array(); $replace = array(); + $vars = array(); + $is_expr = true; - preg_match_all('/{[^}]+}/', $path, $matches); + preg_match_all('#\{((?:' . self::REGEX_NS . '\.)*)(\$)?(' . self::REGEX_VAR . ')\}#', $path, $matches); foreach ($matches[0] as $var_str) { + $tmp_is_expr = false; $var = $this->get_varref($var_str, $tmp_is_expr); $is_expr = $is_expr && $tmp_is_expr; $vars[] = "isset($var)"; @@ -387,7 +390,7 @@ class phpbb_template_filter extends php_user_filter if (!$is_expr) { - return ' if (' . implode(' && ', $vars) . ") { \$_template->$include_type('" . str_replace($matches[0], $replace, $path) . "', true); }"; + return " \$_template->$include_type('" . str_replace($matches[0], $replace, $path) . "', true);"; } else { From 003220dc7c781df38fde75f0007c3b3e48803162 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Tue, 24 Jul 2012 11:55:38 +0100 Subject: [PATCH 04/22] [ticket/10970] Fixed a problem with prepending root paths PHPBB3-10970 --- phpBB/includes/template/template.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 8ab3c44be3..861a5e28e7 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -503,7 +503,11 @@ class phpbb_template // Locate file if ($locate) { - $file = $this->locator->get_first_file_location(array($file), true, true); + $located = $this->locator->get_first_file_location(array($file), false, true); + if ($located) + { + $file = $located; + } } else if ($relative) { From 02ccf392fa11c7c2210f5ba1e8923e82e62a66cf Mon Sep 17 00:00:00 2001 From: Fyorl Date: Fri, 10 Aug 2012 13:42:38 +0100 Subject: [PATCH 05/22] [ticket/10970] Removed unused $vars PHPBB3-10970 --- phpBB/includes/template/filter.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 596b83cc75..e4c3184565 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -375,7 +375,6 @@ class phpbb_template_filter extends php_user_filter { $matches = array(); $replace = array(); - $vars = array(); $is_expr = true; preg_match_all('#\{((?:' . self::REGEX_NS . '\.)*)(\$)?(' . self::REGEX_VAR . ')\}#', $path, $matches); @@ -384,7 +383,6 @@ class phpbb_template_filter extends php_user_filter $tmp_is_expr = false; $var = $this->get_varref($var_str, $tmp_is_expr); $is_expr = $is_expr && $tmp_is_expr; - $vars[] = "isset($var)"; $replace[] = "' . $var . '"; } From 74423eaf126ea719df3ed102e459edad6be864da Mon Sep 17 00:00:00 2001 From: Fyorl Date: Thu, 9 Aug 2012 12:31:49 +0100 Subject: [PATCH 06/22] [ticket/10939] Added $_FILES handling to phpbb_request PHPBB3-10939 --- phpBB/includes/request/interface.php | 1 + phpBB/includes/request/request.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/phpBB/includes/request/interface.php b/phpBB/includes/request/interface.php index afd53002e3..741db35917 100644 --- a/phpBB/includes/request/interface.php +++ b/phpBB/includes/request/interface.php @@ -30,6 +30,7 @@ interface phpbb_request_interface const REQUEST = 2; const COOKIE = 3; const SERVER = 4; + const FILES = 5; /**#@-*/ /** diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php index 4e425dbd27..4fc9e67314 100644 --- a/phpBB/includes/request/request.php +++ b/phpBB/includes/request/request.php @@ -34,6 +34,7 @@ class phpbb_request implements phpbb_request_interface phpbb_request_interface::REQUEST => '_REQUEST', phpbb_request_interface::COOKIE => '_COOKIE', phpbb_request_interface::SERVER => '_SERVER', + phpbb_request_interface::FILES => '_FILES', ); /** @@ -283,6 +284,18 @@ class phpbb_request implements phpbb_request_interface return $this->server($var_name, $default); } + /** + * Shortcut method to retrieve $_FILES variables + * + * @param string $form_name The name of the file input form element + * + * @return array The uploaded file's information + */ + public function file($form_name) + { + return $this->variable($form_name, array(), false, phpbb_request_interface::FILES); + } + /** * Checks whether a certain variable was sent via POST. * To make sure that a request was sent using POST you should call this function From 48a0810ea593fc3ed84762ccd9076ea756cda41c Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 14:20:40 +0100 Subject: [PATCH 07/22] [ticket/10939] Modified request test slightly to include $_FILES PHPBB3-10939 --- tests/request/request_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/request/request_test.php b/tests/request/request_test.php index bca5125b7a..c02fcf829f 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -21,6 +21,13 @@ class phpbb_request_test extends phpbb_test_case $_COOKIE['test'] = 3; $_REQUEST['test'] = 3; $_GET['unset'] = ''; + $_FILES['test'] = array( + 'name' => 'file', + 'tmp_name' => 'tmp', + 'size' => 256, + 'type' => 'application/octet-stream', + 'error' => UPLOAD_ERR_OK, + ); $_SERVER['HTTP_HOST'] = 'example.com'; $_SERVER['HTTP_ACCEPT'] = 'application/json'; @@ -42,6 +49,7 @@ class phpbb_request_test extends phpbb_test_case $this->assertEquals(2, $_GET['test'], 'Checking $_GET after enable_super_globals'); $this->assertEquals(3, $_COOKIE['test'], 'Checking $_COOKIE after enable_super_globals'); $this->assertEquals(3, $_REQUEST['test'], 'Checking $_REQUEST after enable_super_globals'); + $this->assertEquals(256, $_FILES['test']['size']); $_POST['x'] = 2; $this->assertEquals($_POST, $GLOBALS['_POST'], 'Checking whether $_POST can still be accessed via $GLOBALS[\'_POST\']'); From 91b9cc90dd078fda135d975f0e5af798535d9014 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 15:00:03 +0100 Subject: [PATCH 08/22] [ticket/10939] Modified functions_upload to not use $_FILES PHPBB3-10939 --- phpBB/includes/functions_upload.php | 45 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/phpBB/includes/functions_upload.php b/phpBB/includes/functions_upload.php index d4c6b42cf4..b467aa93d1 100644 --- a/phpBB/includes/functions_upload.php +++ b/phpBB/includes/functions_upload.php @@ -566,10 +566,11 @@ class fileupload */ function form_upload($form_name) { - global $user; + global $user, $request; - unset($_FILES[$form_name]['local_mode']); - $file = new filespec($_FILES[$form_name], $this); + $upload = $request->file($form_name); + unset($upload['local_mode']); + $file = new filespec($upload, $this); if ($file->init_error) { @@ -578,9 +579,9 @@ class fileupload } // Error array filled? - if (isset($_FILES[$form_name]['error'])) + if (isset($upload['error'])) { - $error = $this->assign_internal_error($_FILES[$form_name]['error']); + $error = $this->assign_internal_error($upload['error']); if ($error !== false) { @@ -590,7 +591,7 @@ class fileupload } // Check if empty file got uploaded (not catched by is_uploaded_file) - if (isset($_FILES[$form_name]['size']) && $_FILES[$form_name]['size'] == 0) + if (isset($upload['size']) && $upload['size'] == 0) { $file->error[] = $user->lang[$this->error_prefix . 'EMPTY_FILEUPLOAD']; return $file; @@ -631,17 +632,17 @@ class fileupload */ function local_upload($source_file, $filedata = false) { - global $user; + global $user, $request; - $form_name = 'local'; + $upload = array(); - $_FILES[$form_name]['local_mode'] = true; - $_FILES[$form_name]['tmp_name'] = $source_file; + $upload['local_mode'] = true; + $upload['tmp_name'] = $source_file; if ($filedata === false) { - $_FILES[$form_name]['name'] = utf8_basename($source_file); - $_FILES[$form_name]['size'] = 0; + $upload['name'] = utf8_basename($source_file); + $upload['size'] = 0; $mimetype = ''; if (function_exists('mime_content_type')) @@ -655,16 +656,16 @@ class fileupload $mimetype = 'application/octetstream'; } - $_FILES[$form_name]['type'] = $mimetype; + $upload['type'] = $mimetype; } else { - $_FILES[$form_name]['name'] = $filedata['realname']; - $_FILES[$form_name]['size'] = $filedata['size']; - $_FILES[$form_name]['type'] = $filedata['type']; + $upload['name'] = $filedata['realname']; + $upload['size'] = $filedata['size']; + $upload['type'] = $filedata['type']; } - $file = new filespec($_FILES[$form_name], $this); + $file = new filespec($upload, $this); if ($file->init_error) { @@ -672,9 +673,9 @@ class fileupload return $file; } - if (isset($_FILES[$form_name]['error'])) + if (isset($upload['error'])) { - $error = $this->assign_internal_error($_FILES[$form_name]['error']); + $error = $this->assign_internal_error($upload['error']); if ($error !== false) { @@ -709,6 +710,7 @@ class fileupload } $this->common_checks($file); + $request->overwrite('local', $upload, phpbb_request_interface::FILES); return $file; } @@ -1001,7 +1003,10 @@ class fileupload */ function is_valid($form_name) { - return (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none') ? true : false; + global $request; + $upload = $request->file($form_name); + + return (!empty($upload) && $upload['name'] !== 'none'); } From 3eb88b026752512a79b641e3b55193972f221a45 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 15:06:37 +0100 Subject: [PATCH 09/22] [ticket/10939] Modified message_parser.php to not use $_FILES PHPBB3-10939 --- phpBB/includes/message_parser.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/message_parser.php b/phpBB/includes/message_parser.php index 6695047b56..1cd2a46fa1 100644 --- a/phpBB/includes/message_parser.php +++ b/phpBB/includes/message_parser.php @@ -1363,13 +1363,14 @@ class parse_message extends bbcode_firstpass */ function parse_attachments($form_name, $mode, $forum_id, $submit, $preview, $refresh, $is_message = false) { - global $config, $auth, $user, $phpbb_root_path, $phpEx, $db; + global $config, $auth, $user, $phpbb_root_path, $phpEx, $db, $request; $error = array(); $num_attachments = sizeof($this->attachment_data); $this->filename_data['filecomment'] = utf8_normalize_nfc(request_var('filecomment', '', true)); - $upload_file = (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name'])) ? true : false; + $upload = $request->file($form_name); + $upload_file = (!empty($upload) && $upload['name'] !== 'none' && trim($upload['name'])); $add_file = (isset($_POST['add_file'])) ? true : false; $delete_file = (isset($_POST['delete_file'])) ? true : false; From a3b87f1e953e4f79478d8e7eb65ca9855140243a Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 15:07:42 +0100 Subject: [PATCH 10/22] [ticket/10939] Modified functions_user.php to not use $_FILES PHPBB3-10939 --- phpBB/includes/functions_user.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 6e658b4ef4..405c5ef5d1 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2059,13 +2059,14 @@ function avatar_remote($data, &$error) */ function avatar_upload($data, &$error) { - global $phpbb_root_path, $config, $db, $user, $phpEx; + global $phpbb_root_path, $config, $db, $user, $phpEx, $request; // Init upload class include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $config['avatar_filesize'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], (isset($config['mime_triggers']) ? explode('|', $config['mime_triggers']) : false)); - if (!empty($_FILES['uploadfile']['name'])) + $uploadfile = $request->file('uploadfile'); + if (!empty($uploadfile['name'])) { $file = $upload->form_upload('uploadfile'); } @@ -2288,7 +2289,7 @@ function avatar_get_dimensions($avatar, $avatar_type, &$error, $current_x = 0, $ */ function avatar_process_user(&$error, $custom_userdata = false, $can_upload = null) { - global $config, $phpbb_root_path, $auth, $user, $db; + global $config, $phpbb_root_path, $auth, $user, $db, $request; $data = array( 'uploadurl' => request_var('uploadurl', ''), @@ -2330,7 +2331,8 @@ function avatar_process_user(&$error, $custom_userdata = false, $can_upload = nu $can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $change_avatar && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; } - if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload) + $uploadfile = $request->file('uploadfile'); + if ((!empty($uploadfile['name']) || $data['uploadurl']) && $can_upload) { list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_upload($data, $error); } From 83a53eb985d17f203d8ef0d33291c1ad1c4db84c Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 15:11:33 +0100 Subject: [PATCH 11/22] [ticket/10939] Modified ucp_groups.php to not use $_FILES PHPBB3-10939 --- phpBB/includes/ucp/ucp_groups.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 65ab92e78e..9652986cf2 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -513,7 +513,8 @@ class ucp_groups $data['height'] = request_var('height', ''); $delete = request_var('delete', ''); - if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) + $uploadfile = $request->file('uploadfile'); + if (!empty($uploadfile['tmp_name']) || $data['uploadurl'] || $data['remotelink']) { // Avatar stuff $var_ary = array( @@ -527,7 +528,7 @@ class ucp_groups { $data['user_id'] = "g$group_id"; - if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) + if ((!empty($uploadfile['tmp_name']) || $data['uploadurl']) && $can_upload) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); } From 94ed66c777d22e16ba73d317889707b90f755878 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 15:14:52 +0100 Subject: [PATCH 12/22] [ticket/10939] Modified acp_groups.php to not use $_FILES PHPBB3-10939 --- phpBB/includes/acp/acp_groups.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index f88fa76df1..b018faf968 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -26,6 +26,7 @@ class acp_groups { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; + global $request; $user->add_lang('acp/groups'); $this->tpl_name = 'acp_groups'; @@ -323,7 +324,8 @@ class acp_groups $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0; } - if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) + $uploadfile = $request->file('uploadfile'); + if (!empty($uploadfile['tmp_name']) || $data['uploadurl'] || $data['remotelink']) { // Avatar stuff $var_ary = array( @@ -337,7 +339,7 @@ class acp_groups { $data['user_id'] = "g$group_id"; - if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) + if ((!empty($uploadfile['tmp_name']) || $data['uploadurl']) && $can_upload) { list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error); } From 348554cc297bf906a0510894986bb60041a5db9a Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 15:36:41 +0100 Subject: [PATCH 13/22] [ticket/10939] Modified mock request class to handle deactivated $_FILES PHPBB3-10939 --- tests/mock/request.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/mock/request.php b/tests/mock/request.php index 946dfdada9..2a272fc03b 100644 --- a/tests/mock/request.php +++ b/tests/mock/request.php @@ -11,13 +11,14 @@ class phpbb_mock_request implements phpbb_request_interface { protected $data; - public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false) + public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false, $files = array()) { $this->data[phpbb_request_interface::GET] = $get; $this->data[phpbb_request_interface::POST] = $post; $this->data[phpbb_request_interface::COOKIE] = $cookie; $this->data[phpbb_request_interface::REQUEST] = ($request === false) ? $post + $get : $request; $this->data[phpbb_request_interface::SERVER] = $server; + $this->data[phpbb_request_interface::FILES] = $files; } public function overwrite($var_name, $value, $super_global = phpbb_request_interface::REQUEST) @@ -42,6 +43,12 @@ class phpbb_mock_request implements phpbb_request_interface return $this->server($var_name, $default); } + public function file($form_name) + { + $super_global = phpbb_request_interface::FILES; + return isset($this->data[$super_global][$form_name]) ? $this->data[$super_global][$form_name] : array(); + } + public function is_set_post($name) { return $this->is_set($name, phpbb_request_interface::POST); From df86f466e0245669e5cf97a162378fb653c72422 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 15:56:43 +0100 Subject: [PATCH 14/22] [ticket/10939] Modified fileupload tests to deal with new behaviour PHPBB3-10939 --- tests/upload/fileupload_test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php index 076855ab56..1665c493be 100644 --- a/tests/upload/fileupload_test.php +++ b/tests/upload/fileupload_test.php @@ -19,7 +19,8 @@ class phpbb_fileupload_test extends phpbb_test_case { // Global $config required by unique_id // Global $user required by several functions dealing with translations - global $config, $user; + // Global $request required by form_upload, local_upload and is_valid + global $config, $user, $request; if (!is_array($config)) { @@ -31,6 +32,9 @@ class phpbb_fileupload_test extends phpbb_test_case $user = new phpbb_mock_user(); $user->lang = new phpbb_mock_lang(); + + $request = new phpbb_mock_request(); + $this->path = __DIR__ . '/fixture/'; } From 935e717762ccf9cad47058157933b4d372a57320 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 17:03:15 +0100 Subject: [PATCH 15/22] [ticket/10939] Modified the default return for $request->file PHPBB3-10939 --- phpBB/includes/request/request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php index 4fc9e67314..25410c27c4 100644 --- a/phpBB/includes/request/request.php +++ b/phpBB/includes/request/request.php @@ -293,7 +293,7 @@ class phpbb_request implements phpbb_request_interface */ public function file($form_name) { - return $this->variable($form_name, array(), false, phpbb_request_interface::FILES); + return $this->variable($form_name, array('name' => 'none'), false, phpbb_request_interface::FILES); } /** From e9bdca7a8bc8c36b6d55806b1337e5d32409cb9d Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sun, 19 Aug 2012 17:12:08 +0800 Subject: [PATCH 16/22] [ticket/10970] Added newline in docblock PHPBB3-10970 --- phpBB/includes/template/filter.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index e4c3184565..471ca0c777 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -363,6 +363,7 @@ class phpbb_template_filter extends php_user_filter /** * Parse paths of the form {FOO}/a/{BAR}/b + * * Note: this method assumes at least one variable in the path, this should * be checked before this method is called. * From aa5f6dffa5ad7e8c357006ba539885bf9814d8f5 Mon Sep 17 00:00:00 2001 From: Fyorl Date: Mon, 20 Aug 2012 21:40:53 +0100 Subject: [PATCH 17/22] [ticket/10939] Added tests for phpbb_request::file PHPBB3-10939 --- tests/request/request_test.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/request/request_test.php b/tests/request/request_test.php index c02fcf829f..52c21abd2a 100644 --- a/tests/request/request_test.php +++ b/tests/request/request_test.php @@ -93,6 +93,23 @@ class phpbb_request_test extends phpbb_test_case $this->request->header('SOMEVAR'); } + public function test_file() + { + $file = $this->request->file('test'); + $this->assertEquals('file', $file['name']); + $this->assertEquals('tmp', $file['tmp_name']); + $this->assertEquals(256, $file['size']); + $this->assertEquals('application/octet-stream', $file['type']); + $this->assertEquals(UPLOAD_ERR_OK, $file['error']); + } + + public function test_file_not_exists() + { + $file = $this->request->file('404'); + $this->assertTrue(is_array($file)); + $this->assertTrue(empty($file)); + } + /** * Checks that directly accessing $_POST will trigger * an error. From 1f9bff2126bbec514c4a7b675723bfe7f26c432e Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 10 Nov 2012 08:51:12 +0000 Subject: [PATCH 18/22] [ticket/10939] Added documentation for phpbb_request::file PHPBB3-10939 --- phpBB/includes/request/request.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/request/request.php b/phpBB/includes/request/request.php index 25410c27c4..94445f232c 100644 --- a/phpBB/includes/request/request.php +++ b/phpBB/includes/request/request.php @@ -289,7 +289,8 @@ class phpbb_request implements phpbb_request_interface * * @param string $form_name The name of the file input form element * - * @return array The uploaded file's information + * @return array The uploaded file's information or an empty array if the + * variable does not exist in _FILES. */ public function file($form_name) { From a05f354fdf903d00e85d8e4ad1d50f9ef906534d Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 10 Nov 2012 09:36:02 +0000 Subject: [PATCH 19/22] [ticket/10970] Added extra documentation to parse_dynamic_path. PHPBB3-10970 --- phpBB/includes/template/filter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/phpBB/includes/template/filter.php b/phpBB/includes/template/filter.php index 471ca0c777..3e90190db7 100644 --- a/phpBB/includes/template/filter.php +++ b/phpBB/includes/template/filter.php @@ -370,7 +370,8 @@ class phpbb_template_filter extends php_user_filter * @param string $path The path to parse * @param string $include_type The type of template function to call * @return string An appropriately formatted string to include in the - * template + * template or an empty string if an expression like S_FIRST_ROW was + * incorrectly used */ private function parse_dynamic_path($path, $include_type) { From c73293d82673631da61acffeef31a93bcca139dd Mon Sep 17 00:00:00 2001 From: Fyorl Date: Sat, 10 Nov 2012 13:46:40 +0000 Subject: [PATCH 20/22] [ticket/11187] Added a blank array to fix errors in functional tests PHPBB3-11187 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index d002615e8c..d0bbf85960 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -125,7 +125,7 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->extension_manager = new phpbb_extension_manager( $this->get_db(), - new phpbb_config(), + new phpbb_config(array()), self::$config['table_prefix'] . 'ext', $phpbb_root_path, ".$phpEx", From 7085a6c74d9bc5a4c5a92033977a89f56cce01e1 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 10:12:25 -0600 Subject: [PATCH 21/22] [ticket/11189] Always log critical errors when in cron or in image output PHPBB3-11189 --- phpBB/includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 43b81f3f26..7801c48aa7 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4196,7 +4196,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) $msg_text = $log_text; } - if ((defined('DEBUG') || defined('IN_CRON') || defined('IMAGE_OUTPUT')) && isset($db)) + if ((defined('IN_CRON') || defined('IMAGE_OUTPUT')) && isset($db)) { // let's avoid loops $db->sql_return_on_error(true); From bd37f7f6c04780819dfa8f81b2d761b91859fd67 Mon Sep 17 00:00:00 2001 From: Nathaniel Guse Date: Sat, 10 Nov 2012 10:45:02 -0600 Subject: [PATCH 22/22] [ticket/11189] Replace DEBUG_EXTRA with DEBUG PHPBB3-11189 --- phpBB/cron.php | 6 +++--- phpBB/feed.php | 2 +- phpBB/includes/db/dbal.php | 4 ++-- phpBB/includes/db/firebird.php | 6 +++--- phpBB/includes/db/mssql.php | 6 +++--- phpBB/includes/db/mssql_odbc.php | 6 +++--- phpBB/includes/db/mssqlnative.php | 6 +++--- phpBB/includes/db/mysql.php | 6 +++--- phpBB/includes/db/mysqli.php | 6 +++--- phpBB/includes/db/oracle.php | 6 +++--- phpBB/includes/db/postgres.php | 6 +++--- phpBB/includes/db/sqlite.php | 6 +++--- phpBB/includes/functions.php | 6 +++--- phpBB/includes/functions_acp.php | 4 ++-- phpBB/includes/functions_install.php | 2 -- phpBB/includes/session.php | 2 +- phpBB/includes/template/template.php | 4 ++-- phpBB/includes/user.php | 10 +++++----- phpBB/install/database_update.php | 2 +- phpBB/install/install_convert.php | 8 ++++---- 20 files changed, 51 insertions(+), 53 deletions(-) diff --git a/phpBB/cron.php b/phpBB/cron.php index 95d2f8f9b6..787183f689 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -39,7 +39,7 @@ function do_cron($cron_lock, $run_tasks) foreach ($run_tasks as $task) { - if (defined('DEBUG_EXTRA') && $config['use_system_cron']) + if (defined('DEBUG') && $config['use_system_cron']) { echo "[phpBB cron] Running task '{$task->get_name()}'\n"; } @@ -57,7 +57,7 @@ function do_cron($cron_lock, $run_tasks) // // Attempt to alleviate the problem by doing setup outside of the lock as much as possible. // -// If DEBUG_EXTRA is defined and cron lock cannot be obtained, a message will be printed. +// If DEBUG is defined and cron lock cannot be obtained, a message will be printed. if ($config['use_system_cron']) { @@ -100,7 +100,7 @@ if ($cron_lock->acquire()) } else { - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { echo "Could not obtain cron lock.\n"; } diff --git a/phpBB/feed.php b/phpBB/feed.php index 9b7ef3a575..58ae251089 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -150,7 +150,7 @@ if ($config['gzip_compress']) } // IF debug extra is enabled and admin want to "explain" the page we need to set other headers... -if (defined('DEBUG_EXTRA') && request_var('explain', 0) && $auth->acl_get('a_')) +if (defined('DEBUG') && request_var('explain', 0) && $auth->acl_get('a_')) { header('Content-type: text/html; charset=UTF-8'); header('Cache-Control: private, no-cache="set-cookie"'); diff --git a/phpBB/includes/db/dbal.php b/phpBB/includes/db/dbal.php index 1de236d3de..ef1dd7d14d 100644 --- a/phpBB/includes/db/dbal.php +++ b/phpBB/includes/db/dbal.php @@ -766,8 +766,8 @@ class dbal // Show complete SQL error and path to administrators only // Additionally show complete error on installation or if extended debug mode is enabled - // The DEBUG_EXTRA constant is for development only! - if ((isset($auth) && $auth->acl_get('a_')) || defined('IN_INSTALL') || defined('DEBUG_EXTRA')) + // The DEBUG constant is for development only! + if ((isset($auth) && $auth->acl_get('a_')) || defined('IN_INSTALL') || defined('DEBUG')) { $message .= ($sql) ? '

SQL

' . htmlspecialchars($sql) : ''; } diff --git a/phpBB/includes/db/firebird.php b/phpBB/includes/db/firebird.php index 9f9b8a1abd..5728eb901c 100644 --- a/phpBB/includes/db/firebird.php +++ b/phpBB/includes/db/firebird.php @@ -150,7 +150,7 @@ class dbal_firebird extends dbal global $cache; // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('start', $query); } @@ -251,7 +251,7 @@ class dbal_firebird extends dbal $this->sql_error($query); } - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('stop', $query); } @@ -279,7 +279,7 @@ class dbal_firebird extends dbal $this->open_queries[(int) $this->query_result] = $this->query_result; } } - else if (defined('DEBUG_EXTRA')) + else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } diff --git a/phpBB/includes/db/mssql.php b/phpBB/includes/db/mssql.php index bde283c3ea..1ec8517308 100644 --- a/phpBB/includes/db/mssql.php +++ b/phpBB/includes/db/mssql.php @@ -139,7 +139,7 @@ class dbal_mssql extends dbal global $cache; // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('start', $query); } @@ -154,7 +154,7 @@ class dbal_mssql extends dbal $this->sql_error($query); } - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('stop', $query); } @@ -169,7 +169,7 @@ class dbal_mssql extends dbal $this->open_queries[(int) $this->query_result] = $this->query_result; } } - else if (defined('DEBUG_EXTRA')) + else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } diff --git a/phpBB/includes/db/mssql_odbc.php b/phpBB/includes/db/mssql_odbc.php index 687bc52abc..7c1ffbc808 100644 --- a/phpBB/includes/db/mssql_odbc.php +++ b/phpBB/includes/db/mssql_odbc.php @@ -157,7 +157,7 @@ class dbal_mssql_odbc extends dbal global $cache; // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('start', $query); } @@ -173,7 +173,7 @@ class dbal_mssql_odbc extends dbal $this->sql_error($query); } - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('stop', $query); } @@ -188,7 +188,7 @@ class dbal_mssql_odbc extends dbal $this->open_queries[(int) $this->query_result] = $this->query_result; } } - else if (defined('DEBUG_EXTRA')) + else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } diff --git a/phpBB/includes/db/mssqlnative.php b/phpBB/includes/db/mssqlnative.php index c31f7f6892..e9191fae8a 100644 --- a/phpBB/includes/db/mssqlnative.php +++ b/phpBB/includes/db/mssqlnative.php @@ -311,7 +311,7 @@ class dbal_mssqlnative extends dbal global $cache; // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('start', $query); } @@ -329,7 +329,7 @@ class dbal_mssqlnative extends dbal // reset options for next query $this->query_options = array(); - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('stop', $query); } @@ -344,7 +344,7 @@ class dbal_mssqlnative extends dbal $this->open_queries[(int) $this->query_result] = $this->query_result; } } - else if (defined('DEBUG_EXTRA')) + else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } diff --git a/phpBB/includes/db/mysql.php b/phpBB/includes/db/mysql.php index 5b4ff86579..f685ab055c 100644 --- a/phpBB/includes/db/mysql.php +++ b/phpBB/includes/db/mysql.php @@ -167,7 +167,7 @@ class dbal_mysql extends dbal global $cache; // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('start', $query); } @@ -182,7 +182,7 @@ class dbal_mysql extends dbal $this->sql_error($query); } - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('stop', $query); } @@ -197,7 +197,7 @@ class dbal_mysql extends dbal $this->open_queries[(int) $this->query_result] = $this->query_result; } } - else if (defined('DEBUG_EXTRA')) + else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } diff --git a/phpBB/includes/db/mysqli.php b/phpBB/includes/db/mysqli.php index 1f13bd5459..6d81b8bc3e 100644 --- a/phpBB/includes/db/mysqli.php +++ b/phpBB/includes/db/mysqli.php @@ -174,7 +174,7 @@ class dbal_mysqli extends dbal global $cache; // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('start', $query); } @@ -189,7 +189,7 @@ class dbal_mysqli extends dbal $this->sql_error($query); } - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('stop', $query); } @@ -199,7 +199,7 @@ class dbal_mysqli extends dbal $this->query_result = $cache->sql_save($query, $this->query_result, $cache_ttl); } } - else if (defined('DEBUG_EXTRA')) + else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index de2729e973..6d9339b2d8 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -236,7 +236,7 @@ class dbal_oracle extends dbal global $cache; // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('start', $query); } @@ -413,7 +413,7 @@ class dbal_oracle extends dbal } } - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('stop', $query); } @@ -428,7 +428,7 @@ class dbal_oracle extends dbal $this->open_queries[(int) $this->query_result] = $this->query_result; } } - else if (defined('DEBUG_EXTRA')) + else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index f0a4a7a7a2..8dfbfc3b60 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -194,7 +194,7 @@ class dbal_postgres extends dbal global $cache; // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('start', $query); } @@ -210,7 +210,7 @@ class dbal_postgres extends dbal $this->sql_error($query); } - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('stop', $query); } @@ -225,7 +225,7 @@ class dbal_postgres extends dbal $this->open_queries[(int) $this->query_result] = $this->query_result; } } - else if (defined('DEBUG_EXTRA')) + else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } diff --git a/phpBB/includes/db/sqlite.php b/phpBB/includes/db/sqlite.php index 2cf55b07e2..5fc89ced18 100644 --- a/phpBB/includes/db/sqlite.php +++ b/phpBB/includes/db/sqlite.php @@ -112,7 +112,7 @@ class dbal_sqlite extends dbal global $cache; // EXPLAIN only in extra debug mode - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('start', $query); } @@ -127,7 +127,7 @@ class dbal_sqlite extends dbal $this->sql_error($query); } - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { $this->sql_report('stop', $query); } @@ -142,7 +142,7 @@ class dbal_sqlite extends dbal $this->open_queries[(int) $this->query_result] = $this->query_result; } } - else if (defined('DEBUG_EXTRA')) + else if (defined('DEBUG')) { $this->sql_report('fromcache', $query); } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 7801c48aa7..804d89d1a2 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -4191,7 +4191,7 @@ function msg_handler($errno, $msg_text, $errfile, $errline) $log_text .= '

BACKTRACE
' . $backtrace; } - if (defined('IN_INSTALL') || defined('DEBUG_EXTRA') || isset($auth) && $auth->acl_get('a_')) + if (defined('IN_INSTALL') || defined('DEBUG') || isset($auth) && $auth->acl_get('a_')) { $msg_text = $log_text; } @@ -5241,14 +5241,14 @@ function page_footer($run_cron = true) $mtime = explode(' ', microtime()); $totaltime = $mtime[0] + $mtime[1] - $starttime; - if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report')) + if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report')) { $db->sql_report('display'); } $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress'] && @extension_loaded('zlib')) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime); - if ($auth->acl_get('a_') && defined('DEBUG_EXTRA')) + if ($auth->acl_get('a_') && defined('DEBUG')) { if (function_exists('memory_get_peak_usage')) { diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index 11cc1f6dd8..2f3fd7bac0 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -145,14 +145,14 @@ function adm_page_footer($copyright_html = true) $mtime = explode(' ', microtime()); $totaltime = $mtime[0] + $mtime[1] - $starttime; - if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG_EXTRA') && method_exists($db, 'sql_report')) + if ($request->variable('explain', false) && $auth->acl_get('a_') && defined('DEBUG') && method_exists($db, 'sql_report')) { $db->sql_report('display'); } $debug_output = sprintf('Time : %.3fs | ' . $db->sql_num_queries() . ' Queries | GZIP : ' . (($config['gzip_compress']) ? 'On' : 'Off') . (($user->load) ? ' | Load : ' . $user->load : ''), $totaltime); - if ($auth->acl_get('a_') && defined('DEBUG_EXTRA')) + if ($auth->acl_get('a_') && defined('DEBUG')) { if (function_exists('memory_get_peak_usage')) { diff --git a/phpBB/includes/functions_install.php b/phpBB/includes/functions_install.php index 3421c90c88..7a799993db 100644 --- a/phpBB/includes/functions_install.php +++ b/phpBB/includes/functions_install.php @@ -528,12 +528,10 @@ function phpbb_create_config_file_data($data, $dbms, $debug = false, $debug_test if ($debug) { $config_data .= "@define('DEBUG', true);\n"; - $config_data .= "@define('DEBUG_EXTRA', true);\n"; } else { $config_data .= "// @define('DEBUG', true);\n"; - $config_data .= "// @define('DEBUG_EXTRA', true);\n"; } if ($debug_test) diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 257ffb07f6..ee8a4094c7 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -474,7 +474,7 @@ class phpbb_session else { // Added logging temporarly to help debug bugs... - if (defined('DEBUG_EXTRA') && $this->data['user_id'] != ANONYMOUS) + if (defined('DEBUG') && $this->data['user_id'] != ANONYMOUS) { if ($referer_valid) { diff --git a/phpBB/includes/template/template.php b/phpBB/includes/template/template.php index 5d3ce4c82b..367c02aa15 100644 --- a/phpBB/includes/template/template.php +++ b/phpBB/includes/template/template.php @@ -250,7 +250,7 @@ class phpbb_template * If template cache is writable the compiled php code will be stored * on filesystem and template will not be subsequently recompiled. * If template cache is not writable template source will be recompiled - * every time it is needed. DEBUG_EXTRA define and load_tplcompile + * every time it is needed. DEBUG define and load_tplcompile * configuration setting may be used to force templates to be always * recompiled. * @@ -268,7 +268,7 @@ class phpbb_template { $output_file = $this->_compiled_file_for_handle($handle); - $recompile = defined('DEBUG_EXTRA') || + $recompile = defined('DEBUG') || !file_exists($output_file) || @filesize($output_file) === 0; diff --git a/phpBB/includes/user.php b/phpBB/includes/user.php index 93557f3558..9ddd806b27 100644 --- a/phpBB/includes/user.php +++ b/phpBB/includes/user.php @@ -162,8 +162,8 @@ class phpbb_user extends phpbb_session // We include common language file here to not load it every time a custom language file is included $lang = &$this->lang; - // Do not suppress error if in DEBUG_EXTRA mode - $include_result = (defined('DEBUG_EXTRA')) ? (include $this->lang_path . $this->lang_name . "/common.$phpEx") : (@include $this->lang_path . $this->lang_name . "/common.$phpEx"); + // Do not suppress error if in DEBUG mode + $include_result = (defined('DEBUG')) ? (include $this->lang_path . $this->lang_name . "/common.$phpEx") : (@include $this->lang_path . $this->lang_name . "/common.$phpEx"); if ($include_result === false) { @@ -252,7 +252,7 @@ class phpbb_user extends phpbb_session // Disable board if the install/ directory is still present // For the brave development army we do not care about this, else we need to comment out this everytime we develop locally - if (!defined('DEBUG_EXTRA') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) + if (!defined('DEBUG') && !defined('ADMIN_START') && !defined('IN_INSTALL') && !defined('IN_LOGIN') && file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) { // Adjust the message slightly according to the permissions if ($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) @@ -618,8 +618,8 @@ class phpbb_user extends phpbb_session return; } - // Do not suppress error if in DEBUG_EXTRA mode - $include_result = (defined('DEBUG_EXTRA')) ? (include $language_filename) : (@include $language_filename); + // Do not suppress error if in DEBUG mode + $include_result = (defined('DEBUG')) ? (include $language_filename) : (@include $language_filename); if ($include_result === false) { diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index dcdd17cbc0..899394cd08 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -620,7 +620,7 @@ function _sql($sql, &$errored, &$error_ary, $echo_dot = true) { global $db; - if (defined('DEBUG_EXTRA')) + if (defined('DEBUG')) { echo "
\n{$sql}\n
"; } diff --git a/phpBB/install/install_convert.php b/phpBB/install/install_convert.php index b8045cb98b..41de9de44c 100644 --- a/phpBB/install/install_convert.php +++ b/phpBB/install/install_convert.php @@ -1196,7 +1196,7 @@ class install_convert extends module $template->assign_block_vars('checks', array( 'TITLE' => "skip_rows = $skip_rows", - 'RESULT' => $rows . ((defined('DEBUG_EXTRA') && function_exists('memory_get_usage')) ? ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] : ''), + 'RESULT' => $rows . ((defined('DEBUG') && function_exists('memory_get_usage')) ? ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] : ''), )); $mtime = explode(' ', microtime()); @@ -1380,7 +1380,7 @@ class install_convert extends module } // When we reach this point, either the current table has been processed or we're running out of time. - if (still_on_time() && $counting < $convert->batch_size/* && !defined('DEBUG_EXTRA')*/) + if (still_on_time() && $counting < $convert->batch_size/* && !defined('DEBUG')*/) { $skip_rows = 0; $current_table++; @@ -1469,7 +1469,7 @@ class install_convert extends module sync('topic', 'range', 'topic_id BETWEEN ' . $sync_batch . ' AND ' . $end, true, true); $template->assign_block_vars('checks', array( - 'TITLE' => sprintf($user->lang['SYNC_TOPIC_ID'], $sync_batch, ($sync_batch + $batch_size)) . ((defined('DEBUG_EXTRA') && function_exists('memory_get_usage')) ? ' [' . ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] . ']' : ''), + 'TITLE' => sprintf($user->lang['SYNC_TOPIC_ID'], $sync_batch, ($sync_batch + $batch_size)) . ((defined('DEBUG') && function_exists('memory_get_usage')) ? ' [' . ceil(memory_get_usage()/1024) . ' ' . $user->lang['KIB'] . ']' : ''), 'RESULT' => $user->lang['DONE'], )); @@ -1757,7 +1757,7 @@ class install_convert extends module global $convert; // Can we use IGNORE with this DBMS? - $sql_ignore = (strpos($db->sql_layer, 'mysql') === 0 && !defined('DEBUG_EXTRA')) ? 'IGNORE ' : ''; + $sql_ignore = (strpos($db->sql_layer, 'mysql') === 0 && !defined('DEBUG')) ? 'IGNORE ' : ''; $insert_query = 'INSERT ' . $sql_ignore . 'INTO ' . $schema['target'] . ' ('; $aliases = array();