JapanExpoBridge.php 3.6 KB

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