CADBridge.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. class CADBridge extends FeedExpander {
  3. const MAINTAINER = "nyutag";
  4. const NAME = "CAD Bridge";
  5. const URI = "http://www.cad-comic.com/";
  6. const DESCRIPTION = "Returns the newest articles.";
  7. public function collectData(){
  8. $this->collectExpandableDatas('http://cdn2.cad-comic.com/rss.xml', 10);
  9. }
  10. protected function parseItem($newsItem){
  11. $item = parent::parseItem($newsItem);
  12. $item['content'] = $this->CADExtractContent($item['uri']);
  13. return $item;
  14. }
  15. private function CADExtractContent($url) {
  16. $html3 = getSimpleHTMLDOMCached($url);
  17. // The request might fail due to missing https support or wrong URL
  18. if($html3 == false)
  19. return 'Daily comic not released yet';
  20. $htmlpart = explode("/", $url);
  21. switch ($htmlpart[3]){
  22. case 'cad':
  23. preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/cad-\S*png/", $html3, $url2);
  24. break;
  25. case 'sillies':
  26. preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/sillies-\S*gif/", $html3, $url2);
  27. break;
  28. default:
  29. return 'Daily comic not released yet';
  30. }
  31. $img = implode ($url2[0]);
  32. $html3->clear();
  33. unset ($html3);
  34. if ($img == '')
  35. return 'Daily comic not released yet';
  36. return '<img src="'.$img.'"/>';
  37. }
  38. public function getCacheDuration(){
  39. return 3600*2; // 2 hours
  40. }
  41. }
  42. ?>