summaryrefslogtreecommitdiff
path: root/init.php
blob: 4e81fde050a5f1fd00b1c549e86e5a3d06ccfa13 (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
<?php
class Af_Fsckportal extends Plugin {

	private $host;

	function about() {
		return array(null,
			"Remove feedsportal spamlinks from article content",
			"fox");
	}

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

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

	function hook_article_filter($article) {

			$doc = new DOMDocument();

			if (@$doc->loadHTML('<?xml encoding="UTF-8">' . $article["content"])) {
				$xpath = new DOMXPath($doc);
				$entries = $xpath->query('(//img[@src]|//a[@href])');

				foreach ($entries as $entry) {
					if (preg_match("/feedsportal.com/", $entry->getAttribute("src"))) {
						$entry->parentNode->removeChild($entry);
					} else if (preg_match("/feedsportal.com/", $entry->getAttribute("href"))) {
						$entry->parentNode->removeChild($entry);
					}
				}

				$article["content"] = $doc->saveHTML();
		}

		return $article;
	}

	function api_version() {
		return 2;
	}

}