ScmbBridge.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. class ScmbBridge extends BridgeAbstract {
  3. const MAINTAINER = 'Astalaseven';
  4. const NAME = 'Se Coucher Moins Bête Bridge';
  5. const URI = 'http://secouchermoinsbete.fr';
  6. const CACHE_TIMEOUT = 21600; // 6h
  7. const DESCRIPTION = 'Returns the newest anecdotes.';
  8. public function collectData(){
  9. $html = '';
  10. $html = getSimpleHTMLDOM(self::URI)
  11. or returnServerError('Could not request Se Coucher Moins Bete.');
  12. foreach($html->find('article') as $article) {
  13. $item = array();
  14. $item['uri'] = self::URI . $article->find('p.summary a', 0)->href;
  15. $item['title'] = $article->find('header h1 a', 0)->innertext;
  16. // remove text "En savoir plus" from anecdote content
  17. $article->find('span.read-more', 0)->outertext = '';
  18. $content = $article->find('p.summary a', 0)->innertext;
  19. // remove superfluous spaces at the end
  20. $content = substr($content, 0, strlen($content) - 17);
  21. // get publication date
  22. $str_date = $article->find('time', 0)->datetime;
  23. list($date, $time) = explode(' ', $str_date);
  24. list($y, $m, $d) = explode('-', $date);
  25. list($h, $i) = explode(':', $time);
  26. $timestamp = mktime($h, $i, 0, $m, $d, $y);
  27. $item['timestamp'] = $timestamp;
  28. $item['content'] = $content;
  29. $this->items[] = $item;
  30. }
  31. }
  32. }