From 60a82b52b722ea163f8f875cd60c540e4598694a Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Fri, 30 Oct 2015 17:45:10 +0100 Subject: [PATCH 1/9] [LeBonCoin] add region selection list --- bridges/LeBonCoinBridge.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/bridges/LeBonCoinBridge.php b/bridges/LeBonCoinBridge.php index e3cc256..f3ac149 100755 --- a/bridges/LeBonCoinBridge.php +++ b/bridges/LeBonCoinBridge.php @@ -3,17 +3,13 @@ * 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). -* Region identifiers : alsace, aquitaine, auvergne, basse_normandie, bourgogne, bretagne, centre, -* champagne_ardenne, corse, franche_comte, haute_normandie, ile_de_france, languedoc_roussillon, -* limousin, lorraine, midi_pyrenees, nord_pas_de_calais, pays_de_la_loire, picardie, -* poitou_charentes, provence_alpes_cote_d_azur, rhone_alpes, guadeloupe, martinique, guyane, reunion. -* 2014-07-22 * * @name LeBonCoin * @homepage http://www.leboncoin.fr * @description Returns most recent results from LeBonCoin for a region and a keyword. * @maintainer 16mhz -* @use1(r="Region identifier", k="Keyword") +* @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", k="Keyword") */ class LeBonCoinBridge extends BridgeAbstract{ From 182be9b57564ba26d7318e281a470768f9b4db68 Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Fri, 30 Oct 2015 17:49:46 +0100 Subject: [PATCH 2/9] [LeBonCoin] -oops- forgot keyword type --- bridges/LeBonCoinBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/LeBonCoinBridge.php b/bridges/LeBonCoinBridge.php index f3ac149..3a1df70 100755 --- a/bridges/LeBonCoinBridge.php +++ b/bridges/LeBonCoinBridge.php @@ -9,7 +9,7 @@ * @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", k="Keyword") +* @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{ From 0eb773148109a38c4b6740e36778afa38e3ee7e3 Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Fri, 30 Oct 2015 18:03:55 +0100 Subject: [PATCH 3/9] [AnimeUltime ] add list selection --- bridges/AnimeUltimeBridge.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bridges/AnimeUltimeBridge.php b/bridges/AnimeUltimeBridge.php index 1b8c745..9c89afe 100644 --- a/bridges/AnimeUltimeBridge.php +++ b/bridges/AnimeUltimeBridge.php @@ -5,10 +5,10 @@ * * @name Anime-Ultime * @homepage http://www.anime-ultime.net/ - * @description Returns the 10 newest releases posted on Anime-Ultime
Type = A (Anime), D (Drama), T (Tokusatsu), or leave empty for everything + * @description Returns the 10 newest releases posted on Anime-Ultime * @maintainer ORelio - * @update 2015-09-07 - * @use1(type="A/D/T/Empty") + * @update 2015-10-30 + * @use1(list|type="everything=>;Anime=>A;Drama=>D;Tokusatsu=>T") */ class AnimeUltimeBridge extends BridgeAbstract { From 42fc08b93d7661083d2043e7a58e31adbda4b028 Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Fri, 30 Oct 2015 18:27:49 +0100 Subject: [PATCH 4/9] [OpenClassrooms] fixed, list selection --- bridges/OpenClassroomsBridge.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bridges/OpenClassroomsBridge.php b/bridges/OpenClassroomsBridge.php index 29db57a..0c8eda7 100644 --- a/bridges/OpenClassroomsBridge.php +++ b/bridges/OpenClassroomsBridge.php @@ -3,32 +3,32 @@ * RssBridgeOpenClassrooms * Retrieve lastest tutorials from OpenClassrooms. * Returns the most recent tutorials, sorting by date (most recent first). -* 2014-05-25 * * @name OpenClassrooms Bridge -* @homepage http://fr.openclassrooms.com/ +* @homepage https://openclassrooms.com/ * @description Returns latest tutorials from OpenClassrooms. * @maintainer sebsauvage -* @use1(u="informatique or sciences") +* @update 2015-10-30 +* @use1(list|u="Arts & Culture=>arts;Code=>code;Design=>design;Entreprise=>business;Numérique=>digital;Sciences=>sciences;Sciences humaines=>humanities;Systèmes d'information=>it;Autres=>others") */ class OpenClassroomsBridge extends BridgeAbstract{ public function collectData(array $param){ - if ($param['u']!='informatique' && $param['u']!='sciences') + if (empty($param['u'])) { - $this->returnError('Error: You must chose "informatique" or "science".', 404); + $this->returnError('Error: You must chose a category.', 404); } $html = ''; - $link = 'http://fr.openclassrooms.com/'.$param['u'].'/cours?title=&sort=updatedAt+desc'; + $link = 'https://openclassrooms.com/courses?categories='.$param['u'].'&title=&sort=updatedAt+desc'; $html = file_get_html($link) or $this->returnError('Could not request OpenClassrooms.', 404); - foreach($html->find('li.col6') as $element) { + foreach($html->find('.courseListItem') as $element) { $item = new \Item(); - $item->uri = 'http://fr.openclassrooms.com'.$element->find('a', 0)->href; - $item->title = $element->find('div.courses-content strong', 0)->innertext; - $item->content = $element->find('span.course-tags', 0)->innertext; + $item->uri = 'https://openclassrooms.com'.$element->find('a', 0)->href; + $item->title = $element->find('h3', 0)->plaintext; + $item->content = $element->find('slidingItem__descriptionContent', 0)->plaintext; $this->items[] = $item; } } @@ -38,7 +38,7 @@ class OpenClassroomsBridge extends BridgeAbstract{ } public function getURI(){ - return 'http://fr.openclassrooms.com'; + return 'https://openclassrooms.com/'; } public function getCacheDuration(){ From 871efdd5ce88cc2339c0a6f5a0a96e5f4b11893c Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Fri, 30 Oct 2015 18:30:58 +0100 Subject: [PATCH 5/9] [TwitchApi] broadcast select list --- bridges/TwitchApiBridge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bridges/TwitchApiBridge.php b/bridges/TwitchApiBridge.php index 7e7f1c4..ae02284 100644 --- a/bridges/TwitchApiBridge.php +++ b/bridges/TwitchApiBridge.php @@ -9,8 +9,8 @@ * @description Returns the newest broadcasts or highlights by channel name using the Twitch API (v3) * @maintainer logmanoriginal * @update 2015-07-14 -* @use1(channel="Channel", broadcasts="true|false") -* @use2(channel="Channel", limit="Limit", broadcasts="true|false") +* @use1(channel="Channel", list|broadcasts="Show broadcasts=>true;Don't show broadcasts=>false") +* @use2(channel="Channel", 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 */ From b339f157c1b3a10ff253333ab951a17a4cd21730 Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Fri, 30 Oct 2015 18:37:01 +0100 Subject: [PATCH 6/9] [WordOfTanks] add language select list --- bridges/TwitchApiBridge.php | 4 ++-- bridges/WorldOfTanks.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bridges/TwitchApiBridge.php b/bridges/TwitchApiBridge.php index ae02284..cedb749 100644 --- a/bridges/TwitchApiBridge.php +++ b/bridges/TwitchApiBridge.php @@ -9,8 +9,8 @@ * @description Returns the newest broadcasts or highlights by channel name using the Twitch API (v3) * @maintainer logmanoriginal * @update 2015-07-14 -* @use1(channel="Channel", list|broadcasts="Show broadcasts=>true;Don't show broadcasts=>false") -* @use2(channel="Channel", limit="Limit", list|broadcasts="Show broadcasts=>true;Don't show broadcasts=>false") +* @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 */ diff --git a/bridges/WorldOfTanks.php b/bridges/WorldOfTanks.php index 80c9f3a..ccc80bf 100644 --- a/bridges/WorldOfTanks.php +++ b/bridges/WorldOfTanks.php @@ -2,9 +2,9 @@ /** * * @name World of Tanks -* @description News about the tank slaughter game. Language can be fr, ? +* @description News about the tank slaughter game. * @update 2015-09-12 -* @use1(lang="Searched language",category="Category id") +* @use1(list|lang="Français=>fr;English=>en;Español=>es;Deutsch=>de;Čeština=>cs;Polski=>pl;Türkçe=>tr",text|category="Category id") */ define('WORLD_OF_TANKS', 'http://worldoftanks.eu/'); define('NEWS', '/news/'); From ba161b0b12a901b655d2ea356625196651c219a9 Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Sat, 31 Oct 2015 13:26:56 +0100 Subject: [PATCH 7/9] [Arte+7] remove-merge bridges, 2 lists for language selection --- .../{Arte7deBridge.php => Arte7Bridge.php} | 32 +++++---- bridges/Arte7frBridge.php | 71 ------------------- 2 files changed, 17 insertions(+), 86 deletions(-) rename bridges/{Arte7deBridge.php => Arte7Bridge.php} (60%) delete mode 100644 bridges/Arte7frBridge.php diff --git a/bridges/Arte7deBridge.php b/bridges/Arte7Bridge.php similarity index 60% rename from bridges/Arte7deBridge.php rename to bridges/Arte7Bridge.php index 55d6dcf..7673c15 100644 --- a/bridges/Arte7deBridge.php +++ b/bridges/Arte7Bridge.php @@ -1,22 +1,22 @@ alle-videos;Aktuelles & Gesellschaft=>aktuelles-gesellschaft;Fernsehfilme & Serien=>fernsehfilme-serien;Kino=>kino;Kunst & Kultur=>kunst-kultur;Popkultur & Alternativ=>popkultur-alternativ;Entdeckung=>entdeckung;Geschichte=>geschichte;Junior=>junior") +* @update 2015-10-31 +* @use1(list|catfr="Toutes les vidéos (français)=>toutes-les-videos;Actu & société=>actu-société;Séries & fiction=>séries-fiction;Cinéma=>cinéma;Arts & spectacles classiques=>arts-spectacles-classiques;Culture pop=>culture-pop;Découverte=>découverte;Histoire=>histoire;Junior=>junior") +* @use2(list|catde="Alle Videos (deutsch)=>alle-videos;Aktuelles & Gesellschaft=>aktuelles-gesellschaft;Fernsehfilme & Serien=>fernsehfilme-serien;Kino=>kino;Kunst & Kultur=>kunst-kultur;Popkultur & Alternativ=>popkultur-alternativ;Entdeckung=>entdeckung;Geschichte=>geschichte;Junior=>junior") */ -class Arte7deBridge extends BridgeAbstract{ +class Arte7Bridge extends BridgeAbstract{ public function collectData(array $param){ - function extractVideoset($category='alle-videos') + function extractVideoset($category='toutes-les-videos', $lang='fr') { - $url = 'http://www.arte.tv/guide/de/plus7/'.$category; + $url = 'http://www.arte.tv/guide/'.$lang.'/plus7/'.$category; $input = file_get_contents($url) or die('Could not request ARTE.'); if(strpos($input, 'categoryVideoSet') !== FALSE) { @@ -34,10 +34,12 @@ class Arte7deBridge extends BridgeAbstract{ return $input; } - $category='alle-videos'; - if (!empty($param['cat'])) - $category=$param['cat']; - $input_json = extractVideoset($category); + $category='toutes-les-videos'; $lang='fr'; + if (!empty($param['catfr'])) + $category=$param['catfr']; + if (!empty($param['catde'])) + { $category=$param['catde']; $lang='de'; } + $input_json = extractVideoset($category, $lang); foreach($input_json['videos'] as $element) { $item = new \Item(); @@ -58,7 +60,7 @@ class Arte7deBridge extends BridgeAbstract{ } public function getName(){ - return 'Arte7de'; + return 'Arte7'; } public function getURI(){ diff --git a/bridges/Arte7frBridge.php b/bridges/Arte7frBridge.php deleted file mode 100644 index f521e85..0000000 --- a/bridges/Arte7frBridge.php +++ /dev/null @@ -1,71 +0,0 @@ -toutes-les-videos;Actu & société=>actu-société;Séries & fiction=>séries-fiction;Cinéma=>cinéma;Arts & spectacles classiques=>arts-spectacles-classiques;Culture pop=>culture-pop;Découverte=>découverte;Histoire=>histoire;Junior=>junior") -*/ -class Arte7frBridge extends BridgeAbstract{ - - public function collectData(array $param){ - - function extractVideoset($category='toutes-les-videos') - { - $url = 'http://www.arte.tv/guide/fr/plus7/'.$category; - $input = file_get_contents($url) or die('Could not request ARTE.'); - if(strpos($input, 'categoryVideoSet') !== FALSE) - { - $input = explode('categoryVideoSet: ', $input); - $input = explode('}},', $input[1]); - $input = $input[0].'}}'; - } - else - { - $input = explode('videoSet: ', $input); - $input = explode('}]},', $input[1]); - $input = $input[0].'}]}'; - } - $input = json_decode($input, TRUE); - return $input; - } - - $category='toutes-les-videos'; - if (!empty($param['cat'])) - $category=$param['cat']; - $input_json = extractVideoset($category); - - foreach($input_json['videos'] as $element) { - $item = new \Item(); - $item->uri = $element['url']; - $item->id = $element['id']; - $hack_broadcast_time = $element['rights_end']; - $hack_broadcast_time = strtok($hack_broadcast_time, 'T'); - $hack_broadcast_time = strtok('T'); - $item->timestamp = strtotime($element['scheduled_on'].'T'.$hack_broadcast_time); - $item->thumbnailUri = $element['thumbnail_url']; - $item->title = $element['title']; - if (!empty($element['subtitle'])) - $item->title = $element['title'].' | '.$element['subtitle']; - $item->duration = round((int)$element['duration']/60); - $item->content = $element['teaser'].'

'.$item->duration.'min
'; - $this->items[] = $item; - } - } - - public function getName(){ - return 'Arte7fr'; - } - - public function getURI(){ - return 'http://www.arte.tv/'; - } - - public function getCacheDuration(){ - return 1800; // 30 minutes - } -} From c204b9d914f075801394bf12c7cd5d7ff155e974 Mon Sep 17 00:00:00 2001 From: teromene Date: Sun, 1 Nov 2015 11:17:36 +0000 Subject: [PATCH 8/9] =?UTF-8?q?Premi=C3=A8re=20version=20du=20nouveau=20sy?= =?UTF-8?q?st=C3=A8me=20de=20m=C3=A9ta-donn=C3=A9es.=20Voir=20exemple=20da?= =?UTF-8?q?ns=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 0ab85e0..494ebb3 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(); + ?> @@ -239,24 +240,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" From 1c869631d67db9b009c23e92f3428e3a42427fbf Mon Sep 17 00:00:00 2001 From: teromene Date: Tue, 3 Nov 2015 14:36:19 +0000 Subject: [PATCH 9/9] =?UTF-8?q?Ajout=20d'options=20multiples=20pour=20les?= =?UTF-8?q?=20m=C3=A9ta-donn=C3=A9es.=20Ajout=20d'un=20bridge=20de=20d?= =?UTF-8?q?=C3=A9monstration,=20DemoBridge.=20Ajout=20d'un=20d=C3=A9but=20?= =?UTF-8?q?de=20documentation=20pour=20cr=C3=A9er=20un=20bridge=20dans=20C?= =?UTF-8?q?REATE=5FBRIDGE.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CREATE_BRIDGE.md | 23 ++++++++++++ bridges/AcrimedBridge.php | 20 +++++----- bridges/Arte7Bridge.php | 40 ++++++++++++++++++++ bridges/DemoBridge.php | 72 +++++++++++++++++++++++++++++++++++ bridges/FacebookBridge.php | 2 +- index.php | 26 +++++++++---- lib/Bridge.php | 77 +++++++------------------------------- 7 files changed, 179 insertions(+), 81 deletions(-) create mode 100644 CREATE_BRIDGE.md create mode 100644 bridges/DemoBridge.php diff --git a/CREATE_BRIDGE.md b/CREATE_BRIDGE.md new file mode 100644 index 0000000..215ae28 --- /dev/null +++ b/CREATE_BRIDGE.md @@ -0,0 +1,23 @@ +# Howto create a bridge + +A bridge is an interface that allows rss-bridge to create a RSS feed from a website. +The bridge is a PHP file, located in the `bridges/` folder. + +##Specifications + +A rss bridge must extend the `BridgeAbstract` class, and implement the following functions : + +* The `loadMetadatas` function, described below, +* The `getCacheDuration` function, describing the time during which rss-bridge will output cached values instead of re-generating a RSS feed. +* The `collectData` function, also described below. + +##The `collectData` function + +This function takes as a parameter an array called `$param`, that is automatically filled with values from the user, according to the values setted in `loadMetadatas`. +This function is the place where all the website scrapping and the RSS feed generation process will go. + +The RSS elements are stored in the class variable `items[]`. + +Every RSS element is an instance of the `Item` class. + + diff --git a/bridges/AcrimedBridge.php b/bridges/AcrimedBridge.php index 97a2e4a..d50a0d6 100644 --- a/bridges/AcrimedBridge.php +++ b/bridges/AcrimedBridge.php @@ -1,6 +1,6 @@ maintainer = "qwertygc"; + $this->name = "Acrimed Bridge"; + $this->uri = "http://www.acrimed.org/"; + $this->description = "Returns the newest articles."; + $this->update = "2014-05-25"; + + } + public function collectData(array $param){ function StripCDATA($string) { $string = str_replace('maintainer = "mitsukarenai"; + $this->name = "Arte +7"; + $this->uri = "http://www.arte.tv/"; + $this->description = "Returns newest videos from ARTE +7"; + $this->update = "2015-10-31"; + $this->parameters["Catégorie (Français)"] = + '[ + { + "type" : "list", + "identifier" : "catfr", + "name" : "Catégorie", + "values" : [ + { + "name" : "Toutes les vidéos (français)", + "value" : "toutes-les-videos" + }, + { + "name" : "Actu & société", + "value" : "actu-société" + }, + { + "name" : "Séries & fiction", + "value" : "séries-fiction" + }, + { + "name" : "Cinéma", + "value" : "cinéma" + } + + ] + + + } + + ]'; + } + + public function collectData(array $param){ function extractVideoset($category='toutes-les-videos', $lang='fr') diff --git a/bridges/DemoBridge.php b/bridges/DemoBridge.php new file mode 100644 index 0000000..df38be6 --- /dev/null +++ b/bridges/DemoBridge.php @@ -0,0 +1,72 @@ +maintainer = "teromene"; + $this->name = "DemoBridge"; + $this->uri = "http://github.com/sebsauvage/rss-bridge"; + $this->description = "Bridge used for demos"; + $this->update = "2015-11-03"; + + $this->parameters['testCheckbox'] = + '[ + { + "type" : "checkbox", + "identifier" : "testCheckbox", + "name" : "test des checkbox" + } + + ]'; + + $this->parameters['testList'] = + '[ + { + "type" : "list", + "identifier" : "testList", + "name" : "test des listes", + "values" : [ + { + "name" : "Test", + "value" : "test" + }, + { + "name" : "Test 2", + "value" : "test2" + } + ] + } + ]'; + $this->parameters['testNumber'] = + '[ + { + "type" : "number", + "identifier" : "testNumber", + "name" : "test des numéros", + "exampleValue" : "1515632" + + } + + ]'; + + } + + public function collectData(array $param){ + + } + + public function getCacheDuration(){ + return 3600; // 1 hour + } +} diff --git a/bridges/FacebookBridge.php b/bridges/FacebookBridge.php index 15f648c..dc37d5e 100644 --- a/bridges/FacebookBridge.php +++ b/bridges/FacebookBridge.php @@ -9,7 +9,7 @@ */ class FacebookBridge extends BridgeAbstract{ - private $name; + public function collectData(array $param){ diff --git a/index.php b/index.php index 494ebb3..5a4dea8 100644 --- a/index.php +++ b/index.php @@ -96,14 +96,14 @@ try{ $bridge->setCache($cache); // just add disable cache to your query to disable caching } $bridge->setDatas($_REQUEST); - + $bridge->loadMetadatas(); // Data transformation $format = Format::create($format); $format ->setDatas($bridge->getDatas()) ->setExtraInfos(array( - 'name' => $bridge->getName(), - 'uri' => $bridge->getURI(), + 'name' => $bridge->name, + 'uri' => $bridge->uri, )) ->display(); die; @@ -143,7 +143,7 @@ function displayBridgeCard($bridgeName, $formats, $isActive = true) $bridgeElement = Bridge::create($bridgeName); $bridgeElement->loadMetadatas(); - $name = ''.$bridgeElement->name.''; + $name = ''.$bridgeElement->name.''; $description = $bridgeElement->description; $card = <<parameters) == 0) { - $card .= '
+ $card .= ' ' . PHP_EOL; @@ -177,7 +177,7 @@ CARD; { $card .= '
    ' . PHP_EOL; $card .= '
    '.$parameterName.'
    ' . PHP_EOL; - $card .= ' + $card .= ' ' . PHP_EOL; @@ -193,6 +193,18 @@ CARD; $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; + } } @@ -240,7 +252,7 @@ $formats = Format::searchInformation(); $activeFoundBridgeCount = 0; $showInactive = isset($_REQUEST['show_inactive']) && $_REQUEST['show_inactive'] == 1; $inactiveBridges = ''; - foreach($whitelist_selection as $bridgeName) + foreach(Bridge::listBridges() as $bridgeName) { if(BridgeWhitelist($whitelist_selection, $bridgeName)) { diff --git a/lib/Bridge.php b/lib/Bridge.php index e063277..29ac6d2 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -6,8 +6,6 @@ interface BridgeInterface{ public function collectData(array $param); - public function getName(); - public function getURI(); public function getCacheDuration(); public function loadMetadatas(); } @@ -18,7 +16,7 @@ abstract class BridgeAbstract implements BridgeInterface{ protected $items = array(); public $name = "Bridge sans nom"; - public $homepage = ""; + public $uri = ""; public $description = 'No description provided'; public $maintainer = 'No maintainer'; public $parameters = array(); @@ -257,74 +255,25 @@ class Bridge{ } /** - * Read bridge dir and catch informations about each bridge depending annotation - * @return array Informations about each bridge + * Lists the available bridges. + * @return array List of the bridges */ - static public function searchInformation(){ + static public function listBridges() { + $pathDirBridge = self::getDir(); - $listBridge = array(); + $dirFiles = scandir($pathDirBridge); - $searchCommonPattern = array('maintainer', 'description', 'homepage', 'name'); - - $dirFiles = scandir($pathDirBridge); if( $dirFiles !== false ){ foreach( $dirFiles as $fileName ){ - if( preg_match('@([^.]+)\.php@U', $fileName, $out) ){ // Is PHP file ? - $infos = array(); // Information about the bridge - $resParse = token_get_all(file_get_contents($pathDirBridge . $fileName)); // Parse PHP file - foreach($resParse as $v){ - if( is_array($v) && $v[0] == T_DOC_COMMENT ){ // Lexer node is COMMENT ? - $commentary = $v[1]; - foreach( $searchCommonPattern as $name){ // Catch information with common pattern - preg_match('#@' . preg_quote($name, '#') . '\s+(.+)#', $commentary, $outComment); - if( isset($outComment[1]) ){ - $infos[$name] = $outComment[1]; - } - } + if( preg_match('@([^.]+)\.php@U', $fileName, $out) ){ + $listBridge[] = $out[1]; + } + } + } - preg_match_all('#@use(?[1-9][0-9]*)\s?\((?.+)\)(?:\r|\n)#', $commentary, $outComment); // Catch specific information about "use". + return $listBridge; + } - if( isset($outComment['args']) && is_array($outComment['args']) ){ - $infos['use'] = array(); - - foreach($outComment['args'] as $num => $args){ // Each use - - preg_match_all('#(?[a-z]+)\|(?[a-z]+)="(?.*)"(?:,|$)#U', $args, $outArg); // Catch arguments for current use - - if(!isset($outArg['name']) || count($outArg['name']) == 0) { - preg_match_all('#(?[a-z]+)="(?.*)"(?:,|$)#U', $args, $outArg); // Catch arguments - } - - - if( isset($outArg['name'])){ - $usePos = $outComment['num'][$num]; // Current use name - if( !isset($infos['use'][$usePos]) ){ // Not information actually for this "use" ? - $infos['use'][$usePos] = array(); - } - - foreach($outArg['name'] as $numArg => $name){ // Each arguments - $infos['use'][$usePos][$name] = array(); - - $infos['use'][$usePos][$name]['query-name'] = $name; - $infos['use'][$usePos][$name]['value'] = $outArg['value'][$numArg]; - $infos['use'][$usePos][$name]['type'] = $outArg['type'][$numArg]; - - } - } - } - } - } - } - - if( isset($infos['name']) ){ // If informations containt at least a name - $listBridge[$out[1]] = $infos; - } - } - } - } - - return $listBridge; - } }