From 2deef45867dd1cc735dd0e2b8f0a0e5977a030c1 Mon Sep 17 00:00:00 2001 From: teromene Date: Sun, 1 Nov 2015 11:17:36 +0000 Subject: [PATCH] =?UTF-8?q?Premi=C3=A8re=20version=20du=20nouveau=20syst?= =?UTF-8?q?=C3=A8me=20de=20m=C3=A9ta-donn=C3=A9es.=20Voir=20exemple=20dans?= =?UTF-8?q?=20YoutubeBridge.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bridges/YoutubeBridge.php | 77 ++++++++++++++++----- index.php | 138 ++++++++++++++++++++------------------ lib/Bridge.php | 18 +++++ 3 files changed, 150 insertions(+), 83 deletions(-) diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php index 0aa787b..bcc6d2f 100644 --- a/bridges/YoutubeBridge.php +++ b/bridges/YoutubeBridge.php @@ -2,25 +2,70 @@ /** * RssBridgeYoutube * Returns the newest videos -* -* @name Youtube Bridge -* @homepage https://www.youtube.com/ -* @description Returns the 10 newest videos by username/channel/playlist or search -* @maintainer mitsukarenai -* @update 2015-07-08 -* @use1(u="username") -* @use2(c="channel id") -* @use3(p="playlist id") -* @use4(s="search keyword",pa="page") -* -* WARNING: to parse big playlists (over ~90 videos), you need to edit simple_html_dom.php: +* WARNING: to parse big playlists (over ~90 videos), you need to edit simple_html_dom.php: * change: define('MAX_FILE_SIZE', 600000); * into: define('MAX_FILE_SIZE', 900000); (or more) */ -class YoutubeBridge extends BridgeAbstract{ - - private $request; - +class YoutubeBridge extends BridgeAbstract { + + + public function loadMetadatas() { + + $this->name = "Youtube Bridge"; + + $this->homepage = "https://youtube.com"; + $this->description = "Returns the 10 newest videos by username/channel/playlist or search"; + $this->maintainer = "mitsukarenai"; + + $this->parameters["By username"] = + '[ + { + "type" : "text", + "identifier" : "u", + "name" : "username", + "exampleValue" : "test" + } + ]'; + + $this->parameters['By channel id'] = + '[ + { + "type" : "number", + "identifier" : "c", + "name" : "channel id", + "exampleValue" : "15" + } + ]'; + + $this->parameters['By playlist Id'] = + '[ + { + "type" : "number", + "identifier" : "c", + "name" : "playlist id", + "exampleValue" : "15" + } + ]'; + + $this->parameters["Search result"] = + '[ + { + "type" : "text", + "identifier" : "s", + "name" : "search keyword", + "exampleValue" : "test" + + }, + { + "type" : "number", + "identifier" : "pa", + "name" : "page", + "exampleValue" : "1" + + } + ]'; + } + public function collectData(array $param){ function getPublishDate($id) { diff --git a/index.php b/index.php index 75eadda..72ee585 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,5 @@ '.$bridgeInformations['name'].'' : $bridgeInformations['name']; - $description = isset($bridgeInformations['description']) ? $bridgeInformations['description'] : 'No description provided'; + + $bridgeElement = Bridge::create($bridgeName); + $bridgeElement->loadMetadatas(); + + $name = ''.$bridgeElement->name.''; + $description = $bridgeElement->description; + $card = << +

{$name}

{$description}

CARD; - if( isset($bridgeInformations['use']) && count($bridgeInformations['use']) > 0 ) + + // 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 .= '
    ' . PHP_EOL; - foreach($bridgeInformations['use'] as $anUseNum => $anUse) - { - $card .= '
  1. ' . PHP_EOL; - $card .= ' - - ' . PHP_EOL; - - foreach($anUse as $argValue) - { - $idArg = 'arg-' . $bridgeReference . '-' . $anUseNum . '-' . $argValue['query-name']; - if($argValue['type'] == null || $argValue['type'] == "text") { //If we have no type, treat it as a text field for compatibility - $card .= '' . PHP_EOL; - } else if($argValue['type'] == "list") { - $card .= '"; - } - - } - - $card .= '
    '; - - if ($isActive) - { - $card .= getHelperButtonsFormat($formats); - } - else - { - $card .= 'Inactive'; - } - - $card .= '
  2. ' . PHP_EOL; - } - $card .= '
' . PHP_EOL; + $card .= getHelperButtonsFormat($formats); } else { - $card .= '
- - ' . PHP_EOL; - - if ($isActive) - { - $card .= getHelperButtonsFormat($formats); - } - else - { - $card .= 'Inactive'; - } - $card .= '
' . PHP_EOL; + $card .= 'Inactive'; } + $card .= '' . PHP_EOL; + } - $card .= isset($bridgeInformations['maintainer']) ? ''.$bridgeInformations['maintainer'].'' : ''; + foreach($bridgeElement->parameters as $parameterName => $parameter) + { + $card .= '
    ' . PHP_EOL; + $card .= '
    '.$parameterName.'
    ' . PHP_EOL; + $card .= '
    + + ' . PHP_EOL; + + $parameter = json_decode($parameter, true); + + foreach($parameter as $inputEntry) { + + $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; + } + + } + if ($isActive) + { + $card .= getHelperButtonsFormat($formats); + } + else + { + $card .= 'Inactive'; + } + $card .= '
    ' . PHP_EOL; + + } + + $card .= ''.$bridgeElement->maintainer.''; $card .= '
'; return $card; } -$bridges = Bridge::searchInformation(); $formats = Format::searchInformation(); + ?> @@ -257,24 +258,27 @@ $formats = Format::searchInformation(); $activeFoundBridgeCount = 0; $showInactive = isset($_REQUEST['show_inactive']) && $_REQUEST['show_inactive'] == 1; $inactiveBridges = ''; - foreach($bridges as $bridgeReference => $bridgeInformations) + foreach($whitelist_selection as $bridgeName) { - if(BridgeWhitelist($whitelist_selection, $bridgeReference)) + if(BridgeWhitelist($whitelist_selection, $bridgeName)) { - echo displayBridgeCard($bridgeReference, $bridgeInformations, $formats); + echo displayBridgeCard($bridgeName, $formats); $activeFoundBridgeCount++; } elseif ($showInactive) { // inactive bridges - $inactiveBridges .= displayBridgeCard($bridgeReference, $bridgeInformations, $formats, false) . PHP_EOL; + $inactiveBridges .= displayBridgeCard($bridgeName, $formats, false) . PHP_EOL; } } echo '
' . $inactiveBridges; ?> + + diff --git a/lib/Bridge.php b/lib/Bridge.php index f4960b9..e063277 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -9,12 +9,28 @@ interface BridgeInterface{ public function getName(); public function getURI(); public function getCacheDuration(); + public function loadMetadatas(); } abstract class BridgeAbstract implements BridgeInterface{ + protected $cache; protected $items = array(); + public $name = "Bridge sans nom"; + public $homepage = ""; + public $description = 'No description provided'; + public $maintainer = 'No maintainer'; + public $parameters = array(); + + /** + * Loads the Bridge Metadatas + */ + public function loadMetadatas() { + + + } + /** * Launch probative exception */ @@ -30,6 +46,8 @@ abstract class BridgeAbstract implements BridgeInterface{ return $this->items; } + + /** * Defined datas with parameters depending choose bridge * Note : you can defined a cache before with "setCache"