SupInfoBridge.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. class SupInfoBridge extends BridgeAbstract {
  3. const MAINTAINER = 'teromene';
  4. const NAME = 'SupInfoBridge';
  5. const URI = 'https://www.supinfo.com';
  6. const DESCRIPTION = 'Returns the newest articles.';
  7. const PARAMETERS = array(array(
  8. 'tag' => array(
  9. 'name' => 'Category (not mandatory)',
  10. 'type' => 'text',
  11. )
  12. ));
  13. public function collectData() {
  14. if(empty($this->getInput('tag'))) {
  15. $html = getSimpleHTMLDOM(self::URI . '/articles/')
  16. or returnServerError('Unable to fetch articles !');
  17. } else {
  18. $html = getSimpleHTMLDOM(self::URI . '/articles/tag/' . $this->getInput('tag'))
  19. or returnServerError('Unable to fetch articles !');
  20. }
  21. $content = $html->find('#latest', 0)->find('ul[class=courseContent]', 0);
  22. for($i = 0; $i < 5; $i++) {
  23. $this->items[] = $this->fetchArticle($content->find('h4', $i)->find('a', 0)->href);
  24. }
  25. }
  26. private function fetchArticle($link) {
  27. $articleHTML = getSimpleHTMLDOM(self::URI . $link)
  28. or returnServerError('Unable to fetch article !');
  29. $article = $articleHTML->find('div[id=courseDocZero]', 0);
  30. $item = array();
  31. $item['author'] = $article->find('#courseMetas', 0)->find('a', 0)->plaintext;
  32. $item['id'] = $link;
  33. $item['uri'] = self::URI . $link;
  34. $item['title'] = $article->find('h1', 0)->plaintext;
  35. $date = explode(' ', $article->find('#courseMetas', 0)->find('span', 1)->plaintext);
  36. $item['timestamp'] = DateTime::createFromFormat('d/m/Y H:i:s', $date[2] . ' ' . $date[4])->getTimestamp();
  37. $article->find('div[id=courseHeader]', 0)->innertext = '';
  38. $article->find('div[id=author-infos]', 0)->innertext = '';
  39. $article->find('div[id=cartouche-tete]', 0)->innertext = '';
  40. $item['content'] = $article;
  41. return $item;
  42. }
  43. }