1
0
Fork 0
forked from blallo/rss-bridge

Correction de quelques bugs dans les bridges, qui apparaissent à cause du fait qu'ils sont tous instanciés lors du chargement de tout les bridges.

Ré-ajout et ré-utilisation de getName et getURI, qui permettent d'avoir des élements dynamiques.
Changement en public de certaines valeurs.
Changement du nom de certaines constantes, déja utilisés.

Signed-off-by: teromene <teromene@teromene.fr>
This commit is contained in:
teromene 2015-11-03 23:05:10 +00:00 committed by Mitsukarenai
parent 11ad75c7e6
commit 2d526f4e0a
13 changed files with 75 additions and 17 deletions

View file

@ -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(){ public function getCacheDuration(){
return 3600; // 1 hour return 3600; // 1 hour
} }

View file

@ -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(){ public function getCacheDuration(){
return 3600*2; // 2 hours return 3600*2; // 2 hours

View file

@ -53,6 +53,18 @@ class DemoBridge extends BridgeAbstract{
public function collectData(array $param){ public function collectData(array $param){
}
public function getName() {
return "DemoBridge";
}
public function getURI() {
return "http://github.com/sebsauvage/rss-bridge";
} }
public function getCacheDuration(){ public function getCacheDuration(){

View file

@ -12,7 +12,7 @@
* @use2(n="max number of returned items") * @use2(n="max number of returned items")
*/ */
define(GIPHY_LIMIT, 10); define('GIPHY_LIMIT', 10);
class GiphyBridge extends BridgeAbstract{ class GiphyBridge extends BridgeAbstract{

View file

@ -1,7 +1,7 @@
<?php <?php
require_once 'bridges/RssExpander.php'; require_once 'bridges/RssExpander.php';
define("SEXE", "http://sexes.blogs.liberation.fr"); define("SEXE", "http://sexes.blogs.liberation.fr");
define("RSS", "http://sexes.blogs.liberation.fr/feeds/"); define("SEXE_FEED", "http://sexes.blogs.liberation.fr/feeds/");
/** /**
* As it seems that Les 400 culs currently offer a full feed, we won't change it content here. * As it seems that Les 400 culs currently offer a full feed, we won't change it content here.
* But I'm ready for the day where it will ... again ... provide some truncated content * But I'm ready for the day where it will ... again ... provide some truncated content
@ -20,7 +20,7 @@ class Les400Culs extends RssExpander{
public function collectData(array $param){ public function collectData(array $param){
$param['url'] = RSS; $param['url'] = SEXE_FEED;
parent::collectData($param); parent::collectData($param);
} }

View file

@ -9,9 +9,9 @@
*/ */
abstract class RssExpander extends HttpCachingBridgeAbstract{ abstract class RssExpander extends HttpCachingBridgeAbstract{
protected $name; public $name;
private $uri; public $uri;
private $description; public $description;
public function collectData(array $param){ public function collectData(array $param){
if (empty($param['url'])) { if (empty($param['url'])) {
$this->returnError('There is no $param[\'url\'] for this RSS expander', 404); $this->returnError('There is no $param[\'url\'] for this RSS expander', 404);

View file

@ -14,7 +14,7 @@
class SoundCloudBridge extends BridgeAbstract{ class SoundCloudBridge extends BridgeAbstract{
private $request; private $request;
private $name; public $name;
const CLIENT_ID = '0aca19eae3843844e4053c6d8fdb7875'; const CLIENT_ID = '0aca19eae3843844e4053c6d8fdb7875';
public function collectData(array $param){ public function collectData(array $param){

View file

@ -10,11 +10,11 @@
*/ */
require_once 'bridges/RssExpander.php'; require_once 'bridges/RssExpander.php';
define("THE_OATMEAL", "http://theoatmeal.com/"); 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{ class TheOatmealBridge extends RssExpander{
public function collectData(array $param){ public function collectData(array $param){
$param['url'] = RSS; $param['url'] = THE_OATMEAL_RSS;
parent::collectData($param); parent::collectData($param);
} }

View file

@ -14,7 +14,7 @@
class WhydBridge extends BridgeAbstract{ class WhydBridge extends BridgeAbstract{
private $request; private $request;
private $name; public $name;
public function collectData(array $param){ public function collectData(array $param){
$html = ''; $html = '';

View file

@ -14,7 +14,7 @@
class WordPressBridge extends BridgeAbstract { class WordPressBridge extends BridgeAbstract {
private $url; private $url;
private $name; public $name;
public function collectData(array $param) { public function collectData(array $param) {
$this->processParams($param); $this->processParams($param);

View file

@ -10,8 +10,8 @@ define('WORLD_OF_TANKS', 'http://worldoftanks.eu/');
define('NEWS', '/news/'); define('NEWS', '/news/');
class WorldOfTanks extends HttpCachingBridgeAbstract{ class WorldOfTanks extends HttpCachingBridgeAbstract{
private $lang = "fr"; private $lang = "fr";
private $uri = WORLD_OF_TANKS; public $uri = WORLD_OF_TANKS;
private $name = 'World of tanks news'; public $name = 'World of tanks news';
public function collectData(array $param){ public function collectData(array $param){
if (!empty($param['lang'])) { if (!empty($param['lang'])) {

View file

@ -120,8 +120,8 @@ try{
$format $format
->setDatas($bridge->getDatas()) ->setDatas($bridge->getDatas())
->setExtraInfos(array( ->setExtraInfos(array(
'name' => $bridge->name, 'name' => $bridge->getName(),
'uri' => $bridge->uri, 'uri' => $bridge->getURI(),
)) ))
->display(); ->display();
die; die;
@ -158,7 +158,11 @@ function getHelperButtonsFormat($formats){
function displayBridgeCard($bridgeName, $formats, $isActive = true) function displayBridgeCard($bridgeName, $formats, $isActive = true)
{ {
$bridgeElement = Bridge::create($bridgeName); $bridgeElement = Bridge::create($bridgeName);
if($bridgeElement == false) {
return "";
}
$bridgeElement->loadMetadatas(); $bridgeElement->loadMetadatas();
$name = '<a href="'.$bridgeElement->uri.'">'.$bridgeElement->name.'</a>'; $name = '<a href="'.$bridgeElement->uri.'">'.$bridgeElement->name.'</a>';

View file

@ -8,6 +8,8 @@ interface BridgeInterface{
public function collectData(array $param); public function collectData(array $param);
public function getCacheDuration(); public function getCacheDuration();
public function loadMetadatas(); public function loadMetadatas();
public function getName();
public function getURI();
} }
abstract class BridgeAbstract implements BridgeInterface{ abstract class BridgeAbstract implements BridgeInterface{
@ -207,6 +209,19 @@ class Bridge{
throw new \LogicException('Please use ' . __CLASS__ . '::create for new object.'); 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 * Create a new bridge object
* @param string $nameBridge Defined bridge name you want use * @param string $nameBridge Defined bridge name you want use
@ -225,7 +240,11 @@ class Bridge{
require_once $pathBridge; require_once $pathBridge;
if(Bridge::isInstantiable($nameBridge)) {
return new $nameBridge(); return new $nameBridge();
} else {
return FALSE;
}
} }
static public function setDir($dirBridge){ static public function setDir($dirBridge){