From aa3472ce76c8bc14b3b67cfe6fb38c9caff25c24 Mon Sep 17 00:00:00 2001 From: v12mike Date: Tue, 28 Jul 2020 19:10:07 -0400 Subject: [PATCH 1/5] [ticket/16558] Improve viewonline page Pages that are not handled by viewonline now shown as "Unrecognised Page" Admins see the URI of session table page PHPBB3-16558 --- phpBB/language/en/common.php | 1 + phpBB/viewonline.php | 65 +++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/phpBB/language/en/common.php b/phpBB/language/en/common.php index 44c37c26fb..34c688ff24 100644 --- a/phpBB/language/en/common.php +++ b/phpBB/language/en/common.php @@ -835,6 +835,7 @@ $lang = array_merge($lang, array( 'UNREAD_MESSAGES' => 'Unread messages', 'UNREAD_POST' => 'Unread post', 'UNREAD_POSTS' => 'Unread posts', + 'UNRECOGNISED_PAGE' => 'Unrecognised page', 'UNWATCH_FORUM_CONFIRM' => 'Are you sure you wish to unsubscribe from this forum?', 'UNWATCH_FORUM_DETAILED' => 'Are you sure you wish to unsubscribe from the forum ā€œ%sā€?', 'UNWATCH_TOPIC_CONFIRM' => 'Are you sure you wish to unsubscribe from this topic?', diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 1b28750a0b..e5affc8e2f 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -263,6 +263,55 @@ while ($row = $db->sql_fetchrow($result)) case 'viewtopic': $forum_id = $row['session_forum_id']; + if (!$forum_id) + { + $array_match_index = 5; + // find the forum_id from the page URI + $matches = array(); + + $pattern = '#(viewtopic|posting)\.' . $phpEx . '((\?|&)\w+=\w+)*(\?|&)'; + preg_match($pattern . 'f=(\d+)#', $row['session_page'], $matches, PREG_UNMATCHED_AS_NULL); + if ($matches[$array_match_index]) + { + $forum_id = (int) $matches[$array_match_index]; + } + else + { + preg_match($pattern . 't=(\d+)#', $row['session_page'], $matches, PREG_UNMATCHED_AS_NULL); + if ($matches[$array_match_index]) + { + $topic_id = $matches[$array_match_index]; + + $sql = 'SELECT forum_id + FROM ' . TOPICS_TABLE . " + WHERE topic_id = $topic_id"; + $db->sql_query($sql); + $forum_id = (int) $db->sql_fetchfield('forum_id'); + } + else + { + preg_match($pattern . 'p=(\d+)#', $row['session_page'], $matches, PREG_UNMATCHED_AS_NULL); + if ($matches[$array_match_index]) + { + $post_id = $matches[$array_match_index]; + + $topic_forum = array(); + + $sql = 'SELECT t.forum_id + FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p + WHERE p.post_id = ' . $post_id . ' + AND t.topic_id = p.topic_id'; + $db->sql_query($sql); + $forum_id = (int) $db->sql_fetchfield('forum_id'); + } + else + { + $forum_id = 0; + } + } + } + } + if ($forum_id && $auth->acl_get('f_list', $forum_id)) { $location = ''; @@ -304,7 +353,7 @@ while ($row = $db->sql_fetchrow($result)) } else { - $location = $user->lang['INDEX']; + $location = $user->lang['UNRECOGNISED_PAGE']; $location_url = append_sid("{$phpbb_root_path}index.$phpEx"); } break; @@ -377,17 +426,23 @@ while ($row = $db->sql_fetchrow($result)) break; default: - $location = $user->lang['INDEX']; - $location_url = append_sid("{$phpbb_root_path}index.$phpEx"); - if ($row['session_page'] === 'app.' . $phpEx . '/help/faq' || $row['session_page'] === 'app.' . $phpEx . '/help/bbcode') { $location = $user->lang['VIEWING_FAQ']; $location_url = $controller_helper->route('phpbb_help_faq_controller'); } + else + { + $location = $user->lang['UNRECOGNISED_PAGE']; + $location_url = append_sid("{$phpbb_root_path}index.$phpEx"); + } break; } + if ($auth->acl_get('a_')) + { + $location .= '
' . substr($row['session_page'], 0, 99); + } /** * Overwrite the location's name and URL, which are displayed in the list @@ -405,7 +460,7 @@ while ($row = $db->sql_fetchrow($result)) extract($phpbb_dispatcher->trigger_event('core.viewonline_overwrite_location', compact($vars))); $template_row = array( - 'USERNAME' => $row['username'], + 'USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'USERNAME_FULL' => $username_full, 'LASTUPDATE' => $user->format_date($row['session_time']), From 9f682ea220e59692dc94907888c2046991729038 Mon Sep 17 00:00:00 2001 From: v12mike Date: Tue, 28 Jul 2020 23:54:57 -0400 Subject: [PATCH 2/5] [ticket/16558] Improve viewonline page Remove unsupport PHP syntax PHPBB3-16558 --- phpBB/viewonline.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index e5affc8e2f..1596cab26c 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -270,14 +270,14 @@ while ($row = $db->sql_fetchrow($result)) $matches = array(); $pattern = '#(viewtopic|posting)\.' . $phpEx . '((\?|&)\w+=\w+)*(\?|&)'; - preg_match($pattern . 'f=(\d+)#', $row['session_page'], $matches, PREG_UNMATCHED_AS_NULL); + preg_match($pattern . 'f=(\d+)#', $row['session_page'], $matches); if ($matches[$array_match_index]) { $forum_id = (int) $matches[$array_match_index]; } else { - preg_match($pattern . 't=(\d+)#', $row['session_page'], $matches, PREG_UNMATCHED_AS_NULL); + preg_match($pattern . 't=(\d+)#', $row['session_page'], $matches); if ($matches[$array_match_index]) { $topic_id = $matches[$array_match_index]; @@ -290,7 +290,7 @@ while ($row = $db->sql_fetchrow($result)) } else { - preg_match($pattern . 'p=(\d+)#', $row['session_page'], $matches, PREG_UNMATCHED_AS_NULL); + preg_match($pattern . 'p=(\d+)#', $row['session_page'], $matches); if ($matches[$array_match_index]) { $post_id = $matches[$array_match_index]; From 8d0c38383cb733aa93efec475d2ae54c81a0570d Mon Sep 17 00:00:00 2001 From: v12mike Date: Wed, 29 Jul 2020 00:05:36 -0400 Subject: [PATCH 3/5] [ticket/16558] Improve viewonline page Fix memory leak PHPBB3-16558 --- phpBB/viewonline.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 1596cab26c..1e57b9b6b4 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -285,8 +285,9 @@ while ($row = $db->sql_fetchrow($result)) $sql = 'SELECT forum_id FROM ' . TOPICS_TABLE . " WHERE topic_id = $topic_id"; - $db->sql_query($sql); + $result = $db->sql_query($sql); $forum_id = (int) $db->sql_fetchfield('forum_id'); + $db->sql_freeresult($result); } else { @@ -301,8 +302,9 @@ while ($row = $db->sql_fetchrow($result)) FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE p.post_id = ' . $post_id . ' AND t.topic_id = p.topic_id'; - $db->sql_query($sql); + $result = $db->sql_query($sql); $forum_id = (int) $db->sql_fetchfield('forum_id'); + $db->sql_freeresult($result); } else { From 4761fef7a8168644e70f9ddb1b105516e47b1af2 Mon Sep 17 00:00:00 2001 From: v12mike Date: Wed, 29 Jul 2020 01:43:14 -0400 Subject: [PATCH 4/5] [ticket/16558] Improve viewonline page Fix overload of variables PHPBB3-16558 --- phpBB/viewonline.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 1e57b9b6b4..4022522da2 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -285,9 +285,9 @@ while ($row = $db->sql_fetchrow($result)) $sql = 'SELECT forum_id FROM ' . TOPICS_TABLE . " WHERE topic_id = $topic_id"; - $result = $db->sql_query($sql); + $result1 = $db->sql_query($sql); $forum_id = (int) $db->sql_fetchfield('forum_id'); - $db->sql_freeresult($result); + $db->sql_freeresult($result1); } else { @@ -302,9 +302,9 @@ while ($row = $db->sql_fetchrow($result)) FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . ' p WHERE p.post_id = ' . $post_id . ' AND t.topic_id = p.topic_id'; - $result = $db->sql_query($sql); + $result1 = $db->sql_query($sql); $forum_id = (int) $db->sql_fetchfield('forum_id'); - $db->sql_freeresult($result); + $db->sql_freeresult($result1); } else { From 17c64bada3f772c48fbfa4a1eda4c077e03de131 Mon Sep 17 00:00:00 2001 From: v12mike Date: Fri, 22 Oct 2021 13:48:24 +1300 Subject: [PATCH 5/5] Update viewonline.php remove html from php file --- phpBB/viewonline.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/viewonline.php b/phpBB/viewonline.php index 4022522da2..d88ab490de 100644 --- a/phpBB/viewonline.php +++ b/phpBB/viewonline.php @@ -443,7 +443,7 @@ while ($row = $db->sql_fetchrow($result)) } if ($auth->acl_get('a_')) { - $location .= '
' . substr($row['session_page'], 0, 99); + $location .= nl2br("\n" . substr($row['session_page'], 0, 99)); } /**