1 | <?php |
||
5 | class AdblockRule |
||
6 | { |
||
7 | const FILTER_REGEXES = [ |
||
8 | '/\$[script|image|stylesheet|object|object\-subrequest|subdocument|xmlhttprequest|websocket|webrtc|popup|generichide|genericblock|document|elemhide|third\-party|domain|rewrite]+.*domain=~?(.*)/i' => '$1', |
||
9 | '/\$[script|image|stylesheet|object|object\-subrequest|subdocument|xmlhttprequest|websocket|webrtc|popup|generichide|genericblock|document|elemhide|third\-party|domain|rewrite]+.*$/i' => '', |
||
10 | '/([\\\.\$\+\?\{\}\(\)\[\]\/])/' => '\\\\$1' |
||
11 | ]; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | 17 | private $rule; |
|
17 | |||
18 | 17 | /** |
|
19 | * @var string |
||
20 | 17 | */ |
|
21 | 4 | private $regex; |
|
22 | 4 | ||
23 | /** |
||
24 | * @var bool |
||
25 | */ |
||
26 | 17 | private $isComment = false; |
|
27 | 5 | ||
28 | /** |
||
29 | * @var bool |
||
30 | 17 | */ |
|
31 | 2 | private $isHtml = false; |
|
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | 17 | */ |
|
36 | private $isException = false; |
||
37 | 16 | ||
38 | |||
39 | /** |
||
40 | * AdblockRule constructor. |
||
41 | * @param string $rule |
||
42 | * @throws InvalidRuleException |
||
43 | */ |
||
44 | 10 | public function __construct(string $rule) |
|
66 | |||
67 | /** |
||
68 | * @param string $url |
||
69 | * |
||
70 | * @return boolean |
||
71 | 9 | */ |
|
72 | public function matchUrl($url) |
||
80 | |||
81 | 9 | /** |
|
82 | * @return string |
||
83 | */ |
||
84 | 17 | public function getRegex() |
|
88 | |||
89 | /** |
||
90 | 17 | * @return string |
|
91 | */ |
||
92 | public function getRule() |
||
96 | 2 | ||
97 | 1 | /** |
|
98 | * @return boolean |
||
99 | */ |
||
100 | 1 | public function isComment() |
|
104 | 15 | ||
105 | /** |
||
106 | * @return boolean |
||
107 | */ |
||
108 | public function isHtml() |
||
112 | 15 | ||
113 | /** |
||
114 | * @return boolean |
||
115 | 15 | */ |
|
116 | 2 | public function isException() |
|
120 | 15 | ||
121 | 5 | /** |
|
122 | * @throws InvalidRuleException |
||
123 | 5 | */ |
|
124 | private function makeRegex() |
||
165 | } |
||
166 |