JapanExpoBridge.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 frenchPubDateToTimestamp($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(
  63. '/<img [^>]+ style="[^\(]+\(\'([^\']+)\'[^>]+>/i',
  64. $convert_article_images,
  65. $article);
  66. $content = $headings . $article;
  67. } else {
  68. $date_text = $element->find('span.date', 0)->plaintext;
  69. $timestamp = frenchPubDateToTimestamp($date_text);
  70. $title = trim($element->find('span._title', 0)->plaintext);
  71. $content = '<img src="'
  72. . $thumbnail
  73. . '"></img><br />'
  74. . $date_text
  75. . '<br /><a href="'
  76. . $url
  77. . '">Lire l\'article</a>';
  78. }
  79. $item = array();
  80. $item['uri'] = $url;
  81. $item['title'] = $title;
  82. $item['timestamp'] = $timestamp;
  83. $item['content'] = $content;
  84. $this->items[] = $item;
  85. $count++;
  86. }
  87. }
  88. }