diff --git a/public/src/modules/search.js b/public/src/modules/search.js index 957032c47f..81b98e9ab3 100644 --- a/public/src/modules/search.js +++ b/public/src/modules/search.js @@ -11,7 +11,7 @@ define('search', ['navigator', 'translator'], function(nav, translator) { var term = data.term; // Detect if a tid was specified - var topicSearch = term.match(/in:topic-([\d]+)/); + var topicSearch = term.match(/^in:topic-([\d]+) /); if (!topicSearch) { term = term.replace(/^[ ?#]*/, ''); @@ -28,7 +28,9 @@ define('search', ['navigator', 'translator'], function(nav, translator) { var cleanedTerm = term.replace(topicSearch[0], ''), tid = topicSearch[1]; - Search.queryTopic(tid, cleanedTerm, callback); + if (cleanedTerm.length > 0) { + Search.queryTopic(tid, cleanedTerm, callback); + } } }; diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index 4569fb0d5b..42efe5c529 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -125,7 +125,7 @@ if (typeof language === 'function') { callback = language; if ('undefined' !== typeof window && config) { - language = config.userLang || 'en_GB'; + language = utils.params().lang || config.userLang || 'en_GB'; } else { var meta = require('../../../src/meta'); language = meta.config.defaultLang || 'en_GB'; diff --git a/src/categories.js b/src/categories.js index ac89bb4ac1..e033102264 100644 --- a/src/categories.js +++ b/src/categories.js @@ -156,7 +156,7 @@ var async = require('async'), } category.name = validator.escape(category.name); - category.disabled = parseInt(category.disabled, 10) === 1; + category.disabled = category.hasOwnProperty('disabled') ? parseInt(category.disabled, 10) === 1 : undefined; category.icon = category.icon || 'hidden'; if (category.hasOwnProperty('post_count')) { category.post_count = category.totalPostCount = category.post_count || 0; diff --git a/src/controllers/api.js b/src/controllers/api.js index 5518addd45..c09a96490d 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -64,7 +64,7 @@ apiController.getConfig = function(req, res, next) { config.maximumFileSize = meta.config.maximumFileSize; config['theme:id'] = meta.config['theme:id']; config.defaultLang = meta.config.defaultLang || 'en_GB'; - config.userLang = config.defaultLang; + config.userLang = req.query.lang || config.defaultLang; config.environment = process.env.NODE_ENV; config.loggedIn = !!req.user; config['cache-buster'] = meta.config['cache-buster'] || ''; @@ -89,7 +89,7 @@ apiController.getConfig = function(req, res, next) { config.topicsPerPage = settings.topicsPerPage; config.postsPerPage = settings.postsPerPage; config.notificationSounds = settings.notificationSounds; - config.userLang = settings.userLang || config.defaultLang; + config.userLang = req.query.lang || settings.userLang || config.defaultLang; config.openOutgoingLinksInNewTab = settings.openOutgoingLinksInNewTab; config.topicPostSort = settings.topicPostSort || config.topicPostSort; config.categoryTopicSort = settings.categoryTopicSort || config.categoryTopicSort; diff --git a/src/controllers/unread.js b/src/controllers/unread.js index 0354ea7310..672ec37542 100644 --- a/src/controllers/unread.js +++ b/src/controllers/unread.js @@ -30,11 +30,11 @@ unreadController.unread = function(req, res, next) { }, function(_results, next) { results = _results; - categories.getMultipleCategoryFields(results.watchedCategories, ['cid', 'name', 'slug', 'icon', 'link'], next); + categories.getMultipleCategoryFields(results.watchedCategories, ['cid', 'name', 'slug', 'icon', 'link', 'disabled'], next); }, function(categories, next) { categories = categories.filter(function(category) { - return category && !category.link; + return category && !category.link && !category.disabled; }); categories.forEach(function(category) { category.selected = parseInt(category.cid, 10) === parseInt(cid, 10); diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index 0c4cca5e3e..77951daf74 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -168,6 +168,7 @@ middleware.isAdmin = function(req, res, next) { middleware.buildHeader = function(req, res, next) { res.locals.renderHeader = true; + res.locals.isAPI = false; middleware.applyCSRF(req, res, function() { async.parallel({ @@ -347,6 +348,7 @@ middleware.processRender = function(req, res, next) { } str = template + str; var language = res.locals.config ? res.locals.config.userLang || 'en_GB' : 'en_GB'; + language = req.query.lang || language; translator.translate(str, language, function(translated) { fn(err, translated); }); diff --git a/src/posts/summary.js b/src/posts/summary.js index b41519473a..582354499d 100644 --- a/src/posts/summary.js +++ b/src/posts/summary.js @@ -72,6 +72,11 @@ module.exports = function(Posts) { }); async.map(posts, function(post, next) { + // If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest. + if (!results.users.hasOwnProperty(post.uid)) { + post.uid = 0; + } + post.user = results.users[post.uid]; post.topic = results.topics[post.tid]; post.category = results.categories[post.topic.cid]; diff --git a/src/topics/teaser.js b/src/topics/teaser.js index 4558fb251a..29e05703d2 100644 --- a/src/topics/teaser.js +++ b/src/topics/teaser.js @@ -57,6 +57,11 @@ module.exports = function(Topics) { var tidToPost = {}; async.each(postData, function(post, next) { + // If the post author isn't represented in the retrieved users' data, then it means they were deleted, assume guest. + if (!users.hasOwnProperty(post.uid)) { + post.uid = 0; + } + post.user = users[post.uid]; post.timestamp = utils.toISOString(post.timestamp); tidToPost[post.tid] = post;