ZatazBridge.php 1.3 KB

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