From f1fb95b2575dd57ec2f9d0fbb844762b7cb21cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 25 Sep 2016 23:22:33 +0200 Subject: [PATCH] [core] extract BridgeAbstract methods to make them functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - returnError, returnServerError, returnClientError ,debugMessage are moved to lib/error.php - getContents, getSimpleHTMLDOM, getSimpleHTMLDOMCached are moved to lib/contents.php Signed-off-by: Pierre Mazière --- bridges/ABCTabsBridge.php | 2 +- bridges/AcrimedBridge.php | 2 +- bridges/AllocineFRBridge.php | 4 +- bridges/AnimeUltimeBridge.php | 8 +- bridges/Arte7Bridge.php | 2 +- bridges/AskfmBridge.php | 4 +- bridges/BandcampBridge.php | 4 +- bridges/BastaBridge.php | 6 +- bridges/BlaguesDeMerdeBridge.php | 4 +- bridges/CADBridge.php | 2 +- bridges/CNETBridge.php | 4 +- bridges/CastorusBridge.php | 14 +- bridges/CollegeDeFranceBridge.php | 4 +- bridges/CommonDreamsBridge.php | 2 +- bridges/CopieDoubleBridge.php | 4 +- bridges/CourrierInternationalBridge.php | 6 +- bridges/CpasbienBridge.php | 6 +- bridges/CryptomeBridge.php | 4 +- bridges/DailymotionBridge.php | 6 +- bridges/DanbooruBridge.php | 4 +- bridges/DansTonChatBridge.php | 4 +- bridges/DauphineLibereBridge.php | 2 +- bridges/DeveloppezDotComBridge.php | 2 +- bridges/DilbertBridge.php | 2 +- bridges/DuckDuckGoBridge.php | 4 +- bridges/EZTVBridge.php | 4 +- bridges/EliteDangerousGalnetBridge.php | 4 +- bridges/ElsevierBridge.php | 2 +- bridges/EstCeQuonMetEnProdBridge.php | 2 +- bridges/FacebookBridge.php | 14 +- bridges/FeedExpanderExampleBridge.php | 4 +- bridges/FierPandaBridge.php | 2 +- bridges/FlickrExploreBridge.php | 8 +- bridges/FlickrTagBridge.php | 8 +- bridges/FootitoBridge.php | 4 +- bridges/FourchanBridge.php | 4 +- bridges/FuturaSciencesBridge.php | 4 +- bridges/GBAtempBridge.php | 8 +- bridges/GiphyBridge.php | 8 +- bridges/GithubIssueBridge.php | 6 +- bridges/GizmodoBridge.php | 2 +- bridges/GooglePlusPostBridge.php | 6 +- bridges/GoogleSearchBridge.php | 4 +- bridges/HDWallpapersBridge.php | 2 +- bridges/HentaiHavenBridge.php | 4 +- bridges/IdenticaBridge.php | 4 +- bridges/InstagramBridge.php | 4 +- bridges/IsoHuntBridge.php | 50 +++---- bridges/JapanExpoBridge.php | 6 +- bridges/KoreusBridge.php | 2 +- bridges/KununuBridge.php | 32 ++--- bridges/LWNprevBridge.php | 4 +- bridges/LeBonCoinBridge.php | 4 +- bridges/LeMondeInformatiqueBridge.php | 4 +- bridges/LegifranceJOBridge.php | 2 +- bridges/LesJoiesDuCodeBridge.php | 4 +- bridges/LichessBridge.php | 2 +- bridges/LinkedInCompanyBridge.php | 4 +- bridges/MangareaderBridge.php | 4 +- bridges/MoebooruBridge.php | 4 +- bridges/MondeDiploBridge.php | 4 +- bridges/MsnMondeBridge.php | 4 +- bridges/NasaApodBridge.php | 4 +- bridges/NeuviemeArtBridge.php | 2 +- bridges/NextInpactBridge.php | 2 +- bridges/NextgovBridge.php | 4 +- bridges/NiceMatinBridge.php | 2 +- bridges/NovelUpdatesBridge.php | 4 +- bridges/OpenClassroomsBridge.php | 4 +- bridges/ParuVenduImmoBridge.php | 4 +- bridges/PickyWallpapersBridge.php | 4 +- bridges/PinterestBridge.php | 8 +- bridges/PlanetLibreBridge.php | 6 +- bridges/RTBFBridge.php | 4 +- bridges/Releases3DSBridge.php | 4 +- bridges/ReporterreBridge.php | 4 +- bridges/Rue89Bridge.php | 2 +- bridges/ScmbBridge.php | 4 +- bridges/ScoopItBridge.php | 4 +- bridges/SensCritiqueBridge.php | 6 +- bridges/SexactuBridge.php | 2 +- bridges/ShanaprojectBridge.php | 22 +-- bridges/SoundcloudBridge.php | 8 +- bridges/StripeAPIChangeLogBridge.php | 4 +- bridges/SuperbWallpapersBridge.php | 8 +- bridges/T411Bridge.php | 8 +- bridges/TagBoardBridge.php | 4 +- bridges/TheCodingLoveBridge.php | 4 +- bridges/TheHackerNewsBridge.php | 4 +- bridges/TheOatMealBridge.php | 2 +- bridges/ThePirateBayBridge.php | 6 +- bridges/TwitchApiBridge.php | 4 +- bridges/TwitterBridge.php | 6 +- bridges/UnsplashBridge.php | 4 +- bridges/ViadeoCompanyBridge.php | 4 +- bridges/VineBridge.php | 4 +- bridges/VkBridge.php | 4 +- bridges/WallpaperStopBridge.php | 4 +- bridges/WeLiveSecurityBridge.php | 2 +- bridges/WhydBridge.php | 12 +- bridges/WikipediaBridge.php | 12 +- bridges/WordPressBridge.php | 4 +- bridges/WorldOfTanksBridge.php | 10 +- bridges/YoutubeBridge.php | 14 +- bridges/ZDNetBridge.php | 4 +- index.php | 5 +- lib/BridgeAbstract.php | 175 +----------------------- lib/FeedExpander.php | 32 ++--- lib/RssBridge.php | 2 + lib/contents.php | 142 +++++++++++++++++++ lib/error.php | 30 ++++ 111 files changed, 485 insertions(+), 477 deletions(-) create mode 100644 lib/contents.php create mode 100644 lib/error.php diff --git a/bridges/ABCTabsBridge.php b/bridges/ABCTabsBridge.php index 247ab00c..1e7e170c 100644 --- a/bridges/ABCTabsBridge.php +++ b/bridges/ABCTabsBridge.php @@ -8,7 +8,7 @@ class ABCTabsBridge extends BridgeAbstract{ public function collectData(){ $html = ''; - $html = $this->getSimpleHTMLDOM(static::URI.'tablatures/nouveautes.html') or $this->returnClientError('No results for this query.'); + $html = getSimpleHTMLDOM(static::URI.'tablatures/nouveautes.html') or returnClientError('No results for this query.'); $table = $html->find('table#myTable', 0)->children(1); foreach ($table->find('tr') as $tab) diff --git a/bridges/AcrimedBridge.php b/bridges/AcrimedBridge.php index 0042fc8b..f614f64e 100644 --- a/bridges/AcrimedBridge.php +++ b/bridges/AcrimedBridge.php @@ -14,7 +14,7 @@ class AcrimedBridge extends FeedExpander { $item = parent::parseItem($newsItem); $hs = new HTMLSanitizer(); - $articlePage = $this->getSimpleHTMLDOM($newsItem->link); + $articlePage = getSimpleHTMLDOM($newsItem->link); $article = $hs->sanitize($articlePage->find('article.article1', 0)->innertext); $article = HTMLSanitizer::defaultImageSrcTo($article, static::URI); $item['content'] = $article; diff --git a/bridges/AllocineFRBridge.php b/bridges/AllocineFRBridge.php index 82405b06..8dabd2d9 100644 --- a/bridges/AllocineFRBridge.php +++ b/bridges/AllocineFRBridge.php @@ -47,8 +47,8 @@ class AllocineFRBridge extends BridgeAbstract{ public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError("Could not request ".$this->getURI()." !"); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError("Could not request ".$this->getURI()." !"); $category=array_search( $this->getInput('category'), diff --git a/bridges/AnimeUltimeBridge.php b/bridges/AnimeUltimeBridge.php index 301475fc..1dbb75f6 100644 --- a/bridges/AnimeUltimeBridge.php +++ b/bridges/AnimeUltimeBridge.php @@ -38,8 +38,8 @@ class AnimeUltimeBridge extends BridgeAbstract { //Retrive page contents $url = self::URI.'history-0-1/'.$requestFilter; - $html = $this->getSimpleHTMLDOM($url) - or $this->returnServerError('Could not request Anime-Ultime: '.$url); + $html = getSimpleHTMLDOM($url) + or returnServerError('Could not request Anime-Ultime: '.$url); //Relases are sorted by day : process each day individually foreach ($html->find('div.history', 0)->find('h3') as $daySection) { @@ -67,8 +67,8 @@ class AnimeUltimeBridge extends BridgeAbstract { if (!empty($item_uri)) { //Retrieve description from description page and convert relative image src info absolute image src - $html_item = $this->getContents($item_uri) - or $this->returnServerError('Could not request Anime-Ultime: '.$item_uri); + $html_item = getContents($item_uri) + or returnServerError('Could not request Anime-Ultime: '.$item_uri); $item_description = substr( $html_item, strpos($html_item, 'class="principal_contain" align="center">') diff --git a/bridges/Arte7Bridge.php b/bridges/Arte7Bridge.php index 7080648e..460e3d6c 100644 --- a/bridges/Arte7Bridge.php +++ b/bridges/Arte7Bridge.php @@ -57,7 +57,7 @@ } $url = self::URI.'guide/'.$lang.'/plus7/'.$category; - $input = $this->getContents($url) or die('Could not request ARTE.'); + $input = getContents($url) or die('Could not request ARTE.'); if(strpos($input, 'categoryVideoSet') !== FALSE){ $input = explode('categoryVideoSet: ', $input); $input = explode('}},', $input[1]); diff --git a/bridges/AskfmBridge.php b/bridges/AskfmBridge.php index a4c22dfa..16ba1289 100644 --- a/bridges/AskfmBridge.php +++ b/bridges/AskfmBridge.php @@ -15,8 +15,8 @@ class AskfmBridge extends BridgeAbstract{ ); public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('Requested username can\'t be found.'); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Requested username can\'t be found.'); foreach($html->find('div.streamItem-answer') as $element) { $item = array(); diff --git a/bridges/BandcampBridge.php b/bridges/BandcampBridge.php index 77b88e6a..7fc68fcd 100644 --- a/bridges/BandcampBridge.php +++ b/bridges/BandcampBridge.php @@ -14,8 +14,8 @@ class BandcampBridge extends BridgeAbstract{ )); public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('No results for this query.'); foreach($html->find('li.item') as $release) { $script = $release->find('div.art', 0)->getAttribute('onclick'); diff --git a/bridges/BastaBridge.php b/bridges/BastaBridge.php index be366628..ce565230 100644 --- a/bridges/BastaBridge.php +++ b/bridges/BastaBridge.php @@ -11,8 +11,8 @@ class BastaBridge extends BridgeAbstract{ return preg_replace('/src=["\']{1}([^"\']+)/ims', 'src=\''.self::URI.'$1\'', $content); } - $html = $this->getSimpleHTMLDOM(self::URI.'spip.php?page=backend') - or $this->returnServerError('Could not request Bastamag.'); + $html = getSimpleHTMLDOM(self::URI.'spip.php?page=backend') + or returnServerError('Could not request Bastamag.'); $limit = 0; foreach($html->find('item') as $element) { @@ -21,7 +21,7 @@ class BastaBridge extends BridgeAbstract{ $item['title'] = $element->find('title', 0)->innertext; $item['uri'] = $element->find('guid', 0)->plaintext; $item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext); - $item['content'] = ReplaceImageUrl($this->getSimpleHTMLDOM($item['uri'])->find('div.texte', 0)->innertext); + $item['content'] = ReplaceImageUrl(getSimpleHTMLDOM($item['uri'])->find('div.texte', 0)->innertext); $this->items[] = $item; $limit++; } diff --git a/bridges/BlaguesDeMerdeBridge.php b/bridges/BlaguesDeMerdeBridge.php index 0392bed4..fc7dc7d0 100644 --- a/bridges/BlaguesDeMerdeBridge.php +++ b/bridges/BlaguesDeMerdeBridge.php @@ -8,8 +8,8 @@ class BlaguesDeMerdeBridge extends BridgeAbstract{ public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request BDM.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request BDM.'); foreach($html->find('article.joke_contener') as $element) { $item = array(); diff --git a/bridges/CADBridge.php b/bridges/CADBridge.php index b4e68d4f..47140f37 100644 --- a/bridges/CADBridge.php +++ b/bridges/CADBridge.php @@ -16,7 +16,7 @@ class CADBridge extends FeedExpander { } private function CADExtractContent($url) { - $html3 = $this->getSimpleHTMLDOMCached($url); + $html3 = getSimpleHTMLDOMCached($url); // The request might fail due to missing https support or wrong URL if($html3 == false) diff --git a/bridges/CNETBridge.php b/bridges/CNETBridge.php index 755033d1..08f1bea3 100644 --- a/bridges/CNETBridge.php +++ b/bridges/CNETBridge.php @@ -38,7 +38,7 @@ class CNETBridge extends BridgeAbstract { } $pageUrl = self::URI.(empty($this->getInput('topic')) ? '' : 'topics/'.$this->getInput('topic').'/'); - $html = $this->getSimpleHTMLDOM($pageUrl) or $this->returnServerError('Could not request CNET: '.$pageUrl); + $html = getSimpleHTMLDOM($pageUrl) or returnServerError('Could not request CNET: '.$pageUrl); $limit = 0; foreach($html->find('div.assetBody') as $element) { @@ -51,7 +51,7 @@ class CNETBridge extends BridgeAbstract { if (!empty($article_title) && !empty($article_uri) && strpos($article_uri, '/news/') !== false) { - $article_html = $this->getSimpleHTMLDOM($article_uri) or $this->returnServerError('Could not request CNET: '.$article_uri); + $article_html = getSimpleHTMLDOM($article_uri) or returnServerError('Could not request CNET: '.$article_uri); $article_content = trim(CleanArticle(ExtractFromDelimiters($article_html, '
getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request CopieDouble.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request CopieDouble.'); $table = $html->find('table table', 2); foreach($table->find('tr') as $element) diff --git a/bridges/CourrierInternationalBridge.php b/bridges/CourrierInternationalBridge.php index f91916f6..d2e1d74c 100644 --- a/bridges/CourrierInternationalBridge.php +++ b/bridges/CourrierInternationalBridge.php @@ -8,8 +8,8 @@ class CourrierInternationalBridge extends BridgeAbstract{ public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Error.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Error.'); $element = $html->find("article"); @@ -25,7 +25,7 @@ class CourrierInternationalBridge extends BridgeAbstract{ $item['uri'] = self::URI.$item['uri']; } - $page = $this->getSimpleHTMLDOM($item['uri']); + $page = getSimpleHTMLDOM($item['uri']); $cleaner = new HTMLSanitizer(); diff --git a/bridges/CpasbienBridge.php b/bridges/CpasbienBridge.php index 10af594d..bf130132 100644 --- a/bridges/CpasbienBridge.php +++ b/bridges/CpasbienBridge.php @@ -16,14 +16,14 @@ class CpasbienBridge extends BridgeAbstract { public function collectData(){ $request = str_replace(" ","-",trim($this->getInput('q'))); - $html = $this->getSimpleHTMLDOM(self::URI.'/recherche/'.urlencode($request).'.html') - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM(self::URI.'/recherche/'.urlencode($request).'.html') + or returnServerError('No results for this query.'); foreach ($html->find('#gauche',0)->find('div') as $episode) { if ($episode->getAttribute('class')=='ligne0' || $episode->getAttribute('class')=='ligne1') { - $htmlepisode=$this->getSimpleHTMLDOMCached($episode->find('a', 0)->getAttribute('href')); + $htmlepisode=getSimpleHTMLDOMCached($episode->find('a', 0)->getAttribute('href')); $item = array(); $item['author'] = $episode->find('a', 0)->text(); diff --git a/bridges/CryptomeBridge.php b/bridges/CryptomeBridge.php index e58607a4..90160557 100644 --- a/bridges/CryptomeBridge.php +++ b/bridges/CryptomeBridge.php @@ -16,8 +16,8 @@ class CryptomeBridge extends BridgeAbstract{ )); public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request Cryptome.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request Cryptome.'); $number=$this->getInput('n'); if (!empty($number)) { /* number of documents */ $num = min($number, 20); diff --git a/bridges/DailymotionBridge.php b/bridges/DailymotionBridge.php index 8e639fed..dc823031 100644 --- a/bridges/DailymotionBridge.php +++ b/bridges/DailymotionBridge.php @@ -35,7 +35,7 @@ class DailymotionBridge extends BridgeAbstract{ function getMetadata($id) { $metadata=array(); - $html2 = $this->getSimpleHTMLDOM(self::URI.'video/'.$id); + $html2 = getSimpleHTMLDOM(self::URI.'video/'.$id); if(!$html2){ return $metadata; } @@ -52,8 +52,8 @@ class DailymotionBridge extends BridgeAbstract{ $limit = 5; $count = 0; - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('Could not request Dailymotion.'); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request Dailymotion.'); foreach($html->find('div.media a.preview_link') as $element) { if($count < $limit) { diff --git a/bridges/DanbooruBridge.php b/bridges/DanbooruBridge.php index 9f0a8c6a..728ed561 100644 --- a/bridges/DanbooruBridge.php +++ b/bridges/DanbooruBridge.php @@ -40,8 +40,8 @@ class DanbooruBridge extends BridgeAbstract{ } public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getFullURI()) - or $this->returnServerError('Could not request '.$this->getName()); + $html = getSimpleHTMLDOM($this->getFullURI()) + or returnServerError('Could not request '.$this->getName()); foreach($html->find(static::PATHTODATA) as $element) { $this->items[] = $this->getItemFromElement($element); diff --git a/bridges/DansTonChatBridge.php b/bridges/DansTonChatBridge.php index 30849b4d..e39c68f6 100644 --- a/bridges/DansTonChatBridge.php +++ b/bridges/DansTonChatBridge.php @@ -8,8 +8,8 @@ class DansTonChatBridge extends BridgeAbstract{ public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI.'latest.html') - or $this->returnServerError('Could not request DansTonChat.'); + $html = getSimpleHTMLDOM(self::URI.'latest.html') + or returnServerError('Could not request DansTonChat.'); foreach($html->find('div.item') as $element) { $item = array(); diff --git a/bridges/DauphineLibereBridge.php b/bridges/DauphineLibereBridge.php index be768ae8..d1e280ff 100644 --- a/bridges/DauphineLibereBridge.php +++ b/bridges/DauphineLibereBridge.php @@ -47,7 +47,7 @@ class DauphineLibereBridge extends FeedExpander { } private function ExtractContent($url) { - $html2 = $this->getSimpleHTMLDOMCached($url); + $html2 = getSimpleHTMLDOMCached($url); $text = $html2->find('div.column', 0)->innertext; $text = preg_replace('@]*?>.*?@si', '', $text); return $text; diff --git a/bridges/DeveloppezDotComBridge.php b/bridges/DeveloppezDotComBridge.php index 4804935d..21a76144 100644 --- a/bridges/DeveloppezDotComBridge.php +++ b/bridges/DeveloppezDotComBridge.php @@ -42,7 +42,7 @@ class DeveloppezDotComBridge extends FeedExpander { } private function DeveloppezDotComExtractContent($url) { - $articleHTMLContent = $this->getSimpleHTMLDOMCached($url); + $articleHTMLContent = getSimpleHTMLDOMCached($url); $text = $this->convert_smart_quotes($articleHTMLContent->find('div.content', 0)->innertext); $text = utf8_encode($text); return trim($text); diff --git a/bridges/DilbertBridge.php b/bridges/DilbertBridge.php index ba5a042b..b845899c 100644 --- a/bridges/DilbertBridge.php +++ b/bridges/DilbertBridge.php @@ -8,7 +8,7 @@ class DilbertBridge extends BridgeAbstract { public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) or $this->returnServerError('Could not request Dilbert: '.$this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request Dilbert: '.$this->getURI()); foreach ($html->find('section.comic-item') as $element) { diff --git a/bridges/DuckDuckGoBridge.php b/bridges/DuckDuckGoBridge.php index 25ec859f..57feef00 100644 --- a/bridges/DuckDuckGoBridge.php +++ b/bridges/DuckDuckGoBridge.php @@ -13,8 +13,8 @@ class DuckDuckGoBridge extends BridgeAbstract{ )); public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI.'html/?q='.$this->getInput('u').'+sort:date') - or $this->returnServerError('Could not request DuckDuckGo.'); + $html = getSimpleHTMLDOM(self::URI.'html/?q='.$this->getInput('u').'+sort:date') + or returnServerError('Could not request DuckDuckGo.'); foreach($html->find('div.results_links') as $element) { $item = array(); diff --git a/bridges/EZTVBridge.php b/bridges/EZTVBridge.php index d2399e02..42793598 100644 --- a/bridges/EZTVBridge.php +++ b/bridges/EZTVBridge.php @@ -34,8 +34,8 @@ class EZTVBridge extends BridgeAbstract{ foreach($showList as $showID){ // Get show page - $html = $this->getSimpleHTMLDOM(self::URI.'shows/'.rawurlencode($showID).'/') - or $this->returnServerError('Could not request EZTV for id "'.$showID.'"'); + $html = getSimpleHTMLDOM(self::URI.'shows/'.rawurlencode($showID).'/') + or returnServerError('Could not request EZTV for id "'.$showID.'"'); // Loop on each element that look like an episode entry... foreach($html->find('.forum_header_border') as $element) { diff --git a/bridges/EliteDangerousGalnetBridge.php b/bridges/EliteDangerousGalnetBridge.php index 09d3770c..f6b4112c 100644 --- a/bridges/EliteDangerousGalnetBridge.php +++ b/bridges/EliteDangerousGalnetBridge.php @@ -8,8 +8,8 @@ class EliteDangerousGalnetBridge extends BridgeAbstract public function collectData() { - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Error while downloading the website content'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Error while downloading the website content'); foreach($html->find('div.article') as $element) { $item = array(); diff --git a/bridges/ElsevierBridge.php b/bridges/ElsevierBridge.php index 8905a9e9..fb6b17ad 100644 --- a/bridges/ElsevierBridge.php +++ b/bridges/ElsevierBridge.php @@ -57,7 +57,7 @@ class ElsevierBridge extends BridgeAbstract{ public function collectData(){ $uri = self::URI . $this->getInput('j') . '/recent-articles/'; - $html = $this->getSimpleHTMLDOM($uri) or $this->returnServerError('No results for Elsevier journal '.$this->getInput('j')); + $html = getSimpleHTMLDOM($uri) or returnServerError('No results for Elsevier journal '.$this->getInput('j')); foreach($html->find('.pod-listing') as $article){ $item = array(); diff --git a/bridges/EstCeQuonMetEnProdBridge.php b/bridges/EstCeQuonMetEnProdBridge.php index b4f94b82..78b92e7e 100644 --- a/bridges/EstCeQuonMetEnProdBridge.php +++ b/bridges/EstCeQuonMetEnProdBridge.php @@ -15,7 +15,7 @@ class EstCeQuonMetEnProdBridge extends BridgeAbstract { } return false; } - $html = $this->getSimpleHTMLDOM($this->getURI()) or $this->returnServerError('Could not request EstCeQuonMetEnProd: '.$this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request EstCeQuonMetEnProd: '.$this->getURI()); $item = array(); $item['uri'] = $this->getURI().'#'.date('Y-m-d'); diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index 90b73609..ede9e575 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -92,8 +92,8 @@ class FacebookBridge extends BridgeAbstract{ ), ); $context = stream_context_create($http_options); - $html = $this->getContents($captcha_action, false, $context); - if ($html === FALSE) { $this->returnServerError('Failed to submit captcha response back to Facebook'); } + $html = getContents($captcha_action, false, $context); + if ($html === FALSE) { returnServerError('Failed to submit captcha response back to Facebook'); } unset($_SESSION['captcha_fields']); $html = str_get_html($html); } @@ -104,11 +104,11 @@ class FacebookBridge extends BridgeAbstract{ //Retrieve page contents if (is_null($html)) { if (!strpos($this->getInput('u'), "/")) { - $html = $this->getSimpleHTMLDOM(self::URI.urlencode($this->getInput('u')).'?_fb_noscript=1') - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM(self::URI.urlencode($this->getInput('u')).'?_fb_noscript=1') + or returnServerError('No results for this query.'); } else { - $html = $this->getSimpleHTMLDOM(self::URI.'pages/'.$this->getInput('u').'?_fb_noscript=1') - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM(self::URI.'pages/'.$this->getInput('u').'?_fb_noscript=1') + or returnServerError('No results for this query.'); } } @@ -126,7 +126,7 @@ class FacebookBridge extends BridgeAbstract{ $_SESSION['captcha_action'] = self::URI.$captcha->find('form', 0)->action; //Show captcha filling form to the viewer, proxying the captcha image - $img = base64_encode($this->getContents($captcha->find('img', 0)->src)); + $img = base64_encode(getContents($captcha->find('img', 0)->src)); header('HTTP/1.1 500 '.Http::getMessageForCode(500)); header('Content-Type: text/html'); die('
' diff --git a/bridges/FeedExpanderExampleBridge.php b/bridges/FeedExpanderExampleBridge.php index c9badd68..e9d955d6 100644 --- a/bridges/FeedExpanderExampleBridge.php +++ b/bridges/FeedExpanderExampleBridge.php @@ -38,7 +38,7 @@ class FeedExpanderExampleBridge extends FeedExpander { case 'atom_1_0': parent::collectExpandableDatas('http://segfault.linuxmint.com/feed/atom/'); break; - default: $this->returnClientError('Unknown version ' . $this->getInput('version') . '!'); + default: returnClientError('Unknown version ' . $this->getInput('version') . '!'); } } @@ -56,7 +56,7 @@ class FeedExpanderExampleBridge extends FeedExpander { case 'atom_1_0': return $this->parseATOMItem($newsItem); break; - default: $this->returnClientError('Unknown version ' . $this->getInput('version') . '!'); + default: returnClientError('Unknown version ' . $this->getInput('version') . '!'); } } } diff --git a/bridges/FierPandaBridge.php b/bridges/FierPandaBridge.php index b2e9d9cc..d36fdcd3 100644 --- a/bridges/FierPandaBridge.php +++ b/bridges/FierPandaBridge.php @@ -7,7 +7,7 @@ class FierPandaBridge extends BridgeAbstract { const DESCRIPTION = "Returns latest articles from Fier Panda."; public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) or $this->returnServerError('Could not request Fier Panda.'); + $html = getSimpleHTMLDOM(self::URI) or returnServerError('Could not request Fier Panda.'); foreach($html->find('div.container-content article') as $element) { $item = array(); diff --git a/bridges/FlickrExploreBridge.php b/bridges/FlickrExploreBridge.php index f35333f8..91fcfb22 100644 --- a/bridges/FlickrExploreBridge.php +++ b/bridges/FlickrExploreBridge.php @@ -7,8 +7,8 @@ class FlickrExploreBridge extends BridgeAbstract{ const DESCRIPTION = "Returns the latest interesting images from Flickr"; public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI.'explore') - or $this->returnServerError('Could not request Flickr.'); + $html = getSimpleHTMLDOM(self::URI.'explore') + or returnServerError('Could not request Flickr.'); foreach($html->find('.photo-list-photo-view') as $element) { // Get the styles @@ -22,14 +22,14 @@ class FlickrExploreBridge extends BridgeAbstract{ $imageID = reset($imageURIs); // Get the image JSON via Flickr API - $imageJSON = json_decode($this->getContents( + $imageJSON = json_decode(getContents( 'https://api.flickr.com/services/rest/?' .'method=flickr.photos.getInfo&' .'api_key=103b574d49bd51f0e18bfe907da44a0f&' .'photo_id='.$imageID.'&' .'format=json&' .'nojsoncallback=1' - )) or $this->returnServerError('Could not request Flickr.'); // FIXME: Request time too long... + )) or returnServerError('Could not request Flickr.'); // FIXME: Request time too long... $item = array(); $item['uri'] = self::URI.'photo.gne?id='.$imageID; diff --git a/bridges/FlickrTagBridge.php b/bridges/FlickrTagBridge.php index 8b3f1b26..b96e8400 100644 --- a/bridges/FlickrTagBridge.php +++ b/bridges/FlickrTagBridge.php @@ -25,12 +25,12 @@ class FlickrTagBridge extends BridgeAbstract{ public function collectData(){ switch($this->queriedContext){ case 'By keyword': - $html = $this->getSimpleHTMLDOM(self::URI.'search/?q='.urlencode($this->getInput('q')).'&s=rec') - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM(self::URI.'search/?q='.urlencode($this->getInput('q')).'&s=rec') + or returnServerError('No results for this query.'); break; case 'by username': - $html = $this->getSimpleHTMLDOM(self::URI.'photos/'.urlencode($this->getInput('u')).'/') - or $this->returnServerError('Requested username can\'t be found.'); + $html = getSimpleHTMLDOM(self::URI.'photos/'.urlencode($this->getInput('u')).'/') + or returnServerError('Requested username can\'t be found.'); break; } diff --git a/bridges/FootitoBridge.php b/bridges/FootitoBridge.php index b669ac58..8b7a12a6 100644 --- a/bridges/FootitoBridge.php +++ b/bridges/FootitoBridge.php @@ -7,8 +7,8 @@ class FootitoBridge extends BridgeAbstract{ const DESCRIPTION = "Footito"; public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request Footito.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request Footito.'); foreach($html->find('div.post') as $element) { $item = array(); diff --git a/bridges/FourchanBridge.php b/bridges/FourchanBridge.php index 3b6d1057..84d43f01 100644 --- a/bridges/FourchanBridge.php +++ b/bridges/FourchanBridge.php @@ -25,8 +25,8 @@ class FourchanBridge extends BridgeAbstract{ public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError("Could not request 4chan, thread not found"); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError("Could not request 4chan, thread not found"); foreach($html->find('div.postContainer') as $element) { $item = array(); diff --git a/bridges/FuturaSciencesBridge.php b/bridges/FuturaSciencesBridge.php index b0f09f08..d8884bc8 100644 --- a/bridges/FuturaSciencesBridge.php +++ b/bridges/FuturaSciencesBridge.php @@ -86,8 +86,8 @@ class FuturaSciencesBridge extends FeedExpander { protected function parseItem($newsItem){ $item = parent::parseItem($newsItem); $item['uri'] = str_replace('#xtor=RSS-8', '', $item['uri']); - $article = $this->getSimpleHTMLDOMCached($item['uri']) - or $this->returnServerError('Could not request Futura-Sciences: ' . $item['uri']); + $article = getSimpleHTMLDOMCached($item['uri']) + or returnServerError('Could not request Futura-Sciences: ' . $item['uri']); $item['content'] = $this->ExtractArticleContent($article); $item['author'] = empty($this->ExtractAuthor($article)) ? $item['author'] : $this->ExtractAuthor($article); return $item; diff --git a/bridges/GBAtempBridge.php b/bridges/GBAtempBridge.php index 0950dc30..dd8cb1c3 100644 --- a/bridges/GBAtempBridge.php +++ b/bridges/GBAtempBridge.php @@ -54,7 +54,7 @@ class GBAtempBridge extends BridgeAbstract { } private function fetch_post_content($uri, $site_url) { - $html = $this->getSimpleHTMLDOM($uri); + $html = getSimpleHTMLDOM($uri); if(!$html){ return 'Could not request GBAtemp '.$uri; } @@ -65,8 +65,8 @@ class GBAtempBridge extends BridgeAbstract { public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request GBAtemp.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request GBAtemp.'); switch($this->getInput('type')){ case 'N': @@ -82,7 +82,7 @@ class GBAtempBridge extends BridgeAbstract { foreach ($html->find('li.portal_review') as $reviewItem) { $url = self::URI.$reviewItem->find('a', 0)->href; $title = $reviewItem->find('span.review_title', 0)->plaintext; - $content = $this->getSimpleHTMLDOM($url) or $this->returnServerError('Could not request GBAtemp: '.$uri); + $content = getSimpleHTMLDOM($url) or returnServerError('Could not request GBAtemp: '.$uri); $author = $content->find('a.username', 0)->plaintext; $time = intval($this->ExtractFromDelimiters($content->find('abbr.DateTime', 0)->outertext, 'data-time="', '"')); $intro = '

'.($content->find('div#review_intro', 0)->plaintext).'

'; diff --git a/bridges/GiphyBridge.php b/bridges/GiphyBridge.php index dcdff8bf..45c668bc 100644 --- a/bridges/GiphyBridge.php +++ b/bridges/GiphyBridge.php @@ -22,8 +22,8 @@ class GiphyBridge extends BridgeAbstract{ public function collectData(){ $html = ''; $base_url = 'http://giphy.com'; - $html = $this->getSimpleHTMLDOM(self::URI.'/search/'.urlencode($this->getInput('s').'/')) - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM(self::URI.'/search/'.urlencode($this->getInput('s').'/')) + or returnServerError('No results for this query.'); $max = GIPHY_LIMIT; if ($this->getInput('n')) { @@ -37,8 +37,8 @@ class GiphyBridge extends BridgeAbstract{ $node = $entry->first_child(); $href = $node->getAttribute('href'); - $html2 = $this->getSimpleHTMLDOM(self::URI . $href) - or $this->returnServerError('No results for this query.'); + $html2 = getSimpleHTMLDOM(self::URI . $href) + or returnServerError('No results for this query.'); $figure = $html2->getElementByTagName('figure'); $img = $figure->firstChild(); $caption = $figure->lastChild(); diff --git a/bridges/GithubIssueBridge.php b/bridges/GithubIssueBridge.php index a8a71718..c346ce25 100644 --- a/bridges/GithubIssueBridge.php +++ b/bridges/GithubIssueBridge.php @@ -135,8 +135,8 @@ class GithubIssueBridge extends BridgeAbstract{ } public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('No results for Github Issue '.$this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('No results for Github Issue '.$this->getURI()); switch($this->queriedContext){ case 'Issue comments': @@ -152,7 +152,7 @@ class GithubIssueBridge extends BridgeAbstract{ if($this->getInput('c')){ $uri=static::URI.$this->getInput('u').'/'.$this->getInput('p').'/issues/'.$issueNbr; - $issue=$this->getSimpleHTMLDOMCached($uri,1800); + $issue=getSimpleHTMLDOMCached($uri,1800); if($issue){ $this->items=array_merge($this->items,$this->extractIssueComments($issue)); continue; diff --git a/bridges/GizmodoBridge.php b/bridges/GizmodoBridge.php index 0fc80a53..2989d9d2 100644 --- a/bridges/GizmodoBridge.php +++ b/bridges/GizmodoBridge.php @@ -9,7 +9,7 @@ class GizmodoBridge extends FeedExpander { protected function parseItem($item){ $item = parent::parseItem($item); - $articleHTMLContent = $this->getSimpleHTMLDOMCached($item['uri']); + $articleHTMLContent = getSimpleHTMLDOMCached($item['uri']); if(!$articleHTMLContent){ $text = 'Could not load '.$item['uri']; }else{ diff --git a/bridges/GooglePlusPostBridge.php b/bridges/GooglePlusPostBridge.php index b86151d2..d43e9daa 100644 --- a/bridges/GooglePlusPostBridge.php +++ b/bridges/GooglePlusPostBridge.php @@ -19,13 +19,13 @@ class GooglePlusPostBridge extends BridgeAbstract public function collectData() { // get content parsed -// $html = $this->getSimpleHTMLDOM(__DIR__ . '/../posts2.html' - $html = $this->getSimpleHTMLDOM(self::URI . urlencode($this->getInput('username')) . '/posts' +// $html = getSimpleHTMLDOM(__DIR__ . '/../posts2.html' + $html = getSimpleHTMLDOM(self::URI . urlencode($this->getInput('username')) . '/posts' // force language , false, stream_context_create(array('http'=> array( 'header' => 'Accept-Language: fr,fr-be,fr-fr;q=0.8,en;q=0.4,en-us;q=0.2;*' . "\r\n" ))) - ) OR $this->returnServerError('No results for this query.'); + ) OR returnServerError('No results for this query.'); // get title, url, ... there is a lot of intresting stuff in meta $this->_title = $html->find('meta[property]', 0)->getAttribute('content'); diff --git a/bridges/GoogleSearchBridge.php b/bridges/GoogleSearchBridge.php index 9c3724f0..ef42b433 100644 --- a/bridges/GoogleSearchBridge.php +++ b/bridges/GoogleSearchBridge.php @@ -25,10 +25,10 @@ class GoogleSearchBridge extends BridgeAbstract{ public function collectData(){ $html = ''; - $html = $this->getSimpleHTMLDOM(self::URI + $html = getSimpleHTMLDOM(self::URI .'search?q=' . urlencode($this->getInput('q')) .'&num=100&complete=0&tbs=qdr:y,sbd:1') - or $this->returnServerError('No results for this query.'); + or returnServerError('No results for this query.'); $emIsRes = $html->find('div[id=ires]',0); if( !is_null($emIsRes) ){ diff --git a/bridges/HDWallpapersBridge.php b/bridges/HDWallpapersBridge.php index bfa4979d..1f10c5ee 100644 --- a/bridges/HDWallpapersBridge.php +++ b/bridges/HDWallpapersBridge.php @@ -30,7 +30,7 @@ class HDWallpapersBridge extends BridgeAbstract { for ($page = 1; $page <= $lastpage; $page++) { $link = self::URI.'/'.$category.'/page/'.$page; - $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM($link) or returnServerError('No results for this query.'); if ($page === 1) { preg_match('/page\/(\d+)$/', $html->find('.pagination a', -2)->href, $matches); diff --git a/bridges/HentaiHavenBridge.php b/bridges/HentaiHavenBridge.php index 27325606..bb28c454 100644 --- a/bridges/HentaiHavenBridge.php +++ b/bridges/HentaiHavenBridge.php @@ -7,8 +7,8 @@ class HentaiHavenBridge extends BridgeAbstract{ const DESCRIPTION = "Returns releases from Hentai Haven"; public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request Hentai Haven.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request Hentai Haven.'); foreach($html->find('div.zoe-grid') as $element) { $item = array(); $item['uri'] = $element->find('div.brick-content h3 a', 0)->href; diff --git a/bridges/IdenticaBridge.php b/bridges/IdenticaBridge.php index 200634ee..8674c4bb 100644 --- a/bridges/IdenticaBridge.php +++ b/bridges/IdenticaBridge.php @@ -14,8 +14,8 @@ class IdenticaBridge extends BridgeAbstract{ )); public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('Requested username can\'t be found.'); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Requested username can\'t be found.'); foreach($html->find('li.major') as $dent) { $item = array(); diff --git a/bridges/InstagramBridge.php b/bridges/InstagramBridge.php index 47eb8152..e3c4b511 100644 --- a/bridges/InstagramBridge.php +++ b/bridges/InstagramBridge.php @@ -14,8 +14,8 @@ class InstagramBridge extends BridgeAbstract{ )); public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('Could not request Instagram.'); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request Instagram.'); $innertext = null; diff --git a/bridges/IsoHuntBridge.php b/bridges/IsoHuntBridge.php index 4c4b2687..fee18cf8 100644 --- a/bridges/IsoHuntBridge.php +++ b/bridges/IsoHuntBridge.php @@ -208,21 +208,21 @@ class IsoHuntBridge extends BridgeAbstract{ private function get_movie_torrents($html){ $container = $html->find('div#w0', 0); if(!$container) - $this->returnServerError('Unable to find torrent container!'); + returnServerError('Unable to find torrent container!'); $torrents = $container->find('article'); if(!$torrents) - $this->returnServerError('Unable to find torrents!'); + returnServerError('Unable to find torrents!'); foreach($torrents as $torrent){ $anchor = $torrent->find('a', 0); if(!$anchor) - $this->returnServerError('Unable to find anchor!'); + returnServerError('Unable to find anchor!'); $date = $torrent->find('small', 0); if(!$date) - $this->returnServerError('Unable to find date!'); + returnServerError('Unable to find date!'); $item = array(); @@ -243,11 +243,11 @@ class IsoHuntBridge extends BridgeAbstract{ private function get_latest_hot_torrents($html){ $container = $html->find('div#serps', 0); if(!$container) - $this->returnServerError('Unable to find torrent container!'); + returnServerError('Unable to find torrent container!'); $torrents = $container->find('tr'); if(!$torrents) - $this->returnServerError('Unable to find torrents!'); + returnServerError('Unable to find torrents!'); // Remove first element (header row) $torrents = array_slice($torrents, 1); @@ -256,11 +256,11 @@ class IsoHuntBridge extends BridgeAbstract{ $cell = $torrent->find('td', 0); if(!$cell) - $this->returnServerError('Unable to find cell!'); + returnServerError('Unable to find cell!'); $element = $cell->find('a', 0); if(!$element) - $this->returnServerError('Unable to find element!'); + returnServerError('Unable to find element!'); $item = array(); @@ -281,11 +281,11 @@ class IsoHuntBridge extends BridgeAbstract{ private function get_latest_news($html){ $container = $html->find('div#postcontainer', 0); if(!$container) - $this->returnServerError('Unable to find post container!'); + returnServerError('Unable to find post container!'); $posts = $container->find('div.index-post'); if(!$posts) - $this->returnServerError('Unable to find posts!'); + returnServerError('Unable to find posts!'); foreach($posts as $post){ $item = array(); @@ -303,7 +303,7 @@ class IsoHuntBridge extends BridgeAbstract{ private function latest_news_extract_author($post){ $author = $post->find('small', 0); if(!$author) - $this->returnServerError('Unable to find author!'); + returnServerError('Unable to find author!'); // The author is hidden within a string like: 'Posted by {author} on {date}' preg_match('/Posted\sby\s(.*)\son/i', $author->innertext, $matches); @@ -314,7 +314,7 @@ class IsoHuntBridge extends BridgeAbstract{ private function latest_news_extract_timestamp($post){ $date = $post->find('small', 0); if(!$date) - $this->returnServerError('Unable to find date!'); + returnServerError('Unable to find date!'); // The date is hidden within a string like: 'Posted by {author} on {date}' preg_match('/Posted\sby\s.*\son\s(.*)/i', $date->innertext, $matches); @@ -332,7 +332,7 @@ class IsoHuntBridge extends BridgeAbstract{ private function latest_news_extract_title($post){ $title = $post->find('a', 0); if(!$title) - $this->returnServerError('Unable to find title!'); + returnServerError('Unable to find title!'); return $title->plaintext; } @@ -340,7 +340,7 @@ class IsoHuntBridge extends BridgeAbstract{ private function latest_news_extract_uri($post){ $uri = $post->find('a', 0); if(!$uri) - $this->returnServerError('Unable to find uri!'); + returnServerError('Unable to find uri!'); return $uri->href; } @@ -348,7 +348,7 @@ class IsoHuntBridge extends BridgeAbstract{ private function latest_news_extract_content($post){ $content = $post->find('div', 0); if(!$content) - $this->returnServerError('Unable to find content!'); + returnServerError('Unable to find content!'); // Remove

...

(title) foreach($content->find('h2') as $element){ @@ -370,11 +370,11 @@ class IsoHuntBridge extends BridgeAbstract{ private function get_latest_torrents($html){ $container = $html->find('div#serps', 0); if(!$container) - $this->returnServerError('Unable to find torrent container!'); + returnServerError('Unable to find torrent container!'); $torrents = $container->find('tr[data-key]'); if(!$torrents) - $this->returnServerError('Unable to find torrents!'); + returnServerError('Unable to find torrents!'); foreach($torrents as $torrent){ $item = array(); @@ -392,11 +392,11 @@ class IsoHuntBridge extends BridgeAbstract{ private function latest_torrents_extract_title($torrent){ $cell = $torrent->find('td.title-row', 0); if(!$cell) - $this->returnServerError('Unable to find title cell!'); + returnServerError('Unable to find title cell!'); $title = $cell->find('span', 0); if(!$title) - $this->returnServerError('Unable to find title!'); + returnServerError('Unable to find title!'); return $title->plaintext; } @@ -404,11 +404,11 @@ class IsoHuntBridge extends BridgeAbstract{ private function latest_torrents_extract_uri($torrent){ $cell = $torrent->find('td.title-row', 0); if(!$cell) - $this->returnServerError('Unable to find title cell!'); + returnServerError('Unable to find title cell!'); $uri = $cell->find('a', 0); if(!$uri) - $this->returnServerError('Unable to find uri!'); + returnServerError('Unable to find uri!'); return $this->fix_relative_uri($uri->href); } @@ -420,7 +420,7 @@ class IsoHuntBridge extends BridgeAbstract{ $user = $cell->find('a', 0); if(!$user) - $this->returnServerError('Unable to find user!'); + returnServerError('Unable to find user!'); return $user->plaintext; } @@ -428,7 +428,7 @@ class IsoHuntBridge extends BridgeAbstract{ private function latest_torrents_extract_timestamp($torrent){ $cell = $torrent->find('td.date-row', 0); if(!$cell) - $this->returnServerError('Unable to find date cell!'); + returnServerError('Unable to find date cell!'); return strtotime('-' . $cell->plaintext, time()); } @@ -438,9 +438,9 @@ class IsoHuntBridge extends BridgeAbstract{ #region Generic helper functions private function load_html($uri){ - $html = $this->getSimpleHTMLDOM($uri); + $html = getSimpleHTMLDOM($uri); if(!$html) - $this->returnServerError('Unable to load ' . $uri . '!'); + returnServerError('Unable to load ' . $uri . '!'); return $html; } diff --git a/bridges/JapanExpoBridge.php b/bridges/JapanExpoBridge.php index dcd951ad..41cd8360 100644 --- a/bridges/JapanExpoBridge.php +++ b/bridges/JapanExpoBridge.php @@ -42,8 +42,8 @@ class JapanExpoBridge extends BridgeAbstract { } }; - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request JapanExpo: '.self::URI); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request JapanExpo: '.self::URI); $fullcontent = $this->getInput('mode'); $count = 0; @@ -60,7 +60,7 @@ class JapanExpoBridge extends BridgeAbstract { break; } - $article_html = $this->getSimpleHTMLDOMCached('Could not request JapanExpo: '.$url); + $article_html = getSimpleHTMLDOMCached('Could not request JapanExpo: '.$url); $header = $article_html->find('header.pageHeadBox', 0); $timestamp = strtotime($header->find('time', 0)->datetime); $title_html = $header->find('div.section', 0)->next_sibling(); diff --git a/bridges/KoreusBridge.php b/bridges/KoreusBridge.php index de3893d8..25d8dbf9 100644 --- a/bridges/KoreusBridge.php +++ b/bridges/KoreusBridge.php @@ -9,7 +9,7 @@ class KoreusBridge extends FeedExpander { protected function parseItem($item) { $item = parent::parseItem($item); - $html = $this->getSimpleHTMLDOMCached($item['uri']); + $html = getSimpleHTMLDOMCached($item['uri']); $text = $html->find('p.itemText', 0)->innertext; $item['content'] = utf8_encode($text); diff --git a/bridges/KununuBridge.php b/bridges/KununuBridge.php index a958b77b..76cde70e 100644 --- a/bridges/KununuBridge.php +++ b/bridges/KununuBridge.php @@ -67,21 +67,21 @@ class KununuBridge extends BridgeAbstract { $full = $this->getInput('full'); // Load page - $html = $this->getSimpleHTMLDOM($this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()); if(!$html) - $this->returnServerError('Unable to receive data from ' . $this->getURI() . '!'); + returnServerError('Unable to receive data from ' . $this->getURI() . '!'); // Update name for this request $this->companyName = $this->extract_company_name($html); // Find the section with all the panels (reviews) $section = $html->find('section.kununu-scroll-element', 0); if($section === false) - $this->returnServerError('Unable to find panel section!'); + returnServerError('Unable to find panel section!'); // Find all articles (within the panels) $articles = $section->find('article'); if($articles === false || empty($articles)) - $this->returnServerError('Unable to find articles!'); + returnServerError('Unable to find articles!'); // Go through all articles foreach($articles as $article){ @@ -128,11 +128,11 @@ class KununuBridge extends BridgeAbstract { private function extract_company_name($html){ $panel = $html->find('div.panel', 0); if($panel === false) - $this->returnServerError('Cannot find panel for company name!'); + returnServerError('Cannot find panel for company name!'); $company_name = $panel->find('h1', 0); if($company_name === false) - $this->returnServerError('Cannot find company name!'); + returnServerError('Cannot find company name!'); return $company_name->plaintext; } @@ -144,7 +144,7 @@ class KununuBridge extends BridgeAbstract { // They conviniently provide a time attribute for us :) $date = $article->find('time[itemprop=dtreviewed]', 0); if($date === false) - $this->returnServerError('Cannot find article date!'); + returnServerError('Cannot find article date!'); return strtotime($date->datetime); } @@ -155,7 +155,7 @@ class KununuBridge extends BridgeAbstract { private function extract_article_rating($article){ $rating = $article->find('span.rating', 0); if($rating === false) - $this->returnServerError('Cannot find article rating!'); + returnServerError('Cannot find article rating!'); return $rating->getAttribute('aria-label'); } @@ -166,7 +166,7 @@ class KununuBridge extends BridgeAbstract { private function extract_article_summary($article){ $summary = $article->find('[itemprop=summary]', 0); if($summary === false) - $this->returnServerError('Cannot find article summary!'); + returnServerError('Cannot find article summary!'); return strip_tags($summary->innertext); } @@ -178,11 +178,11 @@ class KununuBridge extends BridgeAbstract { // Notice: This first part is the same as in extract_article_summary! $summary = $article->find('[itemprop=summary]', 0); if($summary === false) - $this->returnServerError('Cannot find article summary!'); + returnServerError('Cannot find article summary!'); $anchor = $summary->find('a', 0); if($anchor === false) - $this->returnServerError('Cannot find article URI!'); + returnServerError('Cannot find article URI!'); return self::URI . $anchor->href; } @@ -194,7 +194,7 @@ class KununuBridge extends BridgeAbstract { // We need to parse the aside manually $aside = $article->find('aside', 0); if($aside === false) - $this->returnServerError('Cannot find article author information!'); + returnServerError('Cannot find article author information!'); // Go through all h2 elements to find index of required span (I know... it's stupid) $author_position = 'Unknown'; @@ -214,7 +214,7 @@ class KununuBridge extends BridgeAbstract { private function extract_article_description($article){ $description = $article->find('div[itemprop=description]', 0); if($description === false) - $this->returnServerError('Cannot find article description!'); + returnServerError('Cannot find article description!'); return $this->fix_url($description->innertext); } @@ -224,14 +224,14 @@ class KununuBridge extends BridgeAbstract { */ private function extract_full_description($uri){ // Load full article - $html = $this->getSimpleHTMLDOMCached($uri); + $html = getSimpleHTMLDOMCached($uri); if($html === false) - $this->returnServerError('Could not load full description!'); + returnServerError('Could not load full description!'); // Find the article $article = $html->find('article', 0); if($article === false) - $this->returnServerError('Cannot find article!'); + returnServerError('Cannot find article!'); // Luckily they use the same layout for the review overview and full article pages :) return $this->extract_article_description($article); diff --git a/bridges/LWNprevBridge.php b/bridges/LWNprevBridge.php index 704c1d5c..0d53717f 100644 --- a/bridges/LWNprevBridge.php +++ b/bridges/LWNprevBridge.php @@ -32,8 +32,8 @@ class LWNprevBridge extends BridgeAbstract{ public function collectData(){ // Because the LWN page is written in loose HTML and not XHTML, // Simple HTML Dom is not accurate enough for the job - $content=$this->getContents($this->getURI()) - or $this->returnServerError('No results for LWNprev'); + $content=getContents($this->getURI()) + or returnServerError('No results for LWNprev'); libxml_use_internal_errors(true); $html=new DOMDocument(); diff --git a/bridges/LeBonCoinBridge.php b/bridges/LeBonCoinBridge.php index 2c243086..54c0f5ec 100755 --- a/bridges/LeBonCoinBridge.php +++ b/bridges/LeBonCoinBridge.php @@ -143,11 +143,11 @@ class LeBonCoinBridge extends BridgeAbstract{ $category='annonces'; } - $html = $this->getSimpleHTMLDOM( + $html = getSimpleHTMLDOM( self::URI.$category.'/offres/' . $this->getInput('r') . '/?' .'f=a&th=1&' .'q=' . urlencode($this->getInput('k')) - ) or $this->returnServerError('Could not request LeBonCoin.'); + ) or returnServerError('Could not request LeBonCoin.'); $list = $html->find('.tabsContent', 0); if($list === NULL) { diff --git a/bridges/LeMondeInformatiqueBridge.php b/bridges/LeMondeInformatiqueBridge.php index 889710f1..9b897d68 100644 --- a/bridges/LeMondeInformatiqueBridge.php +++ b/bridges/LeMondeInformatiqueBridge.php @@ -12,8 +12,8 @@ class LeMondeInformatiqueBridge extends FeedExpander { protected function parseItem($newsItem){ $item = parent::parseItem($newsItem); - $article_html = $this->getSimpleHTMLDOMCached($item['uri']) - or $this->returnServerError('Could not request LeMondeInformatique: ' . $item['uri']); + $article_html = getSimpleHTMLDOMCached($item['uri']) + or returnServerError('Could not request LeMondeInformatique: ' . $item['uri']); $item['content'] = $this->CleanArticle($article_html->find('div#article', 0)->innertext); $item['title'] = $article_html->find('h1.cleanprint-title', 0)->plaintext; return $item; diff --git a/bridges/LegifranceJOBridge.php b/bridges/LegifranceJOBridge.php index b35c7e61..6cc8086b 100644 --- a/bridges/LegifranceJOBridge.php +++ b/bridges/LegifranceJOBridge.php @@ -39,7 +39,7 @@ class LegifranceJOBridge extends BridgeAbstract{ } public function collectData(){ - $html=$this->getSimpleHTMLDOM(self::URI) + $html=getSimpleHTMLDOM(self::URI) or $this->returnServer('Unable to download '.self::URI); $this->author=trim($html->find('h2.title',0)->plaintext); diff --git a/bridges/LesJoiesDuCodeBridge.php b/bridges/LesJoiesDuCodeBridge.php index 81023b15..419403e1 100644 --- a/bridges/LesJoiesDuCodeBridge.php +++ b/bridges/LesJoiesDuCodeBridge.php @@ -7,8 +7,8 @@ class LesJoiesDuCodeBridge extends BridgeAbstract{ const DESCRIPTION = "LesJoiesDuCode"; public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request LesJoiesDuCode.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request LesJoiesDuCode.'); foreach($html->find('div.blog-post') as $element) { $item = array(); diff --git a/bridges/LichessBridge.php b/bridges/LichessBridge.php index b1498d2f..e0657b86 100644 --- a/bridges/LichessBridge.php +++ b/bridges/LichessBridge.php @@ -17,7 +17,7 @@ class LichessBridge extends FeedExpander { } private function retrieve_lichess_post($blog_post_uri){ - $blog_post_html = $this->getSimpleHTMLDOMCached($blog_post_uri); + $blog_post_html = getSimpleHTMLDOMCached($blog_post_uri); $blog_post_div = $blog_post_html->find('#lichess_blog', 0); $post_chapo = $blog_post_div->find('.shortlede', 0)->innertext; diff --git a/bridges/LinkedInCompanyBridge.php b/bridges/LinkedInCompanyBridge.php index 6ccbba55..34fb5c1f 100644 --- a/bridges/LinkedInCompanyBridge.php +++ b/bridges/LinkedInCompanyBridge.php @@ -17,8 +17,8 @@ class LinkedInCompanyBridge extends BridgeAbstract{ $html = ''; $link = self::URI.'company/'.$this->getInput('c'); - $html = $this->getSimpleHTMLDOM($link) - or $this->returnServerError('Could not request LinkedIn.'); + $html = getSimpleHTMLDOM($link) + or returnServerError('Could not request LinkedIn.'); foreach($html->find('//*[@id="my-feed-post"]/li') as $element) { $title = $element->find('span.share-body', 0)->innertext; diff --git a/bridges/MangareaderBridge.php b/bridges/MangareaderBridge.php index 60b15f00..905860a9 100644 --- a/bridges/MangareaderBridge.php +++ b/bridges/MangareaderBridge.php @@ -78,9 +78,9 @@ class MangareaderBridge extends BridgeAbstract { public function collectData(){ // We'll use the DOM parser for this as it makes navigation easier - $html = $this->getContents($this->getURI()); + $html = getContents($this->getURI()); if(!$html){ - $this->returnClientError('Could not receive data for ' . $path . '!'); + returnClientError('Could not receive data for ' . $path . '!'); } libxml_use_internal_errors(true); $doc = new DomDocument; diff --git a/bridges/MoebooruBridge.php b/bridges/MoebooruBridge.php index af76de43..54fde19f 100644 --- a/bridges/MoebooruBridge.php +++ b/bridges/MoebooruBridge.php @@ -21,8 +21,8 @@ class MoebooruBridge extends BridgeAbstract{ } public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getFullURI()) - or $this->returnServerError('Could not request '.$this->getName()); + $html = getSimpleHTMLDOM($this->getFullURI()) + or returnServerError('Could not request '.$this->getName()); $input_json = explode('Post.register(', $html); diff --git a/bridges/MondeDiploBridge.php b/bridges/MondeDiploBridge.php index c9d20af6..82ae270b 100644 --- a/bridges/MondeDiploBridge.php +++ b/bridges/MondeDiploBridge.php @@ -7,8 +7,8 @@ class MondeDiploBridge extends BridgeAbstract{ const DESCRIPTION = "Returns most recent results from MondeDiplo."; public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request MondeDiplo. for : ' . self::URI); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request MondeDiplo. for : ' . self::URI); foreach($html->find('div.unarticle') as $article) { $element = $article->parent(); diff --git a/bridges/MsnMondeBridge.php b/bridges/MsnMondeBridge.php index f7b4c779..348bdb91 100644 --- a/bridges/MsnMondeBridge.php +++ b/bridges/MsnMondeBridge.php @@ -11,13 +11,13 @@ class MsnMondeBridge extends BridgeAbstract{ } private function MsnMondeExtractContent($url, &$item) { - $html2 = $this->getSimpleHTMLDOM($url); + $html2 = getSimpleHTMLDOM($url); $item['content'] = $html2->find('#content', 0)->find('article', 0)->find('section', 0)->plaintext; $item['timestamp'] = strtotime($html2->find('.authorinfo-txt', 0)->find('time', 0)->datetime); } public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) or $this->returnServerError('Could not request MsnMonde.'); + $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request MsnMonde.'); $limit = 0; foreach($html->find('.smalla') as $article) { if($limit < 10) { diff --git a/bridges/NasaApodBridge.php b/bridges/NasaApodBridge.php index 93da332c..ca590aac 100644 --- a/bridges/NasaApodBridge.php +++ b/bridges/NasaApodBridge.php @@ -8,7 +8,7 @@ class NasaApodBridge extends BridgeAbstract{ public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI.'archivepix.html') or $this->returnServerError('Error while downloading the website content'); + $html = getSimpleHTMLDOM(self::URI.'archivepix.html') or returnServerError('Error while downloading the website content'); $list = explode("
", $html->find('b', 0)->innertext); for($i = 0; $i < 3;$i++) @@ -20,7 +20,7 @@ class NasaApodBridge extends BridgeAbstract{ $uri = self::URI.$uri_page; $item['uri'] = $uri; - $picture_html = $this->getSimpleHTMLDOM($uri); + $picture_html = getSimpleHTMLDOM($uri); $picture_html_string = $picture_html->innertext; //Extract image and explanation diff --git a/bridges/NeuviemeArtBridge.php b/bridges/NeuviemeArtBridge.php index 16a4a2f3..0bf3ce38 100644 --- a/bridges/NeuviemeArtBridge.php +++ b/bridges/NeuviemeArtBridge.php @@ -17,7 +17,7 @@ class NeuviemeArtBridge extends FeedExpander { protected function parseItem($item){ $item = parent::parseItem($item); - $article_html = $this->getSimpleHTMLDOMCached($item['uri']); + $article_html = getSimpleHTMLDOMCached($item['uri']); if(!$article_html){ $item['content'] = 'Could not request 9eme Art: '.$item['uri']; return $item; diff --git a/bridges/NextInpactBridge.php b/bridges/NextInpactBridge.php index 9196cdde..21baf4c5 100644 --- a/bridges/NextInpactBridge.php +++ b/bridges/NextInpactBridge.php @@ -17,7 +17,7 @@ class NextInpactBridge extends FeedExpander { } private function ExtractContent($url) { - $html2 = $this->getSimpleHTMLDOMCached($url); + $html2 = getSimpleHTMLDOMCached($url); $text = '

'.$html2->find('span.sub_title', 0)->innertext.'

' .'

-

' .'
'.$html2->find('div[itemprop=articleBody]', 0)->innertext.'
'; diff --git a/bridges/NextgovBridge.php b/bridges/NextgovBridge.php index 14f1d53e..78ffb055 100644 --- a/bridges/NextgovBridge.php +++ b/bridges/NextgovBridge.php @@ -56,8 +56,8 @@ class NextgovBridge extends FeedExpander { } private function ExtractContent($url){ - $article = $this->getSimpleHTMLDOMCached($url) - or $this->returnServerError('Could not request Nextgov: ' . $url); + $article = getSimpleHTMLDOMCached($url) + or returnServerError('Could not request Nextgov: ' . $url); $contents = $article->find('div.wysiwyg', 0)->innertext; $contents = $this->StripWithDelimiters($contents, '
', '
'); diff --git a/bridges/NiceMatinBridge.php b/bridges/NiceMatinBridge.php index 5f5f94a2..678b4f77 100644 --- a/bridges/NiceMatinBridge.php +++ b/bridges/NiceMatinBridge.php @@ -17,7 +17,7 @@ class NiceMatinBridge extends FeedExpander { } private function NiceMatinExtractContent($url) { - $html = $this->getSimpleHTMLDOMCached($url); + $html = getSimpleHTMLDOMCached($url); if(!$html) return 'Could not acquire content from url: ' . $url . '!'; diff --git a/bridges/NovelUpdatesBridge.php b/bridges/NovelUpdatesBridge.php index 95dfc7fb..899eac4f 100644 --- a/bridges/NovelUpdatesBridge.php +++ b/bridges/NovelUpdatesBridge.php @@ -20,8 +20,8 @@ class NovelUpdatesBridge extends BridgeAbstract{ } public function collectData(){ - $fullhtml = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('Could not request NovelUpdates, novel "'.$this->getInput('n').'" not found'); + $fullhtml = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request NovelUpdates, novel "'.$this->getInput('n').'" not found'); $this->seriesTitle = $fullhtml->find('h4.seriestitle', 0)->plaintext; // dirty fix for nasty simpledom bug: https://github.com/sebsauvage/rss-bridge/issues/259 diff --git a/bridges/OpenClassroomsBridge.php b/bridges/OpenClassroomsBridge.php index ae4ea10f..4b61639d 100644 --- a/bridges/OpenClassroomsBridge.php +++ b/bridges/OpenClassroomsBridge.php @@ -31,8 +31,8 @@ class OpenClassroomsBridge extends BridgeAbstract{ } public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('Could not request OpenClassrooms.'); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request OpenClassrooms.'); foreach($html->find('.courseListItem') as $element) { $item = array(); diff --git a/bridges/ParuVenduImmoBridge.php b/bridges/ParuVenduImmoBridge.php index e791c7af..79c74f36 100644 --- a/bridges/ParuVenduImmoBridge.php +++ b/bridges/ParuVenduImmoBridge.php @@ -25,8 +25,8 @@ class ParuVenduImmoBridge extends BridgeAbstract public function collectData() { - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('Could not request paruvendu.'); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request paruvendu.'); foreach($html->find('div.annonce a') as $element) { diff --git a/bridges/PickyWallpapersBridge.php b/bridges/PickyWallpapersBridge.php index 14113735..3d098d59 100644 --- a/bridges/PickyWallpapersBridge.php +++ b/bridges/PickyWallpapersBridge.php @@ -33,8 +33,8 @@ class PickyWallpapersBridge extends BridgeAbstract { $resolution = $this->getInput('r'); // Wide wallpaper default for ($page = 1; $page <= $lastpage; $page++) { - $html = $this->getSimpleHTMLDOM($this->getURI().'/page-'.$page.'/') - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM($this->getURI().'/page-'.$page.'/') + or returnServerError('No results for this query.'); if ($page === 1) { preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches); diff --git a/bridges/PinterestBridge.php b/bridges/PinterestBridge.php index 59bbf122..65c3b60d 100644 --- a/bridges/PinterestBridge.php +++ b/bridges/PinterestBridge.php @@ -26,13 +26,13 @@ class PinterestBridge extends BridgeAbstract { ); public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()); if(!$html){ switch($this->queriedContext){ case 'By username and board': - $this->returnServerError('Username and/or board not found'); + returnServerError('Username and/or board not found'); case 'From search': - $this->returnServerError('Could not request Pinterest.'); + returnServerError('Could not request Pinterest.'); } } @@ -72,7 +72,7 @@ class PinterestBridge extends BridgeAbstract { } } elseif($this->queriedContext === 'By username and board'){ $container = $html->find('SCRIPT[type="application/ld+json"]', 0) - or $this->returnServerError('Unable to find data container!'); + or returnServerError('Unable to find data container!'); $json = json_decode($container->innertext, true); diff --git a/bridges/PlanetLibreBridge.php b/bridges/PlanetLibreBridge.php index 1a9a118a..d4d0bc9c 100644 --- a/bridges/PlanetLibreBridge.php +++ b/bridges/PlanetLibreBridge.php @@ -7,14 +7,14 @@ class PlanetLibreBridge extends BridgeAbstract{ const DESCRIPTION = "Returns the 5 newest posts from PlanetLibre (full text)"; private function PlanetLibreExtractContent($url){ - $html2 = $this->getSimpleHTMLDOM($url); + $html2 = getSimpleHTMLDOM($url); $text = $html2->find('div[class="post-text"]', 0)->innertext; return $text; } public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request PlanetLibre.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request PlanetLibre.'); $limit = 0; foreach($html->find('div.post') as $element) { if($limit < 5) { diff --git a/bridges/RTBFBridge.php b/bridges/RTBFBridge.php index 28058840..c7149c53 100644 --- a/bridges/RTBFBridge.php +++ b/bridges/RTBFBridge.php @@ -18,8 +18,8 @@ class RTBFBridge extends BridgeAbstract { $limit = 10; $count = 0; - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('Could not request RTBF.'); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request RTBF.'); foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) { if($count >= $limit) { diff --git a/bridges/Releases3DSBridge.php b/bridges/Releases3DSBridge.php index a69e9ef4..d604f3d3 100644 --- a/bridges/Releases3DSBridge.php +++ b/bridges/Releases3DSBridge.php @@ -33,7 +33,7 @@ class Releases3DSBridge extends BridgeAbstract { } $dataUrl = self::URI.'xml.php'; - $xml = $this->getContents($dataUrl) or $this->returnServerError('Could not request 3dsdb: '.$dataUrl); + $xml = getContents($dataUrl) or returnServerError('Could not request 3dsdb: '.$dataUrl); $limit = 0; foreach (array_reverse(explode('', $xml)) as $element) { @@ -68,7 +68,7 @@ class Releases3DSBridge extends BridgeAbstract { //Retrieve cover art and short desc from IGN? $ignResult = false; $ignDescription = ''; $ignLink = ''; $ignDate = time(); $ignCoverArt = ''; $ignSearchUrl = 'http://www.ign.com/search?q='.urlencode($name); - if ($ignResult = $this->getSimpleHTMLDOM($ignSearchUrl)) { + if ($ignResult = getSimpleHTMLDOM($ignSearchUrl)) { $ignCoverArt = $ignResult->find('div.search-item-media', 0)->find('img', 0)->src; $ignDesc = $ignResult->find('div.search-item-description', 0)->plaintext; $ignLink = $ignResult->find('div.search-item-sub-title', 0)->find('a', 1)->href; diff --git a/bridges/ReporterreBridge.php b/bridges/ReporterreBridge.php index 5061cbeb..be4ceee3 100644 --- a/bridges/ReporterreBridge.php +++ b/bridges/ReporterreBridge.php @@ -7,7 +7,7 @@ class ReporterreBridge extends BridgeAbstract{ const DESCRIPTION = "Returns the newest articles."; private function ExtractContentReporterre($url) { - $html2 = $this->getSimpleHTMLDOM($url); + $html2 = getSimpleHTMLDOM($url); foreach($html2->find('div[style=text-align:justify]') as $e) { $text = $e->outertext; @@ -24,7 +24,7 @@ class ReporterreBridge extends BridgeAbstract{ } public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI.'spip.php?page=backend') or $this->returnServerError('Could not request Reporterre.'); + $html = getSimpleHTMLDOM(self::URI.'spip.php?page=backend') or returnServerError('Could not request Reporterre.'); $limit = 0; foreach($html->find('item') as $element) { diff --git a/bridges/Rue89Bridge.php b/bridges/Rue89Bridge.php index ae08ec2a..400943eb 100644 --- a/bridges/Rue89Bridge.php +++ b/bridges/Rue89Bridge.php @@ -10,7 +10,7 @@ class Rue89Bridge extends FeedExpander { $item = parent::parseItem($item); $url = "http://api.rue89.nouvelobs.com/export/mobile2/node/" . str_replace(" ", "", substr($item['uri'], -8)) . "/full"; - $datas = json_decode($this->getContents($url), true); + $datas = json_decode(getContents($url), true); $item['content'] = $datas['node']['body']; return $item; diff --git a/bridges/ScmbBridge.php b/bridges/ScmbBridge.php index e22b73c8..0a228d13 100644 --- a/bridges/ScmbBridge.php +++ b/bridges/ScmbBridge.php @@ -8,8 +8,8 @@ class ScmbBridge extends BridgeAbstract{ public function collectData(){ $html = ''; - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request Se Coucher Moins Bete.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request Se Coucher Moins Bete.'); foreach($html->find('article') as $article) { $item = array(); diff --git a/bridges/ScoopItBridge.php b/bridges/ScoopItBridge.php index 810edb8c..00fba2bf 100644 --- a/bridges/ScoopItBridge.php +++ b/bridges/ScoopItBridge.php @@ -17,8 +17,8 @@ class ScoopItBridge extends BridgeAbstract{ $this->request = $this->getInput('u'); $link = self::URI.'search?q=' .urlencode($this->getInput('u')); - $html = $this->getSimpleHTMLDOM($link) - or $this->returnServerError('Could not request ScoopIt. for : ' . $link); + $html = getSimpleHTMLDOM($link) + or returnServerError('Could not request ScoopIt. for : ' . $link); foreach($html->find('div.post-view') as $element) { $item = array(); diff --git a/bridges/SensCritiqueBridge.php b/bridges/SensCritiqueBridge.php index 32cd952c..126583f5 100644 --- a/bridges/SensCritiqueBridge.php +++ b/bridges/SensCritiqueBridge.php @@ -46,8 +46,8 @@ class SensCritiqueBridge extends BridgeAbstract { case 'bd': $uri.='bd/actualite'; break; case 'mu': $uri.='musique/actualite'; break; } - $html = $this->getSimpleHTMLDOM($uri) - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM($uri) + or returnServerError('No results for this query.'); $list = $html->find('ul.elpr-list', 0); $this->extractDataFromList($list); @@ -57,7 +57,7 @@ class SensCritiqueBridge extends BridgeAbstract { private function extractDataFromList($list) { if ($list === null) { - $this->returnClientError('Cannot extract data from list'); + returnClientError('Cannot extract data from list'); } foreach ($list->find('li') as $movie) { diff --git a/bridges/SexactuBridge.php b/bridges/SexactuBridge.php index 534cba5d..24205151 100644 --- a/bridges/SexactuBridge.php +++ b/bridges/SexactuBridge.php @@ -10,7 +10,7 @@ class SexactuBridge extends BridgeAbstract{ $find = array('janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'novembre', 'décembre'); $replace = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); - $html = $this->getSimpleHTMLDOM($this->getURI()) or $this->returnServerError('Could not request '.$this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request '.$this->getURI()); foreach($html->find('.content-holder') as $contentHolder) { // only use first list as second one only contains pages numbers diff --git a/bridges/ShanaprojectBridge.php b/bridges/ShanaprojectBridge.php index 875e43c4..7439d785 100644 --- a/bridges/ShanaprojectBridge.php +++ b/bridges/ShanaprojectBridge.php @@ -8,17 +8,17 @@ class ShanaprojectBridge extends BridgeAbstract { // Returns an html object for the Season Anime List (latest season) private function LoadSeasonAnimeList(){ // First we need to find the URI to the latest season from the 'seasons' page searching for 'Season Anime List' - $html = $this->getSimpleHTMLDOM($this->getURI() . '/seasons'); + $html = getSimpleHTMLDOM($this->getURI() . '/seasons'); if(!$html) - $this->returnServerError('Could not load \'seasons\' page!'); + returnServerError('Could not load \'seasons\' page!'); $season = $html->find('div.follows_menu/a', 1); if(!$season) - $this->returnServerError('Could not find \'Season Anime List\'!'); + returnServerError('Could not find \'Season Anime List\'!'); - $html = $this->getSimpleHTMLDOM($this->getURI() . $season->href); + $html = getSimpleHTMLDOM($this->getURI() . $season->href); if(!$html) - $this->returnServerError('Could not load \'Season Anime List\' from \'' . $season->innertext . '\'!'); + returnServerError('Could not load \'Season Anime List\' from \'' . $season->innertext . '\'!'); return $html; } @@ -27,7 +27,7 @@ class ShanaprojectBridge extends BridgeAbstract { private function ExtractAnimeTitle($anime){ $title = $anime->find('a', 0); if(!$title) - $this->returnServerError('Could not find anime title!'); + returnServerError('Could not find anime title!'); return trim($title->innertext); } @@ -35,7 +35,7 @@ class ShanaprojectBridge extends BridgeAbstract { private function ExtractAnimeURI($anime){ $uri = $anime->find('a', 0); if(!$uri) - $this->returnServerError('Could not find anime URI!'); + returnServerError('Could not find anime URI!'); return $this->getURI() . $uri->href; } @@ -43,7 +43,7 @@ class ShanaprojectBridge extends BridgeAbstract { private function ExtractAnimeTimestamp($anime){ $timestamp = $anime->find('span.header_info_block', 1); if(!$timestamp) - $this->returnServerError('Could not find anime timestamp!'); + returnServerError('Could not find anime timestamp!'); return strtotime($timestamp->innertext); } @@ -59,7 +59,7 @@ class ShanaprojectBridge extends BridgeAbstract { private function ExtractAnimeEpisodeInformation($anime){ $episode = $anime->find('div.header_info_episode', 0); if(!$episode) - $this->returnServerError('Could not find anime episode information!'); + returnServerError('Could not find anime episode information!'); return preg_replace('/\r|\n/', ' ', $episode->plaintext); } @@ -71,7 +71,7 @@ class ShanaprojectBridge extends BridgeAbstract { if(preg_match("/url\(\/\/([^\)]+)\)/i", $anime->parent->style, $matches)) return $matches[1]; - $this->returnServerError('Could not extract background image!'); + returnServerError('Could not extract background image!'); } // Builds an URI to search for a specific anime (subber is left empty) @@ -94,7 +94,7 @@ class ShanaprojectBridge extends BridgeAbstract { $animes = $html->find('div.header_display_box_info'); if(!$animes) - $this->returnServerError('Could not find anime headers!'); + returnServerError('Could not find anime headers!'); foreach($animes as $anime){ $item = array(); diff --git a/bridges/SoundcloudBridge.php b/bridges/SoundcloudBridge.php index ec04064d..b3d9002d 100644 --- a/bridges/SoundcloudBridge.php +++ b/bridges/SoundcloudBridge.php @@ -17,16 +17,16 @@ class SoundCloudBridge extends BridgeAbstract{ public function collectData(){ - $res = json_decode($this->getContents( + $res = json_decode(getContents( 'https://api.soundcloud.com/resolve?url=http://www.soundcloud.com/' . urlencode($this->getInput('u')) .'&client_id=' . self::CLIENT_ID - )) or $this->returnServerError('No results for this query'); - $tracks = json_decode($this->getContents( + )) or returnServerError('No results for this query'); + $tracks = json_decode(getContents( 'https://api.soundcloud.com/users/' . urlencode($res->id) .'/tracks?client_id=' . self::CLIENT_ID - )) or $this->returnServerError('No results for this user'); + )) or returnServerError('No results for this user'); for ($i=0; $i < 10; $i++) { $item = array(); diff --git a/bridges/StripeAPIChangeLogBridge.php b/bridges/StripeAPIChangeLogBridge.php index da5934d2..f6bed8c5 100644 --- a/bridges/StripeAPIChangeLogBridge.php +++ b/bridges/StripeAPIChangeLogBridge.php @@ -6,8 +6,8 @@ class StripeAPIChangeLogBridge extends BridgeAbstract{ const DESCRIPTION = 'Returns the changes made to the stripe.com API'; public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('No results for Stripe API Changelog'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('No results for Stripe API Changelog'); foreach($html->find('h3') as $change){ diff --git a/bridges/SuperbWallpapersBridge.php b/bridges/SuperbWallpapersBridge.php index 8bfc7092..dd8dd4c3 100644 --- a/bridges/SuperbWallpapersBridge.php +++ b/bridges/SuperbWallpapersBridge.php @@ -32,15 +32,15 @@ class SuperbWallpapersBridge extends BridgeAbstract { // Get last page number $link = self::URI.'/'.$category.'/9999.html'; - $html = $this->getSimpleHTMLDOM($link) - or $this->returnServerError('Could not load '.$link); + $html = getSimpleHTMLDOM($link) + or returnServerError('Could not load '.$link); $lastpage = min($html->find('.paging .cpage', 0)->innertext(), ceil($max/36)); for ($page = 1; $page <= $lastpage; $page++) { $link = self::URI.'/'.$category.'/'.$page.'.html'; - $html = $this->getSimpleHTMLDOM($link) - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM($link) + or returnServerError('No results for this query.'); foreach($html->find('.wpl .i a') as $element) { $thumbnail = $element->find('img', 0); diff --git a/bridges/T411Bridge.php b/bridges/T411Bridge.php index d3d952f7..0c87f640 100644 --- a/bridges/T411Bridge.php +++ b/bridges/T411Bridge.php @@ -26,12 +26,12 @@ class T411Bridge extends BridgeAbstract { //Retrieve torrent listing from search results, which does not contain torrent description $url = self::URI.'torrents/search/?'.$this->getInput('search').'&order=added&type=desc'; - $html = $this->getSimpleHTMLDOM($url) - or $this->returnServerError('Could not request t411: '.$url); + $html = getSimpleHTMLDOM($url) + or returnServerError('Could not request t411: '.$url); $results = $html->find('table.results', 0); if (is_null($results)) - $this->returnServerError('No results from t411: '.$url); + returnServerError('No results from t411: '.$url); $limit = 0; //Process each item individually @@ -54,7 +54,7 @@ class T411Bridge extends BridgeAbstract { $item_date = strtotime($element->find('dd', 0)->plaintext); //Retrieve full description from torrent page - $item_html = $this->getSimpleHTMLDOM($item_uri); + $item_html = getSimpleHTMLDOM($item_uri); if (!$item_html) { continue; } diff --git a/bridges/TagBoardBridge.php b/bridges/TagBoardBridge.php index cda49251..dbb123b5 100644 --- a/bridges/TagBoardBridge.php +++ b/bridges/TagBoardBridge.php @@ -16,8 +16,8 @@ class TagBoardBridge extends BridgeAbstract{ public function collectData(){ $link = 'https://post-cache.tagboard.com/search/' .$this->getInput('u'); - $html = $this->getSimpleHTMLDOM($link) - or $this->returnServerError('Could not request TagBoard for : ' . $link); + $html = getSimpleHTMLDOM($link) + or returnServerError('Could not request TagBoard for : ' . $link); $parsed_json = json_decode($html); foreach($parsed_json->{'posts'} as $element) { diff --git a/bridges/TheCodingLoveBridge.php b/bridges/TheCodingLoveBridge.php index 2120442c..ab62296c 100644 --- a/bridges/TheCodingLoveBridge.php +++ b/bridges/TheCodingLoveBridge.php @@ -7,8 +7,8 @@ class TheCodingLoveBridge extends BridgeAbstract{ const DESCRIPTION = "The Coding Love"; public function collectData(){ - $html = $this->getSimpleHTMLDOM(self::URI) - or $this->returnServerError('Could not request The Coding Love.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request The Coding Love.'); foreach($html->find('div.post') as $element) { $item = array(); diff --git a/bridges/TheHackerNewsBridge.php b/bridges/TheHackerNewsBridge.php index fe07fd31..58f8f916 100644 --- a/bridges/TheHackerNewsBridge.php +++ b/bridges/TheHackerNewsBridge.php @@ -40,7 +40,7 @@ class TheHackerNewsBridge extends BridgeAbstract { return $string; } - $html = $this->getSimpleHTMLDOM($this->getURI()) or $this->returnServerError('Could not request TheHackerNews: '.$this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()) or returnServerError('Could not request TheHackerNews: '.$this->getURI()); $limit = 0; foreach ($html->find('article') as $element) { @@ -50,7 +50,7 @@ class TheHackerNewsBridge extends BridgeAbstract { $article_author = trim($element->find('span.vcard', 0)->plaintext); $article_title = $element->find('a.entry-title', 0)->plaintext; $article_timestamp = strtotime($element->find('span.updated', 0)->plaintext); - $article = $this->getSimpleHTMLDOM($article_url) or $this->returnServerError('Could not request TheHackerNews: '.$article_url); + $article = getSimpleHTMLDOM($article_url) or returnServerError('Could not request TheHackerNews: '.$article_url); $contents = $article->find('div.articlebodyonly', 0)->innertext; $contents = StripRecursiveHTMLSection($contents, 'div', '
getSimpleHTMLDOMCached($item['uri']); + $articlePage = getSimpleHTMLDOMCached($item['uri']); $content = $articlePage->find('#comic', 0); if(is_null($content)) // load alternative $content = $articlePage->find('#blog', 0); diff --git a/bridges/ThePirateBayBridge.php b/bridges/ThePirateBayBridge.php index 3fe61de9..0de08baa 100644 --- a/bridges/ThePirateBayBridge.php +++ b/bridges/ThePirateBayBridge.php @@ -52,11 +52,11 @@ class ThePirateBayBridge extends BridgeAbstract{ $keywordsList = explode(";",$this->getInput('q')); foreach($keywordsList as $keywords){ - $html = $this->getSimpleHTMLDOM(self::URI.'search/'.rawurlencode($keywords).'/0/3/0') - or $this->returnServerError('Could not request TPB.'); + $html = getSimpleHTMLDOM(self::URI.'search/'.rawurlencode($keywords).'/0/3/0') + or returnServerError('Could not request TPB.'); if ($html->find('table#searchResult', 0) == FALSE) - $this->returnServerError('No result for query '.$keywords); + returnServerError('No result for query '.$keywords); foreach($html->find('tr') as $element) { diff --git a/bridges/TwitchApiBridge.php b/bridges/TwitchApiBridge.php index 11da945d..106f4dd6 100644 --- a/bridges/TwitchApiBridge.php +++ b/bridges/TwitchApiBridge.php @@ -70,10 +70,10 @@ class TwitchApiBridge extends BridgeAbstract{ /* Finally we're ready to request data from the API. Each response provides information for the next request. */ for($i = 0; $i < $requests; $i++) { - $response = $this->getSimpleHTMLDOM($request, false, $context); + $response = getSimpleHTMLDOM($request, false, $context); if($response == false) { - $this->returnServerError('Request failed! Check if the channel name is valid!'); + returnServerError('Request failed! Check if the channel name is valid!'); } $data = json_decode($response); diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php index e30f7f08..baf8508c 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -61,13 +61,13 @@ class TwitterBridge extends BridgeAbstract{ public function collectData(){ $html = ''; - $html = $this->getSimpleHTMLDOM($this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()); if(!$html){ switch($this->queriedContext){ case 'By keyword or hashtag': - $this->returnServerError('No results for this query.'); + returnServerError('No results for this query.'); case 'By username': - $this->returnServerError('Requested username can\'t be found.'); + returnServerError('Requested username can\'t be found.'); } } diff --git a/bridges/UnsplashBridge.php b/bridges/UnsplashBridge.php index 85ce0c2a..8aacd4a9 100644 --- a/bridges/UnsplashBridge.php +++ b/bridges/UnsplashBridge.php @@ -33,8 +33,8 @@ class UnsplashBridge extends BridgeAbstract { for ($page = 1; $page <= $lastpage; $page++) { $link = self::URI.'/grid?page='.$page; - $html = $this->getSimpleHTMLDOM($link) - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM($link) + or returnServerError('No results for this query.'); if ($page === 1) { preg_match('/=(\d+)$/', $html->find('.pagination > a[!class]', -1)->href, $matches); diff --git a/bridges/ViadeoCompanyBridge.php b/bridges/ViadeoCompanyBridge.php index 75fd6aae..09bcf292 100644 --- a/bridges/ViadeoCompanyBridge.php +++ b/bridges/ViadeoCompanyBridge.php @@ -17,8 +17,8 @@ class ViadeoCompanyBridge extends BridgeAbstract{ $html = ''; $link = self::URI.'fr/company/'.$this->getInput('c'); - $html = $this->getSimpleHTMLDOM($link) - or $this->returnServerError('Could not request Viadeo.'); + $html = getSimpleHTMLDOM($link) + or returnServerError('Could not request Viadeo.'); foreach($html->find('//*[@id="company-newsfeed"]/ul/li') as $element) { $title = $element->find('p', 0)->innertext; diff --git a/bridges/VineBridge.php b/bridges/VineBridge.php index 6c42dd1f..da0b7caa 100644 --- a/bridges/VineBridge.php +++ b/bridges/VineBridge.php @@ -17,8 +17,8 @@ class VineBridge extends BridgeAbstract { $html = ''; $uri = self::URI.'/u/'.$this->getInput('u').'?mode=list'; - $html = $this->getSimpleHTMLDOM($uri) - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM($uri) + or returnServerError('No results for this query.'); foreach($html->find('.post') as $element) { $a = $element->find('a', 0); diff --git a/bridges/VkBridge.php b/bridges/VkBridge.php index 54895996..5dbae45c 100644 --- a/bridges/VkBridge.php +++ b/bridges/VkBridge.php @@ -18,8 +18,8 @@ class VkBridge extends BridgeAbstract { return static::URI.urlencode($this->getInput('u')); } public function collectData(){ - $text_html = $this->getContents($this->getURI()) - or $this->returnServerError('No results for group or user name "'.$this->getInput('u').'".'); + $text_html = getContents($this->getURI()) + or returnServerError('No results for group or user name "'.$this->getInput('u').'".'); $text_html = iconv('windows-1251', 'utf-8', $text_html); $html = str_get_html($text_html); diff --git a/bridges/WallpaperStopBridge.php b/bridges/WallpaperStopBridge.php index b10d0cc1..34b290f5 100644 --- a/bridges/WallpaperStopBridge.php +++ b/bridges/WallpaperStopBridge.php @@ -33,8 +33,8 @@ class WallpaperStopBridge extends BridgeAbstract { for ($page = 1; $page <= $lastpage; $page++) { $link = self::URI.'/'.$category.'-wallpaper/'.(!empty($subcategory)?$subcategory.'-wallpaper/':'').'desktop-wallpaper-'.$page.'.html'; - $html = $this->getSimpleHTMLDOM($link) - or $this->returnServerError('No results for this query.'); + $html = getSimpleHTMLDOM($link) + or returnServerError('No results for this query.'); if ($page === 1) { preg_match('/-(\d+)\.html$/', $html->find('.pagination > .last', 0)->href, $matches); diff --git a/bridges/WeLiveSecurityBridge.php b/bridges/WeLiveSecurityBridge.php index 9aa18c74..b05f4732 100644 --- a/bridges/WeLiveSecurityBridge.php +++ b/bridges/WeLiveSecurityBridge.php @@ -18,7 +18,7 @@ class WeLiveSecurityBridge extends FeedExpander { protected function parseItem($item){ $item = parent::parseItem($item); - $article_html = $this->getSimpleHTMLDOMCached($item['uri']); + $article_html = getSimpleHTMLDOMCached($item['uri']); if(!$article_html){ $item['content'] .= '

Could not request '.$this->getName().': '.$item['uri'].'

'; return $item; diff --git a/bridges/WhydBridge.php b/bridges/WhydBridge.php index ec377eba..fae39cfe 100644 --- a/bridges/WhydBridge.php +++ b/bridges/WhydBridge.php @@ -19,19 +19,19 @@ class WhydBridge extends BridgeAbstract{ $html = ''; if (strlen(preg_replace("/[^0-9a-f]/",'', $this->getInput('u'))) == 24){ // is input the userid ? - $html = $this->getSimpleHTMLDOM( + $html = getSimpleHTMLDOM( self::URI.'u/'.preg_replace("/[^0-9a-f]/",'', $this->getInput('u')) - ) or $this->returnServerError('No results for this query.'); + ) or returnServerError('No results for this query.'); } else { // input may be the username - $html = $this->getSimpleHTMLDOM( + $html = getSimpleHTMLDOM( self::URI.'search?q='.urlencode($this->getInput('u')) - ) or $this->returnServerError('No results for this query.'); + ) or returnServerError('No results for this query.'); for ($j = 0; $j < 5; $j++) { if (strtolower($html->find('div.user', $j)->find('a',0)->plaintext) == strtolower($this->getInput('u'))) { - $html = $this->getSimpleHTMLDOM( + $html = getSimpleHTMLDOM( self::URI . $html->find('div.user', $j)->find('a', 0)->getAttribute('href') - ) or $this->returnServerError('No results for this query'); + ) or returnServerError('No results for this query'); break; } } diff --git a/bridges/WikipediaBridge.php b/bridges/WikipediaBridge.php index 5feb4291..c0f0fc02 100644 --- a/bridges/WikipediaBridge.php +++ b/bridges/WikipediaBridge.php @@ -90,10 +90,10 @@ class WikipediaBridge extends BridgeAbstract { $fullArticle = $this->getInput('fullarticle'); // This will automatically send us to the correct main page in any language (try it!) - $html = $this->getSimpleHTMLDOM($this->getURI() . '/wiki'); + $html = getSimpleHTMLDOM($this->getURI() . '/wiki'); if(!$html) - $this->returnServerError('Could not load site: ' . $this->getURI() . '!'); + returnServerError('Could not load site: ' . $this->getURI() . '!'); /* * Now read content depending on the language (make sure to create one function per language!) @@ -103,7 +103,7 @@ class WikipediaBridge extends BridgeAbstract { $function = 'GetContents' . strtoupper($this->getInput('language')); if(!method_exists($this, $function)) - $this->returnServerError('A function to get the contents for your language is missing (\'' . $function . '\')!'); + returnServerError('A function to get the contents for your language is missing (\'' . $function . '\')!'); /* * The method takes care of creating all items. @@ -175,15 +175,15 @@ class WikipediaBridge extends BridgeAbstract { * Loads the full article from a given URI */ private function LoadFullArticle($uri){ - $content_html = $this->getSimpleHTMLDOMCached($uri); + $content_html = getSimpleHTMLDOMCached($uri); if(!$content_html) - $this->returnServerError('Could not load site: ' . $uri . '!'); + returnServerError('Could not load site: ' . $uri . '!'); $content = $content_html->find('#mw-content-text', 0); if(!$content) - $this->returnServerError('Could not find content in page: ' . $uri . '!'); + returnServerError('Could not find content in page: ' . $uri . '!'); // Let's remove a couple of things from the article $table = $content->find('#toc', 0); // Table of contents diff --git a/bridges/WordPressBridge.php b/bridges/WordPressBridge.php index d686a98f..bc45b1a1 100644 --- a/bridges/WordPressBridge.php +++ b/bridges/WordPressBridge.php @@ -22,7 +22,7 @@ class WordPressBridge extends FeedExpander { protected function parseItem($newItem){ $item=parent::parseItem($newItem); - $article_html = $this->getSimpleHTMLDOMCached($item['uri']); + $article_html = getSimpleHTMLDOMCached($item['uri']); $article=null; switch(true){ @@ -63,7 +63,7 @@ class WordPressBridge extends FeedExpander { public function collectData(){ if($this->getInput('url') && substr($this->getInput('url'),0,strlen('http'))!=='http'){ // just in case someone find a way to access local files by playing with the url - $this->returnClientError('The url parameter must either refer to http or https protocol.'); + returnClientError('The url parameter must either refer to http or https protocol.'); } $this->collectExpandableDatas($this->getURI().'/feed/atom/'); diff --git a/bridges/WorldOfTanksBridge.php b/bridges/WorldOfTanksBridge.php index a3179be9..256a6ca9 100644 --- a/bridges/WorldOfTanksBridge.php +++ b/bridges/WorldOfTanksBridge.php @@ -42,9 +42,9 @@ class WorldOfTanksBridge extends BridgeAbstract { } public function collectData(){ - $html = $this->getSimpleHTMLDOM($this->getURI()) - or $this->returnServerError('Could not request '.$this->getURI()); - $this->debugMessage("loaded HTML from ".$this->getURI()); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request '.$this->getURI()); + debugMessage("loaded HTML from ".$this->getURI()); // customize name $this->title = $html->find('title', 0)->innertext; foreach($html->find('.b-imgblock_ico') as $infoLink) { @@ -56,8 +56,8 @@ class WorldOfTanksBridge extends BridgeAbstract { $item = array(); $item['uri'] = self::URI.$infoLink->href; // now load that uri from cache - $this->debugMessage("loading page ".$item['uri']); - $articlePage = $this->getSimpleHTMLDOMCached($item['uri']); + debugMessage("loading page ".$item['uri']); + $articlePage = getSimpleHTMLDOMCached($item['uri']); $content = $articlePage->find('.l-content', 0); HTMLSanitizer::defaultImageSrcTo($content, self::URI); $item['title'] = $content->find('h1', 0)->innertext; diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 6c258f47..a8bc2e54 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -48,7 +48,7 @@ class YoutubeBridge extends BridgeAbstract { ); private function ytBridgeQueryVideoInfo($vid, &$author, &$desc, &$time) { - $html = $this->getSimpleHTMLDOM(self::URI."watch?v=$vid"); + $html = getSimpleHTMLDOM(self::URI."watch?v=$vid"); $author = $html->innertext; $author = substr($author, strpos($author, '"author=') + 8); $author = substr($author, 0, strpos($author, '\u0026')); @@ -118,17 +118,17 @@ class YoutubeBridge extends BridgeAbstract { $url_listing = self::URI.'channel/'.urlencode($this->request).'/videos'; } if (!empty($url_feed) && !empty($url_listing)) { - if ($xml = $this->getSimpleHTMLDOM($url_feed)) { + if ($xml = getSimpleHTMLDOM($url_feed)) { $this->ytBridgeParseXmlFeed($xml); - } else if ($html = $this->getSimpleHTMLDOM($url_listing)) { + } else if ($html = getSimpleHTMLDOM($url_listing)) { $this->ytBridgeParseHtmlListing($html, 'li.channels-content-item', 'h3'); - } else $this->returnServerError("Could not request YouTube. Tried:\n - $url_feed\n - $url_listing"); + } else returnServerError("Could not request YouTube. Tried:\n - $url_feed\n - $url_listing"); } else if ($this->getInput('p')) { /* playlist mode */ $this->request = $this->getInput('p'); $url_listing = self::URI.'playlist?list='.urlencode($this->request); - $html = $this->getSimpleHTMLDOM($url_listing) or $this->returnServerError("Could not request YouTube. Tried:\n - $url_listing"); + $html = getSimpleHTMLDOM($url_listing) or returnServerError("Could not request YouTube. Tried:\n - $url_listing"); $this->ytBridgeParseHtmlListing($html, 'tr.pl-video', '.pl-video-title a'); $this->request = 'Playlist: '.str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); } @@ -136,13 +136,13 @@ class YoutubeBridge extends BridgeAbstract { else if ($this->getInput('s')) { /* search mode */ $this->request = $this->getInput('s'); $page = 1; if ($this->getInput('pa')) $page = (int)preg_replace("/[^0-9]/",'', $this->getInput('pa')); $url_listing = self::URI.'results?search_query='.urlencode($this->request).'&page='.$page.'&filters=video&search_sort=video_date_uploaded'; - $html = $this->getSimpleHTMLDOM($url_listing) or $this->returnServerError("Could not request YouTube. Tried:\n - $url_listing"); + $html = getSimpleHTMLDOM($url_listing) or returnServerError("Could not request YouTube. Tried:\n - $url_listing"); $this->ytBridgeParseHtmlListing($html, 'div.yt-lockup', 'h3'); $this->request = 'Search: '.str_replace(' - YouTube', '', $html->find('title', 0)->plaintext); } else { /* no valid mode */ - $this->returnClientError("You must either specify either:\n - YouTube username (?u=...)\n - Channel id (?c=...)\n - Playlist id (?p=...)\n - Search (?s=...)"); + returnClientError("You must either specify either:\n - YouTube username (?u=...)\n - Channel id (?c=...)\n - Playlist id (?p=...)\n - Search (?s=...)"); } } diff --git a/bridges/ZDNetBridge.php b/bridges/ZDNetBridge.php index af0eb871..aad006f1 100644 --- a/bridges/ZDNetBridge.php +++ b/bridges/ZDNetBridge.php @@ -214,7 +214,7 @@ class ZDNetBridge extends BridgeAbstract { $baseUri = str_replace('www.', 'downloads.', $baseUri); } $url = $baseUri.trim($feed, '/').'/rss.xml'; - $html = $this->getSimpleHTMLDOM($url) or $this->returnServerError('Could not request ZDNet: '.$url); + $html = getSimpleHTMLDOM($url) or returnServerError('Could not request ZDNet: '.$url); $limit = 0; foreach ($html->find('item') as $element) { @@ -224,7 +224,7 @@ class ZDNetBridge extends BridgeAbstract { $article_title = StripCDATA($element->find('title', 0)->plaintext); $article_subtitle = StripCDATA($element->find('description', 0)->plaintext); $article_timestamp = strtotime(StripCDATA($element->find('pubDate', 0)->plaintext)); - $article = $this->getSimpleHTMLDOM($article_url) or $this->returnServerError('Could not request ZDNet: '.$article_url); + $article = getSimpleHTMLDOM($article_url) or returnServerError('Could not request ZDNet: '.$article_url); if (!empty($article_author)) $author = $article_author; diff --git a/index.php b/index.php index bb9555cd..6249f5bb 100644 --- a/index.php +++ b/index.php @@ -124,8 +124,9 @@ try { $bridge->setCache($cache); $noproxy = filter_input(INPUT_GET, '_noproxy', FILTER_VALIDATE_BOOLEAN); - if(defined('PROXY_URL') && PROXY_BYBRIDGE && $noproxy) - $bridge->useProxy = false; + if(defined('PROXY_URL') && PROXY_BYBRIDGE && $noproxy){ + define('NOPROXY',true); + } $params = $_GET; unset($params['action']); diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index f746f1f5..67b3adaa 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -8,25 +8,11 @@ abstract class BridgeAbstract implements BridgeInterface { const MAINTAINER = 'No maintainer'; const PARAMETERS = array(); - public $useProxy = true; - protected $cache; protected $items = array(); protected $inputs = array(); protected $queriedContext = ''; - protected function returnError($message, $code){ - throw new \HttpException($message, $code); - } - - protected function returnClientError($message){ - $this->returnError($message, 400); - } - - protected function returnServerError($message){ - $this->returnError($message, 500); - } - /** * Return items stored in the bridge * @return mixed @@ -260,7 +246,7 @@ abstract class BridgeAbstract implements BridgeInterface { if(empty(static::PARAMETERS)){ if(!empty($inputs)){ - $this->returnClientError('Invalid parameters value(s)'); + returnClientError('Invalid parameters value(s)'); } $this->collectData(); @@ -271,15 +257,15 @@ abstract class BridgeAbstract implements BridgeInterface { } if(!$this->validateData($inputs)){ - $this->returnClientError('Invalid parameters value(s)'); + returnClientError('Invalid parameters value(s)'); } // Guess the paramter context from input data $this->queriedContext = $this->getQueriedContext($inputs); if(is_null($this->queriedContext)){ - $this->returnClientError('Required parameter(s) missing'); + returnClientError('Required parameter(s) missing'); } elseif($this->queriedContext === false){ - $this->returnClientError('Mixed context parameters'); + returnClientError('Mixed context parameters'); } $this->setInputs($inputs, $this->queriedContext); @@ -313,157 +299,4 @@ abstract class BridgeAbstract implements BridgeInterface { public function setCache(\CacheAbstract $cache){ $this->cache = $cache; } - - public function debugMessage($text){ - if(!file_exists('DEBUG')) { - return; - } - - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); - $calling = $backtrace[2]; - $message = $calling['file'] . ':' - . $calling['line'] . ' class ' - . get_class($this) . '->' - . $calling['function'] . ' - ' - . $text; - - error_log($message); - } - - protected function getContents($url - , $use_include_path = false - , $context = null - , $offset = 0 - , $maxlen = null){ - $contextOptions = array( - 'http' => array( - 'user_agent' => ini_get('user_agent') - ) - ); - - if(defined('PROXY_URL') && $this->useProxy){ - $contextOptions['http']['proxy'] = PROXY_URL; - $contextOptions['http']['request_fulluri'] = true; - - if(is_null($context)){ - $context = stream_context_create($contextOptions); - } else { - $prevContext = $context; - if(!stream_context_set_option($context, $contextOptions)){ - $context = $prevContext; - } - } - } - - if(is_null($maxlen)){ - $content = @file_get_contents($url, $use_include_path, $context, $offset); - } else { - $content = @file_get_contents($url, $use_include_path, $context, $offset, $maxlen); - } - - if($content === false) - $this->debugMessage('Cant\'t download ' . $url); - - // handle compressed data - foreach($http_response_header as $header){ - if(stristr($header, 'content-encoding')){ - switch(true){ - case stristr($header, 'gzip'): - $content = gzinflate(substr($content, 10, -8)); - break; - case stristr($header, 'compress'): - //TODO - case stristr($header, 'deflate'): - //TODO - case stristr($header, 'brotli'): - //TODO - $this->returnServerError($header . '=> Not implemented yet'); - break; - case stristr($header, 'identity'): - break; - default: - $this->returnServerError($header . '=> Unknown compression'); - } - } - } - - return $content; - } - - protected function getSimpleHTMLDOM($url - , $use_include_path = false - , $context = null - , $offset = 0 - , $maxLen = null - , $lowercase = true - , $forceTagsClosed = true - , $target_charset = DEFAULT_TARGET_CHARSET - , $stripRN = true - , $defaultBRText = DEFAULT_BR_TEXT - , $defaultSpanText = DEFAULT_SPAN_TEXT){ - $content = $this->getContents($url, $use_include_path, $context, $offset, $maxLen); - return str_get_html($content - , $lowercase - , $forceTagsClosed - , $target_charset - , $stripRN - , $defaultBRText - , $defaultSpanText); - } - - /** - * Maintain locally cached versions of pages to avoid multiple downloads. - * @param url url to cache - * @param duration duration of the cache file in seconds (default: 24h/86400s) - * @return content of the file as string - */ - public function getSimpleHTMLDOMCached($url - , $duration = 86400 - , $use_include_path = false - , $context = null - , $offset = 0 - , $maxLen = null - , $lowercase = true - , $forceTagsClosed = true - , $target_charset = DEFAULT_TARGET_CHARSET - , $stripRN = true - , $defaultBRText = DEFAULT_BR_TEXT - , $defaultSpanText = DEFAULT_SPAN_TEXT){ - $this->debugMessage('Caching url ' . $url . ', duration ' . $duration); - - $filepath = __DIR__ . '/../cache/pages/' . sha1($url) . '.cache'; - $this->debugMessage('Cache file ' . $filepath); - - if(file_exists($filepath) && filectime($filepath) < time() - $duration){ - unlink ($filepath); - $this->debugMessage('Cached file deleted: ' . $filepath); - } - - if(file_exists($filepath)){ - $this->debugMessage('Loading cached file ' . $filepath); - touch($filepath); - $content = file_get_contents($filepath); - } else { - $this->debugMessage('Caching ' . $url . ' to ' . $filepath); - $dir = substr($filepath, 0, strrpos($filepath, '/')); - - if(!is_dir($dir)){ - $this->debugMessage('Creating directory ' . $dir); - mkdir($dir, 0777, true); - } - - $content = $this->getContents($url, $use_include_path, $context, $offset, $maxLen); - if($content !== false){ - file_put_contents($filepath, $content); - } - } - - return str_get_html($content - , $lowercase - , $forceTagsClosed - , $target_charset - , $stripRN - , $defaultBRText - , $defaultSpanText); - } } diff --git a/lib/FeedExpander.php b/lib/FeedExpander.php index 01909a5a..b0d975ae 100644 --- a/lib/FeedExpander.php +++ b/lib/FeedExpander.php @@ -9,46 +9,46 @@ abstract class FeedExpander extends BridgeAbstract { public function collectExpandableDatas($url, $maxItems = -1){ if(empty($url)){ - $this->returnServerError('There is no $url for this RSS expander'); + returnServerError('There is no $url for this RSS expander'); } - $this->debugMessage('Loading from ' . $url); + debugMessage('Loading from ' . $url); /* Notice we do not use cache here on purpose: * we want a fresh view of the RSS stream each time */ - $content = $this->getContents($url) - or $this->returnServerError('Could not request ' . $url); + $content = getContents($url) + or returnServerError('Could not request ' . $url); $rssContent = simplexml_load_string($content); - $this->debugMessage('Detecting feed format/version'); + debugMessage('Detecting feed format/version'); switch(true){ case isset($rssContent->item[0]): - $this->debugMessage('Detected RSS 1.0 format'); + debugMessage('Detected RSS 1.0 format'); $this->feedType = "RSS_1_0"; break; case isset($rssContent->channel[0]): - $this->debugMessage('Detected RSS 0.9x or 2.0 format'); + debugMessage('Detected RSS 0.9x or 2.0 format'); $this->feedType = "RSS_2_0"; break; case isset($rssContent->entry[0]): - $this->debugMessage('Detected ATOM format'); + debugMessage('Detected ATOM format'); $this->feedType = "ATOM_1_0"; break; default: - $this->debugMessage('Unknown feed format/version'); - $this->returnServerError('The feed format is unknown!'); + debugMessage('Unknown feed format/version'); + returnServerError('The feed format is unknown!'); break; } - $this->debugMessage('Calling function "collect_' . $this->feedType . '_data"'); + debugMessage('Calling function "collect_' . $this->feedType . '_data"'); $this->{'collect_' . $this->feedType . '_data'}($rssContent, $maxItems); } protected function collect_RSS_1_0_data($rssContent, $maxItems){ $this->load_RSS_2_0_feed_data($rssContent->channel[0]); foreach($rssContent->item as $item){ - $this->debugMessage('parsing item ' . var_export($item, true)); + debugMessage('parsing item ' . var_export($item, true)); $this->items[] = $this->parseItem($item); if($maxItems !== -1 && count($this->items) >= $maxItems) break; } @@ -56,13 +56,13 @@ abstract class FeedExpander extends BridgeAbstract { protected function collect_RSS_2_0_data($rssContent, $maxItems){ $rssContent = $rssContent->channel[0]; - $this->debugMessage('RSS content is ===========\n' + debugMessage('RSS content is ===========\n' . var_export($rssContent, true) . '==========='); $this->load_RSS_2_0_feed_data($rssContent); foreach($rssContent->item as $item){ - $this->debugMessage('parsing item ' . var_export($item, true)); + debugMessage('parsing item ' . var_export($item, true)); $this->items[] = $this->parseItem($item); if($maxItems !== -1 && count($this->items) >= $maxItems) break; } @@ -71,7 +71,7 @@ abstract class FeedExpander extends BridgeAbstract { protected function collect_ATOM_1_0_data($content, $maxItems){ $this->load_ATOM_feed_data($content); foreach($content->entry as $item){ - $this->debugMessage('parsing item ' . var_export($item, true)); + debugMessage('parsing item ' . var_export($item, true)); $this->items[] = $this->parseItem($item); if($maxItems !== -1 && count($this->items) >= $maxItems) break; } @@ -190,7 +190,7 @@ abstract class FeedExpander extends BridgeAbstract { case 'ATOM_1_0': return $this->parseATOMItem($item); break; - default: $this->returnClientError('Unknown version ' . $this->getInput('version') . '!'); + default: returnClientError('Unknown version ' . $this->getInput('version') . '!'); } } diff --git a/lib/RssBridge.php b/lib/RssBridge.php index cf271144..a0b5a424 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -16,6 +16,8 @@ require __DIR__ . '/FeedExpander.php'; require __DIR__ . '/Cache.php'; require __DIR__ . '/CacheAbstract.php'; require __DIR__ . '/HTMLUtils.php'; +require __DIR__ . '/error.php'; +require __DIR__ . '/contents.php'; $vendorLibSimpleHtmlDom = __DIR__ . PATH_VENDOR . '/simplehtmldom/simple_html_dom.php'; if( !file_exists($vendorLibSimpleHtmlDom) ){ diff --git a/lib/contents.php b/lib/contents.php new file mode 100644 index 00000000..747db5bf --- /dev/null +++ b/lib/contents.php @@ -0,0 +1,142 @@ + array( + 'user_agent' => ini_get('user_agent') + ) + ); + + if(defined('PROXY_URL') && !defined('NOPROXY')){ + $contextOptions['http']['proxy'] = PROXY_URL; + $contextOptions['http']['request_fulluri'] = true; + + if(is_null($context)){ + $context = stream_context_create($contextOptions); + } else { + $prevContext = $context; + if(!stream_context_set_option($context, $contextOptions)){ + $context = $prevContext; + } + } + } + + if(is_null($maxlen)){ + $content = @file_get_contents($url, $use_include_path, $context, $offset); + } else { + $content = @file_get_contents($url, $use_include_path, $context, $offset, $maxlen); + } + + if($content === false) + debugMessage('Cant\'t download ' . $url); + + // handle compressed data + foreach($http_response_header as $header){ + if(stristr($header, 'content-encoding')){ + switch(true){ + case stristr($header, 'gzip'): + $content = gzinflate(substr($content, 10, -8)); + break; + case stristr($header, 'compress'): + //TODO + case stristr($header, 'deflate'): + //TODO + case stristr($header, 'brotli'): + //TODO + returnServerError($header . '=> Not implemented yet'); + break; + case stristr($header, 'identity'): + break; + default: + returnServerError($header . '=> Unknown compression'); + } + } + } + + return $content; +} + +function getSimpleHTMLDOM($url + , $use_include_path = false + , $context = null + , $offset = 0 + , $maxLen = null + , $lowercase = true + , $forceTagsClosed = true + , $target_charset = DEFAULT_TARGET_CHARSET + , $stripRN = true + , $defaultBRText = DEFAULT_BR_TEXT + , $defaultSpanText = DEFAULT_SPAN_TEXT +){ + $content = getContents($url, $use_include_path, $context, $offset, $maxLen); + return str_get_html($content + , $lowercase + , $forceTagsClosed + , $target_charset + , $stripRN + , $defaultBRText + , $defaultSpanText); +} + +/** + * Maintain locally cached versions of pages to avoid multiple downloads. + * @param url url to cache + * @param duration duration of the cache file in seconds (default: 24h/86400s) + * @return content of the file as string + */ +function getSimpleHTMLDOMCached($url + , $duration = 86400 + , $use_include_path = false + , $context = null + , $offset = 0 + , $maxLen = null + , $lowercase = true + , $forceTagsClosed = true + , $target_charset = DEFAULT_TARGET_CHARSET + , $stripRN = true + , $defaultBRText = DEFAULT_BR_TEXT + , $defaultSpanText = DEFAULT_SPAN_TEXT +){ + debugMessage('Caching url ' . $url . ', duration ' . $duration); + + $filepath = __DIR__ . '/../cache/pages/' . sha1($url) . '.cache'; + debugMessage('Cache file ' . $filepath); + + if(file_exists($filepath) && filectime($filepath) < time() - $duration){ + unlink ($filepath); + debugMessage('Cached file deleted: ' . $filepath); + } + + if(file_exists($filepath)){ + debugMessage('Loading cached file ' . $filepath); + touch($filepath); + $content = file_get_contents($filepath); + } else { + debugMessage('Caching ' . $url . ' to ' . $filepath); + $dir = substr($filepath, 0, strrpos($filepath, '/')); + + if(!is_dir($dir)){ + debugMessage('Creating directory ' . $dir); + mkdir($dir, 0777, true); + } + + $content = getContents($url, $use_include_path, $context, $offset, $maxLen); + if($content !== false){ + file_put_contents($filepath, $content); + } + } + + return str_get_html($content + , $lowercase + , $forceTagsClosed + , $target_charset + , $stripRN + , $defaultBRText + , $defaultSpanText); +} + +?> diff --git a/lib/error.php b/lib/error.php new file mode 100644 index 00000000..4a814b19 --- /dev/null +++ b/lib/error.php @@ -0,0 +1,30 @@ +' + . $calling['function'] . ' - ' + . $text; + + error_log($message); +} + +?>