JapanExpoBridge.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. class JapanExpoBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = 'Ginko';
  5. $this->name = 'JapanExpo';
  6. $this->uri = 'http://www.japan-expo-paris.com/fr/actualites';
  7. $this->description = 'Returns most recent entries from Japan Expo actualités.';
  8. $this->update = '2016-06-12';
  9. $this->parameters[] =
  10. '[
  11. {
  12. "name" : "Mode",
  13. "type" : "list",
  14. "identifier" : "mode",
  15. "values" :
  16. [
  17. {
  18. "name" : "Titles only",
  19. "value" : "light"
  20. },
  21. {
  22. "name" : "Full Contents",
  23. "value" : "full"
  24. }
  25. ]
  26. }
  27. ]';
  28. }
  29. public function collectData(array $param) {
  30. function french_pubdate_to_timestamp($date_to_parse) {
  31. return strtotime(
  32. strtr(
  33. strtolower(str_replace('Publié le ', '', $date_to_parse)),
  34. array(
  35. 'janvier' => 'jan',
  36. 'février' => 'feb',
  37. 'mars' => 'march',
  38. 'avril' => 'apr',
  39. 'mai' => 'may',
  40. 'juin' => 'jun',
  41. 'juillet' => 'jul',
  42. 'août' => 'aug',
  43. 'septembre' => 'sep',
  44. 'octobre' => 'oct',
  45. 'novembre' => 'nov',
  46. 'décembre' => 'dec'
  47. )
  48. )
  49. );
  50. }
  51. $convert_article_images = function ($matches) {
  52. if (is_array($matches) && count($matches) > 1) {
  53. return '<img src="'.$matches[1].'" />';
  54. }
  55. };
  56. $link = 'http://www.japan-expo-paris.com/fr/actualites';
  57. $html = $this->file_get_html($link) or $this->returnError('Could not request JapanExpo: '.$link , 500);
  58. $fullcontent = (!empty($param['mode']) && $param['mode'] == 'full');
  59. $count = 0;
  60. foreach ($html->find('a._tile2') as $element) {
  61. $url = $element->href;
  62. $thumbnail = 'http://s.japan-expo.com/katana/images/JES049/paris.png';
  63. preg_match('/url\(([^)]+)\)/', $element->find('img.rspvimgset', 0)->style, $img_search_result);
  64. if (count($img_search_result) >= 2)
  65. $thumbnail = trim($img_search_result[1], "'");
  66. if ($fullcontent) {
  67. if ($count < 5) {
  68. $article_html = $this->file_get_html($url) or $this->returnError('Could not request JapanExpo: '.$url , 500);
  69. $header = $article_html->find('header.pageHeadBox', 0);
  70. $timestamp = strtotime($header->find('time', 0)->datetime);
  71. $title_html = $header->find('div.section', 0)->next_sibling();
  72. $title = $title_html->plaintext;
  73. $headings = $title_html->next_sibling()->outertext;
  74. $article = $article_html->find('div.content', 0)->innertext;
  75. $article = preg_replace_callback('/<img [^>]+ style="[^\(]+\(\'([^\']+)\'[^>]+>/i', $convert_article_images, $article);
  76. $content = $headings.$article;
  77. } else {
  78. break;
  79. }
  80. } else {
  81. $date_text = $element->find('span.date', 0)->plaintext;
  82. $timestamp = french_pubdate_to_timestamp($date_text);
  83. $title = trim($element->find('span._title', 0)->plaintext);
  84. $content = '<img src="'.$thumbnail.'"></img><br />'.$date_text.'<br /><a href="'.$url.'">Lire l\'article</a>';
  85. }
  86. $item = new \Item();
  87. $item->uri = $url;
  88. $item->title = $title;
  89. $item->timestamp = $timestamp;
  90. $item->thumbnailUri = $thumbnail;
  91. $item->content = $content;
  92. $this->items[] = $item;
  93. $count++;
  94. }
  95. }
  96. public function getName(){
  97. return 'Japan Expo Actualités';
  98. }
  99. public function getURI(){
  100. return 'http://www.japan-expo-paris.com/fr/actualites';
  101. }
  102. public function getCacheDuration(){
  103. return 14400; // 4 hours
  104. }
  105. }