diff --git a/bridges/CryptomeBridge.php b/bridges/CryptomeBridge.php
index 1409ecfa..aedd8bf3 100644
--- a/bridges/CryptomeBridge.php
+++ b/bridges/CryptomeBridge.php
@@ -8,9 +8,10 @@
* @description Returns the N most recent documents.
* @use1(n="number")
*/
-class CryptomeBridge extends BridgeAbstract{
-
- public function collectData(array $param){
+class CryptomeBridge extends BridgeAbstract
+{
+ public function collectData(array $param)
+ {
$html = '';
$num = 90;
$link = 'http://cryptome.org/';
@@ -22,8 +23,8 @@ class CryptomeBridge extends BridgeAbstract{
$num = min(max(1, $param['n']+0), $num);
}
- foreach($html->find('pre') as $element) {
- for ( $i = 0; $i < $num; ++$i ) {
+ foreach ($html->find('pre') as $element) {
+ for ($i = 0; $i < $num; ++$i) {
$item = new \Item();
$item->uri = $link.substr($element->find('a', $i)->href, 20);
$item->title = substr($element->find('b', $i)->plaintext, 22);
@@ -34,15 +35,18 @@ class CryptomeBridge extends BridgeAbstract{
}
}
- public function getName(){
+ public function getName()
+ {
return 'Cryptome';
}
- public function getURI(){
+ public function getURI()
+ {
return 'https://secure.netsolhost.com/cryptome.org/';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 21600; // 6 hours
}
}
diff --git a/bridges/DansTonChatBridge.php b/bridges/DansTonChatBridge.php
index 3bb6e0b4..7473c7de 100644
--- a/bridges/DansTonChatBridge.php
+++ b/bridges/DansTonChatBridge.php
@@ -7,32 +7,36 @@
* @name DansTonChat Bridge
* @description Returns latest quotes from DansTonChat.
*/
-class DansTonChatBridge extends BridgeAbstract{
-
- public function collectData(array $param){
+class DansTonChatBridge extends BridgeAbstract
+{
+ public function collectData(array $param)
+ {
$html = '';
$link = 'http://danstonchat.com/latest.html';
$html = file_get_html($link) or $this->returnError('Could not request DansTonChat.', 404);
- foreach($html->find('div.item') as $element) {
- $item = new \Item();
- $item->uri = $element->find('a', 0)->href;
- $item->title = 'DansTonChat '.$element->find('a', 1)->plaintext;
- $item->content = $element->find('a', 0)->innertext;
- $this->items[] = $item;
+ foreach ($html->find('div.item') as $element) {
+ $item = new \Item();
+ $item->uri = $element->find('a', 0)->href;
+ $item->title = 'DansTonChat '.$element->find('a', 1)->plaintext;
+ $item->content = $element->find('a', 0)->innertext;
+ $this->items[] = $item;
}
}
- public function getName(){
+ public function getName()
+ {
return 'DansTonChat';
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://danstonchat.com';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 21600; // 6 hours
}
}
diff --git a/bridges/DuckDuckGoBridge.php b/bridges/DuckDuckGoBridge.php
index a194a5c7..328fc88c 100644
--- a/bridges/DuckDuckGoBridge.php
+++ b/bridges/DuckDuckGoBridge.php
@@ -8,32 +8,36 @@
* @description Returns most recent results from DuckDuckGo.
* @use1(u="keyword")
*/
-class DuckDuckGoBridge extends BridgeAbstract{
-
- public function collectData(array $param){
+class DuckDuckGoBridge extends BridgeAbstract
+{
+ public function collectData(array $param)
+ {
$html = '';
$link = 'https://duckduckgo.com/html/?q='.$param[u].'+sort:date';
$html = file_get_html($link) or $this->returnError('Could not request DuckDuckGo.', 404);
- foreach($html->find('div.results_links') as $element) {
- $item = new \Item();
- $item->uri = $element->find('a', 0)->href;
- $item->title = $element->find('a', 1)->innertext;
- $item->content = $element->find('div.snippet', 0)->plaintext;
- $this->items[] = $item;
+ foreach ($html->find('div.results_links') as $element) {
+ $item = new \Item();
+ $item->uri = $element->find('a', 0)->href;
+ $item->title = $element->find('a', 1)->innertext;
+ $item->content = $element->find('div.snippet', 0)->plaintext;
+ $this->items[] = $item;
}
}
- public function getName(){
+ public function getName()
+ {
return 'DuckDuckGo';
}
- public function getURI(){
+ public function getURI()
+ {
return 'https://duckduckgo.com';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 21600; // 6 hours
}
}
diff --git a/bridges/FSBridge.php b/bridges/FSBridge.php
index 1ffd25d8..1e7b175a 100644
--- a/bridges/FSBridge.php
+++ b/bridges/FSBridge.php
@@ -6,50 +6,55 @@
* @name Futurasciences
* @description Returns the 20 newest posts from FS (full text)
*/
-class FSBridge extends BridgeAbstract{
+class FSBridge extends BridgeAbstract
+{
+ public function FS_StripCDATA($string)
+ {
+ $string = str_replace('', '', $string);
-
-
-
-
- public function collectData(array $param){
-
- function FS_StripCDATA($string) {
- $string = str_replace('', '', $string);
- return $string;
+ return $string;
}
- function FS_ExtractContent($url) {
- $html2 = file_get_html($url);
- $text = $html2->find('div.fiche-actualite', 0)->innertext;
- return $text;
+
+ public function FS_ExtractContent($url)
+ {
+ $html2 = file_get_html($url);
+ $text = $html2->find('div.fiche-actualite', 0)->innertext;
+
+ return $text;
}
+
+ public function collectData(array $param)
+ {
+
$html = file_get_html('http://www.futura-sciences.com/rss/actualites.xml') or $this->returnError('Could not request Futura Sciences.', 404);
- $limit = 0;
+ $limit = 0;
- foreach($html->find('item') as $element) {
- if($limit < 20) {
- $item = new \Item();
- $item->title = FS_StripCDATA($element->find('title', 0)->innertext);
- $item->uri = FS_StripCDATA($element->find('guid', 0)->plaintext);
- $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
- $item->content = FS_ExtractContent($item->uri);
- $this->items[] = $item;
- $limit++;
- }
- }
-
+ foreach ($html->find('item') as $element) {
+ if ($limit < 20) {
+ $item = new \Item();
+ $item->title = $this->FS_StripCDATA($element->find('title', 0)->innertext);
+ $item->uri = $this->FS_StripCDATA($element->find('guid', 0)->plaintext);
+ $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
+ $item->content = $this->FS_ExtractContent($item->uri);
+ $this->items[] = $item;
+ $limit++;
+ }
+ }
}
- public function getName(){
+ public function getName()
+ {
return 'Futura Sciences';
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://www.futura-sciences.com/';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
// return 3600; // 1 hour
return 0; // 1 hour
}
diff --git a/bridges/FlickrExploreBridge.php b/bridges/FlickrExploreBridge.php
index c3b4976d..e3b535cd 100644
--- a/bridges/FlickrExploreBridge.php
+++ b/bridges/FlickrExploreBridge.php
@@ -1,17 +1,18 @@
returnError('Could not request Flickr.', 404);
-
- foreach($html->find('span.photo_container') as $element) {
+
+ foreach ($html->find('span.photo_container') as $element) {
$item = new \Item();
$item->uri = 'http://flickr.com'.$element->find('a',0)->href;
$item->thumbnailUri = $element->find('img',0)->getAttribute('data-defer-src');
@@ -21,15 +22,18 @@ class FlickrExploreBridge extends BridgeAbstract{
}
}
- public function getName(){
+ public function getName()
+ {
return 'Flickr Explore';
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://www.flickr.com/explore';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 21600; // 6 hours
}
-}
\ No newline at end of file
+}
diff --git a/bridges/GoogleSearchBridge.php b/bridges/GoogleSearchBridge.php
index 7f8f3153..ce100844 100644
--- a/bridges/GoogleSearchBridge.php
+++ b/bridges/GoogleSearchBridge.php
@@ -13,26 +13,26 @@
* @description Returns most recent results from Google search.
* @use1(q="keyword")
*/
-class GoogleSearchBridge extends BridgeAbstract{
-
+class GoogleSearchBridge extends BridgeAbstract
+{
private $request;
-
- public function collectData(array $param){
+
+ public function collectData(array $param)
+ {
$html = '';
if (isset($param['q'])) { /* keyword search mode */
$this->request = $param['q'];
$html = file_get_html('http://www.google.com/search?q=' . urlencode($this->request) . '&num=100&complete=0&tbs=qdr:y,sbd:1') or $this->returnError('No results for this query.', 404);
- }
- else{
+ } else {
$this->returnError('You must specify a keyword (?q=...).', 400);
}
$emIsRes = $html->find('div[id=ires]',0);
- if( !is_null($emIsRes) ){
- foreach($emIsRes->find('li[class=g]') as $element) {
+ if ( !is_null($emIsRes) ) {
+ foreach ($emIsRes->find('li[class=g]') as $element) {
$item = new Item();
-
+
// Extract direct URL from google href (eg. /url?q=...)
$t = $element->find('a[href]',0)->href;
$item->uri = 'http://google.com'.$t;
@@ -45,15 +45,18 @@ class GoogleSearchBridge extends BridgeAbstract{
}
}
- public function getName(){
+ public function getName()
+ {
return (!empty($this->request) ? $this->request .' - ' : '') .'Google search';
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://google.com';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 1800; // 30 minutes
}
-}
\ No newline at end of file
+}
diff --git a/bridges/GuruMedBridge.php b/bridges/GuruMedBridge.php
index d312c241..fffaa95a 100644
--- a/bridges/GuruMedBridge.php
+++ b/bridges/GuruMedBridge.php
@@ -1,55 +1,60 @@
', '', $string);
-
-
-
-
- public function collectData(array $param){
-
- function GurumedStripCDATA($string) {
- $string = str_replace('', '', $string);
- return $string;
+ return $string;
}
- function GurumedExtractContent($url) {
- $html2 = file_get_html($url);
- $text = $html2->find('div.entry', 0)->innertext;
- return $text;
+
+ public function GurumedExtractContent($url)
+ {
+ $html2 = file_get_html($url);
+ $text = $html2->find('div.entry', 0)->innertext;
+
+ return $text;
}
+
+ public function collectData(array $param)
+ {
+
$html = file_get_html('http://gurumed.org/feed') or $this->returnError('Could not request Gurumed.', 404);
- $limit = 0;
+ $limit = 0;
- foreach($html->find('item') as $element) {
- if($limit < 10) {
- $item = new \Item();
- $item->title = GurumedStripCDATA($element->find('title', 0)->innertext);
- $item->uri = GurumedStripCDATA($element->find('guid', 0)->plaintext);
- $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
- $item->content = GurumedExtractContent($item->uri);
- $this->items[] = $item;
- $limit++;
- }
- }
-
+ foreach ($html->find('item') as $element) {
+ if ($limit < 10) {
+ $item = new \Item();
+ $item->title = $this->GurumedStripCDATA($element->find('title', 0)->innertext);
+ $item->uri = $this->GurumedStripCDATA($element->find('guid', 0)->plaintext);
+ $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
+ $item->content = $this->GurumedExtractContent($item->uri);
+ $this->items[] = $item;
+ $limit++;
+ }
+ }
}
- public function getName(){
+ public function getName()
+ {
return 'Gurumed';
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://gurumed.org/';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 3600; // 1 hour
}
}
diff --git a/bridges/IdenticaBridge.php b/bridges/IdenticaBridge.php
index 8d4ede50..4223495d 100644
--- a/bridges/IdenticaBridge.php
+++ b/bridges/IdenticaBridge.php
@@ -1,26 +1,26 @@
request = $param['u'];
+ $this->request = $param['u'];
$html = file_get_html('https://identi.ca/'.urlencode($this->request)) or $this->returnError('Requested username can\'t be found.', 404);
- }
- else {
+ } else {
$this->returnError('You must specify an Identica username (?u=...).', 400);
}
- foreach($html->find('li.major') as $dent) {
+ foreach ($html->find('li.major') as $dent) {
$item = new \Item();
$item->uri = html_entity_decode($dent->find('a', 0)->href); // get dent link
$item->timestamp = strtotime($dent->find('abbr.easydate', 0)->plaintext); // extract dent timestamp
@@ -30,15 +30,18 @@ class IdenticaBridge extends BridgeAbstract{
}
}
- public function getName(){
+ public function getName()
+ {
return (!empty($this->request) ? $this->request .' - ' : '') .'Identica Bridge';
}
- public function getURI(){
+ public function getURI()
+ {
return 'https://identica.com';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 300; // 5 minutes
}
}
diff --git a/bridges/InstagramBridge.php b/bridges/InstagramBridge.php
index 8a5575eb..8bf3d9a8 100644
--- a/bridges/InstagramBridge.php
+++ b/bridges/InstagramBridge.php
@@ -7,74 +7,70 @@
* @description Returns the newest images
* @use1(u="username")
*/
-class InstagramBridge extends BridgeAbstract{
-
+class InstagramBridge extends BridgeAbstract
+{
private $request;
-
- public function collectData(array $param){
+
+ public function collectData(array $param)
+ {
$html = '';
if (isset($param['u'])) { /* user timeline mode */
$this->request = $param['u'];
$html = file_get_html('http://instagram.com/'.urlencode($this->request)) or $this->returnError('Could not request Instagram.', 404);
- }
- else {
+ } else {
$this->returnError('You must specify a Instagram username (?u=...).', 400);
}
-
+
$innertext = null;
-
- foreach($html->find('script') as $script)
- {
- if ('' === $script->innertext) {
- continue;
- }
-
- $pos = strpos(trim($script->innertext), 'window._sharedData');
- if (0 !== $pos)
- {
- continue;
- }
-
- $innertext = $script->innertext;
- break;
+
+ foreach ($html->find('script') as $script) {
+ if ('' === $script->innertext) {
+ continue;
+ }
+
+ $pos = strpos(trim($script->innertext), 'window._sharedData');
+ if (0 !== $pos) {
+ continue;
+ }
+
+ $innertext = $script->innertext;
+ break;
}
-
-
-
+
$json = trim(substr($innertext, $pos+18), ' =;');
$data = json_decode($json);
-
+
$userMedia = $data->entry_data->UserProfile[0]->userMedia;
+ foreach ($userMedia as $media) {
+ $image = $media->images->standard_resolution;
- foreach($userMedia as $media)
- {
- $image = $media->images->standard_resolution;
+ $item = new \Item();
+ $item->uri = $media->link;
+ $item->content = '';
+ if (isset($media->caption)) {
+ $item->title = $media->caption->text;
+ } else {
+ $item->title = basename($image->url);
+ }
+ $item->timestamp = $media->created_time;
+ $this->items[] = $item;
- $item = new \Item();
- $item->uri = $media->link;
- $item->content = '
';
- if (isset($media->caption))
- {
- $item->title = $media->caption->text;
- } else {
- $item->title = basename($image->url);
- }
- $item->timestamp = $media->created_time;
- $this->items[] = $item;
-
}
}
- public function getName(){
+ public function getName()
+ {
return (!empty($this->request) ? $this->request .' - ' : '') .'Instagram Bridge';
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://instagram.com/';
}
- public function getCacheDuration(){
- return 3600;
+ public function getCacheDuration()
+ {
+ return 3600;
}
}
diff --git a/bridges/OpenClassroomsBridge.php b/bridges/OpenClassroomsBridge.php
index d2d3c4ae..5b86ac50 100644
--- a/bridges/OpenClassroomsBridge.php
+++ b/bridges/OpenClassroomsBridge.php
@@ -8,32 +8,36 @@
* @description Returns latest tutorials from OpenClassrooms.
* @use1(u="informatique or sciences")
*/
-class OpenClassroomsBridge extends BridgeAbstract{
-
- public function collectData(array $param){
+class OpenClassroomsBridge extends BridgeAbstract
+{
+ public function collectData(array $param)
+ {
$html = '';
$link = 'http://fr.openclassrooms.com/'.$param[u].'/cours?title=&sort=updatedAt+desc';
$html = file_get_html($link) or $this->returnError('Could not request OpenClassrooms.', 404);
- foreach($html->find('li.col6') 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;
- $this->items[] = $item;
+ foreach ($html->find('li.col6') 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;
+ $this->items[] = $item;
}
}
- public function getName(){
+ public function getName()
+ {
return 'OpenClassrooms';
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://fr.openclassrooms.com';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 21600; // 6 hours
}
}
diff --git a/bridges/PinterestBridge.php b/bridges/PinterestBridge.php
index 8c24ecde..7b1e38fa 100644
--- a/bridges/PinterestBridge.php
+++ b/bridges/PinterestBridge.php
@@ -8,81 +8,76 @@
* @use1(u="username",b="board")
* @use2(q="keyword")
*/
-class PinterestBridge extends BridgeAbstract{
-
+class PinterestBridge extends BridgeAbstract
+{
private $username;
private $board;
private $query;
-
- public function collectData(array $param){
+
+ public function collectData(array $param)
+ {
$html = '';
if (isset($param['u']) && isset($param['b'])) {
$this->username = $param['u'];
$this->board = $param['b'];
$html = file_get_html($this->getURI().'/'.urlencode($this->username).'/'.urlencode($this->board)) or $this->returnError('Could not request Pinterest.', 404);
- } else if (isset($param['q']))
- {
- $this->query = $param['q'];
- $html = file_get_html($this->getURI().'/search/?q='.urlencode($this->query)) or $this->returnError('Could not request Pinterest.', 404);
- }
-
- else {
+ } elseif (isset($param['q'])) {
+ $this->query = $param['q'];
+ $html = file_get_html($this->getURI().'/search/?q='.urlencode($this->query)) or $this->returnError('Could not request Pinterest.', 404);
+ } else {
$this->returnError('You must specify a Pinterest username and a board name (?u=...&b=...).', 400);
}
-
-
- foreach($html->find('div.pinWrapper') as $div)
- {
- $a = $div->find('a.pinImageWrapper',0);
-
- $img = $a->find('img', 0);
-
- $item = new \Item();
- $item->uri = $this->getURI().$a->getAttribute('href');
- $item->content = '
';
-
-
- if (isset($this->query))
- {
- $avatar = $div->find('img.creditImg', 0);
- $username = $div->find('span.creditName', 0);
- $board = $div->find('span.creditTitle', 0);
-
- $item->username =$username->innertext;
- $item->fullname = $board->innertext;
- $item->avatar = $avatar->getAttribute('src');
-
- $item->content .= '
'.$item->username.'';
- $item->content .= '
'.$item->fullname;
- } else {
-
- $credit = $div->find('a.creditItem',0);
- $item->content .= '
'.$credit->innertext;
- }
-
- $item->title = basename($img->getAttribute('alt'));
-
- //$item->timestamp = $media->created_time;
- $this->items[] = $item;
-
+
+ foreach ($html->find('div.pinWrapper') as $div) {
+ $a = $div->find('a.pinImageWrapper',0);
+
+ $img = $a->find('img', 0);
+
+ $item = new \Item();
+ $item->uri = $this->getURI().$a->getAttribute('href');
+ $item->content = '';
+
+ if (isset($this->query)) {
+ $avatar = $div->find('img.creditImg', 0);
+ $username = $div->find('span.creditName', 0);
+ $board = $div->find('span.creditTitle', 0);
+
+ $item->username =$username->innertext;
+ $item->fullname = $board->innertext;
+ $item->avatar = $avatar->getAttribute('src');
+
+ $item->content .= '
'.$item->username.'';
+ $item->content .= '
'.$item->fullname;
+ } else {
+
+ $credit = $div->find('a.creditItem',0);
+ $item->content .= '
'.$credit->innertext;
+ }
+
+ $item->title = basename($img->getAttribute('alt'));
+
+ //$item->timestamp = $media->created_time;
+ $this->items[] = $item;
+
}
}
- public function getName(){
-
- if (isset($this->query))
- {
- return $this->query .' - Pinterest';
- } else {
- return $this->username .' - '. $this->board.' - Pinterest';
- }
+ public function getName()
+ {
+ if (isset($this->query)) {
+ return $this->query .' - Pinterest';
+ } else {
+ return $this->username .' - '. $this->board.' - Pinterest';
+ }
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://www.pinterest.com';
}
- public function getCacheDuration(){
- return 0;
+ public function getCacheDuration()
+ {
+ return 0;
}
}
diff --git a/bridges/ScmbBridge.php b/bridges/ScmbBridge.php
index e58088d4..0ec26f41 100644
--- a/bridges/ScmbBridge.php
+++ b/bridges/ScmbBridge.php
@@ -1,49 +1,51 @@
returnError('Could not request Se Coucher Moins Bete.', 404);
-
- foreach($html->find('article') as $article) {
- $item = new \Item();
- $item->uri = 'http://secouchermoinsbete.fr'.$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
- $content = $article->find('p.summary a',0)->innertext;
- $content =substr($content,0,strlen($content)-17); // remove superfluous spaces at the end
-
- // get publication date
- $str_date = $article->find('time',0)->datetime;
- list($date, $time) = explode(' ', $str_date);
- list($y, $m, $d) = explode('-', $date);
- list($h, $i) = explode(':', $time);
- $timestamp = mktime($h,$i,0,$m,$d,$y);
- $item->timestamp = $timestamp;
-
-
- $item->content = $content;
- $this->items[] = $item;
- }
+ foreach ($html->find('article') as $article) {
+ $item = new \Item();
+ $item->uri = 'http://secouchermoinsbete.fr'.$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
+ $content = $article->find('p.summary a',0)->innertext;
+ $content =substr($content,0,strlen($content)-17); // remove superfluous spaces at the end
+
+ // get publication date
+ $str_date = $article->find('time',0)->datetime;
+ list($date, $time) = explode(' ', $str_date);
+ list($y, $m, $d) = explode('-', $date);
+ list($h, $i) = explode(':', $time);
+ $timestamp = mktime($h,$i,0,$m,$d,$y);
+ $item->timestamp = $timestamp;
+
+ $item->content = $content;
+ $this->items[] = $item;
+ }
}
- public function getName(){
+ public function getName()
+ {
return 'Se Coucher Moins Bête Bridge';
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://secouchermoinsbete.fr/';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 21600; // 6 hours
}
}
diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php
index fcc3967b..28f38652 100644
--- a/bridges/TwitterBridge.php
+++ b/bridges/TwitterBridge.php
@@ -1,6 +1,6 @@
request = $param['q'];
$html = file_get_html('http://twitter.com/search/realtime?q='.urlencode($this->request).'+include:retweets&src=typd') or $this->returnError('No results for this query.', 404);
- }
- elseif (isset($param['u'])) { /* user timeline mode */
+ } elseif (isset($param['u'])) { /* user timeline mode */
$this->request = $param['u'];
$html = file_get_html('http://twitter.com/'.urlencode($this->request)) or $this->returnError('Requested username can\'t be found.', 404);
- }
- else {
+ } else {
$this->returnError('You must specify a keyword (?q=...) or a Twitter username (?u=...).', 400);
}
- foreach($html->find('div.tweet') as $tweet) {
+ foreach ($html->find('div.tweet') as $tweet) {
$item = new \Item();
$item->username = trim(substr($tweet->find('span.username', 0)->plaintext, 1)); // extract username and sanitize
$item->fullname = $tweet->getAttribute('data-name'); // extract fullname (pseudonym)
@@ -40,15 +39,18 @@ class TwitterBridge extends BridgeAbstract{
}
}
- public function getName(){
+ public function getName()
+ {
return (!empty($this->request) ? $this->request .' - ' : '') .'Twitter Bridge';
}
- public function getURI(){
+ public function getURI()
+ {
return 'http://twitter.com';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 300; // 5 minutes
}
}
diff --git a/bridges/WikipediaENBridge.php b/bridges/WikipediaENBridge.php
index ecd2ccf5..a8294767 100755
--- a/bridges/WikipediaENBridge.php
+++ b/bridges/WikipediaENBridge.php
@@ -6,9 +6,10 @@
* @name Wikipedia EN "Today's Featured Article..."
* @description Returns the highlighted en.wikipedia.org article.
*/
-class WikipediaENBridge extends BridgeAbstract{
-
- public function collectData(array $param){
+class WikipediaENBridge extends BridgeAbstract
+{
+ public function collectData(array $param)
+ {
$html = '';
$host = 'http://en.wikipedia.org';
// If you want HTTPS access instead, uncomment the following line:
@@ -17,25 +18,28 @@ class WikipediaENBridge extends BridgeAbstract{
$html = file_get_html($host.$link) or $this->returnError('Could not request Wikipedia EN.', 404);
- $element = $html->find('div[id=mp-tfa]', 0);
- // Clean the bottom of the featured article
- $element->find('div', -1)->outertext = '';
- $item = new \Item();
- $item->uri = $host.$element->find('p', 0)->find('a', 0)->href;
- $item->title = $element->find('p',0)->find('a',0)->title;
- $item->content = str_replace('href="/', 'href="'.$host.'/', $element->innertext);
- $this->items[] = $item;
+ $element = $html->find('div[id=mp-tfa]', 0);
+ // Clean the bottom of the featured article
+ $element->find('div', -1)->outertext = '';
+ $item = new \Item();
+ $item->uri = $host.$element->find('p', 0)->find('a', 0)->href;
+ $item->title = $element->find('p',0)->find('a',0)->title;
+ $item->content = str_replace('href="/', 'href="'.$host.'/', $element->innertext);
+ $this->items[] = $item;
}
- public function getName(){
+ public function getName()
+ {
return 'Wikipedia EN "Today\'s Featued Article"';
}
- public function getURI(){
+ public function getURI()
+ {
return 'https://en.wikipedia.org/wiki/Main_Page';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 3600*4; // 4 hours
}
}
diff --git a/bridges/WikipediaEOBridge.php b/bridges/WikipediaEOBridge.php
index 19f8cee0..b34ba691 100644
--- a/bridges/WikipediaEOBridge.php
+++ b/bridges/WikipediaEOBridge.php
@@ -6,9 +6,10 @@
* @name Wikipedia EO "Artikolo de la semajno"
* @description Returns the highlighted eo.wikipedia.org article.
*/
-class WikipediaEOBridge extends BridgeAbstract{
-
- public function collectData(array $param){
+class WikipediaEOBridge extends BridgeAbstract
+{
+ public function collectData(array $param)
+ {
$html = '';
$host = 'http://eo.wikipedia.org';
// If you want HTTPS access instead, uncomment the following line:
@@ -17,25 +18,28 @@ class WikipediaEOBridge extends BridgeAbstract{
$html = file_get_html($host.$link) or $this->returnError('Could not request Wikipedia EO.', 404);
- $element = $html->find('div[id=mf-tfa]', 0);
- // Link to article
- $link = $element->find('p', -2)->find('a', 0);
- $item = new \Item();
- $item->uri = $host.$link->href;
- $item->title = $link->title;
- $item->content = str_replace('href="/', 'href="'.$host.'/', $element->innertext);
- $this->items[] = $item;
+ $element = $html->find('div[id=mf-tfa]', 0);
+ // Link to article
+ $link = $element->find('p', -2)->find('a', 0);
+ $item = new \Item();
+ $item->uri = $host.$link->href;
+ $item->title = $link->title;
+ $item->content = str_replace('href="/', 'href="'.$host.'/', $element->innertext);
+ $this->items[] = $item;
}
- public function getName(){
+ public function getName()
+ {
return 'Wikipedia EO "Artikolo de la semajno"';
}
- public function getURI(){
+ public function getURI()
+ {
return 'https://eo.wikipedia.org/wiki/Vikipedio:%C4%88efpa%C4%9Do';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 3600*12; // 12 hours
}
}
diff --git a/bridges/WikipediaFRBridge.php b/bridges/WikipediaFRBridge.php
index 20376da9..89875ae0 100755
--- a/bridges/WikipediaFRBridge.php
+++ b/bridges/WikipediaFRBridge.php
@@ -6,9 +6,10 @@
* @name Wikipedia FR "Lumière sur..."
* @description Returns the highlighted fr.wikipedia.org article.
*/
-class WikipediaFRBridge extends BridgeAbstract{
-
- public function collectData(array $param){
+class WikipediaFRBridge extends BridgeAbstract
+{
+ public function collectData(array $param)
+ {
$html = '';
$host = 'http://fr.wikipedia.org';
// If you want HTTPS access instead, uncomment the following line:
@@ -17,23 +18,26 @@ class WikipediaFRBridge extends BridgeAbstract{
$html = file_get_html($host.$link) or $this->returnError('Could not request Wikipedia FR.', 404);
- $element = $html->find('div[id=accueil-lumieresur]', 0);
- $item = new \Item();
- $item->uri = $host.$element->find('p', 0)->find('a', 0)->href;
- $item->title = $element->find('p',0)->find('a',0)->title;
- $item->content = str_replace('href="/', 'href="'.$host.'/', $element->find('div[id=mf-lumieresur]', 0)->innertext);
- $this->items[] = $item;
+ $element = $html->find('div[id=accueil-lumieresur]', 0);
+ $item = new \Item();
+ $item->uri = $host.$element->find('p', 0)->find('a', 0)->href;
+ $item->title = $element->find('p',0)->find('a',0)->title;
+ $item->content = str_replace('href="/', 'href="'.$host.'/', $element->find('div[id=mf-lumieresur]', 0)->innertext);
+ $this->items[] = $item;
}
- public function getName(){
+ public function getName()
+ {
return 'Wikipedia FR "Lumière sur..."';
}
- public function getURI(){
+ public function getURI()
+ {
return 'https://fr.wikipedia.org/wiki/Wikip%C3%A9dia:Accueil_principal';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 3600*4; // 4 hours
}
}
diff --git a/bridges/YoutubeBridge.php b/bridges/YoutubeBridge.php
index 8d739251..01c6915b 100644
--- a/bridges/YoutubeBridge.php
+++ b/bridges/YoutubeBridge.php
@@ -1,28 +1,27 @@
request = $param['u'];
$html = file_get_html('https://www.youtube.com/user/'.urlencode($this->request).'/videos') or $this->returnError('Could not request Youtube.', 404);
- }
- else {
+ } else {
$this->returnError('You must specify a Youtbe username (?u=...).', 400);
}
-
-
- foreach($html->find('li.channels-content-item') as $element) {
+
+ foreach ($html->find('li.channels-content-item') as $element) {
$item = new \Item();
$item->uri = 'https://www.youtube.com'.$element->find('a',0)->href;
$item->thumbnailUri = 'https:'.$element->find('img',0)->src;
@@ -32,15 +31,18 @@ class YoutubeBridge extends BridgeAbstract{
}
}
- public function getName(){
+ public function getName()
+ {
return (!empty($this->request) ? $this->request .' - ' : '') .'Youtube Bridge';
}
- public function getURI(){
+ public function getURI()
+ {
return 'https://www.youtube.com/';
}
- public function getCacheDuration(){
+ public function getCacheDuration()
+ {
return 21600; // 6 hours
}
}
diff --git a/caches/FileCache.php b/caches/FileCache.php
index 594343d3..0905ddd5 100644
--- a/caches/FileCache.php
+++ b/caches/FileCache.php
@@ -2,17 +2,19 @@
/**
* Cache with file system
*/
-class FileCache extends CacheAbstract{
+class FileCache extends CacheAbstract
+{
protected $cacheDirCreated; // boolean to avoid always chck dir cache existance
- public function loadData(){
+ public function loadData()
+ {
$this->isPrepareCache();
$datas = json_decode(file_get_contents($this->getCacheFile()),true);
$items = array();
- foreach($datas as $aData){
+ foreach ($datas as $aData) {
$item = new \Item();
- foreach($aData as $name => $value){
+ foreach ($aData as $name => $value) {
$item->$name = $value;
}
$items[] = $item;
@@ -21,7 +23,8 @@ class FileCache extends CacheAbstract{
return $items;
}
- public function saveData($datas){
+ public function saveData($datas)
+ {
$this->isPrepareCache();
file_put_contents($this->getCacheFile(), json_encode($datas));
@@ -29,11 +32,12 @@ class FileCache extends CacheAbstract{
return $this;
}
- public function getTime(){
+ public function getTime()
+ {
$this->isPrepareCache();
$cacheFile = $this->getCacheFile();
- if( file_exists($cacheFile) ){
+ if ( file_exists($cacheFile) ) {
return filemtime($cacheFile);
}
@@ -45,8 +49,9 @@ class FileCache extends CacheAbstract{
* Note : Cache name is based on request information, then cache must be prepare before use
* @return \Exception|true
*/
- protected function isPrepareCache(){
- if( is_null($this->param) ){
+ protected function isPrepareCache()
+ {
+ if ( is_null($this->param) ) {
throw new \Exception('Please feed "prepare" method before try to load');
}
@@ -57,11 +62,12 @@ class FileCache extends CacheAbstract{
* Return cache path (and create if not exist)
* @return string Cache path
*/
- protected function getCachePath(){
+ protected function getCachePath()
+ {
$cacheDir = __DIR__ . '/../cache/'; // FIXME : configuration ?
// FIXME : implement recursive dir creation
- if( is_null($this->cacheDirCreated) && !is_dir($cacheDir) ){
+ if ( is_null($this->cacheDirCreated) && !is_dir($cacheDir) ) {
$this->cacheDirCreated = true;
mkdir($cacheDir,0705);
@@ -75,7 +81,8 @@ class FileCache extends CacheAbstract{
* Get the file name use for cache store
* @return string Path to the file cache
*/
- protected function getCacheFile(){
+ protected function getCacheFile()
+ {
return $this->getCachePath() . $this->getCacheName();
}
@@ -83,10 +90,12 @@ class FileCache extends CacheAbstract{
* Determines file name for store the cache
* return string
*/
- protected function getCacheName(){
+ protected function getCacheName()
+ {
$this->isPrepareCache();
$stringToEncode = $_SERVER['REQUEST_URI'] . http_build_query($this->param);
+
return hash('sha1', $stringToEncode) . '.cache';
}
-}
\ No newline at end of file
+}
diff --git a/formats/AtomFormat.php b/formats/AtomFormat.php
index cdd0a9ad..768fad9c 100644
--- a/formats/AtomFormat.php
+++ b/formats/AtomFormat.php
@@ -5,9 +5,10 @@
*
* @name Atom
*/
-class AtomFormat extends FormatAbstract{
-
- public function stringify(){
+class AtomFormat extends FormatAbstract
+{
+ public function stringify()
+ {
/* Datas preparation */
$https = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 's' : '' );
$httpHost = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';
@@ -20,7 +21,7 @@ class AtomFormat extends FormatAbstract{
$uri = htmlspecialchars($extraInfos['uri']);
$entries = '';
- foreach($this->getDatas() as $data){
+ foreach ($this->getDatas() as $data) {
$entryName = is_null($data->name) ? $title : $data->name;
$entryAuthor = is_null($data->author) ? $uri : $data->author;
$entryTitle = is_null($data->title) ? '' : $data->title;
@@ -66,23 +67,25 @@ EOD;
{$entries}
EOD;
-
+
// Remove invalid non-UTF8 characters
// We cannot use iconv because of a bug in some versions of iconv.
// See http://www.php.net/manual/fr/function.iconv.php#108643
- //$toReturn = iconv("UTF-8", "UTF-8//IGNORE", $toReturn);
+ //$toReturn = iconv("UTF-8", "UTF-8//IGNORE", $toReturn);
// So we use mb_convert_encoding instead:
ini_set('mbstring.substitute_character', 'none');
- $toReturn= mb_convert_encoding($toReturn, 'UTF-8', 'UTF-8');
+ $toReturn= mb_convert_encoding($toReturn, 'UTF-8', 'UTF-8');
+
return $toReturn;
}
- public function display(){
+ public function display()
+ {
$this
->setContentType('application/atom+xml; charset=utf8') // We force UTF-8 in ATOM output.
->callContentType();
return parent::display();
}
-}
\ No newline at end of file
+}
diff --git a/formats/HtmlFormat.php b/formats/HtmlFormat.php
index c52cf963..60dd9a28 100644
--- a/formats/HtmlFormat.php
+++ b/formats/HtmlFormat.php
@@ -5,16 +5,17 @@
*
* @name Html
*/
-class HtmlFormat extends FormatAbstract{
-
- public function stringify(){
+class HtmlFormat extends FormatAbstract
+{
+ public function stringify()
+ {
/* Datas preparation */
$extraInfos = $this->getExtraInfos();
$title = htmlspecialchars($extraInfos['name']);
$uri = htmlspecialchars($extraInfos['uri']);
$entries = '';
- foreach($this->getDatas() as $data){
+ foreach ($this->getDatas() as $data) {
$entryUri = is_null($data->uri) ? $uri : $data->uri;
$entryTitle = is_null($data->title) ? '' : $this->sanitizeHtml(strip_tags($data->title));
$entryTimestamp = is_null($data->timestamp) ? '' : '' . date(DATE_ATOM, $data->timestamp) . '';
@@ -51,11 +52,12 @@ EOD;
return $toReturn;
}
- public function display() {
+ public function display()
+ {
$this
->setContentType('text/html; charset=' . $this->getCharset())
->callContentType();
return parent::display();
}
-}
\ No newline at end of file
+}
diff --git a/formats/JsonFormat.php b/formats/JsonFormat.php
index 400f91f7..79b04a82 100644
--- a/formats/JsonFormat.php
+++ b/formats/JsonFormat.php
@@ -5,20 +5,22 @@
*
* @name Json
*/
-class JsonFormat extends FormatAbstract{
-
- public function stringify(){
+class JsonFormat extends FormatAbstract
+{
+ public function stringify()
+ {
// FIXME : sometime content can be null, transform to empty string
$datas = $this->getDatas();
return json_encode($datas);
}
- public function display(){
+ public function display()
+ {
$this
->setContentType('application/json')
->callContentType();
return parent::display();
}
-}
\ No newline at end of file
+}
diff --git a/formats/PlaintextFormat.php b/formats/PlaintextFormat.php
index 32b4e020..4f356500 100644
--- a/formats/PlaintextFormat.php
+++ b/formats/PlaintextFormat.php
@@ -5,18 +5,21 @@
*
* @name Plaintext
*/
-class PlaintextFormat extends FormatAbstract{
-
- public function stringify(){
+class PlaintextFormat extends FormatAbstract
+{
+ public function stringify()
+ {
$datas = $this->getDatas();
+
return print_r($datas, true);
}
- public function display(){
+ public function display()
+ {
$this
->setContentType('text/plain;charset=' . $this->getCharset())
->callContentType();
return parent::display();
}
-}
\ No newline at end of file
+}
diff --git a/index.php b/index.php
index a95fcbb4..f49daa9f 100644
--- a/index.php
+++ b/index.php
@@ -15,17 +15,17 @@ date_default_timezone_set('UTC');
error_reporting(0);
//ini_set('display_errors','1'); error_reporting(E_ALL); // For debugging only.
-try{
+try {
require_once __DIR__ . '/lib/RssBridge.php';
Bridge::setDir(__DIR__ . '/bridges/');
Format::setDir(__DIR__ . '/formats/');
Cache::setDir(__DIR__ . '/caches/');
- if( isset($_REQUEST) && isset($_REQUEST['action']) ){
- switch($_REQUEST['action']){
+ if ( isset($_REQUEST) && isset($_REQUEST['action']) ) {
+ switch ($_REQUEST['action']) {
case 'display':
- if( isset($_REQUEST['bridge']) ){
+ if ( isset($_REQUEST['bridge']) ) {
unset($_REQUEST['action']);
$bridge = $_REQUEST['bridge'];
unset($_REQUEST['bridge']);
@@ -57,17 +57,16 @@ try{
break;
}
}
-}
-catch(HttpException $e){
+} catch (HttpException $e) {
header('HTTP/1.1 ' . $e->getCode() . ' ' . Http::getMessageForCode($e->getCode()));
header('Content-Type: text/plain');
die($e->getMessage());
-}
-catch(\Exception $e){
+} catch (\Exception $e) {
die($e->getMessage());
}
-function getHelperButtonFormat($value, $name){
+function getHelperButtonFormat($value, $name)
+{
return '';
}
@@ -98,7 +97,7 @@ $formats = Format::searchInformation();
-
+ 0 ): ?>