/** * Get a relative root path from the current URL * * @return string */ public function get_web_root_path() { if ($this->symfony_request === null) { return $this->phpbb_root_path; } if (null !== $this->web_root_path) { return $this->web_root_path; } // We do not need to escape $path_info, $request_uri and $script_name because we can not find their content in the result. // Path info (e.g. /foo/bar) $path_info = $this->filesystem->clean_path($this->symfony_request->getPathInfo()); // Full request URI (e.g. phpBB/app.php/foo/bar) $request_uri = $this->symfony_request->getRequestUri(); // Script name URI (e.g. phpBB/app.php) $script_name = $this->symfony_request->getScriptName(); /* * If the path info is empty but we're using app.php, then we * might be using an empty route like app.php/ which is * supported by symfony's routing */ if ($path_info === '/' && preg_match('/app\\.' . $this->php_ext . '\\/$/', $request_uri)) { return $this->web_root_path = $this->filesystem->clean_path('./../' . $this->phpbb_root_path); } /* * If the path info is empty (single /), then we're not using * a route like app.php/foo/bar */ if ($path_info === '/') { return $this->web_root_path = $this->phpbb_root_path; } /* * Check AJAX request: * If the current request is a AJAX we need to fix the paths. * We need to get the root path based on the Referer, so we can use * the generated URLs in the template of the Referer. If we do not * generate the relative path based on the Referer, but based on the * currently requested URL, the generated URLs will not point to the * intended locations: * Referer desired URL desired relative root path * memberlist.php faq.php ./ * memberlist.php app.php/foo/bar ./ * app.php/foo memberlist.php ../ * app.php/foo app.php/fox ../ * app.php/foo/bar memberlist.php ../../ * ../page.php memberlist.php ./phpBB/ * ../sub/page.php memberlist.php ./../phpBB/ * * The referer must be specified as a parameter in the query. */ if ($this->request->is_ajax() && $this->symfony_request->get('_referer')) { // We need to escape $absolute_board_url because it can be partially concatenated to the result. $absolute_board_url = $this->request->escape($this->symfony_request->getSchemeAndHttpHost() . $this->symfony_request->getBasePath(), true); $referer_web_root_path = $this->get_web_root_path_from_ajax_referer($this->symfony_request->get('_referer'), $absolute_board_url); return $this->web_root_path = $this->phpbb_root_path . $referer_web_root_path; } // How many corrections might we need? $corrections = substr_count($path_info, '/'); /* * If the script name (e.g. phpBB/app.php) does not exists in the * requestUri (e.g. phpBB/app.php/foo/template), then we are rewriting * the URL. So we must reduce the slash count by 1. */ if (strpos($request_uri, $script_name) !== 0) { $corrections--; } // Prepend ../ to the phpbb_root_path as many times as / exists in path_info $this->web_root_path = $this->filesystem->clean_path('./' . str_repeat('../', $corrections) . $this->phpbb_root_path); return $this->web_root_path; }