Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
95.00% |
19 / 20 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| quote_helper | |
95.00% |
19 / 20 |
|
50.00% |
1 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| inject_metadata | |
93.75% |
15 / 16 |
|
0.00% |
0 / 1 |
5.01 | |||
| 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 | class quote_helper |
| 17 | { |
| 18 | /** |
| 19 | * @var string Base URL for a post link, uses {POST_ID} as placeholder |
| 20 | */ |
| 21 | protected $post_url; |
| 22 | |
| 23 | /** |
| 24 | * @var string Base URL for a private message link, uses {MSG_ID} as placeholder |
| 25 | */ |
| 26 | protected $msg_url; |
| 27 | |
| 28 | /** |
| 29 | * @var string Base URL for a profile link, uses {USER_ID} as placeholder |
| 30 | */ |
| 31 | protected $profile_url; |
| 32 | |
| 33 | /** |
| 34 | * @var \phpbb\user |
| 35 | */ |
| 36 | protected $user; |
| 37 | |
| 38 | /** |
| 39 | * Constructor |
| 40 | * |
| 41 | * @param \phpbb\user $user |
| 42 | * @param string $root_path |
| 43 | * @param string $php_ext |
| 44 | */ |
| 45 | public function __construct(\phpbb\user $user, $root_path, $php_ext) |
| 46 | { |
| 47 | $this->post_url = append_sid($root_path . 'viewtopic.' . $php_ext, 'p={POST_ID}#p{POST_ID}', false); |
| 48 | $this->msg_url = append_sid($root_path . 'ucp.' . $php_ext, 'i=pm&mode=view&p={MSG_ID}', false); |
| 49 | $this->profile_url = append_sid($root_path . 'memberlist.' . $php_ext, 'mode=viewprofile&u={USER_ID}', false); |
| 50 | $this->user = $user; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Inject dynamic metadata into QUOTE tags in given XML |
| 55 | * |
| 56 | * @param string $xml Original XML |
| 57 | * @return string Modified XML |
| 58 | */ |
| 59 | public function inject_metadata($xml) |
| 60 | { |
| 61 | return \s9e\TextFormatter\Utils::replaceAttributes( |
| 62 | $xml, |
| 63 | 'QUOTE', |
| 64 | function ($attributes) |
| 65 | { |
| 66 | if (isset($attributes['post_id'])) |
| 67 | { |
| 68 | $attributes['post_url'] = str_replace('{POST_ID}', $attributes['post_id'], $this->post_url); |
| 69 | } |
| 70 | if (isset($attributes['msg_id'])) |
| 71 | { |
| 72 | $attributes['msg_url'] = str_replace('{MSG_ID}', $attributes['msg_id'], $this->msg_url); |
| 73 | } |
| 74 | if (isset($attributes['time'])) |
| 75 | { |
| 76 | $attributes['date'] = $this->user->format_date($attributes['time']); |
| 77 | } |
| 78 | if (isset($attributes['user_id'])) |
| 79 | { |
| 80 | $attributes['profile_url'] = str_replace('{USER_ID}', $attributes['user_id'], $this->profile_url); |
| 81 | } |
| 82 | |
| 83 | return $attributes; |
| 84 | } |
| 85 | ); |
| 86 | } |
| 87 | } |