[ticket/12099] Fix web root path for non ./ root paths

If the current request is an 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/

https://tracker.phpbb.com/browse/PHPBB3-12099