ZatazBridge.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class ZatazBridge extends BridgeAbstract {
  3. public function loadMetadatas() {
  4. $this->maintainer = "aledeg";
  5. $this->name = "Zataz";
  6. $this->uri = "http://www.zataz.com/";
  7. $this->description = "ZATAZ Magazine - S'informer, c'est déjà se sécuriser";
  8. $this->update = "07/02/2015";
  9. }
  10. public function collectData(array $param) {
  11. $html = file_get_html($this->getURI()) or $this->returnError('Could not request ' . $this->getURI(), 404);
  12. $recent_posts = $html->find('#recent-posts-3', 0)->find('ul', 0)->find('li');
  13. foreach ($recent_posts as $article) {
  14. if (count($this->items) < 5) {
  15. $uri = $article->find('a', 0)->href;
  16. $this->items[] = $this->getDetails($uri);
  17. }
  18. }
  19. }
  20. private function getDetails($uri) {
  21. $html = file_get_html($uri) or exit;
  22. $item = new \Item();
  23. $article = $html->find('.gdl-blog-full', 0);
  24. $item->uri = $uri;
  25. $item->title = $article->find('.blog-title', 0)->find('a', 0)->innertext;
  26. $item->content = $article->find('.blog-content', 0)->innertext;
  27. $item->timestamp = $this->getTimestampFromDate($article->find('.blog-date', 0)->find('a', 0)->href);
  28. return $item;
  29. }
  30. private function getTimestampFromDate($uri) {
  31. preg_match('/\d{4}\/\d{2}\/\d{2}/', $uri, $matches);
  32. $date = new \DateTime($matches[0]);
  33. return $date->format('U');
  34. }
  35. public function getName() {
  36. return 'Zataz Magazine';
  37. }
  38. public function getCacheDuration() {
  39. return 7200; // 2h
  40. }
  41. public function getURI() {
  42. return 'http://www.zataz.com';
  43. }
  44. }