CADBridge.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * RssBridgeCAD
  4. * Returns the newest articles
  5. * 2015-04-03
  6. *
  7. * @name CAD Bridge
  8. * @homepage http://www.cad-comic.com/
  9. * @description Returns the newest articles.
  10. * @maintainer nyutag
  11. */
  12. class CADBridge extends BridgeAbstract{
  13. public function collectData(array $param){
  14. function CADUrl($string) {
  15. $html2 = explode("\"", $string);
  16. $string = $html2[1];
  17. if (substr($string,0,4) != 'http')
  18. return 'notanurl';
  19. return $string;
  20. }
  21. function CADExtractContent($url) {
  22. $html3 = file_get_html($url);
  23. preg_match_all("/http:\/\/cdn2\.cad-comic\.com\/comics\/cad-\S*png/", $html3, $url2);
  24. $img = implode ($url2[0]);
  25. return $img;
  26. }
  27. $html = file_get_html('http://cdn2.cad-comic.com/rss.xml') or $this->returnError('Could not request CAD.', 404);
  28. $limit = 0;
  29. foreach($html->find('item') as $element) {
  30. if($limit < 3) {
  31. $item = new \Item();
  32. $item->title = $element->find('title', 0)->innertext;
  33. $item->uri = CADUrl($element->find('description', 0)->innertext);
  34. if ($item->uri != 'notanurl') {
  35. $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
  36. $item->content = '<img src="'.CADExtractContent($item->uri).'"/>';
  37. $this->items[] = $item;
  38. $limit++;
  39. }
  40. }
  41. }
  42. }
  43. public function getName(){
  44. return 'CAD Bridge';
  45. }
  46. public function getURI(){
  47. return 'http://www.cad-comic.com/';
  48. }
  49. public function getCacheDuration(){
  50. return 3600*2; // 2 hours
  51. // return 0;
  52. }
  53. }