1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-10 17:45:18 +02:00

[ticket/13713] Implement mention BBCode

PHPBB3-13713
This commit is contained in:
lavigor 2018-05-30 20:52:35 +03:00 committed by Marc Alexander
parent 86b5fbed38
commit 41b1b32e29
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995
5 changed files with 77 additions and 9 deletions

View File

@ -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) {

View File

@ -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));
}
}

View File

@ -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,
];
}

View File

@ -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'],
];
}

View File

@ -0,0 +1,69 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @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;
}
);
}
}