mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-22 09:35:28 +03:00
refactor: prepare for PSR2 (#2859)
This commit is contained in:
parent
d2313bddcc
commit
5076d09de6
24 changed files with 140 additions and 146 deletions
|
@ -15,7 +15,7 @@ class DisplayAction implements ActionInterface
|
|||
{
|
||||
public $userData = [];
|
||||
|
||||
private function get_return_code($error) {
|
||||
private function getReturnCode($error) {
|
||||
$returnCode = $error->getCode();
|
||||
if ($returnCode === 301 || $returnCode === 302) {
|
||||
# Don't pass redirect codes to the exterior
|
||||
|
@ -184,7 +184,7 @@ class DisplayAction implements ActionInterface
|
|||
|
||||
$items[] = $item;
|
||||
} elseif(Configuration::getConfig('error', 'output') === 'http') {
|
||||
header('Content-Type: text/html', true, $this->get_return_code($e));
|
||||
header('Content-Type: text/html', true, $this->getReturnCode($e));
|
||||
die(buildTransformException($e, $bridge));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,9 @@ if (isset($argv)) {
|
|||
}
|
||||
|
||||
try {
|
||||
$actionFac = new ActionFactory();
|
||||
|
||||
$actionFac = new \ActionFactory();
|
||||
|
||||
if(array_key_exists('action', $params)) {
|
||||
if (array_key_exists('action', $params)) {
|
||||
$action = $actionFac->create($params['action']);
|
||||
$action->userData = $params;
|
||||
$action->execute();
|
||||
|
@ -25,8 +24,9 @@ try {
|
|||
$showInactive = filter_input(INPUT_GET, 'show_inactive', FILTER_VALIDATE_BOOLEAN);
|
||||
echo BridgeList::create($showInactive);
|
||||
}
|
||||
} catch(\Throwable $e) {
|
||||
} catch (\Throwable $e) {
|
||||
error_log($e);
|
||||
|
||||
$code = $e->getCode();
|
||||
if ($code !== -1) {
|
||||
header('Content-Type: text/plain', true, $code);
|
||||
|
|
|
@ -22,5 +22,5 @@ interface ActionInterface {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function execute();
|
||||
public function execute();
|
||||
}
|
||||
|
|
|
@ -286,7 +286,7 @@ This bridge is not fetching its content through a secure connection</div>';
|
|||
* @param bool $isActive Indicates if the bridge is active or not
|
||||
* @return string The bridge card
|
||||
*/
|
||||
static function displayBridgeCard($bridgeName, $formats, $isActive = true){
|
||||
public static function displayBridgeCard($bridgeName, $formats, $isActive = true){
|
||||
|
||||
$bridgeFac = new \BridgeFactory();
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@ EOD;
|
|||
* if enabled.
|
||||
* @return string The home page
|
||||
*/
|
||||
static function create($showInactive = true) {
|
||||
public static function create($showInactive = true) {
|
||||
|
||||
$totalBridges = 0;
|
||||
$totalActiveBridges = 0;
|
||||
|
|
|
@ -111,14 +111,17 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
case isset($rssContent->item[0]):
|
||||
Debug::log('Detected RSS 1.0 format');
|
||||
$this->feedType = self::FEED_TYPE_RSS_1_0;
|
||||
$this->collectRss1($rssContent, $maxItems);
|
||||
break;
|
||||
case isset($rssContent->channel[0]):
|
||||
Debug::log('Detected RSS 0.9x or 2.0 format');
|
||||
$this->feedType = self::FEED_TYPE_RSS_2_0;
|
||||
$this->collectRss2($rssContent, $maxItems);
|
||||
break;
|
||||
case isset($rssContent->entry[0]):
|
||||
Debug::log('Detected ATOM format');
|
||||
$this->feedType = self::FEED_TYPE_ATOM_1_0;
|
||||
$this->collectAtom1($rssContent, $maxItems);
|
||||
break;
|
||||
default:
|
||||
Debug::log('Unknown feed format/version');
|
||||
|
@ -126,9 +129,6 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
break;
|
||||
}
|
||||
|
||||
Debug::log('Calling function "collect_' . $this->feedType . '_data"');
|
||||
$this->{'collect_' . $this->feedType . '_data'}($rssContent, $maxItems);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -145,8 +145,8 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
* @todo Instead of passing $maxItems to all functions, just add all items
|
||||
* and remove excessive items later.
|
||||
*/
|
||||
protected function collect_RSS_1_0_data($rssContent, $maxItems){
|
||||
$this->load_RSS_2_0_feed_data($rssContent->channel[0]);
|
||||
protected function collectRss1($rssContent, $maxItems){
|
||||
$this->loadRss2Data($rssContent->channel[0]);
|
||||
foreach($rssContent->item as $item) {
|
||||
Debug::log('parsing item ' . var_export($item, true));
|
||||
$tmp_item = $this->parseItem($item);
|
||||
|
@ -170,13 +170,13 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
* @todo Instead of passing $maxItems to all functions, just add all items
|
||||
* and remove excessive items later.
|
||||
*/
|
||||
protected function collect_RSS_2_0_data($rssContent, $maxItems){
|
||||
protected function collectRss2($rssContent, $maxItems){
|
||||
$rssContent = $rssContent->channel[0];
|
||||
Debug::log('RSS content is ===========\n'
|
||||
. var_export($rssContent, true)
|
||||
. '===========');
|
||||
|
||||
$this->load_RSS_2_0_feed_data($rssContent);
|
||||
$this->loadRss2Data($rssContent);
|
||||
foreach($rssContent->item as $item) {
|
||||
Debug::log('parsing item ' . var_export($item, true));
|
||||
$tmp_item = $this->parseItem($item);
|
||||
|
@ -200,8 +200,8 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
* @todo Instead of passing $maxItems to all functions, just add all items
|
||||
* and remove excessive items later.
|
||||
*/
|
||||
protected function collect_ATOM_1_0_data($content, $maxItems){
|
||||
$this->load_ATOM_feed_data($content);
|
||||
protected function collectAtom1($content, $maxItems){
|
||||
$this->loadAtomData($content);
|
||||
foreach($content->entry as $item) {
|
||||
Debug::log('parsing item ' . var_export($item, true));
|
||||
$tmp_item = $this->parseItem($item);
|
||||
|
@ -212,16 +212,6 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert RSS 2.0 time to timestamp
|
||||
*
|
||||
* @param object $item A feed item
|
||||
* @return int The timestamp
|
||||
*/
|
||||
protected function RSS_2_0_time_to_timestamp($item){
|
||||
return DateTime::createFromFormat('D, d M Y H:i:s e', $item->pubDate)->getTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load RSS 2.0 feed data into RSS-Bridge
|
||||
*
|
||||
|
@ -230,7 +220,7 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
*
|
||||
* @todo set title, link, description, language, and so on
|
||||
*/
|
||||
protected function load_RSS_2_0_feed_data($rssContent){
|
||||
protected function loadRss2Data($rssContent){
|
||||
$this->title = trim((string)$rssContent->title);
|
||||
$this->uri = trim((string)$rssContent->link);
|
||||
|
||||
|
@ -245,7 +235,7 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
* @param object $content The Atom content
|
||||
* @return void
|
||||
*/
|
||||
protected function load_ATOM_feed_data($content){
|
||||
protected function loadAtomData($content){
|
||||
$this->title = (string)$content->title;
|
||||
|
||||
// Find best link (only one, or first of 'alternate')
|
||||
|
@ -282,7 +272,7 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
*/
|
||||
protected function parseATOMItem($feedItem){
|
||||
// Some ATOM entries also contain RSS 2.0 fields
|
||||
$item = $this->parseRSS_2_0_Item($feedItem);
|
||||
$item = $this->parseRss2Item($feedItem);
|
||||
|
||||
if(isset($feedItem->id)) $item['uri'] = (string)$feedItem->id;
|
||||
if(isset($feedItem->title)) $item['title'] = (string)$feedItem->title;
|
||||
|
@ -317,7 +307,7 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
* @todo To reduce confusion, the RSS-Bridge item should maybe have a class
|
||||
* of its own?
|
||||
*/
|
||||
protected function parseRSS_0_9_1_Item($feedItem){
|
||||
protected function parseRss091Item($feedItem){
|
||||
$item = array();
|
||||
if(isset($feedItem->link)) $item['uri'] = (string)$feedItem->link;
|
||||
if(isset($feedItem->title)) $item['title'] = (string)$feedItem->title;
|
||||
|
@ -338,9 +328,9 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
* @todo To reduce confusion, the RSS-Bridge item should maybe have a class
|
||||
* of its own?
|
||||
*/
|
||||
protected function parseRSS_1_0_Item($feedItem){
|
||||
protected function parseRss1Item($feedItem){
|
||||
// 1.0 adds optional elements around the 0.91 standard
|
||||
$item = $this->parseRSS_0_9_1_Item($feedItem);
|
||||
$item = $this->parseRss091Item($feedItem);
|
||||
|
||||
$namespaces = $feedItem->getNamespaces(true);
|
||||
if(isset($namespaces['dc'])) {
|
||||
|
@ -362,9 +352,9 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
* @todo To reduce confusion, the RSS-Bridge item should maybe have a class
|
||||
* of its own?
|
||||
*/
|
||||
protected function parseRSS_2_0_Item($feedItem){
|
||||
protected function parseRss2Item($feedItem){
|
||||
// Primary data is compatible to 0.91 with some additional data
|
||||
$item = $this->parseRSS_0_9_1_Item($feedItem);
|
||||
$item = $this->parseRss091Item($feedItem);
|
||||
|
||||
$namespaces = $feedItem->getNamespaces(true);
|
||||
if(isset($namespaces['dc'])) $dc = $feedItem->children($namespaces['dc']);
|
||||
|
@ -418,10 +408,10 @@ abstract class FeedExpander extends BridgeAbstract {
|
|||
protected function parseItem($item){
|
||||
switch($this->feedType) {
|
||||
case self::FEED_TYPE_RSS_1_0:
|
||||
return $this->parseRSS_1_0_Item($item);
|
||||
return $this->parseRss1Item($item);
|
||||
break;
|
||||
case self::FEED_TYPE_RSS_2_0:
|
||||
return $this->parseRSS_2_0_Item($item);
|
||||
return $this->parseRss2Item($item);
|
||||
break;
|
||||
case self::FEED_TYPE_ATOM_1_0:
|
||||
return $this->parseATOMItem($item);
|
||||
|
|
|
@ -483,7 +483,7 @@ class FeedItem {
|
|||
* @param string $name Property name
|
||||
* @param mixed $value Property value
|
||||
*/
|
||||
function __set($name, $value) {
|
||||
public function __set($name, $value) {
|
||||
switch($name) {
|
||||
case 'uri': $this->setURI($value); break;
|
||||
case 'title': $this->setTitle($value); break;
|
||||
|
@ -506,7 +506,7 @@ class FeedItem {
|
|||
* @param string $name Property name
|
||||
* @return mixed Property value
|
||||
*/
|
||||
function __get($name) {
|
||||
public function __get($name) {
|
||||
switch($name) {
|
||||
case 'uri': return $this->getURI();
|
||||
case 'title': return $this->getTitle();
|
||||
|
|
Loading…
Reference in a new issue