mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +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, []);
|
return callback(null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
async.map(categories, function(category, next) {
|
async.map(categories, modifyCategory, callback);
|
||||||
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);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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) {
|
Categories.getCategoryField = function(cid, field, callback) {
|
||||||
db.getObjectField('category:' + cid, field, callback);
|
db.getObjectField('category:' + cid, field, callback);
|
||||||
};
|
};
|
||||||
@@ -336,7 +346,12 @@ var db = require('./database'),
|
|||||||
var keys = cids.map(function(cid) {
|
var keys = cids.map(function(cid) {
|
||||||
return 'category:' + 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) {
|
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);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var cidKeys = topics.map(function(topic) {
|
var cids = topics.map(function(topic) {
|
||||||
return 'category:' + topic.cid;
|
return topic && topic.cid;
|
||||||
}).filter(function(value, index, array) {
|
}).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});
|
next(err, {topics: topics, categories: categories});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -320,9 +320,9 @@ var async = require('async'),
|
|||||||
async.map(posts, function(post, next) {
|
async.map(posts, function(post, next) {
|
||||||
post.user = results.users[post.uid];
|
post.user = results.users[post.uid];
|
||||||
post.topic = results.topics[post.tid];
|
post.topic = results.topics[post.tid];
|
||||||
|
post.topic.title = validator.escape(post.topic.title);
|
||||||
post.category = results.categories[post.topic.cid];
|
post.category = results.categories[post.topic.cid];
|
||||||
|
|
||||||
post.topic.title = validator.escape(post.topic.title);
|
|
||||||
post.relativeTime = utils.toISOString(post.timestamp);
|
post.relativeTime = utils.toISOString(post.timestamp);
|
||||||
|
|
||||||
if (!post.content || !options.parse) {
|
if (!post.content || !options.parse) {
|
||||||
|
|||||||
@@ -226,7 +226,6 @@ var async = require('async'),
|
|||||||
for (var i=0; i<topics.length; ++i) {
|
for (var i=0; i<topics.length; ++i) {
|
||||||
if (topics[i]) {
|
if (topics[i]) {
|
||||||
topics[i].category = categories[topics[i].cid] || {};
|
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].user = users[topics[i].uid];
|
||||||
topics[i].teaser = results.teasers[i];
|
topics[i].teaser = results.teasers[i];
|
||||||
topics[i].tags = results.tags[i];
|
topics[i].tags = results.tags[i];
|
||||||
|
|||||||
Reference in New Issue
Block a user