|
|
|
@ -59,115 +59,122 @@ module.exports = function (middleware) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
templateValues.configJSON = JSON.stringify(res.locals.config);
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
scripts: function (next) {
|
|
|
|
|
plugins.fireHook('filter:scripts.get', [], next);
|
|
|
|
|
},
|
|
|
|
|
isAdmin: function (next) {
|
|
|
|
|
user.isAdministrator(req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
isGlobalMod: function (next) {
|
|
|
|
|
user.isGlobalModerator(req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
isModerator: function (next) {
|
|
|
|
|
user.isModeratorOfAnyCategory(req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
user: function (next) {
|
|
|
|
|
var userData = {
|
|
|
|
|
uid: 0,
|
|
|
|
|
username: '[[global:guest]]',
|
|
|
|
|
userslug: '',
|
|
|
|
|
email: '',
|
|
|
|
|
picture: meta.config.defaultAvatar,
|
|
|
|
|
status: 'offline',
|
|
|
|
|
reputation: 0,
|
|
|
|
|
'email:confirmed': false
|
|
|
|
|
};
|
|
|
|
|
if (req.uid) {
|
|
|
|
|
user.getUserFields(req.uid, Object.keys(userData), next);
|
|
|
|
|
} else {
|
|
|
|
|
next(null, userData);
|
|
|
|
|
}
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
scripts: function (next) {
|
|
|
|
|
plugins.fireHook('filter:scripts.get', [], next);
|
|
|
|
|
},
|
|
|
|
|
isAdmin: function (next) {
|
|
|
|
|
user.isAdministrator(req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
isGlobalMod: function (next) {
|
|
|
|
|
user.isGlobalModerator(req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
isModerator: function (next) {
|
|
|
|
|
user.isModeratorOfAnyCategory(req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
user: function (next) {
|
|
|
|
|
var userData = {
|
|
|
|
|
uid: 0,
|
|
|
|
|
username: '[[global:guest]]',
|
|
|
|
|
userslug: '',
|
|
|
|
|
email: '',
|
|
|
|
|
picture: meta.config.defaultAvatar,
|
|
|
|
|
status: 'offline',
|
|
|
|
|
reputation: 0,
|
|
|
|
|
'email:confirmed': false
|
|
|
|
|
};
|
|
|
|
|
if (req.uid) {
|
|
|
|
|
user.getUserFields(req.uid, Object.keys(userData), next);
|
|
|
|
|
} else {
|
|
|
|
|
next(null, userData);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
isEmailConfirmSent: function (next) {
|
|
|
|
|
if (!meta.config.requireEmailConfirmation || !req.uid) {
|
|
|
|
|
return next(null, false);
|
|
|
|
|
}
|
|
|
|
|
db.get('uid:' + req.uid + ':confirm:email:sent', next);
|
|
|
|
|
},
|
|
|
|
|
navigation: async.apply(navigation.get),
|
|
|
|
|
tags: async.apply(meta.tags.parse, res.locals.metaTags, res.locals.linkTags),
|
|
|
|
|
banned: async.apply(user.isBanned, req.uid),
|
|
|
|
|
banReason: async.apply(user.getBannedReason, req.uid)
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
isEmailConfirmSent: function (next) {
|
|
|
|
|
if (!meta.config.requireEmailConfirmation || !req.uid) {
|
|
|
|
|
return next(null, false);
|
|
|
|
|
function (results, next) {
|
|
|
|
|
if (results.banned) {
|
|
|
|
|
req.logout();
|
|
|
|
|
return res.redirect('/?banned=' + (results.banReason || 'no-reason'));
|
|
|
|
|
}
|
|
|
|
|
db.get('uid:' + req.uid + ':confirm:email:sent', next);
|
|
|
|
|
},
|
|
|
|
|
navigation: async.apply(navigation.get),
|
|
|
|
|
tags: async.apply(meta.tags.parse, res.locals.metaTags, res.locals.linkTags),
|
|
|
|
|
banned: async.apply(user.isBanned, req.uid),
|
|
|
|
|
banReason: async.apply(user.getBannedReason, req.uid)
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (results.banned) {
|
|
|
|
|
req.logout();
|
|
|
|
|
return res.redirect('/?banned=' + (results.banReason || 'no-reason'));
|
|
|
|
|
}
|
|
|
|
|
results.user.isAdmin = results.isAdmin;
|
|
|
|
|
results.user.isGlobalMod = results.isGlobalMod;
|
|
|
|
|
results.user.isMod = !!results.isModerator;
|
|
|
|
|
results.user.uid = parseInt(results.user.uid, 10);
|
|
|
|
|
results.user.email = String(results.user.email).replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
|
|
|
results.user['email:confirmed'] = parseInt(results.user['email:confirmed'], 10) === 1;
|
|
|
|
|
results.user.isEmailConfirmSent = !!results.isEmailConfirmSent;
|
|
|
|
|
|
|
|
|
|
results.user.isAdmin = results.isAdmin;
|
|
|
|
|
results.user.isGlobalMod = results.isGlobalMod;
|
|
|
|
|
results.user.isMod = !!results.isModerator;
|
|
|
|
|
results.user.uid = parseInt(results.user.uid, 10);
|
|
|
|
|
results.user.email = String(results.user.email).replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
|
|
|
results.user['email:confirmed'] = parseInt(results.user['email:confirmed'], 10) === 1;
|
|
|
|
|
results.user.isEmailConfirmSent = !!results.isEmailConfirmSent;
|
|
|
|
|
|
|
|
|
|
if (res.locals.config && parseInt(meta.config.disableCustomUserSkins, 10) !== 1 && res.locals.config.bootswatchSkin !== 'default') {
|
|
|
|
|
templateValues.bootswatchCSS = '//maxcdn.bootstrapcdn.com/bootswatch/latest/' + res.locals.config.bootswatchSkin + '/bootstrap.min.css';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
templateValues.browserTitle = controllers.helpers.buildTitle(data.title);
|
|
|
|
|
templateValues.navigation = results.navigation;
|
|
|
|
|
templateValues.metaTags = results.tags.meta;
|
|
|
|
|
templateValues.linkTags = results.tags.link;
|
|
|
|
|
templateValues.isAdmin = results.user.isAdmin;
|
|
|
|
|
templateValues.isGlobalMod = results.user.isGlobalMod;
|
|
|
|
|
templateValues.showModMenu = results.user.isAdmin || results.user.isGlobalMod || results.user.isMod;
|
|
|
|
|
templateValues.user = results.user;
|
|
|
|
|
templateValues.userJSON = JSON.stringify(results.user);
|
|
|
|
|
templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1 && meta.config.customCSS;
|
|
|
|
|
templateValues.customCSS = templateValues.useCustomCSS ? (meta.config.renderedCustomCSS || '') : '';
|
|
|
|
|
templateValues.useCustomJS = parseInt(meta.config.useCustomJS, 10) === 1;
|
|
|
|
|
templateValues.customJS = templateValues.useCustomJS ? meta.config.customJS : '';
|
|
|
|
|
templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin;
|
|
|
|
|
templateValues.defaultLang = meta.config.defaultLang || 'en-GB';
|
|
|
|
|
templateValues.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1;
|
|
|
|
|
templateValues.privateTagListing = parseInt(meta.config.privateTagListing, 10) === 1;
|
|
|
|
|
|
|
|
|
|
templateValues.template = {name: res.locals.template};
|
|
|
|
|
templateValues.template[res.locals.template] = true;
|
|
|
|
|
|
|
|
|
|
templateValues.scripts = results.scripts.map(function (script) {
|
|
|
|
|
return {src: script};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (req.route && req.route.path === '/') {
|
|
|
|
|
modifyTitle(templateValues);
|
|
|
|
|
}
|
|
|
|
|
if (res.locals.config && parseInt(meta.config.disableCustomUserSkins, 10) !== 1 && res.locals.config.bootswatchSkin !== 'default') {
|
|
|
|
|
templateValues.bootswatchCSS = '//maxcdn.bootstrapcdn.com/bootswatch/latest/' + res.locals.config.bootswatchSkin + '/bootstrap.min.css';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plugins.fireHook('filter:middleware.renderHeader', {templateValues: templateValues, req: req, res: res}, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
templateValues.browserTitle = controllers.helpers.buildTitle(data.title);
|
|
|
|
|
templateValues.navigation = results.navigation;
|
|
|
|
|
templateValues.metaTags = results.tags.meta;
|
|
|
|
|
templateValues.linkTags = results.tags.link;
|
|
|
|
|
templateValues.isAdmin = results.user.isAdmin;
|
|
|
|
|
templateValues.isGlobalMod = results.user.isGlobalMod;
|
|
|
|
|
templateValues.showModMenu = results.user.isAdmin || results.user.isGlobalMod || results.user.isMod;
|
|
|
|
|
templateValues.user = results.user;
|
|
|
|
|
templateValues.userJSON = JSON.stringify(results.user);
|
|
|
|
|
templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1 && meta.config.customCSS;
|
|
|
|
|
templateValues.customCSS = templateValues.useCustomCSS ? (meta.config.renderedCustomCSS || '') : '';
|
|
|
|
|
templateValues.useCustomJS = parseInt(meta.config.useCustomJS, 10) === 1;
|
|
|
|
|
templateValues.customJS = templateValues.useCustomJS ? meta.config.customJS : '';
|
|
|
|
|
templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin;
|
|
|
|
|
templateValues.defaultLang = meta.config.defaultLang || 'en-GB';
|
|
|
|
|
templateValues.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1;
|
|
|
|
|
templateValues.privateTagListing = parseInt(meta.config.privateTagListing, 10) === 1;
|
|
|
|
|
|
|
|
|
|
templateValues.template = {name: res.locals.template};
|
|
|
|
|
templateValues.template[res.locals.template] = true;
|
|
|
|
|
|
|
|
|
|
templateValues.scripts = results.scripts.map(function (script) {
|
|
|
|
|
return {src: script};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (req.route && req.route.path === '/') {
|
|
|
|
|
modifyTitle(templateValues);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
req.app.render('header', data.templateValues, callback);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
plugins.fireHook('filter:middleware.renderHeader', {
|
|
|
|
|
req: req,
|
|
|
|
|
res: res,
|
|
|
|
|
templateValues: templateValues
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
req.app.render('header', data.templateValues, next);
|
|
|
|
|
}
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
middleware.renderFooter = function (req, res, data, callback) {
|
|
|
|
|
plugins.fireHook('filter:middleware.renderFooter', {templateValues: data, req: req, res: res}, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(err);
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
plugins.fireHook('filter:middleware.renderFooter', {
|
|
|
|
|
req: req,
|
|
|
|
|
res: res,
|
|
|
|
|
templateValues: data,
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (data, next) {
|
|
|
|
|
req.app.render('footer', data.templateValues, next);
|
|
|
|
|
}
|
|
|
|
|
req.app.render('footer', data.templateValues, callback);
|
|
|
|
|
});
|
|
|
|
|
], callback);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function modifyTitle(obj) {
|
|
|
|
|