mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-19 22:10:14 +02:00
[ticket/13713] Implement mention BBCode
PHPBB3-13713
This commit is contained in:
parent
86b5fbed38
commit
41b1b32e29
@ -388,6 +388,7 @@ function getCaretPosition(txtarea) {
|
|||||||
function handle_mentions(txtarea) {
|
function handle_mentions(txtarea) {
|
||||||
$(txtarea).atwho({
|
$(txtarea).atwho({
|
||||||
at: "@",
|
at: "@",
|
||||||
|
insertTpl: "[mention ${param}=${id}]${name}[/mention]",
|
||||||
callbacks: {
|
callbacks: {
|
||||||
remoteFilter: function(query, callback) {
|
remoteFilter: function(query, callback) {
|
||||||
$.getJSON(mention_url, {keyword: query, topic_id: mention_topic_id}, function (data) {
|
$.getJSON(mention_url, {keyword: query, topic_id: mention_topic_id}, function (data) {
|
||||||
|
@ -57,12 +57,6 @@ class mention
|
|||||||
$names = array_merge($names, $source->get($keyword, $topic_id));
|
$names = array_merge($names, $source->get($keyword, $topic_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
$clean_names = [];
|
return new JsonResponse(array_values($names));
|
||||||
foreach ($names as $name)
|
|
||||||
{
|
|
||||||
$clean_names[] = $name['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return new JsonResponse($clean_names);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,8 @@ abstract class group implements source_interface
|
|||||||
{
|
{
|
||||||
$names['g' . $group_id] = [
|
$names['g' . $group_id] = [
|
||||||
'name' => $groups[$group_id]['group_name'],
|
'name' => $groups[$group_id]['group_name'],
|
||||||
|
'param' => 'group_id',
|
||||||
|
'id' => $group_id,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ abstract class user implements source_interface
|
|||||||
{
|
{
|
||||||
$names['u' . $row['user_id']] = [
|
$names['u' . $row['user_id']] = [
|
||||||
'name' => $row['username'],
|
'name' => $row['username'],
|
||||||
|
'param' => 'user_id',
|
||||||
|
'id' => $row['user_id'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
69
phpbb/phpbb/textformatter/s9e/mention_helper.php
Normal file
69
phpbb/phpbb/textformatter/s9e/mention_helper.php
Normal 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;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user