acp shenans

v1.18.x
barisusakli
parent c15a289d2a
commit 3809b331bc

@ -32,77 +32,86 @@ middleware.isAdmin = function(req, res, next) {
}; };
middleware.buildHeader = function(req, res, next) { middleware.buildHeader = function(req, res, next) {
res.locals.renderAdminHeader = true;
async.parallel({
config: function(next) {
controllers.api.getConfig(req, res, next);
},
footer: function(next) {
app.render('admin/footer', {}, next);
}
}, function(err, results) {
if (err) {
return next(err);
}
res.locals.config = results.config;
res.locals.adminFooter = results.footer;
next();
});
};
middleware.renderHeader = function(req, res, next) {
var uid = req.user ? req.user.uid : 0; var uid = req.user ? req.user.uid : 0;
async.parallel([
function(next) {
var custom_header = {
'plugins': [],
'authentication': []
};
user.getUserFields(uid, ['username', 'userslug', 'email', 'picture', 'email:confirmed'], function(err, userData) { var custom_header = {
if (err) { 'plugins': [],
return next(err); 'authentication': []
} };
userData.uid = uid; user.getUserFields(uid, ['username', 'userslug', 'email', 'picture', 'email:confirmed'], function(err, userData) {
userData['email:confirmed'] = parseInt(userData['email:confirmed'], 10) === 1; if (err) {
return next(err);
async.parallel({ }
scripts: function(next) {
plugins.fireHook('filter:admin.scripts.get', [], function(err, scripts) { userData.uid = uid;
if (err) { userData['email:confirmed'] = parseInt(userData['email:confirmed'], 10) === 1;
return next(err);
} async.parallel({
var arr = []; scripts: function(next) {
scripts.forEach(function(script) { plugins.fireHook('filter:admin.scripts.get', [], function(err, scripts) {
arr.push({src: nconf.get('url') + script});
});
next(null, arr);
});
},
custom_header: function(next) {
plugins.fireHook('filter:admin.header.build', custom_header, next);
},
config: function(next) {
controllers.api.getConfig(req, res, next);
}
}, function(err, results) {
if (err) { if (err) {
return next(err); return next(err);
} }
res.locals.config = results.config; var arr = [];
scripts.forEach(function(script) {
var data = { arr.push({src: nconf.get('url') + script});
relative_path: nconf.get('relative_path'),
configJSON: JSON.stringify(results.config),
user: userData,
userJSON: JSON.stringify(userData),
plugins: results.custom_header.plugins,
authentication: results.custom_header.authentication,
scripts: results.scripts,
'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '',
env: process.env.NODE_ENV ? true : false
};
app.render('admin/header', data, function(err, template) {
if (err) {
return next(err);
}
res.locals.adminHeader = template;
next();
}); });
next(null, arr);
}); });
}); },
}, custom_header: function(next) {
function(next) { plugins.fireHook('filter:admin.header.build', custom_header, next);
app.render('admin/footer', {}, function(err, template) { },
res.locals.adminFooter = template; config: function(next) {
next(err); controllers.api.getConfig(req, res, next);
}); }
} }, function(err, results) {
], next); if (err) {
return next(err);
}
res.locals.config = results.config;
var data = {
relative_path: nconf.get('relative_path'),
configJSON: JSON.stringify(results.config),
user: userData,
userJSON: JSON.stringify(userData),
plugins: results.custom_header.plugins,
authentication: results.custom_header.authentication,
scripts: results.scripts,
'cache-buster': meta.config['cache-buster'] ? 'v=' + meta.config['cache-buster'] : '',
env: process.env.NODE_ENV ? true : false,
};
data.template = {name: res.locals.template};
data.template[res.locals.template] = true;
app.render('admin/header', data, next);
});
});
}; };
module.exports = function(webserver) { module.exports = function(webserver) {

@ -284,7 +284,6 @@ middleware.renderHeader = function(req, res, callback) {
href: nconf.get('relative_path') + '/favicon.ico' href: nconf.get('relative_path') + '/favicon.ico'
}); });
async.parallel({ async.parallel({
customCSS: function(next) { customCSS: function(next) {
templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1; templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1;
@ -401,20 +400,18 @@ middleware.processRender = function(req, res, next) {
str = str + res.locals.adminFooter; str = str + res.locals.adminFooter;
} }
if (res.locals.renderHeader) { if (res.locals.renderHeader || res.locals.renderAdminHeader) {
middleware.renderHeader(req, res, function(err, template) { var method = res.locals.renderHeader ? middleware.renderHeader : middleware.admin.renderHeader;
method(req, res, function(err, template) {
if (err) {
return fn(err);
}
str = template + str; str = template + str;
var language = res.locals.config ? res.locals.config.userLang || 'en_GB' : 'en_GB'; var language = res.locals.config ? res.locals.config.userLang || 'en_GB' : 'en_GB';
translator.translate(str, language, function(translated) { translator.translate(str, language, function(translated) {
fn(err, translated); fn(err, translated);
}); });
}); });
} else if (res.locals.adminHeader) {
str = res.locals.adminHeader + str;
var language = res.locals.config ? res.locals.config.userLang || 'en_GB' : 'en_GB';
translator.translate(str, language, function(translated) {
fn(err, translated);
});
} else { } else {
fn(err, str); fn(err, str);
} }

Loading…
Cancel
Save