Skip to content

Commit

Permalink
[phpcs] enforce single quotes (RSS-Bridge#732)
Browse files Browse the repository at this point in the history
* [phpcs] Add rule to enforce single quoted strings
  • Loading branch information
logmanoriginal authored and teromene committed Jun 29, 2018
1 parent 5ea79ac commit 193ca87
Show file tree
Hide file tree
Showing 43 changed files with 283 additions and 279 deletions.
2 changes: 1 addition & 1 deletion bridges/BlaguesDeMerdeBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function collectData(){
$item['content'] = trim($element->find('div.joke_text_contener', 0)->innertext);
$uri = $temp[2]->href;
$item['uri'] = $uri;
$item['title'] = substr($uri, (strrpos($uri, "/") + 1));
$item['title'] = substr($uri, (strrpos($uri, '/') + 1));
$date = $element->find('li.bdm_date', 0)->innertext;
$time = mktime(0, 0, 0, substr($date, 3, 2), substr($date, 0, 2), substr($date, 6, 4));
$item['timestamp'] = $time;
Expand Down
6 changes: 3 additions & 3 deletions bridges/CADBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ private function extractCADContent($url) {
if($html3 == false)
return 'Daily comic not released yet';

$htmlpart = explode("/", $url);
$htmlpart = explode('/', $url);

switch ($htmlpart[3]) {
case 'cad':
preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/cad-\S*png/", $html3, $url2);
preg_match_all('/http:\/\/cdn2\.cad-comic\.com\/comics\/cad-\S*png/', $html3, $url2);
break;
case 'sillies':
preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/sillies-\S*gif/", $html3, $url2);
preg_match_all('/http:\/\/cdn2\.cad-comic\.com\/comics\/sillies-\S*gif/', $html3, $url2);
break;
default:
return 'Daily comic not released yet';
Expand Down
2 changes: 1 addition & 1 deletion bridges/CopieDoubleBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function collectData(){
} 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('src="/', 'src="/' . self::URI, $element->find('td', 0)->innertext);
$content = str_replace('href="/', 'href="' . self::URI, $content);
$item['content'] = $content;
$this->items[] = $item;
Expand Down
2 changes: 1 addition & 1 deletion bridges/CourrierInternationalBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function collectData(){
$html = getSimpleHTMLDOM(self::URI)
or returnServerError('Error.');

$element = $html->find("article");
$element = $html->find('article');
$article_count = 1;

foreach($element as $article) {
Expand Down
2 changes: 1 addition & 1 deletion bridges/CpasbienBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CpasbienBridge extends BridgeAbstract {
));

public function collectData(){
$request = str_replace(" ", "-", trim($this->getInput('q')));
$request = str_replace(' ', '-', trim($this->getInput('q')));
$html = getSimpleHTMLDOM(self::URI . '/recherche/' . urlencode($request) . '.html')
or returnServerError('No results for this query.');

Expand Down
2 changes: 1 addition & 1 deletion bridges/DanbooruBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected function getItemFromElement($element){

$item = array();
$item['uri'] = $element->find('a', 0)->href;
$item['postid'] = (int)preg_replace("/[^0-9]/", '', $element->getAttribute(static::IDATTRIBUTE));
$item['postid'] = (int)preg_replace('/[^0-9]/', '', $element->getAttribute(static::IDATTRIBUTE));
$item['timestamp'] = time();
$thumbnailUri = $element->find('img', 0)->src;
$item['tags'] = $this->getTags($element);
Expand Down
10 changes: 5 additions & 5 deletions bridges/DemoBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class DemoBridge extends BridgeAbstract {
public function collectData(){

$item = array();
$item['author'] = "Me!";
$item['title'] = "Test";
$item['content'] = "Awesome content !";
$item['id'] = "Lalala";
$item['uri'] = "http://example.com/test";
$item['author'] = 'Me!';
$item['title'] = 'Test';
$item['content'] = 'Awesome content !';
$item['id'] = 'Lalala';
$item['uri'] = 'http://example.com/test';

$this->items[] = $item;
}
Expand Down
68 changes: 34 additions & 34 deletions bridges/DiscogsBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,59 +42,59 @@ public function collectData() {
if(!empty($this->getInput('artistid')) || !empty($this->getInput('labelid'))) {

if(!empty($this->getInput('artistid'))) {
$data = getContents("https://api.discogs.com/artists/"
$data = getContents('https://api.discogs.com/artists/'
. $this->getInput('artistid')
. "/releases?sort=year&sort_order=desc")
or returnServerError("Unable to query discogs !");
. '/releases?sort=year&sort_order=desc')
or returnServerError('Unable to query discogs !');
} elseif(!empty($this->getInput('labelid'))) {
$data = getContents("https://api.discogs.com/labels/"
$data = getContents('https://api.discogs.com/labels/'
. $this->getInput('labelid')
. "/releases?sort=year&sort_order=desc")
or returnServerError("Unable to query discogs !");
. '/releases?sort=year&sort_order=desc')
or returnServerError('Unable to query discogs !');
}

$jsonData = json_decode($data, true);
foreach($jsonData["releases"] as $release) {
foreach($jsonData['releases'] as $release) {

$item = array();
$item["author"] = $release["artist"];
$item["title"] = $release["title"];
$item["id"] = $release["id"];
$resId = array_key_exists("main_release", $release) ? $release["main_release"] : $release["id"];
$item["uri"] = self::URI . $this->getInput('artistid') . "/release/" . $resId;
$item["timestamp"] = DateTime::createFromFormat("Y", $release["year"])->getTimestamp();
$item["content"] = $item["author"] . " - " . $item["title"];
$item['author'] = $release['artist'];
$item['title'] = $release['title'];
$item['id'] = $release['id'];
$resId = array_key_exists('main_release', $release) ? $release['main_release'] : $release['id'];
$item['uri'] = self::URI . $this->getInput('artistid') . '/release/' . $resId;
$item['timestamp'] = DateTime::createFromFormat('Y', $release['year'])->getTimestamp();
$item['content'] = $item['author'] . ' - ' . $item['title'];
$this->items[] = $item;
}

} elseif(!empty($this->getInput("username_wantlist")) || !empty($this->getInput("username_folder"))) {
} elseif(!empty($this->getInput('username_wantlist')) || !empty($this->getInput('username_folder'))) {

if(!empty($this->getInput("username_wantlist"))) {
$data = getContents("https://api.discogs.com/users/"
if(!empty($this->getInput('username_wantlist'))) {
$data = getContents('https://api.discogs.com/users/'
. $this->getInput('username_wantlist')
. "/wants?sort=added&sort_order=desc")
or returnServerError("Unable to query discogs !");
$jsonData = json_decode($data, true)["wants"];
. '/wants?sort=added&sort_order=desc')
or returnServerError('Unable to query discogs !');
$jsonData = json_decode($data, true)['wants'];

} elseif(!empty($this->getInput("username_folder"))) {
$data = getContents("https://api.discogs.com/users/"
} elseif(!empty($this->getInput('username_folder'))) {
$data = getContents('https://api.discogs.com/users/'
. $this->getInput('username_folder')
. "/collection/folders/"
. $this->getInput("folderid")
."/releases?sort=added&sort_order=desc")
or returnServerError("Unable to query discogs !");
$jsonData = json_decode($data, true)["releases"];
. '/collection/folders/'
. $this->getInput('folderid')
.'/releases?sort=added&sort_order=desc')
or returnServerError('Unable to query discogs !');
$jsonData = json_decode($data, true)['releases'];
}
foreach($jsonData as $element) {

$infos = $element["basic_information"];
$infos = $element['basic_information'];
$item = array();
$item["title"] = $infos["title"];
$item["author"] = $infos["artists"][0]["name"];
$item["id"] = $infos["artists"][0]["id"];
$item["uri"] = self::URI . $infos["artists"][0]["id"] . "/release/" . $infos["id"];
$item["timestamp"] = strtotime($element["date_added"]);
$item["content"] = $item["author"] . " - " . $item["title"];
$item['title'] = $infos['title'];
$item['author'] = $infos['artists'][0]['name'];
$item['id'] = $infos['artists'][0]['id'];
$item['uri'] = self::URI . $infos['artists'][0]['id'] . '/release/' . $infos['id'];
$item['timestamp'] = strtotime($element['date_added']);
$item['content'] = $item['author'] . ' - ' . $item['title'];
$this->items[] = $item;

}
Expand Down
4 changes: 2 additions & 2 deletions bridges/ETTVBridge.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class ETTVBridge extends BridgeAbstract {

const MAINTAINER = "GregThib";
const MAINTAINER = 'GregThib';
const NAME = 'ETTV';
const URI = 'https://www.ettv.tv/';
const DESCRIPTION = 'Returns list of 20 latest torrents for a specific search.';
Expand Down Expand Up @@ -113,7 +113,7 @@ public function collectData(){
$entry = $element->find('td', 1)->find('a', 0);

// retrieve result page to get more details
$link = rtrim(self::URI, "/") . $entry->href;
$link = rtrim(self::URI, '/') . $entry->href;
$page = getSimpleHTMLDOM($link)
or returnServerError('Could not request page ' . $link);

Expand Down
10 changes: 5 additions & 5 deletions bridges/EZTVBridge.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
class EZTVBridge extends BridgeAbstract {

const MAINTAINER = "alexAubin";
const MAINTAINER = 'alexAubin';
const NAME = 'EZTV';
const URI = 'https://eztv.ch/';
const DESCRIPTION = 'Returns list of *recent* torrents for a specific show
Expand All @@ -23,15 +23,15 @@ function makeTimestamp($relativeReleaseTime){
$relativeDays = 0;
$relativeHours = 0;

foreach(explode(" ", $relativeReleaseTime) as $relativeTimeElement) {
if(substr($relativeTimeElement, -1) == "d") $relativeDays = substr($relativeTimeElement, 0, -1);
if(substr($relativeTimeElement, -1) == "h") $relativeHours = substr($relativeTimeElement, 0, -1);
foreach(explode(' ', $relativeReleaseTime) as $relativeTimeElement) {
if(substr($relativeTimeElement, -1) == 'd') $relativeDays = substr($relativeTimeElement, 0, -1);
if(substr($relativeTimeElement, -1) == 'h') $relativeHours = substr($relativeTimeElement, 0, -1);
}
return mktime(date('h') - $relativeHours, 0, 0, date('m'), date('d') - $relativeDays, date('Y'));
}

// Loop on show ids
$showList = explode(",", $this->getInput('i'));
$showList = explode(',', $this->getInput('i'));
foreach($showList as $showID) {

// Get show page
Expand Down
52 changes: 26 additions & 26 deletions bridges/FB2Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ function extractFromDelimiters($string, $start, $end){
$html = $this->buildContent($fileContent);
$author = $this->getInput('u');

foreach($html->find("article") as $content) {
foreach($html->find('article') as $content) {

$item = array();

$item['uri'] = "http://touch.facebook.com"
. $content->find("div[class='_52jc _5qc4 _24u0 _36xo']", 0)->find("a", 0)->getAttribute("href");
$item['uri'] = 'http://touch.facebook.com'
. $content->find("div[class='_52jc _5qc4 _24u0 _36xo']", 0)->find('a', 0)->getAttribute('href');

if($content->find("header", 0) !== null) {
$content->find("header", 0)->innertext = "";
if($content->find('header', 0) !== null) {
$content->find('header', 0)->innertext = '';
}

if($content->find("footer", 0) !== null) {
$content->find("footer", 0)->innertext = "";
if($content->find('footer', 0) !== null) {
$content->find('footer', 0)->innertext = '';
}

//Remove html nodes, keep only img, links, basic formatting
Expand Down Expand Up @@ -168,7 +168,7 @@ private function computeNextLink($string, $pageID){
$regex = implode(
'',
array(
"/timeline_unit",
'/timeline_unit',
"\\\\\\\\u00253A1",
"\\\\\\\\u00253A([0-9]*)",
"\\\\\\\\u00253A([0-9]*)",
Expand All @@ -182,26 +182,26 @@ private function computeNextLink($string, $pageID){
return implode(
'',
array(
"https://touch.facebook.com/pages_reaction_units/more/?page_id=",
'https://touch.facebook.com/pages_reaction_units/more/?page_id=',
$pageID,
"&cursor=%7B%22timeline_cursor%22%3A%22timeline_unit%3A1%3A",
'&cursor=%7B%22timeline_cursor%22%3A%22timeline_unit%3A1%3A',
$result[1],
"%3A",
'%3A',
$result[2],
"%3A",
'%3A',
$result[3],
"%3A",
'%3A',
$result[4],
"%22%2C%22timeline_section_cursor%22%3A%7B%7D%2C%22",
"has_next_page%22%3Atrue%7D&surface=mobile_page_home&unit_count=3"
'%22%2C%22timeline_section_cursor%22%3A%7B%7D%2C%22',
'has_next_page%22%3Atrue%7D&surface=mobile_page_home&unit_count=3'
)
);
}

//Builds the HTML from the encoded JS that Facebook provides.
private function buildContent($pageContent){

$regex = "/\\\"html\\\":\\\"(.*?)\\\",\\\"replace/";
$regex = '/\\"html\\":\\"(.*?)\\",\\"replace/';
preg_match($regex, $pageContent, $result);

return str_get_html(html_entity_decode(json_decode('"' . $result[1] . '"')));
Expand All @@ -214,20 +214,20 @@ private function getCookies($pageURL){

$ctx = stream_context_create(array(
'http' => array(
'user_agent' => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0",
'user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
)
)
);
$a = file_get_contents($pageURL, 0, $ctx);

//First request to get the cookie
$cookies = "";
$cookies = '';
foreach($http_response_header as $hdr) {
if(strpos($hdr, "Set-Cookie") !== false) {
$cLine = explode(":", $hdr)[1];
$cLine = explode(";", $cLine)[0];
$cookies .= ";" . $cLine;
if(strpos($hdr, 'Set-Cookie') !== false) {
$cLine = explode(':', $hdr)[1];
$cLine = explode(';', $cLine)[0];
$cookies .= ';' . $cLine;
}
}

Expand All @@ -239,28 +239,28 @@ private function getPageID($page, $cookies){

$context = stream_context_create(array(
'http' => array(
'user_agent' => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0",
'user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0',
'header' => 'Cookie: ' . $cookies
)
)
);

$pageContent = file_get_contents($page, 0, $context);

if(strpos($pageContent, "signup-button") != false) {
if(strpos($pageContent, 'signup-button') != false) {
return -1;
}

//Get the page ID if we don't have a captcha
$regex = "/page_id=([0-9]*)&/";
$regex = '/page_id=([0-9]*)&/';
preg_match($regex, $pageContent, $matches);

if(count($matches) > 0) {
return $matches[1];
}

//Get the page ID if we do have a captcha
$regex = "/\"pageID\":\"([0-9]*)\"/";
$regex = '/"pageID":"([0-9]*)"/';
preg_match($regex, $pageContent, $matches);

return $matches[1];
Expand Down
8 changes: 4 additions & 4 deletions bridges/FacebookBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function extractFromDelimiters($string, $start, $end){
if (isset($_SESSION['captcha_fields'], $_SESSION['captcha_action'])) {
$captcha_action = $_SESSION['captcha_action'];
$captcha_fields = $_SESSION['captcha_fields'];
$captcha_fields['captcha_response'] = preg_replace("/[^a-zA-Z0-9]+/", "", $_POST['captcha_response']);
$captcha_fields['captcha_response'] = preg_replace('/[^a-zA-Z0-9]+/', '', $_POST['captcha_response']);

$header = array("Content-type:
application/x-www-form-urlencoded\r\nReferer: $captcha_action\r\nCookie: noscript=1\r\n");
Expand Down Expand Up @@ -153,11 +153,11 @@ function extractFromDelimiters($string, $start, $end){
} else {

// First character cannot be a forward slash
if(strpos($this->getInput('u'), "/") === 0) {
if(strpos($this->getInput('u'), '/') === 0) {
returnClientError('Remove leading slash "/" from the username!');
}

if(!strpos($this->getInput('u'), "/")) {
if(!strpos($this->getInput('u'), '/')) {
$html = getSimpleHTMLDOM(self::URI . urlencode($this->getInput('u')) . '?_fb_noscript=1', $header)
or returnServerError('No results for this query.');
} else {
Expand Down Expand Up @@ -305,7 +305,7 @@ function extractFromDelimiters($string, $start, $end){
);

//Retrieve date of the post
$date = $post->find("abbr")[0];
$date = $post->find('abbr')[0];
if(isset($date) && $date->hasAttribute('data-utime')) {
$date = $date->getAttribute('data-utime');
} else {
Expand Down
Loading

0 comments on commit 193ca87

Please sign in to comment.