diff --git a/phpBB/feed.php b/phpBB/feed.php index 79fedbf575..b6d93a45f8 100644 --- a/phpBB/feed.php +++ b/phpBB/feed.php @@ -779,6 +779,8 @@ class phpbb_feed_overall extends phpbb_feed_post_base return false; } + $sql_visibility = phpbb_content_visibility::get_visibility_sql('post', array(), 'p.'); + // Get the actual data $this->sql = array( 'SELECT' => 'f.forum_id, f.forum_name, ' . @@ -795,7 +797,7 @@ class phpbb_feed_overall extends phpbb_feed_post_base ), ), 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' - AND ' . phpbb_content_visibility::get_visibility_sql('post', array(), 'p.') . ' + ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . ' AND p.post_time >= ' . $min_post_time . ' AND u.user_id = p.poster_id', 'ORDER_BY' => 'p.post_time DESC', @@ -885,14 +887,14 @@ class phpbb_feed_forum extends phpbb_feed_post_base { global $auth, $db; - $m_approve = ($auth->acl_get('m_approve', $this->forum_id)) ? true : false; + $sql_visibility = phpbb_content_visibility::get_visibility_sql('topic', $this->forum_id); // Determine topics with recent activity $sql = 'SELECT topic_id, topic_last_post_time FROM ' . TOPICS_TABLE . ' WHERE forum_id = ' . $this->forum_id . ' AND topic_moved_id = 0 - AND ' . phpbb_content_visibility::get_visibility_sql('topic', $this->forum_id) . ' + ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . ' ORDER BY topic_last_post_time DESC'; $result = $db->sql_query_limit($sql, $this->num_items); @@ -911,6 +913,8 @@ class phpbb_feed_forum extends phpbb_feed_post_base return false; } + $sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.'); + $this->sql = array( 'SELECT' => 'p.post_id, p.topic_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'u.username, u.user_id', @@ -919,7 +923,7 @@ class phpbb_feed_forum extends phpbb_feed_post_base USERS_TABLE => 'u', ), 'WHERE' => $db->sql_in_set('p.topic_id', $topic_ids) . ' - AND ' . phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . ' + ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . ' AND p.post_time >= ' . $min_post_time . ' AND p.poster_id = u.user_id', 'ORDER_BY' => 'p.post_time DESC', @@ -1017,6 +1021,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base { global $auth, $db; + $sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.'); $this->sql = array( 'SELECT' => 'p.post_id, p.post_time, p.post_edit_time, p.post_visibility, p.post_subject, p.post_text, p.bbcode_bitfield, p.bbcode_uid, p.enable_bbcode, p.enable_smilies, p.enable_magic_url, ' . 'u.username, u.user_id', @@ -1025,7 +1030,7 @@ class phpbb_feed_topic extends phpbb_feed_post_base USERS_TABLE => 'u', ), 'WHERE' => 'p.topic_id = ' . $this->topic_id . ' - AND ' . phpbb_content_visibility::get_visibility_sql('post', $this->forum_id, 'p.') . ' + ' . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . ' AND p.poster_id = u.user_id', 'ORDER_BY' => 'p.post_time DESC', ); diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php index 5c3e9d39dd..287c46a335 100644 --- a/phpBB/includes/content_visibility.php +++ b/phpBB/includes/content_visibility.php @@ -43,9 +43,15 @@ class phpbb_content_visibility { $status_ary[] = ITEM_DELETED; + if (sizeof($status_ary) == 3) + { + // The user can see all types, so we simplify this to an empty string, + // as we don't need to restrict anything on the query. + return ''; + } + // If the user has m_restore, the rest of the function will not // make more content visible, so we can return the query here. - // This avoids one OR in all queries return $db->sql_in_set($table_alias . $mode . '_visibility', $status_ary); } diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index ecec1e5e4a..4b7b3d5057 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1855,7 +1855,8 @@ function update_forum_tracking_info($forum_id, $forum_last_post_time, $f_mark_ti // Handle update of unapproved topics info. // Only update for moderators having m_approve permission for the forum. - $sql_update_unapproved = ($auth->acl_get('m_approve', $forum_id)) ? '': 'AND t.topic_approved = 1'; + $sql_update_unapproved = phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); + $sql_update_unapproved = ($sql_update_unapproved) ? ' AND ' . $sql_update_unapproved : ''; // Check the forum for any left unread topics. // If there are none, we mark the forum as read. diff --git a/phpBB/viewforum.php b/phpBB/viewforum.php index 6f95f526c6..4f1f30d1bf 100644 --- a/phpBB/viewforum.php +++ b/phpBB/viewforum.php @@ -234,6 +234,7 @@ gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $ if ($sort_days) { $min_post_time = time() - ($sort_days * 86400); + $sql_visibility = phpbb_content_visibility::get_visibility_sql('topic', $forum_id); $sql = 'SELECT COUNT(topic_id) AS num_topics FROM ' . TOPICS_TABLE . " @@ -241,7 +242,7 @@ if ($sort_days) AND (topic_last_post_time >= $min_post_time OR topic_type = " . POST_ANNOUNCE . ' OR topic_type = ' . POST_GLOBAL . ') - AND ' . phpbb_content_visibility::get_visibility_sql('topic', $forum_id); + ' . (($sql_visibility) ? ' AND ' . $sql_visibility : ''); $result = $db->sql_query($sql); $topics_count = (int) $db->sql_fetchfield('num_topics'); $db->sql_freeresult($result); @@ -353,7 +354,8 @@ $sql_array = array( 'LEFT_JOIN' => array(), ); -$sql_approved = 'AND ' . phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); +$sql_approved = phpbb_content_visibility::get_visibility_sql('topic', $forum_id, 't.'); +$sql_approved = ($sql_approved) ? ' AND ' . $sql_approved : ''; if ($user->data['is_registered']) { diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 4c598ab204..f05d94b8af 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -79,11 +79,12 @@ if ($view && !$post_id) $topic_tracking_info = get_complete_topic_tracking($forum_id, $topic_id); $topic_last_read = (isset($topic_tracking_info[$topic_id])) ? $topic_tracking_info[$topic_id] : 0; + $sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $forum_id); $sql = 'SELECT post_id, topic_id, forum_id FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id) . " + " . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . " AND post_time > $topic_last_read AND forum_id = $forum_id ORDER BY post_time ASC"; @@ -132,12 +133,14 @@ if ($view && !$post_id) } else { + $sql_visibility = phpbb_content_visibility::get_visibility_sql('topic', $row['forum_id']); + $sql = 'SELECT topic_id, forum_id FROM ' . TOPICS_TABLE . ' WHERE forum_id = ' . $row['forum_id'] . " AND topic_moved_id = 0 AND topic_last_post_time $sql_condition {$row['topic_last_post_time']} - AND" . phpbb_content_visibility::get_visibility_sql('topic', $row['forum_id']) . " + " . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . " ORDER BY topic_last_post_time $sql_ordering"; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); @@ -274,10 +277,12 @@ if ($post_id) } else { + $sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.'); + $sql = 'SELECT COUNT(p.post_id) AS prev_posts FROM ' . POSTS_TABLE . " p WHERE p.topic_id = {$topic_data['topic_id']} - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.'); + " . (($sql_visibility) ? ' AND ' . $sql_visibility : ''); if ($sort_dir == 'd') { @@ -403,12 +408,13 @@ gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $ if ($sort_days) { $min_post_time = time() - ($sort_days * 86400); + $sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $forum_id); $sql = 'SELECT COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . " WHERE topic_id = $topic_id AND post_time >= $min_post_time - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id); + " . (($sql_visibility) ? ' AND ' . $sql_visibility : ''); $result = $db->sql_query($sql); $total_posts = (int) $db->sql_fetchfield('num_posts'); $db->sql_freeresult($result); @@ -942,10 +948,12 @@ $bbcode_bitfield = ''; $i = $i_total = 0; // Go ahead and pull all data for this topic +$sql_visibility = phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.'); + $sql = 'SELECT p.post_id FROM ' . POSTS_TABLE . ' p' . (($join_user_sql[$sort_key]) ? ', ' . USERS_TABLE . ' u': '') . " WHERE p.topic_id = $topic_id - AND " . phpbb_content_visibility::get_visibility_sql('post', $forum_id, 'p.') . " + " . (($sql_visibility) ? ' AND ' . $sql_visibility : '') . " " . (($join_user_sql[$sort_key]) ? 'AND u.user_id = p.poster_id': '') . " $limit_posts_time ORDER BY $sql_sort_order";