From a5a959dceda562435599f0023be33d3eb5acd8eb Mon Sep 17 00:00:00 2001 From: teromene Date: Tue, 3 Nov 2015 23:05:10 +0000 Subject: [PATCH] =?UTF-8?q?Correction=20de=20quelques=20bugs=20dans=20les?= =?UTF-8?q?=20bridges,=20qui=20apparaissent=20=C3=A0=20cause=20du=20fait?= =?UTF-8?q?=20qu'ils=20sont=20tous=20instanci=C3=A9s=20lors=20du=20chargem?= =?UTF-8?q?ent=20de=20tout=20les=20bridges.=20R=C3=A9-ajout=20et=20r=C3=A9?= =?UTF-8?q?-utilisation=20de=20getName=20et=20getURI,=20qui=20permettent?= =?UTF-8?q?=20d'avoir=20des=20=C3=A9lements=20dynamiques.=20Changement=20e?= =?UTF-8?q?n=20public=20de=20certaines=20valeurs.=20Changement=20du=20nom?= =?UTF-8?q?=20de=20certaines=20constantes,=20d=C3=A9ja=20utilis=C3=A9s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: teromene --- bridges/ABCTabsBridge.php | 12 ++++++++++++ bridges/AcrimedBridge.php | 11 +++++++++++ bridges/DemoBridge.php | 12 ++++++++++++ bridges/GiphyBridge.php | 2 +- bridges/Les400Culs.php | 4 ++-- bridges/RssExpander.php | 8 ++++---- bridges/SoundcloudBridge.php | 2 +- bridges/TheOatMealBridge.php | 4 ++-- bridges/WhydBridge.php | 2 +- bridges/WordPressBridge.php | 2 +- bridges/WorldOfTanks.php | 4 ++-- index.php | 8 ++++++-- lib/Bridge.php | 21 ++++++++++++++++++++- 13 files changed, 75 insertions(+), 17 deletions(-) diff --git a/bridges/ABCTabsBridge.php b/bridges/ABCTabsBridge.php index ac0772d..7481f3a 100644 --- a/bridges/ABCTabsBridge.php +++ b/bridges/ABCTabsBridge.php @@ -30,6 +30,18 @@ class ABCTabsBridge extends BridgeAbstract{ } } + public function getName() { + + return "ABC Tabs Bridge"; + + } + + public function getURI() { + + return "http://www.abc-tabs.com/"; + + } + public function getCacheDuration(){ return 3600; // 1 hour } diff --git a/bridges/AcrimedBridge.php b/bridges/AcrimedBridge.php index ae573f8..d0f5abf 100644 --- a/bridges/AcrimedBridge.php +++ b/bridges/AcrimedBridge.php @@ -39,6 +39,17 @@ class AcrimedBridge extends BridgeAbstract{ } + public function getName() { + + return "Acrimed Bridge"; + + } + + public function getURI() { + + return "http://www.acrimed.org/"; + + } public function getCacheDuration(){ return 3600*2; // 2 hours diff --git a/bridges/DemoBridge.php b/bridges/DemoBridge.php index 7c87675..24cd389 100644 --- a/bridges/DemoBridge.php +++ b/bridges/DemoBridge.php @@ -55,6 +55,18 @@ class DemoBridge extends BridgeAbstract{ } + public function getName() { + + return "DemoBridge"; + + } + + public function getURI() { + + return "http://github.com/sebsauvage/rss-bridge"; + + } + public function getCacheDuration(){ return 3600; // 1 hour } diff --git a/bridges/GiphyBridge.php b/bridges/GiphyBridge.php index b0a4f89..f3c0d99 100644 --- a/bridges/GiphyBridge.php +++ b/bridges/GiphyBridge.php @@ -12,7 +12,7 @@ * @use2(n="max number of returned items") */ -define(GIPHY_LIMIT, 10); +define('GIPHY_LIMIT', 10); class GiphyBridge extends BridgeAbstract{ diff --git a/bridges/Les400Culs.php b/bridges/Les400Culs.php index dcb17ae..4694f40 100644 --- a/bridges/Les400Culs.php +++ b/bridges/Les400Culs.php @@ -1,7 +1,7 @@ returnError('There is no $param[\'url\'] for this RSS expander', 404); @@ -65,4 +65,4 @@ abstract class RssExpander extends HttpCachingBridgeAbstract{ public function getDescription() { return $this->description; } -} \ No newline at end of file +} diff --git a/bridges/SoundcloudBridge.php b/bridges/SoundcloudBridge.php index 05c807b..7bcc6d0 100644 --- a/bridges/SoundcloudBridge.php +++ b/bridges/SoundcloudBridge.php @@ -14,7 +14,7 @@ class SoundCloudBridge extends BridgeAbstract{ private $request; - private $name; + public $name; const CLIENT_ID = '0aca19eae3843844e4053c6d8fdb7875'; public function collectData(array $param){ diff --git a/bridges/TheOatMealBridge.php b/bridges/TheOatMealBridge.php index 84b6954..7342ec2 100644 --- a/bridges/TheOatMealBridge.php +++ b/bridges/TheOatMealBridge.php @@ -10,11 +10,11 @@ */ require_once 'bridges/RssExpander.php'; define("THE_OATMEAL", "http://theoatmeal.com/"); -define("RSS", "http://feeds.feedburner.com/oatmealfeed"); +define("THE_OATMEAL_RSS", "http://feeds.feedburner.com/oatmealfeed"); class TheOatmealBridge extends RssExpander{ public function collectData(array $param){ - $param['url'] = RSS; + $param['url'] = THE_OATMEAL_RSS; parent::collectData($param); } diff --git a/bridges/WhydBridge.php b/bridges/WhydBridge.php index 9bac7a0..060a7b6 100644 --- a/bridges/WhydBridge.php +++ b/bridges/WhydBridge.php @@ -14,7 +14,7 @@ class WhydBridge extends BridgeAbstract{ private $request; - private $name; + public $name; public function collectData(array $param){ $html = ''; diff --git a/bridges/WordPressBridge.php b/bridges/WordPressBridge.php index a2eee25..2a182df 100644 --- a/bridges/WordPressBridge.php +++ b/bridges/WordPressBridge.php @@ -14,7 +14,7 @@ class WordPressBridge extends BridgeAbstract { private $url; - private $name; + public $name; public function collectData(array $param) { $this->processParams($param); diff --git a/bridges/WorldOfTanks.php b/bridges/WorldOfTanks.php index ccc80bf..f4de477 100644 --- a/bridges/WorldOfTanks.php +++ b/bridges/WorldOfTanks.php @@ -10,8 +10,8 @@ define('WORLD_OF_TANKS', 'http://worldoftanks.eu/'); define('NEWS', '/news/'); class WorldOfTanks extends HttpCachingBridgeAbstract{ private $lang = "fr"; - private $uri = WORLD_OF_TANKS; - private $name = 'World of tanks news'; + public $uri = WORLD_OF_TANKS; + public $name = 'World of tanks news'; public function collectData(array $param){ if (!empty($param['lang'])) { diff --git a/index.php b/index.php index 5a4dea8..30dee33 100644 --- a/index.php +++ b/index.php @@ -102,8 +102,8 @@ try{ $format ->setDatas($bridge->getDatas()) ->setExtraInfos(array( - 'name' => $bridge->name, - 'uri' => $bridge->uri, + 'name' => $bridge->getName(), + 'uri' => $bridge->getURI(), )) ->display(); die; @@ -140,7 +140,11 @@ function getHelperButtonsFormat($formats){ function displayBridgeCard($bridgeName, $formats, $isActive = true) { + $bridgeElement = Bridge::create($bridgeName); + if($bridgeElement == false) { + return ""; + } $bridgeElement->loadMetadatas(); $name = ''.$bridgeElement->name.''; diff --git a/lib/Bridge.php b/lib/Bridge.php index 29ac6d2..b494520 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -8,6 +8,8 @@ interface BridgeInterface{ public function collectData(array $param); public function getCacheDuration(); public function loadMetadatas(); + public function getName(); + public function getURI(); } abstract class BridgeAbstract implements BridgeInterface{ @@ -207,6 +209,19 @@ class Bridge{ throw new \LogicException('Please use ' . __CLASS__ . '::create for new object.'); } + /** + * Checks if a bridge is an instantiable bridge. + * @param string $nameBridge name of the bridge that you want to use + * @return true if it is an instantiable bridge, false otherwise. + */ + static public function isInstantiable($nameBridge) { + + $re = new ReflectionClass($nameBridge); + return $re->IsInstantiable(); + + } + + /** * Create a new bridge object * @param string $nameBridge Defined bridge name you want use @@ -225,7 +240,11 @@ class Bridge{ require_once $pathBridge; - return new $nameBridge(); + if(Bridge::isInstantiable($nameBridge)) { + return new $nameBridge(); + } else { + return FALSE; + } } static public function setDir($dirBridge){