From 4da956f365275d3f4c3a9160883e25362db6a8cb Mon Sep 17 00:00:00 2001 From: teromene Date: Thu, 5 Nov 2015 18:05:46 +0000 Subject: [PATCH 1/2] Updating a few bridges. Adding everybody to the contributors in README.md Signed-off-by: teromene --- README.md | 20 ++++++++++++++++++++ bridges/AnimeUltimeBridge.php | 11 ----------- bridges/CryptomeBridge.php | 12 ------------ bridges/LeBonCoinBridge.php | 13 ------------- bridges/MspabooruBridge.php | 11 ----------- bridges/SoundcloudBridge.php | 12 ------------ bridges/TwitchApiBridge.php | 18 +----------------- 7 files changed, 21 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index 90edc4d..55dfe7e 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,26 @@ Patch/contributors : * [Polopollo](https://github.com/Polopollo) * [16mhz](https://github.com/16mhz) * [kranack](https://github.com/kranack) + * [logmanoriginal](https://github.com/logmanoriginal) + * [polo2ro](https://github.com/polo2ro) + * [Riduidel](https://github.com/Riduidel) + * [superbaillot.net](http://superbaillot.net/) + * [vinzv](https://github.com/vinzv) + * [teromene](https://github.com/teromene) + * [nel50n](https://github.com/nel50n) + * [nyutag](https://github.com/nyutag) + * [ORelio](https://github.com/ORelio) + * [Pitchoule](https://github.com/Pitchoule) + * [pit-fgfjiudghdf](https://github.com/pit-fgfjiudghdf) + * [aledeg](https://github.com/aledeg) + * [alexAubin](https://github.com/alexAubin) + * [cnlpete](https://github.com/cnlpete) + * [corenting](https://github.com/corenting) + * [Daiyousei](https://github.com/Daiyousei) + * [erwang](https://github.com/erwang) + * [gsurrel](https://github.com/gsurrel) + * [kraoc](https://github.com/kraoc) + * [lagaisse](https://github.com/lagaisse) License === diff --git a/bridges/AnimeUltimeBridge.php b/bridges/AnimeUltimeBridge.php index 97955de..68e199e 100644 --- a/bridges/AnimeUltimeBridge.php +++ b/bridges/AnimeUltimeBridge.php @@ -1,15 +1,4 @@ ;Anime=>A;Drama=>D;Tokusatsu=>T") - */ class AnimeUltimeBridge extends BridgeAbstract { private $filter = 'Releases'; diff --git a/bridges/CryptomeBridge.php b/bridges/CryptomeBridge.php index e12e0c3..c76e0aa 100644 --- a/bridges/CryptomeBridge.php +++ b/bridges/CryptomeBridge.php @@ -1,16 +1,4 @@ alsace;Aquitaine=>aquitaine;Auvergne=>auvergne;Basse Normandie=>basse_normandie;Bourgogne=>bourgogne;Bretagne=>bretagne;Centre=>centre;Champagne Ardenne=>champagne_ardenne;Corse=>corse;Franche Comté=>franche_comte;Haute Normandie=>haute_normandie;Ile de France=>ile_de_france;Languedoc Roussillon=>languedoc_roussillon;Limousin=>limousin;Lorraine=>lorraine;Midi Pyrénées=>midi_pyrenees;Nord Pas De Calais=>nord_pas_de_calais;Pays de la Loire=>pays_de_la_loire;Picardie=>picardie;Poitou Charentes=>poitou_charentes;Provence Alpes Côte d'Azur=>provence_alpes_cote_d_azur;Rhône-Alpes=>rhone_alpes;Guadeloupe=>guadeloupe;Martinique=>martinique;Guyane=>guyane;Réunion=>reunion", text|k="Keyword") -*/ - class LeBonCoinBridge extends BridgeAbstract{ public function loadMetadatas() { diff --git a/bridges/MspabooruBridge.php b/bridges/MspabooruBridge.php index f949026..04c378d 100644 --- a/bridges/MspabooruBridge.php +++ b/bridges/MspabooruBridge.php @@ -1,15 +1,4 @@ true;Don't show broadcasts=>false") -* @use2(text|channel="Channel", text|limit="Limit", list|broadcasts="Show broadcasts=>true;Don't show broadcasts=>false") -* -* Description for the API is available on GitHub: https://github.com/justintv/twitch-api -*/ - define('TWITCH_LIMIT', 10); // The default limit define('TWITCH_BROADCASTS', 'false'); // The default flag for broadcasts class TwitchApiBridge extends BridgeAbstract{ - + // for use in the getName function! private $channel; From d033bb51ac7bcaab553c272cb5ce38d6828c39e9 Mon Sep 17 00:00:00 2001 From: teromene Date: Thu, 5 Nov 2015 20:26:48 +0000 Subject: [PATCH 2/2] Little refactoring to reduce logic on index.php. Moved RssExpander as a core logic system to lib/Bridge.php Signed-off-by: teromene --- bridges/Freenews.php | 6 +- bridges/Gawker.php | 4 +- bridges/Les400Culs.php | 9 +-- bridges/RssExpander.php | 68 ------------------ bridges/TheOatMealBridge.php | 6 +- index.php | 134 +++-------------------------------- lib/Bridge.php | 66 +++++++++++++++++ lib/HTMLUtils.php | 119 +++++++++++++++++++++++++++++++ lib/RssBridge.php | 1 + 9 files changed, 201 insertions(+), 212 deletions(-) delete mode 100644 bridges/RssExpander.php create mode 100644 lib/HTMLUtils.php diff --git a/bridges/Freenews.php b/bridges/Freenews.php index e1cf094..ecdd461 100644 --- a/bridges/Freenews.php +++ b/bridges/Freenews.php @@ -1,6 +1,5 @@ toURI(strtolower($param['site'])); } // $this->message("loading feed from ".$this->getURI()); - parent::collectData($param); + parent::collectExpandableDatas($param, $name); } protected function parseRSSItem($newsItem) { diff --git a/bridges/Les400Culs.php b/bridges/Les400Culs.php index 4694f40..36dc0a8 100644 --- a/bridges/Les400Culs.php +++ b/bridges/Les400Culs.php @@ -1,11 +1,7 @@ returnError('There is no $param[\'url\'] for this RSS expander', 404); - } -// $this->message("Loading from ".$param['url']); - // Notice WE DO NOT use cache here on purpose : we want a fresh view of the RSS stream each time - $rssContent = simplexml_load_file($param['url']) or $this->returnError('Could not request '.$param['url'], 404); -// $this->message("loaded RSS from ".$param['url']); - // TODO insert RSS format detection - // we suppose for now, we have some RSS 2.0 - $this->collect_RSS_2_0_data($rssContent); - } - - protected function collect_RSS_2_0_data($rssContent) { - $rssContent = $rssContent->channel[0]; -// $this->message("RSS content is ===========\n".var_export($rssContent, true)."==========="); - $this->load_RSS_2_0_feed_data($rssContent); - foreach($rssContent->item as $item) { -// $this->message("parsing item ".var_export($item, true)); - $this->items[] = $this->parseRSSItem($item); - } - } - - protected function RSS_2_0_time_to_timestamp($item) { - return DateTime::createFromFormat('D, d M Y H:i:s e', $item->pubDate)->getTimestamp(); - } - - // TODO set title, link, description, language, and so on - protected function load_RSS_2_0_feed_data($rssContent) { - $this->name = trim($rssContent->title); - $this->uri = trim($rssContent->link); - $this->description = trim($rssContent->description); - } - - /** - * Method should return, from a source RSS item given by lastRSS, one of our Items objects - * @param $item the input rss item - * @return a RSS-Bridge Item, with (hopefully) the whole content) - */ - abstract protected function parseRSSItem($item); - - - public function getName(){ - return $this->name; - } - - public function getURI(){ - return $this->uri; - } - - public function getDescription() { - return $this->description; - } -} diff --git a/bridges/TheOatMealBridge.php b/bridges/TheOatMealBridge.php index ba431c8..97aae69 100644 --- a/bridges/TheOatMealBridge.php +++ b/bridges/TheOatMealBridge.php @@ -1,7 +1,4 @@ getMessage()); } -function getHelperButtonFormat($value, $name){ - return ''; -} - -function getHelperButtonsFormat($formats){ - $buttons = ''; - foreach( $formats as $name => $infos ) - { - if ( isset($infos['name']) ) - { - $buttons .= getHelperButtonFormat($name, $infos['name']) . PHP_EOL; - } - } - return $buttons; -} - -function displayBridgeCard($bridgeName, $formats, $isActive = true) -{ - - - $bridgeElement = Bridge::create($bridgeName); - if($bridgeElement == false) { - return ""; - } - $bridgeElement->loadMetadatas(); - - $name = ''.$bridgeElement->name.''; - $description = $bridgeElement->description; - - $card = << -

{$name}

-

- {$description} -

-CARD; - - // If we don't have any parameter for the bridge, we print a generic form to load it. - if(count($bridgeElement->parameters) == 0) { - - $card .= '
- - ' . PHP_EOL; - - if ($isActive) - { - $card .= getHelperButtonsFormat($formats); - } - else - { - $card .= 'Inactive'; - } - $card .= '
' . PHP_EOL; - - } - - foreach($bridgeElement->parameters as $parameterName => $parameter) - { - $card .= '
    ' . PHP_EOL; - if(!is_numeric($parameterName)) { - $card .= '
    '.$parameterName.'
    ' . PHP_EOL; - } - $card .= '
    - - ' . PHP_EOL; - - $parameter = json_decode($parameter, true); - - foreach($parameter as $inputEntry) { - - if(!isset($inputEntry['exampleValue'])) $inputEntry['exampleValue'] = ""; - - $idArg = 'arg-' . $bridgeName . '-' . $parameterName . '-' . $inputEntry['identifier']; - - $card .= '' . PHP_EOL; - - if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text') { - $card .= '
    ' . PHP_EOL; - } else if($inputEntry['type'] == 'number') { - $card .= '
    ' . PHP_EOL; - } else if($inputEntry['type'] == 'list') { - $card .= '
    '; - } else if($inputEntry['type'] == 'checkbox') { - - $card .= '
    ' . PHP_EOL; - - } - - } - if ($isActive) - { - $card .= getHelperButtonsFormat($formats); - } - else - { - $card .= 'Inactive'; - } - $card .= '
    ' . PHP_EOL; - - } - - $card .= ''.$bridgeElement->maintainer.''; - $card .= ''; - - return $card; -} - $formats = Format::searchInformation(); ?> @@ -265,23 +146,24 @@ $formats = Format::searchInformation(); $activeFoundBridgeCount = 0; $showInactive = isset($_REQUEST['show_inactive']) && $_REQUEST['show_inactive'] == 1; $inactiveBridges = ''; - foreach(Bridge::listBridges() as $bridgeName) + $bridgeList = Bridge::listBridges(); + foreach($bridgeList as $bridgeName) { - if(BridgeWhitelist($whitelist_selection, $bridgeName)) + if(Bridge::isWhitelisted($whitelist_selection, $bridgeName)) { - echo displayBridgeCard($bridgeName, $formats); + echo HTMLUtils::displayBridgeCard($bridgeName, $formats); $activeFoundBridgeCount++; } elseif ($showInactive) { // inactive bridges - $inactiveBridges .= displayBridgeCard($bridgeName, $formats, false) . PHP_EOL; + $inactiveBridges .= HTMLUtils::displayBridgeCard($bridgeName, $formats, false) . PHP_EOL; } } echo '
    ' . $inactiveBridges; ?> diff --git a/lib/Bridge.php b/lib/Bridge.php index 6ff1c38..9303210 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -293,6 +293,72 @@ class Bridge{ return $listBridge; } + static function isWhitelisted( $whitelist, $name ) { + if(in_array("$name", $whitelist) or in_array("$name.php", $whitelist)) + return TRUE; + else + return FALSE; + } } +abstract class RssExpander extends HttpCachingBridgeAbstract{ + + public $name; + public $uri; + public $description; + + public function collectExpandableDatas(array $param, $name){ + if (empty($name)) { + $this->returnError('There is no $param[\'url\'] for this RSS expander', 404); + } +// $this->message("Loading from ".$param['url']); + // Notice WE DO NOT use cache here on purpose : we want a fresh view of the RSS stream each time + $rssContent = simplexml_load_file($name) or $this->returnError('Could not request '.$name, 404); +// $this->message("loaded RSS from ".$param['url']); + // TODO insert RSS format detection + // we suppose for now, we have some RSS 2.0 + $this->collect_RSS_2_0_data($rssContent); + } + + protected function collect_RSS_2_0_data($rssContent) { + $rssContent = $rssContent->channel[0]; +// $this->message("RSS content is ===========\n".var_export($rssContent, true)."==========="); + $this->load_RSS_2_0_feed_data($rssContent); + foreach($rssContent->item as $item) { +// $this->message("parsing item ".var_export($item, true)); + $this->items[] = $this->parseRSSItem($item); + } + } + + protected function RSS_2_0_time_to_timestamp($item) { + return DateTime::createFromFormat('D, d M Y H:i:s e', $item->pubDate)->getTimestamp(); + } + + // TODO set title, link, description, language, and so on + protected function load_RSS_2_0_feed_data($rssContent) { + $this->name = trim($rssContent->title); + $this->uri = trim($rssContent->link); + $this->description = trim($rssContent->description); + } + + /** + * Method should return, from a source RSS item given by lastRSS, one of our Items objects + * @param $item the input rss item + * @return a RSS-Bridge Item, with (hopefully) the whole content) + */ + abstract protected function parseRSSItem($item); + + + public function getName(){ + return $this->name; + } + + public function getURI(){ + return $this->uri; + } + + public function getDescription() { + return $this->description; + } +} diff --git a/lib/HTMLUtils.php b/lib/HTMLUtils.php new file mode 100644 index 0000000..85c0dbe --- /dev/null +++ b/lib/HTMLUtils.php @@ -0,0 +1,119 @@ +' . $name . ''; + } + + public static function getHelperButtonsFormat($formats){ + $buttons = ''; + foreach( $formats as $name => $infos ) + { + if ( isset($infos['name']) ) + { + $buttons .= HTMLUtils::getHelperButtonFormat($name, $infos['name']) . PHP_EOL; + } + } + return $buttons; + } + + public static function displayBridgeCard($bridgeName, $formats, $isActive = true) + { + + + $bridgeElement = Bridge::create($bridgeName); + if($bridgeElement == false) { + return ""; + } + $bridgeElement->loadMetadatas(); + + $name = ''.$bridgeElement->name.''; + $description = $bridgeElement->description; + + $card = << +

    {$name}

    +

    + {$description} +

    +CARD; + + // If we don't have any parameter for the bridge, we print a generic form to load it. + if(count($bridgeElement->parameters) == 0) { + + $card .= '
    + + ' . PHP_EOL; + + if ($isActive) + { + $card .= HTMLUtils::getHelperButtonsFormat($formats); + } + else + { + $card .= 'Inactive'; + } + $card .= '
    ' . PHP_EOL; + + } + + foreach($bridgeElement->parameters as $parameterName => $parameter) + { + $card .= '
      ' . PHP_EOL; + if(!is_numeric($parameterName)) { + $card .= '
      '.$parameterName.'
      ' . PHP_EOL; + } + $card .= '
      + + ' . PHP_EOL; + + $parameter = json_decode($parameter, true); + + foreach($parameter as $inputEntry) { + + if(!isset($inputEntry['exampleValue'])) $inputEntry['exampleValue'] = ""; + + $idArg = 'arg-' . $bridgeName . '-' . $parameterName . '-' . $inputEntry['identifier']; + + $card .= '' . PHP_EOL; + + if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text') { + $card .= '
      ' . PHP_EOL; + } else if($inputEntry['type'] == 'number') { + $card .= '
      ' . PHP_EOL; + } else if($inputEntry['type'] == 'list') { + $card .= '
      '; + } else if($inputEntry['type'] == 'checkbox') { + + $card .= '
      ' . PHP_EOL; + + } + + } + if ($isActive) + { + $card .= HTMLUtils::getHelperButtonsFormat($formats); + } + else + { + $card .= 'Inactive'; + } + $card .= '
      ' . PHP_EOL; + + } + + $card .= ''.$bridgeElement->maintainer.''; + $card .= ''; + + return $card; + } + + +} +?> diff --git a/lib/RssBridge.php b/lib/RssBridge.php index 5e0824f..a515a4f 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -12,6 +12,7 @@ require __DIR__ . '/Item.php'; require __DIR__ . '/Format.php'; require __DIR__ . '/Bridge.php'; require __DIR__ . '/Cache.php'; +require __DIR__ . '/HTMLUtils.php'; $vendorLibSimpleHtmlDom = __DIR__ . PATH_VENDOR . '/simplehtmldom/simple_html_dom.php'; if( !file_exists($vendorLibSimpleHtmlDom) ){