From ff834105345b9c2120ce9ed8f3292e7e00a3c6fe Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Tue, 14 Feb 2017 17:28:07 +0100 Subject: [PATCH] style: Fix coding styles --- bridges/CopieDoubleBridge.php | 6 +- bridges/CpasbienBridge.php | 2 +- bridges/FourchanBridge.php | 2 +- bridges/FuturaSciencesBridge.php | 2 +- bridges/GiphyBridge.php | 2 +- bridges/GooglePlusPostBridge.php | 8 +-- bridges/KernelBugTrackerBridge.php | 24 ++++---- bridges/LWNprevBridge.php | 2 +- bridges/NextInpactBridge.php | 2 +- bridges/RTBFBridge.php | 4 +- bridges/ScoopItBridge.php | 2 +- bridges/ThePirateBayBridge.php | 4 +- bridges/TheTVDBBridge.php | 14 ++--- bridges/Torrent9Bridge.php | 4 +- bridges/ViadeoCompanyBridge.php | 2 +- bridges/WebfailBridge.php | 4 +- bridges/WhydBridge.php | 2 +- bridges/WikipediaBridge.php | 8 +-- bridges/ZDNetBridge.php | 2 +- index.php | 2 +- lib/FeedExpander.php | 2 +- lib/FormatAbstract.php | 6 +- lib/RssBridge.php | 8 +-- lib/contents.php | 89 ++++++++++++++---------------- lib/html.php | 8 +-- lib/validation.php | 12 ++-- 26 files changed, 109 insertions(+), 114 deletions(-) diff --git a/bridges/CopieDoubleBridge.php b/bridges/CopieDoubleBridge.php index 63ec5eb..af805f2 100644 --- a/bridges/CopieDoubleBridge.php +++ b/bridges/CopieDoubleBridge.php @@ -22,11 +22,11 @@ class CopieDoubleBridge extends BridgeAbstract { $pos = strpos($title, 'innertext, "/images/suivant.gif") === false){ + } elseif(strpos($element->innertext, '/images/suivant.gif') === false){ $a = $element->find('a', 0); $item['uri'] = self::URI . $a->href; - $content = str_replace('src="/', 'src="/' . self::URI,$element->find("td", 0)->innertext); - $content = str_replace('href="/', 'href="' . self::URI,$content); + $content = str_replace('src="/', 'src="/' . self::URI, $element->find("td", 0)->innertext); + $content = str_replace('href="/', 'href="' . self::URI, $content); $item['content'] = $content; $this->items[] = $item; } diff --git a/bridges/CpasbienBridge.php b/bridges/CpasbienBridge.php index aced628..0773d11 100644 --- a/bridges/CpasbienBridge.php +++ b/bridges/CpasbienBridge.php @@ -20,7 +20,7 @@ class CpasbienBridge extends BridgeAbstract { $html = getSimpleHTMLDOM(self::URI . '/recherche/' . urlencode($request) . '.html') or returnServerError('No results for this query.'); - foreach($html->find('#gauche',0)->find('div') as $episode){ + foreach($html->find('#gauche', 0)->find('div') as $episode){ if($episode->getAttribute('class') == 'ligne0' || $episode->getAttribute('class') == 'ligne1'){ diff --git a/bridges/FourchanBridge.php b/bridges/FourchanBridge.php index ab9cbee..7a83142 100644 --- a/bridges/FourchanBridge.php +++ b/bridges/FourchanBridge.php @@ -54,7 +54,7 @@ class FourchanBridge extends BridgeAbstract { } $content = $element->find('.postMessage', 0)->innertext; - $content = str_replace('href="#p','href="' . $this->getURI() . '#p', $content); + $content = str_replace('href="#p', 'href="' . $this->getURI() . '#p', $content); $item['content'] = '' . $content . ''; if(isset($item['image'])){ diff --git a/bridges/FuturaSciencesBridge.php b/bridges/FuturaSciencesBridge.php index 4e8f0eb..e41e518 100644 --- a/bridges/FuturaSciencesBridge.php +++ b/bridges/FuturaSciencesBridge.php @@ -148,7 +148,7 @@ class FuturaSciencesBridge extends FeedExpander { '
stripRecursiveHTMLSection($contents , 'div', $div_start); + $contents = $this->stripRecursiveHTMLSection($contents, 'div', $div_start); } $contents = $this->stripWithDelimiters($contents, '
'); diff --git a/bridges/GiphyBridge.php b/bridges/GiphyBridge.php index 182d2a3..e8b0dc1 100644 --- a/bridges/GiphyBridge.php +++ b/bridges/GiphyBridge.php @@ -52,7 +52,7 @@ class GiphyBridge extends BridgeAbstract { $title = preg_replace('/\s+/', ' ', $title); $title = str_replace('animated GIF', '', $title); $title = str_replace($kw, '', $title); - $title = preg_replace('/\s+/', ' ',$title); + $title = preg_replace('/\s+/', ' ', $title); $title = trim($title); if(strlen($title) <= 0){ $title = $item['id']; diff --git a/bridges/GooglePlusPostBridge.php b/bridges/GooglePlusPostBridge.php index 5d4680e..1ea5e20 100644 --- a/bridges/GooglePlusPostBridge.php +++ b/bridges/GooglePlusPostBridge.php @@ -19,11 +19,11 @@ class GooglePlusPostBridge extends BridgeAbstract{ public function collectData(){ // get content parsed - $html = getSimpleHTMLDOMCached(self::URI . urlencode($this->getInput('username')) . '/posts' + $html = getSimpleHTMLDOMCached(self::URI . urlencode($this->getInput('username')) . '/posts', // force language - , 84600 - , false - , stream_context_create(array( + 84600, + 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" ))) diff --git a/bridges/KernelBugTrackerBridge.php b/bridges/KernelBugTrackerBridge.php index d8218ab..6494a21 100644 --- a/bridges/KernelBugTrackerBridge.php +++ b/bridges/KernelBugTrackerBridge.php @@ -43,18 +43,18 @@ class KernelBugTrackerBridge extends BridgeAbstract { $sorting = $this->getInput('sorting'); // We use the print preview page for simplicity - $html = getSimpleHTMLDOMCached($this->getURI() . '&format=multiple' - , 86400 - , false - , null - , 0 - , null - , true - , true - , DEFAULT_TARGET_CHARSET - , false // Do NOT remove line breaks - , DEFAULT_BR_TEXT - , DEFAULT_SPAN_TEXT); + $html = getSimpleHTMLDOMCached($this->getURI() . '&format=multiple', + 86400, + false, + null, + 0, + null, + true, + true, + DEFAULT_TARGET_CHARSET, + false, // Do NOT remove line breaks + DEFAULT_BR_TEXT, + DEFAULT_SPAN_TEXT); if($html === false) returnServerError('Failed to load page!'); diff --git a/bridges/LWNprevBridge.php b/bridges/LWNprevBridge.php index c0ad410..78ef3ed 100644 --- a/bridges/LWNprevBridge.php +++ b/bridges/LWNprevBridge.php @@ -73,7 +73,7 @@ class LWNprevBridge extends BridgeAbstract{ break; case 'GAByline': $text = $h2NextSibling->textContent; - $item['author'] = substr($text,strpos($text, 'by ')); + $item['author'] = substr($text, strpos($text, 'by ')); break; default: $item['author'] = 'LWN'; diff --git a/bridges/NextInpactBridge.php b/bridges/NextInpactBridge.php index 0e09828..bf1f8dc 100644 --- a/bridges/NextInpactBridge.php +++ b/bridges/NextInpactBridge.php @@ -21,7 +21,7 @@ class NextInpactBridge extends FeedExpander { $text = '

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

-

' . $html2->find('div[itemprop=articleBody]', 0)->innertext . '
'; diff --git a/bridges/RTBFBridge.php b/bridges/RTBFBridge.php index dda01f5..9303908 100644 --- a/bridges/RTBFBridge.php +++ b/bridges/RTBFBridge.php @@ -37,9 +37,9 @@ class RTBFBridge extends BridgeAbstract { $thumbnailUriLastSrc = end($thumbnailUriSrcSet); $thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0]; - $item['title'] = trim($element->find('h3',0)->plaintext) + $item['title'] = trim($element->find('h3', 0)->plaintext) . ' - ' - . trim($element->find('h4',0)->plaintext); + . trim($element->find('h4', 0)->plaintext); $item['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime')); $item['content'] = ''; diff --git a/bridges/ScoopItBridge.php b/bridges/ScoopItBridge.php index 462e7e5..21c7aa1 100644 --- a/bridges/ScoopItBridge.php +++ b/bridges/ScoopItBridge.php @@ -27,7 +27,7 @@ class ScoopItBridge extends BridgeAbstract { $item['title'] = preg_replace( '~[[:cntrl:]]~', '', - $element->find('div.tCustomization_post_title',0)->plaintext + $element->find('div.tCustomization_post_title', 0)->plaintext ); $item['content'] = preg_replace( diff --git a/bridges/ThePirateBayBridge.php b/bridges/ThePirateBayBridge.php index f0e2685..2411020 100644 --- a/bridges/ThePirateBayBridge.php +++ b/bridges/ThePirateBayBridge.php @@ -41,7 +41,7 @@ class ThePirateBayBridge extends BridgeAbstract { public function collectData(){ function parseDateTimestamp($element){ - $guessedDate = $element->find('font',0)->plaintext; + $guessedDate = $element->find('font', 0)->plaintext; $guessedDate = explode('Uploaded ', $guessedDate)[1]; $guessedDate = explode(',', $guessedDate)[0]; @@ -70,7 +70,7 @@ class ThePirateBayBridge extends BridgeAbstract { ); } elseif(explode(' ', $guessedDate)[0] == 'Y-day'){ $guessedDate = strptime( - explode(' ',$guessedDate)[1], '%H:%M' + explode(' ', $guessedDate)[1], '%H:%M' ); $timestamp = mktime( diff --git a/bridges/TheTVDBBridge.php b/bridges/TheTVDBBridge.php index 551d055..1804bc8 100644 --- a/bridges/TheTVDBBridge.php +++ b/bridges/TheTVDBBridge.php @@ -98,13 +98,13 @@ class TheTVDBBridge extends BridgeAbstract { return $serie['data']->seriesName; } - private function getSeasonEpisodes($token - , $serie_id - , $season - , $seriename - , &$episodelist - , $nbepisodemin - , $page = 1){ + private function getSeasonEpisodes($token, + $serie_id, + $season, + $seriename, + &$episodelist, + $nbepisodemin, + $page = 1){ $url = $this->getApiUri() . 'series/' . $serie_id diff --git a/bridges/Torrent9Bridge.php b/bridges/Torrent9Bridge.php index a360ae1..fe0a944 100644 --- a/bridges/Torrent9Bridge.php +++ b/bridges/Torrent9Bridge.php @@ -47,7 +47,7 @@ class Torrent9Bridge extends BridgeAbstract { $html = getSimpleHTMLDOM($page) or returnServerError('No results for this query.'); - foreach($html->find('table',0)->find('tr') as $episode){ + foreach($html->find('table', 0)->find('tr') as $episode){ if($episode->parent->tag == 'tbody'){ $urlepisode = self::URI . $episode->find('a', 0)->getAttribute('href'); @@ -72,7 +72,7 @@ class Torrent9Bridge extends BridgeAbstract { } $item['id'] = $episode->find('a', 0)->getAttribute('href'); - $item['uri'] = self::URI . $htmlepisode->find('.download',0)->getAttribute('href'); + $item['uri'] = self::URI . $htmlepisode->find('.download', 0)->getAttribute('href'); $this->items[] = $item; } diff --git a/bridges/ViadeoCompanyBridge.php b/bridges/ViadeoCompanyBridge.php index 425133d..127c64a 100644 --- a/bridges/ViadeoCompanyBridge.php +++ b/bridges/ViadeoCompanyBridge.php @@ -27,7 +27,7 @@ class ViadeoCompanyBridge extends BridgeAbstract { if($title){ $item = array(); $item['uri'] = $link; - $item['title'] = mb_substr($element->find('p', 0)->innertext, 0 , 100); + $item['title'] = mb_substr($element->find('p', 0)->innertext, 0, 100); $item['content'] = $element->find('p', 0)->innertext;; $this->items[] = $item; $i++; diff --git a/bridges/WebfailBridge.php b/bridges/WebfailBridge.php index eded93b..55a5a68 100644 --- a/bridges/WebfailBridge.php +++ b/bridges/WebfailBridge.php @@ -43,8 +43,8 @@ class WebfailBridge extends BridgeAbstract { public function collectData(){ $html = getSimpleHTMLDOM($this->getURI() . $this->getInput('type')); - $type = array_search($this->getInput('type') - , self::PARAMETERS[$this->queriedContext]['type']['values']); + $type = array_search($this->getInput('type'), + self::PARAMETERS[$this->queriedContext]['type']['values']); switch(strtolower($type)){ case 'facebook': diff --git a/bridges/WhydBridge.php b/bridges/WhydBridge.php index 919ab38..be85915 100644 --- a/bridges/WhydBridge.php +++ b/bridges/WhydBridge.php @@ -29,7 +29,7 @@ class WhydBridge extends BridgeAbstract { ) 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'))){ + if(strtolower($html->find('div.user', $j)->find('a', 0)->plaintext) == strtolower($this->getInput('u'))){ $html = getSimpleHTMLDOM( self::URI . $html->find('div.user', $j)->find('a', 0)->getAttribute('href') ) or returnServerError('No results for this query'); diff --git a/bridges/WikipediaBridge.php b/bridges/WikipediaBridge.php index a899184..7bda015 100644 --- a/bridges/WikipediaBridge.php +++ b/bridges/WikipediaBridge.php @@ -135,10 +135,10 @@ class WikipediaBridge extends BridgeAbstract { * used to specify a different fallback link than the first * (e.g., -1 for the last) */ - private function addTodaysFeaturedArticleGeneric($element - , $fullArticle - , $anchorText = '...' - , $anchorFallbackIndex = 0){ + private function addTodaysFeaturedArticleGeneric($element, + $fullArticle, + $anchorText = '...', + $anchorFallbackIndex = 0){ // Clean the bottom of the featured article if ($element->find('div', -1)) $element->find('div', -1)->outertext = ''; diff --git a/bridges/ZDNetBridge.php b/bridges/ZDNetBridge.php index fa81d8e..5fb7e30 100644 --- a/bridges/ZDNetBridge.php +++ b/bridges/ZDNetBridge.php @@ -270,7 +270,7 @@ class ZDNetBridge extends BridgeAbstract { '
'); $contents = stripWithDelimiters($contents, ''); diff --git a/index.php b/index.php index b61a02a..80ca78c 100644 --- a/index.php +++ b/index.php @@ -136,7 +136,7 @@ try { $noproxy = filter_input(INPUT_GET, '_noproxy', FILTER_VALIDATE_BOOLEAN); if(defined('PROXY_URL') && PROXY_BYBRIDGE && $noproxy){ - define('NOPROXY',true); + define('NOPROXY', true); } $params = $_GET; diff --git a/lib/FeedExpander.php b/lib/FeedExpander.php index df73306..c66ca72 100644 --- a/lib/FeedExpander.php +++ b/lib/FeedExpander.php @@ -149,7 +149,7 @@ abstract class FeedExpander extends BridgeAbstract { if(isset($feedItem->guid)){ foreach($feedItem->guid->attributes() as $attribute => $value){ if($attribute === 'isPermaLink' - && ($value === 'true' || filter_var($feedItem->guid,FILTER_VALIDATE_URL))){ + && ($value === 'true' || filter_var($feedItem->guid, FILTER_VALIDATE_URL))){ $item['uri'] = (string)$feedItem->guid; break; } diff --git a/lib/FormatAbstract.php b/lib/FormatAbstract.php index c359026..08be123 100644 --- a/lib/FormatAbstract.php +++ b/lib/FormatAbstract.php @@ -89,9 +89,9 @@ abstract class FormatAbstract implements FormatInterface { */ protected function sanitizeHtml($html) { - $html = str_replace(' array( 'user_agent' => ini_get('user_agent'), @@ -61,26 +60,25 @@ function getContents($url 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 -){ +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); + return str_get_html($content, + $lowercase, + $forceTagsClosed, + $target_charset, + $stripRN, + $defaultBRText, + $defaultSpanText); } /** @@ -89,19 +87,18 @@ function getSimpleHTMLDOM($url * @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 -){ +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); // Initialize cache @@ -125,13 +122,11 @@ function getSimpleHTMLDOMCached($url } } - return str_get_html($content - , $lowercase - , $forceTagsClosed - , $target_charset - , $stripRN - , $defaultBRText - , $defaultSpanText); + return str_get_html($content, + $lowercase, + $forceTagsClosed, + $target_charset, + $stripRN, + $defaultBRText, + $defaultSpanText); } - -?> diff --git a/lib/html.php b/lib/html.php index e329102..b13818b 100644 --- a/lib/html.php +++ b/lib/html.php @@ -257,10 +257,10 @@ CARD; return $card; } -function sanitize($textToSanitize - ,$removedTags=array('script','iframe','input','form') - ,$keptAttributes=array('title','href','src') - ,$keptText=array()){ +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){ diff --git a/lib/validation.php b/lib/validation.php index ccc4561..037bc69 100644 --- a/lib/validation.php +++ b/lib/validation.php @@ -1,13 +1,13 @@ array( + $filteredValue = filter_var($value, + FILTER_VALIDATE_REGEXP, + array('options' => array( 'regexp' => '/^' . $pattern . '$/' - )) - ); + ) + )); } else { $filteredValue = filter_var($value); }