From 7148d44f9097f687c26c33e71505d7126469e782 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 29 Oct 2015 14:55:04 -0400 Subject: [PATCH] default cover images for groups --- src/coverPhoto.js | 24 ++++++++++++++++++++++++ src/groups.js | 7 ++----- src/views/admin/settings/group.tpl | 6 ++++++ 3 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 src/coverPhoto.js diff --git a/src/coverPhoto.js b/src/coverPhoto.js new file mode 100644 index 0000000000..137d0e0078 --- /dev/null +++ b/src/coverPhoto.js @@ -0,0 +1,24 @@ +"use strict"; + +var coverPhoto = {}; +var meta = require('./meta'); +var nconf = require('nconf'); + + +coverPhoto.getDefaultCover = function(groupName) { + return getCover('groups', groupName); +}; + +function getCover(type, id) { + var covers = meta.config[type + ':defaultCovers'].split(/\s*?,\s*?/g); + + if (typeof id === 'string') { + id = (id.charCodeAt(0) + id.charCodeAt(1)) % covers.length; + } else { + id = id % covers.length; + } + + return covers && covers.length ? covers[id] : (nconf.get('relative_path') + '/images/cover-default.png'); +} + +module.exports = coverPhoto; \ No newline at end of file diff --git a/src/groups.js b/src/groups.js index 646843bde3..246ca618eb 100644 --- a/src/groups.js +++ b/src/groups.js @@ -163,11 +163,8 @@ var async = require('async'), return callback(new Error('[[error:no-group]]')); } - // Default image - if (!results.base['cover:url']) { - results.base['cover:url'] = nconf.get('relative_path') + '/images/cover-default.png'; - results.base['cover:position'] = '50% 50%'; - } + results.base['cover:url'] = results.base['cover:url'] || require('./coverPhoto').getDefaultCover(groupName); + results.base['cover:position'] = results.base['cover:position'] || '50% 50%'; plugins.fireHook('filter:parse.raw', results.base.description, function(err, descriptionParsed) { if (err) { diff --git a/src/views/admin/settings/group.tpl b/src/views/admin/settings/group.tpl index fb71beda6b..c04abe872a 100644 --- a/src/views/admin/settings/group.tpl +++ b/src/views/admin/settings/group.tpl @@ -28,6 +28,12 @@

If enabled, users can create groups (Default: disabled)

+ + +

+ Add comma-separated default cover images for groups that don't have an uploaded cover image +

+