SuperSmashBlogBridge.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. class SuperSmashBlogBridge extends BridgeAbstract {
  3. const MAINTAINER = 'corenting';
  4. const NAME = 'Super Smash Blog';
  5. const URI = 'https://www.smashbros.com/en_US/blog/index.html';
  6. const CACHE_TIMEOUT = 7200; // 2h
  7. const DESCRIPTION = 'Latest articles from the Super Smash Blog blog';
  8. public function collectData(){
  9. $dlUrl = 'https://www.smashbros.com/data/bs/en_US/json/en_US.json';
  10. $jsonString = getContents($dlUrl) or returnServerError('Error while downloading the website content');
  11. $json = json_decode($jsonString, true);
  12. foreach($json as $article) {
  13. // Build content
  14. $picture = $article['acf']['image1']['url'];
  15. if (strlen($picture) != 0) {
  16. $picture = str_get_html('<img src="https://www.smashbros.com/' . substr($picture, 8) . '"/>');
  17. } else {
  18. $picture = '';
  19. }
  20. $video = $article['acf']['link_url'];
  21. if (strlen($video) != 0) {
  22. $video = str_get_html('<a href="' . $video .'">Youtube video</a>');
  23. } else {
  24. $video = '';
  25. }
  26. $text = str_get_html($article['acf']['editor']);
  27. $content = $picture . $video . $text;
  28. // Build final item
  29. $item = array();
  30. $item['title'] = $article['title']['rendered'];
  31. $item['timestamp'] = strtotime($article['date']);
  32. $item['content'] = $content;
  33. $item['uri'] = self::URI . '?post=' . $article['id'];
  34. $this->items[] = $item;
  35. }
  36. }
  37. }