Skip to content

Node.js based forum software built for the modern web

hiding search buttons and route when search is not configured

Julian Lam2ba11dce15e6
diff --git a/public/templates/header.tpl b/public/templates/header.tpl
index c84294f8e5..5e4c0e2d4a 100644
--- a/public/templates/header.tpl
+++ b/public/templates/header.tpl
@@ -76,9 +76,11 @@
</li>
<!-- ENDIF isAdmin -->
+ <!-- IF searchEnabled -->
<li class="visible-xs">
<a id="mobile-search-button" href="{relative_path}/search"><i class="fa fa-search fa-fw" title="[[global:header.search]]"></i> [[global:header.search]]</a>
</li>
+ <!-- ENDIF searchEnabled -->
<!-- BEGIN navigation -->
<li class="{navigation.class}">
@@ -167,6 +169,7 @@
</li>
</ul>
+ <!-- IF searchEnabled -->
<ul id="logged-conditional-menu" class="nav navbar-nav navbar-right">
<li>
<form id="search-form" class="navbar-form navbar-right hidden-xs" role="search" method="GET" action="">
@@ -180,6 +183,7 @@
</form>
</li>
</ul>
+ <!-- ENDIF searchEnabled -->
<ul class="nav navbar-nav navbar-right pagination-block hide">
<li class="active">
diff --git a/src/routes/api.js b/src/routes/api.js
index 74c434010a..12205e4353 100644
--- a/src/routes/api.js
+++ b/src/routes/api.js
@@ -361,6 +361,10 @@ var path = require('path'),
});
app.get('/search/:term', function (req, res, next) {
+ if (!Plugins.hasListeners('filter:search.query')) {
+ return res.redirect('/404');
+ }
+
var limit = 50;
function searchPosts(callback) {
diff --git a/src/webserver.js b/src/webserver.js
index d6fe44bbbd..ea8e73521f 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -104,7 +104,8 @@ module.exports.server = server;
clientScripts: clientScripts,
navigation: custom_header.navigation,
'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '',
- allowRegistration: meta.config.allowRegistration === undefined || parseInt(meta.config.allowRegistration, 10) === 1
+ allowRegistration: meta.config.allowRegistration === undefined || parseInt(meta.config.allowRegistration, 10) === 1,
+ searchEnabled: plugins.hasListeners('filter:search.query') ? true : false
},
escapeList = {
'&': '&amp;',