From 5b22ccfa762a1934a8a2c326adf50a4e1c0ded44 Mon Sep 17 00:00:00 2001
From: Daniel Sinn <daniel.p.sinn@gmail.com>
Date: Thu, 30 Nov 2017 15:40:18 -0500
Subject: [PATCH 1/2] [ticket/15471] Add core events to ACP when pruning a
 forum

PHPBB3-15471
---
 phpBB/adm/style/acp_prune_forums.html |  4 +++-
 phpBB/docs/events.md                  |  7 ++++++
 phpBB/includes/acp/acp_prune.php      | 34 +++++++++++++++++++++++----
 phpBB/includes/functions_admin.php    | 10 ++++++++
 4 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/phpBB/adm/style/acp_prune_forums.html b/phpBB/adm/style/acp_prune_forums.html
index b8c681ea00..ef3880e851 100644
--- a/phpBB/adm/style/acp_prune_forums.html
+++ b/phpBB/adm/style/acp_prune_forums.html
@@ -94,7 +94,9 @@
 		<dd><label><input type="radio" class="radio" name="prune_sticky" value="1" /> {L_YES}</label>
 			<label><input type="radio" class="radio" id="sticky" name="prune_sticky" value="0" checked="checked" /> {L_NO}</label></dd>
 	</dl>
-	
+
+	<!-- EVENT acp_prune_forums_settings_append -->
+
 	<p class="quick">
 		{S_HIDDEN_FIELDS}
 		{S_FORM_TOKEN}
diff --git a/phpBB/docs/events.md b/phpBB/docs/events.md
index 6af3f55d21..0a00e1644c 100644
--- a/phpBB/docs/events.md
+++ b/phpBB/docs/events.md
@@ -433,6 +433,13 @@ acp_prune_forums_prepend
 * Since: 3.1.7-RC1
 * Purpose: Add content before the forum select form label
 
+acp_prune_forums_settings_append
+===
+* Locations:
+    + adm/style/acp_prune_forums.html
+* Since: 3.2.2-RC1
+* Purpose: Add content after the prune settings
+
 acp_prune_users_find_username_append
 ===
 * Locations:
diff --git a/phpBB/includes/acp/acp_prune.php b/phpBB/includes/acp/acp_prune.php
index d37050869a..91f78bb70d 100644
--- a/phpBB/includes/acp/acp_prune.php
+++ b/phpBB/includes/acp/acp_prune.php
@@ -55,7 +55,7 @@ class acp_prune
 	*/
 	function prune_forums($id, $mode)
 	{
-		global $db, $user, $auth, $template, $phpbb_log, $request;
+		global $db, $user, $auth, $template, $phpbb_log, $request, $phpbb_dispatcher;
 
 		$all_forums = $request->variable('all_forums', 0);
 		$forum_id = $request->variable('f', array(0));
@@ -165,7 +165,7 @@ class acp_prune
 			}
 			else
 			{
-				confirm_box(false, $user->lang['PRUNE_FORUM_CONFIRM'], build_hidden_fields(array(
+				$hidden_fields = array(
 					'i'				=> $id,
 					'mode'			=> $mode,
 					'submit'		=> 1,
@@ -177,7 +177,19 @@ class acp_prune
 					'prune_old_polls'	=> $request->variable('prune_old_polls', 0),
 					'prune_announce'	=> $request->variable('prune_announce', 0),
 					'prune_sticky'		=> $request->variable('prune_sticky', 0),
-				)));
+				);
+
+				/**
+				 * Use this event to pass data from the prune form to the confirmation screen
+				 *
+				 * @event core.prune_forums_settings_confirm
+				 * @var int[]	hidden_fields	The IDs of the topics to be deleted
+				 * @since 3.2.2-RC1
+				 */
+				$vars = array('hidden_fields');
+				extract($phpbb_dispatcher->trigger_event('core.prune_forums_settings_confirm', compact($vars)));
+
+				confirm_box(false, $user->lang['PRUNE_FORUM_CONFIRM'], build_hidden_fields($hidden_fields));
 			}
 		}
 
@@ -217,13 +229,25 @@ class acp_prune
 
 			$l_selected_forums = (sizeof($forum_id) == 1) ? 'SELECTED_FORUM' : 'SELECTED_FORUMS';
 
-			$template->assign_vars(array(
+			$template_data = array(
 				'L_SELECTED_FORUMS'		=> $user->lang[$l_selected_forums],
 				'U_ACTION'				=> $this->u_action,
 				'U_BACK'				=> $this->u_action,
 				'FORUM_LIST'			=> $forum_list,
-				'S_HIDDEN_FIELDS'		=> $s_hidden_fields)
+				'S_HIDDEN_FIELDS'		=> $s_hidden_fields,
 			);
+
+			/**
+			 * Event to add/modify prune forums settings template data
+			 *
+			 * @event core.prune_forums_settings_template_data
+			 * @var array	template_data	Array with form template data
+			 * @since 3.2.2-RC1
+			 */
+			$vars = array('template_data');
+			extract($phpbb_dispatcher->trigger_event('core.prune_forums_settings_template_data', compact($vars)));
+
+			$template->assign_vars($template_data);
 		}
 	}
 
diff --git a/phpBB/includes/functions_admin.php b/phpBB/includes/functions_admin.php
index 1ad41156f9..96916e1e43 100644
--- a/phpBB/includes/functions_admin.php
+++ b/phpBB/includes/functions_admin.php
@@ -2369,6 +2369,16 @@ function prune($forum_id, $prune_mode, $prune_date, $prune_flags = 0, $auto_sync
 		$topic_list = array_unique($topic_list);
 	}
 
+	/**
+	 * Perform additional actions before topic deletion via pruning
+	 *
+	 * @event core.prune_delete_before
+	 * @var int[]	topic_list		The IDs of the topics to be deleted
+	 * @since 3.2.2-RC1
+	 */
+	$vars = array('topic_list');
+	extract($phpbb_dispatcher->trigger_event('core.prune_delete_before', compact($vars)));
+
 	return delete_topics('topic_id', $topic_list, $auto_sync, false);
 }
 

From bf55546d2d1481e909b918ed6cfef16e8ebc2afa Mon Sep 17 00:00:00 2001
From: Daniel Sinn <daniel.p.sinn@gmail.com>
Date: Mon, 18 Dec 2017 08:14:42 -0500
Subject: [PATCH 2/2] [ticket/15471] Fix event documentation for
 core.prune_forums_settings_confirm

PHPBB3-15471
---
 phpBB/includes/acp/acp_prune.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/phpBB/includes/acp/acp_prune.php b/phpBB/includes/acp/acp_prune.php
index 91f78bb70d..a8c0dd060d 100644
--- a/phpBB/includes/acp/acp_prune.php
+++ b/phpBB/includes/acp/acp_prune.php
@@ -183,7 +183,7 @@ class acp_prune
 				 * Use this event to pass data from the prune form to the confirmation screen
 				 *
 				 * @event core.prune_forums_settings_confirm
-				 * @var int[]	hidden_fields	The IDs of the topics to be deleted
+				 * @var array	hidden_fields	Hidden fields that are passed through the confirm screen
 				 * @since 3.2.2-RC1
 				 */
 				$vars = array('hidden_fields');