From 3ff99a9eb1b7921fc8d6c33742c4412270fd1d94 Mon Sep 17 00:00:00 2001
From: rxu <rxu@mail.ru>
Date: Fri, 7 May 2021 16:45:01 +0700
Subject: [PATCH 1/2] [ticket/16771] Add MCP core events

PHPBB3-16771
---
 phpBB/includes/mcp/mcp_front.php   | 69 ++++++++++++++++++++++++++--
 phpBB/includes/mcp/mcp_reports.php | 47 ++++++++++++++++++-
 phpBB/includes/mcp/mcp_topic.php   | 72 +++++++++++++++++++++++++++++-
 3 files changed, 180 insertions(+), 8 deletions(-)

diff --git a/phpBB/includes/mcp/mcp_front.php b/phpBB/includes/mcp/mcp_front.php
index 918a98734b..3a0f4c4905 100644
--- a/phpBB/includes/mcp/mcp_front.php
+++ b/phpBB/includes/mcp/mcp_front.php
@@ -119,11 +119,32 @@ function mcp_front_view($id, $mode, $action)
 						AND t.topic_id = p.topic_id
 						AND p.poster_id = u.user_id
 					ORDER BY p.post_time DESC, p.post_id DESC';
+
+				/**
+				 * Alter posts data SQL query
+				 *
+				 * @event core.mcp_front_view_modify_posts_data_sql
+				 * @var	array	forum_list		List of forums that contain the posts
+				 * @var	array	forum_names		Associative array with forum_id as key and it's corresponding forum_name as value
+				 * @var	array	post_list		List of unapproved posts
+				 * @var	string	sql				String with the SQL query to be executed
+				 * @var	int		total			Number of unapproved posts
+				 * @since 3.3.5-RC1
+				 */
+				$vars = [
+					'forum_list',
+					'forum_names',
+					'post_list',
+					'sql',
+					'total',
+				];
+				extract($phpbb_dispatcher->trigger_event('core.mcp_front_view_modify_posts_data_sql', compact($vars)));
+
 				$result = $db->sql_query($sql);
 
 				while ($row = $db->sql_fetchrow($result))
 				{
-					$template->assign_block_vars('unapproved', array(
+					$unapproved_post_row = [
 						'U_POST_DETAILS'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']),
 						'U_MCP_FORUM'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=forum_view&amp;f=' . $row['forum_id']),
 						'U_MCP_TOPIC'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=topic_view&amp;f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']),
@@ -141,7 +162,27 @@ function mcp_front_view($id, $mode, $action)
 						'SUBJECT'		=> ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
 						'POST_TIME'		=> $user->format_date($row['post_time']),
 						'ATTACH_ICON_IMG'	=> ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
-					));
+					];
+
+					/**
+					 * Alter unapproved posts template block for MCP front page
+					 *
+					 * @event core.mcp_front_view_modify_unapproved_post_row
+					 * @var	array	forum_names				Array containing forum names
+					 * @var	string	mode					MCP front view mode
+					 * @var	array	row						Array with unapproved post data
+					 * @var	array	unapproved_post_row		Template block array of the unapproved post
+					 * @since 3.3.5-RC1
+					 */
+					$vars = [
+						'forum_names',
+						'mode',
+						'row',
+						'unapproved_post_row',
+					];
+					extract($phpbb_dispatcher->trigger_event('core.mcp_front_view_modify_unapproved_post_row', compact($vars)));
+
+					$template->assign_block_vars('unapproved', $unapproved_post_row);
 				}
 				$db->sql_freeresult($result);
 			}
@@ -238,7 +279,7 @@ function mcp_front_view($id, $mode, $action)
 
 				while ($row = $db->sql_fetchrow($result))
 				{
-					$template->assign_block_vars('report', array(
+					$reported_post_row = [
 						'U_POST_DETAILS'	=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id'] . "&amp;i=reports&amp;mode=report_details"),
 						'U_MCP_FORUM'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'f=' . $row['forum_id'] . "&amp;i=$id&amp;mode=forum_view"),
 						'U_MCP_TOPIC'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id'] . "&amp;i=$id&amp;mode=topic_view"),
@@ -261,7 +302,27 @@ function mcp_front_view($id, $mode, $action)
 						'REPORT_TIME'	=> $user->format_date($row['report_time']),
 						'POST_TIME'		=> $user->format_date($row['post_time']),
 						'ATTACH_ICON_IMG'	=> ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
-					));
+					];
+
+					/**
+					 * Alter reported posts template block for MCP front page
+					 *
+					 * @event core.mcp_front_view_modify_reported_post_row
+					 * @var	array	forum_list			List of forums that contain the posts
+					 * @var	string	mode				MCP front view mode
+					 * @var	array	reported_post_row	Template block array of the reported post
+					 * @var	array	row					Array with reported post data
+					 * @since 3.3.5-RC1
+					 */
+					$vars = [
+						'forum_list',
+						'mode',
+						'reported_post_row',
+						'row',
+					];
+					extract($phpbb_dispatcher->trigger_event('core.mcp_front_view_modify_reported_post_row', compact($vars)));
+
+					$template->assign_block_vars('report', $reported_post_row);
 				}
 				$db->sql_freeresult($result);
 			}
diff --git a/phpBB/includes/mcp/mcp_reports.php b/phpBB/includes/mcp/mcp_reports.php
index 273d029cac..d8910f8659 100644
--- a/phpBB/includes/mcp/mcp_reports.php
+++ b/phpBB/includes/mcp/mcp_reports.php
@@ -493,11 +493,30 @@ class mcp_reports
 							AND ru.user_id = r.user_id
 							AND r.pm_id = 0
 						ORDER BY ' . $sort_order_sql;
+
+					/**
+					 * Alter sql query to get reports data for requested forum and topic or just forum
+					 *
+					 * @event core.mcp_reports_modify_reports_data_sql
+					 * @var	string	sql						String with the query to be executed
+					 * @var	array	forum_list				List of forums that contain the posts
+					 * @var	int		topic_id				topic_id in the page request
+					 * @var	string	sort_order_sql			String with the ORDER BY SQL code used in this query
+					 * @since 3.3.5-RC1
+					 */
+					$vars = [
+						'sql',
+						'forum_list',
+						'topic_id',
+						'sort_order_sql',
+					];
+					extract($phpbb_dispatcher->trigger_event('core.mcp_reports_modify_reports_data_sql', compact($vars)));
+
 					$result = $db->sql_query($sql);
 
 					while ($row = $db->sql_fetchrow($result))
 					{
-						$template->assign_block_vars('postrow', array(
+						$post_row = [
 							'U_VIEWFORUM'				=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']),
 							'U_VIEWPOST'				=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']) . '#p' . $row['post_id'],
 							'U_VIEW_DETAILS'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=reports&amp;start=$start&amp;mode=report_details&amp;f={$row['forum_id']}&amp;r={$row['report_id']}"),
@@ -520,7 +539,31 @@ class mcp_reports
 							'REPORT_TIME'	=> $user->format_date($row['report_time']),
 							'TOPIC_TITLE'	=> $row['topic_title'],
 							'ATTACH_ICON_IMG'	=> ($auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment']) ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : '',
-						));
+						];
+
+						/**
+						 * Alter posts template block for MCP reports
+						 *
+						 * @event core.mcp_reports_modify_post_row
+						 * @var	string	mode		Post report mode
+						 * @var	array	forum_data	Array containing forum data
+						 * @var	array	post_row	Template block array of the post
+						 * @var	array	row			Array with original post and report data
+						 * @var	int		start		Start item of this page
+						 * @var	int		topic_id	topic_id in the page request
+						 * @since 3.3.5-RC1
+						 */
+						$vars = [
+							'mode',
+							'forum_data',
+							'post_row',
+							'row',
+							'start',
+							'topic_id',
+						];
+						extract($phpbb_dispatcher->trigger_event('core.mcp_reports_modify_post_row', compact($vars)));
+
+						$template->assign_block_vars('postrow', $post_row);
 					}
 					$db->sql_freeresult($result);
 					unset($report_ids, $row);
diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php
index e47ae47d9b..a38f45f885 100644
--- a/phpBB/includes/mcp/mcp_topic.php
+++ b/phpBB/includes/mcp/mcp_topic.php
@@ -379,7 +379,7 @@ function mcp_topic_view($id, $mode, $action)
 		$pagination->generate_template_pagination($base_url, 'pagination', 'start', $total, $posts_per_page, $start);
 	}
 
-	$template->assign_vars(array(
+	$topic_row = [
 		'TOPIC_TITLE'		=> $topic_info['topic_title'],
 		'U_VIEW_TOPIC'		=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $topic_info['forum_id'] . '&amp;t=' . $topic_info['topic_id']),
 
@@ -420,7 +420,49 @@ function mcp_topic_view($id, $mode, $action)
 		'RETURN_FORUM'		=> sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", "f={$topic_info['forum_id']}&amp;start=$start") . '">', '</a>'),
 
 		'TOTAL_POSTS'		=> $user->lang('VIEW_TOPIC_POSTS', (int) $total),
-	));
+	];
+
+	/**
+	 * Event to modify the template data block for topic data output in the MCP
+	 *
+	 * @event core.mcp_topic_review_modify_topic_row
+	 * @var	string	action					Moderation action type to be performed with the topic
+	 * @var	bool	has_unapproved_posts	Flag indicating if the topic has unapproved posts
+	 * @var	int		icon_id					Split topic icon ID
+	 * @var	int		id						ID of the tab we are displaying
+	 * @var	string	mode					Mode of the MCP page we are displaying
+	 * @var	int		topic_id				The topic ID we are currently reviewing
+	 * @var	int		forum_id				The forum ID we are currently in
+	 * @var	bool	s_topic_icons			Flag indicating if split topic icon to be displayed
+	 * @var	int		start					Start item of this page
+	 * @var	string	subject					Subject of the topic to be split
+	 * @var	array	topic_info				Array with topic data
+	 * @var	int		to_forum_id				Forum id the topic is being moved to
+	 * @var	int		to_topic_id				Topic ID the topic is being merged with
+	 * @var	int		topic_row				Topic template data array
+	 * @var	int		total					Total posts count
+	 * @since 3.3.5-RC1
+	 */
+	$vars = [
+		'action',
+		'has_unapproved_posts',
+		'icon_id',
+		'id',
+		'mode',
+		'topic_id',
+		'forum_id',
+		's_topic_icons',
+		'start',
+		'subject',
+		'topic_info',
+		'to_forum_id',
+		'to_topic_id',
+		'topic_row',
+		'total',
+	];
+	extract($phpbb_dispatcher->trigger_event('core.mcp_topic_review_modify_topic_row', compact($vars)));
+
+	$template->assign_vars($topic_row);
 }
 
 /**
@@ -696,6 +738,32 @@ function split_topic($action, $topic_id, $to_forum_id, $subject)
 		$redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.$phpEx?f=$to_forum_id&amp;t=$to_topic_id");
 		$redirect = reapply_sid($redirect);
 
+		/**
+		 * Event to access topic data after split
+		 *
+		 * @event core.mcp_topic_split_topic_after
+		 * @var	string	action			Split action type to be performed with the topic
+		 * @var	int		topic_id		The topic ID we are currently splitting
+		 * @var	int		forum_id		The forum ID we are currently in
+		 * @var	int		start			Start item of this page
+		 * @var	string	subject			Subject of the topic to be split
+		 * @var	array	topic_info		Array with topic data
+		 * @var	int		to_forum_id		Forum id the topic is being moved to
+		 * @var	int		to_topic_id		Topic ID the topic is being split to
+		 * @since 3.3.5-RC1
+		 */
+		$vars = [
+			'action',
+			'topic_id',
+			'forum_id',
+			'start',
+			'subject',
+			'topic_info',
+			'to_forum_id',
+			'to_topic_id',
+		];
+		extract($phpbb_dispatcher->trigger_event('core.mcp_topic_split_topic_after', compact($vars)));
+
 		meta_refresh(3, $redirect);
 		trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
 	}

From 3bb58556ea1be92fcd76c34cbd88ab6d77ec7968 Mon Sep 17 00:00:00 2001
From: Marc Alexander <admin@m-a-styles.de>
Date: Sat, 15 May 2021 22:49:28 +0200
Subject: [PATCH 2/2] [ticket/16771] Fix typo and invalid type in event
 docblocks

PHPBB3-16771
---
 phpBB/includes/mcp/mcp_front.php | 4 ++--
 phpBB/includes/mcp/mcp_topic.php | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/phpBB/includes/mcp/mcp_front.php b/phpBB/includes/mcp/mcp_front.php
index 3a0f4c4905..578f84ad7f 100644
--- a/phpBB/includes/mcp/mcp_front.php
+++ b/phpBB/includes/mcp/mcp_front.php
@@ -105,7 +105,7 @@ function mcp_front_view($id, $mode, $action)
 			* @var	int		total						Number of unapproved posts
 			* @var	array	post_list					List of unapproved posts
 			* @var	array	forum_list					List of forums that contain the posts
-			* @var	array	forum_names					Associative array with forum_id as key and it's corresponding forum_name as value
+			* @var	array	forum_names					Associative array with forum_id as key and its corresponding forum_name as value
 			* @since 3.1.0-RC3
 			*/
 			$vars = array('total', 'post_list', 'forum_list', 'forum_names');
@@ -125,7 +125,7 @@ function mcp_front_view($id, $mode, $action)
 				 *
 				 * @event core.mcp_front_view_modify_posts_data_sql
 				 * @var	array	forum_list		List of forums that contain the posts
-				 * @var	array	forum_names		Associative array with forum_id as key and it's corresponding forum_name as value
+				 * @var	array	forum_names		Associative array with forum_id as key and its corresponding forum_name as value
 				 * @var	array	post_list		List of unapproved posts
 				 * @var	string	sql				String with the SQL query to be executed
 				 * @var	int		total			Number of unapproved posts
diff --git a/phpBB/includes/mcp/mcp_topic.php b/phpBB/includes/mcp/mcp_topic.php
index a38f45f885..ba4f2b261f 100644
--- a/phpBB/includes/mcp/mcp_topic.php
+++ b/phpBB/includes/mcp/mcp_topic.php
@@ -439,7 +439,7 @@ function mcp_topic_view($id, $mode, $action)
 	 * @var	array	topic_info				Array with topic data
 	 * @var	int		to_forum_id				Forum id the topic is being moved to
 	 * @var	int		to_topic_id				Topic ID the topic is being merged with
-	 * @var	int		topic_row				Topic template data array
+	 * @var	array	topic_row				Topic template data array
 	 * @var	int		total					Total posts count
 	 * @since 3.3.5-RC1
 	 */