Skip to content

Commit 078cd30

Browse files
committed
[ticket/17157] Optimise the quick search code
PHPBB-17157
1 parent 676905b commit 078cd30

2 files changed

Lines changed: 13 additions & 29 deletions

File tree

phpBB/search.php

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -247,29 +247,12 @@
247247
$ex_fid_ary = array_unique(array_merge(array_keys($auth->acl_getf('!f_read', true)), array_keys($auth->acl_getf('!f_search', true))));
248248
}
249249

250-
// There are two exceptional scenarios we want to consider if there are any forums where an read forum = no, can read topics = yes
251-
// 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
252-
// they don't have the permissions for that.
253-
$show_topic_title_only = false;
254-
255-
// 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
256-
// We know if this is the case due to the presence of this request var
257-
$forum_quick_search = $request->variable('viewforum', 0);
258-
if ($forum_quick_search && $auth->acl_get('f_list_topics', $forum_quick_search) && !$auth->acl_get('f_read', $forum_quick_search))
250+
// Consider if there are any forums where can read forum = no, can read topics = yes
251+
// 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
252+
if ($request->variable('sr', '') == 'topics' && $search_fields == 'titleonly')
259253
{
260-
$show_topic_title_only = true;
261-
}
262-
263-
// 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
264-
else if ($request->variable('sr', '') == 'topics' && $search_fields == 'titleonly')
265-
{
266-
// We will allow the 'can read topics = yes' forums back in to the search
267-
$show_topic_title_only = true;
268-
}
269-
270-
if ($show_topic_title_only)
271-
{
272-
// Remove from $ex_fid_ary any of the 'can read topics' forums (meaning they will not be excluded from the search)
254+
// The user could get here from a quick search through the viewforum page, or by doing a main search displayed by topics and searching only the topic titles.
255+
// Allow the 'can read topics = yes' forums back in to the search by removing from $ex_fid_ary any of the 'can read topics' forums
273256
$ex_fid_ary = array_diff($ex_fid_ary, array_keys($auth->acl_getf('f_list_topics', true)));
274257
}
275258

@@ -375,11 +358,6 @@
375358
$show_results = ($show_results == 'posts') ? 'posts' : 'topics';
376359
}
377360

378-
if ($show_topic_title_only)
379-
{
380-
$show_results = 'topics';
381-
}
382-
383361
// define some variables needed for retrieving post_id/topic_id information
384362
$sort_by_sql = [
385363
'a' => 'u.username_clean',

phpBB/viewforum.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,18 @@
384384
// Display active topics?
385385
$s_display_active = ($forum_data['forum_type'] == FORUM_CAT && ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
386386

387-
// Send the forum id and send a parameter to make it clear it's a quick search
387+
// Send the forum id... and maybe some other fields, depending on permissions
388388
$s_search_hidden_fields = [
389389
'fid' => [$forum_id],
390-
'viewforum' => $forum_id,
391390
];
392391

392+
if ($auth->acl_get('f_list_topics', $forum_id) && !$auth->acl_get('f_read', $forum_id))
393+
{
394+
// If the user has list access but not read access, then force the search to only be a topic title search
395+
$s_search_hidden_fields['sr'] = 'topics';
396+
$s_search_hidden_fields['sf'] = 'titleonly';
397+
}
398+
393399
if ($_SID)
394400
{
395401
$s_search_hidden_fields['sid'] = $_SID;

0 commit comments

Comments
 (0)