summaryrefslogtreecommitdiff
path: root/src/application/templates/modern/search.twig
blob: 3546f4187db1c3133a0d5ab1c8bc37b36084a691 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{% set title = __("Search") %}
{% set formId = "search" %}
{% set formError = getAndClearFormError(formId) %}

{% extends "base.twig" %}

{% block content %}

<div class="page-header">
    <h1>{{ __("Search") }}</h1>
</div>

{% if formError %}
    {% include "components/alert_error.twig" with { message: formError } %}
{% endif %}

<form action="." method="get">
    <input type="hidden" name="form_id" value="{{ formId }}">
    <input type="hidden" name="_action" value="search">
    <div class="spring-row">
        <div class="spring-fill">
            <input type="search" id="i_query" name="query" value="{{ lastFormField(formId, "query")|default(g.get.query)|default("") }}" required autofocus placeholder="{{ __("Enter your search query...") }}">
        </div>
        <div class="spring-fit">
            <button class="btn btn-primary" type="submit">{{ __("Search") }}</button>
        </div>
    </div>
</form>

{% if g.get.query is defined and g.get.query is not null and g.get.query != "" %}
    {% if ctx.posts|length > 0 %}
        <p>{{ __("%result_count% result(s) in %search_duration% second(s)", {
            "result_count": ctx.posts|length,
            "search_duration": ctx.search_duration|number_format(2, __(".", context: "Number formatting"), __(",", context: "Number formatting")),
        }) }}</p>
        <div class="post-list">
            {% for post in ctx.posts|filter(p => not p.deleted) %}
                {% set hasAttachments = ctx.attachments[post.id]|length > 0 %}
                {% set postAuthor = ctx.users[post.authorId] %}
                <a href="?_action=viewtopic&amp;topic={{ post.topicId|url_encode }}#post-{{ post.id|url_encode }}" class="_item">
                    <h4 class="_heading">
                        {% if hasAttachments %}
                            <span class="badge">
                                <svg viewBox="0 0 24 24" class="icon"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>
                            </span>
                        {% endif %}
                        {{ renderPostSummary(post.content) }}<br>
                    </h4>
                    <span class="text-muted _text">{{ __("posted by %author% on %post_date% in %topic%", {
                        "author": '<em>' ~ (postAuthor ? postAuthor.displayName : __("unknown"))|e("html") ~ '</em>',
                        "post_date": '<span class="_time">' ~ post.postDate.format("c")|e("html") ~ '</span>',
                        "topic": '<em>'
                            ~ (ctx.topics[post.topicId].isLocked ? '<svg viewBox="0 0 24 24" class="icon text-muted"><rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/></svg> ' : '')
                            ~ (ctx.topics[post.topicId] ? ctx.topics[post.topicId].title : null)|default(__("unknown"))|e("html") ~ '</em>',
                    }) }}</span>
                </a>
            {% endfor %}
        </div>
    {% else %}
        <div class="result-alert">
            <div class="alert alert-info">
                <svg viewBox="0 0 24 24" class="icon"><circle cx="12" cy="12" r="10"/><path d="M12 16v-4"/><path d="M12 8h.01"/></svg>
                <span>{{ __("No results for this search") }}</span>
            </div>
        </div>
    {% endif %}
{% endif %}

{% endblock %}