diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js index a2998a3f38..bdcd2b0b7a 100644 --- a/phpBB/assets/javascript/editor.js +++ b/phpBB/assets/javascript/editor.js @@ -388,6 +388,7 @@ function getCaretPosition(txtarea) { function handle_mentions(txtarea) { $(txtarea).atwho({ at: "@", + insertTpl: "[mention ${param}=${id}]${name}[/mention]", callbacks: { remoteFilter: function(query, callback) { $.getJSON(mention_url, {keyword: query, topic_id: mention_topic_id}, function (data) { diff --git a/phpbb/phpbb/mention/controller/mention.php b/phpbb/phpbb/mention/controller/mention.php index c8bc801e0f..106ba5744f 100644 --- a/phpbb/phpbb/mention/controller/mention.php +++ b/phpbb/phpbb/mention/controller/mention.php @@ -57,12 +57,6 @@ class mention $names = array_merge($names, $source->get($keyword, $topic_id)); } - $clean_names = []; - foreach ($names as $name) - { - $clean_names[] = $name['name']; - } - - return new JsonResponse($clean_names); + return new JsonResponse(array_values($names)); } } diff --git a/phpbb/phpbb/mention/source/group.php b/phpbb/phpbb/mention/source/group.php index b503ac714c..61225c6b6b 100644 --- a/phpbb/phpbb/mention/source/group.php +++ b/phpbb/phpbb/mention/source/group.php @@ -94,7 +94,9 @@ abstract class group implements source_interface foreach ($group_ids as $group_id) { $names['g' . $group_id] = [ - 'name' => $groups[$group_id]['group_name'], + 'name' => $groups[$group_id]['group_name'], + 'param' => 'group_id', + 'id' => $group_id, ]; } diff --git a/phpbb/phpbb/mention/source/user.php b/phpbb/phpbb/mention/source/user.php index 55f94e4866..6910a0b401 100644 --- a/phpbb/phpbb/mention/source/user.php +++ b/phpbb/phpbb/mention/source/user.php @@ -47,7 +47,9 @@ abstract class user implements source_interface while ($row = $this->db->sql_fetchrow($res)) { $names['u' . $row['user_id']] = [ - 'name' => $row['username'], + 'name' => $row['username'], + 'param' => 'user_id', + 'id' => $row['user_id'], ]; } diff --git a/phpbb/phpbb/textformatter/s9e/mention_helper.php b/phpbb/phpbb/textformatter/s9e/mention_helper.php new file mode 100644 index 0000000000..4f19a9dc5f --- /dev/null +++ b/phpbb/phpbb/textformatter/s9e/mention_helper.php @@ -0,0 +1,69 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\textformatter\s9e; + +class mention_helper +{ + /** + * @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 {GROUP_ID} as placeholder + */ + protected $group_profile_url; + + /** + * Constructor + * + * @param string $root_path + * @param string $php_ext + */ + public function __construct($root_path, $php_ext) + { + $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); + } + + /** + * Inject dynamic metadata into MENTION tags in given XML + * + * @param string $xml Original XML + * @return string Modified XML + */ + public function inject_metadata($xml) + { + $user_profile_url = $this->user_profile_url; + $group_profile_url = $this->group_profile_url; + + return \s9e\TextFormatter\Utils::replaceAttributes( + $xml, + 'MENTION', + function ($attributes) use ($user_profile_url, $group_profile_url) + { + if (isset($attributes['user_id'])) + { + $attributes['profile_url'] = str_replace('{USER_ID}', $attributes['user_id'], $user_profile_url); + } + else if (isset($attributes['group_id'])) + { + $attributes['profile_url'] = str_replace('{GROUP_ID}', $attributes['group_id'], $group_profile_url); + } + + return $attributes; + } + ); + } +}