From 4845dfa4253b2e35b20679010958ee1ae04a20b7 Mon Sep 17 00:00:00 2001 From: Benjamin Kitt Date: Sat, 12 Dec 2015 16:32:58 -0600 Subject: [PATCH 1/3] Trim leading slash from $_SERVER["SCRIPT_NAME"] so that server side rendered links are relative instead of absolute. --- base.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/base.php b/base.php index cd5257a..db809b6 100644 --- a/base.php +++ b/base.php @@ -375,13 +375,16 @@ class Link class LinkNavigation extends Link { public function __construct($phref, $prel = NULL, $ptitle = NULL) { + error_log("BENTEST: " . $_SERVER["SCRIPT_NAME"]); parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; if (preg_match ("/(bookdetail|getJSON).php/", $_SERVER["SCRIPT_NAME"])) { $this->href = "index.php" . $this->href; + error_log("BENTEST2: " . $this->href); } else { - $this->href = $_SERVER["SCRIPT_NAME"] . $this->href; + $this->href = trim($_SERVER["SCRIPT_NAME"],'/') . $this->href; + error_log("BENTEST3: " . $this->href); } } } @@ -389,6 +392,7 @@ class LinkNavigation extends Link class LinkFacet extends Link { public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { + error_log("BENTEST: " . $_SERVER["SCRIPT_NAME"]); parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet); if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); $this->href = $_SERVER["SCRIPT_NAME"] . $this->href; From 0ef551c8c828c45bd9e000ce942e5b6f040f58f7 Mon Sep 17 00:00:00 2001 From: Benjamin Kitt Date: Sat, 12 Dec 2015 16:37:02 -0600 Subject: [PATCH 2/3] Remove logging --- base.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/base.php b/base.php index db809b6..0ecaa54 100644 --- a/base.php +++ b/base.php @@ -375,16 +375,13 @@ class Link class LinkNavigation extends Link { public function __construct($phref, $prel = NULL, $ptitle = NULL) { - error_log("BENTEST: " . $_SERVER["SCRIPT_NAME"]); parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; if (preg_match ("/(bookdetail|getJSON).php/", $_SERVER["SCRIPT_NAME"])) { $this->href = "index.php" . $this->href; - error_log("BENTEST2: " . $this->href); } else { $this->href = trim($_SERVER["SCRIPT_NAME"],'/') . $this->href; - error_log("BENTEST3: " . $this->href); } } } From fb99de7159a10be4d548bc7a6ceb91d92aa8a7ab Mon Sep 17 00:00:00 2001 From: Benjamin Kitt Date: Mon, 14 Dec 2015 12:57:32 -0600 Subject: [PATCH 3/3] Add getScriptName() method to Link class as suggested by @seblucas (see seblucas/cops#232) Replace references to $_SERVER["SCRIPT_NAME"] with calls to getScriptName() Leaves reference to $_SERVER["SCRIPT_NAME"] in Data:handleThumbnailLink() as it does not inherit from Link --- base.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/base.php b/base.php index 0ecaa54..ad1fceb 100644 --- a/base.php +++ b/base.php @@ -370,6 +370,11 @@ class Link public function hrefXhtml () { return $this->href; } + + public function getScriptName() { + $parts = explode('/', $_SERVER["SCRIPT_NAME"]); + return $parts[count($parts) - 1]; + } } class LinkNavigation extends Link @@ -378,10 +383,10 @@ class LinkNavigation extends Link parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle); if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); if (!preg_match ("#^\?(.*)#", $this->href) && !empty ($this->href)) $this->href = "?" . $this->href; - if (preg_match ("/(bookdetail|getJSON).php/", $_SERVER["SCRIPT_NAME"])) { + if (preg_match ("/(bookdetail|getJSON).php/", parent::getScriptName())) { $this->href = "index.php" . $this->href; } else { - $this->href = trim($_SERVER["SCRIPT_NAME"],'/') . $this->href; + $this->href = parent::getScriptName() . $this->href; } } } @@ -389,10 +394,9 @@ class LinkNavigation extends Link class LinkFacet extends Link { public function __construct($phref, $ptitle = NULL, $pfacetGroup = NULL, $pactiveFacet = FALSE) { - error_log("BENTEST: " . $_SERVER["SCRIPT_NAME"]); parent::__construct ($phref, Link::OPDS_PAGING_TYPE, "http://opds-spec.org/facet", $ptitle, $pfacetGroup, $pactiveFacet); if (!is_null (GetUrlParam (DB))) $this->href = addURLParameter ($this->href, DB, GetUrlParam (DB)); - $this->href = $_SERVER["SCRIPT_NAME"] . $this->href; + $this->href = parent::getScriptName() . $this->href; } }