diff --git a/bridges/OpenClassroomsBridge.php b/bridges/OpenClassroomsBridge.php index 9e560f9..39fc87b 100644 --- a/bridges/OpenClassroomsBridge.php +++ b/bridges/OpenClassroomsBridge.php @@ -10,6 +10,7 @@ class OpenClassroomsBridge extends BridgeAbstract{ 'u'=>array( 'name'=>'Catégorie', 'type'=>'list', + 'required'=>true, 'values'=>array( 'Arts & Culture'=>'arts', 'Code'=>'code', @@ -24,21 +25,18 @@ class OpenClassroomsBridge extends BridgeAbstract{ ) )); + public function getURI(){ + return $this->uri.'/courses?categories='.$this->getInput('u').'&' + .'title=&sort=updatedAt+desc'; + } public function collectData(){ - if (empty($this->getInput('u'))) - { - $this->returnServerError('Error: You must chose a category.'); - } - - $html = ''; - $link = 'https://openclassrooms.com/courses?categories='.$this->getInput('u').'&title=&sort=updatedAt+desc'; - - $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request OpenClassrooms.'); + $html = $this->getSimpleHTMLDOM($this->getURI()) + or $this->returnServerError('Could not request OpenClassrooms.'); foreach($html->find('.courseListItem') as $element) { $item = array(); - $item['uri'] = 'https://openclassrooms.com'.$element->find('a', 0)->href; + $item['uri'] = $this->uri.$element->find('a', 0)->href; $item['title'] = $element->find('h3', 0)->plaintext; $item['content'] = $element->find('slidingItem__descriptionContent', 0)->plaintext; $this->items[] = $item; diff --git a/bridges/ParuVenduImmoBridge.php b/bridges/ParuVenduImmoBridge.php index d3c3846..9f1cfd4 100644 --- a/bridges/ParuVenduImmoBridge.php +++ b/bridges/ParuVenduImmoBridge.php @@ -25,30 +25,8 @@ class ParuVenduImmoBridge extends BridgeAbstract public function collectData() { - $html = ''; - $num = 20; - $appartment = '&tbApp=1&tbDup=1&tbChb=1&tbLof=1&tbAtl=1&tbPla=1'; - $maison = '&tbMai=1&tbVil=1&tbCha=1&tbPro=1&tbHot=1&tbMou=1&tbFer=1'; - $link = $this->uri.'/immobilier/annonceimmofo/liste/listeAnnonces?tt=1'.$appartment.$maison; - - if ($this->getInput('minarea')) { - $link .= '&sur0='.urlencode($this->getInput('minarea')); - } - - if ($this->getInput('maxprice')) { - $link .= '&px1='.urlencode($this->getInput('maxprice')); - } - - if ($this->getInput('pa')) { - $link .= '&pa='.urlencode($this->getInput('pa')); - } - - if ($this->getInput('lo')) { - $link .= '&lo='.urlencode($this->getInput('lo')); - } - - $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request paruvendu.'); - + $html = $this->getSimpleHTMLDOM($this->getURI()) + or $this->returnServerError('Could not request paruvendu.'); foreach($html->find('div.annonce a') as $element) { @@ -79,16 +57,38 @@ class ParuVenduImmoBridge extends BridgeAbstract } } + public function getURI(){ + $appartment = '&tbApp=1&tbDup=1&tbChb=1&tbLof=1&tbAtl=1&tbPla=1'; + $maison = '&tbMai=1&tbVil=1&tbCha=1&tbPro=1&tbHot=1&tbMou=1&tbFer=1'; + $link = $this->uri.'/immobilier/annonceimmofo/liste/listeAnnonces?tt=1'.$appartment.$maison; + + if ($this->getInput('minarea')) { + $link .= '&sur0='.urlencode($this->getInput('minarea')); + } + + if ($this->getInput('maxprice')) { + $link .= '&px1='.urlencode($this->getInput('maxprice')); + } + + if ($this->getInput('pa')) { + $link .= '&pa='.urlencode($this->getInput('pa')); + } + + if ($this->getInput('lo')) { + $link .= '&lo='.urlencode($this->getInput('lo')); + } + return $link; + } + public function getName(){ $request=''; - if($this->getInput('minarea') && - !empty($this->getInput('minarea')) - ){ - $request .= ' '.$this->getInput('minarea').' m2'; + $minarea=$this->getInput('minarea'); + if(!empty($minarea)){ + $request .= ' '.$minarea.' m2'; } - if($this->getInput('lo') && - !empty($this->getInput('lo'))){ - $request .= ' In: '.$this->getInput('lo'); + $location=$this->getInput('lo'); + if(!empty($location)){ + $request .= ' In: '.$location; } return 'Paru Vendu Immobilier'.$request; } diff --git a/bridges/PickyWallpapersBridge.php b/bridges/PickyWallpapersBridge.php index 6fa77ca..001cd1d 100644 --- a/bridges/PickyWallpapersBridge.php +++ b/bridges/PickyWallpapersBridge.php @@ -1,73 +1,73 @@ array('name'=>'category'), + 'c'=>array( + 'name'=>'category', + 'required'=>true + ), 's'=>array('name'=>'subcategory'), 'm'=>array( 'name'=>'Max number of wallpapers', + 'defaultValue'=>12, 'type'=>'number' ), 'r'=>array( 'name'=>'resolution', 'exampleValue'=>'1920x1200, 1680x1050,…', + 'defaultValue'=>'1920x1200', 'pattern'=>'[0-9]{3,4}x[0-9]{3,4}' ) )); public function collectData(){ - $html = ''; - if (!$this->getInput('c')) { - $this->returnClientError('You must specify at least a category (?c=...).'); - } else { - $baseUri = 'http://www.pickywallpapers.com'; + $lastpage = 1; + $num = 0; + $max = $this->getInput('m'); + $resolution = $this->getInput('r'); // Wide wallpaper default - $this->category = $this->getInput('c'); - $this->subcategory = $this->getInput('s') ?: ''; - $this->resolution = $this->getInput('r') ?: '1920x1200'; // Wide wallpaper default + for ($page = 1; $page <= $lastpage; $page++) { + $html = $this->getSimpleHTMLDOM($this->getURI().'/page-'.$page.'/') + or $this->returnServerError('No results for this query.'); - $num = 0; - $max = $this->getInput('m') ?: 12; - $lastpage = 1; + if ($page === 1) { + preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches); + $lastpage = min($matches[1], ceil($max/12)); + } - for ($page = 1; $page <= $lastpage; $page++) { - $link = $baseUri.'/'.$this->resolution.'/'.$this->category.'/'.(!empty($this->subcategory)?$this->subcategory.'/':'').'page-'.$page.'/'; - $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('No results for this query.'); + foreach($html->find('.items li img') as $element) { - if ($page === 1) { - preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches); - $lastpage = min($matches[1], ceil($max/12)); - } + $item = array(); + $item['uri'] = str_replace('www', 'wallpaper', $this->uri).'/'.$resolution.'/'.basename($element->src); + $item['timestamp'] = time(); + $item['title'] = $element->alt; + $item['content'] = $item['title'].'
'.$element.''; + $this->items[] = $item; - foreach($html->find('.items li img') as $element) { - - $item = array(); - $item['uri'] = str_replace('www', 'wallpaper', $baseUri).'/'.$this->resolution.'/'.basename($element->src); - $item['timestamp'] = time(); - $item['title'] = $element->alt; - $item['content'] = $item['title'].'
'.$element.''; - $this->items[] = $item; - - $num++; - if ($num >= $max) - break 2; - } + $num++; + if ($num >= $max) + break 2; } } } + public function getURI(){ + $subcategory = $this->getInput('s'); + $link = $this->uri.$this->getInput('r').'/'.$this->getInput('c').'/'.$subcategory; + return $link; + } + public function getName(){ - return 'PickyWallpapers - '.$this->category.(!empty($this->subcategory) ? ' > '.$this->subcategory : '').' ['.$this->resolution.']'; + $subcategory = $this->getInput('s'); + return 'PickyWallpapers - '.$this->getInput('c') + .($subcategory? ' > '.$subcategory : '') + .' ['.$this->getInput('r').']'; } public function getCacheDuration(){ diff --git a/bridges/PinterestBridge.php b/bridges/PinterestBridge.php index 1bd868e..8f12e8b 100644 --- a/bridges/PinterestBridge.php +++ b/bridges/PinterestBridge.php @@ -1,53 +1,41 @@ array( - 'u'=>array('name'=>'username'), - 'b'=>array('name'=>'board') + 'u'=>array( + 'name'=>'username', + 'required'=>true + ), + 'b'=>array( + 'name'=>'board', + 'required'=>true + ) ), 'From search' => array( - 'q'=>array('name'=>'Keyword') + 'q'=>array( + 'name'=>'Keyword', + 'required'=>true + ) ) ); + public function collectData(){ - $html = ''; - if ($this->getInput('u') || $this->getInput('b')) { - - if (empty($this->getInput('u'))) - { - $this->returnClientError('You must specify a Pinterest username (?u=...).'); - } - - if (empty($this->getInput('b'))) - { - $this->returnClientError('You must specify a Pinterest board for this username (?b=...).'); - } - - $this->username = $this->getInput('u'); - $this->board = $this->getInput('b'); - $html = $this->getSimpleHTMLDOM($this->getURI().'/'.urlencode($this->username).'/'.urlencode($this->board)) or $this->returnServerError('Username and/or board not found'); - - } else if ($this->getInput('q')) - { - $this->query = $this->getInput('q'); - $html = $this->getSimpleHTMLDOM($this->getURI().'/search/?q='.urlencode($this->query)) or $this->returnServerError('Could not request Pinterest.'); + $html = $this->getSimpleHTMLDOM($this->getURI()) ; + if(!$html){ + switch($this->queriedContext){ + case 'By username and board': + $this->returnServerError('Username and/or board not found'); + case 'From search': + $this->returnServerError('Could not request Pinterest.'); } - - else { - $this->returnClientError('You must specify a Pinterest username and a board name (?u=...&b=...).'); - } - + } foreach($html->find('div.pinWrapper') as $div) { @@ -60,7 +48,7 @@ class PinterestBridge extends BridgeAbstract{ $item['content'] = ''; - if (isset($this->query)) + if ($this->queriedContext==='From search') { $avatar = $div->find('div.creditImg', 0)->find('img', 0); $avatar = $avatar->getAttribute('data-src'); @@ -86,13 +74,28 @@ class PinterestBridge extends BridgeAbstract{ } } - public function getName(){ + public function getURI(){ + switch($this->queriedContext){ + case 'By username and board': + $uri = $this->uri.urlencode($this->getInput('u')).'/'.urlencode($this->getInput('b')); + break; + case 'From search': + $uri = $this->uri.'search/?q='.urlencode($this->getInput('q')); + break; + } - if (isset($this->query)) - { - return $this->query .' - Pinterest'; - } else { - return $this->username .' - '. $this->board.' - Pinterest'; - } + return $uri; + } + + public function getName(){ + switch($this->queriedContext){ + case 'By username and board': + $specific = $this->getInput('u').'-'.$this->getInput('b'); + break; + case 'From search': + $specific = $this->getInput('q'); + break; + } + return $specific .' - '.$this->name; } } diff --git a/bridges/PlanetLibreBridge.php b/bridges/PlanetLibreBridge.php index bfafb48..6e2024f 100644 --- a/bridges/PlanetLibreBridge.php +++ b/bridges/PlanetLibreBridge.php @@ -13,7 +13,8 @@ class PlanetLibreBridge extends BridgeAbstract{ } public function collectData(){ - $html = $this->getSimpleHTMLDOM('http://www.planet-libre.org/') or $this->returnServerError('Could not request PlanetLibre.'); + $html = $this->getSimpleHTMLDOM($this->uri) + or $this->returnServerError('Could not request PlanetLibre.'); $limit = 0; foreach($html->find('div.post') as $element) { if($limit < 5) { diff --git a/bridges/ProjectMGameBridge.php b/bridges/ProjectMGameBridge.php index b7130a2..dad98dd 100644 --- a/bridges/ProjectMGameBridge.php +++ b/bridges/ProjectMGameBridge.php @@ -8,12 +8,12 @@ class ProjectMGameBridge extends BridgeAbstract{ public function collectData(){ - $html = ''; - $html = $this->getSimpleHTMLDOM('http://projectmgame.com/en/') or $this->returnServerError('Error while downloading the Project M homepage'); + $html = $this->getSimpleHTMLDOM($this->uri) + or $this->returnServerError('Error while downloading the Project M homepage'); foreach($html->find('article') as $article) { $item = array(); - $item['uri'] = 'http://projectmgame.com/en/'.$article->find('section div.info_block a',0)->href; + $item['uri'] = $this->uri.$article->find('section div.info_block a',0)->href; $item['title'] = $article->find('h1 p',0)->innertext; $p_list = $article->find('section p'); diff --git a/bridges/RTBFBridge.php b/bridges/RTBFBridge.php index 6097dcf..cee0f0e 100644 --- a/bridges/RTBFBridge.php +++ b/bridges/RTBFBridge.php @@ -1,7 +1,7 @@ getInput('c')) { - $html = $this->getSimpleHTMLDOM('http://www.rtbf.be/auvio/emissions/detail?id='.$this->getInput('c')) or $this->returnServerError('Could not request RTBF.'); + $html = $this->getSimpleHTMLDOM($this->getURI()) + or $this->returnServerError('Could not request RTBF.'); - foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) { - if($count < $limit) { - $item = array(); - $item['id'] = $element->getAttribute('data-id'); - $item['uri'] = 'http://www.rtbf.be/auvio/detail?id='.$item['id']; - $thumbnailUriSrcSet = explode(',', $element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset')); - $thumbnailUriLastSrc = end($thumbnailUriSrcSet); - $thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0]; - $item['title'] = trim($element->find('h3',0)->plaintext) . ' - ' . trim($element->find('h4',0)->plaintext); - $item['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime')); - $item['content'] = ''; - $this->items[] = $item; - $count++; - } - } - } - else { - $this->returnClientError('You must specify a series id.'); + foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element) { + if($count >= $limit) { + break; + } + $item = array(); + $item['id'] = $element->getAttribute('data-id'); + $item['uri'] = $this->uri.'detail?id='.$item['id']; + $thumbnailUriSrcSet = explode(',', $element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset')); + $thumbnailUriLastSrc = end($thumbnailUriSrcSet); + $thumbnailUri = explode(' ', $thumbnailUriLastSrc)[0]; + $item['title'] = trim($element->find('h3',0)->plaintext) . ' - ' . trim($element->find('h4',0)->plaintext); + $item['timestamp'] = strtotime($element->find('time', 0)->getAttribute('datetime')); + $item['content'] = ''; + $this->items[] = $item; + $count++; } } + public function getURI(){ + return $this->uri.'detail?id='.$this->getInput('c'); + } + public function getName(){ - return (!empty($this->request) ? $this->request .' - ' : '') .'RTBF Bridge'; + return $this->getInput('c') .' - RTBF Bridge'; } public function getCacheDuration(){ diff --git a/bridges/Releases3DSBridge.php b/bridges/Releases3DSBridge.php index 25ba50b..3e4ccae 100644 --- a/bridges/Releases3DSBridge.php +++ b/bridges/Releases3DSBridge.php @@ -32,84 +32,88 @@ class Releases3DSBridge extends BridgeAbstract { } } - $dataUrl = 'http://3dsdb.com/xml.php'; + $dataUrl = $this->uri.'xml.php'; $xml = $this->getContents($dataUrl) or $this->returnServerError('Could not request 3dsdb: '.$dataUrl); $limit = 0; foreach (array_reverse(explode('', $xml)) as $element) { - if ($limit < 5) { - if (strpos($element, '') !== false) { - - $id = ExtractFromDelimiters($element, '', ''); - $name = ExtractFromDelimiters($element, '', ''); - $publisher = ExtractFromDelimiters($element, '', ''); - $region = ExtractFromDelimiters($element, '', ''); - $group = ExtractFromDelimiters($element, '', ''); - $imagesize = ExtractFromDelimiters($element, '', ''); - $serial = ExtractFromDelimiters($element, '', ''); - $titleid = ExtractFromDelimiters($element, '', ''); - $imgcrc = ExtractFromDelimiters($element, '', ''); - $filename = ExtractFromDelimiters($element, '', ''); - $releasename = ExtractFromDelimiters($element, '', ''); - $trimmedsize = ExtractFromDelimiters($element, '', ''); - $firmware = ExtractFromDelimiters($element, '', ''); - $type = ExtractFromDelimiters($element, '', ''); - $card = ExtractFromDelimiters($element, '', ''); - - if (!empty($releasename)) { - - //Retrieve cover art and short desc from IGN? - $ignResult = false; $ignDescription = ''; $ignLink = ''; $ignDate = time(); $ignCoverArt = ''; - $ignSearchUrl = 'http://www.ign.com/search?q='.urlencode($name); - if ($ignResult = $this->getSimpleHTMLDOM($ignSearchUrl)) { - $ignCoverArt = $ignResult->find('div.search-item-media', 0)->find('img', 0)->src; - $ignDesc = $ignResult->find('div.search-item-description', 0)->plaintext; - $ignLink = $ignResult->find('div.search-item-sub-title', 0)->find('a', 1)->href; - $ignDate = strtotime(trim($ignResult->find('span.publish-date', 0)->plaintext)); - $ignDescription = '
'.$ignDesc.' More at IGN
'; - } - - //Main section : Release description from 3DS database - $releaseDescription = '

Release Details

' - .'Release ID: '.$id.'
' - .'Game Name: '.$name.'
' - .'Publisher: '.$publisher.'
' - .'Region: '.$region.'
' - .'Group: '.$group.'
' - .'Image size: '.(intval($imagesize)/8).'MB
' - .'Serial: '.$serial.'
' - .'Title ID: '.$titleid.'
' - .'Image CRC: '.$imgcrc.'
' - .'File Name: '.$filename.'
' - .'Release Name: '.$releasename.'
' - .'Trimmed size: '.intval(intval($trimmedsize)/1048576).'MB
' - .'Firmware: '.$firmware.'
' - .'Type: '.TypeToString($type).'
' - .'Card: '.CardToString($card).'
'; - - //Build search links section to facilitate release search using search engines - $releaseNameEncoded = urlencode(str_replace(' ', '+', $releasename)); - $searchLinkGoogle = 'https://google.com/?q='.$releaseNameEncoded; - $searchLinkDuckDuckGo = 'https://duckduckgo.com/?q='.$releaseNameEncoded; - $searchLinkQwant = 'https://lite.qwant.com/?q='.$releaseNameEncoded.'&t=web'; - $releaseSearchLinks = '

Search this release

'; - - //Build and add final item with the above three sections - $item = array(); - $item['title'] = $name; - $item['author'] = $publisher; - $item['timestamp'] = $ignDate; - $item['uri'] = empty($ignLink) ? $searchLinkDuckDuckGo : $ignLink; - $item['content'] = $ignDescription.$releaseDescription.$releaseSearchLinks; - $this->items[] = $item; - $limit++; - } - } + if ($limit >= 5) { + break; } + + if (strpos($element, '') === false) { + continue; + } + + $releasename = ExtractFromDelimiters($element, '', ''); + if (empty($releasename)) { + continue; + } + + $id = ExtractFromDelimiters($element, '', ''); + $name = ExtractFromDelimiters($element, '', ''); + $publisher = ExtractFromDelimiters($element, '', ''); + $region = ExtractFromDelimiters($element, '', ''); + $group = ExtractFromDelimiters($element, '', ''); + $imagesize = ExtractFromDelimiters($element, '', ''); + $serial = ExtractFromDelimiters($element, '', ''); + $titleid = ExtractFromDelimiters($element, '', ''); + $imgcrc = ExtractFromDelimiters($element, '', ''); + $filename = ExtractFromDelimiters($element, '', ''); + $trimmedsize = ExtractFromDelimiters($element, '', ''); + $firmware = ExtractFromDelimiters($element, '', ''); + $type = ExtractFromDelimiters($element, '', ''); + $card = ExtractFromDelimiters($element, '', ''); + + //Retrieve cover art and short desc from IGN? + $ignResult = false; $ignDescription = ''; $ignLink = ''; $ignDate = time(); $ignCoverArt = ''; + $ignSearchUrl = 'http://www.ign.com/search?q='.urlencode($name); + if ($ignResult = $this->getSimpleHTMLDOM($ignSearchUrl)) { + $ignCoverArt = $ignResult->find('div.search-item-media', 0)->find('img', 0)->src; + $ignDesc = $ignResult->find('div.search-item-description', 0)->plaintext; + $ignLink = $ignResult->find('div.search-item-sub-title', 0)->find('a', 1)->href; + $ignDate = strtotime(trim($ignResult->find('span.publish-date', 0)->plaintext)); + $ignDescription = '
'.$ignDesc.' More at IGN
'; + } + + //Main section : Release description from 3DS database + $releaseDescription = '

Release Details

' + .'Release ID: '.$id.'
' + .'Game Name: '.$name.'
' + .'Publisher: '.$publisher.'
' + .'Region: '.$region.'
' + .'Group: '.$group.'
' + .'Image size: '.(intval($imagesize)/8).'MB
' + .'Serial: '.$serial.'
' + .'Title ID: '.$titleid.'
' + .'Image CRC: '.$imgcrc.'
' + .'File Name: '.$filename.'
' + .'Release Name: '.$releasename.'
' + .'Trimmed size: '.intval(intval($trimmedsize)/1048576).'MB
' + .'Firmware: '.$firmware.'
' + .'Type: '.TypeToString($type).'
' + .'Card: '.CardToString($card).'
'; + + //Build search links section to facilitate release search using search engines + $releaseNameEncoded = urlencode(str_replace(' ', '+', $releasename)); + $searchLinkGoogle = 'https://google.com/?q='.$releaseNameEncoded; + $searchLinkDuckDuckGo = 'https://duckduckgo.com/?q='.$releaseNameEncoded; + $searchLinkQwant = 'https://lite.qwant.com/?q='.$releaseNameEncoded.'&t=web'; + $releaseSearchLinks = '

Search this release

'; + + //Build and add final item with the above three sections + $item = array(); + $item['title'] = $name; + $item['author'] = $publisher; + $item['timestamp'] = $ignDate; + $item['uri'] = empty($ignLink) ? $searchLinkDuckDuckGo : $ignLink; + $item['content'] = $ignDescription.$releaseDescription.$releaseSearchLinks; + $this->items[] = $item; + $limit++; } } diff --git a/bridges/ReporterreBridge.php b/bridges/ReporterreBridge.php index 8596942..676604b 100644 --- a/bridges/ReporterreBridge.php +++ b/bridges/ReporterreBridge.php @@ -24,7 +24,7 @@ class ReporterreBridge extends BridgeAbstract{ } public function collectData(){ - $html = $this->getSimpleHTMLDOM('http://www.reporterre.net/spip.php?page=backend') or $this->returnServerError('Could not request Reporterre.'); + $html = $this->getSimpleHTMLDOM($this->uri.'spip.php?page=backend') or $this->returnServerError('Could not request Reporterre.'); $limit = 0; foreach($html->find('item') as $element) { diff --git a/bridges/Rule34Bridge.php b/bridges/Rule34Bridge.php index d18297b..436b909 100644 --- a/bridges/Rule34Bridge.php +++ b/bridges/Rule34Bridge.php @@ -15,21 +15,16 @@ class Rule34Bridge extends BridgeAbstract{ )); public function collectData(){ - $page = 0;$tags=''; - if ($this->getInput('p')) { - $page = (int)preg_replace("/[^0-9]/",'', $this->getInput('p')); - $page = $page - 1; - $page = $page * 50; - } - if ($this->getInput('t')) { - $tags = urlencode($this->getInput('t')); - } - $html = $this->getSimpleHTMLDOM("http://rule34.xxx/index.php?page=post&s=list&tags=$tags&pid=$page") or $this->returnServerError('Could not request Rule34.'); + $html = $this->getSimpleHTMLDOM( + $this->uri.'index.php?page=post&s=list&' + .'&pid='.($this->getInput('p')?($this->getInput('p') -1)*50:'') + .'&tags='.urlencode($this->getInput('t')) + ) or $this->returnServerError('Could not request Rule34.'); foreach($html->find('div[class=content] span') as $element) { $item = array(); - $item['uri'] = 'http://rule34.xxx/'.$element->find('a', 0)->href; + $item['uri'] = $this->uri.$element->find('a', 0)->href; $item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute('id')); $item['timestamp'] = time(); $thumbnailUri = $element->find('img', 0)->src; diff --git a/bridges/Rule34pahealBridge.php b/bridges/Rule34pahealBridge.php index 2a4a61d..af3608e 100644 --- a/bridges/Rule34pahealBridge.php +++ b/bridges/Rule34pahealBridge.php @@ -16,19 +16,13 @@ class Rule34pahealBridge extends BridgeAbstract{ public function collectData(){ - $page = 0;$tags=''; - if ($this->getInput('p')) { - $page = (int)preg_replace("/[^0-9]/",'', $this->getInput('p')); - } - if ($this->getInput('t')) { - $tags = urlencode($this->getInput('t')); - } - $html = $this->getSimpleHTMLDOM("http://rule34.paheal.net/post/list/$tags/$page") or $this->returnServerError('Could not request Rule34paheal.'); + $html = $this->getSimpleHTMLDOM($this->uri.'post/list/'.$tags.'/'.$page) + or $this->returnServerError('Could not request Rule34paheal.'); foreach($html->find('div[class=shm-image-list] div[class=shm-thumb]') as $element) { $item = array(); - $item['uri'] = 'http://rule34.paheal.net'.$element->find('a', 0)->href; + $item['uri'] = $this->uri.$element->find('a', 0)->href; $item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->find('img', 0)->getAttribute('id')); $item['timestamp'] = time(); $thumbnailUri = $element->find('img', 0)->src; diff --git a/bridges/SafebooruBridge.php b/bridges/SafebooruBridge.php index 495a839..9397552 100644 --- a/bridges/SafebooruBridge.php +++ b/bridges/SafebooruBridge.php @@ -15,21 +15,15 @@ class SafebooruBridge extends BridgeAbstract{ )); public function collectData(){ - $page = 0;$tags=''; - if ($this->getInput('p')) { - $page = (int)preg_replace("/[^0-9]/",'', $this->getInput('p')); - $page = $page - 1; - $page = $page * 40; - } - if ($this->getInput('t')) { - $tags = urlencode($this->getInput('t')); - } - $html = $this->getSimpleHTMLDOM("http://safebooru.org/index.php?page=post&s=list&tags=$tags&pid=$page") or $this->returnServerError('Could not request Safebooru.'); - + $html = $this->getSimpleHTMLDOM( + $this->uri.'index.php?page=post&s=list&' + .'&pid='.($this->getInput('p')?($this->getInput('p') -1)*40:'') + .'&tags='.urlencode($this->getInput('t')) + ) or $this->returnServerError('Could not request Safebooru.'); foreach($html->find('div[class=content] span') as $element) { $item = array(); - $item['uri'] = 'http://safebooru.org/'.$element->find('a', 0)->href; + $item['uri'] = $this->uri.$element->find('a', 0)->href; $item['postid'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute('id')); $item['timestamp'] = time(); $thumbnailUri = $element->find('img', 0)->src; diff --git a/bridges/SakugabooruBridge.php b/bridges/SakugabooruBridge.php index ab74d6d..c83eee5 100644 --- a/bridges/SakugabooruBridge.php +++ b/bridges/SakugabooruBridge.php @@ -9,20 +9,19 @@ class SakugabooruBridge extends BridgeAbstract{ public $parameters = array( array( 'p'=>array( 'name'=>'page', + 'defaultValue'=>1, 'type'=>'number' ), 't'=>array('name'=>'tags') )); public function collectData(){ - $page = 1;$tags=''; - if ($this->getInput('p')) { - $page = (int)preg_replace("/[^0-9]/",'', $this->getInput('p')); - } - if ($this->getInput('t')) { - $tags = urlencode($this->getInput('t')); - } - $html = $this->getSimpleHTMLDOM("http://sakuga.yshi.org/post?page=$page&tags=$tags") or $this->returnServerError('Could not request Sakugabooru.'); + $html = $this->getSimpleHTMLDOM( + $this->uri.'post?' + .'&page='.$this->getInput('p') + .'&tags='.urlencode($this->getInput('t')) + ) or $this->returnServerError('Could not request Sakugabooru.'); + $input_json = explode('Post.register(', $html); foreach($input_json as $element) $data[] = preg_replace('/}\)(.*)/', '}', $element); @@ -31,7 +30,7 @@ class SakugabooruBridge extends BridgeAbstract{ foreach($data as $datai) { $json = json_decode($datai, TRUE); $item = array(); - $item['uri'] = 'http://sakuga.yshi.org/post/show/'.$json['id']; + $item['uri'] = $this->uri.'/post/show/'.$json['id']; $item['postid'] = $json['id']; $item['timestamp'] = $json['created_at']; $item['imageUri'] = $json['file_url']; diff --git a/bridges/ScmbBridge.php b/bridges/ScmbBridge.php index 9e5997e..0e0974b 100644 --- a/bridges/ScmbBridge.php +++ b/bridges/ScmbBridge.php @@ -8,11 +8,12 @@ class ScmbBridge extends BridgeAbstract{ public function collectData(){ $html = ''; - $html = $this->getSimpleHTMLDOM('http://secouchermoinsbete.fr/') or $this->returnServerError('Could not request Se Coucher Moins Bete.'); + $html = $this->getSimpleHTMLDOM($this->uri) + or $this->returnServerError('Could not request Se Coucher Moins Bete.'); foreach($html->find('article') as $article) { $item = array(); - $item['uri'] = 'http://secouchermoinsbete.fr'.$article->find('p.summary a',0)->href; + $item['uri'] = $this->uri.$article->find('p.summary a',0)->href; $item['title'] = $article->find('header h1 a',0)->innertext; $article->find('span.read-more',0)->outertext=''; // remove text "En savoir plus" from anecdote content diff --git a/bridges/ScoopItBridge.php b/bridges/ScoopItBridge.php index 32bdc47..db42428 100644 --- a/bridges/ScoopItBridge.php +++ b/bridges/ScoopItBridge.php @@ -3,7 +3,7 @@ class ScoopItBridge extends BridgeAbstract{ public $maintainer = "Pitchoule"; public $name = "ScoopIt"; - public $uri = "http://www.scoop.it"; + public $uri = "http://www.scoop.it/"; public $description = "Returns most recent results from ScoopIt."; public $parameters = array( array( @@ -14,23 +14,19 @@ class ScoopItBridge extends BridgeAbstract{ )); public function collectData(){ - $html = ''; - if ($this->getInput('u') != '') { - $this->request = $this->getInput('u'); - $link = 'http://scoop.it/search?q=' .urlencode($this->request); + $this->request = $this->getInput('u'); + $link = $this->uri.'search?q=' .urlencode($this->getInput('u')); - $html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request ScoopIt. for : ' . $link); + $html = $this->getSimpleHTMLDOM($link) + or $this->returnServerError('Could not request ScoopIt. for : ' . $link); - foreach($html->find('div.post-view') as $element) { - $item = array(); - $item['uri'] = $element->find('a', 0)->href; - $item['title'] = preg_replace('~[[:cntrl:]]~', '', $element->find('div.tCustomization_post_title',0)->plaintext); - $item['content'] = preg_replace('~[[:cntrl:]]~', '', $element->find('div.tCustomization_post_description', 0)->plaintext); - $this->items[] = $item; - } - } else { - $this->returnServerError('You must specify a keyword'); - } + foreach($html->find('div.post-view') as $element) { + $item = array(); + $item['uri'] = $element->find('a', 0)->href; + $item['title'] = preg_replace('~[[:cntrl:]]~', '', $element->find('div.tCustomization_post_title',0)->plaintext); + $item['content'] = preg_replace('~[[:cntrl:]]~', '', $element->find('div.tCustomization_post_description', 0)->plaintext); + $this->items[] = $item; + } } public function getCacheDuration(){ diff --git a/bridges/SensCritiqueBridge.php b/bridges/SensCritiqueBridge.php index f3d1a2d..a202e0c 100644 --- a/bridges/SensCritiqueBridge.php +++ b/bridges/SensCritiqueBridge.php @@ -3,7 +3,7 @@ class SensCritiqueBridge extends BridgeAbstract { public $maintainer = "kranack"; public $name = "Sens Critique"; - public $uri = "http://www.senscritique.com"; + public $uri = "http://www.senscritique.com/"; public $description = "Sens Critique news"; public $parameters = array( array( @@ -34,71 +34,27 @@ class SensCritiqueBridge extends BridgeAbstract { )); public function collectData(){ - if (($this->getInput('m') && $this->getInput('m'))) { - $this->collectMoviesData(); - } else if (($this->getInput('s') && $this->getInput('s'))) { - $this->collectSeriesData(); - } else if (($this->getInput('g') && $this->getInput('g'))) { - $this->collectGamesData(); - } else if (($this->getInput('b') && $this->getInput('b'))) { - $this->collectBooksData(); - } else if (($this->getInput('bd') && $this->getInput('bd'))) { - $this->collectBDsData(); - } else if (($this->getInput('mu') && $this->getInput('mu'))) { - $this->collectMusicsData(); - } else { - $this->returnClientError('You must choose a category'); - } + $categories=array(); + foreach($this->parameters[$this->queriedContext] as $category=>$properties){ + if($this->getInput($category)){ + $uri=$this->uri; + switch($category){ + case 'm': $uri.='films/cette-semaine'; break; + case 's': $uri.='series/actualite'; break; + case 'g': $uri.='jeuxvideo/actualite'; break; + case 'b': $uri.='livres/actualite'; break; + case 'bd': $uri.='bd/actualite'; break; + case 'mu': $uri.='musique/actualite'; break; + } + $html = $this->getSimpleHTMLDOM($uri) + or $this->returnServerError('No results for this query.'); + $list = $html->find('ul.elpr-list', 0); + + $this->extractDataFromList($list); + } + } } - private function collectMoviesData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/films/cette-semaine') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectSeriesData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/series/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectGamesData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/jeuxvideo/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectBooksData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/livres/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectBDsData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/bd/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - - private function collectMusicsData() { - $html = ''; - $html = $this->getSimpleHTMLDOM('http://www.senscritique.com/musique/actualite') or $this->returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); - - $this->extractDataFromList($list); - } - private function extractDataFromList($list) { if ($list === null) { $this->returnClientError('Cannot extract data from list'); diff --git a/bridges/SiliconBridge.php b/bridges/SiliconBridge.php index f821bcf..fffccaa 100644 --- a/bridges/SiliconBridge.php +++ b/bridges/SiliconBridge.php @@ -14,8 +14,9 @@ class SiliconBridge extends BridgeAbstract { return $string; } - $feedUrl = 'http://www.silicon.fr/feed'; - $html = $this->getSimpleHTMLDOM($feedUrl) or $this->returnServerError('Could not request Silicon: '.$feedUrl); + $feedUrl = $this->uri.'feed'; + $html = $this->getSimpleHTMLDOM($feedUrl) + or $this->returnServerError('Could not request Silicon: '.$feedUrl); $limit = 0; foreach($html->find('item') as $element) { @@ -25,7 +26,8 @@ class SiliconBridge extends BridgeAbstract { $article_uri = $element->innertext; $article_uri = substr($article_uri, strpos($article_uri, '') + 6); $article_uri = substr($article_uri, 0, strpos($article_uri, '')); - $article_html = $this->getSimpleHTMLDOM($article_uri) or $this->returnServerError('Could not request Silicon: '.$article_uri); + $article_html = $this->getSimpleHTMLDOM($article_uri) + or $this->returnServerError('Could not request Silicon: '.$article_uri); //Build article contents from corresponding elements $thumbnailUri = $element->find('enclosure', 0)->url; diff --git a/bridges/SoundcloudBridge.php b/bridges/SoundcloudBridge.php index be22cd7..55304e5 100644 --- a/bridges/SoundcloudBridge.php +++ b/bridges/SoundcloudBridge.php @@ -3,7 +3,7 @@ class SoundCloudBridge extends BridgeAbstract{ public $maintainer = "kranack"; public $name = "Soundcloud Bridge"; - public $uri = "http://www.soundcloud.com/"; + public $uri = "https://soundcloud.com/"; public $description = "Returns 10 newest music from user profile"; public $parameters = array( array( @@ -33,10 +33,10 @@ class SoundCloudBridge extends BridgeAbstract{ $item['author'] = $tracks[$i]->user->username .' - '. $tracks[$i]->title; $item['title'] = $tracks[$i]->user->username .' - '. $tracks[$i]->title; $item['content'] = '