codysnider /
tt-rss
| 1 | <?php |
||
| 2 | class Af_Fsckportal extends Plugin { |
||
| 3 | |||
| 4 | private $host; |
||
| 5 | |||
| 6 | public function about() { |
||
| 7 | return array(1.0, |
||
| 8 | "Remove feedsportal spamlinks from article content", |
||
| 9 | "fox"); |
||
| 10 | } |
||
| 11 | |||
| 12 | public function init($host) { |
||
| 13 | $this->host = $host; |
||
| 14 | |||
| 15 | $host->add_hook($host::HOOK_ARTICLE_FILTER, $this); |
||
| 16 | } |
||
| 17 | |||
| 18 | public function hook_article_filter($article) { |
||
| 19 | |||
| 20 | $doc = new DOMDocument(); |
||
| 21 | |||
| 22 | @$doc->loadHTML('<?xml encoding="UTF-8">'.$article["content"]); |
||
|
0 ignored issues
–
show
|
|||
| 23 | |||
| 24 | if ($doc) { |
||
|
0 ignored issues
–
show
|
|||
| 25 | $xpath = new DOMXPath($doc); |
||
| 26 | $entries = $xpath->query('(//img[@src]|//a[@href])'); |
||
| 27 | |||
| 28 | foreach ($entries as $entry) { |
||
| 29 | if (preg_match("/feedsportal.com/", $entry->getAttribute("src"))) { |
||
| 30 | $entry->parentNode->removeChild($entry); |
||
| 31 | } else if (preg_match("/feedsportal.com/", $entry->getAttribute("href"))) { |
||
| 32 | $entry->parentNode->removeChild($entry); |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | $article["content"] = $doc->saveHTML(); |
||
| 37 | |||
| 38 | } |
||
| 39 | |||
| 40 | return $article; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function api_version() { |
||
| 44 | return 2; |
||
| 45 | } |
||
| 46 | |||
| 47 | } |
||
| 48 |
If you suppress an error, we recommend checking for the error condition explicitly: