Skip to content

Commit

Permalink
Merge pull request #64 from paul999/replace
Browse files Browse the repository at this point in the history
Replace atwho library with tribute.
  • Loading branch information
paul999 authored Jun 1, 2019
2 parents 7036a8a + bd8dcf5 commit 0a8388d
Show file tree
Hide file tree
Showing 36 changed files with 2,313 additions and 6,367 deletions.
1 change: 1 addition & 0 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
- '@dbal.conn'
- '@auth'
- '@request'
- '@config'

paul999.mention.listener:
class: paul999\mention\event\main_listener
Expand Down
18 changes: 13 additions & 5 deletions controller/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace paul999\mention\controller;

use phpbb\auth\auth;
use phpbb\config\config;
use phpbb\db\driver\driver_interface;
use phpbb\exception\http_exception;
use phpbb\request\request_interface;
Expand Down Expand Up @@ -42,20 +43,27 @@ class main
*/
private $request;

/**
* @var config
*/
private $config;

/**
* Constructor
*
* @param user $user
* @param driver_interface $db
* @param auth $auth
* @param request_interface $request
* @param config $config
*/
public function __construct(user $user, driver_interface $db, auth $auth, request_interface $request)
public function __construct(user $user, driver_interface $db, auth $auth, request_interface $request, config $config)
{
$this->user = $user;
$this->db = $db;
$this->auth = $auth;
$this->request = $request;
$this->config = $config;
}

/**
Expand All @@ -72,9 +80,9 @@ public function handle()
}
$name = utf8_clean_string($this->request->variable('q', '', true));

if (strlen($name) < 2)
if (strlen($name) < $this->config['simple_mention_minlength'])
{
return new JsonResponse(['usernames' => []]);
return new JsonResponse([]);
}

$sql = 'SELECT user_id, username
Expand All @@ -88,8 +96,8 @@ public function handle()
while ($row = $this->db->sql_fetchrow($result))
{
$return[] = [
'name' => $row['username'],
'id' => $row['user_id'],
'key' =>$row['username'],
'value' => $row['username'],
];
}
$this->db->sql_freeresult($result);
Expand Down
68 changes: 65 additions & 3 deletions event/main_listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ static public function getSubscribedEvents()
'core.posting_modify_template_vars' => 'remove_mention_in_quote',
'core.markread_before' => 'mark_read',
'rxu.postsmerging.posts_merging_end' => 'submit_post',
'core.acp_board_config_edit_add' => 'acp_board_settings',
'core.validate_config_variable' => 'validate_config',
'core.page_header' => 'page_header',
];
}

Expand Down Expand Up @@ -179,11 +182,70 @@ public function mark_read($event)
break;

case 'topic':
$this->mark_topic_tead($event['topic_id'], $event['post_time']);
$this->mark_topic_read($event['topic_id'], $event['post_time']);
break;
}
}

/**
* Add settings to the ACP page.
*
* @param \phpbb\event\data $event The event object
*/
public function acp_board_settings($event)
{
if ($event['mode'] === 'post')
{
$this->user->add_lang('acp_common', false, false, 'paul999/mention');
$display_vars = $event['display_vars'];
$sm_config_vars = [
'simple_mention_minlength' => [
'lang' => 'MENTION_LENGTH',
'validate' => 'int',
'type' => 'number:1:9999',
'explain' => true,
],
'simple_mention_color' => [
'lang' => 'MENTION_COLOR',
'validate' => 'mention_hex',
'type' => 'text:6:6',
'explain' => true,
],
];
$display_vars['vars'] = phpbb_insert_config_array($display_vars['vars'], $sm_config_vars, array('after' => 'allow_quick_reply'));
$event['display_vars'] = $display_vars;
}
}

/**
* Validate the simple mention hex color
* @param \phpbb\event\data $event Event data
*/
public function validate_config($event)
{
if ($event['config_definition']['validate'] === 'mention_hex')
{
$value = $event['cfg_array'][$event['config_name']];
if (!preg_match("/([a-f0-9]{3}){1,2}\b/i", $value))
{
$error = $event['error'];
$error[] = sprintf($this->user->lang('MENTION_COLOR_INVALID'), $value);
$event['error'] = $error;
}
}
}

/**
* Set the mention color on pages.
* @param \phpbb\event\data $event
*/
public function page_header($event)
{
$this->template->assign_vars([
'MENTION_COLOR' => $this->config['simple_mention_color'],
]);
}

/**
* Mark all notifications as read
* @param int $post_time
Expand All @@ -200,7 +262,7 @@ private function mark_all_read($post_time)
* @param int|array $topic_id
* @param int $post_time
*/
private function mark_topic_tead($topic_id, $post_time)
private function mark_topic_read($topic_id, $post_time)
{
$this->notification_manager->mark_notifications_by_parent(array(
'paul999.mention.notification.type.mention',
Expand Down Expand Up @@ -239,7 +301,7 @@ private function mark_forum_read($forum_id, $post_time)
}
$this->db->sql_freeresult($result);

$this->mark_topic_tead($topic_ids, $post_time);
$this->mark_topic_read($topic_ids, $post_time);
}

/**
Expand Down
33 changes: 33 additions & 0 deletions language/ar/acp_common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
*
* phpBB mentions. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2016, paul999, https://www.phpbbextensions.io
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

if (!defined('IN_PHPBB'))
{
exit;
}

if (empty($lang) || !is_array($lang))
{
$lang = array();
}

/**
* As there is no proper way of including this file just when the notification is
* loaded we need to include it on all pages. Make sure to only include important
* language items (That are directly needed by the notification system) in this file.
*/
$lang = array_merge($lang, array(
'MENTION_LENGTH' => 'Simple mention minimum length',
'MENTION_LENGTH_EXPLAIN' => 'The minimum text length before the simple mention dropdown is shown.
On larger boards you might want to increase this value.',
'MENTION_COLOR' => 'Simple mention color',
'MENTION_COLOR_EXPLAIN' => 'This color is used within the post to define what user is mentioned. Only hex values can be used.',
'MENTION_COLOR_INVALID' => 'The selected mention color (%s) is invalid. Please select a valid HEX color, without #',
));
2 changes: 1 addition & 1 deletion language/ar/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
*/
$lang = array_merge($lang, array(
'MENTION_MENTION_NOTIFICATION' => 'تمت الإشارة اليك بواسطة %1$s<br />في “%2$s”',
'NOTIFICATION_TYPE_MENTION' => 'شخص أشار لي بمنشور'
'NOTIFICATION_TYPE_MENTION' => 'شخص أشار لي بمنشور',
));
33 changes: 33 additions & 0 deletions language/cs/acp_common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
*
* phpBB mentions. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2016, paul999, https://www.phpbbextensions.io
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

if (!defined('IN_PHPBB'))
{
exit;
}

if (empty($lang) || !is_array($lang))
{
$lang = array();
}

/**
* As there is no proper way of including this file just when the notification is
* loaded we need to include it on all pages. Make sure to only include important
* language items (That are directly needed by the notification system) in this file.
*/
$lang = array_merge($lang, array(
'MENTION_LENGTH' => 'Simple mention minimum length',
'MENTION_LENGTH_EXPLAIN' => 'The minimum text length before the simple mention dropdown is shown.
On larger boards you might want to increase this value.',
'MENTION_COLOR' => 'Simple mention color',
'MENTION_COLOR_EXPLAIN' => 'This color is used within the post to define what user is mentioned. Only hex values can be used.',
'MENTION_COLOR_INVALID' => 'The selected mention color (%s) is invalid. Please select a valid HEX color, without #',
));
2 changes: 1 addition & 1 deletion language/cs/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
*/
$lang = array_merge($lang, array(
'MENTION_MENTION_NOTIFICATION' => 'Byli jste zmíněni od %1$s<br />v “%2$s”',
'NOTIFICATION_TYPE_MENTION' => 'Někdo mě zmínil'
'NOTIFICATION_TYPE_MENTION' => 'Někdo mě zmínil',
));
33 changes: 33 additions & 0 deletions language/cs_nef/acp_common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
*
* phpBB mentions. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2016, paul999, https://www.phpbbextensions.io
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

if (!defined('IN_PHPBB'))
{
exit;
}

if (empty($lang) || !is_array($lang))
{
$lang = array();
}

/**
* As there is no proper way of including this file just when the notification is
* loaded we need to include it on all pages. Make sure to only include important
* language items (That are directly needed by the notification system) in this file.
*/
$lang = array_merge($lang, array(
'MENTION_LENGTH' => 'Simple mention minimum length',
'MENTION_LENGTH_EXPLAIN' => 'The minimum text length before the simple mention dropdown is shown.
On larger boards you might want to increase this value.',
'MENTION_COLOR' => 'Simple mention color',
'MENTION_COLOR_EXPLAIN' => 'This color is used within the post to define what user is mentioned. Only hex values can be used.',
'MENTION_COLOR_INVALID' => 'The selected mention color (%s) is invalid. Please select a valid HEX color, without #',
));
2 changes: 1 addition & 1 deletion language/cs_nef/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
*/
$lang = array_merge($lang, array(
'MENTION_MENTION_NOTIFICATION' => 'Byl jsi zmíněn od %1$s<br />v “%2$s”',
'NOTIFICATION_TYPE_MENTION' => 'Někdo mě zmínil'
'NOTIFICATION_TYPE_MENTION' => 'Někdo mě zmínil',
));
33 changes: 33 additions & 0 deletions language/de/acp_common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
*
* phpBB mentions. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2016, paul999, https://www.phpbbextensions.io
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

if (!defined('IN_PHPBB'))
{
exit;
}

if (empty($lang) || !is_array($lang))
{
$lang = array();
}

/**
* As there is no proper way of including this file just when the notification is
* loaded we need to include it on all pages. Make sure to only include important
* language items (That are directly needed by the notification system) in this file.
*/
$lang = array_merge($lang, array(
'MENTION_LENGTH' => 'Simple mention minimum length',
'MENTION_LENGTH_EXPLAIN' => 'The minimum text length before the simple mention dropdown is shown.
On larger boards you might want to increase this value.',
'MENTION_COLOR' => 'Simple mention color',
'MENTION_COLOR_EXPLAIN' => 'This color is used within the post to define what user is mentioned. Only hex values can be used.',
'MENTION_COLOR_INVALID' => 'The selected mention color (%s) is invalid. Please select a valid HEX color, without #',
));
2 changes: 1 addition & 1 deletion language/de/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
*/
$lang = array_merge($lang, array(
'MENTION_MENTION_NOTIFICATION' => 'Du wurdest von %1$s erwähnt<br />in “%2$s”',
'NOTIFICATION_TYPE_MENTION' => 'Jemand hat dich erwähnt'
'NOTIFICATION_TYPE_MENTION' => 'Jemand hat dich erwähnt',
));
33 changes: 33 additions & 0 deletions language/de_x_sie/acp_common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
*
* phpBB mentions. An extension for the phpBB Forum Software package.
*
* @copyright (c) 2016, paul999, https://www.phpbbextensions.io
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/

if (!defined('IN_PHPBB'))
{
exit;
}

if (empty($lang) || !is_array($lang))
{
$lang = array();
}

/**
* As there is no proper way of including this file just when the notification is
* loaded we need to include it on all pages. Make sure to only include important
* language items (That are directly needed by the notification system) in this file.
*/
$lang = array_merge($lang, array(
'MENTION_LENGTH' => 'Simple mention minimum length',
'MENTION_LENGTH_EXPLAIN' => 'The minimum text length before the simple mention dropdown is shown.
On larger boards you might want to increase this value.',
'MENTION_COLOR' => 'Simple mention color',
'MENTION_COLOR_EXPLAIN' => 'This color is used within the post to define what user is mentioned. Only hex values can be used.',
'MENTION_COLOR_INVALID' => 'The selected mention color (%s) is invalid. Please select a valid HEX color, without #',
));
2 changes: 1 addition & 1 deletion language/de_x_sie/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
*/
$lang = array_merge($lang, array(
'MENTION_MENTION_NOTIFICATION' => 'Sie wurden von %1$s in “%2$s” erwähnt',
'NOTIFICATION_TYPE_MENTION' => 'Jemand hat Sie erwähnt'
'NOTIFICATION_TYPE_MENTION' => 'Jemand hat Sie erwähnt',
));
Loading

0 comments on commit 0a8388d

Please sign in to comment.