diff --git a/phpBB/config/default/container/services_notification.yml b/phpBB/config/default/container/services_notification.yml
index b3ff08586dd..0768686e6c7 100644
--- a/phpBB/config/default/container/services_notification.yml
+++ b/phpBB/config/default/container/services_notification.yml
@@ -260,3 +260,35 @@ services:
- '@request'
- '@user'
- '%core.root_path%'
+
+ notification.controller.mark_all_read:
+ class: phpbb\notification\controller\mark_all_read
+ arguments:
+ - '@config'
+ - '@language'
+ - '@request'
+ - '@user'
+ - '%core.root_path%'
+ - '%core.php_ext%'
+
+ notification.controller.mark_subforums_read:
+ class: phpbb\notification\controller\mark_subforums_read
+ arguments:
+ - '@auth'
+ - '@config'
+ - '@language'
+ - '@request'
+ - '@user'
+ - '%core.root_path%'
+ - '%core.php_ext%'
+
+
+ notification.controller.mark_topics_read:
+ class: phpbb\notification\controller\mark_topics_read
+ arguments:
+ - '@config'
+ - '@language'
+ - '@request'
+ - '@user'
+ - '%core.root_path%'
+ - '%core.php_ext%'
diff --git a/phpBB/config/default/routing/notifications.yml b/phpBB/config/default/routing/notifications.yml
index 4a0f3d56ad4..0311ae49b81 100644
--- a/phpBB/config/default/routing/notifications.yml
+++ b/phpBB/config/default/routing/notifications.yml
@@ -4,3 +4,24 @@ phpbb_notifications_mark_read:
_controller: notification.controller.mark_read:handle
requirements:
id: \d+
+
+phpbb_notifications_mark_all_read:
+ path: /mark-all-read
+ defaults:
+ _controller: notification.controller.mark_all_read:handle
+
+
+phpbb_notifications_mark_subforums_read:
+ path: /mark-subforums-read/{id}
+ defaults:
+ _controller: notification.controller.mark_subforums_read:handle
+ requirements:
+ id: \d+
+
+
+phpbb_notifications_mark_topics_read:
+ path: /mark-topics-read/{id}
+ defaults:
+ _controller: notification.controller.mark_topics_read:handle
+ requirements:
+ id: \d+
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 188f98d7e99..3ff8756b028 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -539,8 +539,8 @@ function phpbb_timezone_select($user, $default = '', $truncate = false)
* Marks a topic as posted to
*
* @param string $mode (all, topics, topic, post)
-* @param int|bool $forum_id Used in all, topics, and topic mode
-* @param int|bool $topic_id Used in topic and post mode
+* @param array|int|false $forum_id Used in all, topics, and topic mode
+* @param int|false $topic_id Used in topic and post mode
* @param int $post_time 0 means current time(), otherwise to set a specific mark time
* @param int $user_id can only be used with $mode == 'post'
*/
@@ -4230,3 +4230,129 @@ function phpbb_get_board_contact_link(\phpbb\config\config $config, $phpbb_root_
return 'mailto:' . htmlspecialchars($config['board_contact'], ENT_COMPAT);
}
}
+
+/**
+ * Get forum rows
+ *
+ * @param $root_data
+ * @return array|false|mixed
+ */
+function get_forums_rows($root_data)
+{
+ global $db, $config, $user, $phpbb_dispatcher;
+
+ if (!$root_data)
+ {
+ $sql_where = '';
+ }
+ else
+ {
+ $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
+ }
+
+ // Display list of active topics for this category?
+ $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
+
+ $sql_array = array(
+ 'SELECT' => 'f.*',
+ 'FROM' => array(
+ FORUMS_TABLE => 'f'
+ ),
+ 'LEFT_JOIN' => array(),
+ );
+
+ if ($config['load_db_lastread'] && $user->data['is_registered'])
+ {
+ $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id');
+ $sql_array['SELECT'] .= ', ft.mark_time';
+ }
+
+ if ($show_active)
+ {
+ $sql_array['LEFT_JOIN'][] = array(
+ 'FROM' => array(FORUMS_ACCESS_TABLE => 'fa'),
+ 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
+ );
+
+ $sql_array['SELECT'] .= ', fa.user_id';
+ }
+
+ $sql_ary = array(
+ 'SELECT' => $sql_array['SELECT'],
+ 'FROM' => $sql_array['FROM'],
+ 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
+
+ 'WHERE' => $sql_where,
+
+ 'ORDER_BY' => 'f.left_id',
+ );
+
+ /**
+ * Event to modify the SQL query before the forum data is queried
+ *
+ * @event core.display_forums_modify_sql
+ * @var array sql_ary The SQL array to get the data of the forums
+ * @since 3.1.0-a1
+ */
+ $vars = array('sql_ary');
+ extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars)));
+
+ $sql = $db->sql_build_query('SELECT', $sql_ary);
+ $result = $db->sql_query($sql);
+ $data = $db->sql_fetchrowset($result);
+ $db->sql_freeresult($result);
+
+ return $data;
+}
+
+/**
+ * Get forum data
+ *
+ * @param int $forum_id
+ * @return array|false
+ */
+function get_forum_data($forum_id)
+{
+ global $user, $config, $phpbb_dispatcher, $db;
+
+ $sql_ary = [
+ 'SELECT' => 'f.*',
+ 'FROM' => [
+ FORUMS_TABLE => 'f',
+ ],
+ 'WHERE' => 'f.forum_id = ' . $forum_id,
+ ];
+
+ // Grab appropriate forum data
+ if ($config['load_db_lastread'] && $user->data['is_registered'])
+ {
+ $sql_ary['LEFT_JOIN'][] = [
+ 'FROM' => [FORUMS_TRACK_TABLE => 'ft'],
+ 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id',
+ ];
+ $sql_ary['SELECT'] .= ', ft.mark_time';
+ }
+
+ if ($user->data['is_registered'])
+ {
+ $sql_ary['LEFT_JOIN'][] = [
+ 'FROM' => [FORUMS_WATCH_TABLE => 'fw'],
+ 'ON' => 'fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'],
+ ];
+ $sql_ary['SELECT'] .= ', fw.notify_status';
+ }
+
+ /**
+ * You can use this event to modify the sql that selects the forum on the viewforum page.
+ *
+ * @event core.viewforum_modify_sql
+ * @var array sql_ary The SQL array to get the data for a forum
+ * @since 3.3.14-RC1
+ */
+ $vars = ['sql_ary'];
+ extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_sql', compact($vars)));
+ $result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
+ $forum_data = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+ return $forum_data;
+}
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php
index 860bb8d89ab..df4603c1100 100644
--- a/phpBB/includes/functions_display.php
+++ b/phpBB/includes/functions_display.php
@@ -22,89 +22,32 @@
/**
* Display Forums
*/
-function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
+function display_forums($root_data = '', $return_moderators = false)
{
- global $db, $auth, $user, $template;
+ global $auth, $user, $template, $request;
global $phpbb_root_path, $phpEx, $config;
- global $request, $phpbb_dispatcher, $phpbb_container;
+ global $phpbb_dispatcher, $phpbb_container;
- $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
+ /** @var \phpbb\controller\helper */
+ $controller_helper = $phpbb_container->get('controller.helper');
+
+ $forum_rows = $subforums = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
$parent_id = $visible_forums = 0;
$parent_subforum_limit = false;
- // Mark forums read?
- $mark_read = $request->variable('mark', '');
-
- if ($mark_read == 'all')
- {
- $mark_read = '';
- }
+ $rows = get_forums_rows($root_data);
if (!$root_data)
{
- if ($mark_read == 'forums')
- {
- $mark_read = 'all';
- }
-
$root_data = array('forum_id' => 0);
- $sql_where = '';
- }
- else
- {
- $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
- }
-
- // Handle marking everything read
- if ($mark_read == 'all')
- {
- $redirect = build_url(array('mark', 'hash', 'mark_time'));
- meta_refresh(3, $redirect);
-
- if (check_link_hash($request->variable('hash', ''), 'global'))
- {
- markread('all', false, false, $request->variable('mark_time', 0));
-
- if ($request->is_ajax())
- {
- // Tell the ajax script what language vars and URL need to be replaced
- $data = array(
- 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'],
- 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'],
- 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time(), false) : '',
- 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
- 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']
- );
- $json_response = new \phpbb\json_response();
- $json_response->send($data);
- }
-
- trigger_error(
- $user->lang['FORUMS_MARKED'] . '
' .
- sprintf($user->lang['RETURN_INDEX'], '', '')
- );
- }
- else
- {
- trigger_error(sprintf($user->lang['RETURN_PAGE'], '', ''));
- }
}
// Display list of active topics for this category?
$show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
- $sql_array = array(
- 'SELECT' => 'f.*',
- 'FROM' => array(
- FORUMS_TABLE => 'f'
- ),
- 'LEFT_JOIN' => array(),
- );
-
if ($config['load_db_lastread'] && $user->data['is_registered'])
{
- $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id');
- $sql_array['SELECT'] .= ', ft.mark_time';
+
}
else if ($config['load_anon_lastread'] || $user->data['is_registered'])
{
@@ -117,46 +60,13 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
}
}
- if ($show_active)
- {
- $sql_array['LEFT_JOIN'][] = array(
- 'FROM' => array(FORUMS_ACCESS_TABLE => 'fa'),
- 'ON' => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
- );
-
- $sql_array['SELECT'] .= ', fa.user_id';
- }
-
- $sql_ary = array(
- 'SELECT' => $sql_array['SELECT'],
- 'FROM' => $sql_array['FROM'],
- 'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
-
- 'WHERE' => $sql_where,
-
- 'ORDER_BY' => 'f.left_id',
- );
-
- /**
- * Event to modify the SQL query before the forum data is queried
- *
- * @event core.display_forums_modify_sql
- * @var array sql_ary The SQL array to get the data of the forums
- * @since 3.1.0-a1
- */
- $vars = array('sql_ary');
- extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars)));
-
- $sql = $db->sql_build_query('SELECT', $sql_ary);
- $result = $db->sql_query($sql);
-
$forum_tracking_info = $valid_categories = array();
$branch_root_id = $root_data['forum_id'];
/* @var $phpbb_content_visibility \phpbb\content_visibility */
$phpbb_content_visibility = $phpbb_container->get('content.visibility');
- while ($row = $db->sql_fetchrow($result))
+ foreach ($rows as $row)
{
/**
* Event to modify the data set of a forum
@@ -173,17 +83,6 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
$forum_id = $row['forum_id'];
- // Mark forums read?
- if ($mark_read == 'forums')
- {
- if ($auth->acl_get('f_list', $forum_id))
- {
- $forum_ids[] = $forum_id;
- }
-
- continue;
- }
-
// Category with no members
if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
{
@@ -338,46 +237,9 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
$vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row');
extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars)));
}
- $db->sql_freeresult($result);
-
- // Handle marking posts
- if ($mark_read == 'forums')
- {
- $redirect = build_url(array('mark', 'hash', 'mark_time'));
- $token = $request->variable('hash', '');
- if (check_link_hash($token, 'global'))
- {
- markread('topics', $forum_ids, false, $request->variable('mark_time', 0));
- $message = sprintf($user->lang['RETURN_FORUM'], '', '');
- meta_refresh(3, $redirect);
-
- if ($request->is_ajax())
- {
- // Tell the ajax script what language vars and URL need to be replaced
- $data = array(
- 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'],
- 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'],
- 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time(), false) : '',
- 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
- 'MESSAGE_TEXT' => $user->lang['FORUMS_MARKED']
- );
- $json_response = new \phpbb\json_response();
- $json_response->send($data);
- }
-
- trigger_error($user->lang['FORUMS_MARKED'] . '
' . $message);
- }
- else
- {
- $message = sprintf($user->lang['RETURN_PAGE'], '', '');
- meta_refresh(3, $redirect);
- trigger_error($message);
- }
-
- }
// Grab moderators ... if necessary
- if ($display_moderators)
+ if ($config['load_moderators'])
{
if ($return_moderators)
{
@@ -386,6 +248,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
get_moderators($forum_moderators, $forum_ids_moderator);
}
+ $display_moderators = $config['load_moderators'];
+
/**
* Event to perform additional actions before the forum list is being generated
*
@@ -560,7 +424,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
// Output moderator listing ... if applicable
$l_moderator = $moderators_list = '';
- if ($display_moderators && !empty($forum_moderators[$forum_id]))
+ if ($config['load_moderators'] && !empty($forum_moderators[$forum_id]))
{
$l_moderator = (count($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
$moderators_list = implode($user->lang['COMMA_SEPARATOR'], $forum_moderators[$forum_id]);
@@ -691,7 +555,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
}
$template->assign_vars(array(
- 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&f=' . $root_data['forum_id'] . '&mark=forums&mark_time=' . time()) : '',
+ 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? $controller_helper->route('phpbb_notifications_mark_subforums_read', ['id' => $root_data['forum_id'], 'hash' => generate_link_hash('global'), 'mark_time' => time()]) : '',
'S_HAS_SUBFORUM' => ($visible_forums) ? true : false,
'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
@@ -699,6 +563,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod
'UNAPPROVED_POST_IMG' => $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED_FORUM'),
));
+ $display_moderators = $config['load_moderators'];
+
/**
* Event to perform additional actions after the forum list has been generated
*
diff --git a/phpBB/index.php b/phpBB/index.php
index 4353264b213..696a80182d0 100644
--- a/phpBB/index.php
+++ b/phpBB/index.php
@@ -25,7 +25,7 @@
$auth->acl($user->data);
$user->setup('viewforum');
-display_forums('', $config['load_moderators']);
+display_forums('');
/** @var \phpbb\group\helper $group_helper */
$group_helper = $phpbb_container->get('group_helper');
@@ -126,7 +126,7 @@
'S_INDEX' => true,
'U_CANONICAL' => generate_board_url() . '/',
- 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&mark=forums&mark_time=' . time()) : '',
+ 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? $controller_helper->route('phpbb_notifications_mark_all_read', ['hash' => generate_link_hash('global'), 'mark_time' => time()]) : '',
'U_MCP' => ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&mode=front') : '')
);
diff --git a/phpBB/phpbb/notification/controller/mark_all_read.php b/phpBB/phpbb/notification/controller/mark_all_read.php
new file mode 100644
index 00000000000..23c34f074d4
--- /dev/null
+++ b/phpBB/phpbb/notification/controller/mark_all_read.php
@@ -0,0 +1,105 @@
+
+ * @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\notification\controller;
+
+use phpbb\config\config;
+use phpbb\language\language;
+use phpbb\request\request;
+use phpbb\user;
+use Symfony\Component\HttpFoundation\JsonResponse;
+
+class mark_all_read
+{
+ /** @var config */
+ protected $config;
+
+ /** @var language */
+ protected $language;
+
+ /** @var request */
+ protected $request;
+
+ /** @var user */
+ protected $user;
+
+ /** @var string */
+ protected $phpbb_root_path;
+
+ /** @var string */
+ protected $php_ext;
+
+ /**
+ * Constructor
+ *
+ * @param config $config
+ * @param language $language
+ * @param request $request
+ * @param user $user
+ * @param string $phpbb_root_path
+ * @param string $php_ext
+ */
+ public function __construct(config $config, language $language, request $request, user $user, string $phpbb_root_path, string $php_ext)
+ {
+ $this->config = $config;
+ $this->language = $language;
+ $this->request = $request;
+ $this->user = $user;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+ }
+
+ /**
+ * Handle marking everything read
+ *
+ * @return void|JsonResponse
+ */
+ public function handle()
+ {
+ global $phpbb_container;
+
+ /* @var \phpbb\controller\helper $controller_helper */
+ $controller_helper = $phpbb_container->get('controller.helper');
+
+ // Handle marking everything read
+ $redirect = build_url(['mark', 'hash', 'mark_time']); // todo: redirect to previous page (index.php) (is this redirection doing something?)
+ meta_refresh(3, $redirect);
+
+ if (check_link_hash($this->request->variable('hash', ''), 'global'))
+ {
+ markread('all', false, false, $this->request->variable('mark_time', 0));
+
+ if ($this->request->is_ajax())
+ {
+ // Tell the ajax script what language vars and URL need to be replaced
+ $data = [
+ 'NO_UNREAD_POSTS' => $this->language->lang('NO_UNREAD_POSTS'),
+ 'UNREAD_POSTS' => $this->language->lang('UNREAD_POSTS'),
+ 'U_MARK_FORUMS' => ($this->user->data['is_registered'] || $this->config['load_anon_lastread']) ? $controller_helper->route('phpbb_notifications_mark_all_read', ['hash' => generate_link_hash('global'), 'mark_time' => time()]) : '',
+ 'MESSAGE_TITLE' => $this->language->lang('INFORMATION'),
+ 'MESSAGE_TEXT' => $this->language->lang('FORUMS_MARKED')
+ ];
+ return new JsonResponse($data);
+ }
+
+ trigger_error(
+ $this->language->lang('FORUMS_MARKED') . '
' .
+ sprintf($this->language->lang('RETURN_INDEX'), '', '')
+ );
+ }
+ else
+ {
+ trigger_error(sprintf($this->language->lang('RETURN_PAGE'), '', ''));
+ }
+ }
+}
diff --git a/phpBB/phpbb/notification/controller/mark_subforums_read.php b/phpBB/phpbb/notification/controller/mark_subforums_read.php
new file mode 100644
index 00000000000..b44e7e40cf1
--- /dev/null
+++ b/phpBB/phpbb/notification/controller/mark_subforums_read.php
@@ -0,0 +1,131 @@
+
+ * @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\notification\controller;
+
+use phpbb\auth\auth;
+use phpbb\config\config;
+use phpbb\language\language;
+use phpbb\request\request;
+use phpbb\user;
+use Symfony\Component\HttpFoundation\JsonResponse;
+
+class mark_subforums_read
+{
+ /** @var auth */
+ protected $auth;
+
+ /** @var config */
+ protected $config;
+
+ /** @var language */
+ protected $language;
+
+ /** @var request */
+ protected $request;
+
+ /** @var user */
+ protected $user;
+
+ /** @var string */
+ protected $phpbb_root_path;
+
+ /** @var string */
+ protected $php_ext;
+
+ /**
+ * Constructor
+ *
+ * @param auth $auth
+ * @param config $config
+ * @param language $language
+ * @param request $request
+ * @param user $user
+ * @param string $phpbb_root_path
+ * @param string $php_ext
+ */
+ public function __construct(auth $auth, config $config, language $language, request $request, user $user, string $phpbb_root_path, string $php_ext)
+ {
+ $this->auth = $auth;
+ $this->config = $config;
+ $this->language = $language;
+ $this->request = $request;
+ $this->user = $user;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+ }
+
+ /**
+ * Handle marking forums read
+ *
+ * @param int $id Forum ID
+ * @return void|JsonResponse
+ */
+ public function handle(int $id)
+ {
+ global $phpbb_container;
+
+ /** @var \phpbb\controller\helper $controller_helper */
+ $controller_helper = $phpbb_container->get('controller.helper');
+
+ $root_data = get_forum_data($id);
+
+ if (!$root_data)
+ {
+ trigger_error('NO_FORUM');
+ }
+
+ $rows = get_forums_rows($root_data);
+
+ $forum_ids = [];
+ foreach ($rows as $row)
+ {
+ $forum_id = $row['forum_id'];
+
+ if ($this->auth->acl_get('f_list', $forum_id))
+ {
+ $forum_ids[] = $forum_id;
+ }
+ }
+
+ $redirect = build_url(['mark', 'hash', 'mark_time']);
+ $token = $this->request->variable('hash', '');
+ if (check_link_hash($token, 'global'))
+ {
+ markread('topics', $forum_ids, false, $this->request->variable('mark_time', 0));
+ $message = sprintf($this->language->lang('RETURN_FORUM'), '', '');
+ meta_refresh(3, $redirect);
+
+ if ($this->request->is_ajax())
+ {
+ // Tell the ajax script what language vars and URL need to be replaced
+ $data = [
+ 'NO_UNREAD_POSTS' => $this->language->lang('NO_UNREAD_POSTS'),
+ 'UNREAD_POSTS' => $this->language->lang('UNREAD_POSTS'),
+ 'U_MARK_FORUMS' => ($this->user->data['is_registered'] || $this->config['load_anon_lastread']) ? $controller_helper->route('phpbb_notifications_mark_subforums_read', ['id' => $root_data['forum_id'], 'hash' => generate_link_hash('global'), 'mark_time' => time()]) : '',
+ 'MESSAGE_TITLE' => $this->language->lang('INFORMATION'),
+ 'MESSAGE_TEXT' => $this->language->lang('FORUMS_MARKED')
+ ];
+ return new JsonResponse($data);
+ }
+
+ trigger_error($this->language->lang('FORUMS_MARKED') . '
' . $message);
+ }
+ else
+ {
+ $message = sprintf($this->language->lang('RETURN_PAGE'), '', '');
+ meta_refresh(3, $redirect);
+ trigger_error($message);
+ }
+ }
+}
diff --git a/phpBB/phpbb/notification/controller/mark_topics_read.php b/phpBB/phpbb/notification/controller/mark_topics_read.php
new file mode 100644
index 00000000000..d41011f996b
--- /dev/null
+++ b/phpBB/phpbb/notification/controller/mark_topics_read.php
@@ -0,0 +1,101 @@
+
+ * @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\notification\controller;
+
+use phpbb\config\config;
+use phpbb\language\language;
+use phpbb\request\request;
+use phpbb\user;
+use Symfony\Component\HttpFoundation\JsonResponse;
+
+class mark_topics_read
+{
+ /** @var config */
+ protected $config;
+
+ /** @var language */
+ protected $language;
+
+ /** @var request */
+ protected $request;
+
+ /** @var user */
+ protected $user;
+
+ /** @var string */
+ protected $phpbb_root_path;
+
+ /** @var string */
+ protected $php_ext;
+
+ /**
+ * Constructor
+ *
+ * @param config $config
+ * @param language $language
+ * @param request $request
+ * @param user $user
+ * @param string $phpbb_root_path
+ * @param string $php_ext
+ */
+ public function __construct(config $config, language $language, request $request, user $user, string $phpbb_root_path, string $php_ext)
+ {
+ $this->config = $config;
+ $this->language = $language;
+ $this->request = $request;
+ $this->user = $user;
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->php_ext = $php_ext;
+ }
+
+ /**
+ * Handle marking topics read
+ *
+ * @param int $id Forum ID
+ * @return void|JsonResponse
+ */
+ public function handle(int $id)
+ {
+ global $phpbb_container;
+
+ /** @var \phpbb\controller\helper $controller_helper */
+ $controller_helper = $phpbb_container->get('controller.helper');
+
+ $forum_id = $id;
+
+ // Handle marking posts
+ $token = $this->request->variable('hash', '');
+ if (check_link_hash($token, 'global'))
+ {
+ markread('topics', $forum_id, false, $this->request->variable('mark_time', 0));
+ }
+ $redirect_url = append_sid("{$this->phpbb_root_path}viewforum.{$this->php_ext}", 'f=' . $forum_id);
+ meta_refresh(3, $redirect_url);
+
+ if ($this->request->is_ajax())
+ {
+ // Tell the ajax script what language vars and URL need to be replaced
+ $data = [
+ 'NO_UNREAD_POSTS' => $this->language->lang('NO_UNREAD_POSTS'),
+ 'UNREAD_POSTS' => $this->language->lang('UNREAD_POSTS'),
+ 'U_MARK_TOPICS' => ($this->user->data['is_registered'] || $this->config['load_anon_lastread']) ? $controller_helper->route('phpbb_notifications_mark_topics_read', ['id' => $forum_id, 'hash' => generate_link_hash('global'), 'mark_time' => time()]) : '',
+ 'MESSAGE_TITLE' => $this->language->lang('INFORMATION'),
+ 'MESSAGE_TEXT' => $this->language->lang('TOPICS_MARKED')
+ ];
+ return new JsonResponse($data);
+ }
+
+ trigger_error($this->language->lang('TOPICS_MARKED') . '
' . sprintf($this->language->lang('RETURN_FORUM'), '', ''));
+ }
+}
diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php
index 94f967be7b6..ea289ae00ea 100644
--- a/phpBB/viewforum.php
+++ b/phpBB/viewforum.php
@@ -20,13 +20,15 @@
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+/* @var $controller_helper \phpbb\controller\helper */
+$controller_helper = $phpbb_container->get('controller.helper');
+
// Start session
$user->session_begin();
$auth->acl($user->data);
// Start initial var setup
$forum_id = $request->variable('f', 0);
-$mark_read = $request->variable('mark', '');
$start = $request->variable('start', 0);
$default_sort_days = (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0;
@@ -47,47 +49,7 @@
trigger_error('NO_FORUM');
}
-$sql_ary = [
- 'SELECT' => 'f.*',
- 'FROM' => [
- FORUMS_TABLE => 'f',
- ],
- 'WHERE' => 'f.forum_id = ' . $forum_id,
-];
-
-$lastread_select = '';
-
-// Grab appropriate forum data
-if ($config['load_db_lastread'] && $user->data['is_registered'])
-{
- $sql_ary['LEFT_JOIN'][] = [
- 'FROM' => [FORUMS_TRACK_TABLE => 'ft'],
- 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id',
- ];
- $sql_ary['SELECT'] .= ', ft.mark_time';
-}
-
-if ($user->data['is_registered'])
-{
- $sql_ary['LEFT_JOIN'][] = [
- 'FROM' => [FORUMS_WATCH_TABLE => 'fw'],
- 'ON' => 'fw.forum_id = f.forum_id AND fw.user_id = ' . $user->data['user_id'],
- ];
- $sql_ary['SELECT'] .= ', fw.notify_status';
-}
-
-/**
- * You can use this event to modify the sql that selects the forum on the viewforum page.
- *
- * @event core.viewforum_modify_sql
- * @var array sql_ary The SQL array to get the data for a forum
- * @since 3.3.14-RC1
- */
-$vars = ['sql_ary'];
-extract($phpbb_dispatcher->trigger_event('core.viewforum_modify_sql', compact($vars)));
-$result = $db->sql_query($db->sql_build_query('SELECT', $sql_ary));
-$forum_data = $db->sql_fetchrow($result);
-$db->sql_freeresult($result);
+$forum_data = get_forum_data($forum_id);
if (!$forum_data)
{
@@ -155,7 +117,7 @@
if ($forum_data['left_id'] != $forum_data['right_id'] - 1)
{
- list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators'], $config['load_moderators']);
+ list($active_forum_ary, $moderators) = display_forums($forum_data, $config['load_moderators']);
}
else
{
@@ -223,34 +185,6 @@
page_footer();
}
-// Handle marking posts
-if ($mark_read == 'topics')
-{
- $token = $request->variable('hash', '');
- if (check_link_hash($token, 'global'))
- {
- markread('topics', array($forum_id), false, $request->variable('mark_time', 0));
- }
- $redirect_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
- meta_refresh(3, $redirect_url);
-
- if ($request->is_ajax())
- {
- // Tell the ajax script what language vars and URL need to be replaced
- $data = array(
- 'NO_UNREAD_POSTS' => $user->lang['NO_UNREAD_POSTS'],
- 'UNREAD_POSTS' => $user->lang['UNREAD_POSTS'],
- 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&f=$forum_id&mark=topics&mark_time=" . time(), false) : '',
- 'MESSAGE_TITLE' => $user->lang['INFORMATION'],
- 'MESSAGE_TEXT' => $user->lang['TOPICS_MARKED']
- );
- $json_response = new \phpbb\json_response();
- $json_response->send($data);
- }
-
- trigger_error($user->lang['TOPICS_MARKED'] . '
' . sprintf($user->lang['RETURN_FORUM'], '', ''));
-}
-
// Do the forum Prune thang - cron type job ...
if (!$config['use_system_cron'])
{
@@ -461,7 +395,7 @@
'U_POST_NEW_TOPIC' => ($auth->acl_get('f_post', $forum_id) || $user->data['user_id'] == ANONYMOUS) ? append_sid("{$phpbb_root_path}posting.$phpEx", 'mode=post&f=' . $forum_id) : '',
'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($start == 0) ? '' : "&start=$start")),
'U_CANONICAL' => generate_board_url() . '/' . append_sid("viewforum.$phpEx", "f=$forum_id" . (($start) ? "&start=$start" : ''), true, ''),
- 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . "&f=$forum_id&mark=topics&mark_time=" . time()) : '',
+ 'U_MARK_TOPICS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? $controller_helper->route('phpbb_notifications_mark_topics_read', ['id' => $forum_id, 'hash' => generate_link_hash('global'), 'mark_time' => time()]) : '',
'U_SEARCH_FORUM' => append_sid("{$phpbb_root_path}search.$phpEx", 'fid%5B%5D=' . $forum_id),
));