mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
hide category icons if they are not set
This commit is contained in:
@@ -314,20 +314,30 @@ var db = require('./database'),
|
||||
return callback(null, []);
|
||||
}
|
||||
|
||||
async.map(categories, function(category, next) {
|
||||
if (!category || !parseInt(category.cid, 10)) {
|
||||
return next(null, null);
|
||||
}
|
||||
category.name = validator.escape(category.name);
|
||||
category.description = validator.escape(category.description);
|
||||
category.backgroundImage = category.image ? nconf.get('relative_path') + category.image : '';
|
||||
category.disabled = parseInt(category.disabled, 10) === 1;
|
||||
|
||||
next(null, category);
|
||||
}, callback);
|
||||
async.map(categories, modifyCategory, callback);
|
||||
});
|
||||
};
|
||||
|
||||
function modifyCategory(category, callback) {
|
||||
if (!category || !parseInt(category.cid, 10)) {
|
||||
return callback(null, null);
|
||||
}
|
||||
|
||||
category.name = validator.escape(category.name);
|
||||
category.disabled = parseInt(category.disabled, 10) === 1;
|
||||
category.icon = category.icon || 'hidden';
|
||||
|
||||
if (category.description) {
|
||||
category.description = validator.escape(category.description);
|
||||
}
|
||||
|
||||
if (category.image) {
|
||||
category.backgroundImage = category.image ? nconf.get('relative_path') + category.image : '';
|
||||
}
|
||||
|
||||
callback(null, category);
|
||||
}
|
||||
|
||||
Categories.getCategoryField = function(cid, field, callback) {
|
||||
db.getObjectField('category:' + cid, field, callback);
|
||||
};
|
||||
@@ -336,7 +346,12 @@ var db = require('./database'),
|
||||
var keys = cids.map(function(cid) {
|
||||
return 'category:' + cid;
|
||||
});
|
||||
db.getObjectsFields(keys, fields, callback);
|
||||
db.getObjectsFields(keys, fields, function(err, categories) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
async.map(categories, modifyCategory, callback);
|
||||
});
|
||||
};
|
||||
|
||||
Categories.getCategoryFields = function(cid, fields, callback) {
|
||||
|
||||
10
src/posts.js
10
src/posts.js
@@ -270,13 +270,13 @@ var async = require('async'),
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var cidKeys = topics.map(function(topic) {
|
||||
return 'category:' + topic.cid;
|
||||
var cids = topics.map(function(topic) {
|
||||
return topic && topic.cid;
|
||||
}).filter(function(value, index, array) {
|
||||
return array.indexOf(value) === index;
|
||||
return value && array.indexOf(value) === index;
|
||||
});
|
||||
|
||||
db.getObjectsFields(cidKeys, ['cid', 'name', 'icon', 'slug'], function(err, categories) {
|
||||
categories.getMultipleCategoryFields(cids, ['cid', 'name', 'icon', 'slug'], function(err, categories) {
|
||||
next(err, {topics: topics, categories: categories});
|
||||
});
|
||||
});
|
||||
@@ -320,9 +320,9 @@ var async = require('async'),
|
||||
async.map(posts, function(post, next) {
|
||||
post.user = results.users[post.uid];
|
||||
post.topic = results.topics[post.tid];
|
||||
post.topic.title = validator.escape(post.topic.title);
|
||||
post.category = results.categories[post.topic.cid];
|
||||
|
||||
post.topic.title = validator.escape(post.topic.title);
|
||||
post.relativeTime = utils.toISOString(post.timestamp);
|
||||
|
||||
if (!post.content || !options.parse) {
|
||||
|
||||
@@ -226,7 +226,6 @@ var async = require('async'),
|
||||
for (var i=0; i<topics.length; ++i) {
|
||||
if (topics[i]) {
|
||||
topics[i].category = categories[topics[i].cid] || {};
|
||||
topics[i].category.disabled = parseInt(topics[i].category.disabled, 10) === 1;
|
||||
topics[i].user = users[topics[i].uid];
|
||||
topics[i].teaser = results.teasers[i];
|
||||
topics[i].tags = results.tags[i];
|
||||
|
||||
Reference in New Issue
Block a user