2016-03-23 00:51:55 +03:00
|
|
|
<?php
|
|
|
|
|
2016-08-28 21:07:56 +03:00
|
|
|
class LichessBridge extends HttpCachingBridgeAbstract
|
2016-03-23 00:51:55 +03:00
|
|
|
{
|
2016-08-30 12:23:55 +03:00
|
|
|
const MAINTAINER = 'AmauryCarrade';
|
|
|
|
const NAME = 'Lichess Blog';
|
|
|
|
const URI = 'http://fr.lichess.org/blog';
|
|
|
|
const DESCRIPTION = 'Returns the 5 newest posts from the Lichess blog (full text)';
|
2016-03-23 00:51:55 +03:00
|
|
|
|
2016-08-25 02:24:53 +03:00
|
|
|
public function collectData()
|
2016-03-23 00:51:55 +03:00
|
|
|
{
|
2016-08-30 12:23:55 +03:00
|
|
|
$xml_feed = $this->getSimpleHTMLDOM(self::URI.'.atom')
|
2016-08-29 13:55:15 +03:00
|
|
|
or $this->returnServerError('Could not retrieve Lichess blog feed.');
|
2016-03-23 00:51:55 +03:00
|
|
|
|
|
|
|
$posts_loaded = 0;
|
|
|
|
foreach($xml_feed->find('entry') as $entry)
|
|
|
|
{
|
|
|
|
if ($posts_loaded < 5)
|
|
|
|
{
|
2016-08-22 19:55:59 +03:00
|
|
|
$item = array();
|
2016-03-23 00:51:55 +03:00
|
|
|
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['title'] = html_entity_decode($entry->find('title', 0)->innertext);
|
|
|
|
$item['author'] = $entry->find('author', 0)->find('name', 0)->innertext;
|
|
|
|
$item['uri'] = $entry->find('id', 0)->plaintext;
|
|
|
|
$item['timestamp'] = strtotime($entry->find('published', 0)->plaintext);
|
2016-03-23 00:51:55 +03:00
|
|
|
|
2016-08-22 19:55:59 +03:00
|
|
|
$item['content'] = $this->retrieve_lichess_post($item['uri']);
|
2016-03-23 00:51:55 +03:00
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
$posts_loaded++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function retrieve_lichess_post($blog_post_uri)
|
|
|
|
{
|
2016-08-28 21:07:56 +03:00
|
|
|
if($this->get_cached_time($blog_post_uri) <= strtotime('-24 hours'))
|
|
|
|
$this->remove_from_cache($blog_post_uriuri);
|
|
|
|
|
|
|
|
$blog_post_html = $this->get_cached($blog_post_uri);
|
2016-03-23 00:51:55 +03:00
|
|
|
$blog_post_div = $blog_post_html->find('#lichess_blog', 0);
|
|
|
|
|
|
|
|
$post_chapo = $blog_post_div->find('.shortlede', 0)->innertext;
|
|
|
|
$post_content = $blog_post_div->find('.body', 0)->innertext;
|
|
|
|
|
|
|
|
$content = '<p><em>' . $post_chapo . '</em></p>';
|
|
|
|
$content .= '<div>' . $post_content . '</div>';
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
}
|