style: Fix coding styles

This commit is contained in:
logmanoriginal 2017-02-14 17:28:07 +01:00
parent d8f5aa3c79
commit ff83410534
26 changed files with 109 additions and 114 deletions

View file

@ -22,11 +22,11 @@ class CopieDoubleBridge extends BridgeAbstract {
$pos = strpos($title, '<a'); $pos = strpos($title, '<a');
$title = substr($title, 0, $pos); $title = substr($title, 0, $pos);
$item['title'] = $title; $item['title'] = $title;
} elseif(strpos($element->innertext, "/images/suivant.gif") === false){ } elseif(strpos($element->innertext, '/images/suivant.gif') === false){
$a = $element->find('a', 0); $a = $element->find('a', 0);
$item['uri'] = self::URI . $a->href; $item['uri'] = self::URI . $a->href;
$content = str_replace('src="/', 'src="/' . self::URI,$element->find("td", 0)->innertext); $content = str_replace('src="/', 'src="/' . self::URI, $element->find("td", 0)->innertext);
$content = str_replace('href="/', 'href="' . self::URI,$content); $content = str_replace('href="/', 'href="' . self::URI, $content);
$item['content'] = $content; $item['content'] = $content;
$this->items[] = $item; $this->items[] = $item;
} }

View file

@ -20,7 +20,7 @@ class CpasbienBridge extends BridgeAbstract {
$html = getSimpleHTMLDOM(self::URI . '/recherche/' . urlencode($request) . '.html') $html = getSimpleHTMLDOM(self::URI . '/recherche/' . urlencode($request) . '.html')
or returnServerError('No results for this query.'); 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' if($episode->getAttribute('class') == 'ligne0'
|| $episode->getAttribute('class') == 'ligne1'){ || $episode->getAttribute('class') == 'ligne1'){

View file

@ -54,7 +54,7 @@ class FourchanBridge extends BridgeAbstract {
} }
$content = $element->find('.postMessage', 0)->innertext; $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'] = '<span id="' . $item['id'] . '">' . $content . '</span>'; $item['content'] = '<span id="' . $item['id'] . '">' . $content . '</span>';
if(isset($item['image'])){ if(isset($item['image'])){

View file

@ -148,7 +148,7 @@ class FuturaSciencesBridge extends FeedExpander {
'<div id="forumcomments', '<div id="forumcomments',
'<div ng-if="active"' '<div ng-if="active"'
) as $div_start) { ) as $div_start) {
$contents = $this->stripRecursiveHTMLSection($contents , 'div', $div_start); $contents = $this->stripRecursiveHTMLSection($contents, 'div', $div_start);
} }
$contents = $this->stripWithDelimiters($contents, '<hr ', '/>'); $contents = $this->stripWithDelimiters($contents, '<hr ', '/>');

View file

@ -52,7 +52,7 @@ class GiphyBridge extends BridgeAbstract {
$title = preg_replace('/\s+/', ' ', $title); $title = preg_replace('/\s+/', ' ', $title);
$title = str_replace('animated GIF', '', $title); $title = str_replace('animated GIF', '', $title);
$title = str_replace($kw, '', $title); $title = str_replace($kw, '', $title);
$title = preg_replace('/\s+/', ' ',$title); $title = preg_replace('/\s+/', ' ', $title);
$title = trim($title); $title = trim($title);
if(strlen($title) <= 0){ if(strlen($title) <= 0){
$title = $item['id']; $title = $item['id'];

View file

@ -19,11 +19,11 @@ class GooglePlusPostBridge extends BridgeAbstract{
public function collectData(){ public function collectData(){
// get content parsed // get content parsed
$html = getSimpleHTMLDOMCached(self::URI . urlencode($this->getInput('username')) . '/posts' $html = getSimpleHTMLDOMCached(self::URI . urlencode($this->getInput('username')) . '/posts',
// force language // force language
, 84600 84600,
, false false,
, stream_context_create(array( stream_context_create(array(
'http' => 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" 'header' => 'Accept-Language: fr,fr-be,fr-fr;q=0.8,en;q=0.4,en-us;q=0.2;*' . "\r\n"
))) )))

View file

@ -43,18 +43,18 @@ class KernelBugTrackerBridge extends BridgeAbstract {
$sorting = $this->getInput('sorting'); $sorting = $this->getInput('sorting');
// We use the print preview page for simplicity // We use the print preview page for simplicity
$html = getSimpleHTMLDOMCached($this->getURI() . '&format=multiple' $html = getSimpleHTMLDOMCached($this->getURI() . '&format=multiple',
, 86400 86400,
, false false,
, null null,
, 0 0,
, null null,
, true true,
, true true,
, DEFAULT_TARGET_CHARSET DEFAULT_TARGET_CHARSET,
, false // Do NOT remove line breaks false, // Do NOT remove line breaks
, DEFAULT_BR_TEXT DEFAULT_BR_TEXT,
, DEFAULT_SPAN_TEXT); DEFAULT_SPAN_TEXT);
if($html === false) if($html === false)
returnServerError('Failed to load page!'); returnServerError('Failed to load page!');

View file

@ -73,7 +73,7 @@ class LWNprevBridge extends BridgeAbstract{
break; break;
case 'GAByline': case 'GAByline':
$text = $h2NextSibling->textContent; $text = $h2NextSibling->textContent;
$item['author'] = substr($text,strpos($text, 'by ')); $item['author'] = substr($text, strpos($text, 'by '));
break; break;
default: default:
$item['author'] = 'LWN'; $item['author'] = 'LWN';

View file

@ -21,7 +21,7 @@ class NextInpactBridge extends FeedExpander {
$text = '<p><em>' $text = '<p><em>'
. $html2->find('span.sub_title', 0)->innertext . $html2->find('span.sub_title', 0)->innertext
. '</em></p><p><img src="' . '</em></p><p><img src="'
. $html2->find('div.container_main_image_article', 0)->find('img.dedicated',0)->src . $html2->find('div.container_main_image_article', 0)->find('img.dedicated', 0)->src
. '" alt="-" /></p><div>' . '" alt="-" /></p><div>'
. $html2->find('div[itemprop=articleBody]', 0)->innertext . $html2->find('div[itemprop=articleBody]', 0)->innertext
. '</div>'; . '</div>';

View file

@ -37,9 +37,9 @@ class RTBFBridge extends BridgeAbstract {
$thumbnailUriLastSrc = end($thumbnailUriSrcSet); $thumbnailUriLastSrc = end($thumbnailUriSrcSet);
$thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0]; $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['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime'));
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>'; $item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $thumbnailUri . '" /></a>';

View file

@ -27,7 +27,7 @@ class ScoopItBridge extends BridgeAbstract {
$item['title'] = preg_replace( $item['title'] = preg_replace(
'~[[:cntrl:]]~', '~[[:cntrl:]]~',
'', '',
$element->find('div.tCustomization_post_title',0)->plaintext $element->find('div.tCustomization_post_title', 0)->plaintext
); );
$item['content'] = preg_replace( $item['content'] = preg_replace(

View file

@ -41,7 +41,7 @@ class ThePirateBayBridge extends BridgeAbstract {
public function collectData(){ public function collectData(){
function parseDateTimestamp($element){ function parseDateTimestamp($element){
$guessedDate = $element->find('font',0)->plaintext; $guessedDate = $element->find('font', 0)->plaintext;
$guessedDate = explode('Uploaded ', $guessedDate)[1]; $guessedDate = explode('Uploaded ', $guessedDate)[1];
$guessedDate = explode(',', $guessedDate)[0]; $guessedDate = explode(',', $guessedDate)[0];
@ -70,7 +70,7 @@ class ThePirateBayBridge extends BridgeAbstract {
); );
} elseif(explode('&nbsp;', $guessedDate)[0] == 'Y-day'){ } elseif(explode('&nbsp;', $guessedDate)[0] == 'Y-day'){
$guessedDate = strptime( $guessedDate = strptime(
explode('&nbsp;',$guessedDate)[1], '%H:%M' explode('&nbsp;', $guessedDate)[1], '%H:%M'
); );
$timestamp = mktime( $timestamp = mktime(

View file

@ -98,13 +98,13 @@ class TheTVDBBridge extends BridgeAbstract {
return $serie['data']->seriesName; return $serie['data']->seriesName;
} }
private function getSeasonEpisodes($token private function getSeasonEpisodes($token,
, $serie_id $serie_id,
, $season $season,
, $seriename $seriename,
, &$episodelist &$episodelist,
, $nbepisodemin $nbepisodemin,
, $page = 1){ $page = 1){
$url = $this->getApiUri() $url = $this->getApiUri()
. 'series/' . 'series/'
. $serie_id . $serie_id

View file

@ -47,7 +47,7 @@ class Torrent9Bridge extends BridgeAbstract {
$html = getSimpleHTMLDOM($page) $html = getSimpleHTMLDOM($page)
or returnServerError('No results for this query.'); 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'){ if($episode->parent->tag == 'tbody'){
$urlepisode = self::URI . $episode->find('a', 0)->getAttribute('href'); $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['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; $this->items[] = $item;
} }

View file

@ -27,7 +27,7 @@ class ViadeoCompanyBridge extends BridgeAbstract {
if($title){ if($title){
$item = array(); $item = array();
$item['uri'] = $link; $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;; $item['content'] = $element->find('p', 0)->innertext;;
$this->items[] = $item; $this->items[] = $item;
$i++; $i++;

View file

@ -43,8 +43,8 @@ class WebfailBridge extends BridgeAbstract {
public function collectData(){ public function collectData(){
$html = getSimpleHTMLDOM($this->getURI() . $this->getInput('type')); $html = getSimpleHTMLDOM($this->getURI() . $this->getInput('type'));
$type = array_search($this->getInput('type') $type = array_search($this->getInput('type'),
, self::PARAMETERS[$this->queriedContext]['type']['values']); self::PARAMETERS[$this->queriedContext]['type']['values']);
switch(strtolower($type)){ switch(strtolower($type)){
case 'facebook': case 'facebook':

View file

@ -29,7 +29,7 @@ class WhydBridge extends BridgeAbstract {
) or returnServerError('No results for this query.'); ) or returnServerError('No results for this query.');
for($j = 0; $j < 5; $j++){ 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( $html = getSimpleHTMLDOM(
self::URI . $html->find('div.user', $j)->find('a', 0)->getAttribute('href') self::URI . $html->find('div.user', $j)->find('a', 0)->getAttribute('href')
) or returnServerError('No results for this query'); ) or returnServerError('No results for this query');

View file

@ -135,10 +135,10 @@ class WikipediaBridge extends BridgeAbstract {
* used to specify a different fallback link than the first * used to specify a different fallback link than the first
* (e.g., -1 for the last) * (e.g., -1 for the last)
*/ */
private function addTodaysFeaturedArticleGeneric($element private function addTodaysFeaturedArticleGeneric($element,
, $fullArticle $fullArticle,
, $anchorText = '...' $anchorText = '...',
, $anchorFallbackIndex = 0){ $anchorFallbackIndex = 0){
// Clean the bottom of the featured article // Clean the bottom of the featured article
if ($element->find('div', -1)) if ($element->find('div', -1))
$element->find('div', -1)->outertext = ''; $element->find('div', -1)->outertext = '';

View file

@ -270,7 +270,7 @@ class ZDNetBridge extends BridgeAbstract {
'<div id="sharethrough', '<div id="sharethrough',
'<div id="inpage-video' '<div id="inpage-video'
) as $div_start){ ) as $div_start){
$contents = stripRecursiveHtmlSection($contents , 'div', $div_start); $contents = stripRecursiveHtmlSection($contents, 'div', $div_start);
} }
$contents = stripWithDelimiters($contents, '<script', '</script>'); $contents = stripWithDelimiters($contents, '<script', '</script>');
$contents = stripWithDelimiters($contents, '<meta itemprop="image"', '>'); $contents = stripWithDelimiters($contents, '<meta itemprop="image"', '>');

View file

@ -136,7 +136,7 @@ try {
$noproxy = filter_input(INPUT_GET, '_noproxy', FILTER_VALIDATE_BOOLEAN); $noproxy = filter_input(INPUT_GET, '_noproxy', FILTER_VALIDATE_BOOLEAN);
if(defined('PROXY_URL') && PROXY_BYBRIDGE && $noproxy){ if(defined('PROXY_URL') && PROXY_BYBRIDGE && $noproxy){
define('NOPROXY',true); define('NOPROXY', true);
} }
$params = $_GET; $params = $_GET;

View file

@ -149,7 +149,7 @@ abstract class FeedExpander extends BridgeAbstract {
if(isset($feedItem->guid)){ if(isset($feedItem->guid)){
foreach($feedItem->guid->attributes() as $attribute => $value){ foreach($feedItem->guid->attributes() as $attribute => $value){
if($attribute === 'isPermaLink' 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; $item['uri'] = (string)$feedItem->guid;
break; break;
} }

View file

@ -89,9 +89,9 @@ abstract class FormatAbstract implements FormatInterface {
*/ */
protected function sanitizeHtml($html) protected function sanitizeHtml($html)
{ {
$html = str_replace('<script','<&zwnj;script',$html); // Disable scripts, but leave them visible. $html = str_replace('<script', '<&zwnj;script', $html); // Disable scripts, but leave them visible.
$html = str_replace('<iframe','<&zwnj;iframe',$html); $html = str_replace('<iframe', '<&zwnj;iframe', $html);
$html = str_replace('<link','<&zwnj;link',$html); $html = str_replace('<link', '<&zwnj;link', $html);
// We leave alone object and embed so that videos can play in RSS readers. // We leave alone object and embed so that videos can play in RSS readers.
return $html; return $html;
} }

View file

@ -21,12 +21,12 @@ require __DIR__ . '/error.php';
require __DIR__ . '/contents.php'; require __DIR__ . '/contents.php';
$vendorLibSimpleHtmlDom = __DIR__ . PATH_VENDOR . '/simplehtmldom/simple_html_dom.php'; $vendorLibSimpleHtmlDom = __DIR__ . PATH_VENDOR . '/simplehtmldom/simple_html_dom.php';
if( !file_exists($vendorLibSimpleHtmlDom) ){ if(!file_exists($vendorLibSimpleHtmlDom)){
throw new \HttpException('"PHP Simple HTML DOM Parser" library is missing. throw new \HttpException('"PHP Simple HTML DOM Parser" library is missing.
Get it from http://simplehtmldom.sourceforge.net and place the script "simple_html_dom.php" in ' Get it from http://simplehtmldom.sourceforge.net and place the script "simple_html_dom.php" in '
. substr(PATH_VENDOR,4) . substr(PATH_VENDOR, 4)
. '/simplehtmldom/' . '/simplehtmldom/',
, 500); 500);
} }
require_once $vendorLibSimpleHtmlDom; require_once $vendorLibSimpleHtmlDom;

View file

@ -1,10 +1,9 @@
<?php <?php
function getContents($url function getContents($url,
, $use_include_path = false $use_include_path = false,
, $context = null $context = null,
, $offset = 0 $offset = 0,
, $maxlen = null $maxlen = null){
){
$contextOptions = array( $contextOptions = array(
'http' => array( 'http' => array(
'user_agent' => ini_get('user_agent'), 'user_agent' => ini_get('user_agent'),
@ -61,26 +60,25 @@ function getContents($url
return $content; return $content;
} }
function getSimpleHTMLDOM($url function getSimpleHTMLDOM($url,
, $use_include_path = false $use_include_path = false,
, $context = null $context = null,
, $offset = 0 $offset = 0,
, $maxLen = null $maxLen = null,
, $lowercase = true $lowercase = true,
, $forceTagsClosed = true $forceTagsClosed = true,
, $target_charset = DEFAULT_TARGET_CHARSET $target_charset = DEFAULT_TARGET_CHARSET,
, $stripRN = true $stripRN = true,
, $defaultBRText = DEFAULT_BR_TEXT $defaultBRText = DEFAULT_BR_TEXT,
, $defaultSpanText = DEFAULT_SPAN_TEXT $defaultSpanText = DEFAULT_SPAN_TEXT){
){
$content = getContents($url, $use_include_path, $context, $offset, $maxLen); $content = getContents($url, $use_include_path, $context, $offset, $maxLen);
return str_get_html($content return str_get_html($content,
, $lowercase $lowercase,
, $forceTagsClosed $forceTagsClosed,
, $target_charset $target_charset,
, $stripRN $stripRN,
, $defaultBRText $defaultBRText,
, $defaultSpanText); $defaultSpanText);
} }
/** /**
@ -89,19 +87,18 @@ function getSimpleHTMLDOM($url
* @param duration duration of the cache file in seconds (default: 24h/86400s) * @param duration duration of the cache file in seconds (default: 24h/86400s)
* @return content of the file as string * @return content of the file as string
*/ */
function getSimpleHTMLDOMCached($url function getSimpleHTMLDOMCached($url,
, $duration = 86400 $duration = 86400,
, $use_include_path = false $use_include_path = false,
, $context = null $context = null,
, $offset = 0 $offset = 0,
, $maxLen = null $maxLen = null,
, $lowercase = true $lowercase = true,
, $forceTagsClosed = true $forceTagsClosed = true,
, $target_charset = DEFAULT_TARGET_CHARSET $target_charset = DEFAULT_TARGET_CHARSET,
, $stripRN = true $stripRN = true,
, $defaultBRText = DEFAULT_BR_TEXT $defaultBRText = DEFAULT_BR_TEXT,
, $defaultSpanText = DEFAULT_SPAN_TEXT $defaultSpanText = DEFAULT_SPAN_TEXT){
){
debugMessage('Caching url ' . $url . ', duration ' . $duration); debugMessage('Caching url ' . $url . ', duration ' . $duration);
// Initialize cache // Initialize cache
@ -125,13 +122,11 @@ function getSimpleHTMLDOMCached($url
} }
} }
return str_get_html($content return str_get_html($content,
, $lowercase $lowercase,
, $forceTagsClosed $forceTagsClosed,
, $target_charset $target_charset,
, $stripRN $stripRN,
, $defaultBRText $defaultBRText,
, $defaultSpanText); $defaultSpanText);
} }
?>

View file

@ -257,10 +257,10 @@ CARD;
return $card; return $card;
} }
function sanitize($textToSanitize function sanitize($textToSanitize,
,$removedTags=array('script','iframe','input','form') $removedTags = array('script', 'iframe', 'input', 'form'),
,$keptAttributes=array('title','href','src') $keptAttributes = array('title', 'href', 'src'),
,$keptText=array()){ $keptText = array()){
$htmlContent = str_get_html($textToSanitize); $htmlContent = str_get_html($textToSanitize);
foreach($htmlContent->find('*[!b38fd2b1fe7f4747d6b1c1254ccd055e]') as $element){ foreach($htmlContent->find('*[!b38fd2b1fe7f4747d6b1c1254ccd055e]') as $element){

View file

@ -1,13 +1,13 @@
<?php <?php
function validateData(&$data,$parameters){ function validateData(&$data, $parameters){
$validateTextValue = function($value, $pattern = null){ $validateTextValue = function($value, $pattern = null){
if(!is_null($pattern)){ if(!is_null($pattern)){
$filteredValue = filter_var($value $filteredValue = filter_var($value,
, FILTER_VALIDATE_REGEXP FILTER_VALIDATE_REGEXP,
, array('options' => array( array('options' => array(
'regexp' => '/^' . $pattern . '$/' 'regexp' => '/^' . $pattern . '$/'
)) )
); ));
} else { } else {
$filteredValue = filter_var($value); $filteredValue = filter_var($value);
} }