From 31e4fb472942a71c8aed19be73342470e34f0a26 Mon Sep 17 00:00:00 2001 From: lavigor Date: Fri, 15 Jun 2018 02:03:57 +0300 Subject: [PATCH] [ticket/13713] Introduce ACP settings for mentions PHPBB3-13713 --- phpBB/adm/style/acp_posting_buttons.html | 5 ++- phpBB/assets/javascript/editor.js | 9 +++- phpBB/includes/acp/acp_board.php | 6 ++- phpBB/includes/functions.php | 4 +- phpBB/includes/functions_acp.php | 6 ++- phpBB/language/en/acp/board.php | 3 ++ phpBB/language/en/acp/permissions_phpbb.php | 2 + .../data/v330/add_mention_settings.php | 42 +++++++++++++++++++ phpBB/phpbb/notification/type/mention.php | 2 +- phpBB/phpbb/permissions.php | 2 + .../textformatter/renderer_interface.php | 8 ++++ phpBB/phpbb/textformatter/s9e/factory.php | 4 +- phpBB/phpbb/textformatter/s9e/renderer.php | 15 +++++++ .../prosilver/template/posting_buttons.html | 6 ++- 14 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 phpBB/phpbb/db/migration/data/v330/add_mention_settings.php diff --git a/phpBB/adm/style/acp_posting_buttons.html b/phpBB/adm/style/acp_posting_buttons.html index be15ab40d3..8a6a4462c7 100644 --- a/phpBB/adm/style/acp_posting_buttons.html +++ b/phpBB/adm/style/acp_posting_buttons.html @@ -1,7 +1,5 @@ + + + diff --git a/phpBB/assets/javascript/editor.js b/phpBB/assets/javascript/editor.js index 63d28e918a..61d852d254 100644 --- a/phpBB/assets/javascript/editor.js +++ b/phpBB/assets/javascript/editor.js @@ -386,6 +386,10 @@ function getCaretPosition(txtarea) { (function($) { function handle_mentions(txtarea) { + var $mentionParams = $('#mention_params'), + mentionURL = $mentionParams.data('mentionUrl'), + mentionNamesLimit = $mentionParams.data('mentionNamesLimit'), + mentionTopicId = $mentionParams.data('topicId'); $(txtarea).atwho({ at: "@", displayTpl: function(data) { @@ -395,9 +399,10 @@ function getCaretPosition(txtarea) { return "
  • " + avatar + "" + data.name + "" + rank + "
  • "; }, insertTpl: "[mention ${param}=${id}]${name}[/mention]", + limit: mentionNamesLimit, callbacks: { 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) }); } @@ -431,7 +436,7 @@ function getCaretPosition(txtarea) { phpbb.showDragNDrop(textarea); } - if (mention_url) { + if ($('#mention_params').length) { handle_mentions(textarea); } diff --git a/phpBB/includes/acp/acp_board.php b/phpBB/includes/acp/acp_board.php index f03a3e1ee4..62daba0373 100644 --- a/phpBB/includes/acp/acp_board.php +++ b/phpBB/includes/acp/acp_board.php @@ -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_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; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index c7c6375b06..bc9bc3dbd9 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -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_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_AUTOLOGIN_ENABLED' => ($config['allow_autologin']) ? true : false, diff --git a/phpBB/includes/functions_acp.php b/phpBB/includes/functions_acp.php index ce6712ffd0..a2ffe0b1b2 100644 --- a/phpBB/includes/functions_acp.php +++ b/phpBB/includes/functions_acp.php @@ -24,7 +24,7 @@ if (!defined('IN_PHPBB')) */ 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_dispatcher, $phpbb_container; @@ -89,7 +89,9 @@ function adm_page_header($page_title) 'U_ADM_INDEX' => append_sid("{$phpbb_admin_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_SMILIES_PATH' => "{$phpbb_root_path}{$config['smilies_path']}/", diff --git a/phpBB/language/en/acp/board.php b/phpBB/language/en/acp/board.php index d02c8b0141..d4aba08f3c 100644 --- a/phpBB/language/en/acp/board.php +++ b/phpBB/language/en/acp/board.php @@ -157,6 +157,7 @@ $lang = array_merge($lang, array( // Post Settings $lang = array_merge($lang, array( '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_EXPLAIN' => 'If disallowed the [URL] BBCode tag and automatic/magic URLs are disabled.', '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_URLS' => 'Maximum links per post', '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_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', diff --git a/phpBB/language/en/acp/permissions_phpbb.php b/phpBB/language/en/acp/permissions_phpbb.php index cdf4820475..475ac5aadd 100644 --- a/phpBB/language/en/acp/permissions_phpbb.php +++ b/phpBB/language/en/acp/permissions_phpbb.php @@ -76,6 +76,7 @@ $lang = array_merge($lang, array( 'ACL_U_ATTACH' => 'Can attach files', 'ACL_U_DOWNLOAD' => 'Can download files', + 'ACL_U_MENTION' => 'Can mention users and groups', 'ACL_U_SAVEDRAFTS' => 'Can save drafts', 'ACL_U_CHGCENSORS' => 'Can disable word censors', 'ACL_U_SIG' => 'Can use signature', @@ -123,6 +124,7 @@ $lang = array_merge($lang, array( 'ACL_F_STICKY' => 'Can post stickies', 'ACL_F_ANNOUNCE' => 'Can post 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_EDIT' => 'Can edit own posts', 'ACL_F_DELETE' => 'Can permanently delete own posts', diff --git a/phpBB/phpbb/db/migration/data/v330/add_mention_settings.php b/phpBB/phpbb/db/migration/data/v330/add_mention_settings.php new file mode 100644 index 0000000000..1f38d919b2 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v330/add_mention_settings.php @@ -0,0 +1,42 @@ + +* @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')), + ); + } +} diff --git a/phpBB/phpbb/notification/type/mention.php b/phpBB/phpbb/notification/type/mention.php index 54c180ad2c..1161814dbe 100644 --- a/phpBB/phpbb/notification/type/mention.php +++ b/phpBB/phpbb/notification/type/mention.php @@ -58,7 +58,7 @@ class mention extends \phpbb\notification\type\post */ public function is_available() { - return true; + return $this->config['allow_mentions'] && $this->auth->acl_get('u_mention'); } /** diff --git a/phpBB/phpbb/permissions.php b/phpBB/phpbb/permissions.php index bf3b33856e..857ae2a1ec 100644 --- a/phpBB/phpbb/permissions.php +++ b/phpBB/phpbb/permissions.php @@ -231,6 +231,7 @@ class permissions 'u_attach' => array('lang' => 'ACL_U_ATTACH', '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_chgcensors' => array('lang' => 'ACL_U_CHGCENSORS', '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_announce' => array('lang' => 'ACL_F_ANNOUNCE', '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_edit' => array('lang' => 'ACL_F_EDIT', 'cat' => 'post'), 'f_delete' => array('lang' => 'ACL_F_DELETE', 'cat' => 'post'), diff --git a/phpBB/phpbb/textformatter/renderer_interface.php b/phpBB/phpbb/textformatter/renderer_interface.php index 609b0bb642..106dbdc25f 100644 --- a/phpBB/phpbb/textformatter/renderer_interface.php +++ b/phpBB/phpbb/textformatter/renderer_interface.php @@ -89,4 +89,12 @@ interface renderer_interface * @return null */ public function set_viewsmilies($value); + + /** + * Set the "usemention" option + * + * @param bool $value Option's value + * @return null + */ + public function set_usemention($value); } diff --git a/phpBB/phpbb/textformatter/s9e/factory.php b/phpBB/phpbb/textformatter/s9e/factory.php index 1edb170634..16bd63cf73 100644 --- a/phpBB/phpbb/textformatter/s9e/factory.php +++ b/phpBB/phpbb/textformatter/s9e/factory.php @@ -310,8 +310,8 @@ class factory implements \phpbb\textformatter\cache_interface $configurator->tags['QUOTE']->nestingLimit = PHP_INT_MAX; } - // Modify the template to disable images/flash depending on user's settings - foreach (array('FLASH', 'IMG') as $name) + // Modify the template to disable images/flash/mentions depending on user's settings + foreach (array('FLASH', 'IMG', 'MENTION') as $name) { $tag = $configurator->tags[$name]; $tag->template = '' . $tag->template . ''; diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index cc909ea90c..64875d96fc 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -63,6 +63,11 @@ class renderer implements \phpbb\textformatter\renderer_interface */ protected $viewsmilies = false; + /** + * @var bool Whether the user is allowed to use mentions + */ + protected $usemention = false; + /** * Constructor * @@ -177,6 +182,7 @@ class renderer implements \phpbb\textformatter\renderer_interface $this->set_viewflash($user->optionget('viewflash')); $this->set_viewimg($user->optionget('viewimg')); $this->set_viewsmilies($user->optionget('viewsmilies')); + $this->set_usemention($config['allow_mentions'] && $auth->acl_get('u_mention')); // Set the stylesheet parameters foreach (array_keys($this->renderer->getParameters()) as $param_name) @@ -330,4 +336,13 @@ class renderer implements \phpbb\textformatter\renderer_interface $this->viewsmilies = $value; $this->renderer->setParameter('S_VIEWSMILIES', $value); } + + /** + * {@inheritdoc} + */ + public function set_usemention($value) + { + $this->usemention = $value; + $this->renderer->setParameter('S_VIEWMENTION', $value); + } } diff --git a/phpBB/styles/prosilver/template/posting_buttons.html b/phpBB/styles/prosilver/template/posting_buttons.html index 3ce5539d54..df4c038323 100644 --- a/phpBB/styles/prosilver/template/posting_buttons.html +++ b/phpBB/styles/prosilver/template/posting_buttons.html @@ -4,8 +4,6 @@ var text_name = 'signature''message'; var load_draft = false; var upload = false; - var mention_url = '{UA_MENTION_URL}'; - var mention_topic_id = '{S_TOPIC_ID}'; // Define the bbCode tags var bbcode = new Array(); @@ -27,6 +25,10 @@ } } + + + +