[ticket/13713] Introduce ACP settings for mentions

PHPBB3-13713
This commit is contained in:
lavigor 2018-06-15 02:03:57 +03:00 committed by Marc Alexander
parent 012d009fbe
commit 31e4fb4729
No known key found for this signature in database
GPG key ID: 50E0D2423696F995
14 changed files with 101 additions and 13 deletions

View file

@ -1,7 +1,5 @@
<script> <script>
// <![CDATA[ // <![CDATA[
var mention_url = '{UA_MENTION_URL}';
var mention_topic_id = '{S_TOPIC_ID}';
// Define the bbCode tags // Define the bbCode tags
var bbcode = new Array(); var bbcode = new Array();
@ -10,6 +8,9 @@
// ]]> // ]]>
</script> </script>
<!-- IF S_ALLOW_MENTIONS -->
<div id="mention_params" style="display: none;" data-mention-url="{U_MENTION_URL}" data-mention-names-limit="{S_MENTION_NAMES_LIMIT}" data-topic-id="{S_TOPIC_ID}"></div>
<!-- ENDIF -->
<!-- INCLUDECSS {T_ASSETS_PATH}/css/jquery.atwho.min.css --> <!-- INCLUDECSS {T_ASSETS_PATH}/css/jquery.atwho.min.css -->
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/jquery.caret.min.js --> <!-- INCLUDEJS {T_ASSETS_PATH}/javascript/jquery.caret.min.js -->
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/jquery.atwho.min.js --> <!-- INCLUDEJS {T_ASSETS_PATH}/javascript/jquery.atwho.min.js -->

View file

@ -386,6 +386,10 @@ function getCaretPosition(txtarea) {
(function($) { (function($) {
function handle_mentions(txtarea) { function handle_mentions(txtarea) {
var $mentionParams = $('#mention_params'),
mentionURL = $mentionParams.data('mentionUrl'),
mentionNamesLimit = $mentionParams.data('mentionNamesLimit'),
mentionTopicId = $mentionParams.data('topicId');
$(txtarea).atwho({ $(txtarea).atwho({
at: "@", at: "@",
displayTpl: function(data) { displayTpl: function(data) {
@ -395,9 +399,10 @@ function getCaretPosition(txtarea) {
return "<li>" + avatar + "<span>" + data.name + "</span>" + rank + "</li>"; return "<li>" + avatar + "<span>" + data.name + "</span>" + rank + "</li>";
}, },
insertTpl: "[mention ${param}=${id}]${name}[/mention]", insertTpl: "[mention ${param}=${id}]${name}[/mention]",
limit: mentionNamesLimit,
callbacks: { callbacks: {
remoteFilter: function(query, callback) { remoteFilter: function(query, callback) {
$.getJSON(mention_url, {keyword: query, topic_id: mention_topic_id}, function (data) { $.getJSON(mentionURL, {keyword: query, topic_id: mentionTopicId}, function (data) {
callback(data) callback(data)
}); });
} }
@ -431,7 +436,7 @@ function getCaretPosition(txtarea) {
phpbb.showDragNDrop(textarea); phpbb.showDragNDrop(textarea);
} }
if (mention_url) { if ($('#mention_params').length) {
handle_mentions(textarea); handle_mentions(textarea);
} }

View file

@ -220,7 +220,11 @@ class acp_board
'max_post_img_width' => array('lang' => 'MAX_POST_IMG_WIDTH', 'validate' => 'int:0:9999', 'type' => 'number:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']), 'max_post_img_width' => array('lang' => 'MAX_POST_IMG_WIDTH', 'validate' => 'int:0:9999', 'type' => 'number:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
'max_post_img_height' => array('lang' => 'MAX_POST_IMG_HEIGHT', 'validate' => 'int:0:9999', 'type' => 'number:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']), 'max_post_img_height' => array('lang' => 'MAX_POST_IMG_HEIGHT', 'validate' => 'int:0:9999', 'type' => 'number:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['PIXEL']),
'legend3' => 'ACP_SUBMIT_CHANGES', 'legend3' => 'MENTIONS',
'allow_mentions' => array('lang' => 'ALLOW_MENTIONS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
'mention_names_limit' => array('lang' => 'MENTION_NAMES_LIMIT', 'validate' => 'int:1:9999', 'type' => 'number:1:9999', 'explain' => false),
'legend4' => 'ACP_SUBMIT_CHANGES',
) )
); );
break; break;

View file

@ -3946,7 +3946,9 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
'U_RESTORE_PERMISSIONS' => ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm') : '', 'U_RESTORE_PERMISSIONS' => ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm') : '',
'U_FEED' => $controller_helper->route('phpbb_feed_index'), 'U_FEED' => $controller_helper->route('phpbb_feed_index'),
'UA_MENTION_URL' => $controller_helper->route('phpbb_mention_controller'), 'S_ALLOW_MENTIONS' => ($config['allow_mentions'] && $auth->acl_get('u_mention') && (empty($forum_id) || $auth->acl_get('f_mention', $forum_id))) ? true : false,
'S_MENTION_NAMES_LIMIT' => $config['mention_names_limit'],
'U_MENTION_URL' => $controller_helper->route('phpbb_mention_controller'),
'S_USER_LOGGED_IN' => ($user->data['user_id'] != ANONYMOUS) ? true : false, 'S_USER_LOGGED_IN' => ($user->data['user_id'] != ANONYMOUS) ? true : false,
'S_AUTOLOGIN_ENABLED' => ($config['allow_autologin']) ? true : false, 'S_AUTOLOGIN_ENABLED' => ($config['allow_autologin']) ? true : false,

View file

@ -24,7 +24,7 @@ if (!defined('IN_PHPBB'))
*/ */
function adm_page_header($page_title) function adm_page_header($page_title)
{ {
global $config, $user, $template; global $config, $user, $template, $auth;
global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $SID, $_SID;
global $phpbb_dispatcher, $phpbb_container; global $phpbb_dispatcher, $phpbb_container;
@ -89,7 +89,9 @@ function adm_page_header($page_title)
'U_ADM_INDEX' => append_sid("{$phpbb_admin_path}index.$phpEx"), 'U_ADM_INDEX' => append_sid("{$phpbb_admin_path}index.$phpEx"),
'U_INDEX' => append_sid("{$phpbb_root_path}index.$phpEx"), 'U_INDEX' => append_sid("{$phpbb_root_path}index.$phpEx"),
'UA_MENTION_URL' => $controller_helper->route('phpbb_mention_controller'), 'S_ALLOW_MENTIONS' => ($config['allow_mentions'] && $auth->acl_get('u_mention')) ? true : false,
'S_MENTION_NAMES_LIMIT' => $config['mention_names_limit'],
'U_MENTION_URL' => $controller_helper->route('phpbb_mention_controller'),
'T_IMAGES_PATH' => "{$phpbb_root_path}images/", 'T_IMAGES_PATH' => "{$phpbb_root_path}images/",
'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/", 'T_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/",

View file

@ -157,6 +157,7 @@ $lang = array_merge($lang, array(
// Post Settings // Post Settings
$lang = array_merge($lang, array( $lang = array_merge($lang, array(
'ACP_POST_SETTINGS_EXPLAIN' => 'Here you can set all default settings for posting.', 'ACP_POST_SETTINGS_EXPLAIN' => 'Here you can set all default settings for posting.',
'ALLOW_MENTIONS' => 'Allow mentions of users and groups boardwide',
'ALLOW_POST_LINKS' => 'Allow links in posts/private messages', 'ALLOW_POST_LINKS' => 'Allow links in posts/private messages',
'ALLOW_POST_LINKS_EXPLAIN' => 'If disallowed the <code>[URL]</code> BBCode tag and automatic/magic URLs are disabled.', 'ALLOW_POST_LINKS_EXPLAIN' => 'If disallowed the <code>[URL]</code> BBCode tag and automatic/magic URLs are disabled.',
'ALLOWED_SCHEMES_LINKS' => 'Allowed schemes in links', 'ALLOWED_SCHEMES_LINKS' => 'Allowed schemes in links',
@ -187,6 +188,8 @@ $lang = array_merge($lang, array(
'MAX_POST_IMG_WIDTH_EXPLAIN' => 'Maximum width of a flash file in postings. Set to 0 for unlimited size.', 'MAX_POST_IMG_WIDTH_EXPLAIN' => 'Maximum width of a flash file in postings. Set to 0 for unlimited size.',
'MAX_POST_URLS' => 'Maximum links per post', 'MAX_POST_URLS' => 'Maximum links per post',
'MAX_POST_URLS_EXPLAIN' => 'Maximum number of URLs in a post. Set to 0 for unlimited links.', 'MAX_POST_URLS_EXPLAIN' => 'Maximum number of URLs in a post. Set to 0 for unlimited links.',
'MENTIONS' => 'Mentions',
'MENTION_NAMES_LIMIT' => 'Maximum number of names in dropdown list',
'MIN_CHAR_LIMIT' => 'Minimum characters per post/message', 'MIN_CHAR_LIMIT' => 'Minimum characters per post/message',
'MIN_CHAR_LIMIT_EXPLAIN' => 'The minimum number of characters the user need to enter within a post/private message. The minimum for this setting is 1.', 'MIN_CHAR_LIMIT_EXPLAIN' => 'The minimum number of characters the user need to enter within a post/private message. The minimum for this setting is 1.',
'POSTING' => 'Posting', 'POSTING' => 'Posting',

View file

@ -76,6 +76,7 @@ $lang = array_merge($lang, array(
'ACL_U_ATTACH' => 'Can attach files', 'ACL_U_ATTACH' => 'Can attach files',
'ACL_U_DOWNLOAD' => 'Can download files', 'ACL_U_DOWNLOAD' => 'Can download files',
'ACL_U_MENTION' => 'Can mention users and groups',
'ACL_U_SAVEDRAFTS' => 'Can save drafts', 'ACL_U_SAVEDRAFTS' => 'Can save drafts',
'ACL_U_CHGCENSORS' => 'Can disable word censors', 'ACL_U_CHGCENSORS' => 'Can disable word censors',
'ACL_U_SIG' => 'Can use signature', 'ACL_U_SIG' => 'Can use signature',
@ -123,6 +124,7 @@ $lang = array_merge($lang, array(
'ACL_F_STICKY' => 'Can post stickies', 'ACL_F_STICKY' => 'Can post stickies',
'ACL_F_ANNOUNCE' => 'Can post announcements', 'ACL_F_ANNOUNCE' => 'Can post announcements',
'ACL_F_ANNOUNCE_GLOBAL' => 'Can post global announcements', 'ACL_F_ANNOUNCE_GLOBAL' => 'Can post global announcements',
'ACL_F_MENTION' => 'Can mention users and groups',
'ACL_F_REPLY' => 'Can reply to topics', 'ACL_F_REPLY' => 'Can reply to topics',
'ACL_F_EDIT' => 'Can edit own posts', 'ACL_F_EDIT' => 'Can edit own posts',
'ACL_F_DELETE' => 'Can permanently delete own posts', 'ACL_F_DELETE' => 'Can permanently delete own posts',

View file

@ -0,0 +1,42 @@
<?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\db\migration\data\v330;
class add_mention_settings extends \phpbb\db\migration\migration
{
public function update_data()
{
return array(
array('config.add', array('allow_mentions', true)),
array('config.add', array('mention_names_limit', 10)),
// Set up user permissions
array('permission.add', array('u_mention', true)),
array('permission.permission_set', array('ROLE_USER_FULL', 'u_mention')),
array('permission.permission_set', array('ROLE_USER_STANDARD', 'u_mention')),
array('permission.permission_set', array('ROLE_USER_LIMITED', 'u_mention')),
array('permission.permission_set', array('ROLE_USER_NOPM', 'u_mention')),
array('permission.permission_set', array('ROLE_USER_NOAVATAR', 'u_mention')),
// Set up forum permissions
array('permission.add', array('f_mention', false)),
array('permission.permission_set', array('ROLE_FORUM_FULL', 'f_mention')),
array('permission.permission_set', array('ROLE_FORUM_STANDARD', 'f_mention')),
array('permission.permission_set', array('ROLE_FORUM_LIMITED', 'f_mention')),
array('permission.permission_set', array('ROLE_FORUM_ONQUEUE', 'f_mention')),
array('permission.permission_set', array('ROLE_FORUM_POLLS', 'f_mention')),
array('permission.permission_set', array('ROLE_FORUM_LIMITED_POLLS', 'f_mention')),
);
}
}

View file

@ -58,7 +58,7 @@ class mention extends \phpbb\notification\type\post
*/ */
public function is_available() public function is_available()
{ {
return true; return $this->config['allow_mentions'] && $this->auth->acl_get('u_mention');
} }
/** /**

View file

@ -231,6 +231,7 @@ class permissions
'u_attach' => array('lang' => 'ACL_U_ATTACH', 'cat' => 'post'), 'u_attach' => array('lang' => 'ACL_U_ATTACH', 'cat' => 'post'),
'u_download' => array('lang' => 'ACL_U_DOWNLOAD', 'cat' => 'post'), 'u_download' => array('lang' => 'ACL_U_DOWNLOAD', 'cat' => 'post'),
'u_mention' => array('lang' => 'ACL_U_MENTION', 'cat' => 'post'),
'u_savedrafts' => array('lang' => 'ACL_U_SAVEDRAFTS', 'cat' => 'post'), 'u_savedrafts' => array('lang' => 'ACL_U_SAVEDRAFTS', 'cat' => 'post'),
'u_chgcensors' => array('lang' => 'ACL_U_CHGCENSORS', 'cat' => 'post'), 'u_chgcensors' => array('lang' => 'ACL_U_CHGCENSORS', 'cat' => 'post'),
'u_sig' => array('lang' => 'ACL_U_SIG', 'cat' => 'post'), 'u_sig' => array('lang' => 'ACL_U_SIG', 'cat' => 'post'),
@ -276,6 +277,7 @@ class permissions
'f_sticky' => array('lang' => 'ACL_F_STICKY', 'cat' => 'post'), 'f_sticky' => array('lang' => 'ACL_F_STICKY', 'cat' => 'post'),
'f_announce' => array('lang' => 'ACL_F_ANNOUNCE', 'cat' => 'post'), 'f_announce' => array('lang' => 'ACL_F_ANNOUNCE', 'cat' => 'post'),
'f_announce_global' => array('lang' => 'ACL_F_ANNOUNCE_GLOBAL', 'cat' => 'post'), 'f_announce_global' => array('lang' => 'ACL_F_ANNOUNCE_GLOBAL', 'cat' => 'post'),
'f_mention' => array('lang' => 'ACL_F_MENTION', 'cat' => 'post'),
'f_reply' => array('lang' => 'ACL_F_REPLY', 'cat' => 'post'), 'f_reply' => array('lang' => 'ACL_F_REPLY', 'cat' => 'post'),
'f_edit' => array('lang' => 'ACL_F_EDIT', 'cat' => 'post'), 'f_edit' => array('lang' => 'ACL_F_EDIT', 'cat' => 'post'),
'f_delete' => array('lang' => 'ACL_F_DELETE', 'cat' => 'post'), 'f_delete' => array('lang' => 'ACL_F_DELETE', 'cat' => 'post'),

View file

@ -89,4 +89,12 @@ interface renderer_interface
* @return null * @return null
*/ */
public function set_viewsmilies($value); public function set_viewsmilies($value);
/**
* Set the "usemention" option
*
* @param bool $value Option's value
* @return null
*/
public function set_usemention($value);
} }

View file

@ -310,8 +310,8 @@ class factory implements \phpbb\textformatter\cache_interface
$configurator->tags['QUOTE']->nestingLimit = PHP_INT_MAX; $configurator->tags['QUOTE']->nestingLimit = PHP_INT_MAX;
} }
// Modify the template to disable images/flash depending on user's settings // Modify the template to disable images/flash/mentions depending on user's settings
foreach (array('FLASH', 'IMG') as $name) foreach (array('FLASH', 'IMG', 'MENTION') as $name)
{ {
$tag = $configurator->tags[$name]; $tag = $configurator->tags[$name];
$tag->template = '<xsl:choose><xsl:when test="$S_VIEW' . $name . '">' . $tag->template . '</xsl:when><xsl:otherwise><xsl:apply-templates/></xsl:otherwise></xsl:choose>'; $tag->template = '<xsl:choose><xsl:when test="$S_VIEW' . $name . '">' . $tag->template . '</xsl:when><xsl:otherwise><xsl:apply-templates/></xsl:otherwise></xsl:choose>';

View file

@ -63,6 +63,11 @@ class renderer implements \phpbb\textformatter\renderer_interface
*/ */
protected $viewsmilies = false; protected $viewsmilies = false;
/**
* @var bool Whether the user is allowed to use mentions
*/
protected $usemention = false;
/** /**
* Constructor * Constructor
* *
@ -177,6 +182,7 @@ class renderer implements \phpbb\textformatter\renderer_interface
$this->set_viewflash($user->optionget('viewflash')); $this->set_viewflash($user->optionget('viewflash'));
$this->set_viewimg($user->optionget('viewimg')); $this->set_viewimg($user->optionget('viewimg'));
$this->set_viewsmilies($user->optionget('viewsmilies')); $this->set_viewsmilies($user->optionget('viewsmilies'));
$this->set_usemention($config['allow_mentions'] && $auth->acl_get('u_mention'));
// Set the stylesheet parameters // Set the stylesheet parameters
foreach (array_keys($this->renderer->getParameters()) as $param_name) foreach (array_keys($this->renderer->getParameters()) as $param_name)
@ -330,4 +336,13 @@ class renderer implements \phpbb\textformatter\renderer_interface
$this->viewsmilies = $value; $this->viewsmilies = $value;
$this->renderer->setParameter('S_VIEWSMILIES', $value); $this->renderer->setParameter('S_VIEWSMILIES', $value);
} }
/**
* {@inheritdoc}
*/
public function set_usemention($value)
{
$this->usemention = $value;
$this->renderer->setParameter('S_VIEWMENTION', $value);
}
} }

View file

@ -4,8 +4,6 @@
var text_name = <!-- IF $SIG_EDIT -->'signature'<!-- ELSE -->'message'<!-- ENDIF -->; var text_name = <!-- IF $SIG_EDIT -->'signature'<!-- ELSE -->'message'<!-- ENDIF -->;
var load_draft = false; var load_draft = false;
var upload = false; var upload = false;
var mention_url = '{UA_MENTION_URL}';
var mention_topic_id = '{S_TOPIC_ID}';
// Define the bbCode tags // Define the bbCode tags
var bbcode = new Array(); var bbcode = new Array();
@ -27,6 +25,10 @@
} }
} }
</script> </script>
<!-- IF S_ALLOW_MENTIONS -->
<div id="mention_params" style="display: none;" data-mention-url="{U_MENTION_URL}" data-mention-names-limit="{S_MENTION_NAMES_LIMIT}" data-topic-id="{S_TOPIC_ID}"></div>
<!-- ENDIF -->
<!-- INCLUDECSS {T_ASSETS_PATH}/css/jquery.atwho.min.css --> <!-- INCLUDECSS {T_ASSETS_PATH}/css/jquery.atwho.min.css -->
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/jquery.caret.min.js --> <!-- INCLUDEJS {T_ASSETS_PATH}/javascript/jquery.caret.min.js -->
<!-- INCLUDEJS {T_ASSETS_PATH}/javascript/jquery.atwho.min.js --> <!-- INCLUDEJS {T_ASSETS_PATH}/javascript/jquery.atwho.min.js -->