diff options
author | Pedro Amorim <[email protected]> | 2017-11-21 18:03:13 +0100 |
---|---|---|
committer | Pedro Amorim <[email protected]> | 2017-11-23 10:55:52 +0100 |
commit | 99db71502dd7221bd251785dba68a8fe93fdcb39 (patch) | |
tree | 38cfaa4bd263d36da37389705be2890777ce74d9 | |
parent | f7b3b3e0d71dcf84b4be4699a25df95c29682e34 (diff) |
Simplify calls to toAbsoluteUri()
-rw-r--r-- | src/HTMLParser.php | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php index a492307..b63deb7 100644 --- a/src/HTMLParser.php +++ b/src/HTMLParser.php @@ -339,8 +339,6 @@ class HTMLParser public function postProcessContent(DOMDocument $article) { - list($pathBase, $scheme, $prePath) = $this->getPathInfo($this->getConfig()->getOption('originalURL')); - // Readability cannot open relative uris so we convert them to absolute uris. if ($this->getConfig()->getOption('fixRelativeURLs')) { foreach (iterator_to_array($article->getElementsByTagName('a')) as $link) { @@ -353,7 +351,7 @@ class HTMLParser $text = $article->createTextNode($link->textContent); $link->parentNode->replaceChild($text, $link); } else { - $link->setAttribute('href', $this->toAbsoluteURI($href, $pathBase, $scheme, $prePath)); + $link->setAttribute('href', $this->toAbsoluteURI($href)); } } } @@ -362,7 +360,7 @@ class HTMLParser /** @var \DOMElement $img */ $src = $img->getAttribute('src'); if ($src) { - $img->setAttribute('src', $this->toAbsoluteURI($src, $pathBase, $scheme, $prePath)); + $img->setAttribute('src', $this->toAbsoluteURI($src)); } } } @@ -370,8 +368,10 @@ class HTMLParser return $article; } - private function toAbsoluteURI($uri, $pathBase, $scheme, $prePath) + private function toAbsoluteURI($uri) { + list($pathBase, $scheme, $prePath) = $this->getPathInfo($this->getConfig()->getOption('originalURL')); + // If this is already an absolute URI, return it. if (preg_match('/^[a-zA-Z][a-zA-Z0-9\+\-\.]*:/', $uri)) { return $uri; @@ -542,9 +542,8 @@ class HTMLParser } if ($this->getConfig()->getOption('fixRelativeURLs')) { - list($pathBase, $scheme, $prePath) = $this->getPathInfo($this->getConfig()->getOption('originalURL')); foreach ($result as &$imgSrc) { - $imgSrc = $this->toAbsoluteURI($imgSrc, $pathBase, $scheme, $prePath); + $imgSrc = $this->toAbsoluteURI($imgSrc); } } |