LichessBridge.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. class LichessBridge extends BridgeAbstract
  3. {
  4. public function loadMetadatas()
  5. {
  6. $this->maintainer = 'AmauryCarrade';
  7. $this->name = 'Lichess Blog';
  8. $this->uri = 'http://lichess.org/blog';
  9. $this->description = 'Returns the 5 newest posts from the Lichess blog (full text)';
  10. }
  11. public function collectData(array $param)
  12. {
  13. $xml_feed = $this->getSimpleHTMLDOM('http://fr.lichess.org/blog.atom') or $this->returnServerError('Could not retrieve Lichess blog feed.');
  14. $posts_loaded = 0;
  15. foreach($xml_feed->find('entry') as $entry)
  16. {
  17. if ($posts_loaded < 5)
  18. {
  19. $item = array();
  20. $item['title'] = html_entity_decode($entry->find('title', 0)->innertext);
  21. $item['author'] = $entry->find('author', 0)->find('name', 0)->innertext;
  22. $item['uri'] = $entry->find('id', 0)->plaintext;
  23. $item['timestamp'] = strtotime($entry->find('published', 0)->plaintext);
  24. $item['content'] = $this->retrieve_lichess_post($item['uri']);
  25. $this->items[] = $item;
  26. $posts_loaded++;
  27. }
  28. }
  29. }
  30. private function retrieve_lichess_post($blog_post_uri)
  31. {
  32. $blog_post_html = $this->getSimpleHTMLDOM($blog_post_uri);
  33. $blog_post_div = $blog_post_html->find('#lichess_blog', 0);
  34. $post_chapo = $blog_post_div->find('.shortlede', 0)->innertext;
  35. $post_content = $blog_post_div->find('.body', 0)->innertext;
  36. $content = '<p><em>' . $post_chapo . '</em></p>';
  37. $content .= '<div>' . $post_content . '</div>';
  38. return $content;
  39. }
  40. }