forked from blallo/rss-bridge
Merge pull request #171 from teromene/new-attribute-system
Quelques changements.
This commit is contained in:
commit
985ce7a35f
16 changed files with 222 additions and 288 deletions
20
README.md
20
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
|
||||
===
|
||||
|
|
|
@ -1,15 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* AnimeUltimeBridge
|
||||
* Returns 10 newest releases posted on Anime-Ultime
|
||||
*
|
||||
* @name Anime-Ultime
|
||||
* @homepage http://www.anime-ultime.net/
|
||||
* @description Returns the 10 newest releases posted on Anime-Ultime
|
||||
* @maintainer ORelio
|
||||
* @update 2015-10-30
|
||||
* @use1(list|type="everything=>;Anime=>A;Drama=>D;Tokusatsu=>T")
|
||||
*/
|
||||
class AnimeUltimeBridge extends BridgeAbstract {
|
||||
|
||||
private $filter = 'Releases';
|
||||
|
|
|
@ -1,16 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* RssBridgeCryptome
|
||||
* Retrieve lastest documents from Cryptome.
|
||||
* Returns the N most recent documents, sorting by date (most recent first).
|
||||
* 2014-05-25
|
||||
*
|
||||
* @name Cryptome
|
||||
* @homepage http://cryptome.org/
|
||||
* @description Returns the N most recent documents.
|
||||
* @maintainer BoboTiG
|
||||
* @use1(n="number")
|
||||
*/
|
||||
class CryptomeBridge extends BridgeAbstract{
|
||||
|
||||
public function loadMetadatas() {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
require_once 'bridges/RssExpander.php';
|
||||
define("RSS", 'http://feeds.feedburner.com/Freenews-Freebox?format=xml');
|
||||
define("FREENEWS_RSS", 'http://feeds.feedburner.com/Freenews-Freebox?format=xml');
|
||||
class Freenews extends RssExpander {
|
||||
|
||||
public function loadMetadatas() {
|
||||
|
@ -21,8 +20,7 @@ class Freenews extends RssExpander {
|
|||
}
|
||||
|
||||
public function collectData(array $param){
|
||||
$param['url'] = RSS;
|
||||
parent::collectData($param);
|
||||
parent::collectExpandableDatas($param, FREENEWS_RSS);
|
||||
}
|
||||
|
||||
protected function parseRSSItem($newsItem) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
require_once 'bridges/RssExpander.php';
|
||||
define("RSS_PREFIX", "http://feeds.gawker.com/");
|
||||
define("RSS_SUFFIX", "/full");
|
||||
|
||||
class Gawker extends RssExpander{
|
||||
|
||||
public function loadMetadatas() {
|
||||
|
@ -34,7 +34,7 @@ class Gawker extends RssExpander{
|
|||
$param['url'] = $this->toURI(strtolower($param['site']));
|
||||
}
|
||||
// $this->message("loading feed from ".$this->getURI());
|
||||
parent::collectData($param);
|
||||
parent::collectExpandableDatas($param, $name);
|
||||
}
|
||||
|
||||
protected function parseRSSItem($newsItem) {
|
||||
|
|
|
@ -1,17 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* RssBridgeLeBonCoin
|
||||
* Search LeBonCoin for most recent ads in a specific region and topic.
|
||||
* Returns the most recent classified ads in results, sorting by date (most recent first).
|
||||
*
|
||||
* @name LeBonCoin
|
||||
* @homepage http://www.leboncoin.fr
|
||||
* @description Returns most recent results from LeBonCoin for a region and a keyword.
|
||||
* @maintainer 16mhz
|
||||
* @update 2015-10-30
|
||||
* @use1(list|r="Alsace=>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() {
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
<?php
|
||||
require_once 'bridges/RssExpander.php';
|
||||
define("SEXE", "http://sexes.blogs.liberation.fr");
|
||||
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.
|
||||
* But I'm ready for the day where it will ... again ... provide some truncated content
|
||||
*/
|
||||
|
||||
class Les400Culs extends RssExpander{
|
||||
|
||||
public function loadMetadatas() {
|
||||
|
@ -20,8 +16,7 @@ class Les400Culs extends RssExpander{
|
|||
|
||||
|
||||
public function collectData(array $param){
|
||||
$param['url'] = SEXE_FEED;
|
||||
parent::collectData($param);
|
||||
parent::collectExpandableDatas($param, SEXE_FEED);
|
||||
}
|
||||
|
||||
protected function parseRSSItem($newsItem) {
|
||||
|
|
|
@ -1,15 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* RssBridgeMspabooru
|
||||
* Returns images from given page
|
||||
* 2014-05-25
|
||||
*
|
||||
* @name Mspabooru
|
||||
* @homepage http://mspabooru.com/
|
||||
* @description Returns images from given page
|
||||
* @maintainer mitsukarenai
|
||||
* @use1(p="page",t="tags")
|
||||
*/
|
||||
class MspabooruBridge extends BridgeAbstract{
|
||||
|
||||
public function loadMetadatas() {
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* A class providing facilities for RSS expansion. The goal here is to facilitate, as much as possible, writing bridges such as FreeNews, Gawker and other ones
|
||||
* @name RssExpander
|
||||
* @description Un bridge générique d'expansion automatique de contenu RSS ... pour tous ces sites qui ont un flux RSS mochement tonqué.
|
||||
* @update 15/03/2015
|
||||
* @use1(url="URL du flux dont vous souhaitez le contenu complet")
|
||||
*/
|
||||
|
||||
abstract class RssExpander extends HttpCachingBridgeAbstract{
|
||||
public $name;
|
||||
public $uri;
|
||||
public $description;
|
||||
public function collectData(array $param){
|
||||
if (empty($param['url'])) {
|
||||
$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($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;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* SoundcloudBridge
|
||||
* Returns the newest music from user
|
||||
*
|
||||
* @name Soundcloud Bridge
|
||||
* @homepage http://www.soundcloud.com/
|
||||
* @description Returns 10 newest music from user profile
|
||||
* @maintainer kranack
|
||||
* @update 2015-09-08
|
||||
* @use1(u="username")
|
||||
*
|
||||
*/
|
||||
class SoundCloudBridge extends BridgeAbstract{
|
||||
|
||||
private $request;
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
<?php
|
||||
|
||||
require_once 'bridges/RssExpander.php';
|
||||
|
||||
define("THE_OATMEAL", "http://theoatmeal.com/");
|
||||
define("THE_OATMEAL_RSS", "http://feeds.feedburner.com/oatmealfeed");
|
||||
|
||||
|
@ -18,8 +15,7 @@ class TheOatmealBridge extends RssExpander{
|
|||
}
|
||||
|
||||
public function collectData(array $param){
|
||||
$param['url'] = THE_OATMEAL_RSS;
|
||||
parent::collectData($param);
|
||||
parent::collectExpandableDatas($param, THE_OATMEAL_RSS);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,20 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* RssBridgeTwitchApi
|
||||
* Returns the newest broadcasts or highlights. Be aware that Twitch deletes broadcasts after
|
||||
* 14 days: http://blog.twitch.tv/2014/08/important-reminder-past-broadcasts-removed-today/
|
||||
*
|
||||
* @name Twitch API Bridge
|
||||
* @homepage http://www.twitch.tv
|
||||
* @description Returns the newest broadcasts or highlights by channel name using the Twitch API (v3)
|
||||
* @maintainer logmanoriginal
|
||||
* @update 2015-07-14
|
||||
* @use1(text|channel="Channel", list|broadcasts="Show broadcasts=>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
|
||||
|
||||
|
|
134
index.php
134
index.php
|
@ -52,16 +52,10 @@ if (!file_exists($whitelist_file)) {
|
|||
}
|
||||
else {
|
||||
$whitelist_selection = explode("\n", file_get_contents($whitelist_file));
|
||||
//Remove the last empty line.
|
||||
array_pop($whitelist_selection);
|
||||
}
|
||||
|
||||
// whitelist control function
|
||||
function BridgeWhitelist( $whitelist, $name ) {
|
||||
if(in_array("$name", $whitelist) or in_array("$name.php", $whitelist))
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
try{
|
||||
require_once __DIR__ . '/lib/RssBridge.php';
|
||||
|
@ -81,7 +75,7 @@ try{
|
|||
unset($_REQUEST['format']);
|
||||
|
||||
// whitelist control
|
||||
if(!BridgeWhitelist($whitelist_selection, $bridge)) {
|
||||
if(!Bridge::isWhitelisted($whitelist_selection, $bridge)) {
|
||||
throw new \HttpException('This bridge is not whitelisted', 401);
|
||||
die;
|
||||
}
|
||||
|
@ -126,119 +120,6 @@ catch(\Exception $e){
|
|||
die($e->getMessage());
|
||||
}
|
||||
|
||||
function getHelperButtonFormat($value, $name){
|
||||
return '<button type="submit" name="format" value="' . $value . '">' . $name . '</button>';
|
||||
}
|
||||
|
||||
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 = '<a href="'.$bridgeElement->uri.'">'.$bridgeElement->name.'</a>';
|
||||
$description = $bridgeElement->description;
|
||||
|
||||
$card = <<<CARD
|
||||
<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
|
||||
<h2>{$name}</h2>
|
||||
<p class="description">
|
||||
{$description}
|
||||
</p>
|
||||
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 .= '<form method="POST" action="?">
|
||||
<input type="hidden" name="action" value="display" />
|
||||
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
|
||||
|
||||
if ($isActive)
|
||||
{
|
||||
$card .= getHelperButtonsFormat($formats);
|
||||
}
|
||||
else
|
||||
{
|
||||
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
||||
}
|
||||
$card .= '</form>' . PHP_EOL;
|
||||
|
||||
}
|
||||
|
||||
foreach($bridgeElement->parameters as $parameterName => $parameter)
|
||||
{
|
||||
$card .= '<ol class="list-use">' . PHP_EOL;
|
||||
if(!is_numeric($parameterName)) {
|
||||
$card .= '<h5>'.$parameterName.'</h5>' . PHP_EOL;
|
||||
}
|
||||
$card .= '<form method="POST" action="?">
|
||||
<input type="hidden" name="action" value="display" />
|
||||
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
|
||||
|
||||
$parameter = json_decode($parameter, true);
|
||||
|
||||
foreach($parameter as $inputEntry) {
|
||||
|
||||
if(!isset($inputEntry['exampleValue'])) $inputEntry['exampleValue'] = "";
|
||||
|
||||
$idArg = 'arg-' . $bridgeName . '-' . $parameterName . '-' . $inputEntry['identifier'];
|
||||
|
||||
$card .= '<label for="' .$idArg. '">' .$inputEntry['name']. ' : </label>' . PHP_EOL;
|
||||
|
||||
if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text') {
|
||||
$card .= '<input id="' . $idArg . '" type="text" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
||||
} else if($inputEntry['type'] == 'number') {
|
||||
$card .= '<input id="' . $idArg . '" type="number" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
||||
} else if($inputEntry['type'] == 'list') {
|
||||
$card .= '<select id="' . $idArg . '" name="' . $inputEntry['name'] . '" >';
|
||||
foreach($inputEntry['values'] as $listValues) {
|
||||
|
||||
$card .= "<option value='" . $listValues['value'] . "'>" . $listValues['name'] . "</option>";
|
||||
|
||||
}
|
||||
$card .= '</select><br >';
|
||||
} else if($inputEntry['type'] == 'checkbox') {
|
||||
|
||||
$card .= '<input id="' . $idArg . '" type="checkbox" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if ($isActive)
|
||||
{
|
||||
$card .= getHelperButtonsFormat($formats);
|
||||
}
|
||||
else
|
||||
{
|
||||
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
||||
}
|
||||
$card .= '</form>' . PHP_EOL;
|
||||
|
||||
}
|
||||
|
||||
$card .= '<span class="maintainer">'.$bridgeElement->maintainer.'</span>';
|
||||
$card .= '</section>';
|
||||
|
||||
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 '<hr />' . $inactiveBridges;
|
||||
?>
|
||||
<footer>
|
||||
<?= $activeFoundBridgeCount; ?>/<?= count($whitelist_selection) ?> active bridges (<a href="?show_inactive=1">Show inactive</a>)<br />
|
||||
<?= $activeFoundBridgeCount; ?>/<?= count($bridgeList) ?> active bridges (<a href="?show_inactive=1">Show inactive</a>)<br />
|
||||
<a href="https://github.com/sebsauvage/rss-bridge">RSS-Bridge alpha 0.2 ~ Public Domain</a>
|
||||
</footer>
|
||||
</body>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
119
lib/HTMLUtils.php
Normal file
119
lib/HTMLUtils.php
Normal file
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
class HTMLUtils {
|
||||
|
||||
public static function getHelperButtonFormat($value, $name){
|
||||
return '<button type="submit" name="format" value="' . $value . '">' . $name . '</button>';
|
||||
}
|
||||
|
||||
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 = '<a href="'.$bridgeElement->uri.'">'.$bridgeElement->name.'</a>';
|
||||
$description = $bridgeElement->description;
|
||||
|
||||
$card = <<<CARD
|
||||
<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
|
||||
<h2>{$name}</h2>
|
||||
<p class="description">
|
||||
{$description}
|
||||
</p>
|
||||
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 .= '<form method="POST" action="?">
|
||||
<input type="hidden" name="action" value="display" />
|
||||
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
|
||||
|
||||
if ($isActive)
|
||||
{
|
||||
$card .= HTMLUtils::getHelperButtonsFormat($formats);
|
||||
}
|
||||
else
|
||||
{
|
||||
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
||||
}
|
||||
$card .= '</form>' . PHP_EOL;
|
||||
|
||||
}
|
||||
|
||||
foreach($bridgeElement->parameters as $parameterName => $parameter)
|
||||
{
|
||||
$card .= '<ol class="list-use">' . PHP_EOL;
|
||||
if(!is_numeric($parameterName)) {
|
||||
$card .= '<h5>'.$parameterName.'</h5>' . PHP_EOL;
|
||||
}
|
||||
$card .= '<form method="POST" action="?">
|
||||
<input type="hidden" name="action" value="display" />
|
||||
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
|
||||
|
||||
$parameter = json_decode($parameter, true);
|
||||
|
||||
foreach($parameter as $inputEntry) {
|
||||
|
||||
if(!isset($inputEntry['exampleValue'])) $inputEntry['exampleValue'] = "";
|
||||
|
||||
$idArg = 'arg-' . $bridgeName . '-' . $parameterName . '-' . $inputEntry['identifier'];
|
||||
|
||||
$card .= '<label for="' .$idArg. '">' .$inputEntry['name']. ' : </label>' . PHP_EOL;
|
||||
|
||||
if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text') {
|
||||
$card .= '<input id="' . $idArg . '" type="text" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
||||
} else if($inputEntry['type'] == 'number') {
|
||||
$card .= '<input id="' . $idArg . '" type="number" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
||||
} else if($inputEntry['type'] == 'list') {
|
||||
$card .= '<select id="' . $idArg . '" name="' . $inputEntry['name'] . '" >';
|
||||
foreach($inputEntry['values'] as $listValues) {
|
||||
|
||||
$card .= "<option value='" . $listValues['value'] . "'>" . $listValues['name'] . "</option>";
|
||||
|
||||
}
|
||||
$card .= '</select><br >';
|
||||
} else if($inputEntry['type'] == 'checkbox') {
|
||||
|
||||
$card .= '<input id="' . $idArg . '" type="checkbox" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if ($isActive)
|
||||
{
|
||||
$card .= HTMLUtils::getHelperButtonsFormat($formats);
|
||||
}
|
||||
else
|
||||
{
|
||||
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
||||
}
|
||||
$card .= '</form>' . PHP_EOL;
|
||||
|
||||
}
|
||||
|
||||
$card .= '<span class="maintainer">'.$bridgeElement->maintainer.'</span>';
|
||||
$card .= '</section>';
|
||||
|
||||
return $card;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
|
@ -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) ){
|
||||
|
|
Loading…
Reference in a new issue