Rue89Bridge.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class Rue89Bridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "pit-fgfjiudghdf";
  5. $this->name = "Rue89";
  6. $this->uri = "http://rue89.nouvelobs.com/";
  7. $this->description = "Returns the 5 newest posts from Rue89 (full text)";
  8. $this->update = "2015-01-30";
  9. }
  10. private function rue89getDatas($url){
  11. $url = "http://api.rue89.nouvelobs.com/export/mobile2/node/" . str_replace(" ", "", substr($url, -8)) . "/full";
  12. $datas = json_decode(file_get_contents($url), true);
  13. return $datas["node"];
  14. }
  15. public function collectData(array $param){
  16. $html = $this->file_get_html('http://api.rue89.nouvelobs.com/feed') or $this->returnError('Could not request Rue89.', 404);
  17. $limit = 0;
  18. foreach($html->find('item') as $element) {
  19. if($limit < 5) {
  20. $datas = $this->rue89getDatas(str_replace('#commentaires', '', ($element->find('comments', 0)->plaintext)));
  21. $item = new \Item();
  22. $item->title = $datas["title"];
  23. $item->author = $datas["author"][0]["name"];
  24. $item->timestamp = $datas["updated"];
  25. $item->content = $datas["body"];
  26. $item->uri = $datas["url"];
  27. $this->items[] = $item;
  28. }
  29. }
  30. }
  31. public function getName(){
  32. return 'Rue89';
  33. }
  34. public function getURI(){
  35. return 'http://rue89.nouvelobs.com/';
  36. }
  37. public function getCacheDuration(){
  38. return 3600; // 1 hour
  39. }
  40. }