Skip to content

Node.js based forum software built for the modern web

refactor: move search, filters and results to core

Barış Soner Uşaklı8b00bf2cd801
diff --git a/install/package.json b/install/package.json
index 7b2a7bc8a1..e170be3283 100644
--- a/install/package.json
+++ b/install/package.json
@@ -112,10 +112,10 @@
"nodebb-plugin-spam-be-gone": "2.3.3",
"nodebb-plugin-web-push": "0.7.10",
"nodebb-rewards-essentials": "1.0.3",
- "nodebb-theme-harmony": "3.0.7",
+ "nodebb-theme-harmony": "3.0.8",
"nodebb-theme-lavender": "8.0.4",
- "nodebb-theme-peace": "3.0.3",
- "nodebb-theme-persona": "15.0.6",
+ "nodebb-theme-peace": "3.0.4",
+ "nodebb-theme-persona": "15.0.7",
"nodebb-widget-essentials": "8.0.0",
"nodemailer": "8.0.11",
"nprogress": "0.2.0",
diff --git a/public/src/modules/helpers.common.js b/public/src/modules/helpers.common.js
index 409cc8a48a..d6c5ec47ab 100644
--- a/public/src/modules/helpers.common.js
+++ b/public/src/modules/helpers.common.js
@@ -166,9 +166,10 @@ module.exports = function (utils, Benchpress, tx, relative_path) {
tag = 'span';
}
const href = tag === 'a' ? `href="${relative_path}/category/${escape(category.slug)}"` : '';
+ const categoryName = stripTags(_tx.call(this, String(category.name)));
return `<${tag} component="topic/category" ${href} class="badge px-1 text-truncate text-decoration-none ${className}" style="color: ${color};background-color: ${bgColor};border-color: ${bgColor}!important; max-width: 70vw;">
${icon && icon !== 'fa-nbb-none' ? `<i class="fa fa-fw ${icon}"></i>` : ''}
- ${_tx.call(this, String(category.name))}
+ ${categoryName}
</${tag}>`;
}
diff --git a/src/views/admin/partials/breadcrumbs.tpl b/src/views/admin/partials/breadcrumbs.tpl
index b5bea23fa9..50600ede92 100644
--- a/src/views/admin/partials/breadcrumbs.tpl
+++ b/src/views/admin/partials/breadcrumbs.tpl
@@ -4,7 +4,7 @@
<li{{{ if @last }}} component="breadcrumb/current"{{{ end }}} itemscope="itemscope" itemprop="itemListElement" itemtype="http://schema.org/ListItem" class="breadcrumb-item {{{ if @last }}}active{{{ end }}}">
<meta itemprop="position" content="{@index}" />
{{{ if ./url }}}<a href="{./url}" itemprop="item">{{{ end }}}
- <span class="fw-semibold" itemprop="name">{{tx(./text)}}</span>
+ <span class="fw-semibold" itemprop="name">{{stripTags(tx(./text))}}</span>
{{{ if ./url }}}</a>{{{ end }}}
</li>
{{{ end }}}
diff --git a/src/views/admin/partials/category/selector-dropdown-content.tpl b/src/views/admin/partials/category/selector-dropdown-content.tpl
index ed624775b2..45c4e72697 100644
--- a/src/views/admin/partials/category/selector-dropdown-content.tpl
+++ b/src/views/admin/partials/category/selector-dropdown-content.tpl
@@ -3,11 +3,11 @@
{{{ if (selectedCategory && !showCategorySelectLabel) }}}
<span class="category-item d-inline-flex align-items-center gap-1">
{{buildCategoryIcon(selectedCategory, "24px", "rounded-circle")}}
- <span class="fw-semibold text-truncate" style="max-width:200px;">{tx(selectedCategory.name)}</span>
+ <span class="fw-semibold text-truncate" style="max-width:200px;">{{stripTags(tx(selectedCategory.name))}}</span>
</span>
{{{ else }}}
<i class="fa fa-fw {{{ if selectCategoryIcon }}}{selectCategoryIcon}{{{ else }}}fa-list{{{ end }}}"></i>
- {{{ if selectCategoryLabel }}}{tx(selectCategoryLabel)}{{{ else }}}[[topic:thread-tools.select-category]]{{{ end }}}
+ {{{ if selectCategoryLabel }}}{{stripTags(tx(selectCategoryLabel))}}{{{ else }}}[[topic:thread-tools.select-category]]{{{ end }}}
{{{ end }}}
</span>
<span class="caret"></span>
@@ -31,7 +31,7 @@
{{{ if ./icon }}}
{{buildCategoryIcon(@value, "24px", "rounded-circle")}}
{{{ end }}}
- {./name}
+ {{stripTags(tx(./name))}}
</div>
</span>
</a>
diff --git a/src/views/partials/category/filter-dropdown-content.tpl b/src/views/partials/category/filter-dropdown-content.tpl
index 293a1c3c67..145799b710 100644
--- a/src/views/partials/category/filter-dropdown-content.tpl
+++ b/src/views/partials/category/filter-dropdown-content.tpl
@@ -2,7 +2,7 @@
{{{ if selectedCategory }}}
<span class="category-item d-inline-flex align-items-center gap-1">
{{buildCategoryIcon(selectedCategory, "18px", "rounded-circle")}}
- <span class="d-none d-md-inline fw-semibold">{selectedCategory.name}</span>
+ <span class="d-none d-md-inline fw-semibold">{{stripTags(tx(selectedCategory.name))}}</span>
</span>
{{{ else }}}
<i class="fa fa-fw fa-list text-primary"></i>
@@ -35,7 +35,7 @@
{{{ if ./icon }}}
{{buildCategoryIcon(@value, "24px", "rounded-circle")}}
{{{ end }}}
- <span class="category-name">{tx(./name)}</span>
+ <span class="category-name">{{stripTags(tx(./name))}}</span>
</div>
</span>
<i component="category/select/icon" class="flex-shrink-0 fa fa-fw fa-check {{{ if !./selected }}}invisible{{{ end }}}"></i>
diff --git a/src/views/partials/category/selector-dropdown-content.tpl b/src/views/partials/category/selector-dropdown-content.tpl
index 1b71a40e57..9a6b10483d 100644
--- a/src/views/partials/category/selector-dropdown-content.tpl
+++ b/src/views/partials/category/selector-dropdown-content.tpl
@@ -3,11 +3,11 @@
{{{ if (selectedCategory && !showCategorySelectLabel) }}}
<span class="category-item d-inline-flex align-items-center gap-1">
{{buildCategoryIcon(selectedCategory, "24px", "rounded-circle")}}
- <span class="category-name">{tx(selectedCategory.name)}</span>
+ <span class="category-name">{{stripTags(tx(selectedCategory.name))}}</span>
</span>
{{{ else }}}
<i class="fa fa-fw {{{ if selectCategoryIcon }}}{selectCategoryIcon}{{{ else }}}fa-list{{{ end }}} text-primary"></i>
- <span class="d-none d-md-inline">{{{ if selectCategoryLabel }}}{tx(selectCategoryLabel)}{{{ else }}}[[topic:thread-tools.select-category]]{{{ end }}}</span>
+ <span class="d-none d-md-inline">{{{ if selectCategoryLabel }}}{{stripTags(tx(selectCategoryLabel))}}{{{ else }}}[[topic:thread-tools.select-category]]{{{ end }}}</span>
{{{ end }}}
</span>
</button>
@@ -29,7 +29,7 @@
{{{ if ./icon }}}
{{buildCategoryIcon(@value, "24px", "rounded-circle")}}
{{{ end }}}
- <span class="category-name">{tx(./name)}</span>
+ <span class="category-name">{{stripTags(tx(./name))}}</span>
</span>
</span>
</a>
diff --git a/src/views/partials/flags/filters.tpl b/src/views/partials/flags/filters.tpl
index cc97cb286f..02ec5f0701 100644
--- a/src/views/partials/flags/filters.tpl
+++ b/src/views/partials/flags/filters.tpl
@@ -16,7 +16,7 @@
{{{ if selectedCategory }}}
<span class="category-item d-inline-flex align-items-baseline gap-1">
{{buildCategoryIcon(selectedCategory, "18px", "rounded-circle align-self-center")}}
- <span class="visible-md-inline visible-lg-inline">{tx(selectedCategory.name)}</span>
+ <span class="visible-md-inline visible-lg-inline">{{stripTags(tx(selectedCategory.name))}}</span>
</span>
{{{ else }}}
<span class="visible-md-inline visible-lg-inline">[[unread:all-categories]]</span>
diff --git a/src/views/partials/search/filters.tpl b/src/views/partials/search/filters.tpl
new file mode 100644
index 0000000000..4b31117d9f
--- /dev/null
+++ b/src/views/partials/search/filters.tpl
@@ -0,0 +1,184 @@
+<div class="d-flex flex-wrap gap-2 align-items-center" component="search/filters">
+ <!-- category filter -->
+ <div class="post-search-item">
+ <div component="category/filter" class="dropdown" data-filter-name="category">
+ <a component="category/filter/button" class="filter-btn btn btn-light btn-sm border {{{ if filters.categories.active }}}active-filter{{{ end }}} dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-haspopup="true" aria-expanded="false">
+ <span class="filter-label">{{{ if filters.categories.active }}}{{stripTags(tx(filters.categories.label))}}{{{ else }}}[[search:categories]]{{{ end }}}</span>
+ <span class="caret text-primary opacity-75"></span>
+ </a>
+
+ <ul class="dropdown-menu p-1 text-sm" role="menu">
+ <li class="px-2 py-1 mb-2 d-flex flex-column gap-2">
+ <div component="category-selector-search">
+ <input type="text" class="form-control form-control-sm" component="category/filter/search" placeholder="[[search:type-a-category]]">
+ </div>
+ </li>
+ <div component="category/list" class="overflow-auto ghost-scrollbar" style="max-height: 350px;"></div>
+ <div class="px-3 py-1 border-top">
+ <div class="form-check">
+ <input id="search-children" class="form-check-input" type="checkbox"/>
+ <label class="form-check-label" for="search-children">[[search:search-child-categories]]</label>
+ </div>
+ </div>
+ </ul>
+ </div>
+ </div>
+
+
+ <!-- tag filter -->
+ <div class="post-search-item">
+ <div component="tag/filter" class="dropdown" data-filter-name="tag">
+ <a component="tag/filter/button" class="filter-btn btn btn-light btn-sm border {{{ if filters.tags.active }}}active-filter{{{ end }}} dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-haspopup="true" aria-expanded="false">
+ <span class="filter-label">{{{ if filters.tags.active }}}{{tx(filters.tags.label)}}{{{ else }}}[[search:tags]]{{{ end }}}</span>
+ <span class="caret text-primary opacity-75"></span>
+ </a>
+
+ <ul class="dropdown-menu p-1 text-sm" style="width: 350px;" role="menu">
+ <li class="px-2 py-1 d-flex flex-column gap-2">
+ <input type="text" class="form-control form-control-sm" component="tag/filter/search" placeholder="[[search:type-a-tag]]">
+ <div component="tag/filter/selected" class="d-flex flex-wrap gap-2">
+ {{{ each tagFilterSelected }}}
+ <div class="d-flex px-2 py-1 rounded-1 text-bg-primary gap-2 align-items-center text-sm">
+ <div>{./value}</div>
+ <button component="tag/filter/delete" data-tag="{./value}" class="btn btn-primary btn-sm py-0"><i class="fa fa-times fa-xs"></i></button>
+ </div>
+ {{{ end }}}
+ </div>
+ <hr class="my-2"/>
+ <div component="tag/filter/results" class="d-flex flex-wrap gap-2">
+ {{{ each tagFilterResults }}}
+ <button class="btn btn-light btn-sm border" data-tag="{./value}">{./value}</button>
+ {{{ end }}}
+ </div>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <!-- user name filter -->
+ <div class="post-search-item">
+ <div component="user/filter" class="dropdown" data-filter-name="user">
+ <a component="user/filter/button" class="filter-btn btn btn-light btn-sm border {{{ if filters.users.active }}}active-filter{{{ end }}} dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" data-bs-auto-close="outside" aria-haspopup="true" aria-expanded="false">
+ <span class="filter-label">{{{ if filters.users.active }}}{{tx(filters.users.label)}}{{{ else }}}[[search:posted-by]]{{{ end }}}</span>
+ <span class="caret text-primary opacity-75"></span>
+ </a>
+
+ <ul class="dropdown-menu p-1 text-sm" style="width: 350px;" role="menu">
+ <li class="px-2 py-1 d-flex flex-column gap-2">
+ <input type="text" class="form-control form-control-sm" component="user/filter/search" placeholder="[[search:type-a-username]]">
+ <div component="user/filter/selected" class="d-flex flex-wrap gap-2">
+ {{{ each userFilterSelected }}}
+ <div class="d-flex px-2 py-1 rounded-1 text-bg-primary gap-2 align-items-center text-sm">
+ {{buildAvatar(@value, "16px", true)}} {./username}
+ <button component="user/filter/delete" data-uid="{./uid}" class="btn btn-primary btn-sm py-0"><i class="fa fa-times fa-xs"></i></button>
+ </div>
+ {{{ end }}}
+ </div>
+ <hr class="my-2"/>
+ <div component="user/filter/results" class="d-flex flex-wrap gap-2">
+ {{{ each userFilterResults }}}
+ <button class="btn btn-light btn-sm border" data-uid="{./uid}" data-username="{./username}">{{buildAvatar(@value, "16px", true)}} {./username}</button>
+ {{{ end }}}
+ </div>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+
+ <!-- reply count filter -->
+ <div class="post-search-item">
+ <div class="dropdown" data-filter-name="replies">
+ <a id="reply-count-button" class="filter-btn btn btn-light btn-sm border {{{ if filters.replies.active }}}active-filter{{{ end }}} dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ <span class="filter-label">{{{ if filters.replies.active }}}{tx(filters.replies.label)}}{{{ else }}}[[search:replies]]{{{ end }}}</span>
+ <span class="caret text-primary opacity-75"></span>
+ </a>
+
+ <ul class="dropdown-menu p-1 text-sm" style="width: 300px;" role="menu">
+ <li class="px-2 py-1 d-flex flex-nowrap gap-2">
+ <select id="reply-count-filter" class="form-select form-select-sm">
+ <option value="atleast">[[search:at-least]]</option>
+ <option value="atmost">[[search:at-most]]</option>
+ </select>
+ <input id="reply-count" type="number" min="0" class="form-control form-control-sm" />
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <!-- time filter -->
+ <div class="post-search-item">
+ <div class="dropdown" data-filter-name="time">
+ <a id="post-time-button" class="filter-btn btn btn-light btn-sm border {{{ if filters.time.active }}}active-filter{{{ end }}} dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ <span class="filter-label">{{{ if filters.time.active }}}{tx(filters.time.label)}{{{ else }}}[[search:time]]{{{ end }}}</span>
+ <span class="caret text-primary opacity-75"></span>
+ </a>
+
+ <ul class="dropdown-menu p-1 text-sm" style="width: 350px;" role="menu">
+ <li class="px-2 py-1 d-flex flex-nowrap gap-2">
+ <select id="post-time-filter" class="form-select form-select-sm">
+ <option value="newer">[[search:newer-than]]</option>
+ <option value="older">[[search:older-than]]</option>
+ </select>
+ <select id="post-time-range" class="form-select form-select-sm">
+ <option value="">[[search:any-date]]</option>
+ <option value="86400">[[search:yesterday]]</option>
+ <option value="604800">[[search:one-week]]</option>
+ <option value="1209600">[[search:two-weeks]]</option>
+ <option value="2592000">[[search:one-month]]</option>
+ <option value="7776000">[[search:three-months]]</option>
+ <option value="15552000">[[search:six-months]]</option>
+ <option value="31104000">[[search:one-year]]</option>
+ </select>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <!-- sort filter -->
+ <div class="post-search-item">
+ <div class="dropdown" data-filter-name="sort">
+ <a id="sort-by-button" class="filter-btn btn btn-light btn-sm border {{{ if filters.sort.active }}}active-filter{{{ end }}} dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ <span class="filter-label">{{{ if filters.sort.active }}}{tx(filters.sort.label)}{{{ else }}}[[search:sort]]{{{ end }}}</span>
+ <span class="caret text-primary opacity-75"></span>
+ </a>
+
+ <ul class="dropdown-menu p-1 text-sm" style="width: 250px;" role="menu">
+ <li class="px-2 py-1 d-flex flex-column gap-2">
+ <select id="post-sort-by" class="form-select form-select-sm">
+ <option value="relevance">[[search:relevance]]</option>
+ <option value="timestamp">[[search:post-time]]</option>
+ <option value="votes">[[search:votes]]</option>
+ <option value="topic.lastposttime">[[search:last-reply-time]]</option>
+ <option value="topic.title">[[search:topic-title]]</option>
+ <option value="topic.postcount">[[search:number-of-replies]]</option>
+ <option value="topic.viewcount">[[search:number-of-views]]</option>
+ <option value="topic.votes">[[search:topic-votes]]</option>
+ <option value="topic.timestamp">[[search:topic-start-date]]</option>
+ <option value="user.username">[[search:username]]</option>
+ <option value="category.name">[[search:category]]</option>
+ </select>
+ <select id="post-sort-direction" class="form-select form-select-sm">
+ <option value="desc">[[search:descending]]</option>
+ <option value="asc">[[search:ascending]]</option>
+ </select>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <!-- save & reset preferences -->
+ <div class="post-search-item">
+ <div class="dropdown">
+ <a class="btn btn-light btn-sm border border-gray-300 dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">[[search:save]] <span class="caret text-primary opacity-75"></span>
+ </a>
+
+ <ul class="dropdown-menu p-1 text-sm" style="width: 300px;" role="menu">
+ <li class="px-2 py-1 d-flex flex-column gap-2">
+ <button id="save-preferences" class="btn btn-sm btn-primary">[[search:save-preferences]]</button>
+ <button id="clear-preferences" class="btn btn-sm btn-ghost border">[[search:clear-preferences]]</button>
+ </li>
+ </ul>
+ </div>
+ </div>
+</div>
\ No newline at end of file
diff --git a/src/views/partials/search/results.tpl b/src/views/partials/search/results.tpl
new file mode 100644
index 0000000000..0b198cc68e
--- /dev/null
+++ b/src/views/partials/search/results.tpl
@@ -0,0 +1,55 @@
+{{{ if matchCount }}}
+<div class="card card-header text-xs px-2 py-1 fw-semibold border-0 align-self-start">{{tx("search:results-matching", matchCount, txEscape(search_query), time)}}</div>
+{{{ else }}}
+{{{ if search_query }}}
+<div class="badge text-bg-warning align-self-start">[[search:no-matches]]</div>
+{{{ end }}}
+{{{ end }}}
+
+<div id="results" class="search-results" data-search-query="{search_query}">
+ {{{ if showAsPosts }}}
+ {{{ if posts.length }}}
+ <!-- IMPORT partials/posts_list.tpl -->
+ {{{ end }}}
+ {{{ end }}}
+
+ {{{ if showAsTopics }}}
+ {{{ each posts }}}
+ <hr/>
+ <div class="topic-row mb-3">
+ <a class="topic-title fw-semibold fs-5 text-reset text-break" href="{config.relative_path}/post/{encodeURIComponent(./pid)}">
+ {{{ if !./isMainPost }}}RE: {{{ end }}}{./topic.title}
+ </a>
+ <div class="post-body d-flex flex-column gap-1">
+ <div class="d-flex gap-3 post-info">
+ <div class="post-author d-flex gap-1">
+ <a class="lh-1 text-decoration-none" href="{config.relative_path}/user/{./user.userslug}">{{buildAvatar(./user, "16px", true, "not-responsive")}}</a>
+ <a class="fw-semibold text-sm" href="{config.relative_path}/user/{./user.userslug}">{./user.displayname}</a>
+ </div>
+ <span class="timeago text-sm text-muted" title="{./timestampISO}"></span>
+ </div>
+ </div>
+ </div>
+ {{{ end }}}
+ {{{ end }}}
+
+ {{{ if users.length }}}
+ <!-- IMPORT partials/users_list.tpl -->
+ {{{ end }}}
+
+ {{{ if tags.length }}}
+ <div class="tag-list row row-cols-2 row-cols-lg-3 row-cols-xl-4 gx-3 gy-2">
+ <!-- IMPORT partials/tags_list.tpl -->
+ </div>
+ {{{ end }}}
+
+ {{{ if categories.length }}}
+ <ul class="categories list-unstyled">
+ {{{each categories}}}
+ <!-- IMPORT partials/categories/item.tpl -->
+ {{{end}}}
+ </ul>
+ {{{ end }}}
+
+ <!-- IMPORT partials/paginator.tpl -->
+</div>
\ No newline at end of file
diff --git a/src/views/search.tpl b/src/views/search.tpl
new file mode 100644
index 0000000000..242e5690fd
--- /dev/null
+++ b/src/views/search.tpl
@@ -0,0 +1,46 @@
+<div class="search flex-fill">
+ <div id="advanced-search" class="d-flex flex-column flex-md-row">
+ <!-- sidebar -->
+ <div class="flex-shrink-0 pe-2 border-end-md text-sm mb-3" style="flex-basis: 240px!important;">
+ <form action="{config.relative_path}/search" method="get" class="nav sticky-md-top d-flex flex-row flex-md-column flex-wrap gap-3 pe-md-3" style="top: 1rem; z-index: 1;">
+ <h2 class="fw-semibold tracking-tight mb-0">[[global:search]]</h2>
+
+ <input id="search-input" name="term" type="text" class="form-control fw-semibold py-2 ps-2 pe-3" id="search-input" placeholder="[[search:type-to-search]]">
+
+ <select id="search-in" name="in" class="form-select text-sm py-2 ps-2 pe-3">
+ <option value="titlesposts">[[search:in-titles-posts]]</option>
+ <option value="titles">[[search:in-titles]]</option>
+ <option value="posts">[[search:in-posts]]</option>
+ <option value="bookmarks">[[search:in-bookmarks]]</option>
+ <option value="categories">[[search:in-categories]]</option>
+ {{{if privileges.search:users}}}
+ <option value="users">[[search:in-users]]</option>
+ {{{end}}}
+ {{{if privileges.search:tags}}}
+ <option value="tags">[[search:in-tags]]</option>
+ {{{end}}}
+ </select>
+
+ <select id="match-words-filter" name="matchWords" class="post-search-item form-select text-sm py-2 ps-2 pe-3">
+ <option value="all">[[search:match-all-words]]</option>
+ <option value="any">[[search:match-any-word]]</option>
+ </select>
+
+ <select id="show-results-as" name="showAs" class="post-search-item form-select text-sm py-2 ps-2 pe-3">
+ <option value="posts" selected>[[search:show-results-as-posts]]</option>
+ <option value="topics">[[search:show-results-as-topics]]</option>
+ </select>
+
+ <button type="submit" class="btn btn-primary fw-semibold form-control py-2 px-3">[[global:search]]</button>
+ </form>
+ </div>
+
+ <!-- filters and search results -->
+ <div class="flex-grow-1 ps-md-2 ps-lg-5" style="min-width:0;">
+ <div class="d-flex flex-column gap-3">
+ <!-- IMPORT partials/search/filters.tpl -->
+ <!-- IMPORT partials/search/results.tpl -->
+ </div>
+ </div>
+ </div>
+</div>