Skip to content

Commit

Permalink
[core + bridges] add BridgeAbstract::$inputs and BridgeAbstract::getI…
Browse files Browse the repository at this point in the history
…nput()

Inputs are not stored in BridgeAbstract::$parameters anymore to separate
static data from dynamic data.
The getInput method allows for more readable code.

Also fix an "undefined index 'global'" notice

Probability of breaking bridges: high !

Signed-off-by: Pierre Mazière <[email protected]>
  • Loading branch information
Pierre Mazière committed Aug 28, 2016
1 parent a4fd7b8 commit 1b3c8a8
Show file tree
Hide file tree
Showing 78 changed files with 303 additions and 385 deletions.
8 changes: 1 addition & 7 deletions bridges/AllocineFRBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ class AllocineFRBridge extends BridgeAbstract{
));

public function collectData(){
$params=$this->parameters[$this->queriedContext];

// Check all parameters
if(!isset($params['category']['value']))
$this->returnClientError('You must specify a valid category (&category= )!');

$category = '';
switch($params['category']['value']){
switch($this->getInput('category')){
case 'faux-raccord':
$this->uri = 'http://www.allocine.fr/video/programme-12284/saison-24580/';
$category = 'Faux Raccord';
Expand Down
7 changes: 3 additions & 4 deletions bridges/AnimeUltimeBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ class AnimeUltimeBridge extends BridgeAbstract {
private $filter = 'Releases';

public function collectData(){
$param=$this->parameters[$this->queriedContext];

//Add type filter if provided
$typeFilter = '';
if (!empty($param['type']['value'])) {
if ($param['type']['value'] == 'A' || $param['type']['value'] == 'D' || $param['type']['value'] == 'T') {
$typeFilter = $param['type']['value'];
if (!empty($this->getInput('type'))) {
if ($this->getInput('type') == 'A' || $this->getInput('type') == 'D' || $this->getInput('type') == 'T') {
$typeFilter = $this->getInput('type');
if ($typeFilter == 'A') { $this->filter = 'Anime'; }
if ($typeFilter == 'D') { $this->filter = 'Drama'; }
if ($typeFilter == 'T') { $this->filter = 'Tokusatsu'; }
Expand Down
9 changes: 4 additions & 5 deletions bridges/Arte7Bridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ protected function extractVideoset($category='toutes-les-videos', $lang='fr'){
}

public function collectData(){
$param=$this->parameters[$this->queriedContext];

$category='toutes-les-videos'; $lang='fr';
if (!empty($param['catfr']['value']))
$category=$param['catfr']['value'];
if (!empty($param['catde']['value']))
{ $category=$param['catde']['value']; $lang='de'; }
if (!empty($this->getInput('catfr')))
$category=$this->getInput('catfr');
if (!empty($this->getInput('catde')))
{ $category=$this->getInput('catde'); $lang='de'; }
$input_json = $this->extractVideoset($category, $lang);

foreach($input_json['videos'] as $element) {
Expand Down
5 changes: 2 additions & 3 deletions bridges/AskfmBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ class AskfmBridge extends BridgeAbstract{
);

public function collectData(){
$param=$this->parameters[$this->queriedContext];
$html = '';
if (isset($param['u']['value'])) {
$this->request = $param['u']['value'];
if (isset($this->getInput('u'))) {
$this->request = $this->getInput('u');
$html = $this->getSimpleHTMLDOM('http://ask.fm/'.urlencode($this->request).'/answers/more?page=0') or $this->returnServerError('Requested username can\'t be found.');
}
else {
Expand Down
8 changes: 3 additions & 5 deletions bridges/BandcampBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ class BandcampBridge extends BridgeAbstract{
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];
$html = '';
if (isset($param['tag']['value'])) {
$html = $this->getSimpleHTMLDOM('http://bandcamp.com/tag/'.urlencode($param['tag']['value']).'?sort_field=date') or $this->returnServerError('No results for this query.');
if (isset($this->getInput('tag'))) {
$html = $this->getSimpleHTMLDOM('http://bandcamp.com/tag/'.urlencode($this->getInput('tag')).'?sort_field=date') or $this->returnServerError('No results for this query.');
}
else {
$this->returnClientError('You must specify tag (/tag/...)');
Expand All @@ -38,9 +37,8 @@ public function collectData(){
}

public function getName(){
$param=$this->parameters[$this->queriedContext];

return (!empty($param['tag']['value']) ? $param['tag']['value'] .' - ' : '') .'Bandcamp Tag';
return (!empty($this->getInput('tag')) ? $this->getInput('tag') .' - ' : '') .'Bandcamp Tag';
}

public function getCacheDuration(){
Expand Down
17 changes: 8 additions & 9 deletions bridges/BooruprojectBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,28 @@ class BooruprojectBridge extends BridgeAbstract{
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];
$page = 0; $tags = '';
if (!empty($param['p']['value'])) {
$page = (int)preg_replace("/[^0-9]/",'', $param['p']['value']);
if (!empty($this->getInput('p'))) {
$page = (int)preg_replace("/[^0-9]/",'', $this->getInput('p'));
$page = $page - 1;
$page = $page * 20;
}
if (!empty($param['t']['value'])) {
$tags = '&tags='.urlencode($param['t']['value']);
if (!empty($this->getInput('t'))) {
$tags = '&tags='.urlencode($this->getInput('t'));
}
if (empty($param['i']['value'])) {
if (empty($this->getInput('i'))) {
$this->returnServerError('Please enter a ***.booru.org instance.');
}
$html = $this->getSimpleHTMLDOM("http://".$param['i']['value'].".booru.org/index.php?page=post&s=list&pid=".$page.$tags) or $this->returnServerError('Could not request Booruproject.');
$html = $this->getSimpleHTMLDOM("http://".$this->getInput('i').".booru.org/index.php?page=post&s=list&pid=".$page.$tags) or $this->returnServerError('Could not request Booruproject.');


foreach($html->find('div[class=content] span') as $element) {
$item = array();
$item['uri'] = 'http://'.$param['i']['value'].'.booru.org/'.$element->find('a', 0)->href;
$item['uri'] = 'http://'.$this->getInput('i').'.booru.org/'.$element->find('a', 0)->href;
$item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->find('a', 0)->getAttribute('id'));
$item['timestamp'] = time();
$item['tags'] = $element->find('img', 0)->getAttribute('title');
$item['title'] = 'Booruproject '.$param['i']['value'].' | '.$item['postid'];
$item['title'] = 'Booruproject '.$this->getInput('i').' | '.$item['postid'];
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $element->find('img', 0)->src . '" /></a><br>Tags: '.$item['tags'];
$this->items[] = $item;
}
Expand Down
6 changes: 2 additions & 4 deletions bridges/CNETBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class CNETBridge extends BridgeAbstract {
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];

function ExtractFromDelimiters($string, $start, $end) {
if (strpos($string, $start) !== false) {
Expand All @@ -38,7 +37,7 @@ function CleanArticle($article_html) {
return $article_html;
}

$pageUrl = 'http://www.cnet.com/'.(empty($param['topic']['value']) ? '' : 'topics/'.$param['topic']['value'].'/');
$pageUrl = 'http://www.cnet.com/'.(empty($this->getInput('topic')) ? '' : 'topics/'.$this->getInput('topic').'/');
$html = $this->getSimpleHTMLDOM($pageUrl) or $this->returnServerError('Could not request CNET: '.$pageUrl);
$limit = 0;

Expand Down Expand Up @@ -70,8 +69,7 @@ function CleanArticle($article_html) {
}

public function getName() {
$param=$this->parameters[$this->queriedContext];
return 'CNET News Bridge'.(empty($param['topic']['value']) ? '' : ' - '.$this->param['topic']['value']);
return 'CNET News Bridge'.(empty($this->getInput('topic')) ? '' : ' - '.$this->param['topic']['value']);
}

public function getCacheDuration() {
Expand Down
9 changes: 4 additions & 5 deletions bridges/CastorusBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ private function ExtractActivityPrice($activity){
}

public function collectData(){
$params=$this->parameters[$this->queriedContext];
if(isset($params['zip']['value']))
$zip_filter = trim($params['zip']['value']);
if(isset($this->getInput('zip')))
$zip_filter = trim($this->getInput('zip'));

if(isset($params['city']['value']))
$city_filter = trim($params['city']['value']);
if(isset($this->getInput('city')))
$city_filter = trim($this->getInput('city'));

$html = $this->getSimpleHTMLDOM($this->uri);

Expand Down
5 changes: 2 additions & 3 deletions bridges/CpasbienBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ class CpasbienBridge extends HttpCachingBridgeAbstract{
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];
$html = '';
if (isset($param['q']['value'])) { /* keyword search mode */
$request = str_replace(" ","-",trim($param['q']['value']));
if (isset($this->getInput('q'))) { /* keyword search mode */
$request = str_replace(" ","-",trim($this->getInput('q')));
$html = $this->getSimpleHTMLDOM($this->uri.'/recherche/'.urlencode($request).'.html') or $this->returnServerError('No results for this query.');
} else {
$this->returnClientError('You must specify a keyword (?q=...).');
Expand Down
5 changes: 2 additions & 3 deletions bridges/CryptomeBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ class CryptomeBridge extends BridgeAbstract{
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];
$html = '';
$num = 20;
$link = 'http://cryptome.org/';
// If you want HTTPS access instead, uncomment the following line:
//$link = 'https://secure.netsolhost.com/cryptome.org/';

$html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request Cryptome.');
if (!empty($param['n']['value'])) { /* number of documents */
$num = min(max(1, $param['n']['value']+0), $num);
if (!empty($this->getInput('n'))) { /* number of documents */
$num = min(max(1, $this->getInput('n')+0), $num);
}


Expand Down
18 changes: 8 additions & 10 deletions bridges/DailymotionBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,36 @@ public function collectData(){
}

public function getName(){
$param=$this->parameters[$this->queriedContext];
switch($this->queriedContext){
case 'By username':
$specific=$param['u']['value'];
$specific=$this->getInput('u');
break;
case 'By playlist id':
$specific=strtok($param['p']['value'], '_');
$specific=strtok($this->getInput('p'), '_');
break;
case 'From search results':
$specific=$param['s']['value'];
$specific=$this->getInput('s');
break;
}

return $specific.' : Dailymotion Bridge';
}

public function getURI(){
$param=$this->parameters[$this->queriedContext];
switch($this->queriedContext){
case 'By username':
$uri='http://www.dailymotion.com/user/'
.urlencode($param['u']['value']).'/1';
.urlencode($this->getInput('u')).'/1';
break;
case 'By playlist id':
$uri='http://www.dailymotion.com/playlist/'
.urlencode(strtok($param['p']['value'], '_'));
.urlencode(strtok($this->getInput('p'), '_'));
break;
case 'From search results':
$uri='http://www.dailymotion.com/search/'
.urlencode($param['s']['value']);
if(isset($param['pa']['value'])){
$uri.='/'.$param['pa']['value'];
.urlencode($this->getInput('s'));
if(isset($this->getInput('pa'))){
$uri.='/'.$this->getInput('pa');
}
break;
}
Expand Down
9 changes: 4 additions & 5 deletions bridges/DanbooruBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ class DanbooruBridge extends BridgeAbstract{
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];
$page = 1;$tags='';
if (isset($param['p']['value'])) {
$page = (int)preg_replace("/[^0-9]/",'', $param['p']['value']);
if (isset($this->getInput('p'))) {
$page = (int)preg_replace("/[^0-9]/",'', $this->getInput('p'));
}
if (isset($param['t']['value'])) {
$tags = urlencode($param['t']['value']);
if (isset($this->getInput('t'))) {
$tags = urlencode($this->getInput('t'));
}
$html = $this->getSimpleHTMLDOM("http://donmai.us/posts?&page=$page&tags=$tags") or $this->returnServerError('Could not request Danbooru.');
foreach($html->find('div[id=posts] article') as $element) {
Expand Down
5 changes: 2 additions & 3 deletions bridges/DauphineLibereBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private function ExtractContent($url, $context) {
}

public function collectData(){
$param=$this->parameters[$this->queriedContext];

// Simulate Mozilla user-agent to fix error 403 (Forbidden)
$opts = array('http' =>
Expand All @@ -50,8 +49,8 @@ public function collectData(){

$context = stream_context_create($opts);

if (isset($param['u']['value'])) { /* user timeline mode */
$this->request = $param['u']['value'];
if (isset($this->getInput('u'))) { /* user timeline mode */
$this->request = $this->getInput('u');
$html = $this->getSimpleHTMLDOM('http://www.ledauphine.com/'.$this->request.'/rss',false,$context) or $this->returnServerError('Could not request DauphineLibere.');
}
else {
Expand Down
9 changes: 4 additions & 5 deletions bridges/DollbooruBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ class DollbooruBridge extends BridgeAbstract{
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];
$page = 0;$tags='';
if (isset($param['p']['value'])) {
$page = (int)preg_replace("/[^0-9]/",'', $param['p']['value']);
if (isset($this->getInput('p'))) {
$page = (int)preg_replace("/[^0-9]/",'', $this->getInput('p'));
}
if (isset($param['t']['value'])) {
$tags = urlencode($param['t']['value']);
if (isset($this->getInput('t'))) {
$tags = urlencode($this->getInput('t'));
}
$html = $this->getSimpleHTMLDOM("http://dollbooru.org/post/list/$tags/$page") or $this->returnServerError('Could not request Dollbooru.');

Expand Down
3 changes: 1 addition & 2 deletions bridges/DuckDuckGoBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ class DuckDuckGoBridge extends BridgeAbstract{
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];
$html = '';
$link = 'http://duckduckgo.com/html/?q='.$param['u']['value'].'+sort:date';
$link = 'http://duckduckgo.com/html/?q='.$this->getInput('u').'+sort:date';

$html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request DuckDuckGo.');

Expand Down
5 changes: 2 additions & 3 deletions bridges/EZTVBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class EZTVBridge extends BridgeAbstract{
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];

// Make timestamp from relative released time in table
function makeTimestamp($relativeReleaseTime){
Expand All @@ -31,11 +30,11 @@ function makeTimestamp($relativeReleaseTime){
}

// Check for ID provided
if (!isset($param['i']['value']))
if (!isset($this->getInput('i')))
$this->returnClientError('You must provide a list of ID (?i=showID1,showID2,...)');

// Loop on show ids
$showList = explode(",",$param['i']['value']);
$showList = explode(",",$this->getInput('i'));
foreach($showList as $showID){

// Get show page
Expand Down
5 changes: 2 additions & 3 deletions bridges/ElsevierBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ private function ExtractArticleContent ($article){
}

public function collectData(){
$param=$this->parameters[$this->queriedContext];
$uri = 'http://www.journals.elsevier.com/' . $param['j']['value'] . '/recent-articles/';
$html = $this->getSimpleHTMLDOM($uri) or $this->returnServerError('No results for Elsevier journal '.$param['j']['value']);
$uri = 'http://www.journals.elsevier.com/' . $this->getInput('j') . '/recent-articles/';
$html = $this->getSimpleHTMLDOM($uri) or $this->returnServerError('No results for Elsevier journal '.$this->getInput('j'));

foreach($html->find('.pod-listing') as $article){
$item = array();
Expand Down
15 changes: 7 additions & 8 deletions bridges/FacebookBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class FacebookBridge extends BridgeAbstract{
));

public function collectData(){
$param=$this->parameters[$this->queriedContext];

//Extract a string using start and end delimiters
function ExtractFromDelimiters($string, $start, $end) {
Expand Down Expand Up @@ -102,11 +101,11 @@ function ExtractFromDelimiters($string, $start, $end) {

//Retrieve page contents
if (is_null($html)) {
if (isset($param['u']['value'])) {
if (!strpos($param['u']['value'], "/")) {
$html = $this->getSimpleHTMLDOM('https://www.facebook.com/'.urlencode($param['u']['value']).'?_fb_noscript=1') or $this->returnServerError('No results for this query.');
if (isset($this->getInput('u'))) {
if (!strpos($this->getInput('u'), "/")) {
$html = $this->getSimpleHTMLDOM('https://www.facebook.com/'.urlencode($this->getInput('u')).'?_fb_noscript=1') or $this->returnServerError('No results for this query.');
} else {
$html = $this->getSimpleHTMLDOM('https://www.facebook.com/pages/'.$param['u']['value'].'?_fb_noscript=1') or $this->returnServerError('No results for this query.');
$html = $this->getSimpleHTMLDOM('https://www.facebook.com/pages/'.$this->getInput('u').'?_fb_noscript=1') or $this->returnServerError('No results for this query.');
}
} else {
$this->returnClientError('You must specify a Facebook username.');
Expand Down Expand Up @@ -146,7 +145,7 @@ function ExtractFromDelimiters($string, $start, $end) {
if(isset($element)) {

$author = str_replace(' | Facebook', '', $html->find('title#pageTitle', 0)->innertext);
$profilePic = 'https://graph.facebook.com/'.$param['u']['value'].'/picture?width=200&amp;height=200';
$profilePic = 'https://graph.facebook.com/'.$this->getInput('u').'/picture?width=200&amp;height=200';
$this->name = $author;

foreach($element->children() as $post) {
Expand Down Expand Up @@ -205,8 +204,8 @@ function ExtractFromDelimiters($string, $start, $end) {
}

public function setDatas(array $param){
if (isset($param['captcha_response']['value']))
unset($param['captcha_response']['value']);
if (isset($this->getInput('captcha_response')))
unset($this->getInput('captcha_response'));
parent::setDatas($param);
}

Expand Down
Loading

0 comments on commit 1b3c8a8

Please sign in to comment.