2014-04-02 13:55:42 +04:00
< ? php
2015-03-18 19:42:55 +03:00
define ( " RSS_PREFIX " , " http://feeds.gawker.com/ " );
define ( " RSS_SUFFIX " , " /full " );
2015-11-05 23:26:48 +03:00
2015-03-18 19:42:55 +03:00
class Gawker extends RssExpander {
2015-11-05 18:50:18 +03:00
public function loadMetadatas () {
$this -> maintainer = " mitsukarenai " ;
$this -> name = " Gawker media " ;
$this -> uri = " http://feeds.gawker.com/ " ;
$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 " ;
$this -> update = " 27/03/2014 " ;
$this -> parameters [] =
' [
{
" name " : " site id to put in uri between feeds.gawker.com and /full .. which is obviously not full AT ALL " ,
" identifier " : " site "
}
] ' ;
}
2015-03-18 19:42:55 +03:00
private function toURI ( $name ) {
return RSS_PREFIX . $name . RSS_SUFFIX ;
}
2014-04-02 13:55:42 +04:00
public function collectData ( array $param ){
if ( empty ( $param [ 'site' ])) {
trigger_error ( " If no site is provided, nothing is gonna happen " , E_USER_ERROR );
} else {
2015-03-18 19:42:55 +03:00
$this -> name = $param [ 'site' ];
2015-11-27 17:20:33 +03:00
$url = $this -> toURI ( strtolower ( $param [ 'site' ]));
2014-04-02 13:55:42 +04:00
}
2015-03-18 19:42:55 +03:00
// $this->message("loading feed from ".$this->getURI());
2015-11-27 17:20:33 +03:00
parent :: collectExpandableDatas ( $param , $url );
2014-04-02 13:55:42 +04:00
}
2015-03-18 19:42:55 +03:00
protected function parseRSSItem ( $newsItem ) {
2014-04-02 13:55:42 +04:00
$item = new Item ();
2015-03-18 19:42:55 +03:00
$item -> uri = trim ( $newsItem -> link );
$item -> title = trim ( $newsItem -> title );
$item -> timestamp = $this -> RSS_2_0_time_to_timestamp ( $newsItem );
// $this->message("///////////////////////////////////////////////////////////////////////////////////////\nprocessing item ".var_export($item, true)."\n\n\nbuilt from\n\n\n".var_export($newsItem, true));
2014-04-02 13:55:42 +04:00
try {
// now load that uri from cache
// $this->message("loading page ".$item->uri);
$articlePage = str_get_html ( $this -> get_cached ( $item -> uri ));
if ( is_object ( $articlePage )) {
$content = $articlePage -> find ( '.post-content' , 0 );
2015-11-27 17:20:33 +03:00
HTMLSanitizer :: defaultImageSrcTo ( $content , $this -> getURI ());
2014-04-02 13:55:42 +04:00
$vcard = $articlePage -> find ( '.vcard' , 0 );
if ( is_object ( $vcard )) {
2015-03-18 19:42:55 +03:00
$authorLink = $vcard -> find ( 'a' , 0 );
$item -> name = $authorLink -> innertext ;
// TODO use author link href to fill the feed info
2014-04-02 13:55:42 +04:00
}
2015-03-18 19:42:55 +03:00
// $this->message("item quite loaded : ".var_export($item, true));
// I set item content as last element, for easier var_export reading
$item -> content = $content -> innertext ;
2014-04-02 13:55:42 +04:00
} else {
throw new Exception ( " cache content for " . $item -> uri . " is NOT a Simple DOM parser object ! " );
}
} catch ( Exception $e ) {
$this -> message ( " obtaining " . $item -> uri . " resulted in exception " . $e -> getMessage () . " . Deleting cached page ... " );
// maybe file is incorrect. it should be discarded from cache
$this -> remove_from_cache ( $item -> url );
$item -> content = $e -> getMessage ();
}
2015-03-18 19:42:55 +03:00
return $item ;
2014-04-02 13:55:42 +04:00
}
}