]>
git.wh0rd.org - tt-rss.git/blob - plugins/af_comics/init.php
2 class Af_Comics
extends Plugin
{
5 private $filters = array ();
9 "Fixes RSS feeds of assorted comic strips" ,
13 function init ( $host ) {
16 $host -> add_hook ( $host :: HOOK_FETCH_FEED
, $this );
17 $host -> add_hook ( $host :: HOOK_ARTICLE_FILTER
, $this );
18 $host -> add_hook ( $host :: HOOK_PREFS_TAB
, $this );
20 require_once __DIR__
. "/filter_base.php" ;
22 $filters = array_merge ( glob ( __DIR__
. "/filters.local/*.php" ), glob ( __DIR__
. "/filters/*.php" ));
25 foreach ( $filters as $file ) {
26 $filter_name = preg_replace ( "/\..*$/" , "" , basename ( $file ));
28 if ( array_search ( $filter_name , $names ) === FALSE ) {
29 if (! class_exists ( $filter_name )) {
33 array_push ( $names , $filter_name );
35 $filter = new $filter_name ();
37 if ( is_subclass_of ( $filter , "Af_ComicFilter" )) {
38 array_push ( $this -> filters
, $filter );
39 array_push ( $names , $filter_name );
45 function hook_prefs_tab ( $args ) {
46 if ( $args != "prefFeeds" ) return ;
48 print "<div dojoType= \" dijit.layout.AccordionPane \" title= \" " . __ ( 'Feeds supported by af_comics' ). " \" >" ;
50 print "<p>" . __ ( "The following comics are currently supported:" ) . "</p>" ;
52 $comics = array ( "GoComics" );
54 foreach ( $this -> filters
as $f ) {
55 foreach ( $f -> supported () as $comic ) {
56 array_push ( $comics , $comic );
62 print "<ul class= \" browseFeedList \" style= \" border-width : 1px \" >" ;
63 foreach ( $comics as $comic ) {
64 print "<li> $comic </li>" ;
68 print "<p>" . __ ( "To subscribe to GoComics use the comic's regular web page as the feed URL (e.g. for the <em>Garfield</em> comic use <code>http://www.gocomics.com/garfield</code>)." ). "</p>" ;
70 print "<p>" . __ ( 'Drop any updated filters into <code>filters.local</code> in plugin directory.' ). "</p>" ;
75 function hook_article_filter ( $article ) {
76 foreach ( $this -> filters
as $f ) {
77 if ( $f -> process ( $article ))
84 // GoComics dropped feed support so it needs to be handled when fetching the feed.
86 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
88 function hook_fetch_feed ( $feed_data , $fetch_url , $owner_uid , $feed , $last_article_timestamp , $auth_login , $auth_pass ) {
89 if ( $auth_login ||
$auth_pass )
92 if ( preg_match ( '#^https?://(?:feeds\.feedburner\.com/uclick|www\.gocomics\.com)/([-a-z0-9]+)$#i' , $fetch_url , $comic )) {
93 $site_url = 'http://www.gocomics.com/' . $comic [ 1 ];
95 $article_link = $site_url . date ( '/Y/m/d' );
97 $body = fetch_file_contents ( array ( 'url' => $article_link , 'type' => 'text/html' , 'followlocation' => false ));
99 require_once 'lib/MiniTemplator.class.php' ;
101 $feed_title = htmlspecialchars ( $comic [ 1 ]);
102 $site_url = htmlspecialchars ( $site_url );
103 $article_link = htmlspecialchars ( $article_link );
105 $tpl = new MiniTemplator ();
107 $tpl -> readTemplateFromFile ( 'templates/generated_feed.txt' );
109 $tpl -> setVariable ( 'FEED_TITLE' , $feed_title , true );
110 $tpl -> setVariable ( 'VERSION' , VERSION
, true );
111 $tpl -> setVariable ( 'FEED_URL' , htmlspecialchars ( $fetch_url ), true );
112 $tpl -> setVariable ( 'SELF_URL' , $site_url , true );
114 $tpl -> setVariable ( 'ARTICLE_UPDATED_ATOM' , date ( 'c' ), true );
115 $tpl -> setVariable ( 'ARTICLE_UPDATED_RFC822' , date ( DATE_RFC822
), true );
118 $doc = new DOMDocument ();
120 if (@ $doc -> loadHTML ( $body )) {
121 $xpath = new DOMXPath ( $doc );
123 $node = $xpath -> query ( '//picture[contains( @class , "item-comic-image")]/img' )-> item ( 0 );
126 $node -> removeAttribute ( "width" );
128 $tpl -> setVariable ( 'ARTICLE_ID' , $article_link , true );
129 $tpl -> setVariable ( 'ARTICLE_LINK' , $article_link , true );
130 $tpl -> setVariable ( 'ARTICLE_TITLE' , date ( 'l, F d, Y' ), true );
131 $tpl -> setVariable ( 'ARTICLE_EXCERPT' , '' , true );
132 $tpl -> setVariable ( 'ARTICLE_CONTENT' , $doc -> saveHTML ( $node ), true );
134 $tpl -> setVariable ( 'ARTICLE_AUTHOR' , '' , true );
135 $tpl -> setVariable ( 'ARTICLE_SOURCE_LINK' , $site_url , true );
136 $tpl -> setVariable ( 'ARTICLE_SOURCE_TITLE' , $feed_title , true );
138 $tpl -> addBlock ( 'entry' );
143 $tpl -> addBlock ( 'feed' );
147 if ( $tpl -> generateOutputToString ( $tmp_data ))
148 $feed_data = $tmp_data ;
154 function api_version () {