From c44fb25845437654b44d652bc49a1faa7b7dcea9 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Mon, 13 Feb 2017 19:26:39 +0100 Subject: [PATCH 1/4] core: Improve documentation and style for BridgeAbstract and BridgeInterface Public functions defined in BridgeAbstract also belong to BridgeInterface getInput may only be used by this class or its children. --- lib/BridgeAbstract.php | 47 ++++++++++++++++++++++++++++++++++------- lib/BridgeInterface.php | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 8 deletions(-) diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index 6d35ba47..cc130442 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -20,7 +20,10 @@ abstract class BridgeAbstract implements BridgeInterface { * @return mixed */ public function getCachable(){ - return array("items" => $this->getItems(), "extraInfos" => $this->getExtraInfos()); + return array( + 'items' => $this->getItems(), + 'extraInfos' => $this->getExtraInfos() + ); } /** @@ -31,7 +34,13 @@ abstract class BridgeAbstract implements BridgeInterface { return $this->items; } - + /** + * Sets the input values for a given context. Existing values are + * overwritten. + * + * @param array $inputs Associative array of inputs + * @param string $context The context name + */ protected function setInputs(array $inputs, $queriedContext){ // Import and assign all inputs to their context foreach($inputs as $name => $value){ @@ -89,7 +98,7 @@ abstract class BridgeAbstract implements BridgeInterface { foreach(static::PARAMETERS['global'] as $name => $properties){ if(isset($inputs[$name])){ $value = $inputs[$name]; - } elseif (isset($properties['value'])){ + } elseif(isset($properties['value'])){ $value = $properties['value']; } else { continue; @@ -106,10 +115,20 @@ abstract class BridgeAbstract implements BridgeInterface { } } + /** + * Returns the name of the context matching the provided inputs + * + * @param array $inputs Associative array of inputs + * @return mixed Returns the context name or null if no match was found + */ protected function getQueriedContext(array $inputs){ $queriedContexts = array(); + + // Detect matching context foreach(static::PARAMETERS as $context => $set){ $queriedContexts[$context] = null; + + // Check if all parameters of the context are satisfied foreach($set as $id => $properties){ if(isset($inputs[$id]) && !empty($inputs[$id])){ $queriedContexts[$context] = true; @@ -119,8 +138,10 @@ abstract class BridgeAbstract implements BridgeInterface { break; } } + } + // Abort if one of the globally required parameters is not satisfied if(array_key_exists('global', static::PARAMETERS) && $queriedContexts['global'] === false){ return null; @@ -128,14 +149,15 @@ abstract class BridgeAbstract implements BridgeInterface { unset($queriedContexts['global']); switch(array_sum($queriedContexts)){ - case 0: + case 0: // Found no match, is there a context without parameters? foreach($queriedContexts as $context => $queried){ - if (is_null($queried)){ + if(is_null($queried)){ return $context; } } return null; - case 1: return array_search(true, $queriedContexts); + case 1: // Found unique match + return array_search(true, $queriedContexts); default: return false; } } @@ -193,7 +215,13 @@ abstract class BridgeAbstract implements BridgeInterface { } } - function getInput($input){ + /** + * Returns the value for the provided input + * + * @param string $input The input name + * @return mixed Returns the input value or null if the input is not defined + */ + protected function getInput($input){ if(!isset($this->inputs[$this->queriedContext][$input]['value'])){ return null; } @@ -209,7 +237,10 @@ abstract class BridgeAbstract implements BridgeInterface { } public function getExtraInfos(){ - return array("name" => $this->getName(), "uri" => $this->getURI()); + return array( + 'name' => $this->getName(), + 'uri' => $this->getURI() + ); } public function setCache(\CacheInterface $cache){ diff --git a/lib/BridgeInterface.php b/lib/BridgeInterface.php index a7932a87..fbb7a0f0 100644 --- a/lib/BridgeInterface.php +++ b/lib/BridgeInterface.php @@ -1,6 +1,50 @@ Date: Mon, 13 Feb 2017 20:56:19 +0100 Subject: [PATCH 2/4] core: Use methods to access bridge information Bridge information were exposed and accessed via public constants which doesn't work if you want to generate bridges dynamically as discussed in #402 --- lib/BridgeAbstract.php | 18 +++++++++++++++--- lib/BridgeInterface.php | 21 +++++++++++++++++++++ lib/html.php | 25 +++++++++++-------------- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/lib/BridgeAbstract.php b/lib/BridgeAbstract.php index cc130442..2b1c7639 100644 --- a/lib/BridgeAbstract.php +++ b/lib/BridgeAbstract.php @@ -21,7 +21,7 @@ abstract class BridgeAbstract implements BridgeInterface { */ public function getCachable(){ return array( - 'items' => $this->getItems(), + 'items' => $this->getItems(), 'extraInfos' => $this->getExtraInfos() ); } @@ -35,7 +35,7 @@ abstract class BridgeAbstract implements BridgeInterface { } /** - * Sets the input values for a given context. Existing values are + * Sets the input values for a given context. Existing values are * overwritten. * * @param array $inputs Associative array of inputs @@ -228,17 +228,29 @@ abstract class BridgeAbstract implements BridgeInterface { return $this->inputs[$this->queriedContext][$input]['value']; } + public function getDescription(){ + return static::DESCRIPTION; + } + + public function getMaintainer(){ + return static::MAINTAINER; + } + public function getName(){ return static::NAME; } + public function getParameters(){ + return static::PARAMETERS; + } + public function getURI(){ return static::URI; } public function getExtraInfos(){ return array( - 'name' => $this->getName(), + 'name' => $this->getName(), 'uri' => $this->getURI() ); } diff --git a/lib/BridgeInterface.php b/lib/BridgeInterface.php index fbb7a0f0..a4add2c9 100644 --- a/lib/BridgeInterface.php +++ b/lib/BridgeInterface.php @@ -13,6 +13,13 @@ interface BridgeInterface { */ public function getCachable(); + /** + * Returns the description + * + * @return string Description + */ + public function getDescription(); + /** * Return an array of extra information * @@ -27,6 +34,13 @@ interface BridgeInterface { */ public function getItems(); + /** + * Returns the bridge maintainer + * + * @return string Bridge maintainer + */ + public function getMaintainer(); + /** * Returns the bridge name * @@ -34,6 +48,13 @@ interface BridgeInterface { */ public function getName(); + /** + * Returns the bridge parameters + * + * @return array Bridge parameters + */ + public function getParameters(); + /** * Returns the bridge URI * diff --git a/lib/html.php b/lib/html.php index b13818b3..1b9b5ab7 100644 --- a/lib/html.php +++ b/lib/html.php @@ -15,22 +15,21 @@ function displayBridgeCard($bridgeName, $formats, $isActive = true){ return $buttons; }; - $getFormHeader = function($bridge){ + $getFormHeader = function($bridgeName){ return << - + EOD; }; - $bridgeElement = Bridge::create($bridgeName); - $bridgeClass = $bridgeName . 'Bridge'; + $bridge = Bridge::create($bridgeName); - if($bridgeElement == false) + if($bridge == false) return ""; - $name = '' . $bridgeClass::NAME . ''; - $description = $bridgeClass::DESCRIPTION; + $name = '' . $bridge->getName() . ''; + $description = $bridge->getDescription(); $card = << @@ -43,7 +42,7 @@ EOD; CARD; // If we don't have any parameter for the bridge, we print a generic form to load it. - if(count($bridgeClass::PARAMETERS) == 0){ + if(count($bridge->getParameters()) == 0){ $card .= $getFormHeader($bridgeName); @@ -77,13 +76,13 @@ CARD; $card .= '' . PHP_EOL; } - $hasGlobalParameter = array_key_exists('global', $bridgeClass::PARAMETERS); + $hasGlobalParameter = array_key_exists('global', $bridge->getParameters()); if($hasGlobalParameter){ - $globalParameters = $bridgeClass::PARAMETERS['global']; + $globalParameters = $bridge->getParameters()['global']; } - foreach($bridgeClass::PARAMETERS as $parameterName => $parameter){ + foreach($bridge->getParameters() as $parameterName => $parameter){ if(!is_numeric($parameterName) && $parameterName == 'global') continue; @@ -251,7 +250,7 @@ CARD; } $card .= ''; - $card .= '

' . $bridgeClass::MAINTAINER . '

'; + $card .= '

' . $bridge->getMaintainer() . '

'; $card .= ''; return $card; @@ -288,5 +287,3 @@ function defaultImageSrcTo($content, $server){ } return $content; } - -?> From c4169f1579701342f7f462f0103f68c5382946ad Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Tue, 14 Feb 2017 22:20:55 +0100 Subject: [PATCH 3/4] bridges: Return parent::getName by default --- bridges/AllocineFRBridge.php | 10 +++++----- bridges/AmazonBridge.php | 5 ++++- bridges/AskfmBridge.php | 6 +++++- bridges/BandcampBridge.php | 6 +++++- bridges/BooruprojectBridge.php | 6 +++++- bridges/CNETBridge.php | 8 ++++++-- bridges/CpasbienBridge.php | 6 +++++- bridges/FacebookBridge.php | 7 ++++++- bridges/GithubIssueBridge.php | 1 + bridges/GoComicsBridge.php | 6 +++++- bridges/GoogleSearchBridge.php | 6 +++++- bridges/HDWallpapersBridge.php | 14 +++++++++----- bridges/IdenticaBridge.php | 6 +++++- bridges/InstagramBridge.php | 6 +++++- bridges/KununuBridge.php | 2 +- bridges/MixCloudBridge.php | 6 +++++- bridges/NovelUpdatesBridge.php | 4 ++++ bridges/ParuVenduImmoBridge.php | 22 +++++++++++++--------- bridges/PickyWallpapersBridge.php | 18 +++++++++++------- bridges/RTBFBridge.php | 6 +++++- bridges/SoundcloudBridge.php | 6 +++++- bridges/SuperbWallpapersBridge.php | 6 +++++- bridges/TagBoardBridge.php | 6 +++++- bridges/Torrent9Bridge.php | 6 +++++- bridges/TwitterBridge.php | 1 + bridges/WallpaperStopBridge.php | 18 +++++++++++------- bridges/WikipediaBridge.php | 4 +--- bridges/WorldOfTanksBridge.php | 2 +- lib/FeedExpander.php | 2 +- 29 files changed, 145 insertions(+), 57 deletions(-) diff --git a/bridges/AllocineFRBridge.php b/bridges/AllocineFRBridge.php index 74601c92..91e3305a 100644 --- a/bridges/AllocineFRBridge.php +++ b/bridges/AllocineFRBridge.php @@ -44,11 +44,11 @@ class AllocineFRBridge extends BridgeAbstract { public function getName(){ if(!is_null($this->getInput('category'))){ - return self::NAME . ' : ' - .array_search( - $this->getInput('category'), - self::PARAMETERS[$this->queriedContext]['category']['values'] - ); + return self::NAME . ' : ' + .array_search( + $this->getInput('category'), + self::PARAMETERS[$this->queriedContext]['category']['values'] + ); } return parent::getName(); diff --git a/bridges/AmazonBridge.php b/bridges/AmazonBridge.php index 5dbef299..d7f77c51 100644 --- a/bridges/AmazonBridge.php +++ b/bridges/AmazonBridge.php @@ -51,8 +51,11 @@ class AmazonBridge extends BridgeAbstract { )); public function getName(){ + if(!is_null($this->getInput('tld')) && !is_null($this->getInput('q'))){ + return 'Amazon.'.$this->getInput('tld').': '.$this->getInput('q'); + } - return 'Amazon.'.$this->getInput('tld').': '.$this->getInput('q'); + return parent::getName(); } public function collectData() { diff --git a/bridges/AskfmBridge.php b/bridges/AskfmBridge.php index 85d469fc..e871c9c0 100644 --- a/bridges/AskfmBridge.php +++ b/bridges/AskfmBridge.php @@ -57,7 +57,11 @@ class AskfmBridge extends BridgeAbstract { } public function getName(){ - return self::NAME . ' : ' . $this->getInput('u'); + if(!is_null($this->getInput('u'))){ + return self::NAME . ' : ' . $this->getInput('u'); + } + + return parent::getName(); } public function getURI(){ diff --git a/bridges/BandcampBridge.php b/bridges/BandcampBridge.php index 7156de46..818a2d08 100644 --- a/bridges/BandcampBridge.php +++ b/bridges/BandcampBridge.php @@ -50,6 +50,10 @@ class BandcampBridge extends BridgeAbstract { } public function getName(){ - return $this->getInput('tag') . ' - Bandcamp Tag'; + if(!is_null($this->getInput('tag'))){ + return $this->getInput('tag') . ' - Bandcamp Tag'; + } + + return parent::getName(); } } diff --git a/bridges/BooruprojectBridge.php b/bridges/BooruprojectBridge.php index d60a9f20..35b51491 100644 --- a/bridges/BooruprojectBridge.php +++ b/bridges/BooruprojectBridge.php @@ -32,6 +32,10 @@ class BooruprojectBridge extends GelbooruBridge { } public function getName(){ - return static::NAME . ' ' . $this->getInput('i'); + if(!is_null($this->getInput('i'))){ + return static::NAME . ' ' . $this->getInput('i'); + } + + return parent::getName(); } } diff --git a/bridges/CNETBridge.php b/bridges/CNETBridge.php index fa76ec0c..0abd02cc 100644 --- a/bridges/CNETBridge.php +++ b/bridges/CNETBridge.php @@ -83,7 +83,11 @@ topic found in some section URLs, else all topics are selected.'; } public function getName(){ - $topic = $this->getInput('topic'); - return 'CNET News Bridge' . (empty($topic) ? '' : ' - ' . $topic); + if(!is_null($this->getInput('topic'))){ + $topic = $this->getInput('topic'); + return 'CNET News Bridge' . (empty($topic) ? '' : ' - ' . $topic); + } + + return parent::getName(); } } diff --git a/bridges/CpasbienBridge.php b/bridges/CpasbienBridge.php index 0773d11f..9ca95f44 100644 --- a/bridges/CpasbienBridge.php +++ b/bridges/CpasbienBridge.php @@ -50,7 +50,11 @@ class CpasbienBridge extends BridgeAbstract { } public function getName(){ - return $this->getInput('q') . ' : ' . self::NAME; + if(!is_null($this->getInput('q'))){ + return $this->getInput('q') . ' : ' . self::NAME; + } + + return parent::getName(); } private function getCachedDate($url){ diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index 04898cb0..efc93265 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -257,6 +257,11 @@ EOD; } public function getName(){ - return isset($this->extraInfos['name']) ? $this->extraInfos['name'] : $this->authorName . ' - Facebook Bridge'; + if(!empty($this->authorName)){ + return isset($this->extraInfos['name']) ? $this->extraInfos['name'] : $this->authorName + . ' - Facebook Bridge'; + } + + return parent::getName(); } } diff --git a/bridges/GithubIssueBridge.php b/bridges/GithubIssueBridge.php index ba5b5e26..d1f1cc6f 100644 --- a/bridges/GithubIssueBridge.php +++ b/bridges/GithubIssueBridge.php @@ -47,6 +47,7 @@ class GithubIssueBridge extends BridgeAbstract { case 'Issue comments': $name = static::NAME . ' ' . $name . ' #' . $this->getInput('i'); break; + default: return parent::getName(); } return $name; } diff --git a/bridges/GoComicsBridge.php b/bridges/GoComicsBridge.php index b9d6b2d8..851e11fe 100644 --- a/bridges/GoComicsBridge.php +++ b/bridges/GoComicsBridge.php @@ -46,6 +46,10 @@ class GoComicsBridge extends BridgeAbstract { } public function getName(){ - return $this->getInput('comicname') . ' - GoComics'; + if(!is_null($this->getInput('comicname'))){ + return $this->getInput('comicname') . ' - GoComics'; + } + + return parent::getName(); } } diff --git a/bridges/GoogleSearchBridge.php b/bridges/GoogleSearchBridge.php index bd07f36d..67e14dc4 100644 --- a/bridges/GoogleSearchBridge.php +++ b/bridges/GoogleSearchBridge.php @@ -55,6 +55,10 @@ class GoogleSearchBridge extends BridgeAbstract { } public function getName(){ - return $this->getInput('q') . ' - Google search'; + if(!is_null($this->getInput('q'))){ + return $this->getInput('q') . ' - Google search'; + } + + return parent::getName(); } } diff --git a/bridges/HDWallpapersBridge.php b/bridges/HDWallpapersBridge.php index 309c3fdf..29f9c00c 100644 --- a/bridges/HDWallpapersBridge.php +++ b/bridges/HDWallpapersBridge.php @@ -70,10 +70,14 @@ class HDWallpapersBridge extends BridgeAbstract { } public function getName(){ - return 'HDWallpapers - ' - . str_replace(['__', '_'], [' & ', ' '], $this->getInput('c')) - . ' [' - . $this->getInput('r') - . ']'; + if(!is_null($this->getInput('c')) && !is_null($this->getInput('r'))){ + return 'HDWallpapers - ' + . str_replace(['__', '_'], [' & ', ' '], $this->getInput('c')) + . ' [' + . $this->getInput('r') + . ']'; + } + + return parent::getName(); } } diff --git a/bridges/IdenticaBridge.php b/bridges/IdenticaBridge.php index 05d832ad..ca101f41 100644 --- a/bridges/IdenticaBridge.php +++ b/bridges/IdenticaBridge.php @@ -35,7 +35,11 @@ class IdenticaBridge extends BridgeAbstract { } public function getName(){ - return $this->getInput('u') . ' - Identica Bridge'; + if(!is_null($this->getInput('u'))){ + return $this->getInput('u') . ' - Identica Bridge'; + } + + return parent::getName(); } public function getURI(){ diff --git a/bridges/InstagramBridge.php b/bridges/InstagramBridge.php index 36240b10..555a2558 100644 --- a/bridges/InstagramBridge.php +++ b/bridges/InstagramBridge.php @@ -53,7 +53,11 @@ class InstagramBridge extends BridgeAbstract { } public function getName(){ - return $this->getInput('u') . ' - Instagram Bridge'; + if(!is_null($this->getInput('u'))){ + return $this->getInput('u') . ' - Instagram Bridge'; + } + + return parent::getName(); } public function getURI(){ diff --git a/bridges/KununuBridge.php b/bridges/KununuBridge.php index 083f660d..ad3fdea4 100644 --- a/bridges/KununuBridge.php +++ b/bridges/KununuBridge.php @@ -70,7 +70,7 @@ class KununuBridge extends BridgeAbstract { return ($this->companyName ?: $company) . ' - ' . self::NAME; } - return paren::getName(); + return parent::getName(); } public function collectData(){ diff --git a/bridges/MixCloudBridge.php b/bridges/MixCloudBridge.php index f9ae7fe3..04fbb967 100644 --- a/bridges/MixCloudBridge.php +++ b/bridges/MixCloudBridge.php @@ -16,7 +16,11 @@ class MixCloudBridge extends BridgeAbstract { )); public function getName(){ - return 'MixCloud - ' . $this->getInput('u'); + if(!is_null($this->getInput('u'))){ + return 'MixCloud - ' . $this->getInput('u'); + } + + return parent::getName(); } public function collectData(){ diff --git a/bridges/NovelUpdatesBridge.php b/bridges/NovelUpdatesBridge.php index bb40b89f..1a5880c7 100644 --- a/bridges/NovelUpdatesBridge.php +++ b/bridges/NovelUpdatesBridge.php @@ -56,6 +56,10 @@ class NovelUpdatesBridge extends BridgeAbstract { } public function getName(){ + if(!empty($this->seriesTitle)){ return $this->seriesTitle . ' - ' . static::NAME; + } + + return parent::getName(); } } diff --git a/bridges/ParuVenduImmoBridge.php b/bridges/ParuVenduImmoBridge.php index 6a6f1440..5d050ae6 100644 --- a/bridges/ParuVenduImmoBridge.php +++ b/bridges/ParuVenduImmoBridge.php @@ -84,15 +84,19 @@ class ParuVenduImmoBridge extends BridgeAbstract { } public function getName(){ - $request = ''; - $minarea = $this->getInput('minarea'); - if(!empty($minarea)){ - $request .= ' ' . $minarea . ' m2'; + if(!is_null($this->getInput('minarea'))){ + $request = ''; + $minarea = $this->getInput('minarea'); + if(!empty($minarea)){ + $request .= ' ' . $minarea . ' m2'; + } + $location = $this->getInput('lo'); + if(!empty($location)){ + $request .= ' In: ' . $location; + } + return 'Paru Vendu Immobilier' . $request; } - $location = $this->getInput('lo'); - if(!empty($location)){ - $request .= ' In: ' . $location; - } - return 'Paru Vendu Immobilier' . $request; + + return parent::getName(); } } diff --git a/bridges/PickyWallpapersBridge.php b/bridges/PickyWallpapersBridge.php index a2be7edd..43e91c5b 100644 --- a/bridges/PickyWallpapersBridge.php +++ b/bridges/PickyWallpapersBridge.php @@ -82,12 +82,16 @@ class PickyWallpapersBridge extends BridgeAbstract { } public function getName(){ - $subcategory = $this->getInput('s'); - return 'PickyWallpapers - ' - . $this->getInput('c') - . ($subcategory ? ' > ' . $subcategory : '') - . ' [' - . $this->getInput('r') - . ']'; + if(!is_null($this->getInput('s'))){ + $subcategory = $this->getInput('s'); + return 'PickyWallpapers - ' + . $this->getInput('c') + . ($subcategory ? ' > ' . $subcategory : '') + . ' [' + . $this->getInput('r') + . ']'; + } + + return parent::getName(); } } diff --git a/bridges/RTBFBridge.php b/bridges/RTBFBridge.php index 93039086..6109704f 100644 --- a/bridges/RTBFBridge.php +++ b/bridges/RTBFBridge.php @@ -53,6 +53,10 @@ class RTBFBridge extends BridgeAbstract { } public function getName(){ - return $this->getInput('c') .' - RTBF Bridge'; + if(!is_null($this->getInput('c'))){ + return $this->getInput('c') .' - RTBF Bridge'; + } + + return parent::getName(); } } diff --git a/bridges/SoundcloudBridge.php b/bridges/SoundcloudBridge.php index cb4ba915..ea80d56a 100644 --- a/bridges/SoundcloudBridge.php +++ b/bridges/SoundcloudBridge.php @@ -55,6 +55,10 @@ class SoundCloudBridge extends BridgeAbstract { } public function getName(){ - return self::NAME . ' - ' . $this->getInput('u'); + if(!is_null($this->getInput('u'))){ + return self::NAME . ' - ' . $this->getInput('u'); + } + + return parent::getName(); } } diff --git a/bridges/SuperbWallpapersBridge.php b/bridges/SuperbWallpapersBridge.php index 7f7195db..874f3abf 100644 --- a/bridges/SuperbWallpapersBridge.php +++ b/bridges/SuperbWallpapersBridge.php @@ -61,6 +61,10 @@ class SuperbWallpapersBridge extends BridgeAbstract { } public function getName(){ - return self::NAME . '- ' . $this->getInput('c') . ' [' . $this->getInput('r') . ']'; + if(!is_null($this->getInput('c')) && !is_null($this->getInput('r'))){ + return self::NAME . '- ' . $this->getInput('c') . ' [' . $this->getInput('r') . ']'; + } + + return parent::getName(); } } diff --git a/bridges/TagBoardBridge.php b/bridges/TagBoardBridge.php index 1845d220..d2f74bfe 100644 --- a/bridges/TagBoardBridge.php +++ b/bridges/TagBoardBridge.php @@ -40,6 +40,10 @@ class TagBoardBridge extends BridgeAbstract { } public function getName(){ - return 'tagboard - ' . $this->getInput('u'); + if(!is_null($this->getInput('u'))){ + return 'tagboard - ' . $this->getInput('u'); + } + + return parent::getName(); } } diff --git a/bridges/Torrent9Bridge.php b/bridges/Torrent9Bridge.php index fe0a9440..a339e58e 100644 --- a/bridges/Torrent9Bridge.php +++ b/bridges/Torrent9Bridge.php @@ -81,7 +81,11 @@ class Torrent9Bridge extends BridgeAbstract { public function getName(){ - return $this->getInput('q') . ' : ' . self::NAME; + if(!is_null($this->getInput('q'))){ + return $this->getInput('q') . ' : ' . self::NAME; + } + + return parent::getName(); } private function getCachedDate($url){ diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php index 18de5d81..60f2eaed 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -46,6 +46,7 @@ class TwitterBridge extends BridgeAbstract { $specific = '@'; $param = 'u'; break; + default: return parent::getName(); } return 'Twitter ' . $specific . $this->getInput($param); } diff --git a/bridges/WallpaperStopBridge.php b/bridges/WallpaperStopBridge.php index ce0cbb9a..87be0d15 100644 --- a/bridges/WallpaperStopBridge.php +++ b/bridges/WallpaperStopBridge.php @@ -92,12 +92,16 @@ class WallpaperStopBridge extends BridgeAbstract { } public function getName(){ - $subcategory = $this->getInput('s'); - return 'WallpaperStop - ' - . $this->getInput('c') - . (!empty($subcategory) ? ' > ' . $subcategory : '') - . ' [' - . $this->getInput('r') - . ']'; + if(!is_null($this->getInput('s')) && !is_null($this->getInput('c')) && !is_null($this->getInput('r'))){ + $subcategory = $this->getInput('s'); + return 'WallpaperStop - ' + . $this->getInput('c') + . (!empty($subcategory) ? ' > ' . $subcategory : '') + . ' [' + . $this->getInput('r') + . ']'; + } + + return parent::getName(); } } diff --git a/bridges/WikipediaBridge.php b/bridges/WikipediaBridge.php index 7bda0156..2410656d 100644 --- a/bridges/WikipediaBridge.php +++ b/bridges/WikipediaBridge.php @@ -56,9 +56,7 @@ class WikipediaBridge extends BridgeAbstract { case 'dyk': $subject = WIKIPEDIA_SUBJECT_DYK; break; - default: - $subject = WIKIPEDIA_SUBJECT_TFA; - break; + default: return parent::getName(); } switch($subject){ diff --git a/bridges/WorldOfTanksBridge.php b/bridges/WorldOfTanksBridge.php index c59cdaa9..21f37d76 100644 --- a/bridges/WorldOfTanksBridge.php +++ b/bridges/WorldOfTanksBridge.php @@ -38,7 +38,7 @@ class WorldOfTanksBridge extends BridgeAbstract { } public function getName(){ - return $this->title ?: self::NAME; + return $this->title ?: parent::getName(); } public function collectData(){ diff --git a/lib/FeedExpander.php b/lib/FeedExpander.php index c66ca728..eb9940f2 100644 --- a/lib/FeedExpander.php +++ b/lib/FeedExpander.php @@ -194,6 +194,6 @@ abstract class FeedExpander extends BridgeAbstract { } public function getName(){ - return $this->name; + return $this->name ?: parent::getName(); } } From 512a4f292b48de827357cbef6874d4c5df6d9e20 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Tue, 14 Feb 2017 22:36:33 +0100 Subject: [PATCH 4/4] bridges: Return parent::getURI by default --- bridges/AskfmBridge.php | 6 +++++- bridges/BandcampBridge.php | 6 +++++- bridges/BooruprojectBridge.php | 6 +++++- bridges/DailymotionBridge.php | 1 + bridges/FourchanBridge.php | 6 +++++- bridges/GithubIssueBridge.php | 16 ++++++++++------ bridges/GoComicsBridge.php | 6 +++++- bridges/GooglePlusPostBridge.php | 2 +- bridges/IdenticaBridge.php | 6 +++++- bridges/InstagramBridge.php | 6 +++++- bridges/NovelUpdatesBridge.php | 6 +++++- bridges/OpenClassroomsBridge.php | 6 +++++- bridges/PickyWallpapersBridge.php | 20 ++++++++++++-------- bridges/RTBFBridge.php | 6 +++++- bridges/TwitterBridge.php | 1 + bridges/VkBridge.php | 6 +++++- bridges/WebfailBridge.php | 2 +- bridges/WikipediaBridge.php | 10 +++++++--- bridges/WordPressBridge.php | 2 +- bridges/WorldOfTanksBridge.php | 16 ++++++++++------ lib/FeedExpander.php | 2 +- 21 files changed, 100 insertions(+), 38 deletions(-) diff --git a/bridges/AskfmBridge.php b/bridges/AskfmBridge.php index e871c9c0..7d6639b6 100644 --- a/bridges/AskfmBridge.php +++ b/bridges/AskfmBridge.php @@ -65,6 +65,10 @@ class AskfmBridge extends BridgeAbstract { } public function getURI(){ - return self::URI . urlencode($this->getInput('u')) . '/answers/more?page=0'; + if(!is_null($this->getInput('u'))){ + return self::URI . urlencode($this->getInput('u')) . '/answers/more?page=0'; + } + + return parent::getURI(); } } diff --git a/bridges/BandcampBridge.php b/bridges/BandcampBridge.php index 818a2d08..96c96da9 100644 --- a/bridges/BandcampBridge.php +++ b/bridges/BandcampBridge.php @@ -46,7 +46,11 @@ class BandcampBridge extends BridgeAbstract { } public function getURI(){ - return self::URI . 'tag/' . urlencode($this->getInput('tag')) . '?sort_field=date'; + if(!is_null($this->getInput('tag'))){ + return self::URI . 'tag/' . urlencode($this->getInput('tag')) . '?sort_field=date'; + } + + return parent::getURI(); } public function getName(){ diff --git a/bridges/BooruprojectBridge.php b/bridges/BooruprojectBridge.php index 35b51491..1219b72f 100644 --- a/bridges/BooruprojectBridge.php +++ b/bridges/BooruprojectBridge.php @@ -28,7 +28,11 @@ class BooruprojectBridge extends GelbooruBridge { const PIDBYPAGE = 20; public function getURI(){ - return 'http://' . $this->getInput('i') . '.booru.org/'; + if(!is_null($this->getInput('i'))){ + return 'http://' . $this->getInput('i') . '.booru.org/'; + } + + return parent::getURI(); } public function getName(){ diff --git a/bridges/DailymotionBridge.php b/bridges/DailymotionBridge.php index 566d4a40..15ea52ff 100644 --- a/bridges/DailymotionBridge.php +++ b/bridges/DailymotionBridge.php @@ -116,6 +116,7 @@ class DailymotionBridge extends BridgeAbstract { $uri .= '/' . $this->getInput('pa'); } break; + default: return parent::getURI(); } return $uri; } diff --git a/bridges/FourchanBridge.php b/bridges/FourchanBridge.php index 7a83142e..5cfc6ea4 100644 --- a/bridges/FourchanBridge.php +++ b/bridges/FourchanBridge.php @@ -20,7 +20,11 @@ class FourchanBridge extends BridgeAbstract { )); public function getURI(){ - return static::URI . $this->getInput('c') . '/thread/' . $this->getInput('t'); + if(!is_null($this->getInput('c')) && !is_null($this->getInput('t'))){ + return static::URI . $this->getInput('c') . '/thread/' . $this->getInput('t'); + } + + return parent::getURI(); } public function collectData(){ diff --git a/bridges/GithubIssueBridge.php b/bridges/GithubIssueBridge.php index d1f1cc6f..d008f073 100644 --- a/bridges/GithubIssueBridge.php +++ b/bridges/GithubIssueBridge.php @@ -53,13 +53,17 @@ class GithubIssueBridge extends BridgeAbstract { } public function getURI(){ - $uri = static::URI . $this->getInput('u') . '/' . $this->getInput('p') . '/issues'; - if($this->queriedContext === 'Issue comments'){ - $uri .= '/' . $this->getInput('i'); - } elseif($this->getInput('c')){ - $uri .= '?q=is%3Aissue+sort%3Aupdated-desc'; + if(!is_null($this->getInput('u')) && !is_null($this->getInput('p'))){ + $uri = static::URI . $this->getInput('u') . '/' . $this->getInput('p') . '/issues'; + if($this->queriedContext === 'Issue comments'){ + $uri .= '/' . $this->getInput('i'); + } elseif($this->getInput('c')){ + $uri .= '?q=is%3Aissue+sort%3Aupdated-desc'; + } + return $uri; } - return $uri; + + return parent::getURI(); } protected function extractIssueComment($issueNbr, $title, $comment){ diff --git a/bridges/GoComicsBridge.php b/bridges/GoComicsBridge.php index 851e11fe..d4a6be21 100644 --- a/bridges/GoComicsBridge.php +++ b/bridges/GoComicsBridge.php @@ -42,7 +42,11 @@ class GoComicsBridge extends BridgeAbstract { } public function getURI(){ - return self::URI . urlencode($this->getInput('comicname')); + if(!is_null($this->getInput('comicname'))){ + return self::URI . urlencode($this->getInput('comicname')); + } + + return parent::getURI(); } public function getName(){ diff --git a/bridges/GooglePlusPostBridge.php b/bridges/GooglePlusPostBridge.php index 1ea5e202..39cfb9a0 100644 --- a/bridges/GooglePlusPostBridge.php +++ b/bridges/GooglePlusPostBridge.php @@ -97,6 +97,6 @@ class GooglePlusPostBridge extends BridgeAbstract{ } public function getURI(){ - return $this->_url ?: self::URI; + return $this->_url ?: parent::getURI(); } } diff --git a/bridges/IdenticaBridge.php b/bridges/IdenticaBridge.php index ca101f41..826ff5b9 100644 --- a/bridges/IdenticaBridge.php +++ b/bridges/IdenticaBridge.php @@ -43,6 +43,10 @@ class IdenticaBridge extends BridgeAbstract { } public function getURI(){ - return self::URI . urlencode($this->getInput('u')); + if(!is_null($this->getInput('u'))){ + return self::URI . urlencode($this->getInput('u')); + } + + return parent::getURI(); } } diff --git a/bridges/InstagramBridge.php b/bridges/InstagramBridge.php index 555a2558..2bb94638 100644 --- a/bridges/InstagramBridge.php +++ b/bridges/InstagramBridge.php @@ -61,6 +61,10 @@ class InstagramBridge extends BridgeAbstract { } public function getURI(){ - return self::URI . urlencode($this->getInput('u')); + if(!is_null($this->getInput('u'))){ + return self::URI . urlencode($this->getInput('u')); + } + + return parent::getURI(); } } diff --git a/bridges/NovelUpdatesBridge.php b/bridges/NovelUpdatesBridge.php index 1a5880c7..5a2a8dab 100644 --- a/bridges/NovelUpdatesBridge.php +++ b/bridges/NovelUpdatesBridge.php @@ -17,7 +17,11 @@ class NovelUpdatesBridge extends BridgeAbstract { private $seriesTitle = ''; public function getURI(){ - return static::URI . '/series/' . $this->getInput('n') . '/'; + if(!is_null($this->getInput('n'))){ + return static::URI . '/series/' . $this->getInput('n') . '/'; + } + + return parent::getURI(); } public function collectData(){ diff --git a/bridges/OpenClassroomsBridge.php b/bridges/OpenClassroomsBridge.php index 24afb29c..eb4366cc 100644 --- a/bridges/OpenClassroomsBridge.php +++ b/bridges/OpenClassroomsBridge.php @@ -27,7 +27,11 @@ class OpenClassroomsBridge extends BridgeAbstract { )); public function getURI(){ - return self::URI . '/courses?categories=' . $this->getInput('u') . '&title=&sort=updatedAt+desc'; + if(!is_null($this->getInput('u'))){ + return self::URI . '/courses?categories=' . $this->getInput('u') . '&title=&sort=updatedAt+desc'; + } + + return parent::getURI(); } public function collectData(){ diff --git a/bridges/PickyWallpapersBridge.php b/bridges/PickyWallpapersBridge.php index 43e91c5b..340474e3 100644 --- a/bridges/PickyWallpapersBridge.php +++ b/bridges/PickyWallpapersBridge.php @@ -70,15 +70,19 @@ class PickyWallpapersBridge extends BridgeAbstract { } public function getURI(){ - $subcategory = $this->getInput('s'); - $link = self::URI - . $this->getInput('r') - . '/' - . $this->getInput('c') - . '/' - . $subcategory; + if(!is_null($this->getInput('s')) && !is_null($this->getInput('r')) && !is_null($this->getInput('c'))){ + $subcategory = $this->getInput('s'); + $link = self::URI + . $this->getInput('r') + . '/' + . $this->getInput('c') + . '/' + . $subcategory; - return $link; + return $link; + } + + return parent::getURI(); } public function getName(){ diff --git a/bridges/RTBFBridge.php b/bridges/RTBFBridge.php index 6109704f..d8f5c67b 100644 --- a/bridges/RTBFBridge.php +++ b/bridges/RTBFBridge.php @@ -49,7 +49,11 @@ class RTBFBridge extends BridgeAbstract { } public function getURI(){ - return self::URI . 'detail?id=' . $this->getInput('c'); + if(!is_null($this->getInput('c'))){ + return self::URI . 'detail?id=' . $this->getInput('c'); + } + + return parent::getURI(); } public function getName(){ diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php index 60f2eaed..ef34285b 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -62,6 +62,7 @@ class TwitterBridge extends BridgeAbstract { return self::URI . urlencode($this->getInput('u')) . ($this->getInput('norep') ? '' : '/with_replies'); + default: return parent::getURI(); } } diff --git a/bridges/VkBridge.php b/bridges/VkBridge.php index d32782c4..97987f6b 100644 --- a/bridges/VkBridge.php +++ b/bridges/VkBridge.php @@ -16,7 +16,11 @@ class VkBridge extends BridgeAbstract { ); public function getURI(){ - return static::URI . urlencode($this->getInput('u')); + if(!is_null($this->getInput('u'))){ + return static::URI . urlencode($this->getInput('u')); + } + + return parent::getURI(); } public function collectData(){ diff --git a/bridges/WebfailBridge.php b/bridges/WebfailBridge.php index 55a5a683..46711223 100644 --- a/bridges/WebfailBridge.php +++ b/bridges/WebfailBridge.php @@ -34,7 +34,7 @@ class WebfailBridge extends BridgeAbstract { public function getURI(){ if(is_null($this->getInput('language'))) - return self::URI; + return parent::getURI(); // e.g.: https://en.webfail.com return 'https://' . $this->getInput('language') . '.webfail.com'; diff --git a/bridges/WikipediaBridge.php b/bridges/WikipediaBridge.php index 2410656d..ed024946 100644 --- a/bridges/WikipediaBridge.php +++ b/bridges/WikipediaBridge.php @@ -43,9 +43,13 @@ class WikipediaBridge extends BridgeAbstract { )); public function getURI(){ - return 'https://' - . strtolower($this->getInput('language')) - . '.wikipedia.org'; + if(!is_null($this->getInput('language'))){ + return 'https://' + . strtolower($this->getInput('language')) + . '.wikipedia.org'; + } + + return parent::getURI(); } public function getName(){ diff --git a/bridges/WordPressBridge.php b/bridges/WordPressBridge.php index 40e29e7f..954325e6 100644 --- a/bridges/WordPressBridge.php +++ b/bridges/WordPressBridge.php @@ -56,7 +56,7 @@ class WordPressBridge extends FeedExpander { public function getURI(){ $url = $this->getInput('url'); if(empty($url)){ - $url = static::URI; + $url = parent::getURI(); } return $url; } diff --git a/bridges/WorldOfTanksBridge.php b/bridges/WorldOfTanksBridge.php index 21f37d76..1cc41b73 100644 --- a/bridges/WorldOfTanksBridge.php +++ b/bridges/WorldOfTanksBridge.php @@ -28,13 +28,17 @@ class WorldOfTanksBridge extends BridgeAbstract { private $title = ''; - function getURI(){ - $lang = $this->getInput('lang'); - $uri = self::URI . $lang . '/news/'; - if(!empty($this->getInput('category'))) { - $uri .= 'pc-browser/' . $this->getInput('category') . '/'; + public function getURI(){ + if(!is_null($this->getInput('lang'))){ + $lang = $this->getInput('lang'); + $uri = self::URI . $lang . '/news/'; + if(!empty($this->getInput('category'))) { + $uri .= 'pc-browser/' . $this->getInput('category') . '/'; + } + return $uri; } - return $uri; + + return parent::getURI(); } public function getName(){ diff --git a/lib/FeedExpander.php b/lib/FeedExpander.php index eb9940f2..87545c99 100644 --- a/lib/FeedExpander.php +++ b/lib/FeedExpander.php @@ -190,7 +190,7 @@ abstract class FeedExpander extends BridgeAbstract { } public function getURI(){ - return $this->uri; + return $this->uri ?: parent::getURI(); } public function getName(){