1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-01 14:30:32 +02:00

Merge branch 'ticket/17107' into ticket/17107-master

This commit is contained in:
rxu
2023-06-14 21:23:14 +07:00
5 changed files with 181 additions and 13 deletions

View File

@@ -67,3 +67,5 @@ services:
viewonline_helper:
class: phpbb\viewonline_helper
arguments:
- '@dbal.conn'

View File

@@ -16,23 +16,69 @@ namespace phpbb;
use phpbb\filesystem\helper as filesystem_helper;
/**
* Class to handle viewonline related tasks
*/
* Class to handle viewonline related tasks
*/
class viewonline_helper
{
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/**
*
*/
public function __construct()
* @param \phpbb\db\driver\driver_interface $db
*/
public function __construct(\phpbb\db\driver\driver_interface $db)
{
$this->db = $db;
}
/**
* Get user page
*
* @param string $session_page User's session page
* @return array Match array filled by preg_match()
*/
* Get forum IDs for topics
*
* Retrieve forum IDs and add the data into the session data array
* Array structure matches sql_fethrowset() result array
*
* @param array $session_data_rowset Users' session data array
* @return void
*/
public function get_forum_ids(array &$session_data_rowset): void
{
$topic_ids = $match = [];
foreach ($session_data_rowset as $number => $row)
{
if ($row['session_forum_id'] == 0 && preg_match('#t=([0-9]+)#', $row['session_page'], $match))
{
$topic_ids[$number] = (int) $match[1];
}
}
if (count($topic_ids = array_unique($topic_ids)))
{
$sql_ary = [
'SELECT' => 't.topic_id, t.forum_id',
'FROM' => [
TOPICS_TABLE => 't',
],
'WHERE' => $this->db->sql_in_set('t.topic_id', $topic_ids),
'ORDER_BY' => 't.topic_id',
];
$result = $this->db->sql_query($this->db->sql_build_query('SELECT', $sql_ary));
$forum_ids_rowset = $this->db->sql_fetchrowset($result);
$this->db->sql_freeresult($result);
foreach ($forum_ids_rowset as $forum_ids_row)
{
$session_data_row_number = array_search((int) $forum_ids_row['topic_id'], $topic_ids);
$session_data_rowset[$session_data_row_number]['session_forum_id'] = (int) $forum_ids_row['forum_id'];
}
}
}
/**
* Get user page
*
* @param string $session_page User's session page
* @return array Match array filled by preg_match()
*/
public function get_user_page($session_page)
{
$session_page = filesystem_helper::clean_path($session_page);

View File

@@ -180,6 +180,8 @@ $vars = array('sql_ary', 'show_guests', 'guest_counter', 'forum_data');
extract($phpbb_dispatcher->trigger_event('core.viewonline_modify_sql', compact($vars)));
$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
$session_data_rowset = $db->sql_fetchrowset($result);
$db->sql_freeresult($result);
$prev_id = $prev_ip = $user_list = array();
$logged_visible_online = $logged_hidden_online = $counter = 0;
@@ -190,7 +192,10 @@ $controller_helper = $phpbb_container->get('controller.helper');
/** @var \phpbb\group\helper $group_helper */
$group_helper = $phpbb_container->get('group_helper');
while ($row = $db->sql_fetchrow($result))
// Get forum IDs for session pages which have only 't' parameter
$viewonline_helper->get_forum_ids($session_data_rowset);
foreach ($session_data_rowset as $row)
{
if ($row['user_id'] != ANONYMOUS && !isset($prev_id[$row['user_id']]))
{
@@ -438,7 +443,6 @@ while ($row = $db->sql_fetchrow($result))
$template->assign_block_vars('user_row', $template_row);
}
$db->sql_freeresult($result);
unset($prev_id, $prev_ip);
$group_helper->display_legend($db, $template);