diff --git a/bridges/ABCTabsBridge.php b/bridges/ABCTabsBridge.php index 1e7e170c..8c47175f 100644 --- a/bridges/ABCTabsBridge.php +++ b/bridges/ABCTabsBridge.php @@ -1,25 +1,43 @@ find('table#myTable', 0)->children(1); foreach ($table->find('tr') as $tab) { - $item = array(); - $item['author'] = $tab->find('td', 1)->plaintext . ' - ' . $tab->find('td', 2)->plaintext; - $item['title'] = $tab->find('td', 1)->plaintext . ' - ' . $tab->find('td', 2)->plaintext; - $item['content'] = 'Le ' . $tab->find('td', 0)->plaintext . '
Par: ' . $tab->find('td', 5)->plaintext . '
Type: ' . $tab->find('td', 3)->plaintext; - $item['id'] = static::URI . $tab->find('td', 2)->find('a', 0)->getAttribute('href'); - $item['uri'] = static::URI . $tab->find('td', 2)->find('a', 0)->getAttribute('href'); - $this->items[] = $item; + $item = array(); + $item['author'] = $tab->find('td', 1)->plaintext + . ' - ' + . $tab->find('td', 2)->plaintext; + + $item['title'] = $tab->find('td', 1)->plaintext + . ' - ' + . $tab->find('td', 2)->plaintext; + + $item['content'] = 'Le ' + . $tab->find('td', 0)->plaintext + . '
Par: ' + . $tab->find('td', 5)->plaintext + . '
Type: ' + . $tab->find('td', 3)->plaintext; + + $item['id'] = static::URI + . $tab->find('td', 2)->find('a', 0)->getAttribute('href'); + + $item['uri'] = static::URI + . $tab->find('td', 2)->find('a', 0)->getAttribute('href'); + + $this->items[] = $item; } - } + } } diff --git a/bridges/AcrimedBridge.php b/bridges/AcrimedBridge.php index 31481adf..3ca8e803 100644 --- a/bridges/AcrimedBridge.php +++ b/bridges/AcrimedBridge.php @@ -1,25 +1,25 @@ collectExpandableDatas(static::URI.'spip.php?page=backend'); - } + public function collectData(){ + $this->collectExpandableDatas(static::URI . 'spip.php?page=backend'); + } - protected function parseItem($newsItem){ - $item = parent::parseItem($newsItem); + protected function parseItem($newsItem){ + $item = parent::parseItem($newsItem); - $articlePage = getSimpleHTMLDOM($newsItem->link); - $article = sanitize($articlePage->find('article.article1', 0)->innertext); - $article = defaultImageSrcTo($article, static::URI); - $item['content'] = $article; + $articlePage = getSimpleHTMLDOM($newsItem->link); + $article = sanitize($articlePage->find('article.article1', 0)->innertext); + $article = defaultImageSrcTo($article, static::URI); + $item['content'] = $article; - return $item; - } + return $item; + } } diff --git a/bridges/AllocineFRBridge.php b/bridges/AllocineFRBridge.php index 0c4a048f..74601c92 100644 --- a/bridges/AllocineFRBridge.php +++ b/bridges/AllocineFRBridge.php @@ -1,91 +1,88 @@ array( + 'name' => 'category', + 'type' => 'list', + 'required' => true, + 'exampleValue' => 'Faux Raccord', + 'title' => 'Select your category', + 'values' => array( + 'Faux Raccord' => 'faux-raccord', + 'Top 5' => 'top-5', + 'Tueurs en Séries' => 'tueurs-en-serie' + ) + ) + )); - const MAINTAINER = "superbaillot.net"; - const NAME = "Allo Cine Bridge"; - const CACHE_TIMEOUT = 25200; // 7h - const URI = "http://www.allocine.fr/"; - const DESCRIPTION = "Bridge for allocine.fr"; - const PARAMETERS = array( array( - 'category'=>array( - 'name'=>'category', - 'type'=>'list', - 'required'=>true, - 'exampleValue'=>'Faux Raccord', - 'title'=>'Select your category', - 'values'=>array( - 'Faux Raccord'=>'faux-raccord', - 'Top 5'=>'top-5', - 'Tueurs en Séries'=>'tueurs-en-serie' - ) - ) - )); + public function getURI(){ + if(!is_null($this->getInput('category'))){ - public function getURI(){ - if(!is_null($this->getInput('category'))){ + switch($this->getInput('category')){ + case 'faux-raccord': + $uri = static::URI . 'video/programme-12284/saison-27129/'; + break; + case 'top-5': + $uri = static::URI . 'video/programme-12299/saison-29561/'; + break; + case 'tueurs-en-serie': + $uri = static::URI . 'video/programme-12286/saison-22938/'; + break; + } - switch($this->getInput('category')){ - case 'faux-raccord': - $uri = static::URI.'video/programme-12284/saison-27129/'; - break; - case 'top-5': - $uri = static::URI.'video/programme-12299/saison-29561/'; - break; - case 'tueurs-en-serie': - $uri = static::URI.'video/programme-12286/saison-22938/'; - break; - } + return $uri; + } - return $uri; - } + return parent::getURI(); + } - return parent::getURI(); - } + public function getName(){ + if(!is_null($this->getInput('category'))){ + return self::NAME . ' : ' + .array_search( + $this->getInput('category'), + self::PARAMETERS[$this->queriedContext]['category']['values'] + ); + } - public function getName(){ - if(!is_null($this->getInput('category'))){ - return self::NAME.' : ' - .array_search( - $this->getInput('category'), - self::PARAMETERS[$this->queriedContext]['category']['values'] - ); - } + return parent::getName(); + } - return parent::getName(); - } + public function collectData(){ - public function collectData(){ + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request ' . $this->getURI() . ' !'); - $html = getSimpleHTMLDOM($this->getURI()) - or returnServerError("Could not request ".$this->getURI()." !"); + $category = array_search( + $this->getInput('category'), + self::PARAMETERS[$this->queriedContext]['category']['values'] + ); - $category=array_search( - $this->getInput('category'), - self::PARAMETERS[$this->queriedContext]['category']['values'] - ); + foreach($html->find('figure.media-meta-fig') as $element){ + $item = array(); + $title = $element->find('div.titlebar h3.title a', 0); + $content = trim($element->innertext); + $figCaption = strpos($content, $category); - foreach($html->find('figure.media-meta-fig') as $element) - { - $item = array(); - - $title = $element->find('div.titlebar h3.title a', 0); - $content = trim($element->innertext); - $figCaption = strpos($content, $category); - - if($figCaption !== false) - { - $content = str_replace('src="/', 'src="'.static::URI, $content); - $content = str_replace('href="/', 'href="'.static::URI, $content); - $content = str_replace('src=\'/', 'src=\''.static::URI, $content); - $content = str_replace('href=\'/', 'href=\''.static::URI, $content); - $item['content'] = $content; - $item['title'] = trim($title->innertext); - $item['uri'] = static::URI . $title->href; - $this->items[] = $item; - } - } - } + if($figCaption !== false) + { + $content = str_replace('src="/', 'src="' . static::URI, $content); + $content = str_replace('href="/', 'href="' . static::URI, $content); + $content = str_replace('src=\'/', 'src=\'' . static::URI, $content); + $content = str_replace('href=\'/', 'href=\'' . static::URI, $content); + $item['content'] = $content; + $item['title'] = trim($title->innertext); + $item['uri'] = static::URI . $title->href; + $this->items[] = $item; + } + } + } } diff --git a/bridges/AnimeUltimeBridge.php b/bridges/AnimeUltimeBridge.php index aea376bd..caedba1e 100644 --- a/bridges/AnimeUltimeBridge.php +++ b/bridges/AnimeUltimeBridge.php @@ -1,123 +1,135 @@ array( - 'name'=>'Type', - 'type'=>'list', - 'values'=>array( - 'Everything'=>'', - 'Anime'=>'A', - 'Drama'=>'D', - 'Tokusatsu'=>'T' - ) - ) - )); + const MAINTAINER = 'ORelio'; + const NAME = 'Anime-Ultime'; + const URI = 'http://www.anime-ultime.net/'; + const CACHE_TIMEOUT = 10800; // 3h + const DESCRIPTION = 'Returns the 10 newest releases posted on Anime-Ultime'; + const PARAMETERS = array( array( + 'type' => array( + 'name' => 'Type', + 'type' => 'list', + 'values' => array( + 'Everything' => '', + 'Anime' => 'A', + 'Drama' => 'D', + 'Tokusatsu' => 'T' + ) + ) + )); - private $filter = 'Releases'; + private $filter = 'Releases'; - public function collectData(){ + public function collectData(){ - //Add type filter if provided - $typeFilter = array_search( - $this->getInput('type'), - self::PARAMETERS[$this->queriedContext]['type']['values'] - ); + //Add type filter if provided + $typeFilter = array_search( + $this->getInput('type'), + self::PARAMETERS[$this->queriedContext]['type']['values'] + ); - //Build date and filters for making requests - $thismonth = date('mY').$typeFilter; - $lastmonth = date('mY', mktime(0, 0, 0, date('n') - 1, 1, date('Y'))).$typeFilter; + //Build date and filters for making requests + $thismonth = date('mY') . $typeFilter; + $lastmonth = date('mY', mktime(0, 0, 0, date('n') - 1, 1, date('Y'))) . $typeFilter; - //Process each HTML page until having 10 releases - $processedOK = 0; - foreach (array($thismonth, $lastmonth) as $requestFilter) { + //Process each HTML page until having 10 releases + $processedOK = 0; + foreach (array($thismonth, $lastmonth) as $requestFilter) { - //Retrive page contents - $url = self::URI.'history-0-1/'.$requestFilter; - $html = getSimpleHTMLDOM($url) - or returnServerError('Could not request Anime-Ultime: '.$url); + //Retrive page contents + $url = self::URI . 'history-0-1/' . $requestFilter; + $html = getSimpleHTMLDOM($url) + or returnServerError('Could not request Anime-Ultime: ' . $url); - //Relases are sorted by day : process each day individually - foreach ($html->find('div.history', 0)->find('h3') as $daySection) { + //Relases are sorted by day : process each day individually + foreach($html->find('div.history', 0)->find('h3') as $daySection) { - //Retrieve day and build date information - $dateString = $daySection->plaintext; - $day = intval(substr($dateString, strpos($dateString, ' ') + 1, 2)); - $item_date = strtotime(str_pad($day, 2, '0', STR_PAD_LEFT).'-' - .substr($requestFilter, 0, 2).'-' - .substr($requestFilter, 2, 4)); - $release = $daySection->next_sibling()->next_sibling()->first_child(); //

day


<-- useful data in table rows + //Retrieve day and build date information + $dateString = $daySection->plaintext; + $day = intval(substr($dateString, strpos($dateString, ' ') + 1, 2)); + $item_date = strtotime(str_pad($day, 2, '0', STR_PAD_LEFT) + . '-' + . substr($requestFilter, 0, 2) + . '-' + . substr($requestFilter, 2, 4)); - //Process each release of that day, ignoring first table row: contains table headers - while (!is_null($release = $release->next_sibling())) { - if (count($release->find('td')) > 0) { + //

day


<-- useful data in table rows + $release = $daySection->next_sibling()->next_sibling()->first_child(); - //Retrieve metadata from table columns - $item_link_element = $release->find('td', 0)->find('a', 0); - $item_uri = self::URI.$item_link_element->href; - $item_name = html_entity_decode($item_link_element->plaintext); - $item_episode = html_entity_decode(str_pad($release->find('td', 1)->plaintext, 2, '0', STR_PAD_LEFT)); - $item_fansub = $release->find('td', 2)->plaintext; - $item_type = $release->find('td', 4)->plaintext; + //Process each release of that day, ignoring first table row: contains table headers + while(!is_null($release = $release->next_sibling())) { + if(count($release->find('td')) > 0) { - if (!empty($item_uri)) { + //Retrieve metadata from table columns + $item_link_element = $release->find('td', 0)->find('a', 0); + $item_uri = self::URI . $item_link_element->href; + $item_name = html_entity_decode($item_link_element->plaintext); + $item_episode = html_entity_decode( + str_pad( + $release->find('td', 1)->plaintext, + 2, + '0', + STR_PAD_LEFT + ) + ); - //Retrieve description from description page and convert relative image src info absolute image src - $html_item = getContents($item_uri) - or returnServerError('Could not request Anime-Ultime: '.$item_uri); - $item_description = substr( - $html_item, - strpos($html_item, 'class="principal_contain" align="center">') - + 41 - ); - $item_description = substr($item_description, - 0, - strpos($item_description, '
') - ); - $item_description = str_replace( - 'src="images', 'src="'.self::URI.'images', - $item_description - ); - $item_description = str_replace("\r", '', $item_description); - $item_description = str_replace("\n", '', $item_description); - $item_description = utf8_encode($item_description); + $item_fansub = $release->find('td', 2)->plaintext; + $item_type = $release->find('td', 4)->plaintext; - //Build and add final item - $item = array(); - $item['uri'] = $item_uri; - $item['title'] = $item_name.' '.$item_type.' '.$item_episode; - $item['author'] = $item_fansub; - $item['timestamp'] = $item_date; - $item['content'] = $item_description; - $this->items[] = $item; - $processedOK++; + if(!empty($item_uri)) { - //Stop processing once limit is reached - if ($processedOK >= 10) - return; - } - } - } - } - } - } + // Retrieve description from description page and + // convert relative image src info absolute image src + $html_item = getContents($item_uri) + or returnServerError('Could not request Anime-Ultime: ' . $item_uri); + $item_description = substr( + $html_item, + strpos($html_item, 'class="principal_contain" align="center">') + 41 + ); + $item_description = substr($item_description, + 0, + strpos($item_description, '
') + ); + $item_description = str_replace( + 'src="images', 'src="' . self::URI . 'images', + $item_description + ); + $item_description = str_replace("\r", '', $item_description); + $item_description = str_replace("\n", '', $item_description); + $item_description = utf8_encode($item_description); - public function getName() { - if(!is_null($this->getInput('type'))){ - $typeFilter = array_search( - $this->getInput('type'), - self::PARAMETERS[$this->queriedContext]['type']['values'] - ); + //Build and add final item + $item = array(); + $item['uri'] = $item_uri; + $item['title'] = $item_name . ' ' . $item_type . ' ' . $item_episode; + $item['author'] = $item_fansub; + $item['timestamp'] = $item_date; + $item['content'] = $item_description; + $this->items[] = $item; + $processedOK++; - return 'Latest '.$typeFilter.' - Anime-Ultime Bridge'; - } + //Stop processing once limit is reached + if ($processedOK >= 10) + return; + } + } + } + } + } + } - return parent::getName(); - } + public function getName() { + if(!is_null($this->getInput('type'))){ + $typeFilter = array_search( + $this->getInput('type'), + self::PARAMETERS[$this->queriedContext]['type']['values'] + ); + + return 'Latest ' . $typeFilter . ' - Anime-Ultime Bridge'; + } + + return parent::getName(); + } } diff --git a/bridges/Arte7Bridge.php b/bridges/Arte7Bridge.php index 582c913d..09a1ee4d 100644 --- a/bridges/Arte7Bridge.php +++ b/bridges/Arte7Bridge.php @@ -1,91 +1,102 @@ array( - 'catfr'=>array( - 'type'=>'list', - 'name'=>'Catégorie', - 'values'=>array( - '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' + const MAINTAINER = 'mitsukarenai'; + const NAME = 'Arte +7'; + const URI = 'http://www.arte.tv/'; + const CACHE_TIMEOUT = 1800; // 30min + const DESCRIPTION = 'Returns newest videos from ARTE +7'; + const PARAMETERS = array( + 'Catégorie (Français)' => array( + 'catfr' => array( + 'type' => 'list', + 'name' => 'Catégorie', + 'values' => array( + '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' + ) + ) + ), + 'Catégorie (Allemand)' => array( + 'catde' => array( + 'type' => 'list', + 'name' => 'Catégorie', + 'values' => array( + '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' + ) + ) + ) + ); - ) - ) - ), - 'Catégorie (Allemand)' => array( - 'catde'=>array( - 'type'=>'list', - 'name'=>'Catégorie', - 'values'=>array( - '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' - ) - ) - ) - ); + public function collectData(){ + switch($this->queriedContext){ + case 'Catégorie (Français)': + $category = $this->getInput('catfr'); + $lang = 'fr'; + break; + case 'Catégorie (Allemand)': + $category = $this->getInput('catde'); + $lang = 'de'; + break; + } - public function collectData(){ + $url = self::URI . 'guide/' . $lang . '/plus7/' . $category; + $input = getContents($url) or die('Could not request ARTE.'); - switch($this->queriedContext){ - case 'Catégorie (Français)': - $category=$this->getInput('catfr'); - $lang='fr'; - break; - case 'Catégorie (Allemand)': - $category=$this->getInput('catde'); - $lang='de'; - break; - } + 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] . '}]}'; + } - $url = self::URI.'guide/'.$lang.'/plus7/'.$category; - $input = getContents($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 = json_decode(html_entity_decode($input, ENT_QUOTES), true); - $input_json = json_decode(html_entity_decode($input, ENT_QUOTES), TRUE); + foreach($input_json['videos'] as $element) { + $item = array(); + $item['uri'] = str_replace("autoplay=1", "", $element['url']); + $item['id'] = $element['id']; - foreach($input_json['videos'] as $element) { - $item = array(); - $item['uri'] = str_replace("autoplay=1", "", $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['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; - } - } + $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['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; + } + } } diff --git a/bridges/AskfmBridge.php b/bridges/AskfmBridge.php index 45bcc36f..85d469fc 100644 --- a/bridges/AskfmBridge.php +++ b/bridges/AskfmBridge.php @@ -1,52 +1,66 @@ array( - 'u'=>array( - 'name'=>'Username', - 'required'=>true - ) - ) - ); + const MAINTAINER = 'az5he6ch'; + const NAME = 'Ask.fm Answers'; + const URI = 'http://ask.fm/'; + const CACHE_TIMEOUT = 300; //5 min + const DESCRIPTION = 'Returns answers from an Ask.fm user'; + const PARAMETERS = array( + 'Ask.fm username' => array( + 'u' => array( + 'name' => 'Username', + 'required' => true + ) + ) + ); - public function collectData(){ - $html = getSimpleHTMLDOM($this->getURI()) - or returnServerError('Requested username can\'t be found.'); + public function collectData(){ + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Requested username can\'t be found.'); - foreach($html->find('div.streamItem-answer') as $element) { - $item = array(); - $item['uri'] = self::URI.$element->find('a.streamItemsAge',0)->href; - $question = trim($element->find('h1.streamItemContent-question',0)->innertext); - $item['title'] = trim(htmlspecialchars_decode($element->find('h1.streamItemContent-question',0)->plaintext, ENT_QUOTES)); - $answer = trim($element->find('p.streamItemContent-answer',0)->innertext); - #$item['update'] = $element->find('a.streamitemsage',0)->data-hint; // Doesn't work, DOM parser doesn't seem to like data-hint, dunno why - $visual = $element->find('div.streamItemContent-visual',0)->innertext; // This probably should be cleaned up, especially for YouTube embeds - //Fix tracking links, also doesn't work - foreach($element->find('a') as $link) { - if (strpos($link->href, 'l.ask.fm') !== false) { - #$link->href = str_replace('#_=_', '', get_headers($link->href, 1)['Location']); // Too slow - $link->href = $link->plaintext; - } - } - $content = '

' . $question . '

' . $answer . '

' . $visual . '

'; - // Fix relative links without breaking // scheme used by YouTube stuff - $content = preg_replace('#href="\/(?!\/)#', 'href="'.self::URI,$content); - $item['content'] = $content; - $this->items[] = $item; - } - } + foreach($html->find('div.streamItem-answer') as $element){ + $item = array(); + $item['uri'] = self::URI . $element->find('a.streamItemsAge', 0)->href; + $question = trim($element->find('h1.streamItemContent-question', 0)->innertext); - public function getName(){ - return self::NAME.' : '.$this->getInput('u'); - } + $item['title'] = trim( + htmlspecialchars_decode($element->find('h1.streamItemContent-question', 0)->plaintext, + ENT_QUOTES + ) + ); - public function getURI(){ - return self::URI.urlencode($this->getInput('u')).'/answers/more?page=0'; - } + $answer = trim($element->find('p.streamItemContent-answer', 0)->innertext); + + // Doesn't work, DOM parser doesn't seem to like data-hint, dunno why + #$item['update'] = $element->find('a.streamitemsage',0)->data-hint; + + // This probably should be cleaned up, especially for YouTube embeds + $visual = $element->find('div.streamItemContent-visual', 0)->innertext; + //Fix tracking links, also doesn't work + foreach($element->find('a') as $link){ + if(strpos($link->href, 'l.ask.fm') !== false) { + + // Too slow + #$link->href = str_replace('#_=_', '', get_headers($link->href, 1)['Location']); + + $link->href = $link->plaintext; + } + } + + $content = '

' . $question . '

' . $answer . '

' . $visual . '

'; + // Fix relative links without breaking // scheme used by YouTube stuff + $content = preg_replace('#href="\/(?!\/)#', 'href="' . self::URI, $content); + $item['content'] = $content; + $this->items[] = $item; + } + } + + public function getName(){ + return self::NAME . ' : ' . $this->getInput('u'); + } + + public function getURI(){ + return self::URI . urlencode($this->getInput('u')) . '/answers/more?page=0'; + } } diff --git a/bridges/BandcampBridge.php b/bridges/BandcampBridge.php index 70df97b0..7156de46 100644 --- a/bridges/BandcampBridge.php +++ b/bridges/BandcampBridge.php @@ -1,43 +1,55 @@ array( - 'name'=>'tag', - 'type'=>'text', - 'required'=>true - ) - )); + const MAINTAINER = 'sebsauvage'; + const NAME = 'Bandcamp Tag'; + const URI = 'http://bandcamp.com/'; + const CACHE_TIMEOUT = 600; // 10min + const DESCRIPTION = 'New bandcamp release by tag'; + const PARAMETERS = array( array( + 'tag' => array( + 'name' => 'tag', + 'type' => 'text', + 'required' => true + ) + )); - public function collectData(){ - $html = getSimpleHTMLDOM($this->getURI()) - or returnServerError('No results for this query.'); + public function collectData(){ + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('No results for this query.'); - foreach($html->find('li.item') as $release) { - $script = $release->find('div.art', 0)->getAttribute('onclick'); - $uri = ltrim($script, "return 'url("); - $uri = rtrim($uri, "')"); + foreach($html->find('li.item') as $release){ + $script = $release->find('div.art', 0)->getAttribute('onclick'); + $uri = ltrim($script, "return 'url("); + $uri = rtrim($uri, "')"); - $item = array(); - $item['author'] = $release->find('div.itemsubtext',0)->plaintext . ' - ' . $release->find('div.itemtext',0)->plaintext; - $item['title'] = $release->find('div.itemsubtext',0)->plaintext . ' - ' . $release->find('div.itemtext',0)->plaintext; - $item['content'] = '
' . $release->find('div.itemsubtext',0)->plaintext . ' - ' . $release->find('div.itemtext',0)->plaintext; - $item['id'] = $release->find('a',0)->getAttribute('href'); - $item['uri'] = $release->find('a',0)->getAttribute('href'); - $this->items[] = $item; - } - } + $item = array(); + $item['author'] = $release->find('div.itemsubtext', 0)->plaintext + . ' - ' + . $release->find('div.itemtext', 0)->plaintext; - public function getURI(){ - return self::URI.'tag/'.urlencode($this->getInput('tag')).'?sort_field=date'; - } + $item['title'] = $release->find('div.itemsubtext', 0)->plaintext + . ' - ' + . $release->find('div.itemtext', 0)->plaintext; - public function getName(){ - return $this->getInput('tag') .' - '.'Bandcamp Tag'; - } + $item['content'] = '
' + . $release->find('div.itemsubtext', 0)->plaintext + . ' - ' + . $release->find('div.itemtext', 0)->plaintext; + + $item['id'] = $release->find('a', 0)->getAttribute('href'); + $item['uri'] = $release->find('a', 0)->getAttribute('href'); + $this->items[] = $item; + } + } + + public function getURI(){ + return self::URI . 'tag/' . urlencode($this->getInput('tag')) . '?sort_field=date'; + } + + public function getName(){ + return $this->getInput('tag') . ' - Bandcamp Tag'; + } } diff --git a/bridges/BastaBridge.php b/bridges/BastaBridge.php index b700272c..11a31ac8 100644 --- a/bridges/BastaBridge.php +++ b/bridges/BastaBridge.php @@ -1,32 +1,34 @@ find('item') as $element) { - if($limit < 10) { + foreach($html->find('item') as $element){ + if($limit < 10){ $item = array(); $item['title'] = $element->find('title', 0)->innertext; $item['uri'] = $element->find('guid', 0)->plaintext; $item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext); - $item['content'] = ReplaceImageUrl(getSimpleHTMLDOM($item['uri'])->find('div.texte', 0)->innertext); + $item['content'] = replaceImageUrl(getSimpleHTMLDOM($item['uri'])->find('div.texte', 0)->innertext); $this->items[] = $item; $limit++; } } } } -?> diff --git a/bridges/BlaguesDeMerdeBridge.php b/bridges/BlaguesDeMerdeBridge.php index 4cda1184..12814a50 100644 --- a/bridges/BlaguesDeMerdeBridge.php +++ b/bridges/BlaguesDeMerdeBridge.php @@ -1,33 +1,31 @@ find('article.joke_contener') as $element){ + $item = array(); + $temp = $element->find('a'); - foreach($html->find('article.joke_contener') as $element) { - $item = array(); - $temp = $element->find('a'); - if(isset($temp[2])) - { - $item['content'] = trim($element->find('div.joke_text_contener', 0)->innertext); - $uri = $temp[2]->href; - $item['uri'] = $uri; - $item['title'] = substr($uri, (strrpos($uri, "/") + 1)); - $date = $element->find("li.bdm_date",0)->innertext; - $time = mktime(0, 0, 0, substr($date, 3, 2), substr($date, 0, 2), substr($date, 6, 4)); - $item['timestamp'] = $time; - $item['author'] = $element->find("li.bdm_pseudo",0)->innertext;; - $this->items[] = $item; - } - } - } + if(isset($temp[2])){ + $item['content'] = trim($element->find('div.joke_text_contener', 0)->innertext); + $uri = $temp[2]->href; + $item['uri'] = $uri; + $item['title'] = substr($uri, (strrpos($uri, "/") + 1)); + $date = $element->find('li.bdm_date', 0)->innertext; + $time = mktime(0, 0, 0, substr($date, 3, 2), substr($date, 0, 2), substr($date, 6, 4)); + $item['timestamp'] = $time; + $item['author'] = $element->find('li.bdm_pseudo', 0)->innertext; + $this->items[] = $item; + } + } + } } -?> diff --git a/bridges/BooruprojectBridge.php b/bridges/BooruprojectBridge.php index b6df6654..d60a9f20 100644 --- a/bridges/BooruprojectBridge.php +++ b/bridges/BooruprojectBridge.php @@ -1,36 +1,37 @@ array( + 'p' => array( + 'name' => 'page', + 'type' => 'number' + ), + 't' => array( + 'name' => 'tags' + ) + ), + 'Booru subdomain (subdomain.booru.org)' => array( + 'i' => array( + 'name' => 'Subdomain', + 'required' => true + ) + ) + ); - const PARAMETERS = array( - 'global'=>array( - 'p'=>array( - 'name'=>'page', - 'type'=>'number' - ), - 't'=>array('name'=>'tags') - ), - 'Booru subdomain (subdomain.booru.org)'=>array( - 'i'=>array( - 'name'=>'Subdomain', - 'required'=>true - ) - ) - ); + const PIDBYPAGE = 20; - const PIDBYPAGE=20; + public function getURI(){ + return 'http://' . $this->getInput('i') . '.booru.org/'; + } - public function getURI(){ - return 'http://'.$this->getInput('i').'.booru.org/'; - } - - public function getName(){ - return static::NAME . ' ' . $this->getInput('i'); - } + public function getName(){ + return static::NAME . ' ' . $this->getInput('i'); + } } diff --git a/bridges/CADBridge.php b/bridges/CADBridge.php index 86c0fefd..761d77f4 100644 --- a/bridges/CADBridge.php +++ b/bridges/CADBridge.php @@ -1,10 +1,10 @@ collectExpandableDatas('http://cdn2.cad-comic.com/rss.xml', 10); @@ -12,11 +12,11 @@ class CADBridge extends FeedExpander { protected function parseItem($newsItem){ $item = parent::parseItem($newsItem); - $item['content'] = $this->CADExtractContent($item['uri']); + $item['content'] = $this->extractCADContent($item['uri']); return $item; } - private function CADExtractContent($url) { + private function extractCADContent($url) { $html3 = getSimpleHTMLDOMCached($url); // The request might fail due to missing https support or wrong URL @@ -35,12 +35,11 @@ class CADBridge extends FeedExpander { default: return 'Daily comic not released yet'; } - $img = implode ($url2[0]); + $img = implode($url2[0]); $html3->clear(); - unset ($html3); + unset($html3); if ($img == '') return 'Daily comic not released yet'; - return ''; + return ''; } } -?> diff --git a/bridges/CNETBridge.php b/bridges/CNETBridge.php index a890edb3..fa76ec0c 100644 --- a/bridges/CNETBridge.php +++ b/bridges/CNETBridge.php @@ -1,76 +1,89 @@ You may specify a topic found in some section URLs, else all topics are selected.'; + const MAINTAINER = 'ORelio'; + const NAME = 'CNET News'; + const URI = 'http://www.cnet.com/'; + const CACHE_TIMEOUT = 1800; // 30min + const DESCRIPTION = 'Returns the newest articles.
You may specify a +topic found in some section URLs, else all topics are selected.'; - const PARAMETERS = array( array( - 'topic'=>array('name'=>'Topic name') - )); + const PARAMETERS = array( array( + 'topic' => array( + 'name' => 'Topic name' + ) + )); - public function collectData(){ + public function collectData(){ - function ExtractFromDelimiters($string, $start, $end) { - if (strpos($string, $start) !== false) { - $section_retrieved = substr($string, strpos($string, $start) + strlen($start)); - $section_retrieved = substr($section_retrieved, 0, strpos($section_retrieved, $end)); - return $section_retrieved; - } return false; - } + function extractFromDelimiters($string, $start, $end){ + if(strpos($string, $start) !== false){ + $section_retrieved = substr($string, strpos($string, $start) + strlen($start)); + $section_retrieved = substr($section_retrieved, 0, strpos($section_retrieved, $end)); + return $section_retrieved; + } - function StripWithDelimiters($string, $start, $end) { - while (strpos($string, $start) !== false) { - $section_to_remove = substr($string, strpos($string, $start)); - $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end)); - $string = str_replace($section_to_remove, '', $string); - } return $string; - } + return false; + } - function CleanArticle($article_html) { - $article_html = '

'.substr($article_html, strpos($article_html, '

') + 3); - $article_html = StripWithDelimiters($article_html, '', ''); - $article_html = StripWithDelimiters($article_html, ''); - $article_html = StripWithDelimiters($article_html, '

'); //strip thead - $html = stristr($html, ''); //remove tbody - $html = str_get_html(stristr($html, '', true)); //remove last tbody and get back as an array - foreach($html->find('tr') as $element){ - $item = array(); - $item['uri'] = $element->find('td', 2)->find('a', 0)->href; - $item['title'] = $element->find('td', 2)->find('a', 0)->plaintext; - $item['team'] = $element->find('td', 1)->innertext; - $item['timestamp'] = strtotime($element->find('td', 0)->plaintext); - $item['content'] = - '' - .$this->seriesTitle.' - '.$item['title'] - .' by '.$item['team'].'
' - .''.$fullhtml->find('div.seriesimg', 0)->innertext.''; - $this->items[] = $item; - } - } + $this->seriesTitle = $fullhtml->find('h4.seriestitle', 0)->plaintext; + // dirty fix for nasty simpledom bug: https://github.com/sebsauvage/rss-bridge/issues/259 + // forcefully removes tbody + $html = $fullhtml->find('table#myTable', 0)->innertext; + $html = stristr($html, '
'); //strip thead + $html = stristr($html, ''); //remove tbody + $html = str_get_html(stristr($html, '', true)); //remove last tbody and get back as an array + foreach($html->find('tr') as $element){ + $item = array(); + $item['uri'] = $element->find('td', 2)->find('a', 0)->href; + $item['title'] = $element->find('td', 2)->find('a', 0)->plaintext; + $item['team'] = $element->find('td', 1)->innertext; + $item['timestamp'] = strtotime($element->find('td', 0)->plaintext); + $item['content'] = '' + . $this->seriesTitle + . ' - ' + . $item['title'] + . ' by ' + . $item['team'] + . '
' + . $fullhtml->find('div.seriesimg', 0)->innertext + . ''; - public function getName(){ - return $this->seriesTitle. ' - ' . static::NAME; - } + $this->items[] = $item; + } + } + + public function getName(){ + return $this->seriesTitle . ' - ' . static::NAME; + } } diff --git a/bridges/OpenClassroomsBridge.php b/bridges/OpenClassroomsBridge.php index d5424eae..24afb29c 100644 --- a/bridges/OpenClassroomsBridge.php +++ b/bridges/OpenClassroomsBridge.php @@ -1,46 +1,45 @@ array( - 'name'=>'Catégorie', - 'type'=>'list', - 'required'=>true, - 'values'=>array( - 'Arts & Culture'=>'arts', - 'Code'=>'code', - 'Design'=>'design', - 'Entreprise'=>'business', - 'Numérique'=>'digital', - 'Sciences'=>'sciences', - 'Sciences Humaines'=>'humainities', - 'Systèmes d\'information'=>'it', - 'Autres'=>'others' - ) - ) - )); + const PARAMETERS = array( array( + 'u' => array( + 'name' => 'Catégorie', + 'type' => 'list', + 'required' => true, + 'values' => array( + 'Arts & Culture' => 'arts', + 'Code' => 'code', + 'Design' => 'design', + 'Entreprise' => 'business', + 'Numérique' => 'digital', + 'Sciences' => 'sciences', + 'Sciences Humaines' => 'humainities', + 'Systèmes d\'information' => 'it', + 'Autres' => 'others' + ) + ) + )); - public function getURI(){ - return self::URI.'/courses?categories='.$this->getInput('u').'&' - .'title=&sort=updatedAt+desc'; - } + public function getURI(){ + return self::URI . '/courses?categories=' . $this->getInput('u') . '&title=&sort=updatedAt+desc'; + } - public function collectData(){ - $html = getSimpleHTMLDOM($this->getURI()) - or returnServerError('Could not request OpenClassrooms.'); + public function collectData(){ + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request OpenClassrooms.'); - foreach($html->find('.courseListItem') as $element) { - $item = array(); - $item['uri'] = self::URI.$element->find('a', 0)->href; - $item['title'] = $element->find('h3', 0)->plaintext; - $item['content'] = $element->find('slidingItem__descriptionContent', 0)->plaintext; - $this->items[] = $item; - } - } + foreach($html->find('.courseListItem') as $element){ + $item = array(); + $item['uri'] = self::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 ee94e700..6a6f1440 100644 --- a/bridges/ParuVenduImmoBridge.php +++ b/bridges/ParuVenduImmoBridge.php @@ -1,96 +1,98 @@ array( + 'name' => 'Minimal surface m²', + 'type' => 'number' + ), + 'maxprice' => array( + 'name' => 'Max price', + 'type' => 'number' + ), + 'pa' => array( + 'name' => 'Country code', + 'exampleValue' => 'FR' + ), + 'lo' => array( + 'name' => 'department numbers or postal codes, comma-separated' + ) + )); - const PARAMETERS = array( array( - 'minarea'=>array( - 'name'=>'Minimal surface m²', - 'type'=>'number' - ), - 'maxprice'=>array( - 'name'=>'Max price', - 'type'=>'number' - ), - 'pa'=>array( - 'name'=>'Country code', - 'exampleValue'=>'FR' - ), - 'lo'=>array('name'=>'department numbers or postal codes, comma-separated') - )); + public function collectData(){ + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request paruvendu.'); - public function collectData() - { - $html = getSimpleHTMLDOM($this->getURI()) - or returnServerError('Could not request paruvendu.'); + foreach($html->find('div.annonce a') as $element){ - foreach($html->find('div.annonce a') as $element) { + if(!$element->title){ + continue; + } - if (!$element->title) { - continue; - } + $img = ''; + foreach($element->find('span.img img') as $img){ + if($img->original){ + $img = ''; + } + } - $img =''; - foreach($element->find('span.img img') as $img) { - if ($img->original) { - $img = ''; - } - } + $desc = $element->find('span.desc')[0]->innertext; + $desc = str_replace("voir l'annonce", '', $desc); - $desc = $element->find('span.desc')[0]->innertext; - $desc = str_replace("voir l'annonce", '', $desc); + $price = $element->find('span.price')[0]->innertext; - $price = $element->find('span.price')[0]->innertext; + list($href) = explode('#', $element->href); - list($href) = explode('#', $element->href); + $item = array(); + $item['uri'] = self::URI . $href; + $item['title'] = $element->title; + $item['content'] = $img . $desc . $price; + $this->items[] = $item; + } + } - $item = array(); - $item['uri'] = self::URI.$href; - $item['title'] = $element->title; - $item['content'] = $img.$desc.$price; - $this->items[] = $item; + 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 = self::URI + . '/immobilier/annonceimmofo/liste/listeAnnonces?tt=1' + . $appartment + . $maison; - } - } + if($this->getInput('minarea')){ + $link .= '&sur0=' . urlencode($this->getInput('minarea')); + } - 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 = self::URI.'/immobilier/annonceimmofo/liste/listeAnnonces?tt=1'.$appartment.$maison; + if($this->getInput('maxprice')){ + $link .= '&px1=' . urlencode($this->getInput('maxprice')); + } - if ($this->getInput('minarea')) { - $link .= '&sur0='.urlencode($this->getInput('minarea')); - } + if($this->getInput('pa')){ + $link .= '&pa=' . urlencode($this->getInput('pa')); + } - if ($this->getInput('maxprice')) { - $link .= '&px1='.urlencode($this->getInput('maxprice')); - } + if($this->getInput('lo')){ + $link .= '&lo=' . urlencode($this->getInput('lo')); + } + return $link; + } - 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=''; - $minarea=$this->getInput('minarea'); - if(!empty($minarea)){ - $request .= ' '.$minarea.' m2'; - } - $location=$this->getInput('lo'); - if(!empty($location)){ - $request .= ' In: '.$location; - } - return 'Paru Vendu Immobilier'.$request; - } + public function getName(){ + $request = ''; + $minarea = $this->getInput('minarea'); + if(!empty($minarea)){ + $request .= ' ' . $minarea . ' m2'; + } + $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 cef99a28..a2be7edd 100644 --- a/bridges/PickyWallpapersBridge.php +++ b/bridges/PickyWallpapersBridge.php @@ -1,73 +1,93 @@ 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}' - ) - )); + const PARAMETERS = array( array( + '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(){ + $lastpage = 1; + $num = 0; + $max = $this->getInput('m'); + $resolution = $this->getInput('r'); // Wide wallpaper default - public function collectData(){ - $lastpage = 1; - $num = 0; - $max = $this->getInput('m'); - $resolution = $this->getInput('r'); // Wide wallpaper default + for($page = 1; $page <= $lastpage; $page++){ + $html = getSimpleHTMLDOM($this->getURI() . '/page-' . $page . '/') + or returnServerError('No results for this query.'); - for ($page = 1; $page <= $lastpage; $page++) { - $html = getSimpleHTMLDOM($this->getURI().'/page-'.$page.'/') - or returnServerError('No results for this query.'); + if($page === 1){ + preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches); + $lastpage = min($matches[1], ceil($max / 12)); + } - if ($page === 1) { - preg_match('/page-(\d+)\/$/', $html->find('.pages li a', -2)->href, $matches); - $lastpage = min($matches[1], ceil($max/12)); - } + foreach($html->find('.items li img') as $element){ + $item = array(); + $item['uri'] = str_replace('www', 'wallpaper', self::URI) + . '/' + . $resolution + . '/' + . basename($element->src); - foreach($html->find('.items li img') as $element) { + $item['timestamp'] = time(); + $item['title'] = $element->alt; + $item['content'] = $item['title'] + . '
' + . $element + . ''; - $item = array(); - $item['uri'] = str_replace('www', 'wallpaper', self::URI).'/'.$resolution.'/'.basename($element->src); - $item['timestamp'] = time(); - $item['title'] = $element->alt; - $item['content'] = $item['title'].'
'.$element.''; - $this->items[] = $item; + $this->items[] = $item; - $num++; - if ($num >= $max) - break 2; - } - } - } + $num++; + if ($num >= $max) + break 2; + } + } + } - public function getURI(){ - $subcategory = $this->getInput('s'); - $link = self::URI.$this->getInput('r').'/'.$this->getInput('c').'/'.$subcategory; - return $link; - } + public function getURI(){ + $subcategory = $this->getInput('s'); + $link = self::URI + . $this->getInput('r') + . '/' + . $this->getInput('c') + . '/' + . $subcategory; - public function getName(){ - $subcategory = $this->getInput('s'); - return 'PickyWallpapers - '.$this->getInput('c') - .($subcategory? ' > '.$subcategory : '') - .' ['.$this->getInput('r').']'; - } + return $link; + } + + public function getName(){ + $subcategory = $this->getInput('s'); + return 'PickyWallpapers - ' + . $this->getInput('c') + . ($subcategory ? ' > ' . $subcategory : '') + . ' [' + . $this->getInput('r') + . ']'; + } } diff --git a/bridges/PinterestBridge.php b/bridges/PinterestBridge.php index 1d8895e2..68989790 100644 --- a/bridges/PinterestBridge.php +++ b/bridges/PinterestBridge.php @@ -1,10 +1,10 @@ array( @@ -63,8 +63,7 @@ class PinterestBridge extends BridgeAbstract { . htmlentities($item['avatar']) . '" /> ' . $item['username'] - . '' - . '
' + . '
' . $item['fullname']; $item['title'] = $img->getAttribute('alt'); diff --git a/bridges/PlanetLibreBridge.php b/bridges/PlanetLibreBridge.php index 469c37e4..ecf687bd 100644 --- a/bridges/PlanetLibreBridge.php +++ b/bridges/PlanetLibreBridge.php @@ -1,28 +1,35 @@ find('div[class="post-text"]', 0)->innertext; return $text; } public function collectData(){ - $html = getSimpleHTMLDOM(self::URI) - or returnServerError('Could not request PlanetLibre.'); + $html = getSimpleHTMLDOM(self::URI) + or returnServerError('Could not request PlanetLibre.'); $limit = 0; - foreach($html->find('div.post') as $element) { - if($limit < 5) { + foreach($html->find('div.post') as $element){ + if($limit < 5){ $item = array(); $item['title'] = $element->find('h1', 0)->plaintext; $item['uri'] = $element->find('a', 0)->href; - $item['timestamp'] = strtotime(str_replace('/', '-', $element->find('div[class="post-date"]', 0)->plaintext)); - $item['content'] = $this->PlanetLibreExtractContent($item['uri']); + $item['timestamp'] = strtotime( + str_replace( + '/', + '-', + $element->find('div[class="post-date"]', 0)->plaintext + ) + ); + + $item['content'] = $this->extractContent($item['uri']); $this->items[] = $item; $limit++; } diff --git a/bridges/RTBFBridge.php b/bridges/RTBFBridge.php index 54e1a58a..dda01f5b 100644 --- a/bridges/RTBFBridge.php +++ b/bridges/RTBFBridge.php @@ -1,38 +1,46 @@ array( - 'name'=>'series id', - 'exampleValue'=>9500, - 'required'=>true - ) - )); + const PARAMETERS = array( array( + 'c' => array( + 'name' => 'series id', + 'exampleValue' => 9500, + 'required' => true + ) + )); public function collectData(){ $html = ''; $limit = 10; $count = 0; - $html = getSimpleHTMLDOM($this->getURI()) - or returnServerError('Could not request RTBF.'); + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request RTBF.'); + + foreach($html->find('section[id!=widget-ml-avoiraussi-] .rtbf-media-grid article') as $element){ + if($count >= $limit){ + break; + } - 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'] = self::URI.'detail?id='.$item['id']; - $thumbnailUriSrcSet = explode(',', $element->find('figure .www-img-16by9 img', 0)->getAttribute('data-srcset')); + $item['uri'] = self::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['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; @@ -40,9 +48,9 @@ class RTBFBridge extends BridgeAbstract { } } - public function getURI(){ - return self::URI.'detail?id='.$this->getInput('c'); - } + public function getURI(){ + return self::URI . 'detail?id=' . $this->getInput('c'); + } public function getName(){ return $this->getInput('c') .' - RTBF Bridge'; diff --git a/bridges/ReadComicsBridge.php b/bridges/ReadComicsBridge.php index 59f48d3c..8540fe3e 100644 --- a/bridges/ReadComicsBridge.php +++ b/bridges/ReadComicsBridge.php @@ -1,43 +1,44 @@ array( - 'name'=>'keywords, separated by semicolons', - 'exampleValue'=>'first list;second list;...', - 'required'=>true - ), - )); + const PARAMETERS = array( array( + 'q' => array( + 'name' => 'keywords, separated by semicolons', + 'exampleValue' => 'first list;second list;...', + 'required' => true + ), + )); public function collectData(){ - function parseDateTimestamp($element){ - $guessedDate = $element->find('span',0)->plaintext; - $guessedDate = strptime($guessedDate, '%m/%d/%Y'); - $timestamp = mktime(0, 0, 0, $guessedDate['tm_mon'] + 1, $guessedDate['tm_mday'], date('Y')); - - return $timestamp; - } + function parseDateTimestamp($element){ + $guessedDate = $element->find('span', 0)->plaintext; + $guessedDate = strptime($guessedDate, '%m/%d/%Y'); + $timestamp = mktime(0, 0, 0, $guessedDate['tm_mon'] + 1, $guessedDate['tm_mday'], date('Y')); - $keywordsList = explode(";",$this->getInput('q')); - foreach($keywordsList as $keywords){ - $html = $this->getSimpleHTMLDOM(self::URI.'comic/'.rawurlencode($keywords)) - or $this->returnServerError('Could not request readcomics.tv.'); + return $timestamp; + } - foreach($html->find('li') as $element) { - $item = array(); - $item['uri'] = $element->find('a.ch-name',0)->href; - $item['id'] = $item['uri']; - $item['timestamp'] = parseDateTimestamp($element); - $item['title'] = $element->find('a.ch-name',0)->plaintext; - if(isset($item['title'])) - $this->items[] = $item; - } - } + $keywordsList = explode(";", $this->getInput('q')); + foreach($keywordsList as $keywords){ + $html = $this->getSimpleHTMLDOM(self::URI . 'comic/' . rawurlencode($keywords)) + or $this->returnServerError('Could not request readcomics.tv.'); + + foreach($html->find('li') as $element){ + $item = array(); + $item['uri'] = $element->find('a.ch-name', 0)->href; + $item['id'] = $item['uri']; + $item['timestamp'] = parseDateTimestamp($element); + $item['title'] = $element->find('a.ch-name', 0)->plaintext; + if(isset($item['title'])) + $this->items[] = $item; + } + } } } diff --git a/bridges/Releases3DSBridge.php b/bridges/Releases3DSBridge.php index 535ecf34..c14e576e 100644 --- a/bridges/Releases3DSBridge.php +++ b/bridges/Releases3DSBridge.php @@ -1,120 +1,136 @@ ', $xml)) as $element) { - if ($limit >= 5) { - break; - } + $dataUrl = self::URI . 'xml.php'; + $xml = getContents($dataUrl) + or returnServerError('Could not request 3dsdb: ' . $dataUrl); + $limit = 0; - if (strpos($element, '') === false) { - continue; - } + foreach(array_reverse(explode('', $xml)) as $element){ + if($limit >= 5){ + break; + } - $releasename = ExtractFromDelimiters($element, '', ''); - if (empty($releasename)) { - continue; - } + if(strpos($element, '') === false){ + 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, '', ''); + $releasename = extractFromDelimiters($element, '', ''); + if(empty($releasename)){ + continue; + } - //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 = 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
'; - } + $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, '', ''); - //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).'
'; + //Retrieve cover art and short desc from IGN? + $ignResult = false; + $ignDescription = ''; + $ignLink = ''; + $ignDate = time(); + $ignCoverArt = ''; - //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

'; + $ignSearchUrl = 'http://www.ign.com/search?q=' . urlencode($name); + if($ignResult = 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
'; + } - //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++; - } - } + //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 be4ceee3..dff8818f 100644 --- a/bridges/ReporterreBridge.php +++ b/bridges/ReporterreBridge.php @@ -1,39 +1,44 @@ find('div[style=text-align:justify]') as $e) { + foreach($html2->find('div[style=text-align:justify]') as $e){ $text = $e->outertext; } $html2->clear(); - unset ($html2); + unset($html2); // Replace all relative urls with absolute ones - $text = preg_replace('/(href|src)(\=[\"\'])(?!http)([^"\']+)/ims', "$1$2" . self::URI . "$3", $text); + $text = preg_replace( + '/(href|src)(\=[\"\'])(?!http)([^"\']+)/ims', + "$1$2" . self::URI . "$3", + $text + ); $text = strip_tags($text, '


'); return $text; } public function collectData(){ - $html = getSimpleHTMLDOM(self::URI.'spip.php?page=backend') or returnServerError('Could not request Reporterre.'); + $html = getSimpleHTMLDOM(self::URI . 'spip.php?page=backend') + or returnServerError('Could not request Reporterre.'); $limit = 0; - foreach($html->find('item') as $element) { + foreach($html->find('item') as $element){ if($limit < 5) { $item = array(); $item['title'] = html_entity_decode($element->find('title', 0)->plaintext); $item['timestamp'] = strtotime($element->find('dc:date', 0)->plaintext); $item['uri'] = $element->find('guid', 0)->innertext; - $item['content'] = html_entity_decode($this->ExtractContentReporterre($item['uri'])); + $item['content'] = html_entity_decode($this->extractContent($item['uri'])); $this->items[] = $item; $limit++; } diff --git a/bridges/Rue89Bridge.php b/bridges/Rue89Bridge.php index 400943eb..65991225 100644 --- a/bridges/Rue89Bridge.php +++ b/bridges/Rue89Bridge.php @@ -1,22 +1,25 @@ collectExpandableDatas('http://api.rue89.nouvelobs.com/feed'); - } + } } diff --git a/bridges/Rule34Bridge.php b/bridges/Rule34Bridge.php index 62a9e105..b46ec00a 100644 --- a/bridges/Rule34Bridge.php +++ b/bridges/Rule34Bridge.php @@ -1,12 +1,12 @@ find('article') as $article) { - $item = array(); - $item['uri'] = self::URI.$article->find('p.summary a',0)->href; - $item['title'] = $article->find('header h1 a',0)->innertext; + foreach($html->find('article') as $article){ + $item = array(); + $item['uri'] = self::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 - $content = $article->find('p.summary a',0)->innertext; - $content =substr($content,0,strlen($content)-17); // remove superfluous spaces at the end + // remove text "En savoir plus" from anecdote content + $article->find('span.read-more', 0)->outertext = ''; + $content = $article->find('p.summary a', 0)->innertext; + + // remove superfluous spaces at the end + $content = substr($content, 0, strlen($content) - 17); // get publication date - $str_date = $article->find('time',0)->datetime; + $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); + $timestamp = mktime($h, $i, 0, $m, $d, $y); $item['timestamp'] = $timestamp; - $item['content'] = $content; $this->items[] = $item; } - } + } } diff --git a/bridges/ScoopItBridge.php b/bridges/ScoopItBridge.php index 999519b5..462e7e56 100644 --- a/bridges/ScoopItBridge.php +++ b/bridges/ScoopItBridge.php @@ -1,33 +1,42 @@ array( - 'name'=>'keyword', - 'required'=>true - ) - )); + const PARAMETERS = array( array( + 'u' => array( + 'name' => 'keyword', + 'required' => true + ) + )); - public function collectData(){ - $this->request = $this->getInput('u'); - $link = self::URI.'search?q=' .urlencode($this->getInput('u')); + public function collectData(){ + $this->request = $this->getInput('u'); + $link = self::URI . 'search?q=' . urlencode($this->getInput('u')); - $html = getSimpleHTMLDOM($link) - or returnServerError('Could not request ScoopIt. for : ' . $link); + $html = getSimpleHTMLDOM($link) + or 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; - } - } + 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; + } + } } - diff --git a/bridges/SensCritiqueBridge.php b/bridges/SensCritiqueBridge.php index 3daee27e..d8ba094d 100644 --- a/bridges/SensCritiqueBridge.php +++ b/bridges/SensCritiqueBridge.php @@ -1,78 +1,97 @@ array( - 'name'=>'Movies', - 'type'=>'checkbox' - ), - 's'=>array( - 'name'=>'Series', - 'type'=>'checkbox' - ), - 'g'=>array( - 'name'=>'Video Games', - 'type'=>'checkbox' - ), - 'b'=>array( - 'name'=>'Books', - 'type'=>'checkbox' - ), - 'bd'=>array( - 'name'=>'BD', - 'type'=>'checkbox' - ), - 'mu'=>array( - 'name'=>'Music', - 'type'=>'checkbox' - ) - )); + const PARAMETERS = array( array( + 'm' => array( + 'name' => 'Movies', + 'type' => 'checkbox' + ), + 's' => array( + 'name' => 'Series', + 'type' => 'checkbox' + ), + 'g' => array( + 'name' => 'Video Games', + 'type' => 'checkbox' + ), + 'b' => array( + 'name' => 'Books', + 'type' => 'checkbox' + ), + 'bd' => array( + 'name' => 'BD', + 'type' => 'checkbox' + ), + 'mu' => array( + 'name' => 'Music', + 'type' => 'checkbox' + ) + )); public function collectData(){ - $categories=array(); - foreach(self::PARAMETERS[$this->queriedContext] as $category=>$properties){ - if($this->getInput($category)){ - $uri=self::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 = getSimpleHTMLDOM($uri) - or returnServerError('No results for this query.'); - $list = $html->find('ul.elpr-list', 0); + $categories = array(); + foreach(self::PARAMETERS[$this->queriedContext] as $category => $properties){ + if($this->getInput($category)){ + $uri = self::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 = getSimpleHTMLDOM($uri) + or returnServerError('No results for this query.'); + $list = $html->find('ul.elpr-list', 0); - $this->extractDataFromList($list); - } - } - } + $this->extractDataFromList($list); + } + } + } - private function extractDataFromList($list) { - if ($list === null) { + private function extractDataFromList($list){ + if($list === null){ returnClientError('Cannot extract data from list'); } - foreach ($list->find('li') as $movie) { - $item = array(); - $item['author'] = htmlspecialchars_decode($movie->find('.elco-title a', 0)->plaintext, ENT_QUOTES) . ' ' . $movie->find('.elco-date', 0)->plaintext; - $item['title'] = $movie->find('.elco-title a', 0)->plaintext . ' ' . $movie->find('.elco-date', 0)->plaintext; - $item['content'] = '' . $movie->find('.elco-original-title', 0)->plaintext . '

' . - $movie->find('.elco-baseline', 0)->plaintext . '
' . - $movie->find('.elco-baseline', 1)->plaintext . '

' . - $movie->find('.elco-description', 0)->plaintext . '

' . - trim($movie->find('.erra-ratings .erra-global', 0)->plaintext) . ' / 10'; - $item['id'] = $this->getURI() . $movie->find('.elco-title a', 0)->href; - $item['uri'] = $this->getURI() . $movie->find('.elco-title a', 0)->href; - $this->items[] = $item; + foreach($list->find('li') as $movie){ + $item = array(); + $item['author'] = htmlspecialchars_decode($movie->find('.elco-title a', 0)->plaintext, ENT_QUOTES) + . ' ' + . $movie->find('.elco-date', 0)->plaintext; + + $item['title'] = $movie->find('.elco-title a', 0)->plaintext + . ' ' + . $movie->find('.elco-date', 0)->plaintext; + + $item['content'] = '' + . $movie->find('.elco-original-title', 0)->plaintext + . '

' + . $movie->find('.elco-baseline', 0)->plaintext + . '
' + . $movie->find('.elco-baseline', 1)->plaintext + . '

' + . $movie->find('.elco-description', 0)->plaintext + . '

' + . trim($movie->find('.erra-ratings .erra-global', 0)->plaintext) + . ' / 10'; + + $item['id'] = $this->getURI() . $movie->find('.elco-title a', 0)->href; + $item['uri'] = $this->getURI() . $movie->find('.elco-title a', 0)->href; + $this->items[] = $item; } } } diff --git a/bridges/SexactuBridge.php b/bridges/SexactuBridge.php index 4265d3a0..6dd04781 100644 --- a/bridges/SexactuBridge.php +++ b/bridges/SexactuBridge.php @@ -1,75 +1,99 @@ getURI()) or returnServerError('Could not request '.$this->getURI()); + $replace = array( + 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December' + ); - foreach($html->find('.content-holder') as $contentHolder) { - // only use first list as second one only contains pages numbers - $articles = $contentHolder->find('ul', 0); - foreach($articles->find('li') as $element) { - // if you ask about that method_exists, there seems to be a bug in simple html dom - // see stackoverflow for more details : http://stackoverflow.com/a/10828479/15619 - if(is_object($element)) { - $item = array(); - // various metadata - $titleBlock = $element->find('.title-holder', 0); - if(is_object($titleBlock)) { - $titleDetails = $titleBlock->find('.article-title',0); - $titleData = $titleDetails->find('h2', 0)->find('a',0); - $titleTimestamp =$titleDetails->find('h4',0); - $item['title'] = $this->correctCase(trim($titleData->innertext)); - $item['uri'] = self::URI.$titleData->href; + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request ' . $this->getURI()); - // Fugly date parsing due to the fact my DNS-323 doesn't support php intl extension - $dateText = $titleTimestamp->innertext; - $dateText = substr($dateText, strpos($dateText,',')+1); - $dateText = str_replace($find, $replace, strtolower($dateText)); - $date = strtotime($dateText); - $item['timestamp'] = $date; + foreach($html->find('.content-holder') as $contentHolder){ + // only use first list as second one only contains pages numbers + $articles = $contentHolder->find('ul', 0); + foreach($articles->find('li') as $element){ + // if you ask about that method_exists, there seems to be a bug in simple html dom + // see stackoverflow for more details : http://stackoverflow.com/a/10828479/15619 + if(is_object($element)){ + $item = array(); + // various metadata + $titleBlock = $element->find('.title-holder', 0); + if(is_object($titleBlock)){ + $titleDetails = $titleBlock->find('.article-title', 0); + $titleData = $titleDetails->find('h2', 0)->find('a', 0); + $titleTimestamp = $titleDetails->find('h4', 0); + $item['title'] = $this->correctCase(trim($titleData->innertext)); + $item['uri'] = self::URI . $titleData->href; - $item['author'] = "Maïa Mazaurette"; - $elementText = $element->find('.text-container', 0); - // don't forget to replace images server url with gq one - foreach($elementText->find('img') as $image) { - $image->src = self::URI.$image->src; - } - $item['content'] = $elementText->innertext; - $this->items[] = $item; - } + // Fugly date parsing due to the fact my DNS-323 doesn't support php intl extension + $dateText = $titleTimestamp->innertext; + $dateText = substr($dateText, strpos($dateText, ',') + 1); + $dateText = str_replace($find, $replace, strtolower($dateText)); + $date = strtotime($dateText); + $item['timestamp'] = $date; - } + $item['author'] = 'Maïa Mazaurette'; + $elementText = $element->find('.text-container', 0); + // don't forget to replace images server url with gq one + foreach($elementText->find('img') as $image){ + $image->src = self::URI . $image->src; + } + $item['content'] = $elementText->innertext; + $this->items[] = $item; + } + } + } + } + } - } - } - } + public function getURI(){ + return self::URI . '/sexactu'; + } - public function getURI(){ - return self::URI.'/sexactu'; - } + private function correctCase($str){ + $sentences = explode('.', mb_strtolower($str, 'UTF-8')); + $str = ''; + $sep = ''; + foreach ($sentences as $sentence){ + //upper case first char + $sentence = ucfirst(trim($sentence)); - private function correctCase($str) { - $sentences=explode('.', mb_strtolower($str, "UTF-8")); - $str=""; - $sep=""; - foreach ($sentences as $sentence) - { - //upper case first char - $sentence=ucfirst(trim($sentence)); - - //append sentence to output - $str=$str.$sep.$sentence; - $sep=". "; - } - return $str; - } + //append sentence to output + $str = $str . $sep . $sentence; + $sep = '. '; + } + return $str; + } } diff --git a/bridges/ShanaprojectBridge.php b/bridges/ShanaprojectBridge.php index 7439d785..d5fda9f5 100644 --- a/bridges/ShanaprojectBridge.php +++ b/bridges/ShanaprojectBridge.php @@ -1,109 +1,123 @@ getURI() . '/seasons'); - if(!$html) - returnServerError('Could not load \'seasons\' page!'); + // Returns an html object for the Season Anime List (latest season) + private function loadSeasonAnimeList(){ + // First we need to find the URI to the latest season from the + // 'seasons' page searching for 'Season Anime List' + $html = getSimpleHTMLDOM($this->getURI() . '/seasons'); + if(!$html) + returnServerError('Could not load \'seasons\' page!'); - $season = $html->find('div.follows_menu/a', 1); - if(!$season) - returnServerError('Could not find \'Season Anime List\'!'); + $season = $html->find('div.follows_menu/a', 1); + if(!$season) + returnServerError('Could not find \'Season Anime List\'!'); - $html = getSimpleHTMLDOM($this->getURI() . $season->href); - if(!$html) - returnServerError('Could not load \'Season Anime List\' from \'' . $season->innertext . '\'!'); + $html = getSimpleHTMLDOM($this->getURI() . $season->href); + if(!$html) + returnServerError( + 'Could not load \'Season Anime List\' from \'' + . $season->innertext + . '\'!' + ); - return $html; - } + return $html; + } - // Extracts the anime title - private function ExtractAnimeTitle($anime){ - $title = $anime->find('a', 0); - if(!$title) - returnServerError('Could not find anime title!'); - return trim($title->innertext); - } + // Extracts the anime title + private function extractAnimeTitle($anime){ + $title = $anime->find('a', 0); + if(!$title) + returnServerError('Could not find anime title!'); + return trim($title->innertext); + } - // Extracts the anime URI - private function ExtractAnimeURI($anime){ - $uri = $anime->find('a', 0); - if(!$uri) - returnServerError('Could not find anime URI!'); - return $this->getURI() . $uri->href; - } + // Extracts the anime URI + private function extractAnimeUri($anime){ + $uri = $anime->find('a', 0); + if(!$uri) + returnServerError('Could not find anime URI!'); + return $this->getURI() . $uri->href; + } - // Extracts the anime release date (timestamp) - private function ExtractAnimeTimestamp($anime){ - $timestamp = $anime->find('span.header_info_block', 1); - if(!$timestamp) - returnServerError('Could not find anime timestamp!'); - return strtotime($timestamp->innertext); - } + // Extracts the anime release date (timestamp) + private function extractAnimeTimestamp($anime){ + $timestamp = $anime->find('span.header_info_block', 1); + if(!$timestamp) + returnServerError('Could not find anime timestamp!'); + return strtotime($timestamp->innertext); + } - // Extracts the anime studio name (author) - private function ExtractAnimeAuthor($anime){ - $author = $anime->find('span.header_info_block', 2); - if(!$author) - return; // Sometimes the studio is unknown, so leave empty - return trim($author->innertext); - } + // Extracts the anime studio name (author) + private function extractAnimeAuthor($anime){ + $author = $anime->find('span.header_info_block', 2); + if(!$author) + return; // Sometimes the studio is unknown, so leave empty + return trim($author->innertext); + } - // Extracts the episode information (x of y released) - private function ExtractAnimeEpisodeInformation($anime){ - $episode = $anime->find('div.header_info_episode', 0); - if(!$episode) - returnServerError('Could not find anime episode information!'); - return preg_replace('/\r|\n/', ' ', $episode->plaintext); - } + // Extracts the episode information (x of y released) + private function extractAnimeEpisodeInformation($anime){ + $episode = $anime->find('div.header_info_episode', 0); + if(!$episode) + returnServerError('Could not find anime episode information!'); + return preg_replace('/\r|\n/', ' ', $episode->plaintext); + } - // Extracts the background image - private function ExtractAnimeBackgroundImage($anime){ - // Getting the picture is a little bit tricky as it is part of the style. - // Luckily the style is part of the parent div :) + // Extracts the background image + private function extractAnimeBackgroundImage($anime){ + // Getting the picture is a little bit tricky as it is part of the style. + // Luckily the style is part of the parent div :) - if(preg_match("/url\(\/\/([^\)]+)\)/i", $anime->parent->style, $matches)) - return $matches[1]; + if(preg_match("/url\(\/\/([^\)]+)\)/i", $anime->parent->style, $matches)) + return $matches[1]; - returnServerError('Could not extract background image!'); - } + returnServerError('Could not extract background image!'); + } - // Builds an URI to search for a specific anime (subber is left empty) - private function BuildAnimeSearchURI($anime){ - return $this->getURI() . '/search/?title=' . urlencode($this->ExtractAnimeTitle($anime)) . '&subber='; - } + // Builds an URI to search for a specific anime (subber is left empty) + private function buildAnimeSearchUri($anime){ + return $this->getURI() + . '/search/?title=' + . urlencode($this->extractAnimeTitle($anime)) + . '&subber='; + } - // Builds the content string for a given anime - private function BuildAnimeContent($anime){ - // We'll use a template string to place our contents - return '
- ' . htmlspecialchars($this->ExtractAnimeTitle($anime)) . ' -
-

' . $this->ExtractAnimeEpisodeInformation($anime) . '


-

Search episodes

'; - } + // Builds the content string for a given anime + private function buildAnimeContent($anime){ + // We'll use a template string to place our contents + return ''
+		. htmlspecialchars($this->extractAnimeTitle($anime))
+		. '

' + . $this->extractAnimeEpisodeInformation($anime) + . '


Search episodes

'; + } - public function collectData(){ - $html = $this->LoadSeasonAnimeList(); + public function collectData(){ + $html = $this->loadSeasonAnimeList(); - $animes = $html->find('div.header_display_box_info'); - if(!$animes) - returnServerError('Could not find anime headers!'); + $animes = $html->find('div.header_display_box_info'); + if(!$animes) + returnServerError('Could not find anime headers!'); - foreach($animes as $anime){ - $item = array(); - $item['title'] = $this->ExtractAnimeTitle($anime); - $item['author'] = $this->ExtractAnimeAuthor($anime); - $item['uri'] = $this->ExtractAnimeURI($anime); - $item['timestamp'] = $this->ExtractAnimeTimestamp($anime); - $item['content'] = $this->BuildAnimeContent($anime); - $this->items[] = $item; - } - } + foreach($animes as $anime){ + $item = array(); + $item['title'] = $this->extractAnimeTitle($anime); + $item['author'] = $this->extractAnimeAuthor($anime); + $item['uri'] = $this->extractAnimeUri($anime); + $item['timestamp'] = $this->extractAnimeTimestamp($anime); + $item['content'] = $this->buildAnimeContent($anime); + $this->items[] = $item; + } + } } diff --git a/bridges/Shimmie2Bridge.php b/bridges/Shimmie2Bridge.php index 80a242ae..efbcd9b7 100644 --- a/bridges/Shimmie2Bridge.php +++ b/bridges/Shimmie2Bridge.php @@ -1,31 +1,39 @@ getURI().'post/list/' - .$this->getInput('t').'/' - .$this->getInput('p'); - } + protected function getFullURI(){ + return $this->getURI() + . 'post/list/' + . $this->getInput('t') + . '/' + . $this->getInput('p'); + } - protected function getItemFromElement($element){ - $item = array(); - $item['uri'] = $this->getURI().$element->href; - $item['id'] = (int)preg_replace("/[^0-9]/",'', $element->getAttribute(static::IDATTRIBUTE)); - $item['timestamp'] = time(); - $thumbnailUri = $this->getURI().$element->find('img', 0)->src; - $item['tags'] = $element->getAttribute('data-tags'); - $item['title'] = $this->getName().' | '.$item['id']; - $item['content'] = '
Tags: '.$item['tags']; - return $item; - } + protected function getItemFromElement($element){ + $item = array(); + $item['uri'] = $this->getURI() . $element->href; + $item['id'] = (int)preg_replace("/[^0-9]/", '', $element->getAttribute(static::IDATTRIBUTE)); + $item['timestamp'] = time(); + $thumbnailUri = $this->getURI() . $element->find('img', 0)->src; + $item['tags'] = $element->getAttribute('data-tags'); + $item['title'] = $this->getName() . ' | ' . $item['id']; + $item['content'] = '
Tags: ' + . $item['tags']; + + return $item; + } } diff --git a/bridges/SoundcloudBridge.php b/bridges/SoundcloudBridge.php index 7f7da37e..cb4ba915 100644 --- a/bridges/SoundcloudBridge.php +++ b/bridges/SoundcloudBridge.php @@ -1,50 +1,60 @@ array( - 'name'=>'username', - 'required'=>true - ) - )); + const PARAMETERS = array( array( + 'u' => array( + 'name' => 'username', + 'required' => true + ) + )); - const CLIENT_ID = '0aca19eae3843844e4053c6d8fdb7875'; + const CLIENT_ID = '0aca19eae3843844e4053c6d8fdb7875'; public function collectData(){ - $res = json_decode(getContents( - 'https://api.soundcloud.com/resolve?url=http://www.soundcloud.com/' - . urlencode($this->getInput('u')) - .'&client_id=' . self::CLIENT_ID - )) or returnServerError('No results for this query'); - $tracks = json_decode(getContents( - 'https://api.soundcloud.com/users/' - . urlencode($res->id) - .'/tracks?client_id=' . self::CLIENT_ID - )) or returnServerError('No results for this user'); + $res = json_decode(getContents( + 'https://api.soundcloud.com/resolve?url=http://www.soundcloud.com/' + . urlencode($this->getInput('u')) + . '&client_id=' + . self::CLIENT_ID + )) or returnServerError('No results for this query'); - for ($i=0; $i < 10; $i++) { - $item = array(); - $item['author'] = $tracks[$i]->user->username .' - '. $tracks[$i]->title; - $item['title'] = $tracks[$i]->user->username .' - '. $tracks[$i]->title; - $item['content'] = '