LichessBridge.php 1.9 KB

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