diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 58c1f2f16d..d872a7094c 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -85,8 +85,10 @@ class factory implements \phpbb\textformatter\cache_interface 'list' => '[LIST type={HASHMAP=1:decimal,a:lower-alpha,A:upper-alpha,i:lower-roman,I:upper-roman;optional;postFilter=#simpletext} #createChild=LI]{TEXT}[/LIST]', 'li' => '[* $tagName=LI]{TEXT}[/*]', 'mention' => - "[MENTION={PARSE=/^(?[ug]):(?\d+)$/} + "[MENTION={PARSE=/^g:(?'group_id'\d+)|u:(?'user_id'\d+)$/} + group_id={UINT;optional} profile_url={URL;optional;postFilter=#false} + user_id={UINT;optional} ]{TEXT}[/MENTION]", 'quote' => "[QUOTE diff --git a/phpBB/phpbb/textformatter/s9e/mention_helper.php b/phpBB/phpbb/textformatter/s9e/mention_helper.php index e7b58f0b81..3094dabb4a 100644 --- a/phpBB/phpbb/textformatter/s9e/mention_helper.php +++ b/phpBB/phpbb/textformatter/s9e/mention_helper.php @@ -33,12 +33,12 @@ class mention_helper protected $user; /** - * @var string Base URL for a user profile link, uses {ID} as placeholder + * @var string Base URL for a user profile link, uses {USER_ID} as placeholder */ protected $user_profile_url; /** - * @var string Base URL for a group profile link, uses {ID} as placeholder + * @var string Base URL for a group profile link, uses {GROUP_ID} as placeholder */ protected $group_profile_url; @@ -61,8 +61,8 @@ class mention_helper $this->db = $db; $this->auth = $auth; $this->user = $user; - $this->user_profile_url = append_sid($root_path . 'memberlist.' . $php_ext, 'mode=viewprofile&u={ID}', false); - $this->group_profile_url = append_sid($root_path . 'memberlist.' . $php_ext, 'mode=group&g={ID}', false); + $this->user_profile_url = append_sid($root_path . 'memberlist.' . $php_ext, 'mode=viewprofile&u={USER_ID}', false); + $this->group_profile_url = append_sid($root_path . 'memberlist.' . $php_ext, 'mode=group&g={GROUP_ID}', false); } /** @@ -83,12 +83,13 @@ class mention_helper 'MENTION', function ($attributes) use ($profile_urls) { - if (isset($attributes['type']) && isset($attributes['id'])) + if (isset($attributes['user_id'])) { - $type = $attributes['type']; - $id = $attributes['id']; - - $attributes['profile_url'] = str_replace('{ID}', $id, $profile_urls[$type]); + $attributes['profile_url'] = str_replace('{USER_ID}', $attributes['user_id'], $profile_urls['u']); + } + else if (isset($attributes['group_id'])) + { + $attributes['profile_url'] = str_replace('{GROUP_ID}', $attributes['group_id'], $profile_urls['g']); } return $attributes; @@ -186,21 +187,15 @@ class mention_helper return $ids; } - $dom = new \DOMDocument; - $dom->loadXML($xml); - $xpath = new \DOMXPath($dom); + // Add IDs of users mentioned directly + $user_ids = TextFormatterUtils::getAttributeValues($xml, 'MENTION', 'user_id'); + $ids = array_merge($ids, array_map('intval', $user_ids)); - /** @var \DOMElement $mention */ - foreach ($xpath->query('//MENTION') as $mention) + // Add IDs of users mentioned as group members + $group_ids = TextFormatterUtils::getAttributeValues($xml, 'MENTION', 'group_id'); + foreach ($group_ids as $group_id) { - if ($mention->getAttribute('type') === 'u') - { - $ids[] = (int) $mention->getAttribute('id'); - } - else if ($mention->getAttribute('type') === 'g') - { - $this->get_user_ids_for_group($ids, (int) $mention->getAttribute('id')); - } + $this->get_user_ids_for_group($ids, (int) $group_id); } return $ids; diff --git a/tests/text_formatter/s9e/mention_helper_test.php b/tests/text_formatter/s9e/mention_helper_test.php index e0293c9747..7bd89fa843 100644 --- a/tests/text_formatter/s9e/mention_helper_test.php +++ b/tests/text_formatter/s9e/mention_helper_test.php @@ -80,11 +80,11 @@ class mention_helper_test extends phpbb_database_test_case { return [ [ - '[mention=u:3]test[/mention]', + '[mention=u:3]test[/mention]', 'mode=viewprofile&u=3', ], [ - '[mention=g:3]test[/mention]', + '[mention=g:3]test[/mention]', 'mode=group&g=3', ], ]; @@ -103,11 +103,11 @@ class mention_helper_test extends phpbb_database_test_case { return [ [ - '[mention=u:3]test[/mention][mention=u:4]test[/mention][mention=u:5]test[/mention]', + '[mention=u:3]test[/mention][mention=u:4]test[/mention][mention=u:5]test[/mention]', [3, 4, 5], ], [ - '[mention=g:1]test[/mention][mention=g:2]test[/mention][mention=g:3]test[/mention]', + '[mention=g:1]test[/mention][mention=g:2]test[/mention][mention=g:3]test[/mention]', [4, 2, 6], ], ];