From 50f5bf7deb0567f2628db75041b9bafc56e3fc17 Mon Sep 17 00:00:00 2001 From: Piotr KUCHARSKI Date: Wed, 26 Nov 2014 21:27:30 +0100 Subject: [PATCH] improve rss self-url discovery: use ports if not standard, use other vars for scheme, remove extra '/'. --- rss.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/rss.php b/rss.php index aab1293..bb6b8b1 100644 --- a/rss.php +++ b/rss.php @@ -2,11 +2,31 @@ /*============================*/ /* Gallery address definition */ /*============================*/ -$gallery_protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; -$gallery_domain = $_SERVER['HTTP_HOST'].'/'; -$gallery_path = dirname($_SERVER['REQUEST_URI']); -$gallery_link = $gallery_protocol.$gallery_domain.$gallery_path; +if (!empty($_SERVER['REQUEST_SCHEME'])) { + $g_protocol = $_SERVER['REQUEST_SCHEME']; +} elseif (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { + $g_protocol = 'https'; +} else { + $g_protocol = 'http'; +} +$g_host = $_SERVER['HTTP_HOST']; +$g_port = $_SERVER['SERVER_PORT']; +$g_path = dirname($_SERVER['REQUEST_URI']); + +// remove default ports +if (($g_protocol == 'https' && $g_port == '443') || + ($g_protocol == 'http' && $g_port == '80')) { + $g_port = ''; +} else { + $g_port = ':' . $g_port; +} + +if ($g_path[0] != '/') { + $g_path = '/' . $g_path; +} + +$gallery_link = $g_protocol . '://' . $g_host . $g_port . $g_path; /*===================*/ /* Functions */