mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-29 11:00:10 +02:00
refactor: prepare for PSR2 (#2859)
This commit is contained in:
@@ -43,10 +43,10 @@ class BAEBridge extends BridgeAbstract {
|
||||
|
||||
$content = $htmlDetail->find('article p', 0)->innertext;
|
||||
if (!empty($this->getInput('keyword'))) {
|
||||
$keyword = $this->remove_accents(strtolower($this->getInput('keyword')));
|
||||
$cleanTitle = $this->remove_accents(strtolower($item['title']));
|
||||
$keyword = $this->removeAccents(strtolower($this->getInput('keyword')));
|
||||
$cleanTitle = $this->removeAccents(strtolower($item['title']));
|
||||
if (strpos($cleanTitle, $keyword) === false) {
|
||||
$cleanContent = $this->remove_accents(strtolower($content));
|
||||
$cleanContent = $this->removeAccents(strtolower($content));
|
||||
if (strpos($cleanContent, $keyword) === false) {
|
||||
continue;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class BAEBridge extends BridgeAbstract {
|
||||
return $uri;
|
||||
}
|
||||
|
||||
private function remove_accents($string) {
|
||||
private function removeAccents($string) {
|
||||
$chars = array(
|
||||
// Decompositions for Latin-1 Supplement
|
||||
'ª' => 'a', 'º' => 'o',
|
||||
|
@@ -39,7 +39,7 @@ class CVEDetailsBridge extends BridgeAbstract {
|
||||
// Because of the optional product ID, we need to attach it if it is
|
||||
// set. The search result page has the exact same structure (with and
|
||||
// without the product ID).
|
||||
private function _buildURL() {
|
||||
private function buildUrl() {
|
||||
$url = self::URI . '/vulnerability-list/vendor_id-' . $this->getInput('vendor_id');
|
||||
if ($this->getInput('product_id') !== '') {
|
||||
$url .= '/product_id-' . $this->getInput('product_id');
|
||||
@@ -54,8 +54,8 @@ class CVEDetailsBridge extends BridgeAbstract {
|
||||
|
||||
// Make the actual request to cvedetails.com and stores the response
|
||||
// (HTML) for later use and extract vendor and product from it.
|
||||
private function _fetchContent() {
|
||||
$html = getSimpleHTMLDOM($this->_buildURL());
|
||||
private function fetchContent() {
|
||||
$html = getSimpleHTMLDOM($this->buildUrl());
|
||||
$this->html = defaultLinkTo($html, self::URI);
|
||||
|
||||
$vendor = $html->find('#contentdiv > h1 > a', 0);
|
||||
@@ -80,7 +80,7 @@ class CVEDetailsBridge extends BridgeAbstract {
|
||||
}
|
||||
|
||||
if ($this->html == null) {
|
||||
$this->_fetchContent();
|
||||
$this->fetchContent();
|
||||
}
|
||||
|
||||
$name = 'CVE Vulnerabilities for ' . $this->vendor;
|
||||
@@ -94,7 +94,7 @@ class CVEDetailsBridge extends BridgeAbstract {
|
||||
// Pull the data from the HTML response and fill the items..
|
||||
public function collectData() {
|
||||
if ($this->html == null) {
|
||||
$this->_fetchContent();
|
||||
$this->fetchContent();
|
||||
}
|
||||
|
||||
foreach ($this->html->find('#vulnslisttable .srrowns') as $i => $tr) {
|
||||
|
@@ -395,7 +395,7 @@ class FacebookBridge extends BridgeAbstract {
|
||||
/**
|
||||
* Bypass external link redirection
|
||||
*/
|
||||
private function unescape_fb_link($content){
|
||||
private function unescapeFacebookLink($content){
|
||||
return preg_replace_callback('/ href=\"([^"]+)\"/i', function($matches){
|
||||
if(is_array($matches) && count($matches) > 1) {
|
||||
|
||||
@@ -413,7 +413,7 @@ class FacebookBridge extends BridgeAbstract {
|
||||
/**
|
||||
* Remove Facebook's tracking code
|
||||
*/
|
||||
private function remove_tracking_codes($content){
|
||||
private function removeTrackingCodes($content){
|
||||
return preg_replace_callback('/ href=\"([^"]+)\"/i', function($matches){
|
||||
if(is_array($matches) && count($matches) > 1) {
|
||||
|
||||
@@ -434,7 +434,7 @@ class FacebookBridge extends BridgeAbstract {
|
||||
* Convert textual representation of emoticons back to ASCII emoticons.
|
||||
* i.e. "<i><u>smile emoticon</u></i>" => ":)"
|
||||
*/
|
||||
private function unescape_fb_emote($content){
|
||||
private function unescapeFacebookEmote($content){
|
||||
return preg_replace_callback('/<i><u>([^ <>]+) ([^<>]+)<\/u><\/i>/i', function($matches){
|
||||
static $facebook_emoticons = array(
|
||||
'smile' => ':)',
|
||||
@@ -669,7 +669,7 @@ EOD;
|
||||
// Remove html nodes, keep only img, links, basic formatting
|
||||
$content = strip_tags($content, '<a><img><i><u><br><p>');
|
||||
|
||||
$content = $this->unescape_fb_link($content);
|
||||
$content = $this->unescapeFacebookLink($content);
|
||||
|
||||
// Clean useless html tag properties and fix link closing tags
|
||||
foreach (array(
|
||||
@@ -690,7 +690,7 @@ EOD;
|
||||
|
||||
$content = preg_replace('/<\/a [^>]+>/i', '</a>', $content);
|
||||
|
||||
$this->unescape_fb_emote($content);
|
||||
$this->unescapeFacebookEmote($content);
|
||||
|
||||
// Restore links in the post before further parsing
|
||||
$post = defaultLinkTo($post, self::URI);
|
||||
@@ -698,7 +698,7 @@ EOD;
|
||||
// Restore links in the content before adding to the item
|
||||
$content = defaultLinkTo($content, self::URI);
|
||||
|
||||
$content = $this->remove_tracking_codes($content);
|
||||
$content = $this->removeTrackingCodes($content);
|
||||
|
||||
// Retrieve date of the post
|
||||
$date = $post->find('abbr')[0];
|
||||
|
@@ -44,13 +44,13 @@ class FeedExpanderExampleBridge extends FeedExpander {
|
||||
protected function parseItem($newsItem) {
|
||||
switch($this->getInput('version')) {
|
||||
case 'rss_0_9_1':
|
||||
return $this->parseRSS_0_9_1_Item($newsItem);
|
||||
return $this->parseRss091Item($newsItem);
|
||||
break;
|
||||
case 'rss_1_0':
|
||||
return $this->parseRSS_1_0_Item($newsItem);
|
||||
return $this->parseRss1Item($newsItem);
|
||||
break;
|
||||
case 'rss_2_0':
|
||||
return $this->parseRSS_2_0_Item($newsItem);
|
||||
return $this->parseRss2Item($newsItem);
|
||||
break;
|
||||
case 'atom_1_0':
|
||||
return $this->parseATOMItem($newsItem);
|
||||
|
@@ -39,36 +39,36 @@ class FicbookBridge extends BridgeAbstract {
|
||||
|
||||
public function getURI() {
|
||||
switch($this->queriedContext) {
|
||||
case 'Site News': {
|
||||
case 'Site News':
|
||||
// For some reason this is not HTTPS
|
||||
return 'http://ficbook.net/sitenews';
|
||||
}
|
||||
case 'Fiction Updates': {
|
||||
|
||||
case 'Fiction Updates':
|
||||
return self::URI
|
||||
. 'readfic/'
|
||||
. urlencode($this->getInput('fiction_id'));
|
||||
}
|
||||
case 'Fiction Comments': {
|
||||
|
||||
case 'Fiction Comments':
|
||||
return self::URI
|
||||
. 'readfic/'
|
||||
. urlencode($this->getInput('fiction_id'))
|
||||
. '/comments#content';
|
||||
}
|
||||
|
||||
default: return parent::getURI();
|
||||
}
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
switch($this->queriedContext) {
|
||||
case 'Site News': {
|
||||
case 'Site News':
|
||||
return $this->queriedContext . ' | ' . self::NAME;
|
||||
}
|
||||
case 'Fiction Updates': {
|
||||
|
||||
case 'Fiction Updates':
|
||||
return $this->titleName . ' | ' . self::NAME;
|
||||
}
|
||||
case 'Fiction Comments': {
|
||||
|
||||
case 'Fiction Comments':
|
||||
return $this->titleName . ' | Comments | ' . self::NAME;
|
||||
}
|
||||
|
||||
default: return self::NAME;
|
||||
}
|
||||
}
|
||||
|
@@ -98,48 +98,48 @@ class GiteaBridge extends BridgeAbstract {
|
||||
|
||||
public function getURI() {
|
||||
switch($this->queriedContext) {
|
||||
case 'Commits': {
|
||||
case 'Commits':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/commits/' . $this->getInput('branch');
|
||||
} break;
|
||||
case 'Issues': {
|
||||
|
||||
case 'Issues':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/issues/';
|
||||
} break;
|
||||
case 'Single issue': {
|
||||
|
||||
case 'Single issue':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/issues/' . $this->getInput('issue');
|
||||
} break;
|
||||
case 'Releases': {
|
||||
|
||||
case 'Releases':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/releases/';
|
||||
} break;
|
||||
case 'Tags': {
|
||||
|
||||
case 'Tags':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/tags/';
|
||||
} break;
|
||||
case 'Pull requests': {
|
||||
|
||||
case 'Pull requests':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/pulls/';
|
||||
} break;
|
||||
case 'Single pull request': {
|
||||
|
||||
case 'Single pull request':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/pulls/' . $this->getInput('pull_request');
|
||||
} break;
|
||||
|
||||
default: return parent::getURI();
|
||||
}
|
||||
}
|
||||
@@ -152,27 +152,27 @@ class GiteaBridge extends BridgeAbstract {
|
||||
$this->title = $html->find('[property="og:title"]', 0)->content;
|
||||
|
||||
switch($this->queriedContext) {
|
||||
case 'Commits': {
|
||||
case 'Commits':
|
||||
$this->collectCommitsData($html);
|
||||
} break;
|
||||
case 'Issues': {
|
||||
break;
|
||||
case 'Issues':
|
||||
$this->collectIssuesData($html);
|
||||
} break;
|
||||
case 'Pull requests': {
|
||||
break;
|
||||
case 'Pull requests':
|
||||
$this->collectPullRequestsData($html);
|
||||
} break;
|
||||
case 'Single issue': {
|
||||
break;
|
||||
case 'Single issue':
|
||||
$this->collectSingleIssueOrPrData($html);
|
||||
} break;
|
||||
case 'Single pull request': {
|
||||
break;
|
||||
case 'Single pull request':
|
||||
$this->collectSingleIssueOrPrData($html);
|
||||
} break;
|
||||
case 'Releases': {
|
||||
break;
|
||||
case 'Releases':
|
||||
$this->collectReleasesData($html);
|
||||
} break;
|
||||
case 'Tags': {
|
||||
break;
|
||||
case 'Tags':
|
||||
$this->collectTagsData($html);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -263,23 +263,22 @@ class GithubIssueBridge extends BridgeAbstract {
|
||||
$path_segments = array_values(array_filter(explode('/', $url_components['path'])));
|
||||
|
||||
switch(count($path_segments)) {
|
||||
case 2: { // Project issues
|
||||
case 2: // Project issues
|
||||
list($user, $project) = $path_segments;
|
||||
$show_comments = 'off';
|
||||
} break;
|
||||
case 3: { // Project issues with issue comments
|
||||
break;
|
||||
case 3: // Project issues with issue comments
|
||||
if($path_segments[2] !== static::URL_PATH) {
|
||||
return null;
|
||||
}
|
||||
list($user, $project) = $path_segments;
|
||||
$show_comments = 'on';
|
||||
} break;
|
||||
case 4: { // Issue comments
|
||||
break;
|
||||
case 4: // Issue comments
|
||||
list($user, $project, /* issues */, $issue) = $path_segments;
|
||||
} break;
|
||||
default: {
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
|
@@ -64,30 +64,30 @@ class GogsBridge extends BridgeAbstract {
|
||||
|
||||
public function getURI() {
|
||||
switch($this->queriedContext) {
|
||||
case 'Commits': {
|
||||
case 'Commits':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/commits/' . $this->getInput('branch');
|
||||
} break;
|
||||
case 'Issues': {
|
||||
|
||||
case 'Issues':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/issues/';
|
||||
} break;
|
||||
case 'Single issue': {
|
||||
|
||||
case 'Single issue':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/issues/' . $this->getInput('issue');
|
||||
} break;
|
||||
case 'Releases': {
|
||||
|
||||
case 'Releases':
|
||||
return $this->getInput('host')
|
||||
. '/' . $this->getInput('user')
|
||||
. '/' . $this->getInput('project')
|
||||
. '/releases/';
|
||||
} break;
|
||||
|
||||
default: return parent::getURI();
|
||||
}
|
||||
}
|
||||
@@ -115,18 +115,18 @@ class GogsBridge extends BridgeAbstract {
|
||||
$this->title = $html->find('[property="og:title"]', 0)->content;
|
||||
|
||||
switch($this->queriedContext) {
|
||||
case 'Commits': {
|
||||
case 'Commits':
|
||||
$this->collectCommitsData($html);
|
||||
} break;
|
||||
case 'Issues': {
|
||||
break;
|
||||
case 'Issues':
|
||||
$this->collectIssuesData($html);
|
||||
} break;
|
||||
case 'Single issue': {
|
||||
break;
|
||||
case 'Single issue':
|
||||
$this->collectSingleIssueData($html);
|
||||
} break;
|
||||
case 'Releases': {
|
||||
break;
|
||||
case 'Releases':
|
||||
$this->collectReleasesData($html);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -68,7 +68,7 @@ class IPBBridge extends FeedExpander {
|
||||
case $this->isTopic($html):
|
||||
$this->collectTopic($html, $limit);
|
||||
break;
|
||||
case $this->isForum($html);
|
||||
case $this->isForum($html):
|
||||
$this->collectForum($html);
|
||||
break;
|
||||
default:
|
||||
|
@@ -78,7 +78,9 @@ Returns feeds for bug comments';
|
||||
// Order comments
|
||||
switch($sorting) {
|
||||
case 'lf': $comments = array_reverse($comments, true);
|
||||
// fall-through
|
||||
case 'of':
|
||||
// fall-through
|
||||
default: // Nothing to do, keep original order
|
||||
}
|
||||
|
||||
|
@@ -8,7 +8,7 @@ class LWNprevBridge extends BridgeAbstract{
|
||||
|
||||
private $editionTimeStamp;
|
||||
|
||||
function getURI(){
|
||||
public function getURI(){
|
||||
return self::URI . 'free/bigpage';
|
||||
}
|
||||
|
||||
@@ -144,6 +144,7 @@ EOD;
|
||||
if($cat->getAttribute('class') !== 'Cat2HL') {
|
||||
break;
|
||||
}
|
||||
// fall-through? Looks like a bug
|
||||
case 'Cat2HL':
|
||||
$cat2 = $cat->textContent;
|
||||
$cat = $cat->previousSibling;
|
||||
@@ -155,6 +156,7 @@ EOD;
|
||||
if($cat->getAttribute('class') !== 'Cat1HL') {
|
||||
break;
|
||||
}
|
||||
// fall-through? Looks like a bug
|
||||
case 'Cat1HL':
|
||||
$cat1 = $cat->textContent;
|
||||
$cats[0] = $cat1;
|
||||
|
@@ -113,6 +113,7 @@ class MoinMoinBridge extends BridgeAbstract {
|
||||
|
||||
break;
|
||||
}
|
||||
// fall-through
|
||||
case 'separator':
|
||||
default: // Use contents from the current page
|
||||
$item['content'] = $this->cleanArticle($section[2]);
|
||||
|
@@ -48,12 +48,10 @@ class NationalGeographicBridge extends BridgeAbstract {
|
||||
|
||||
public function getURI() {
|
||||
switch ($this->queriedContext) {
|
||||
case self::CONTEXT_BY_TOPIC: {
|
||||
case self::CONTEXT_BY_TOPIC:
|
||||
return self::URI . $this->getInput(self::PARAMETER_TOPIC);
|
||||
} break;
|
||||
default: {
|
||||
default:
|
||||
return parent::getURI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,26 +66,21 @@ class NationalGeographicBridge extends BridgeAbstract {
|
||||
public function collectData() {
|
||||
$this->topicName = $this->getTopicName($this->getInput(self::PARAMETER_TOPIC));
|
||||
switch($this->topicName) {
|
||||
case self::TOPIC_MAGAZINE: {
|
||||
case self::TOPIC_MAGAZINE:
|
||||
return $this->collectMagazine();
|
||||
} break;
|
||||
case self::TOPIC_LATEST_STORIES: {
|
||||
case self::TOPIC_LATEST_STORIES:
|
||||
return $this->collectLatestStories();
|
||||
} break;
|
||||
default: {
|
||||
default:
|
||||
returnServerError('Unknown topic: "' . $this->topicName . '"');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
switch ($this->queriedContext) {
|
||||
case self::CONTEXT_BY_TOPIC: {
|
||||
case self::CONTEXT_BY_TOPIC:
|
||||
return static::NAME . ': ' . $this->topicName;
|
||||
} break;
|
||||
default: {
|
||||
default:
|
||||
return parent::getName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +320,7 @@ EOD;
|
||||
case 'video':
|
||||
$content .= $this->handleImages($module, $module['cmsType']);
|
||||
break;
|
||||
case 'pullquote';
|
||||
case 'pullquote':
|
||||
$quote = $module['quote'];
|
||||
$author_name = '';
|
||||
$authors = (isset($module['byLineProps']['authors']) ? $module['byLineProps']['authors'] : array());
|
||||
|
@@ -110,7 +110,7 @@ EOD;
|
||||
//preg_replace used for images with spaces in the url
|
||||
|
||||
switch($dimensions) {
|
||||
case 'None': {
|
||||
case 'None':
|
||||
foreach($media as $image) {
|
||||
$imageURL = preg_replace('[ ]', '%20', $image['url']);
|
||||
$text .= <<<EOD
|
||||
@@ -120,8 +120,8 @@ EOD;
|
||||
EOD;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'Small': {
|
||||
|
||||
case 'Small':
|
||||
foreach($media as $image) {
|
||||
$imageURL = preg_replace('[ ]', '%20', $image['small_image_url']);
|
||||
$text .= <<<EOD
|
||||
@@ -134,8 +134,8 @@ EOD;
|
||||
EOD;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'Full': {
|
||||
|
||||
case 'Full':
|
||||
foreach($media as $image) {
|
||||
$imageURL = preg_replace('[ ]', '%20', $image['url']);
|
||||
$text .= <<<EOD
|
||||
@@ -148,7 +148,7 @@ EOD;
|
||||
EOD;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ class RaceDepartmentBridge extends FeedExpander {
|
||||
}
|
||||
|
||||
protected function parseItem($feedItem) {
|
||||
$item = parent::parseRSS_2_0_Item($feedItem);
|
||||
$item = parent::parseRss2Item($feedItem);
|
||||
|
||||
//fetch page
|
||||
$articlePage = getSimpleHTMLDOMCached($feedItem->link);
|
||||
|
@@ -266,8 +266,10 @@ EOD
|
||||
switch($this->queriedContext) {
|
||||
case 'By keyword or hashtag':
|
||||
returnServerError('No results for this query.');
|
||||
// fall-through
|
||||
case 'By username':
|
||||
returnServerError('Requested username can\'t be found.');
|
||||
// fall-through
|
||||
case 'By list':
|
||||
returnServerError('Requested username or list can\'t be found');
|
||||
}
|
||||
@@ -613,6 +615,7 @@ EOD;
|
||||
} catch (HttpException $e) {
|
||||
switch ($e->getCode()) {
|
||||
case 401:
|
||||
// fall-through
|
||||
case 403:
|
||||
if ($retries) {
|
||||
$retries--;
|
||||
@@ -620,6 +623,7 @@ EOD;
|
||||
$this->getApiKey(1);
|
||||
continue 2;
|
||||
}
|
||||
// fall-through
|
||||
default:
|
||||
$code = $e->getCode();
|
||||
$data = $e->getMessage();
|
||||
|
@@ -259,10 +259,13 @@ EOD
|
||||
switch($this->queriedContext) {
|
||||
case 'By keyword or hashtag':
|
||||
returnServerError('No results for this query.');
|
||||
// fall-through
|
||||
case 'By username':
|
||||
returnServerError('Requested username cannnot be found.');
|
||||
// fall-through
|
||||
case 'By list ID':
|
||||
returnServerError('Requested list cannnot be found');
|
||||
// fall-through
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user