diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2013-09-27 20:03:00 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2013-09-27 20:03:16 +0200 |
commit | d6066c382083dedf426abbfd5f2f1df725c68aaf (patch) | |
tree | 4406388c5a827ebe8ed62234e11e49c35e16f3a5 /utility | |
parent | 30080c220a3f5013875d6a52e4dfe634719cbeca (diff) |
use seperate direcotires for article enhancers and fetchers
Diffstat (limited to 'utility')
-rw-r--r-- | utility/articleenhancer/articleenhancer.php | 33 | ||||
-rw-r--r-- | utility/articleenhancer/enhancer.php | 65 | ||||
-rw-r--r-- | utility/articleenhancer/regexarticleenhancer.php | 55 | ||||
-rw-r--r-- | utility/articleenhancer/regexenhancers.json | 12 | ||||
-rw-r--r-- | utility/articleenhancer/xpatharticleenhancer.php | 218 | ||||
-rw-r--r-- | utility/articleenhancer/xpathenhancers.json | 57 | ||||
-rw-r--r-- | utility/feedfetcher.php | 213 | ||||
-rw-r--r-- | utility/fetcher.php | 52 | ||||
-rw-r--r-- | utility/fetcherexception.php | 38 | ||||
-rw-r--r-- | utility/ifeedfetcher.php | 47 | ||||
-rw-r--r-- | utility/twitterfetcher.php | 69 |
11 files changed, 0 insertions, 859 deletions
diff --git a/utility/articleenhancer/articleenhancer.php b/utility/articleenhancer/articleenhancer.php deleted file mode 100644 index 1842a0c02..000000000 --- a/utility/articleenhancer/articleenhancer.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -/** -* ownCloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News\Utility\ArticleEnhancer; - -use \OCA\News\Db\Item; - - -interface ArticleEnhancer { - public function enhance(Item $item); -}
\ No newline at end of file diff --git a/utility/articleenhancer/enhancer.php b/utility/articleenhancer/enhancer.php deleted file mode 100644 index d7d96f6a9..000000000 --- a/utility/articleenhancer/enhancer.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -/** -* ownCloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News\Utility\ArticleEnhancer; - - -class Enhancer { - - private $enhancers = array(); - - public function registerEnhancer($feedUrl, ArticleEnhancer $enhancer){ - $feedUrl = $this->removeTrailingSlash($feedUrl); - - // create hashkeys for all supported protocols for quick access - $this->enhancers[$feedUrl] = $enhancer; - $this->enhancers['https://' . $feedUrl] = $enhancer; - $this->enhancers['http://' . $feedUrl] = $enhancer; - $this->enhancers['https://www.' . $feedUrl] = $enhancer; - $this->enhancers['http://www.' . $feedUrl] = $enhancer; - } - - - public function enhance($item, $feedUrl){ - $feedUrl = $this->removeTrailingSlash($feedUrl); - - if(array_key_exists($feedUrl, $this->enhancers)) { - return $this->enhancers[$feedUrl]->enhance($item); - } else { - return $item; - } - } - - - private function removeTrailingSlash($url) { - if($url[strlen($url)-1] === '/') { - return substr($url, 0, -1); - } else { - return $url; - } - } - - -}
\ No newline at end of file diff --git a/utility/articleenhancer/regexarticleenhancer.php b/utility/articleenhancer/regexarticleenhancer.php deleted file mode 100644 index dfd822c85..000000000 --- a/utility/articleenhancer/regexarticleenhancer.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php - -/** - * ownCloud - News - * - * @author Alessandro Cosentino - * @author Bernhard Posselt - * @copyright 2012 Alessandro Cosentino cosenal@gmail.com - * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE - * License as published by the Free Software Foundation; either - * version 3 of the License, or any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU AFFERO GENERAL PUBLIC LICENSE for more details. - * - * You should have received a copy of the GNU Affero General Public - * License along with this library. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\News\Utility\ArticleEnhancer; - -use \OCA\News\Utility\SimplePieFileFactory; -use \OCA\News\Db\Item; - - -class RegexArticleEnhancer implements ArticleEnhancer { - - private $matchArticleUrl; - private $regexPair; - - public function __construct($matchArticleUrl, array $regexPair) { - $this->matchArticleUrl = $matchArticleUrl; - $this->regexPair = $regexPair; - } - - - public function enhance(Item $item) { - if (preg_match($this->matchArticleUrl, $item->getUrl())) { - $body = $item->getBody(); - foreach($this->regexPair as $search => $replaceWith) { - $body = preg_replace($search, $replaceWith, $body); - } - $item->setBody($body); - } - return $item; - } - - -} diff --git a/utility/articleenhancer/regexenhancers.json b/utility/articleenhancer/regexenhancers.json deleted file mode 100644 index 95231985d..000000000 --- a/utility/articleenhancer/regexenhancers.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "twogag.com": { - "%(?:www.twogag.com/archives)|(feedproxy.google.com/~r/TwoGuysAndGuy)%": { - "%http://www.twogag.com/comics-rss/([^.]+)\\.jpg%": "http://www.twogag.com/comics/$1.jpg" - } - }, - "buttersafe.com": { - "%(?:buttersafe.com)|(feedproxy.google.com/~r/Buttersafe)%": { - "%buttersafe.com/comics/rss/([^.]+)RSS([^.]+)?.jpg%": "buttersafe.com/comics/$1$2.jpg" - } - } -} diff --git a/utility/articleenhancer/xpatharticleenhancer.php b/utility/articleenhancer/xpatharticleenhancer.php deleted file mode 100644 index c9cff238a..000000000 --- a/utility/articleenhancer/xpatharticleenhancer.php +++ /dev/null @@ -1,218 +0,0 @@ -<?php - -/** -* ownCloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News\Utility\ArticleEnhancer; - -use \OCA\News\Utility\SimplePieFileFactory; -use \OCA\News\Db\Item; - - -class XPathArticleEnhancer implements ArticleEnhancer { - - - private $feedRegex; - private $purifier; - private $fileFactory; - private $maximumTimeout; - - - /** - * @param $purifier the purifier object to clean the html which will be - * matched - * @param SimplePieFileFactory a factory for getting a simple pie file instance - * @param array $regexXPathPair an associative array containing regex to - * match the url and the xpath that should be used for it to extract the - * page - * @param int $maximumTimeout maximum timeout in seconds, defaults to 10 sec - */ - public function __construct($purifier, SimplePieFileFactory $fileFactory, - array $regexXPathPair, $maximumTimeout=10){ - $this->purifier = $purifier; - $this->regexXPathPair = $regexXPathPair; - $this->fileFactory = $fileFactory; - $this->maximumTimeout = $maximumTimeout; - } - - - public function enhance(Item $item){ - - foreach($this->regexXPathPair as $regex => $search) { - - if(preg_match($regex, $item->getUrl())) { - $file = $this->fileFactory->getFile($item->getUrl(), $this->maximumTimeout); - - // convert encoding by detecting charset from header - $contentType = $file->headers['content-type']; - if( preg_match( '/(?<=charset=)[^;]*/', $contentType, $matches ) ) { - $body = mb_convert_encoding($file->body, 'HTML-ENTITIES', $matches[0]); - } else { - $body = $file->body; - } - - $dom = new \DOMDocument(); - @$dom->loadHTML($body); - - $xpath = new \DOMXpath($dom); - $xpathResult = $xpath->evaluate($search); - - // in case it wasnt a text query assume its a single - if(!is_string($xpathResult)) { - $xpathResult = $this->domToString($xpathResult); - } - - // convert all relative to absolute URLs - $xpathResult = $this->substituteRelativeLinks($xpathResult, $item->getUrl()); - - $sanitizedResult = $this->purifier->purify($xpathResult); - $item->setBody($sanitizedResult); - } - } - - return $item; - } - - - /** - * Method which converts all relative "href" and "src" URLs of - * a HTML snippet with their absolute equivalent - * @param string $xmlString a HTML snippet as string with the relative URLs to be replaced - * @param string $absoluteUrl the approptiate absolute url of the HTML snippet - * @return string the result HTML snippet as a string - */ - protected function substituteRelativeLinks($xmlString, $absoluteUrl) { - $dom = new \DOMDocument(); - $dom->preserveWhiteSpace = false; - - // return, if xml is empty or loading the HTML fails - if( trim($xmlString) == "" || !@$dom->loadHTML($xmlString) ) { - return $xmlString; - } - - // remove <!DOCTYPE - $dom->removeChild($dom->firstChild); - // remove <html></html> - $dom->replaceChild($dom->firstChild->firstChild, $dom->firstChild); - - $substitution = array("href", "src"); - - foreach ($substitution as $attribute) { - $xpath = new \DOMXpath($dom); - $xpathResult = $xpath->query( - "//*[@" . $attribute . " " . - "and not(contains(@" . $attribute . ", '://')) " . - "and not(starts-with(@" . $attribute . ", 'mailto:'))]"); - foreach ($xpathResult as $linkNode) { - $urlElement = $linkNode->attributes->getNamedItem($attribute); - $abs = $this->relativeToAbsoluteUrl( $urlElement->nodeValue, $absoluteUrl ); - $urlElement->nodeValue = htmlspecialchars($abs); - } - } - - // save dom to string and remove <body></body> - $xmlString = substr(trim($dom->saveHTML()), 6, -7); - // domdocument spoils the string with line breaks between the elements. strip them. - $xmlString = str_replace("\n", "", $xmlString); - - return $xmlString; - } - - - /** - * Method which builds a URL by taking a relative URL and its corresponding - * absolute URL - * For examle relative URL "../example/path/file.php?a=1#anchor" and - * absolute URL "https://username:password@www.website.com/subfolder/index.html" - * will result in "https://username:password@www.website.com/example/path/file.php?a=1#anchor" - * @param string $relativeUrl the relative URL - * @param string $absoluteUrl the absolute URL with at least scheme and host - * @return string the resulting absolute URL - */ - protected function relativeToAbsoluteUrl($relativeUrl, $absoluteUrl) { - $abs = parse_url($absoluteUrl); - - $newUrl = $abs["scheme"]."://" - .( (isset($abs["user"])) ? $abs["user"] . ( (isset($abs["pass"])) ? ":".$abs["pass"] : "") . "@" : "" ) - .$abs["host"] - .( (isset($abs["port"])) ? ":".$abs["port"] : "" ); - - if(substr(trim($relativeUrl), 0, 1) == "/") { - // we have a relative url like "/a/path/file" - return $newUrl . $relativeUrl; - } else { - // we have a relative url like "a/path/file", handle "."" and ".." directories - - // the starting point is the absolute path, but with out the last part (we don't need the file name) - $newPath = explode("/", substr($abs["path"], 1) ); - array_pop($newPath); - - $relPath = parse_url($relativeUrl, PHP_URL_PATH); - $relPath = explode("/", $relPath); - - // cross the relative and the absolute path - for($i=0; $i<count($relPath)-1; $i++) { - if($relPath[$i] == ".") { - continue; - } elseif($relPath[$i] == "..") { - array_pop($newPath); - } else { - $newPath[] = $relPath[$i]; - } - } - - // add the last part (the file name) of the relative URL - $newPath[] = $relPath[ count($relPath)-1 ]; - $newPath = implode("/", $newPath); - - $rel = parse_url($relativeUrl); - return $newUrl . "/" . $newPath - . ( (isset($rel["query"])) ? "?".$rel["query"] : "") - . ( (isset($rel["fragment"])) ? "#".$rel["fragment"] : ""); - } - } - - - /** - * Method which turns an xpath result to a string - * you can customize it by overwriting this method - * @param $xpathResult the result from the xpath query - * @return the result as a string - */ - protected function domToString($xpathResult) { - $result = ""; - foreach($xpathResult as $node) { - $result .= $this->toInnerHTML($node); - } - return $result; - } - - - protected function toInnerHTML($node) { - $dom = new \DOMDocument(); - $dom->appendChild($dom->importNode($node, true)); - return trim($dom->saveHTML($dom->documentElement)); - } - - -}
\ No newline at end of file diff --git a/utility/articleenhancer/xpathenhancers.json b/utility/articleenhancer/xpathenhancers.json deleted file mode 100644 index 29296c79f..000000000 --- a/utility/articleenhancer/xpathenhancers.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "cad-comic.com": { - "%cad-comic.com/cad/\\d+/$%": "//*[@id='content']/img" - }, - "explosm.net": { - "%explosm.net/comics%": "//*[@id='maincontent']/div[2]/div/img", - "%explosm.net/show%": "//*[@id='videoPlayer']/iframe" - }, - "themerepublic.net": { - "%feedproxy.google.com/~r/blogspot/DngUJ%": "//*[@class='post hentry']" - }, - "penny-arcade.com": { - "%feeds.penny-arcade.com/~r/pa-mainsite%": "//*[starts-with(@class, \"post\")]" - }, - "leasticoulddo.com": { - "%feedproxy.google.com/~r/LICD%": "//*[@id='comic-img']/a/img | //*[@id='comic-img']/img" - }, - "escapistmagazine.com/articles/view/comics/critical-miss": { - "%escapistmagazine.com/articles/view/comics/critical-miss%": "//*[@class='body']/span/img" - }, - "escapistmagazine.com/articles/view/comics/namegame": { - "%escapistmagazine.com/articles/view/comics/namegame%": "//*[@class='body']/span/p/img[@height != \"120\"]" - }, - "escapistmagazine.com/articles/view/comics/stolen-pixels": { - "%escapistmagazine.com/articles/view/comics/stolen-pixels%": "//*[@class='body']/span/p[2]/img" - }, - "escapistmagazine.com/articles/view/comics/bumhugparade": { - "%escapistmagazine.com/articles/view/comics/bumhugparade%": "//*[@class='body']/span/p[2]/img" - }, - "escapistmagazine.com/articles/view/comics/escapistradiotheater": { - "%escapistmagazine.com/articles/view/comics/escapistradiotheater%": "//*[@class='body']/span/p[2]/img" - }, - "escapistmagazine.com/articles/view/comics/paused": { - "%escapistmagazine.com/articles/view/comics/paused%": "//*[@class='body']/span/p[2]/img | //*[@class='body']/span/div/img" - }, - "escapistmagazine.com/articles/view/comics/fraughtwithperil": { - "%escapistmagazine.com/articles/view/comics/fraughtwithperil%": "//*[@class='body']" - }, - "trenchescomic.com": { - "%trenchescomic.com/comic%": "//*[@class=\"top\"]/img", - "%trenchescomic.com/tales%": "//*[@class=\"copy\"]" - }, - "lfgcomic.com": { - "%(lfgcomic.com/page)|(feedproxy.google.com/~r/LookingForGroup)%": "//*[@id=\"comic\"]/img | //*[@class=\"content\"]" - }, - "sandraandwoo.com": { - "%sandraandwoo.com%": "//*[@id=\"comic\"]/img | //*[@class=\"post\"]" - }, - "sandraandwoo.com/gaia": { - "%sandraandwoo.com%": "//*[@id=\"comic\"]/img | //*[@class=\"post\"]" - }, - "theoatmeal.com": { - "%theoatmeal.com/blog%": "//*[@class=\"post_body\"]", - "%theoatmeal.com/comics%": "//*[@id=\"comic\"] | //*[@class=\"super_vacum\"] | //*[@class=\"pad\"]" - } -} - diff --git a/utility/feedfetcher.php b/utility/feedfetcher.php deleted file mode 100644 index e36fe3beb..000000000 --- a/utility/feedfetcher.php +++ /dev/null @@ -1,213 +0,0 @@ -<?php - -/** -* ownCloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News\Utility; - -use \OCA\AppFramework\Core\API; -use \OCA\AppFramework\Utility\FaviconFetcher; -use \OCA\AppFramework\Utility\SimplePieAPIFactory; -use \OCA\AppFramework\Utility\TimeFactory; - -use \OCA\News\Db\Item; -use \OCA\News\Db\Feed; - - -class FeedFetcher implements IFeedFetcher { - - private $api; - private $cacheDirectory; - private $cacheDuration; - private $faviconFetcher; - private $simplePieFactory; - private $fetchTimeout; - private $time; - private $purifier; - - public function __construct(API $api, - SimplePieAPIFactory $simplePieFactory, - FaviconFetcher $faviconFetcher, - TimeFactory $time, - $cacheDirectory, - $cacheDuration, - $fetchTimeout, - $purifier){ - $this->api = $api; - $this->cacheDirectory = $cacheDirectory; - $this->cacheDuration = $cacheDuration; - $this->faviconFetcher = $faviconFetcher; - $this->simplePieFactory = $simplePieFactory; - $this->time = $time; - $this->purifier = $purifier; - $this->fetchTimeout = $fetchTimeout; - } - - - /** - * This fetcher handles all the remaining urls therefore always returns true - */ - public function canHandle($url){ - return true; - } - - - /** - * Fetch a feed from remote - * @param string url remote url of the feed - * @throws FetcherException if simple pie fails - * @return array an array containing the new feed and its items - */ - public function fetch($url, $getFavicon=true) { - $simplePie = $this->simplePieFactory->getCore(); - $simplePie->set_feed_url($url); - $simplePie->enable_cache(true); - $simplePie->set_timeout($this->fetchTimeout); - $simplePie->set_cache_location($this->cacheDirectory); - $simplePie->set_cache_duration($this->cacheDuration); - - if (!$simplePie->init()) { - throw new FetcherException('Could not initialize simple pie on feed with url ' . $url); - } - - - try { - // somehow $simplePie turns into a feed after init - $items = array(); - if ($feedItems = $simplePie->get_items()) { - foreach($feedItems as $feedItem) { - array_push($items, $this->buildItem($feedItem)); - } - } - - $feed = $this->buildFeed($simplePie, $url, $getFavicon); - - return array($feed, $items); - - } catch(\Exception $ex){ - throw new FetcherException($ex->getMessage()); - } - - } - - - private function decodeTwice($string) { - // behold! ' is not converted by PHP thats why we need to do it - // manually (TM) - return str_replace(''', '\'', - html_entity_decode( - html_entity_decode( - $string, ENT_QUOTES, 'UTF-8' - ), - ENT_QUOTES, 'UTF-8' - ) - ); - } - - - protected function buildItem($simplePieItem) { - $item = new Item(); - $item->setStatus(0); - $item->setUnread(); - $item->setUrl($this->decodeTwice($simplePieItem->get_permalink())); - - // unescape content because angularjs helps against XSS - $item->setTitle($this->decodeTwice($simplePieItem->get_title())); - $guid = $simplePieItem->get_id(); - $item->setGuid($guid); - - // links should always open in a new window - $item->setBody( - str_replace( - '<a', '<a target="_blank"', $this->purifier->purify( - $simplePieItem->get_content() - ) - ) - ); - - // pubdate is not required. if not given use the current date - $date = $simplePieItem->get_date('U'); - if(!$date) { - $date = $this->time->getTime(); - } - - $item->setPubDate($date); - - $item->setLastModified($this->time->getTime()); - - $author = $simplePieItem->get_author(); - if ($author !== null) { - $name = $this->decodeTwice($author->get_name()); - if ($name) { - $item->setAuthor($name); - } else { - $item->setAuthor($this->decodeTwice($author->get_email())); - } - } - - // TODO: make it work for video files also - $enclosure = $simplePieItem->get_enclosure(); - if($enclosure !== null) { - $enclosureType = $enclosure->get_type(); - if(stripos($enclosureType, "audio/") !== false) { - $item->setEnclosureMime($enclosureType); - $item->setEnclosureLink($enclosure->get_link()); - } - } - - return $item; - } - - - protected function buildFeed($simplePieFeed, $url, $getFavicon) { - $feed = new Feed(); - - // unescape content because angularjs helps against XSS - $title = $this->decodeTwice($simplePieFeed->get_title(), - ENT_COMPAT, 'UTF-8' ); - - // if there is no title use the url - if(!$title) { - $title = $url; - } - - $feed->setTitle($title); - $feed->setUrl($url); - $feed->setLink($simplePieFeed->get_permalink()); - $feed->setAdded($this->time->getTime()); - - if ($getFavicon) { - // use the favicon from the page first since most feeds use a weird image - $favicon = $this->faviconFetcher->fetch($feed->getLink()); - - if (!$favicon) { - $favicon = $simplePieFeed->get_image_url(); - } - - $feed->setFaviconLink($favicon); - } - - return $feed; - } - -} diff --git a/utility/fetcher.php b/utility/fetcher.php deleted file mode 100644 index 535e214de..000000000 --- a/utility/fetcher.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php - -/** -* ownCloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News\Utility; - - -class Fetcher { - - private $fetchers; - - public function __construct(){ - $this->fetchers = array(); - } - - - public function registerFetcher(IFeedFetcher $fetcher){ - array_push($this->fetchers, $fetcher); - } - - - public function fetch($url, $getFavicon=true){ - foreach($this->fetchers as $fetcher){ - if($fetcher->canHandle($url)){ - return $fetcher->fetch($url, $getFavicon); - } - } - } - - -}
\ No newline at end of file diff --git a/utility/fetcherexception.php b/utility/fetcherexception.php deleted file mode 100644 index b03619d0e..000000000 --- a/utility/fetcherexception.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -/** -* ownCloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News\Utility; - -class FetcherException extends \Exception { - - /** - * Constructor - * @param string $msg the error message - */ - public function __construct($msg){ - parent::__construct($msg); - } - -}
\ No newline at end of file diff --git a/utility/ifeedfetcher.php b/utility/ifeedfetcher.php deleted file mode 100644 index c37e82f31..000000000 --- a/utility/ifeedfetcher.php +++ /dev/null @@ -1,47 +0,0 @@ -<?php - -/** -* ownCloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News\Utility; - -interface IFeedFetcher { - - /** - * @param string url the url that the user entered in the add feed dialog - * box - * @throws FetcherException if the fetcher encounters a problem - * @return array with the first element being the feed and the - * second element being an array of items. Those items will be saved into - * into the database - */ - function fetch($url, $getFavicon=true); - - /** - * @param string $url the url that should be fetched - * @return boolean if the fetcher can handle the url. This fetcher will be - * used exclusively to fetch the feed and the items of the page - */ - function canHandle($url); - -}
\ No newline at end of file diff --git a/utility/twitterfetcher.php b/utility/twitterfetcher.php deleted file mode 100644 index 22ff9ffde..000000000 --- a/utility/twitterfetcher.php +++ /dev/null @@ -1,69 +0,0 @@ -<?php - -/** -* ownCloud - News -* -* @author Alessandro Cosentino -* @author Bernhard Posselt -* @copyright 2012 Alessandro Cosentino cosenal@gmail.com -* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -namespace OCA\News\Utility; - |