2016-02-13 13:52:28 +01:00
|
|
|
<?php
|
|
|
|
class NeuviemeArtBridge extends BridgeAbstract {
|
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "ORelio";
|
|
|
|
const NAME = '9ème Art Bridge';
|
|
|
|
const URI = "http://www.9emeart.fr/";
|
|
|
|
const DESCRIPTION = "Returns the newest articles.";
|
2016-02-13 13:52:28 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
2016-02-13 13:52:28 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
$feedUrl = self::URI.'9emeart.rss';
|
2016-07-08 19:06:35 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM($feedUrl) or $this->returnServerError('Could not request 9eme Art: '.$feedUrl);
|
2016-02-13 13:52:28 +01:00
|
|
|
$limit = 0;
|
|
|
|
|
|
|
|
foreach ($html->find('item') as $element) {
|
|
|
|
if ($limit < 5) {
|
|
|
|
|
|
|
|
//Retrieve article Uri and get that page
|
|
|
|
$article_uri = $element->find('guid', 0)->plaintext;
|
2016-07-08 19:06:35 +02:00
|
|
|
$article_html = $this->getSimpleHTMLDOM($article_uri) or $this->returnServerError('Could not request 9eme Art: '.$article_uri);
|
2016-02-13 13:52:28 +01:00
|
|
|
|
|
|
|
//Build article contents from corresponding elements
|
|
|
|
$article_title = trim($element->find('title', 0)->plaintext);
|
|
|
|
$article_image = $element->find('enclosure', 0)->url;
|
|
|
|
foreach ($article_html->find('img.img_full') as $img)
|
|
|
|
if ($img->alt == $article_title)
|
2016-08-30 11:23:55 +02:00
|
|
|
$article_image = self::URI.$img->src;
|
2016-02-13 13:52:28 +01:00
|
|
|
$article_content = '<p><img src="'.$article_image.'" /></p>'
|
2016-08-30 11:23:55 +02:00
|
|
|
.str_replace('src="/', 'src="'.self::URI, $article_html->find('div.newsGenerique_con', 0)->innertext);
|
2016-02-13 13:52:28 +01:00
|
|
|
$article_content = StripWithDelimiters($article_content, '<script', '</script>');
|
|
|
|
$article_content = StripWithDelimiters($article_content, '<style', '</style>');
|
|
|
|
$article_content = StripWithDelimiters($article_content, '<link', '>');
|
|
|
|
|
|
|
|
//Build and add final item
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $article_uri;
|
|
|
|
$item['title'] = $article_title;
|
|
|
|
$item['author'] = $article_html->find('a[class=upp transition_fast upp]', 0)->plaintext;
|
|
|
|
$item['timestamp'] = strtotime($element->find('pubDate', 0)->plaintext);
|
|
|
|
$item['content'] = $article_content;
|
2016-02-13 13:52:28 +01:00
|
|
|
$this->items[] = $item;
|
|
|
|
$limit++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-09 20:01:21 +02:00
|
|
|
}
|