Af_Fsckportal::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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
Security Best Practice introduced by
It seems like you do not handle an error condition for loadHTML(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

22
            /** @scrutinizer ignore-unhandled */ @$doc->loadHTML('<?xml encoding="UTF-8">'.$article["content"]);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
23
24
            if ($doc) {
0 ignored issues
show
introduced by
$doc is of type DOMDocument, thus it always evaluated to true.
Loading history...
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