TheOatMealBridge.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. define("THE_OATMEAL", "http://theoatmeal.com/");
  3. define("THE_OATMEAL_RSS", "http://feeds.feedburner.com/oatmealfeed");
  4. class TheOatmealBridge extends RssExpander{
  5. public function loadMetadatas() {
  6. $this->maintainer = "Riduidel";
  7. $this->name = "The Oatmeal";
  8. $this->uri = "http://theoatmeal.com/";
  9. $this->description = "Un petit site de dessins assez rigolos";
  10. $this->update = "2015-07-03";
  11. }
  12. public function collectData(array $param){
  13. parent::collectExpandableDatas($param, THE_OATMEAL_RSS);
  14. }
  15. /**
  16. * Since the oatmeal produces a weird RSS feed, I have to fix it by loading the items separatly from the feed infos
  17. */
  18. protected function collect_RSS_2_0_data($rssContent) {
  19. $rssContent->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
  20. $rssHeaderContent = $rssContent->channel[0];
  21. // $this->message("RSS content is ===========\n".var_export($rssHeaderContent, true)."===========");
  22. $this->load_RSS_2_0_feed_data($rssHeaderContent);
  23. foreach($rssContent->item as $item) {
  24. $this->message("parsing item ".var_export($item, true));
  25. $this->items[] = $this->parseRSSItem($item);
  26. }
  27. }
  28. protected function parseRSSItem($newsItem) {
  29. $namespaces = $newsItem->getNameSpaces(true);
  30. $dc = $newsItem->children($namespaces['dc']);
  31. $rdf = $newsItem->children($namespaces['rdf']);
  32. $item = new Item();
  33. $item->title = trim($newsItem->title);
  34. $this->message("browsing Oatmeal item ".var_export($newsItem, true));
  35. $item->uri=(string) $newsItem->attributes($namespaces['rdf'])->about;
  36. // now load that uri from cache
  37. $this->message("now loading page ".$item->uri);
  38. $articlePage = str_get_html($this->get_cached($item->uri));
  39. $content = $articlePage->find('#comic', 0);
  40. if($content==null) {
  41. $content = $articlePage->find('#blog');
  42. }
  43. $item->content = $content->innertext;
  44. $this->message("dc content is ".var_export($dc, true));
  45. $item->name = (string) $dc->creator;
  46. $item->timestamp = DateTime::createFromFormat(DateTime::ISO8601, $dc->date)->getTimestamp();
  47. $this->message("writtem by ".$item->name." on ".$item->timestamp);
  48. return $item;
  49. }
  50. public function getCacheDuration(){
  51. return 7200; // 2h hours
  52. }
  53. }