]> git.wh0rd.org Git - tt-rss.git/blob - plugins/af_fsckportal/init.php
Merge branch 'master' of git.tt-rss.org:fox/tt-rss
[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
20                         $doc = new DOMDocument();
21
22                         $charset_hack = '<head>
23                                 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
24                         </head>';
25
26                         @$doc->loadHTML($charset_hack . $article["content"]);
27
28                         if ($doc) {
29                                 $xpath = new DOMXPath($doc);
30                                 $entries = $xpath->query('(//img[@src]|//a[@href])');
31
32                                 foreach ($entries as $entry) {
33                                         if (preg_match("/feedsportal.com/", $entry->getAttribute("src"))) {
34                                                 $entry->parentNode->removeChild($entry);
35                                         } else if (preg_match("/feedsportal.com/", $entry->getAttribute("href"))) {
36                                                 $entry->parentNode->removeChild($entry);
37                                         }
38                                 }
39
40                                 $article["content"] = $doc->saveHTML();
41
42                 }
43
44                 return $article;
45         }
46
47         function api_version() {
48                 return 2;
49         }
50
51 }