mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/13713] Abstract class for usernames
PHPBB3-13713
This commit is contained in:
parent
f757e65559
commit
b6e2d1f48c
5 changed files with 145 additions and 43 deletions
|
@ -3,6 +3,7 @@ services:
|
||||||
phpbb.mention.controller:
|
phpbb.mention.controller:
|
||||||
class: phpbb\mention\controller\mention
|
class: phpbb\mention\controller\mention
|
||||||
arguments:
|
arguments:
|
||||||
|
- '@phpbb.mention.source_collection'
|
||||||
- '@request'
|
- '@request'
|
||||||
- '%core.root_path%'
|
- '%core.root_path%'
|
||||||
- '%core.php_ext%'
|
- '%core.php_ext%'
|
||||||
|
@ -15,11 +16,17 @@ services:
|
||||||
tags:
|
tags:
|
||||||
- { name: service_collection, tag: mention.source }
|
- { name: service_collection, tag: mention.source }
|
||||||
|
|
||||||
|
phpbb.mention.source.friend:
|
||||||
|
class: phpbb\mention\source\friend
|
||||||
|
arguments:
|
||||||
|
- '@dbal.conn'
|
||||||
|
- '@user'
|
||||||
|
tags:
|
||||||
|
- { name: mention.source }
|
||||||
|
|
||||||
phpbb.mention.source.topic:
|
phpbb.mention.source.topic:
|
||||||
class: phpbb\mention\source\topic
|
class: phpbb\mention\source\topic
|
||||||
arguments:
|
arguments:
|
||||||
- '@dbal.conn'
|
- '@dbal.conn'
|
||||||
- '@request'
|
|
||||||
tags:
|
tags:
|
||||||
- { name: mention.source }
|
- { name: mention.source }
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,9 @@ use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
class mention
|
class mention
|
||||||
{
|
{
|
||||||
|
/** @var \phpbb\di\service_collection */
|
||||||
|
protected $mention_sources;
|
||||||
|
|
||||||
/** @var \phpbb\request\request_interface */
|
/** @var \phpbb\request\request_interface */
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
|
@ -30,8 +33,9 @@ class mention
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\request\request_interface $request, $phpbb_root_path, $phpEx)
|
public function __construct($mention_sources, \phpbb\request\request_interface $request, $phpbb_root_path, $phpEx)
|
||||||
{
|
{
|
||||||
|
$this->mention_sources = $mention_sources;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
$this->phpbb_root_path = $phpbb_root_path;
|
$this->phpbb_root_path = $phpbb_root_path;
|
||||||
$this->php_ext = $phpEx;
|
$this->php_ext = $phpEx;
|
||||||
|
@ -44,9 +48,15 @@ class mention
|
||||||
redirect(append_sid($this->phpbb_root_path . 'index.' . $this->php_ext));
|
redirect(append_sid($this->phpbb_root_path . 'index.' . $this->php_ext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$keyword = $this->request->variable('keyword', '', true);
|
||||||
$topic_id = $this->request->variable('topic_id', 0);
|
$topic_id = $this->request->variable('topic_id', 0);
|
||||||
// TODO
|
$names = [];
|
||||||
|
|
||||||
return new JsonResponse();
|
foreach ($this->mention_sources as $source)
|
||||||
|
{
|
||||||
|
$names = array_merge($names, $source->get($keyword, $topic_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new JsonResponse($names);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
56
phpbb/phpbb/mention/source/friend.php
Normal file
56
phpbb/phpbb/mention/source/friend.php
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
<?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\mention\source;
|
||||||
|
|
||||||
|
class friend extends user
|
||||||
|
{
|
||||||
|
/** @var \phpbb\db\driver\driver_interface */
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
/** @var \phpbb\user */
|
||||||
|
protected $user;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\db\driver\driver_interface $db, \phpbb\user $user)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
$this->user = $user;
|
||||||
|
|
||||||
|
parent::__construct($db);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function query($keyword, $topic_id)
|
||||||
|
{
|
||||||
|
$query = $this->db->sql_build_query('SELECT', [
|
||||||
|
'SELECT' => 'u.username, u.user_id',
|
||||||
|
'FROM' => [
|
||||||
|
USERS_TABLE => 'u',
|
||||||
|
],
|
||||||
|
'LEFT_JOIN' => [
|
||||||
|
[
|
||||||
|
'FROM' => [ZEBRA_TABLE => 'z'],
|
||||||
|
'ON' => 'u.user_id = z.zebra_id'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'WHERE' => 'z.friend = 1 AND z.user_id = ' . (int) $this->user->data['user_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' => 'u.user_lastvisit DESC'
|
||||||
|
]);
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,26 +11,11 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpbb\mention\method;
|
namespace phpbb\mention\source;
|
||||||
|
|
||||||
class topic
|
class topic extends user
|
||||||
{
|
{
|
||||||
/** @var \phpbb\db\driver\driver_interface */
|
protected function query($keyword, $topic_id)
|
||||||
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', [
|
$query = $this->db->sql_build_query('SELECT', [
|
||||||
'SELECT' => 'u.username, u.user_id',
|
'SELECT' => 'u.username, u.user_id',
|
||||||
|
@ -38,16 +23,16 @@ class topic
|
||||||
USERS_TABLE => 'u',
|
USERS_TABLE => 'u',
|
||||||
],
|
],
|
||||||
'LEFT_JOIN' => [
|
'LEFT_JOIN' => [
|
||||||
|
[
|
||||||
'FROM' => [POSTS_TABLE => 'p'],
|
'FROM' => [POSTS_TABLE => 'p'],
|
||||||
'ON' => 'u.user_id = p.poster_id'
|
'ON' => 'u.user_id = p.poster_id'
|
||||||
|
]
|
||||||
],
|
],
|
||||||
'WHERE' => 'p.topic_id = ' . $topic_id . ' AND u.user_id <> ' . ANONYMOUS . '
|
'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 ' . $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()),
|
AND u.username_clean ' . $this->db->sql_like_expression($keyword . $this->db->get_any_char()),
|
||||||
'ORDER_BY' => 'p.post_time DESC'
|
'ORDER_BY' => 'p.post_time DESC'
|
||||||
]);
|
]);
|
||||||
$res = $this->db->sql_query_limit($query, 5);
|
return $query;
|
||||||
|
|
||||||
return $this->db->sql_fetchrowset($res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
44
phpbb/phpbb/mention/source/user.php
Normal file
44
phpbb/phpbb/mention/source/user.php
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?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\mention\source;
|
||||||
|
|
||||||
|
abstract class user
|
||||||
|
{
|
||||||
|
/** @var \phpbb\db\driver\driver_interface */
|
||||||
|
protected $db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct(\phpbb\db\driver\driver_interface $db)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected function query($keyword, $topic_id);
|
||||||
|
|
||||||
|
public function get($keyword, $topic_id)
|
||||||
|
{
|
||||||
|
$keyword = utf8_clean_string($keyword);
|
||||||
|
$res = $this->db->sql_query_limit($this->query($keyword, $topic_id), 5);
|
||||||
|
|
||||||
|
$names = [];
|
||||||
|
while ($row = $this->db->sql_fetchrow($res))
|
||||||
|
{
|
||||||
|
$names['u' . $row['user_id']] = $row['username'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $names;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue