ForGifsBridge.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. class ForGifsBridge extends FeedExpander {
  3. const MAINTAINER = 'logmanoriginal';
  4. const NAME = 'forgifs Bridge';
  5. const URI = 'https://forgifs.com';
  6. const DESCRIPTION = 'Returns the forgifs feed with actual gifs instead of images';
  7. public function collectData() {
  8. $this->collectExpandableDatas('https://forgifs.com/gallery/srss/7');
  9. }
  10. protected function parseItem($feedItem) {
  11. $item = parent::parseItem($feedItem);
  12. $content = str_get_html($item['content']);
  13. $img = $content->find('img', 0);
  14. $poster = $img->src;
  15. // The actual gif is the same path but its id must be decremented by one.
  16. // Example:
  17. // http://forgifs.com/gallery/d/279419-2/Reporter-videobombed-shoulder-checks.gif
  18. // http://forgifs.com/gallery/d/279418-2/Reporter-videobombed-shoulder-checks.gif
  19. // Notice how this changes ----------^
  20. // Now let's extract that number and do some math
  21. // Notice: Technically we could also load the content page but that would
  22. // require unnecessary traffic. As long as it works...
  23. $num = substr($img->src, 29, 6);
  24. $num -= 1;
  25. $img->src = substr_replace($img->src, $num, 29, strlen($num));
  26. $img->width = 'auto';
  27. $img->height = 'auto';
  28. $item['content'] = $content;
  29. return $item;
  30. }
  31. }