v1.18.x
psychobunny 10 years ago
parent 298625225a
commit eb4baf62b5

@ -24,6 +24,8 @@ var fs = require('fs'),
websockets = require('../socket.io'); websockets = require('../socket.io');
function userNotFound(res) { function userNotFound(res) {
res.locals.notFound = true;
if (res.locals.isAPI) { if (res.locals.isAPI) {
res.status(404).json('no-user'); res.status(404).json('no-user');
} else { } else {

@ -15,7 +15,7 @@ module.exports = function(Meta) {
isUserPage: /^user\/[^\/]+(\/[\w]+)?/ isUserPage: /^user\/[^\/]+(\/[\w]+)?/
}; };
Meta.title.build = function (urlFragment, language, callback) { Meta.title.build = function (urlFragment, language, locals, callback) {
var uri = ''; var uri = '';
try { try {
uri = decodeURIComponent(urlFragment); uri = decodeURIComponent(urlFragment);
@ -23,7 +23,8 @@ module.exports = function(Meta) {
winston.error('Invalid url fragment : ' + urlFragment, e.stack); winston.error('Invalid url fragment : ' + urlFragment, e.stack);
return callback(null, Meta.config.browserTitle || 'NodeBB'); return callback(null, Meta.config.browserTitle || 'NodeBB');
} }
Meta.title.parseFragment(uri, language, function(err, title) {
Meta.title.parseFragment(uri, language, locals, function(err, title) {
if (err) { if (err) {
title = Meta.config.browserTitle || 'NodeBB'; title = Meta.config.browserTitle || 'NodeBB';
} else { } else {
@ -34,7 +35,7 @@ module.exports = function(Meta) {
}); });
}; };
Meta.title.parseFragment = function (urlFragment, language, callback) { Meta.title.parseFragment = function (urlFragment, language, locals, callback) {
urlFragment = validator.escape(urlFragment); urlFragment = validator.escape(urlFragment);
var translated = ['', 'recent', 'unread', 'users', 'notifications']; var translated = ['', 'recent', 'unread', 'users', 'notifications'];
if (translated.indexOf(urlFragment) !== -1) { if (translated.indexOf(urlFragment) !== -1) {
@ -69,6 +70,10 @@ module.exports = function(Meta) {
return callback(err); return callback(err);
} }
if (locals.notFound) {
username = '[[error:no-user]]';
}
if (!subpage) { if (!subpage) {
return callback(null, username); return callback(null, username);
} }

@ -339,10 +339,10 @@ middleware.renderHeader = function(req, res, callback) {
if (err) { if (err) {
return next(err); return next(err);
} }
meta.title.build(req.url.slice(1), settings.language, next); meta.title.build(req.url.slice(1), settings.language, res.locals, next);
}); });
} else { } else {
meta.title.build(req.url.slice(1), meta.config.defaultLang, next); meta.title.build(req.url.slice(1), meta.config.defaultLang, res.locals, next);
} }
}, },
isAdmin: function(next) { isAdmin: function(next) {

Loading…
Cancel
Save