default cover images for groups

v1.18.x
psychobunny 9 years ago
parent 8787f04757
commit 7148d44f90

@ -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;

@ -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) {

@ -28,6 +28,12 @@
<p class="help-block">
If enabled, users can create groups <em>(Default: disabled)</em>
</p>
<label for="groups:defaultCovers"><strong>Default Cover Images</strong></label>
<p class="help-block">
Add comma-separated default cover images for groups that don't have an uploaded cover image
</p>
<input type="text" class="form-control input-lg" id="groups:defaultCovers" data-field="groups:defaultCovers" value="{config.relative_path}/images/cover-default.png" placeholder="https://example.com/group1.png, https://example.com/group2.png" /><br />
</form>
</div>
</div>

Loading…
Cancel
Save