diff options
author | Nils Adermann <naderman@naderman.de> | 2013-09-17 16:56:50 +0200 |
---|---|---|
committer | Nils Adermann <naderman@naderman.de> | 2013-09-17 16:56:50 +0200 |
commit | f039a3308a3d57e7b9fab562bdd71cf1a9fb4dc9 (patch) | |
tree | 1fff31b35cc52590b0f14ef3b1f457cb84ad448c /phpBB/includes | |
parent | 13ba981fc300171d88a197107317f3f1391ddb03 (diff) | |
parent | 6ba2fb6d62bb1429665f9e1b4f22dd241508950b (diff) | |
download | forums-f039a3308a3d57e7b9fab562bdd71cf1a9fb4dc9.tar forums-f039a3308a3d57e7b9fab562bdd71cf1a9fb4dc9.tar.gz forums-f039a3308a3d57e7b9fab562bdd71cf1a9fb4dc9.tar.bz2 forums-f039a3308a3d57e7b9fab562bdd71cf1a9fb4dc9.tar.xz forums-f039a3308a3d57e7b9fab562bdd71cf1a9fb4dc9.zip |
Merge remote-tracking branch 'github-phpbb/develop' into ticket/11700
* github-phpbb/develop:
[ticket/11832] Correct paths in tests
[ticket/11832] Correct ROOT_PATH variable
[ticket/11832] get_url() from phpbb_template_asset should return web path
[ticket/11832] Fix INCLUDE(JS/CSS)
[ticket/11832] Fix constructions of phpbb_filesystem
[ticket/11832] Fix smiley paths
[ticket/11832] Create phpbb_symfony_request to handle initiating symfony_request
[ticket/11832] Fix build_url and the S_LOGIN_ACTION
[ticket/11832] Changing comments to say app.php rather than index.php
[ticket/11832] We must instantiate the $phpbb_filesystem in common
[ticket/11832] Fix the web path corrections
[ticket/11832] More extensive testing
[ticket/11832] Use dirname(__FILE__)
[ticket/11832] Use $phpbb_filesystem instead of the container in append_sid
Revert "[ticket/11832] Make $phpbb_container a global initiated by the framework"
[ticket/11832] Make $phpbb_container a global initiated by the framework
[ticket/11832] Fix log tests
[ticket/11832] update_web_root_path helper and tests
[ticket/11832] Inject dependencies for phpbb_get_web_root_path (also moving)
Conflicts:
phpBB/common.php
phpBB/config/services.yml
phpBB/includes/bbcode.php
phpBB/includes/functions.php
phpBB/includes/functions_messenger.php
phpBB/install/index.php
phpBB/phpbb/filesystem.php
phpBB/phpbb/template/twig/environment.php
phpBB/phpbb/template/twig/node/includeasset.php
phpBB/phpbb/template/twig/twig.php
tests/controller/helper_url_test.php
tests/dbal/migrator_test.php
tests/extension/manager_test.php
tests/extension/metadata_manager_test.php
tests/filesystem/clean_path_test.php
tests/mock/extension_manager.php
tests/template/template_events_test.php
tests/template/template_test_case.php
tests/template/template_test_case_with_tree.php
tests/test_framework/phpbb_functional_test_case.php
Diffstat (limited to 'phpBB/includes')
-rw-r--r-- | phpBB/includes/bbcode.php | 4 | ||||
-rw-r--r-- | phpBB/includes/functions.php | 139 | ||||
-rw-r--r-- | phpBB/includes/functions_content.php | 4 | ||||
-rw-r--r-- | phpBB/includes/functions_messenger.php | 4 |
4 files changed, 39 insertions, 112 deletions
diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php index b6da41f9aa..f617b4b10a 100644 --- a/phpBB/includes/bbcode.php +++ b/phpBB/includes/bbcode.php @@ -126,13 +126,13 @@ class bbcode */ function bbcode_cache_init() { - global $phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager; + global $phpbb_root_path, $phpEx, $config, $user, $phpbb_extension_manager, $phpbb_filesystem; if (empty($this->template_filename)) { $this->template_bitfield = new bitfield($user->style['bbcode_bitfield']); - $template = new \phpbb\template\twig($phpbb_root_path, $phpEx, $config, $user, new phpbb_template_context(), $phpbb_extension_manager); + $template = new phpbb\template\twig\twig($phpbb_filesystem, $config, $user, new phpbb_template_context(), $phpbb_extension_manager); $template->set_style(); $template->set_filenames(array('bbcode.html' => 'bbcode.html')); $this->template_filename = $template->get_source_file_for_handle('bbcode.html'); diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 03a4895433..53ee8c2512 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -7,8 +7,6 @@ * */ -use Symfony\Component\HttpFoundation\Request; - /** * @ignore */ @@ -1072,7 +1070,14 @@ function phpbb_clean_path($path) global $phpbb_root_path, $phpEx; require($phpbb_root_path . 'includes/filesystem.' . $phpEx); } - $phpbb_filesystem = new \phpbb\filesystem(); + + $phpbb_filesystem = new phpbb\filesystem( + new phpbb\symfony\request( + new phpbb\request\request() + ), + $phpbb_root_path, + $phpEx + ); } return $phpbb_filesystem->clean_path($path); @@ -2410,9 +2415,8 @@ function phpbb_on_page($template, $user, $base_url, $num_items, $per_page, $star */ function append_sid($url, $params = false, $is_amp = true, $session_id = false) { - global $_SID, $_EXTRA_URL, $phpbb_hook; + global $_SID, $_EXTRA_URL, $phpbb_hook, $phpbb_filesystem; global $phpbb_dispatcher; - global $symfony_request, $phpbb_root_path; if ($params === '' || (is_array($params) && empty($params))) { @@ -2420,10 +2424,10 @@ function append_sid($url, $params = false, $is_amp = true, $session_id = false) $params = false; } - $corrected_path = $symfony_request !== null ? phpbb_get_web_root_path($symfony_request, $phpbb_root_path) : ''; - if ($corrected_path) + // Update the root path with the correct relative web path + if ($phpbb_filesystem instanceof phpbb_filesystem) { - $url = substr($corrected_path . $url, strlen($phpbb_root_path)); + $url = $phpbb_filesystem->update_web_root_path($url); } $append_sid_overwrite = false; @@ -2815,8 +2819,22 @@ function build_url($strip_vars = false) { global $user, $phpbb_root_path; + $page = $user->page['page']; + + // We need to be cautious here. + // On some situations, the redirect path is an absolute URL, sometimes a relative path + // For a relative path, let's prefix it with $phpbb_root_path to point to the correct location, + // else we use the URL directly. + $url_parts = parse_url($page); + + // URL + if ($url_parts !== false && !empty($url_parts['scheme']) && !empty($url_parts['host'])) + { + $page = $phpbb_root_path . $page; + } + // Append SID - $redirect = append_sid($user->page['page'], false, false); + $redirect = append_sid($page, false, false); // Add delimiter if not there... if (strpos($redirect, '?') === false) @@ -2871,19 +2889,7 @@ function build_url($strip_vars = false) $redirect .= ($query) ? '?' . $query : ''; } - // We need to be cautious here. - // On some situations, the redirect path is an absolute URL, sometimes a relative path - // For a relative path, let's prefix it with $phpbb_root_path to point to the correct location, - // else we use the URL directly. - $url_parts = @parse_url($redirect); - - // URL - if ($url_parts !== false && !empty($url_parts['scheme']) && !empty($url_parts['host'])) - { - return str_replace('&', '&', $redirect); - } - - return $phpbb_root_path . str_replace('&', '&', $redirect); + return str_replace('&', '&', $redirect); } /** @@ -5080,7 +5086,7 @@ function phpbb_build_hidden_fields_for_query_params($request, $exclude = null) function page_header($page_title = '', $display_online_list = true, $item_id = 0, $item = 'forum') { global $db, $config, $template, $SID, $_SID, $_EXTRA_URL, $user, $auth, $phpEx, $phpbb_root_path; - global $phpbb_dispatcher, $request, $phpbb_container, $symfony_request; + global $phpbb_dispatcher, $request, $phpbb_container, $adm_relative_path; if (defined('HEADER_INC')) { @@ -5240,7 +5246,8 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 // This path is sent with the base template paths in the assign_vars() // call below. We need to correct it in case we are accessing from a // controller because the web paths will be incorrect otherwise. - $corrected_path = $symfony_request !== null ? phpbb_get_web_root_path($symfony_request, $phpbb_root_path) : ''; + $phpbb_filesystem = $phpbb_container->get('filesystem'); + $corrected_path = $phpbb_filesystem->get_web_root_path(); $web_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? $board_url : $corrected_path; // Send a proper content-language to the output @@ -5322,7 +5329,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'SID' => $SID, '_SID' => $_SID, 'SESSION_ID' => $user->session_id, - 'ROOT_PATH' => $phpbb_root_path, + 'ROOT_PATH' => $web_path, 'BOARD_URL' => $board_url, 'L_LOGIN_LOGOUT' => $l_login_logout, @@ -5378,7 +5385,7 @@ function page_header($page_title = '', $display_online_list = true, $item_id = 0 'S_FORUM_ID' => $forum_id, 'S_TOPIC_ID' => $topic_id, - 'S_LOGIN_ACTION' => ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("index.$phpEx", false, true, $user->session_id)), + 'S_LOGIN_ACTION' => ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("{$phpbb_root_path}{$adm_relative_path}index.$phpEx", false, true, $user->session_id)), 'S_LOGIN_REDIRECT' => build_hidden_fields(array('redirect' => build_url())), 'S_ENABLE_FEEDS' => ($config['feed_enable']) ? true : false, @@ -5705,83 +5712,3 @@ function phpbb_convert_30_dbms_to_31($dbms) throw new \RuntimeException("You have specified an invalid dbms driver: $dbms"); } - -/** -* Create a Symfony Request object from \phpbb\request\request object -* -* @param \phpbb\request\request $request Request object -* @return Request A Symfony Request object -*/ -function phpbb_create_symfony_request(\phpbb\request\request $request) -{ - // If we have already gotten it, don't go back through all the trouble of - // creating it again; instead, just return it. This allows multiple calls - // of this method so we don't have to globalize $symfony_request in other - // functions. - static $symfony_request; - if (null !== $symfony_request) - { - return $symfony_request; - } - - // This function is meant to sanitize the global input arrays - $sanitizer = function(&$value, $key) { - $type_cast_helper = new \phpbb\request\type_cast_helper(); - $type_cast_helper->set_var($value, $value, gettype($value), true); - }; - - // We need to re-enable the super globals so we can access them here - $request->enable_super_globals(); - $get_parameters = $_GET; - $post_parameters = $_POST; - $server_parameters = $_SERVER; - $files_parameters = $_FILES; - $cookie_parameters = $_COOKIE; - // And now disable them again for security - $request->disable_super_globals(); - - array_walk_recursive($get_parameters, $sanitizer); - array_walk_recursive($post_parameters, $sanitizer); - - $symfony_request = new Request($get_parameters, $post_parameters, array(), $cookie_parameters, $files_parameters, $server_parameters); - return $symfony_request; -} - -/** -* Get a relative root path from the current URL -* -* @param Request $symfony_request Symfony Request object -*/ -function phpbb_get_web_root_path(Request $symfony_request, $phpbb_root_path = '') -{ - global $phpbb_container; - - static $path; - if (null !== $path) - { - return $path; - } - - $path_info = $symfony_request->getPathInfo(); - if ($path_info === '/') - { - $path = $phpbb_root_path; - return $path; - } - - $filesystem = $phpbb_container->get('filesystem'); - $path_info = $filesystem->clean_path($path_info); - - // Do not count / at start of path - $corrections = substr_count(substr($path_info, 1), '/'); - - // When URL Rewriting is enabled, app.php is optional. We have to - // correct for it not being there - if (strpos($symfony_request->getRequestUri(), $symfony_request->getScriptName()) === false) - { - $corrections -= 1; - } - - $path = $phpbb_root_path . str_repeat('../', $corrections); - return $path; -} diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 05d3c5fde2..5fa37f60bd 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -813,7 +813,7 @@ function bbcode_nl2br($text) */ function smiley_text($text, $force_option = false) { - global $config, $user, $phpbb_root_path; + global $config, $user, $phpbb_filesystem; if ($force_option || !$config['allow_smilies'] || !$user->optionget('viewsmilies')) { @@ -821,7 +821,7 @@ function smiley_text($text, $force_option = false) } else { - $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_root_path; + $root_path = (defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH) ? generate_board_url() . '/' : $phpbb_filesystem->get_web_root_path(); return preg_replace('#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/(.*?) \/><!\-\- s\1 \-\->#', '<img class="smilies" src="' . $root_path . $config['smilies_path'] . '/\2 />', $text); } } diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php index e5eff46fe0..f8b01bc770 100644 --- a/phpBB/includes/functions_messenger.php +++ b/phpBB/includes/functions_messenger.php @@ -626,14 +626,14 @@ class messenger */ protected function setup_template() { - global $config, $phpbb_root_path, $phpEx, $user, $phpbb_extension_manager; + global $config, $phpbb_filesystem, $user, $phpbb_extension_manager; if ($this->template instanceof \phpbb\template\template) { return; } - $this->template = new \phpbb\template\twig\twig($phpbb_root_path, $phpEx, $config, $user, new \phpbb\template\context(), $phpbb_extension_manager); + $this->template = new \phpbb\template\twig\twig($phpbb_filesystem, $config, $user, new \phpbb\template\context(), $phpbb_extension_manager); } /** |