1
0

Gawker.php 2.8 KB

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