BlaguesDeMerdeBridge.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. class BlaguesDeMerdeBridge extends BridgeAbstract {
  3. const MAINTAINER = 'superbaillot.net, logmanoriginal';
  4. const NAME = 'Blagues De Merde';
  5. const URI = 'http://www.blaguesdemerde.fr/';
  6. const CACHE_TIMEOUT = 7200; // 2h
  7. const DESCRIPTION = 'Blagues De Merde';
  8. public function collectData(){
  9. $html = getSimpleHTMLDOM(self::URI)
  10. or returnServerError('Could not request BDM.');
  11. foreach($html->find('div.blague') as $element) {
  12. $item = array();
  13. $item['uri'] = static::URI . '#' . $element->id;
  14. $item['author'] = $element->find('div[class="blague-footer"] p strong', 0)->plaintext;
  15. // Let the title be everything up to the first <br>
  16. $item['title'] = trim(explode("\n", $element->find('div.text', 0)->plaintext)[0]);
  17. $item['content'] = strip_tags($element->find('div.text', 0));
  18. // timestamp is part of:
  19. // <p>Par <strong>{author}</strong> le {date} dans <strong>{category}</strong></p>
  20. preg_match(
  21. '/.+le(.+)dans.*/',
  22. $element->find('div[class="blague-footer"]', 0)->plaintext,
  23. $matches
  24. );
  25. $item['timestamp'] = strtotime($matches[1]);
  26. $this->items[] = $item;
  27. }
  28. }
  29. }