]>
Commit | Line | Data |
---|---|---|
1130125a AD |
1 | <?php |
2 | class Af_Fsckportal extends Plugin { | |
3 | ||
4 | private $host; | |
5 | ||
6 | function about() { | |
7 | return array(1.0, | |
8 | "Remove feedsportal spamlinks from article content", | |
9 | "fox"); | |
10 | } | |
11 | ||
12 | function init($host) { | |
13 | $this->host = $host; | |
14 | ||
15 | $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); | |
16 | } | |
17 | ||
18 | function hook_article_filter($article) { | |
19 | $owner_uid = $article["owner_uid"]; | |
20 | ||
21 | if (strpos($article["plugin_data"], "fsckportal,$owner_uid:") === FALSE) { | |
22 | ||
23 | $doc = new DOMDocument(); | |
24 | ||
25 | $charset_hack = '<head> | |
26 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
27 | </head>'; | |
28 | ||
29 | @$doc->loadHTML($charset_hack . $article["content"]); | |
30 | ||
31 | if ($doc) { | |
32 | $xpath = new DOMXPath($doc); | |
33 | $entries = $xpath->query('(//img[@src]|//a[@href])'); | |
34 | ||
1130125a AD |
35 | foreach ($entries as $entry) { |
36 | if (preg_match("/feedsportal.com/", $entry->getAttribute("src"))) { | |
37 | $entry->parentNode->removeChild($entry); | |
38 | } else if (preg_match("/feedsportal.com/", $entry->getAttribute("href"))) { | |
39 | $entry->parentNode->removeChild($entry); | |
40 | } | |
41 | } | |
42 | ||
3263c9cc | 43 | $article["content"] = $doc->saveXML(); |
1130125a AD |
44 | $article["plugin_data"] = "fsckportal,$owner_uid:" . $article["plugin_data"]; |
45 | ||
46 | } | |
47 | } else if (isset($article["stored"]["content"])) { | |
48 | $article["content"] = $article["stored"]["content"]; | |
49 | } | |
50 | ||
51 | return $article; | |
52 | } | |
53 | ||
54 | function api_version() { | |
55 | return 2; | |
56 | } | |
57 | ||
58 | } | |
59 | ?> |