Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
acp_utils | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
analyse_bbcode | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\textformatter\s9e; |
15 | |
16 | use phpbb\textformatter\acp_utils_interface; |
17 | use s9e\TextFormatter\Configurator\Exceptions\UnsafeTemplateException; |
18 | |
19 | class acp_utils implements acp_utils_interface |
20 | { |
21 | /** |
22 | * @var factory $factory |
23 | */ |
24 | protected $factory; |
25 | |
26 | /** |
27 | * @param factory $factory |
28 | */ |
29 | public function __construct(factory $factory) |
30 | { |
31 | $this->factory = $factory; |
32 | } |
33 | |
34 | /** |
35 | * {@inheritdoc} |
36 | */ |
37 | public function analyse_bbcode(string $definition, string $template): array |
38 | { |
39 | $configurator = $this->factory->get_configurator(); |
40 | $return = ['status' => self::BBCODE_STATUS_SAFE]; |
41 | |
42 | // Capture and normalize the BBCode name manually because there's no easy way to retrieve |
43 | // it in TextFormatter <= 2.x |
44 | if (preg_match('(\\[([-\\w]++))', $definition, $m)) |
45 | { |
46 | $return['name'] = strtoupper($m[1]); |
47 | } |
48 | |
49 | try |
50 | { |
51 | $configurator->BBCodes->addCustom($definition, $template); |
52 | } |
53 | catch (UnsafeTemplateException $e) |
54 | { |
55 | $return['status'] = self::BBCODE_STATUS_UNSAFE; |
56 | $return['error_text'] = $e->getMessage(); |
57 | $return['error_html'] = $e->highlightNode('<span class="highlight">'); |
58 | } |
59 | catch (\Exception $e) |
60 | { |
61 | $return['status'] = (preg_match('(xml|xpath|xsl)i', $e->getMessage())) ? self::BBCODE_STATUS_INVALID_TEMPLATE : self::BBCODE_STATUS_INVALID_DEFINITION; |
62 | $return['error_text'] = $e->getMessage(); |
63 | } |
64 | |
65 | return $return; |
66 | } |
67 | } |