Use news_preview macrro for search results.
This commit is contained in:
parent
4a3afa9fb0
commit
f5d693f24b
3 changed files with 35 additions and 12 deletions
|
@ -6,6 +6,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));
|
||||
$forumPosts = forum_post_search($searchQuery);
|
||||
$newsPosts = news_posts_search($searchQuery);
|
||||
|
||||
$findUsers = db_prepare(sprintf(
|
||||
'
|
||||
|
@ -64,15 +65,6 @@ if (!empty($searchQuery)) {
|
|||
$findUsers->bindValue('query', $searchQuery);
|
||||
$findUsers->bindValue('current_user_id', user_session_current('user_id', 0));
|
||||
$users = db_fetch_all($findUsers);
|
||||
|
||||
$findNewsPosts = db_prepare('
|
||||
SELECT `post_id`, `post_title`, `post_text`
|
||||
FROM `msz_news_posts`
|
||||
WHERE MATCH(`post_title`, `post_text`)
|
||||
AGAINST (:query IN NATURAL LANGUAGE MODE);
|
||||
');
|
||||
$findNewsPosts->bindValue('query', $searchQuery);
|
||||
$newsPosts = db_fetch_all($findNewsPosts);
|
||||
}
|
||||
|
||||
echo tpl_render('home.search', [
|
||||
|
|
32
src/news.php
32
src/news.php
|
@ -264,6 +264,38 @@ function news_posts_get(
|
|||
return db_fetch_all($getPosts);
|
||||
}
|
||||
|
||||
function news_posts_search(string $query): array {
|
||||
$searchPosts = db_prepare('
|
||||
SELECT
|
||||
p.`post_id`, p.`post_is_featured`, p.`post_title`, p.`post_text`, p.`comment_section_id`,
|
||||
p.`post_created`, p.`post_updated`, p.`post_deleted`, p.`post_scheduled`,
|
||||
c.`category_id`, c.`category_name`,
|
||||
u.`user_id`, u.`username`,
|
||||
COALESCE(u.`user_colour`, r.`role_colour`) as `user_colour`,
|
||||
(
|
||||
SELECT COUNT(`comment_id`)
|
||||
FROM `msz_comments_posts`
|
||||
WHERE `category_id` = `comment_section_id`
|
||||
AND `comment_deleted` IS NULL
|
||||
) as `post_comments`
|
||||
FROM `msz_news_posts` as p
|
||||
LEFT JOIN `msz_news_categories` as c
|
||||
ON p.`category_id` = c.`category_id`
|
||||
LEFT JOIN `msz_users` as u
|
||||
ON p.`user_id` = u.`user_id`
|
||||
LEFT JOIN `msz_roles` as r
|
||||
ON u.`display_role` = r.`role_id`
|
||||
WHERE MATCH(`post_title`, `post_text`)
|
||||
AGAINST (:query IN NATURAL LANGUAGE MODE)
|
||||
AND p.`post_deleted` IS NULL
|
||||
AND p.`post_scheduled` < NOW()
|
||||
ORDER BY p.`post_created` DESC
|
||||
');
|
||||
$searchPosts->bindValue('query', $query);
|
||||
|
||||
return db_fetch_all($searchPosts);
|
||||
}
|
||||
|
||||
function news_post_comments_set(int $postId, int $sectionId): void
|
||||
{
|
||||
db_prepare('
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
{% from '_layout/input.twig' import input_text %}
|
||||
{% from 'user/macros.twig' import user_card %}
|
||||
{% from 'forum/macros.twig' import forum_topic_listing, forum_post_listing %}
|
||||
{% from 'news/macros.twig' import news_preview %}
|
||||
|
||||
{% set title = search_query|length < 1 ? 'Search' : 'Looking for ' ~ search_query %}
|
||||
{% set canonical_url = url('search-query', {'query': search_query}) %}
|
||||
|
@ -110,9 +111,7 @@
|
|||
<div class="container search__container">
|
||||
{{ container_title('<i class="fas fa-newspaper fa-fw"></i> News (%s)'|format(news_posts|length|number_format)) }}
|
||||
{% for post in news_posts %}
|
||||
<a href="{{ url('news-post', {'post': post.post_id}) }}" class="link">
|
||||
{{ post.post_title }}
|
||||
</a><br>
|
||||
{{ news_preview(post) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
Loading…
Add table
Reference in a new issue