|
|
@ -5,14 +5,43 @@ var validator = require('validator');
|
|
|
|
var db = require('../database');
|
|
|
|
var db = require('../database');
|
|
|
|
var categories = require('../categories');
|
|
|
|
var categories = require('../categories');
|
|
|
|
var utils = require('../utils');
|
|
|
|
var utils = require('../utils');
|
|
|
|
|
|
|
|
var translator = require('../translator');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function escapeTitle(topicData) {
|
|
|
|
|
|
|
|
if (!topicData) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topicData.title) {
|
|
|
|
|
|
|
|
topicData.title = translator.escape(validator.escape(topicData.title.toString()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topicData.titleRaw) {
|
|
|
|
|
|
|
|
topicData.titleRaw = translator.escape(topicData.titleRaw);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = function (Topics) {
|
|
|
|
module.exports = function (Topics) {
|
|
|
|
Topics.getTopicField = function (tid, field, callback) {
|
|
|
|
Topics.getTopicField = function (tid, field, callback) {
|
|
|
|
db.getObjectField('topic:' + tid, field, callback);
|
|
|
|
db.getObjectField('topic:' + tid, field, function (err, value) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (field === 'title') {
|
|
|
|
|
|
|
|
value = translator.escape(validator.escape(String(value)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(null, value);
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Topics.getTopicFields = function (tid, fields, callback) {
|
|
|
|
Topics.getTopicFields = function (tid, fields, callback) {
|
|
|
|
db.getObjectFields('topic:' + tid, fields, callback);
|
|
|
|
db.getObjectFields('topic:' + tid, fields, function (err, topic) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
escapeTitle(topic);
|
|
|
|
|
|
|
|
callback(null, topic);
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Topics.getTopicsFields = function (tids, fields, callback) {
|
|
|
|
Topics.getTopicsFields = function (tids, fields, callback) {
|
|
|
@ -22,7 +51,14 @@ module.exports = function (Topics) {
|
|
|
|
var keys = tids.map(function (tid) {
|
|
|
|
var keys = tids.map(function (tid) {
|
|
|
|
return 'topic:' + tid;
|
|
|
|
return 'topic:' + tid;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
db.getObjectsFields(keys, fields, callback);
|
|
|
|
db.getObjectsFields(keys, fields, function (err, topics) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
return callback(err);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
topics.forEach(escapeTitle);
|
|
|
|
|
|
|
|
callback(null, topics);
|
|
|
|
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Topics.getTopicData = function (tid, callback) {
|
|
|
|
Topics.getTopicData = function (tid, callback) {
|
|
|
@ -57,8 +93,10 @@ module.exports = function (Topics) {
|
|
|
|
if (!topic) {
|
|
|
|
if (!topic) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
topic.titleRaw = topic.title;
|
|
|
|
topic.titleRaw = topic.title;
|
|
|
|
topic.title = validator.escape(String(topic.title));
|
|
|
|
topic.title = String(topic.title);
|
|
|
|
|
|
|
|
escapeTitle(topic);
|
|
|
|
topic.timestampISO = utils.toISOString(topic.timestamp);
|
|
|
|
topic.timestampISO = utils.toISOString(topic.timestamp);
|
|
|
|
topic.lastposttimeISO = utils.toISOString(topic.lastposttime);
|
|
|
|
topic.lastposttimeISO = utils.toISOString(topic.lastposttime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|