2016-01-19 19:20:21 +01:00
|
|
|
<?php
|
2016-08-28 20:07:56 +02:00
|
|
|
class JapanExpoBridge extends HttpCachingBridgeAbstract {
|
2016-01-19 19:20:21 +01:00
|
|
|
|
|
|
|
public function loadMetadatas() {
|
2016-06-25 12:12:33 +02:00
|
|
|
$this->maintainer = 'Ginko';
|
2016-08-09 20:01:21 +02:00
|
|
|
$this->name = 'Japan Expo Actualités';
|
2016-06-25 12:12:33 +02:00
|
|
|
$this->uri = 'http://www.japan-expo-paris.com/fr/actualites';
|
|
|
|
$this->description = 'Returns most recent entries from Japan Expo actualités.';
|
2016-08-22 01:25:56 +02:00
|
|
|
$this->parameters[] = array(
|
|
|
|
'mode'=>array(
|
|
|
|
'name'=>'Mode',
|
|
|
|
'type'=>'list',
|
|
|
|
'values'=>array(
|
|
|
|
'Titles only'=>'light',
|
|
|
|
'Full Contents'=>'full'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2016-06-25 12:12:33 +02:00
|
|
|
}
|
2016-01-19 19:20:21 +01:00
|
|
|
|
2016-08-25 01:24:53 +02:00
|
|
|
public function collectData(){
|
|
|
|
$param=$this->parameters[$this->queriedContext];
|
2016-01-19 19:20:21 +01:00
|
|
|
|
2016-06-25 12:12:33 +02:00
|
|
|
function french_pubdate_to_timestamp($date_to_parse) {
|
|
|
|
return strtotime(
|
|
|
|
strtr(
|
|
|
|
strtolower(str_replace('Publié le ', '', $date_to_parse)),
|
|
|
|
array(
|
|
|
|
'janvier' => 'jan',
|
|
|
|
'février' => 'feb',
|
|
|
|
'mars' => 'march',
|
|
|
|
'avril' => 'apr',
|
|
|
|
'mai' => 'may',
|
|
|
|
'juin' => 'jun',
|
|
|
|
'juillet' => 'jul',
|
|
|
|
'août' => 'aug',
|
|
|
|
'septembre' => 'sep',
|
|
|
|
'octobre' => 'oct',
|
|
|
|
'novembre' => 'nov',
|
|
|
|
'décembre' => 'dec'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$convert_article_images = function ($matches) {
|
|
|
|
if (is_array($matches) && count($matches) > 1) {
|
|
|
|
return '<img src="'.$matches[1].'" />';
|
|
|
|
}
|
|
|
|
};
|
2016-01-19 19:20:21 +01:00
|
|
|
|
|
|
|
$link = 'http://www.japan-expo-paris.com/fr/actualites';
|
2016-07-08 19:06:35 +02:00
|
|
|
$html = $this->getSimpleHTMLDOM($link) or $this->returnServerError('Could not request JapanExpo: '.$link);
|
2016-08-25 01:24:53 +02:00
|
|
|
$fullcontent = (!empty($param['mode']['value']) && $param['mode']['value'] == 'full');
|
2016-06-25 12:12:33 +02:00
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
foreach ($html->find('a._tile2') as $element) {
|
|
|
|
|
|
|
|
$url = $element->href;
|
|
|
|
$thumbnail = 'http://s.japan-expo.com/katana/images/JES049/paris.png';
|
|
|
|
preg_match('/url\(([^)]+)\)/', $element->find('img.rspvimgset', 0)->style, $img_search_result);
|
|
|
|
if (count($img_search_result) >= 2)
|
|
|
|
$thumbnail = trim($img_search_result[1], "'");
|
|
|
|
|
|
|
|
if ($fullcontent) {
|
|
|
|
if ($count < 5) {
|
2016-08-28 20:07:56 +02:00
|
|
|
if($this->get_cached_time($url) <= strtotime('-24 hours'))
|
|
|
|
$this->remove_from_cache($url);
|
|
|
|
|
|
|
|
$article_html = $this->get_cached($url) or $this->returnServerError('Could not request JapanExpo: '.$url);
|
2016-06-25 12:12:33 +02:00
|
|
|
$header = $article_html->find('header.pageHeadBox', 0);
|
|
|
|
$timestamp = strtotime($header->find('time', 0)->datetime);
|
|
|
|
$title_html = $header->find('div.section', 0)->next_sibling();
|
|
|
|
$title = $title_html->plaintext;
|
|
|
|
$headings = $title_html->next_sibling()->outertext;
|
|
|
|
$article = $article_html->find('div.content', 0)->innertext;
|
|
|
|
$article = preg_replace_callback('/<img [^>]+ style="[^\(]+\(\'([^\']+)\'[^>]+>/i', $convert_article_images, $article);
|
|
|
|
$content = $headings.$article;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$date_text = $element->find('span.date', 0)->plaintext;
|
|
|
|
$timestamp = french_pubdate_to_timestamp($date_text);
|
|
|
|
$title = trim($element->find('span._title', 0)->plaintext);
|
|
|
|
$content = '<img src="'.$thumbnail.'"></img><br />'.$date_text.'<br /><a href="'.$url.'">Lire l\'article</a>';
|
|
|
|
}
|
|
|
|
|
2016-08-22 18:55:59 +02:00
|
|
|
$item = array();
|
|
|
|
$item['uri'] = $url;
|
|
|
|
$item['title'] = $title;
|
|
|
|
$item['timestamp'] = $timestamp;
|
|
|
|
$item['content'] = $content;
|
2016-06-25 12:12:33 +02:00
|
|
|
$this->items[] = $item;
|
|
|
|
$count++;
|
2016-01-19 19:20:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCacheDuration(){
|
2016-06-25 12:12:33 +02:00
|
|
|
return 14400; // 4 hours
|
2016-01-19 19:20:21 +01:00
|
|
|
}
|
|
|
|
}
|