diff --git a/phpBB/search.php b/phpBB/search.php index 7ab8e15a1e..3e05204043 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -247,6 +247,32 @@ if ($keywords || $author || $author_id || $search_id || $submit) $ex_fid_ary = array_unique(array_merge(array_keys($auth->acl_getf('!f_read', true)), array_keys($auth->acl_getf('!f_search', true)))); } + // There are two exceptional scenarios we want to consider if there are any forums where an read forum = no, can read topics = yes + // In these cases, the user should see the topic title in the search results but not the link to the topic (or any posts) because + // they don't have the permissions for that. + $show_topic_title_only = false; + + // Firstly, is someone doing a quick search from the viewforum page? If so, force it to be a topic-only search for that one forum + // We know if this is the case due to the presence of this request var + $forum_quick_search = $request->variable('viewforum', 0); + if ($forum_quick_search && $auth->acl_get('f_list_topics', $forum_quick_search) && !$auth->acl_get('f_read', $forum_quick_search)) + { + $show_topic_title_only = true; + } + + // Secondly, is someone doing a topic search from the main search page? If so, we will strip the topic links while still showing the name + else if ($request->variable('sr', '') == 'topics' && $search_fields == 'titleonly') + { + // We will allow the 'can read topics = yes' forums back in to the search + $show_topic_title_only = true; + } + + if ($show_topic_title_only) + { + // Remove from $ex_fid_ary any of the 'can read topics' forums (meaning they will not be excluded from the search) + $ex_fid_ary = array_diff($ex_fid_ary, array_keys($auth->acl_getf('f_list_topics', true))); + } + $not_in_fid = (count($ex_fid_ary)) ? 'WHERE ' . $db->sql_in_set('f.forum_id', $ex_fid_ary, true) . " OR (f.forum_password <> '' AND fa.user_id <> " . (int) $user->data['user_id'] . ')' : ""; $sql = 'SELECT f.forum_id, f.forum_name, f.parent_id, f.forum_type, f.right_id, f.forum_password, f.forum_flags, fa.user_id @@ -349,6 +375,11 @@ if ($keywords || $author || $author_id || $search_id || $submit) $show_results = ($show_results == 'posts') ? 'posts' : 'topics'; } + if ($show_topic_title_only) + { + $show_results = 'topics'; + } + // define some variables needed for retrieving post_id/topic_id information $sort_by_sql = [ 'a' => 'u.username_clean', @@ -1157,10 +1188,10 @@ if ($keywords || $author || $author_id || $search_id || $submit) 'S_TOPIC_DELETED' => $topic_deleted, 'S_HAS_POLL' => ($row['poll_start']) ? true : false, - 'U_LAST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'], + 'U_LAST_POST' => $auth->acl_get('f_read', $forum_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['topic_last_post_id']) . '#p' . $row['topic_last_post_id'] : false, 'U_LAST_POST_AUTHOR' => get_username_string('profile', $row['topic_last_poster_id'], $row['topic_last_poster_name'], $row['topic_last_poster_colour']), 'U_TOPIC_AUTHOR' => get_username_string('profile', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']), - 'U_NEWEST_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&view=unread') . '#unread', + 'U_NEWEST_POST' => $auth->acl_get('f_read', $forum_id) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params . '&view=unread') . '#unread' : false, 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&mode=reports&t=' . $result_topic_id, true, $user->session_id), 'U_MCP_QUEUE' => $u_mcp_queue, ); @@ -1230,7 +1261,7 @@ if ($keywords || $author || $author_id || $search_id || $submit) 'TOPIC_REPLIES' => $replies, 'TOPIC_VIEWS' => $row['topic_views'], - 'U_VIEW_TOPIC' => $view_topic_url, + 'U_VIEW_TOPIC' => $auth->acl_get('f_read', $forum_id) ? $view_topic_url : false, 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id), 'U_VIEW_POST' => (!empty($row['post_id'])) ? append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id'] . (($u_hilit) ? '&hilit=' . $u_hilit : '')) . '#p' . $row['post_id'] : '', )); diff --git a/phpBB/styles/prosilver/template/search_results.html b/phpBB/styles/prosilver/template/search_results.html index 01cf17a746..8f664201bb 100644 --- a/phpBB/styles/prosilver/template/search_results.html +++ b/phpBB/styles/prosilver/template/search_results.html @@ -80,15 +80,15 @@