diff --git a/bridges/ABCTabsBridge.php b/bridges/ABCTabsBridge.php index 247ab00..1e7e170 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 911abfc..31481ad 100644 --- a/bridges/AcrimedBridge.php +++ b/bridges/AcrimedBridge.php @@ -14,10 +14,9 @@ class AcrimedBridge extends FeedExpander { protected function parseItem($newsItem){ $item = parent::parseItem($newsItem); - $hs = new HTMLSanitizer(); - $articlePage = $this->getSimpleHTMLDOM($newsItem->link); - $article = $hs->sanitize($articlePage->find('article.article1', 0)->innertext); - $article = HTMLSanitizer::defaultImageSrcTo($article, static::URI); + $articlePage = getSimpleHTMLDOM($newsItem->link); + $article = sanitize($articlePage->find('article.article1', 0)->innertext); + $article = defaultImageSrcTo($article, static::URI); $item['content'] = $article; return $item; diff --git a/bridges/AllocineFRBridge.php b/bridges/AllocineFRBridge.php index 6ca6b8e..7f8c6e8 100644 --- a/bridges/AllocineFRBridge.php +++ b/bridges/AllocineFRBridge.php @@ -48,8 +48,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 aed1e00..ef87499 100644 --- a/bridges/AnimeUltimeBridge.php +++ b/bridges/AnimeUltimeBridge.php @@ -39,8 +39,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) { @@ -68,8 +68,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 134dd9f..0fcb793 100644 --- a/bridges/Arte7Bridge.php +++ b/bridges/Arte7Bridge.php @@ -58,7 +58,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 0a4d967..45bcc36 100644 --- a/bridges/AskfmBridge.php +++ b/bridges/AskfmBridge.php @@ -16,8 +16,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 55c5b41..70df97b 100644 --- a/bridges/BandcampBridge.php +++ b/bridges/BandcampBridge.php @@ -15,8 +15,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 55f68f6..b700272 100644 --- a/bridges/BastaBridge.php +++ b/bridges/BastaBridge.php @@ -12,8 +12,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) { @@ -22,7 +22,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 ba93e9a..4cda118 100644 --- a/bridges/BlaguesDeMerdeBridge.php +++ b/bridges/BlaguesDeMerdeBridge.php @@ -9,8 +9,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 12071be..86c0fef 100644 --- a/bridges/CADBridge.php +++ b/bridges/CADBridge.php @@ -17,7 +17,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 ea74203..a890edb 100644 --- a/bridges/CNETBridge.php +++ b/bridges/CNETBridge.php @@ -39,7 +39,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) { @@ -52,7 +52,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 c3f4793..09f89ed 100644 --- a/bridges/CourrierInternationalBridge.php +++ b/bridges/CourrierInternationalBridge.php @@ -9,8 +9,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"); @@ -26,11 +26,9 @@ class CourrierInternationalBridge extends BridgeAbstract{ $item['uri'] = self::URI.$item['uri']; } - $page = $this->getSimpleHTMLDOM($item['uri']); + $page = getSimpleHTMLDOM($item['uri']); - $cleaner = new HTMLSanitizer(); - - $item['content'] = $cleaner->sanitize($page->find("div.article-text")[0]); + $item['content'] = sanitize($page->find("div.article-text")[0]); $item['title'] = strip_tags($article->find(".title")[0]); $dateTime = date_parse($page->find("time")[0]); diff --git a/bridges/CpasbienBridge.php b/bridges/CpasbienBridge.php index c8669b3..26b8f31 100644 --- a/bridges/CpasbienBridge.php +++ b/bridges/CpasbienBridge.php @@ -17,14 +17,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 e497eae..7fbb68a 100644 --- a/bridges/CryptomeBridge.php +++ b/bridges/CryptomeBridge.php @@ -17,8 +17,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 4f49618..50d8c0b 100644 --- a/bridges/DailymotionBridge.php +++ b/bridges/DailymotionBridge.php @@ -36,7 +36,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; } @@ -53,8 +53,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 609d55a..9b7ab18 100644 --- a/bridges/DanbooruBridge.php +++ b/bridges/DanbooruBridge.php @@ -41,8 +41,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 6081310..6cefca8 100644 --- a/bridges/DansTonChatBridge.php +++ b/bridges/DansTonChatBridge.php @@ -9,8 +9,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 e2d38fb..0d05243 100644 --- a/bridges/DauphineLibereBridge.php +++ b/bridges/DauphineLibereBridge.php @@ -48,7 +48,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 dbf8514..969f5eb 100644 --- a/bridges/DeveloppezDotComBridge.php +++ b/bridges/DeveloppezDotComBridge.php @@ -43,7 +43,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 6257a00..b741127 100644 --- a/bridges/DilbertBridge.php +++ b/bridges/DilbertBridge.php @@ -9,7 +9,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 480deb9..125975b 100644 --- a/bridges/DuckDuckGoBridge.php +++ b/bridges/DuckDuckGoBridge.php @@ -14,8 +14,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 d2399e0..4279359 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 bf76102..ef98e7f 100644 --- a/bridges/EliteDangerousGalnetBridge.php +++ b/bridges/EliteDangerousGalnetBridge.php @@ -9,8 +9,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 8e7580e..a85015a 100644 --- a/bridges/ElsevierBridge.php +++ b/bridges/ElsevierBridge.php @@ -58,7 +58,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 fdb99b4..e625e44 100644 --- a/bridges/EstCeQuonMetEnProdBridge.php +++ b/bridges/EstCeQuonMetEnProdBridge.php @@ -16,7 +16,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 c595373..230c11f 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -93,8 +93,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); } @@ -105,11 +105,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.'); } } @@ -127,7 +127,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 c9badd6..e9d955d 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 b6c49d1..2d8f71e 100644 --- a/bridges/FierPandaBridge.php +++ b/bridges/FierPandaBridge.php @@ -8,7 +8,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 46d330d..170bec0 100644 --- a/bridges/FlickrExploreBridge.php +++ b/bridges/FlickrExploreBridge.php @@ -8,8 +8,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 @@ -23,14 +23,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 3b97c66..2662c57 100644 --- a/bridges/FlickrTagBridge.php +++ b/bridges/FlickrTagBridge.php @@ -26,12 +26,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 b669ac5..8b7a12a 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 9895cc3..64dfaa2 100644 --- a/bridges/FourchanBridge.php +++ b/bridges/FourchanBridge.php @@ -26,8 +26,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 b0f09f0..d8884bc 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 d271cd9..a171aff 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 9498141..90f23a9 100644 --- a/bridges/GiphyBridge.php +++ b/bridges/GiphyBridge.php @@ -23,8 +23,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')) { @@ -38,8 +38,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 81c1625..58dfc37 100644 --- a/bridges/GithubIssueBridge.php +++ b/bridges/GithubIssueBridge.php @@ -136,8 +136,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': @@ -153,7 +153,7 @@ class GithubIssueBridge extends BridgeAbstract{ if($this->getInput('c')){ $uri=static::URI.$this->getInput('u').'/'.$this->getInput('p').'/issues/'.$issueNbr; - $issue=$this->getSimpleHTMLDOMCached($uri,static::CACHE_TIMEOUT); + $issue=getSimpleHTMLDOMCached($uri,static::CACHE_TIMEOUT); if($issue){ $this->items=array_merge($this->items,$this->extractIssueComments($issue)); continue; diff --git a/bridges/GizmodoBridge.php b/bridges/GizmodoBridge.php index 3879c47..bb99c66 100644 --- a/bridges/GizmodoBridge.php +++ b/bridges/GizmodoBridge.php @@ -10,7 +10,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 214911d..1c1e1d9 100644 --- a/bridges/GooglePlusPostBridge.php +++ b/bridges/GooglePlusPostBridge.php @@ -20,13 +20,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 0619acf..53d8a95 100644 --- a/bridges/GoogleSearchBridge.php +++ b/bridges/GoogleSearchBridge.php @@ -26,10 +26,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 9733af9..740b700 100644 --- a/bridges/HDWallpapersBridge.php +++ b/bridges/HDWallpapersBridge.php @@ -31,7 +31,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 2bab505..f075cb6 100644 --- a/bridges/HentaiHavenBridge.php +++ b/bridges/HentaiHavenBridge.php @@ -8,8 +8,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 0ee1e28..a0c3bb2 100644 --- a/bridges/IdenticaBridge.php +++ b/bridges/IdenticaBridge.php @@ -15,8 +15,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 47eb815..e3c4b51 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 72d0a03..a95c85b 100644 --- a/bridges/IsoHuntBridge.php +++ b/bridges/IsoHuntBridge.php @@ -205,21 +205,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(); @@ -240,11 +240,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); @@ -253,11 +253,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(); @@ -278,11 +278,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(); @@ -300,7 +300,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); @@ -311,7 +311,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); @@ -329,7 +329,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; } @@ -337,7 +337,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; } @@ -345,7 +345,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){ @@ -367,11 +367,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(); @@ -389,11 +389,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; } @@ -401,11 +401,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); } @@ -417,7 +417,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; } @@ -425,7 +425,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()); } @@ -435,9 +435,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 c44a7e9..72dd0a6 100644 --- a/bridges/JapanExpoBridge.php +++ b/bridges/JapanExpoBridge.php @@ -43,8 +43,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; @@ -61,7 +61,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 de3893d..25d8dbf 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 76a8007..11ebd32 100644 --- a/bridges/KununuBridge.php +++ b/bridges/KununuBridge.php @@ -68,21 +68,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){ @@ -125,11 +125,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; } @@ -141,7 +141,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); } @@ -152,7 +152,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'); } @@ -163,7 +163,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); } @@ -175,11 +175,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; } @@ -191,7 +191,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'; @@ -211,7 +211,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); } @@ -221,14 +221,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 585eaf9..8c2c435 100644 --- a/bridges/LWNprevBridge.php +++ b/bridges/LWNprevBridge.php @@ -33,8 +33,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 2c24308..54c0f5e 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 e1154e4..f737ed4 100644 --- a/bridges/LeMondeInformatiqueBridge.php +++ b/bridges/LeMondeInformatiqueBridge.php @@ -13,8 +13,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 b35c7e6..6cc8086 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 ccd3fd8..cde4977 100644 --- a/bridges/LesJoiesDuCodeBridge.php +++ b/bridges/LesJoiesDuCodeBridge.php @@ -8,8 +8,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 b1498d2..e0657b8 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 6f6c176..7e966f6 100644 --- a/bridges/LinkedInCompanyBridge.php +++ b/bridges/LinkedInCompanyBridge.php @@ -18,8 +18,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 d65c4d8..949e7a4 100644 --- a/bridges/MangareaderBridge.php +++ b/bridges/MangareaderBridge.php @@ -79,9 +79,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 7bb8f34..920bc10 100644 --- a/bridges/MoebooruBridge.php +++ b/bridges/MoebooruBridge.php @@ -22,8 +22,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 002b5c3..e0cf78c 100644 --- a/bridges/MondeDiploBridge.php +++ b/bridges/MondeDiploBridge.php @@ -8,8 +8,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 f7b4c77..348bdb9 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 d7f0da0..bc284cf 100644 --- a/bridges/NasaApodBridge.php +++ b/bridges/NasaApodBridge.php @@ -9,7 +9,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++) @@ -21,7 +21,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 16a4a2f..0bf3ce3 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 9196cdd..21baf4c 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 14f1d53..78ffb05 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 5f5f94a..678b4f7 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 3897b22..d0a6d71 100644 --- a/bridges/NovelUpdatesBridge.php +++ b/bridges/NovelUpdatesBridge.php @@ -21,8 +21,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 ab62e28..d5424ea 100644 --- a/bridges/OpenClassroomsBridge.php +++ b/bridges/OpenClassroomsBridge.php @@ -32,8 +32,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 5717083..ee94e70 100644 --- a/bridges/ParuVenduImmoBridge.php +++ b/bridges/ParuVenduImmoBridge.php @@ -26,8 +26,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 2feb9fb..cef99a2 100644 --- a/bridges/PickyWallpapersBridge.php +++ b/bridges/PickyWallpapersBridge.php @@ -34,8 +34,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 59bbf12..65c3b60 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 e05b2a5..469c37e 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 50bf5b4..54e1a58 100644 --- a/bridges/RTBFBridge.php +++ b/bridges/RTBFBridge.php @@ -19,8 +19,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 7892ca9..535ecf3 100644 --- a/bridges/Releases3DSBridge.php +++ b/bridges/Releases3DSBridge.php @@ -34,7 +34,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) { @@ -69,7 +69,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 5061cbe..be4ceee 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 ae08ec2..400943e 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 d1b2a94..3cde324 100644 --- a/bridges/ScmbBridge.php +++ b/bridges/ScmbBridge.php @@ -9,8 +9,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 e25a0a4..999519b 100644 --- a/bridges/ScoopItBridge.php +++ b/bridges/ScoopItBridge.php @@ -18,8 +18,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 fcced92..3daee27 100644 --- a/bridges/SensCritiqueBridge.php +++ b/bridges/SensCritiqueBridge.php @@ -47,8 +47,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); @@ -58,7 +58,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 e110b23..4265d3a 100644 --- a/bridges/SexactuBridge.php +++ b/bridges/SexactuBridge.php @@ -11,7 +11,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 875e43c..7439d78 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 5aeed2a..7f7da37 100644 --- a/bridges/SoundcloudBridge.php +++ b/bridges/SoundcloudBridge.php @@ -18,16 +18,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 b2bda89..330af9f 100644 --- a/bridges/StripeAPIChangeLogBridge.php +++ b/bridges/StripeAPIChangeLogBridge.php @@ -7,8 +7,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 fd946c8..056eca8 100644 --- a/bridges/SuperbWallpapersBridge.php +++ b/bridges/SuperbWallpapersBridge.php @@ -33,15 +33,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 d3d952f..0c87f64 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 6f947fc..b08b728 100644 --- a/bridges/TagBoardBridge.php +++ b/bridges/TagBoardBridge.php @@ -17,8 +17,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 6e09f6a..3d1d361 100644 --- a/bridges/TheCodingLoveBridge.php +++ b/bridges/TheCodingLoveBridge.php @@ -8,8 +8,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 fe07fd3..58f8f91 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 33f5af8..5d772df 100644 --- a/bridges/ThePirateBayBridge.php +++ b/bridges/ThePirateBayBridge.php @@ -18,7 +18,7 @@ class ThePirateBayBridge extends BridgeAbstract{ 'values'=>array( 'search'=>'search', 'category'=>'cat', - 'user'=>'usr' + 'user'=>'usr' ) ), 'cat_check'=>array( @@ -70,7 +70,7 @@ class ThePirateBayBridge extends BridgeAbstract{ if ($catBool) { $catNum = $this->getInput('cat'); - } + } $critList = $this->getInput('crit'); $keywordsList = explode(";",$this->getInput('q')); foreach($keywordsList as $keywords){ @@ -78,33 +78,32 @@ class ThePirateBayBridge extends BridgeAbstract{ case "search": if ($catBool == FALSE) { - $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.'); } else { - $html = $this->getSimpleHTMLDOM(self::URI.'search/'.rawurlencode($keywords).'/0/3/'.rawurlencode($catNum)) - or $this->returnServerError('Could not request TPB.'); + $html = getSimpleHTMLDOM(self::URI.'search/'.rawurlencode($keywords).'/0/3/'.rawurlencode($catNum)) + or returnServerError('Could not request TPB.'); } break; case "cat": - $html = $this->getSimpleHTMLDOM(self::URI.'browse/'.rawurlencode($keywords).'/0/3/0') - or $this->returnServerError('Could not request TPB.'); + $html = getSimpleHTMLDOM(self::URI.'browse/'.rawurlencode($keywords).'/0/3/0') + or returnServerError('Could not request TPB.'); break; case "usr": - $html = $this->getSimpleHTMLDOM(self::URI.'user/'.rawurlencode($keywords).'/0/3/0') - or $this->returnServerError('Could not request TPB.'); + $html = getSimpleHTMLDOM(self::URI.'user/'.rawurlencode($keywords).'/0/3/0') + or returnServerError('Could not request TPB.'); break; } - 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) { $item = array(); - $item['uri'] = $element->find('a',3)->href; + $item['uri'] = $element->find('a',3)->href; $item['id'] = self::URI.$element->find('a.detLink',0)->href; $item['timestamp'] = parseDateTimestamp($element); $item['author'] = $element->find('a.detDesc',0)->plaintext; diff --git a/bridges/TwitchApiBridge.php b/bridges/TwitchApiBridge.php index a36dab8..5567687 100644 --- a/bridges/TwitchApiBridge.php +++ b/bridges/TwitchApiBridge.php @@ -71,10 +71,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 f4f2a19..624ba58 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -62,13 +62,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 6d776da..378d24e 100644 --- a/bridges/UnsplashBridge.php +++ b/bridges/UnsplashBridge.php @@ -34,8 +34,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 275ff76..714094f 100644 --- a/bridges/ViadeoCompanyBridge.php +++ b/bridges/ViadeoCompanyBridge.php @@ -18,8 +18,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 5969ce7..a30590d 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 98ae78f..7ec81c6 100644 --- a/bridges/VkBridge.php +++ b/bridges/VkBridge.php @@ -19,8 +19,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 35333dc..9a44d03 100644 --- a/bridges/WallpaperStopBridge.php +++ b/bridges/WallpaperStopBridge.php @@ -34,8 +34,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 9aa18c7..b05f473 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 feabdec..2066a91 100644 --- a/bridges/WhydBridge.php +++ b/bridges/WhydBridge.php @@ -20,19 +20,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 5feb429..c0f0fc0 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 ccdb780..01af8d0 100644 --- a/bridges/WordPressBridge.php +++ b/bridges/WordPressBridge.php @@ -23,7 +23,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){ @@ -64,7 +64,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 a3179be..2cd86c4 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,10 +56,10 @@ 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); + defaultImageSrcTo($content, self::URI); $item['title'] = $content->find('h1', 0)->innertext; $item['content'] = $content->find('.b-content', 0)->innertext; $item['timestamp'] = $content->find('.b-statistic_time', 0)->getAttribute("data-timestamp"); diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index aa7f834..4aa54e1 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -49,7 +49,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')); @@ -119,17 +119,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); } @@ -137,13 +137,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 af0eb87..aad006f 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 bb9555c..c8ef051 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']); @@ -187,11 +188,11 @@ $formats = Format::searchInformation(); $bridgeList = Bridge::listBridges(); foreach($bridgeList as $bridgeName){ if(Bridge::isWhitelisted($whitelist_selection, $bridgeName)){ - echo HTMLUtils::displayBridgeCard($bridgeName, $formats); + echo displayBridgeCard($bridgeName, $formats); $activeFoundBridgeCount++; } elseif($showInactive) { // inactive bridges - $inactiveBridges .= HTMLUtils::displayBridgeCard($bridgeName, $formats, false) . PHP_EOL; + $inactiveBridges .= displayBridgeCard($bridgeName, $formats, false) . PHP_EOL; } } echo $inactiveBridges; diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index 854403d..82a1014 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -9,25 +9,11 @@ abstract class BridgeAbstract implements BridgeInterface { const CACHE_TIMEOUT = 3600; 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 @@ -36,105 +22,6 @@ abstract class BridgeAbstract implements BridgeInterface { return $this->items; } - protected function validateTextValue($value, $pattern = null){ - if(!is_null($pattern)){ - $filteredValue = filter_var($value - , FILTER_VALIDATE_REGEXP - , array('options' => array( - 'regexp' => '/^' . $pattern . '$/' - )) - ); - } else { - $filteredValue = filter_var($value); - } - - if($filteredValue === false) - return null; - - return $filteredValue; - } - - protected function validateNumberValue($value){ - $filteredValue = filter_var($value, FILTER_VALIDATE_INT); - - if($filteredValue === false && !empty($value)) - return null; - - return $filteredValue; - } - - protected function validateCheckboxValue($value){ - $filteredValue = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); - - if(is_null($filteredValue)) - return null; - - return $filteredValue; - } - - protected function validateListValue($value, $expectedValues){ - $filteredValue = filter_var($value); - - if($filteredValue === false) - return null; - - if(!in_array($filteredValue, $expectedValues)){ // Check sub-values? - foreach($expectedValues as $subName => $subValue){ - if(is_array($subValue) && in_array($filteredValue, $subValue)) - return $filteredValue; - } - return null; - } - - return $filteredValue; - } - - protected function validateData(&$data){ - if(!is_array($data)) - return false; - - foreach($data as $name => $value){ - $registered = false; - foreach(static::PARAMETERS as $context => $set){ - if(array_key_exists($name, $set)){ - $registered = true; - if(!isset($set[$name]['type'])){ - $set[$name]['type'] = 'text'; - } - - switch($set[$name]['type']){ - case 'number': - $data[$name] = $this->validateNumberValue($value); - break; - case 'checkbox': - $data[$name] = $this->validateCheckboxValue($value); - break; - case 'list': - $data[$name] = $this->validateListValue($value, $set[$name]['values']); - break; - default: - case 'text': - if(isset($set[$name]['pattern'])){ - $data[$name] = $this->validateTextValue($value, $set[$name]['pattern']); - } else { - $data[$name] = $this->validateTextValue($value); - } - break; - } - - if(is_null($data[$name])){ - echo 'Parameter \'' . $name . '\' is invalid!' . PHP_EOL; - return false; - } - } - } - - if(!$registered) - return false; - } - - return true; - } protected function setInputs(array $inputs, $queriedContext){ // Import and assign all inputs to their context @@ -261,7 +148,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,16 +158,16 @@ abstract class BridgeAbstract implements BridgeInterface { return; } - if(!$this->validateData($inputs)){ - $this->returnClientError('Invalid parameters value(s)'); + if(!validateData($inputs, static::PARAMETERS)){ + 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); @@ -310,157 +197,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 01909a5..b0d975a 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/HTMLUtils.php b/lib/HTMLUtils.php deleted file mode 100644 index 750b15b..0000000 --- a/lib/HTMLUtils.php +++ /dev/null @@ -1,307 +0,0 @@ -' . $bridgeClass::NAME . ''; - $description = $bridgeClass::DESCRIPTION; - - $card = << -

{$name}

-

- {$description} -

- - -CARD; - - // If we don't have any parameter for the bridge, we print a generic form to load it. - if(count($bridgeClass::PARAMETERS) == 0){ - - $card .= HTMLUtils::getFormHeader($bridgeName); - - if($isActive){ - if(defined('PROXY_URL') && PROXY_BYBRIDGE){ - $idArg = 'arg-' - . urlencode($bridgeName) - . '-' - . urlencode('proxyoff') - . '-' - . urlencode('_noproxy'); - - $card .= '' - . PHP_EOL; - - $card .= '
' - . PHP_EOL; - } - - $card .= HTMLUtils::getHelperButtonsFormat($formats); - } else { - $card .= 'Inactive'; - } - - $card .= '' . PHP_EOL; - } - - $hasGlobalParameter = array_key_exists('global', $bridgeClass::PARAMETERS); - - if($hasGlobalParameter){ - $globalParameters = $bridgeClass::PARAMETERS['global']; - } - - foreach($bridgeClass::PARAMETERS as $parameterName => $parameter){ - if(!is_numeric($parameterName) && $parameterName == 'global') - continue; - - if($hasGlobalParameter) - $parameter = array_merge($parameter, $globalParameters); - - if(!is_numeric($parameterName)) - $card .= '
' . $parameterName . '
' . PHP_EOL; - - $card .= HTMLUtils::getFormHeader($bridgeName); - - foreach($parameter as $id => $inputEntry){ - $additionalInfoString = ''; - - if(isset($inputEntry['required']) && $inputEntry['required'] === true) - $additionalInfoString .= ' required'; - - if(isset($inputEntry['pattern'])) - $additionalInfoString .= ' pattern="' . $inputEntry['pattern'] . '"'; - - if(isset($inputEntry['title'])) - $additionalInfoString .= ' title="' . $inputEntry['title'] . '"'; - - if(!isset($inputEntry['exampleValue'])) - $inputEntry['exampleValue'] = ''; - - if(!isset($inputEntry['defaultValue'])) - $inputEntry['defaultValue'] = ''; - - $idArg = 'arg-' - . urlencode($bridgeName) - . '-' - . urlencode($parameterName) - . '-' - . urlencode($id); - - $card .= '' - . PHP_EOL; - - if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text'){ - $card .= '
' - . PHP_EOL; - } elseif($inputEntry['type'] == 'number'){ - $card .= '
' - . PHP_EOL; - } else if($inputEntry['type'] == 'list'){ - $card .= '
'; - } elseif($inputEntry['type'] == 'checkbox'){ - if($inputEntry['defaultValue'] === 'checked') - $card .= '
' - . PHP_EOL; - else - $card .= '
' - . PHP_EOL; - } - } - - if($isActive){ - if(defined('PROXY_URL') && PROXY_BYBRIDGE){ - $idArg = 'arg-' - . urlencode($bridgeName) - . '-' - . urlencode('proxyoff') - . '-' - . urlencode('_noproxy'); - - $card .= '' - . PHP_EOL; - - $card .= '
' - . PHP_EOL; - } - $card .= HTMLUtils::getHelperButtonsFormat($formats); - } else { - $card .= 'Inactive'; - } - $card .= '' . PHP_EOL; - } - - $card .= ''; - $card .= '

' . $bridgeClass::MAINTAINER . '

'; - $card .= ''; - - return $card; - } - - private static function getHelperButtonsFormat($formats){ - $buttons = ''; - foreach($formats as $name){ - $buttons .= '' - . PHP_EOL; - } - - return $buttons; - } - - private static function getFormHeader($bridge){ - return << - - -EOD; - } -} - -class HTMLSanitizer { - - var $tagsToRemove; - var $keptAttributes; - var $onlyKeepText; - - public static $DEFAULT_CLEAR_TAGS = ["script", "iframe", "input", "form"]; - public static $KEPT_ATTRIBUTES = ["title", "href", "src"]; - public static $ONLY_TEXT = []; - - public function __construct($tags_to_remove = null - , $kept_attributes = null - , $only_keep_text = null){ - $this->tagsToRemove = is_null($tags_to_remove) ? HTMLSanitizer::$DEFAULT_CLEAR_TAGS : $tags_to_remove; - $this->keptAttributes = is_null($kept_attributes) ? HTMLSanitizer::$KEPT_ATTRIBUTES : $kept_attributes; - $this->onlyKeepText = is_null($only_keep_text) ? HTMLSanitizer::$ONLY_TEXT : $only_keep_text; - } - - public function sanitize($textToSanitize){ - $htmlContent = str_get_html($textToSanitize); - - foreach($htmlContent->find('*[!b38fd2b1fe7f4747d6b1c1254ccd055e]') as $element){ - if(in_array($element->tag, $this->onlyKeepText)){ - $element->outertext = $element->plaintext; - } elseif(in_array($element->tag, $this->tagsToRemove)){ - $element->outertext = ''; - } else { - foreach($element->getAllAttributes() as $attributeName => $attribute){ - if(!in_array($attributeName, $this->keptAttributes)) - $element->removeAttribute($attributeName); - } - } - } - - return $htmlContent; - } - - public static function defaultImageSrcTo($content, $server){ - foreach($content->find('img') as $image){ - if(is_null(strpos($image->src, "http")) - && is_null(strpos($image->src, "//")) - && is_null(strpos($image->src, "data:"))) - $image->src = $server . $image->src; - } - return $content; - } -} diff --git a/lib/RssBridge.php b/lib/RssBridge.php index cf27114..0052abc 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -15,7 +15,11 @@ require __DIR__ . '/BridgeAbstract.php'; require __DIR__ . '/FeedExpander.php'; require __DIR__ . '/Cache.php'; require __DIR__ . '/CacheAbstract.php'; -require __DIR__ . '/HTMLUtils.php'; + +require __DIR__ . '/validation.php'; +require __DIR__ . '/html.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 0000000..747db5b --- /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 0000000..4a814b1 --- /dev/null +++ b/lib/error.php @@ -0,0 +1,30 @@ +' + . $calling['function'] . ' - ' + . $text; + + error_log($message); +} + +?> diff --git a/lib/html.php b/lib/html.php new file mode 100644 index 0000000..e329102 --- /dev/null +++ b/lib/html.php @@ -0,0 +1,292 @@ +' + . $name + . '' + . PHP_EOL; + } + + return $buttons; + }; + + $getFormHeader = function($bridge){ + return << + + +EOD; + }; + + $bridgeElement = Bridge::create($bridgeName); + $bridgeClass = $bridgeName . 'Bridge'; + + if($bridgeElement == false) + return ""; + + $name = '' . $bridgeClass::NAME . ''; + $description = $bridgeClass::DESCRIPTION; + + $card = << +

{$name}

+

+ {$description} +

+ + +CARD; + + // If we don't have any parameter for the bridge, we print a generic form to load it. + if(count($bridgeClass::PARAMETERS) == 0){ + + $card .= $getFormHeader($bridgeName); + + if($isActive){ + if(defined('PROXY_URL') && PROXY_BYBRIDGE){ + $idArg = 'arg-' + . urlencode($bridgeName) + . '-' + . urlencode('proxyoff') + . '-' + . urlencode('_noproxy'); + + $card .= '' + . PHP_EOL; + + $card .= '
' + . PHP_EOL; + } + + $card .= $getHelperButtonsFormat($formats); + } else { + $card .= 'Inactive'; + } + + $card .= '' . PHP_EOL; + } + + $hasGlobalParameter = array_key_exists('global', $bridgeClass::PARAMETERS); + + if($hasGlobalParameter){ + $globalParameters = $bridgeClass::PARAMETERS['global']; + } + + foreach($bridgeClass::PARAMETERS as $parameterName => $parameter){ + if(!is_numeric($parameterName) && $parameterName == 'global') + continue; + + if($hasGlobalParameter) + $parameter = array_merge($parameter, $globalParameters); + + if(!is_numeric($parameterName)) + $card .= '
' . $parameterName . '
' . PHP_EOL; + + $card .= $getFormHeader($bridgeName); + + foreach($parameter as $id => $inputEntry){ + $additionalInfoString = ''; + + if(isset($inputEntry['required']) && $inputEntry['required'] === true) + $additionalInfoString .= ' required'; + + if(isset($inputEntry['pattern'])) + $additionalInfoString .= ' pattern="' . $inputEntry['pattern'] . '"'; + + if(isset($inputEntry['title'])) + $additionalInfoString .= ' title="' . $inputEntry['title'] . '"'; + + if(!isset($inputEntry['exampleValue'])) + $inputEntry['exampleValue'] = ''; + + if(!isset($inputEntry['defaultValue'])) + $inputEntry['defaultValue'] = ''; + + $idArg = 'arg-' + . urlencode($bridgeName) + . '-' + . urlencode($parameterName) + . '-' + . urlencode($id); + + $card .= '' + . PHP_EOL; + + if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text'){ + $card .= '
' + . PHP_EOL; + } elseif($inputEntry['type'] == 'number'){ + $card .= '
' + . PHP_EOL; + } else if($inputEntry['type'] == 'list'){ + $card .= '
'; + } elseif($inputEntry['type'] == 'checkbox'){ + if($inputEntry['defaultValue'] === 'checked') + $card .= '
' + . PHP_EOL; + else + $card .= '
' + . PHP_EOL; + } + } + + if($isActive){ + if(defined('PROXY_URL') && PROXY_BYBRIDGE){ + $idArg = 'arg-' + . urlencode($bridgeName) + . '-' + . urlencode('proxyoff') + . '-' + . urlencode('_noproxy'); + + $card .= '' + . PHP_EOL; + + $card .= '
' + . PHP_EOL; + } + $card .= $getHelperButtonsFormat($formats); + } else { + $card .= 'Inactive'; + } + $card .= '' . PHP_EOL; + } + + $card .= ''; + $card .= '

' . $bridgeClass::MAINTAINER . '

'; + $card .= ''; + + return $card; +} + +function sanitize($textToSanitize + ,$removedTags=array('script','iframe','input','form') + ,$keptAttributes=array('title','href','src') + ,$keptText=array()){ + $htmlContent = str_get_html($textToSanitize); + + foreach($htmlContent->find('*[!b38fd2b1fe7f4747d6b1c1254ccd055e]') as $element){ + if(in_array($element->tag, $keptText)){ + $element->outertext = $element->plaintext; + } elseif(in_array($element->tag, $removedTags)){ + $element->outertext = ''; + } else { + foreach($element->getAllAttributes() as $attributeName => $attribute){ + if(!in_array($attributeName, $keptAttributes)) + $element->removeAttribute($attributeName); + } + } + } + + return $htmlContent; +} + +function defaultImageSrcTo($content, $server){ + foreach($content->find('img') as $image){ + if(is_null(strpos($image->src, "http")) + && is_null(strpos($image->src, "//")) + && is_null(strpos($image->src, "data:"))) + $image->src = $server . $image->src; + } + return $content; +} + +?> diff --git a/lib/validation.php b/lib/validation.php new file mode 100644 index 0000000..c6c3e27 --- /dev/null +++ b/lib/validation.php @@ -0,0 +1,103 @@ + array( + 'regexp' => '/^' . $pattern . '$/' + )) + ); + } else { + $filteredValue = filter_var($value); + } + + if($filteredValue === false) + return null; + + return $filteredValue; + }; + + $validateNumberValue = function($value){ + $filteredValue = filter_var($value, FILTER_VALIDATE_INT); + + if($filteredValue === false && !empty($value)) + return null; + + return $filteredValue; + }; + + $validateCheckboxValue = function($value){ + $filteredValue = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + + if(is_null($filteredValue)) + return null; + + return $filteredValue; + }; + + $validateListValue = function($value, $expectedValues){ + $filteredValue = filter_var($value); + + if($filteredValue === false) + return null; + + if(!in_array($filteredValue, $expectedValues)){ // Check sub-values? + foreach($expectedValues as $subName => $subValue){ + if(is_array($subValue) && in_array($filteredValue, $subValue)) + return $filteredValue; + } + return null; + } + + return $filteredValue; + }; + + + if(!is_array($data)) + return false; + + foreach($data as $name => $value){ + $registered = false; + foreach($parameters as $context => $set){ + if(array_key_exists($name, $set)){ + $registered = true; + if(!isset($set[$name]['type'])){ + $set[$name]['type'] = 'text'; + } + + switch($set[$name]['type']){ + case 'number': + $data[$name] = $validateNumberValue($value); + break; + case 'checkbox': + $data[$name] = $validateCheckboxValue($value); + break; + case 'list': + $data[$name] = $validateListValue($value, $set[$name]['values']); + break; + default: + case 'text': + if(isset($set[$name]['pattern'])){ + $data[$name] = $validateTextValue($value, $set[$name]['pattern']); + } else { + $data[$name] = $validateTextValue($value); + } + break; + } + + if(is_null($data[$name])){ + echo 'Parameter \'' . $name . '\' is invalid!' . PHP_EOL; + return false; + } + } + } + + if(!$registered) + return false; + } + + return true; +} + +?>