2014-01-09 10:08:39 +00:00
< ? php
class Af_Comics extends Plugin {
2021-11-14 15:00:03 +00:00
/** @var array<object> $filters */
2014-02-17 09:00:25 +00:00
private $filters = array ();
2014-01-09 10:08:39 +00:00
function about () {
2021-03-01 09:11:42 +00:00
return array ( null ,
2014-01-09 10:08:39 +00:00
" Fixes RSS feeds of assorted comic strips " ,
" fox " );
}
function init ( $host ) {
2017-01-22 07:14:02 +00:00
$host -> add_hook ( $host :: HOOK_FETCH_FEED , $this );
2019-03-12 17:16:24 +00:00
$host -> add_hook ( $host :: HOOK_FEED_BASIC_INFO , $this );
2018-02-07 06:52:36 +00:00
$host -> add_hook ( $host :: HOOK_SUBSCRIBE_FEED , $this );
2014-01-09 10:08:39 +00:00
$host -> add_hook ( $host :: HOOK_ARTICLE_FILTER , $this );
$host -> add_hook ( $host :: HOOK_PREFS_TAB , $this );
2014-02-17 09:00:25 +00:00
require_once __DIR__ . " /filter_base.php " ;
2014-01-09 10:08:39 +00:00
2017-06-05 09:53:06 +00:00
$filters = array_merge ( glob ( __DIR__ . " /filters.local/*.php " ), glob ( __DIR__ . " /filters/*.php " ));
$names = [];
2014-01-09 10:08:39 +00:00
2014-02-17 09:00:25 +00:00
foreach ( $filters as $file ) {
$filter_name = preg_replace ( " / \ ..* $ / " , " " , basename ( $file ));
2014-01-09 10:08:39 +00:00
2020-09-17 16:02:27 +00:00
if ( array_search ( $filter_name , $names ) === false ) {
2017-06-05 09:53:06 +00:00
if ( ! class_exists ( $filter_name )) {
require_once $file ;
}
2014-01-09 10:08:39 +00:00
2017-06-05 09:53:06 +00:00
array_push ( $names , $filter_name );
2021-10-18 04:41:24 +00:00
$filter = new $filter_name ( $host );
2017-06-05 09:53:06 +00:00
if ( is_subclass_of ( $filter , " Af_ComicFilter " )) {
array_push ( $this -> filters , $filter );
array_push ( $names , $filter_name );
}
2014-02-17 08:26:46 +00:00
}
}
2014-02-17 09:00:25 +00:00
}
2014-01-09 10:08:39 +00:00
2014-02-17 09:00:25 +00:00
function hook_prefs_tab ( $args ) {
2017-06-05 09:53:06 +00:00
if ( $args != " prefFeeds " ) return ;
2014-01-09 10:08:39 +00:00
2020-02-27 09:15:56 +00:00
$comics = [];
2014-01-09 10:08:39 +00:00
2014-02-17 09:00:25 +00:00
foreach ( $this -> filters as $f ) {
foreach ( $f -> supported () as $comic ) {
array_push ( $comics , $comic );
2014-01-09 10:08:39 +00:00
}
}
2014-02-17 09:00:25 +00:00
asort ( $comics );
2014-02-14 12:44:39 +00:00
2021-02-17 09:25:33 +00:00
?>
< div dojoType = " dijit.layout.AccordionPane "
title = " <i class='material-icons'>photo</i> <?= __('Feeds supported by af_comics') ?> " >
2014-01-09 10:08:39 +00:00
2021-02-17 09:25:33 +00:00
< h3 >< ? = __ ( " The following comics are currently supported: " ) ?> </h3>
2017-01-22 18:52:25 +00:00
2021-02-17 09:25:33 +00:00
< ul class = 'panel panel-scrollable list list-unstyled' >
< ? php foreach ( $comics as $comic ) { ?>
< li >< ? = htmlspecialchars ( $comic ) ?> </li>
< ? php } ?>
</ ul >
2017-06-05 09:53:06 +00:00
2021-02-17 09:25:33 +00:00
< ? = format_notice ( " 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>). " ) ?>
< ? = format_notice ( 'Drop any updated filters into <code>filters.local</code> in plugin directory.' ) ?>
</ div >
< ? php
2014-02-17 09:00:25 +00:00
}
2014-01-09 10:08:39 +00:00
2014-02-17 09:00:25 +00:00
function hook_article_filter ( $article ) {
foreach ( $this -> filters as $f ) {
if ( $f -> process ( $article ))
break ;
2014-01-09 10:08:39 +00:00
}
return $article ;
}
2017-01-22 07:14:02 +00:00
function hook_fetch_feed ( $feed_data , $fetch_url , $owner_uid , $feed , $last_article_timestamp , $auth_login , $auth_pass ) {
2020-02-27 09:15:56 +00:00
foreach ( $this -> filters as $f ) {
$res = $f -> on_fetch ( $fetch_url );
2020-02-27 07:19:09 +00:00
2020-02-27 09:15:56 +00:00
if ( $res )
return $res ;
2017-01-22 07:14:02 +00:00
}
return $feed_data ;
}
2018-02-07 06:52:36 +00:00
function hook_subscribe_feed ( $contents , $url , $auth_login , $auth_pass ) {
2020-02-27 09:15:56 +00:00
foreach ( $this -> filters as $f ) {
$res = $f -> on_subscribe ( $url );
2018-02-07 06:52:36 +00:00
2020-02-27 09:15:56 +00:00
if ( $res )
return $res ;
}
2018-02-07 06:52:36 +00:00
return $contents ;
}
2019-03-12 17:16:24 +00:00
function hook_feed_basic_info ( $basic_info , $fetch_url , $owner_uid , $feed , $auth_login , $auth_pass ) {
2020-02-27 09:15:56 +00:00
foreach ( $this -> filters as $f ) {
$res = $f -> on_basic_info ( $fetch_url );
2020-02-27 07:19:09 +00:00
2020-02-27 09:15:56 +00:00
if ( $res )
return $res ;
}
2019-03-12 17:16:24 +00:00
return $basic_info ;
}
2014-01-09 10:08:39 +00:00
function api_version () {
return 2 ;
}
2017-09-09 18:51:59 +00:00
}