v1.18.x
barisusakli 9 years ago
parent 4608b8f07b
commit 738b892074

@ -1,48 +1,44 @@
"use strict"; "use strict";
var tagsController = {},
async = require('async'), var async = require('async');
nconf = require('nconf'), var nconf = require('nconf');
validator = require('validator'), var validator = require('validator');
meta = require('../meta'),
user = require('../user'), var meta = require('../meta');
topics = require('../topics'), var topics = require('../topics');
helpers = require('./helpers'); var helpers = require('./helpers');
var tagsController = {};
tagsController.getTag = function(req, res, next) { tagsController.getTag = function(req, res, next) {
var tag = validator.escape(req.params.tag); var tag = validator.escape(req.params.tag);
var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1; var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
var templateData = {
topics: [],
tag: tag,
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}]),
title: '[[pages:tag, ' + tag + ']]'
};
async.waterfall([ async.waterfall([
function(next) { function (next) {
topics.getTagTids(req.params.tag, 0, stop, next); topics.getTagTids(req.params.tag, 0, stop, next);
}, },
function(tids, next) { function (tids, next) {
if (Array.isArray(tids) && !tids.length) { if (Array.isArray(tids) && !tids.length) {
topics.deleteTag(req.params.tag); topics.deleteTag(req.params.tag);
return res.render('tag', { return res.render('tag', templateData);
topics: [],
tag: tag,
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}])
});
} }
async.parallel({ topics.getTopics(tids, req.uid, next);
isAdmin: async.apply(user.isAdministrator, req.uid),
topics: async.apply(topics.getTopics, tids, req.uid)
}, next);
} }
], function(err, results) { ], function(err, topics) {
if (err) { if (err) {
return next(err); return next(err);
} }
if (!results.isAdmin) {
results.topics = results.topics.filter(function(topic) {
return topic && !topic.deleted;
});
}
res.locals.metaTags = [ res.locals.metaTags = [
{ {
name: 'title', name: 'title',
@ -57,15 +53,10 @@ tagsController.getTag = function(req, res, next) {
content: nconf.get('url') + '/tags/' + tag content: nconf.get('url') + '/tags/' + tag
} }
]; ];
templateData.topics = topics;
templateData.nextStart = stop + 1;
var data = { res.render('tag', templateData);
topics: results.topics,
tag: tag,
nextStart: stop + 1,
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[tags:tags]]', url: '/tags'}, {text: tag}]),
title: '[[pages:tag, ' + tag + ']]'
};
res.render('tag', data);
}); });
}; };

Loading…
Cancel
Save