]> git.wh0rd.org - tt-rss.git/blob - plugins/af_fsckportal/init.php
4795fd8efbabe9f80bc2b30bd696737179aa6dd8
[tt-rss.git] / plugins / af_fsckportal / init.php
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
35 $matches = array();
36
37 foreach ($entries as $entry) {
38 if (preg_match("/feedsportal.com/", $entry->getAttribute("src"))) {
39 $entry->parentNode->removeChild($entry);
40 } else if (preg_match("/feedsportal.com/", $entry->getAttribute("href"))) {
41 $entry->parentNode->removeChild($entry);
42 }
43 }
44
45 $article["content"] = $doc->saveXML($basenode);
46 $article["plugin_data"] = "fsckportal,$owner_uid:" . $article["plugin_data"];
47
48 }
49 } else if (isset($article["stored"]["content"])) {
50 $article["content"] = $article["stored"]["content"];
51 }
52
53 return $article;
54 }
55
56 function api_version() {
57 return 2;
58 }
59
60 }
61 ?>