Node.js based forum software built for the modern web
updated site upload logic so that site logo is resized for email header, implemented site logo in email header
Julian Lamc40b11aa6ed2
diff --git a/src/controllers/admin/uploads.js b/src/controllers/admin/uploads.jsindex a040f12ba2..f4124549bc 100644--- a/src/controllers/admin/uploads.js+++ b/src/controllers/admin/uploads.js@@ -146,6 +146,22 @@ function uploadImage(filename, folder, uploadedFile, req, res, next) {file.saveFileToLocal(filename, folder, uploadedFile.path, next);}},+ function (imageData, next) {+ // Post-processing for site-logo+ if (path.basename(filename, path.extname(filename)) === 'site-logo' && folder === 'system') {+ var uploadPath = path.join(nconf.get('upload_path'), folder, 'site-logo-x50.png');+ image.resizeImage({+ path: uploadedFile.path,+ target: uploadPath,+ extension: 'png',+ height: 50,+ }, function (err) {+ next(err, imageData);+ });+ } else {+ setImmediate(next, null, imageData);+ }+ },], function (err, image) {file.delete(uploadedFile.path);if (err) {diff --git a/src/emailer.js b/src/emailer.jsindex 5120ef9caf..947f5b35a7 100644--- a/src/emailer.js+++ b/src/emailer.js@@ -14,6 +14,7 @@ var User = require('./user');var Plugins = require('./plugins');var meta = require('./meta');var translator = require('./translator');+var pubsub = require('./pubsub');var transports = {sendmail: nodemailer.createTransport(sendmailTransport()),@@ -33,7 +34,11 @@ Emailer.registerApp = function (expressApp) {Emailer._defaultPayload = {url: nconf.get('url'),site_title: meta.config.title || 'NodeBB',- 'brand:logo': nconf.get('url') + meta.config['brand:logo'],+ logo: {+ src: nconf.get('url') + meta.config['brand:logo'].replace('.png', '-x50.png'),+ height: meta.config['brand:emailLogo:height'],+ width: meta.config['brand:emailLogo:width'],+ },};// Enable Gmail transport if enabled in ACP@@ -52,6 +57,14 @@ Emailer.registerApp = function (expressApp) {fallbackTransport = transports.sendmail;}+ // Update default payload if new logo is uploaded+ pubsub.on('config:update', function (config) {+ if (config) {+ Emailer._defaultPayload.logo.height = config['brand:emailLogo:height'];+ Emailer._defaultPayload.logo.width = config['brand:emailLogo:width'];+ }+ });+return Emailer;};diff --git a/src/meta/configs.js b/src/meta/configs.jsindex 925ff61255..e34e7de943 100644--- a/src/meta/configs.js+++ b/src/meta/configs.js@@ -3,6 +3,7 @@var async = require('async');var nconf = require('nconf');+var path = require('path');var db = require('../database');var pubsub = require('../pubsub');@@ -80,13 +81,28 @@ Configs.setMultiple = function (data, callback) {};function processConfig(data, callback) {- if (data.customCSS) {- return saveRenderedCss(data, callback);- }- setImmediate(callback);+ async.parallel([+ async.apply(saveRenderedCss, data),+ function (next) {+ var image = require('../image');+ if (data['brand:logo']) {+ image.size(path.join(nconf.get('upload_path'), 'system', 'site-logo-x50.png'), function (err, size) {+ data['brand:emailLogo:height'] = size.height;+ data['brand:emailLogo:width'] = size.width;+ next(err);+ });+ }+ },+ ], function (err) {+ callback(err);+ });}function saveRenderedCss(data, callback) {+ if (!data.customCSS) {+ return setImmediate(callback);+ }+var less = require('less');async.waterfall([function (next) {diff --git a/src/views/emails/partials/header.tpl b/src/views/emails/partials/header.tplindex fd94ab4294..bc67621ffd 100644--- a/src/views/emails/partials/header.tpl+++ b/src/views/emails/partials/header.tpl@@ -172,7 +172,7 @@<table role="presentation" cellspacing="0" cellpadding="0" border="0" align="center" width="100%" style="max-width: 600px;"><tr><td style="padding: 20px 0; text-align: center">- <img src="{url}/assets/images/emails/nodebb.png" height="49" width="192" alt="{site_title}" border="0" style="height: 49px; width: 192px; background: #222222; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555;">+ <img src="{logo.src}" height="{logo.height}" width="{logo.width}" alt="{site_title}" border="0" style="height: 49px; width: 192px; background: #222222; font-family: sans-serif; font-size: 15px; line-height: 20px; color: #555555;"></td></tr></table>