CADBridge.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. class CADBridge extends BridgeAbstract{
  3. public function loadMetadatas() {
  4. $this->maintainer = "nyutag";
  5. $this->name = "CAD Bridge";
  6. $this->uri = "http://www.cad-comic.com/";
  7. $this->description = "Returns the newest articles.";
  8. $this->update = "2016-08-02";
  9. }
  10. function CADExtractContent($url) {
  11. $html3 = $this->file_get_html($url);
  12. // The request might fail due to missing https support or wrong URL
  13. if($html3 == false)
  14. return 'Daily comic not released yet';
  15. $htmlpart = explode("/", $url);
  16. switch ($htmlpart[3]){
  17. case 'cad':
  18. preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/cad-\S*png/", $html3, $url2);
  19. break;
  20. case 'sillies':
  21. preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/sillies-\S*gif/", $html3, $url2);
  22. break;
  23. default:
  24. return 'Daily comic not released yet';
  25. }
  26. $img = implode ($url2[0]);
  27. $html3->clear();
  28. unset ($html3);
  29. if ($img == '')
  30. return 'Daily comic not released yet';
  31. return '<img src="'.$img.'"/>';
  32. }
  33. public function collectData(array $param){
  34. function CADUrl($string) {
  35. $html2 = explode("\"", $string);
  36. $string = $html2[1];
  37. if (substr($string,0,4) != 'http')
  38. return 'notanurl';
  39. return $string;
  40. }
  41. $html = $this->file_get_html('http://cdn2.cad-comic.com/rss.xml') or $this->returnError('Could not request CAD.', 404);
  42. $limit = 0;
  43. foreach($html->find('item') as $element) {
  44. if($limit < 5) {
  45. $item = new \Item();
  46. $item->title = $element->find('title', 0)->innertext;
  47. $item->uri = CADUrl($element->find('description', 0)->innertext);
  48. if ($item->uri != 'notanurl') {
  49. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  50. $item->content = $this->CADExtractContent($item->uri);
  51. $this->items[] = $item;
  52. $limit++;
  53. }
  54. }
  55. }
  56. }
  57. public function getName(){
  58. return 'CAD Bridge';
  59. }
  60. public function getURI(){
  61. return 'http://www.cad-comic.com/';
  62. }
  63. public function getCacheDuration(){
  64. return 3600*2; // 2 hours
  65. }
  66. }
  67. ?>