From 1177f843c57c81f932b8fd48273c247eb397f135 Mon Sep 17 00:00:00 2001
From: 3D-I <eataly3d@gmail.com>
Date: Wed, 9 Jun 2021 03:51:37 +0200
Subject: [PATCH 1/3] [ticket/16793] Fix topic/post visibility - PHP 8

PHPBB3-16793
---
 phpBB/phpbb/content_visibility.php | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php
index 316df79319..e5ca547f0b 100644
--- a/phpBB/phpbb/content_visibility.php
+++ b/phpBB/phpbb/content_visibility.php
@@ -145,13 +145,13 @@ class content_visibility
 	public function is_visible($mode, $forum_id, $data)
 	{
 		$visibility = $data[$mode . '_visibility'];
-		$poster_key = ($mode === 'topic') ? 'topic_poster' : 'poster_id';
+
 		$is_visible = ($visibility == ITEM_APPROVED) ||
-			($this->config['display_unapproved_posts'] &&
-				($this->user->data['user_id'] != ANONYMOUS) &&
-				($visibility == ITEM_UNAPPROVED || $visibility == ITEM_REAPPROVE) &&
-				($this->user->data['user_id'] == $data[$poster_key])) ||
-			 $this->auth->acl_get('m_approve', $forum_id);
+			($this->config['display_unapproved_posts']
+				&& ($this->user->data['user_id'] != ANONYMOUS)#
+				&& ($visibility == ITEM_UNAPPROVED || $visibility == ITEM_REAPPROVE)
+			) ||
+			$this->auth->acl_get('m_approve', $forum_id);
 
 		/**
 		* Allow changing the result of calling is_visible

From c9b32463ded6542b66c9591256c36948d220e7d5 Mon Sep 17 00:00:00 2001
From: 3D-I <eataly3d@gmail.com>
Date: Wed, 9 Jun 2021 04:07:59 +0200
Subject: [PATCH 2/3] [ticket/16793] Fix topic/post visibility - PHP 8

PHPBB3-16793
---
 phpBB/phpbb/content_visibility.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php
index e5ca547f0b..772a85ec4a 100644
--- a/phpBB/phpbb/content_visibility.php
+++ b/phpBB/phpbb/content_visibility.php
@@ -148,7 +148,7 @@ class content_visibility
 
 		$is_visible = ($visibility == ITEM_APPROVED) ||
 			($this->config['display_unapproved_posts']
-				&& ($this->user->data['user_id'] != ANONYMOUS)#
+				&& ($this->user->data['user_id'] != ANONYMOUS)
 				&& ($visibility == ITEM_UNAPPROVED || $visibility == ITEM_REAPPROVE)
 			) ||
 			$this->auth->acl_get('m_approve', $forum_id);

From c452c83855ad55d35df81f4db0d7ef5badc7b23e Mon Sep 17 00:00:00 2001
From: 3D-I <eataly3d@gmail.com>
Date: Thu, 10 Jun 2021 21:34:07 +0200
Subject: [PATCH 3/3] [ticket/16793] Fix topic/post visibility - PHP 8

PHPBB3-16793
---
 phpBB/download/file.php               |  2 +-
 phpBB/includes/functions_download.php | 12 ++++++------
 phpBB/phpbb/content_visibility.php    | 12 ++++++------
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/phpBB/download/file.php b/phpBB/download/file.php
index 6d0796d2c4..77367a7afd 100644
--- a/phpBB/download/file.php
+++ b/phpBB/download/file.php
@@ -220,7 +220,7 @@ else
 		{
 			phpbb_download_handle_forum_auth($db, $auth, $attachment['topic_id']);
 
-			$sql = 'SELECT forum_id, post_visibility
+			$sql = 'SELECT forum_id, poster_id, post_visibility
 				FROM ' . POSTS_TABLE . '
 				WHERE post_id = ' . (int) $attachment['post_msg_id'];
 			$result = $db->sql_query($sql);
diff --git a/phpBB/includes/functions_download.php b/phpBB/includes/functions_download.php
index 1ae59448ac..f0aef9eac3 100644
--- a/phpBB/includes/functions_download.php
+++ b/phpBB/includes/functions_download.php
@@ -656,15 +656,15 @@ function phpbb_download_handle_forum_auth($db, $auth, $topic_id)
 {
 	global $phpbb_container;
 
-	$sql_array = array(
-		'SELECT'	=> 't.topic_visibility, t.forum_id, f.forum_name, f.forum_password, f.parent_id',
-		'FROM'		=> array(
+	$sql_array = [
+		'SELECT'	=> 't.forum_id, t.topic_poster, t.topic_visibility, f.forum_name, f.forum_password, f.parent_id',
+		'FROM'		=> [
 			TOPICS_TABLE => 't',
 			FORUMS_TABLE => 'f',
-		),
-		'WHERE'	=> 't.topic_id = ' . (int) $topic_id . '
+		],
+		'WHERE'		=> 't.topic_id = ' . (int) $topic_id . '
 			AND t.forum_id = f.forum_id',
-	);
+	];
 
 	$sql = $db->sql_build_query('SELECT', $sql_array);
 	$result = $db->sql_query($sql);
diff --git a/phpBB/phpbb/content_visibility.php b/phpBB/phpbb/content_visibility.php
index 772a85ec4a..316df79319 100644
--- a/phpBB/phpbb/content_visibility.php
+++ b/phpBB/phpbb/content_visibility.php
@@ -145,13 +145,13 @@ class content_visibility
 	public function is_visible($mode, $forum_id, $data)
 	{
 		$visibility = $data[$mode . '_visibility'];
-
+		$poster_key = ($mode === 'topic') ? 'topic_poster' : 'poster_id';
 		$is_visible = ($visibility == ITEM_APPROVED) ||
-			($this->config['display_unapproved_posts']
-				&& ($this->user->data['user_id'] != ANONYMOUS)
-				&& ($visibility == ITEM_UNAPPROVED || $visibility == ITEM_REAPPROVE)
-			) ||
-			$this->auth->acl_get('m_approve', $forum_id);
+			($this->config['display_unapproved_posts'] &&
+				($this->user->data['user_id'] != ANONYMOUS) &&
+				($visibility == ITEM_UNAPPROVED || $visibility == ITEM_REAPPROVE) &&
+				($this->user->data['user_id'] == $data[$poster_key])) ||
+			 $this->auth->acl_get('m_approve', $forum_id);
 
 		/**
 		* Allow changing the result of calling is_visible