diff --git a/public/src/forum/admin/settings.js b/public/src/forum/admin/settings.js index cddd48428b..6bc5d782d0 100644 --- a/public/src/forum/admin/settings.js +++ b/public/src/forum/admin/settings.js @@ -61,21 +61,7 @@ define(['uploader', 'sounds'], function(uploader, sounds) { } }); - $('#uploadLogoBtn').on('click', function() { - uploader.open(RELATIVE_PATH + '/admin/uploadlogo', {}, 0, function(image) { - $('#logoUrl').val(image); - }); - - uploader.hideAlerts(); - }); - - $('#uploadFaviconBtn').on('click', function() { - uploader.open(RELATIVE_PATH + '/admin/uploadfavicon', {}, 0, function(icon) { - $('#faviconUrl').val(icon); - }); - - uploader.hideAlerts(); - }); + handleUploads(); $('#settings-tab a').click(function (e) { e.preventDefault(); @@ -88,6 +74,19 @@ define(['uploader', 'sounds'], function(uploader, sounds) { } }; + function handleUploads() { + $('#content input[data-action="upload"]').each(function() { + var uploadBtn = $(this); + uploadBtn.on('click', function() { + uploader.open(uploadBtn.attr('data-route'), {}, 0, function(image) { + $('#' + uploadBtn.attr('data-target')).val(image); + }); + + uploader.hideAlerts(); + }); + }); + } + Settings.remove = function(key) { socket.emit('admin.config.remove', key); }; diff --git a/src/controllers/admin/uploads.js b/src/controllers/admin/uploads.js index e7c79d6e7e..e0543c9add 100644 --- a/src/controllers/admin/uploads.js +++ b/src/controllers/admin/uploads.js @@ -87,7 +87,20 @@ uploadsController.uploadLogo = function(req, res, next) { if (validateUpload(res, req, allowedTypes)) { var filename = 'site-logo' + path.extname(req.files.userPhoto.name); uploadsController.uploadImage(filename, req, res); - } + } +}; + + +uploadsController.uploadGravatarDefault = function(req, res, next) { + var allowedTypes = ['image/png', 'image/jpeg', 'image/pjpeg', 'image/jpg', 'image/gif'], + er; + + if (validateUpload(res, req, allowedTypes)) { + var filename = 'gravatar-default' + path.extname(req.files.userPhoto.name); + uploadsController.uploadImage(filename, req, res); + } }; + + module.exports = uploadsController; diff --git a/src/posts.js b/src/posts.js index 0f2d938f86..2cb46d2013 100644 --- a/src/posts.js +++ b/src/posts.js @@ -237,7 +237,7 @@ var db = require('./database'), reputation: userData.reputation || 0, postcount: userData.postcount || 0, banned: parseInt(userData.banned, 10) === 1, - picture: userData.picture || gravatar.url('', {}, true) + picture: userData.picture || user.createGravatarURLFromEmail('') }; for (var info in customUserInfo) { diff --git a/src/routes/admin.js b/src/routes/admin.js index 393fc2c3df..6124f9beeb 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -57,6 +57,7 @@ function apiRoutes(app, middleware, controllers) { app.post('/admin/category/uploadpicture', middleware.authenticate, controllers.admin.uploads.uploadCategoryPicture); app.post('/admin/uploadfavicon', middleware.authenticate, controllers.admin.uploads.uploadFavicon); app.post('/admin/uploadlogo', middleware.authenticate, controllers.admin.uploads.uploadLogo); + app.post('/admin/uploadgravatardefault', middleware.authenticate, controllers.admin.uploads.uploadGravatarDefault); } function miscRoutes(app, middleware, controllers) { diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js index 8c40d0ef52..35039a9dd4 100644 --- a/src/socket.io/meta.js +++ b/src/socket.io/meta.js @@ -67,9 +67,7 @@ SocketMeta.updateHeader = function(socket, data, callback) { uid: 0, username: '[[global:guest]]', email: '', - picture: gravatar.url('', { - s: '24' - }, true), + picture: user.createGravatarURLFromEmail(''), config: { allowGuestSearching: meta.config.allowGuestSearching } diff --git a/src/user.js b/src/user.js index d0df487313..10812d551e 100644 --- a/src/user.js +++ b/src/user.js @@ -210,15 +210,15 @@ var bcrypt = require('bcryptjs'), }; User.createGravatarURLFromEmail = function(email) { + var options = { size: '128', - default: 'identicon', + default: meta.config.customGravatarDefaultImage || meta.config.defaultGravatarImage || '', rating: 'pg' }; if (!email) { email = ''; - options.forcedefault = 'y'; } return gravatar.url(email, options, true); @@ -294,7 +294,7 @@ var bcrypt = require('bcryptjs'), callback(null, { username: data.username || '[[global:guest]]', userslug: data.userslug || '', - picture: data.picture || gravatar.url('', {}, true) + picture: data.picture || User.createGravatarURLFromEmail('') }); }); };