JapanExpoBridge.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. class JapanExpoBridge extends BridgeAbstract {
  3. const MAINTAINER = 'Ginko';
  4. const NAME = 'Japan Expo Actualités';
  5. const URI = 'http://www.japan-expo-paris.com/fr/actualites';
  6. const CACHE_TIMEOUT = 14400; // 4h
  7. const DESCRIPTION = 'Returns most recent entries from Japan Expo actualités.';
  8. const PARAMETERS = array( array(
  9. 'mode'=>array(
  10. 'name'=>'Show full contents',
  11. 'type'=>'checkbox',
  12. )
  13. ));
  14. public function collectData(){
  15. function french_pubdate_to_timestamp($date_to_parse) {
  16. return strtotime(
  17. strtr(
  18. strtolower(str_replace('Publié le ', '', $date_to_parse)),
  19. array(
  20. 'janvier' => 'jan',
  21. 'février' => 'feb',
  22. 'mars' => 'march',
  23. 'avril' => 'apr',
  24. 'mai' => 'may',
  25. 'juin' => 'jun',
  26. 'juillet' => 'jul',
  27. 'août' => 'aug',
  28. 'septembre' => 'sep',
  29. 'octobre' => 'oct',
  30. 'novembre' => 'nov',
  31. 'décembre' => 'dec'
  32. )
  33. )
  34. );
  35. }
  36. $convert_article_images = function ($matches) {
  37. if (is_array($matches) && count($matches) > 1) {
  38. return '<img src="'.$matches[1].'" />';
  39. }
  40. };
  41. $html = getSimpleHTMLDOM(self::URI)
  42. or returnServerError('Could not request JapanExpo: '.self::URI);
  43. $fullcontent = $this->getInput('mode');
  44. $count = 0;
  45. foreach ($html->find('a._tile2') as $element) {
  46. $url = $element->href;
  47. $thumbnail = 'http://s.japan-expo.com/katana/images/JES049/paris.png';
  48. preg_match('/url\(([^)]+)\)/', $element->find('img.rspvimgset', 0)->style, $img_search_result);
  49. if (count($img_search_result) >= 2)
  50. $thumbnail = trim($img_search_result[1], "'");
  51. if ($fullcontent) {
  52. if ($count >= 5) {
  53. break;
  54. }
  55. $article_html = getSimpleHTMLDOMCached('Could not request JapanExpo: '.$url);
  56. $header = $article_html->find('header.pageHeadBox', 0);
  57. $timestamp = strtotime($header->find('time', 0)->datetime);
  58. $title_html = $header->find('div.section', 0)->next_sibling();
  59. $title = $title_html->plaintext;
  60. $headings = $title_html->next_sibling()->outertext;
  61. $article = $article_html->find('div.content', 0)->innertext;
  62. $article = preg_replace_callback('/<img [^>]+ style="[^\(]+\(\'([^\']+)\'[^>]+>/i', $convert_article_images, $article);
  63. $content = $headings.$article;
  64. } else {
  65. $date_text = $element->find('span.date', 0)->plaintext;
  66. $timestamp = french_pubdate_to_timestamp($date_text);
  67. $title = trim($element->find('span._title', 0)->plaintext);
  68. $content = '<img src="'.$thumbnail.'"></img><br />'.$date_text.'<br /><a href="'.$url.'">Lire l\'article</a>';
  69. }
  70. $item = array();
  71. $item['uri'] = $url;
  72. $item['title'] = $title;
  73. $item['timestamp'] = $timestamp;
  74. $item['content'] = $content;
  75. $this->items[] = $item;
  76. $count++;
  77. }
  78. }
  79. }