summaryrefslogtreecommitdiff
path: root/plugins/af_comics/init.php
blob: 784be9e0a86e8dc6436c4785c02f4e4d3644c64c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class Af_Comics extends Plugin {

	private $host;
	private $filters = array();

	function about() {
		return array(1.0,
			"Fixes RSS feeds of assorted comic strips",
			"fox");
	}

	function init($host) {
		$this->host = $host;

		$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
		$host->add_hook($host::HOOK_PREFS_TAB, $this);

		require_once __DIR__ . "/filter_base.php";

		$filters = glob(__DIR__ . "/filters/*.php");

		foreach ($filters as $file) {
			require_once $file;
			$filter_name = preg_replace("/\..*$/", "", basename($file));

			$filter = new $filter_name();

			if (is_subclass_of($filter, "Af_ComicFilter")) {
				array_push($this->filters, $filter);
			}
		}

	}

	function hook_prefs_tab($args) {
		if ($args != "prefPrefs") return;

		print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds supported by af_comics')."\">";

		print_notice("This plugin can be easily extended by adding filters to <code>plugins/af_comics/filters</code>.");

		print "<p>" . __("The following comics are currently supported:") . "</p>";

		$comics = array();

		foreach ($this->filters as $f) {
			foreach ($f->supported() as $comic) {
				array_push($comics, $comic);
			}
		}

		asort($comics);

		print "<ul class=\"browseFeedList\" style=\"border-width : 1px\">";
		foreach ($comics as $comic) {
			print "<li>$comic</li>";
		}
		print "</ul>";

		print "</div>";
	}

	function hook_article_filter($article) {
		$owner_uid = $article["owner_uid"];

		foreach ($this->filters as $f) {
			if ($f->process($article))
				break;
		}

		return $article;

	}

	function api_version() {
		return 2;
	}

}
?>