Use real post layout for search page.
This commit is contained in:
parent
84e9345657
commit
4a3afa9fb0
4 changed files with 49 additions and 21 deletions
|
@ -5,19 +5,7 @@ $searchQuery = !empty($_GET['q']) && is_string($_GET['q']) ? $_GET['q'] : '';
|
|||
|
||||
if (!empty($searchQuery)) {
|
||||
$forumTopics = forum_topic_listing_search($searchQuery, user_session_current('user_id', 0));
|
||||
|
||||
$findForumPosts = db_prepare('
|
||||
SELECT fp.`post_id`, fp.`post_text`, ft.`topic_title`, u.`username`
|
||||
FROM `msz_forum_posts` AS fp
|
||||
LEFT JOIN `msz_forum_topics` AS ft
|
||||
ON ft.`topic_id` = fp.`topic_id`
|
||||
LEFT JOIN `msz_users` AS u
|
||||
ON u.`user_id` = fp.`user_id`
|
||||
WHERE MATCH(fp.`post_text`)
|
||||
AGAINST (:query IN NATURAL LANGUAGE MODE);
|
||||
');
|
||||
$findForumPosts->bindValue('query', $searchQuery);
|
||||
$forumPosts = db_fetch_all($findForumPosts);
|
||||
$forumPosts = forum_post_search($searchQuery);
|
||||
|
||||
$findUsers = db_prepare(sprintf(
|
||||
'
|
||||
|
|
|
@ -131,6 +131,50 @@ function forum_post_get(int $postId, bool $allowDeleted = false): array
|
|||
return db_fetch($getPost);
|
||||
}
|
||||
|
||||
function forum_post_search(string $query): array
|
||||
{
|
||||
$searchPosts = db_prepare('
|
||||
SELECT
|
||||
p.`post_id`, p.`post_text`, p.`post_created`, p.`post_parse`, p.`post_display_signature`,
|
||||
p.`topic_id`, p.`post_deleted`, p.`post_edited`, p.`topic_id`, p.`forum_id`,
|
||||
INET6_NTOA(p.`post_ip`) AS `post_ip`,
|
||||
u.`user_id` AS `poster_id`, u.`username` AS `poster_name`,
|
||||
u.`user_created` AS `poster_joined`, u.`user_country` AS `poster_country`,
|
||||
u.`user_signature_content` AS `poster_signature_content`, u.`user_signature_parser` AS `poster_signature_parser`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) AS `poster_colour`,
|
||||
COALESCE(u.`user_title`, r.`role_title`) AS `poster_title`,
|
||||
(
|
||||
SELECT COUNT(`post_id`)
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `user_id` = p.`user_id`
|
||||
AND `post_deleted` IS NULL
|
||||
) AS `poster_post_count`,
|
||||
(
|
||||
SELECT MIN(`post_id`) = p.`post_id`
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = p.`topic_id`
|
||||
) AS `is_opening_post`,
|
||||
(
|
||||
SELECT `user_id` = u.`user_id`
|
||||
FROM `msz_forum_posts`
|
||||
WHERE `topic_id` = p.`topic_id`
|
||||
ORDER BY `post_id`
|
||||
LIMIT 1
|
||||
) AS `is_original_poster`
|
||||
FROM `msz_forum_posts` AS p
|
||||
LEFT JOIN `msz_users` AS u
|
||||
ON u.`user_id` = p.`user_id`
|
||||
LEFT JOIN `msz_roles` AS r
|
||||
ON r.`role_id` = u.`display_role`
|
||||
WHERE MATCH(p.`post_text`)
|
||||
AGAINST (:query IN NATURAL LANGUAGE MODE)
|
||||
AND `post_deleted` IS NULL
|
||||
ORDER BY `post_id`
|
||||
');
|
||||
$searchPosts->bindValue('query', $query);
|
||||
return db_fetch_all($searchPosts);
|
||||
}
|
||||
|
||||
function forum_post_count_user(int $userId, bool $showDeleted = false): int
|
||||
{
|
||||
$getPosts = db_prepare(sprintf(
|
||||
|
|
|
@ -210,9 +210,9 @@ function perms_get_role_raw(int $role): array
|
|||
return $perms;
|
||||
}
|
||||
|
||||
function perms_check(int $perms, int $perm): bool
|
||||
function perms_check(?int $perms, ?int $perm): bool
|
||||
{
|
||||
return ($perms & $perm) > 0;
|
||||
return (($perms ?? 0) & ($perm ?? 0)) > 0;
|
||||
}
|
||||
|
||||
function perms_check_user(string $prefix, ?int $userId, int $perm): bool
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
{% from 'macros.twig' import container_title %}
|
||||
{% from '_layout/input.twig' import input_text %}
|
||||
{% from 'user/macros.twig' import user_card %}
|
||||
{% from 'forum/macros.twig' import forum_topic_listing %}
|
||||
{% from 'forum/macros.twig' import forum_topic_listing, forum_post_listing %}
|
||||
|
||||
{% set title = search_query|length < 1 ? 'Search' : 'Looking for ' ~ search_query %}
|
||||
{% set canonical_url = url('search-query', {'query': search_query}) %}
|
||||
|
@ -86,11 +86,7 @@
|
|||
<div class="container search__container">
|
||||
{{ container_title('<i class="fas fa-comment fa-fw"></i> Posts (%s)'|format(forum_posts|length|number_format)) }}
|
||||
|
||||
{% for post in forum_posts %}
|
||||
<a href="{{ url('forum-post', {'post': post.post_id, 'post_fragment': 'p' ~ post.post_id}) }}" class="link">
|
||||
Reply by {{ post.username }} in "{{ post.topic_title }}"
|
||||
</a><br>
|
||||
{% endfor %}
|
||||
{{ forum_post_listing(forum_posts) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue