1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* Topic Preview |
5
|
|
|
* |
6
|
|
|
* @copyright (c) 2016 Matt Friedman |
7
|
|
|
* @license GNU General Public License, version 2 (GPL-2.0) |
8
|
|
|
* |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace vse\topicpreview\core\trim\tools; |
12
|
|
|
|
13
|
|
|
use phpbb\config\config; |
|
|
|
|
14
|
|
|
use phpbb\textformatter\s9e\utils; |
|
|
|
|
15
|
|
|
|
16
|
|
|
class bbcodes extends base |
17
|
|
|
{ |
18
|
|
|
/** @var config */ |
19
|
|
|
protected $config; |
20
|
|
|
|
21
|
|
|
/** @var bbcodes_legacy */ |
22
|
|
|
protected $trim_bbcodes_legacy; |
23
|
|
|
|
24
|
|
|
/** @var utils|null */ |
25
|
|
|
protected $text_formatter_utils; |
26
|
|
|
|
27
|
|
|
/** @var array Data array of BBCodes to remove */ |
28
|
|
|
protected $data; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Constructor |
32
|
|
|
* |
33
|
|
|
* @param config $config Config object |
34
|
|
|
* @param bbcodes_legacy $trim_bbcodes_legacy Legacy BBCodes trim tool |
35
|
|
|
* @param utils|null $text_formatter_utils Text Formatter Utils |
36
|
|
|
*/ |
37
|
38 |
|
public function __construct(config $config, bbcodes_legacy $trim_bbcodes_legacy, utils $text_formatter_utils = null) |
38
|
|
|
{ |
39
|
38 |
|
$this->config = $config; |
40
|
38 |
|
$this->trim_bbcodes_legacy = $trim_bbcodes_legacy; |
41
|
38 |
|
$this->text_formatter_utils = $text_formatter_utils; |
42
|
38 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @inheritdoc |
46
|
|
|
*/ |
47
|
38 |
|
public function is_available() |
48
|
|
|
{ |
49
|
38 |
|
return ($this->text_formatter_utils !== null); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @inheritdoc |
54
|
|
|
*/ |
55
|
12 |
|
public function run() |
56
|
|
|
{ |
57
|
|
|
// If text is not formatted as expected, use legacy bbcode stripper |
58
|
12 |
|
if (!$this->s9e_format()) |
59
|
12 |
|
{ |
60
|
12 |
|
return $this->trim_bbcodes_legacy |
61
|
12 |
|
->set_text($this->text) |
62
|
12 |
|
->run(); |
63
|
|
|
} |
64
|
|
|
|
65
|
12 |
|
return $this->set_data()->process(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @inheritdoc |
70
|
|
|
*/ |
71
|
12 |
|
public function set_data() |
72
|
|
|
{ |
73
|
12 |
|
if (!isset($this->data) || !is_array($this->data)) |
74
|
12 |
|
{ |
75
|
12 |
|
$this->data = !empty($this->config['topic_preview_strip_bbcodes']) ? explode('|', $this->config['topic_preview_strip_bbcodes']) : array(); |
76
|
12 |
|
array_unshift($this->data, 'flash'); |
77
|
12 |
|
} |
78
|
|
|
|
79
|
12 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Remove specified BBCodes and their contents |
84
|
|
|
* |
85
|
|
|
* @return string Stripped message text |
86
|
|
|
*/ |
87
|
12 |
|
protected function process() |
88
|
|
|
{ |
89
|
12 |
|
foreach ($this->data as $bbcode) |
90
|
|
|
{ |
91
|
12 |
|
$this->text = $this->text_formatter_utils->remove_bbcode($this->text, $bbcode); |
|
|
|
|
92
|
12 |
|
} |
93
|
|
|
|
94
|
12 |
|
return $this->text_formatter_utils->unparse($this->text); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Is the message s9e formatted |
99
|
|
|
* |
100
|
|
|
* @return bool True if message is s9e formatted, false otherwise |
101
|
|
|
*/ |
102
|
12 |
|
protected function s9e_format() |
103
|
|
|
{ |
104
|
12 |
|
return (bool) preg_match('/^<[rt][ >]/', $this->text); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths