-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathviewonline_helper.php
98 lines (88 loc) · 2.36 KB
/
viewonline_helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?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;
use phpbb\filesystem\helper as filesystem_helper;
/**
* Class to handle viewonline related tasks
*/
class viewonline_helper
{
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/**
* @param \phpbb\db\driver\driver_interface $db
*/
public function __construct(\phpbb\db\driver\driver_interface $db)
{
$this->db = $db;
}
/**
* 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);
if (strpos($session_page, './') === 0)
{
$session_page = substr($session_page, 2);
}
preg_match('#^((\.\./)*([a-z0-9/_-]+))#i', $session_page, $on_page);
if (empty($on_page))
{
$on_page[1] = '';
}
return $on_page;
}
}