From f757e65559e94ee332d6d0677471df01d6a9394c Mon Sep 17 00:00:00 2001 From: lavigor Date: Thu, 17 May 2018 04:50:37 +0300 Subject: [PATCH] [ticket/13713] Start working on User Mentions PHPBB3-13713 --- phpBB/config/default/container/services.yml | 1 + phpBB/config/default/routing/routing.yml | 5 ++ .../default/container/services_mention.yml | 25 +++++++++ phpbb/phpbb/mention/controller/mention.php | 52 ++++++++++++++++++ phpbb/phpbb/mention/source/topic.php | 53 +++++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 phpbb/config/default/container/services_mention.yml create mode 100644 phpbb/phpbb/mention/controller/mention.php create mode 100644 phpbb/phpbb/mention/source/topic.php diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index b8fc7fa755..1d48ead588 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -15,6 +15,7 @@ imports: - { resource: services_help.yml } - { resource: services_http.yml } - { resource: services_language.yml } + - { resource: services_mention.yml } - { resource: services_migrator.yml } - { resource: services_mimetype_guesser.yml } - { resource: services_module.yml } diff --git a/phpBB/config/default/routing/routing.yml b/phpBB/config/default/routing/routing.yml index a5e9265dc3..9ed725fc06 100644 --- a/phpBB/config/default/routing/routing.yml +++ b/phpBB/config/default/routing/routing.yml @@ -24,6 +24,11 @@ phpbb_help_routing: resource: help.yml prefix: /help +phpbb_mention_controller: + path: /mention + methods: [GET, POST] + defaults: { _controller: phpbb.mention.controller:handle } + phpbb_report_routing: resource: report.yml diff --git a/phpbb/config/default/container/services_mention.yml b/phpbb/config/default/container/services_mention.yml new file mode 100644 index 0000000000..c7fc969182 --- /dev/null +++ b/phpbb/config/default/container/services_mention.yml @@ -0,0 +1,25 @@ +services: +# ----- Controller ----- + phpbb.mention.controller: + class: phpbb\mention\controller\mention + arguments: + - '@request' + - '%core.root_path%' + - '%core.php_ext%' + +# ----- Sources for mention ----- + phpbb.mention.source_collection: + class: phpbb\di\service_collection + arguments: + - '@service_container' + tags: + - { name: service_collection, tag: mention.source } + + phpbb.mention.source.topic: + class: phpbb\mention\source\topic + arguments: + - '@dbal.conn' + - '@request' + tags: + - { name: mention.source } + diff --git a/phpbb/phpbb/mention/controller/mention.php b/phpbb/phpbb/mention/controller/mention.php new file mode 100644 index 0000000000..b9e51eed28 --- /dev/null +++ b/phpbb/phpbb/mention/controller/mention.php @@ -0,0 +1,52 @@ + + * @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\mention\controller; + +use Symfony\Component\HttpFoundation\JsonResponse; + +class mention +{ + /** @var \phpbb\request\request_interface */ + protected $request; + + /** @var string */ + protected $phpbb_root_path; + + /** @var string */ + protected $php_ext; + + /** + * Constructor + * + */ + public function __construct(\phpbb\request\request_interface $request, $phpbb_root_path, $phpEx) + { + $this->request = $request; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $phpEx; + } + + public function handle() + { + if (!$this->request->is_ajax()) + { + redirect(append_sid($this->phpbb_root_path . 'index.' . $this->php_ext)); + } + + $topic_id = $this->request->variable('topic_id', 0); + // TODO + + return new JsonResponse(); + } +} diff --git a/phpbb/phpbb/mention/source/topic.php b/phpbb/phpbb/mention/source/topic.php new file mode 100644 index 0000000000..739be108cd --- /dev/null +++ b/phpbb/phpbb/mention/source/topic.php @@ -0,0 +1,53 @@ + +* @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\mention\method; + +class topic +{ + /** @var \phpbb\db\driver\driver_interface */ + protected $db; + + /** @var \phpbb\request\request_interface */ + protected $request; + + /** + * Constructor + */ + public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\request\request_interface $request) + { + $this->db = $db; + $this->request = $request; + } + + public function get($keyword, $topic_id) + { + $query = $this->db->sql_build_query('SELECT', [ + 'SELECT' => 'u.username, u.user_id', + 'FROM' => [ + USERS_TABLE => 'u', + ], + 'LEFT_JOIN' => [ + 'FROM' => [POSTS_TABLE => 'p'], + 'ON' => 'u.user_id = p.poster_id' + ], + 'WHERE' => 'p.topic_id = ' . $topic_id . ' AND u.user_id <> ' . ANONYMOUS . ' + AND ' . $this->db->sql_in_set('u.user_type', [USER_NORMAL, USER_FOUNDER]) . ' + AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()), + 'ORDER_BY' => 'p.post_time DESC' + ]); + $res = $this->db->sql_query_limit($query, 5); + + return $this->db->sql_fetchrowset($res); + } +}