diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-28 19:19:28 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-08-28 19:19:28 +0200 |
commit | 2f67340e551b12dce8824381c3291bb2137857cb (patch) | |
tree | 2342cb35b5b337e083bb2fdc866a3d10d92f99c7 /utility/articleenhancer/articleenhancer.php | |
parent | a9eb72911b6f022da645dc08cf8c0f4b1702d1e1 (diff) |
Possible backwards incompatible change by using the link provided by simplepie instead of the user for the url hash. This prevents duplication of the feed when adding a slightly different feed url which points to the same feed and allows a speedup from O(n) to O(1) for article enhanchers
Diffstat (limited to 'utility/articleenhancer/articleenhancer.php')
-rw-r--r-- | utility/articleenhancer/articleenhancer.php | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/utility/articleenhancer/articleenhancer.php b/utility/articleenhancer/articleenhancer.php index d7701d53b..194137e72 100644 --- a/utility/articleenhancer/articleenhancer.php +++ b/utility/articleenhancer/articleenhancer.php @@ -60,27 +60,23 @@ abstract class ArticleEnhancer { } - public function canHandle($item){ - return preg_match($this->articleUrlRegex, $item->getUrl()) == true; - } - - public function enhance($item){ - $file = $this->fileFactory->getFile($item->getUrl(), $this->maximumTimeout); - $dom = new \DOMDocument(); - @$dom->loadHTML($file->body); - $xpath = new \DOMXpath($dom); - $xpathResult = $xpath->evaluate($this->articleXPath); - - // in case it wasnt a text query assume its a single - if(!is_string($xpathResult)) { - $xpathResult = $this->domToString($xpathResult); + if(preg_match($this->articleUrlRegex, $item->getUrl())) { + $file = $this->fileFactory->getFile($item->getUrl(), $this->maximumTimeout); + $dom = new \DOMDocument(); + @$dom->loadHTML($file->body); + $xpath = new \DOMXpath($dom); + $xpathResult = $xpath->evaluate($this->articleXPath); + + // in case it wasnt a text query assume its a single + if(!is_string($xpathResult)) { + $xpathResult = $this->domToString($xpathResult); + } + + $sanitizedResult = $this->purifier->purify($xpathResult); + $item->setBody($sanitizedResult); } - $sanitizedResult = $this->purifier->purify($xpathResult); - $item->setBody($sanitizedResult); - - return $item; } |