Browse Source

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
master
Benjamin Kitt 8 years ago
parent
commit
fb99de7159
1 changed files with 8 additions and 4 deletions
  1. +8
    -4
      base.php

+ 8
- 4
base.php View File

@@ -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;
}
}



Loading…
Cancel
Save