Gawker.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. define("RSS_PREFIX", "http://feeds.gawker.com/");
  3. define("RSS_SUFFIX", "/full");
  4. class Gawker extends RssExpander{
  5. public function loadMetadatas() {
  6. $this->maintainer = "mitsukarenai";
  7. $this->name = "Gawker media";
  8. $this->uri = "http://feeds.gawker.com/";
  9. $this->description = "A bridge allowing access to any of the numerous Gawker media blogs (Lifehacker, deadspin, Kotaku, Jezebel, and so on. Notice you have to give its id to find the RSS stream in gawker maze";
  10. $this->update = "27/03/2014";
  11. $this->parameters[] =
  12. '[
  13. {
  14. "name" : "site id to put in uri between feeds.gawker.com and /full .. which is obviously not full AT ALL",
  15. "identifier" : "site"
  16. }
  17. ]';
  18. }
  19. private function toURI($name) {
  20. return RSS_PREFIX.$name.RSS_SUFFIX;
  21. }
  22. public function collectData(array $param){
  23. if (empty($param['site'])) {
  24. trigger_error("If no site is provided, nothing is gonna happen", E_USER_ERROR);
  25. } else {
  26. $this->name = $param['site'];
  27. $url = $this->toURI(strtolower($param['site']));
  28. }
  29. // $this->message("loading feed from ".$this->getURI());
  30. parent::collectExpandableDatas($param, $url);
  31. }
  32. protected function parseRSSItem($newsItem) {
  33. $item = new Item();
  34. $item->uri = trim($newsItem->link);
  35. $item->title = trim($newsItem->title);
  36. $item->timestamp = $this->RSS_2_0_time_to_timestamp($newsItem);
  37. // $this->message("///////////////////////////////////////////////////////////////////////////////////////\nprocessing item ".var_export($item, true)."\n\n\nbuilt from\n\n\n".var_export($newsItem, true));
  38. try {
  39. // now load that uri from cache
  40. // $this->message("loading page ".$item->uri);
  41. $articlePage = str_get_html($this->get_cached($item->uri));
  42. if(is_object($articlePage)) {
  43. $content = $articlePage->find('.post-content', 0);
  44. HTMLSanitizer::defaultImageSrcTo($content, $this->getURI());
  45. $vcard = $articlePage->find('.vcard', 0);
  46. if(is_object($vcard)) {
  47. $authorLink = $vcard->find('a', 0);
  48. $item->name = $authorLink->innertext;
  49. // TODO use author link href to fill the feed info
  50. }
  51. // $this->message("item quite loaded : ".var_export($item, true));
  52. // I set item content as last element, for easier var_export reading
  53. $item->content = $content->innertext;
  54. } else {
  55. throw new Exception("cache content for ".$item->uri." is NOT a Simple DOM parser object !");
  56. }
  57. } catch(Exception $e) {
  58. $this->message("obtaining ".$item->uri." resulted in exception ".$e->getMessage().". Deleting cached page ...");
  59. // maybe file is incorrect. it should be discarded from cache
  60. $this->remove_from_cache($item->url);
  61. $item->content = $e->getMessage();
  62. }
  63. return $item;
  64. }
  65. }