|
|
|
@ -1,62 +1,52 @@
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var async = require('async'),
|
|
|
|
|
rss = require('rss'),
|
|
|
|
|
nconf = require('nconf'),
|
|
|
|
|
|
|
|
|
|
posts = require('../posts'),
|
|
|
|
|
topics = require('../topics'),
|
|
|
|
|
user = require('../user'),
|
|
|
|
|
categories = require('../categories'),
|
|
|
|
|
meta = require('../meta'),
|
|
|
|
|
helpers = require('../controllers/helpers'),
|
|
|
|
|
privileges = require('../privileges');
|
|
|
|
|
|
|
|
|
|
function hasTopicPrivileges(req, res, next) {
|
|
|
|
|
var tid = req.params.topic_id;
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var rss = require('rss');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
|
|
|
|
|
hasPrivileges(privileges.topics.can, tid, req, res, next);
|
|
|
|
|
}
|
|
|
|
|
var posts = require('../posts');
|
|
|
|
|
var topics = require('../topics');
|
|
|
|
|
var user = require('../user');
|
|
|
|
|
var categories = require('../categories');
|
|
|
|
|
var meta = require('../meta');
|
|
|
|
|
var helpers = require('../controllers/helpers');
|
|
|
|
|
var privileges = require('../privileges');
|
|
|
|
|
|
|
|
|
|
function hasCategoryPrivileges(req, res, next) {
|
|
|
|
|
var cid = req.params.category_id;
|
|
|
|
|
|
|
|
|
|
hasPrivileges(privileges.categories.can, cid, req, res, next);
|
|
|
|
|
function generateForTopic(req, res, callback) {
|
|
|
|
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hasPrivileges(method, id, req, res, next) {
|
|
|
|
|
method('read', id, req.uid, function(err, canRead) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
var tid = req.params.topic_id;
|
|
|
|
|
var userPrivileges;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
privileges: function(next) {
|
|
|
|
|
privileges.topics.get(tid, req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
topic: function(next) {
|
|
|
|
|
topics.getTopicData(tid, next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!canRead) {
|
|
|
|
|
return helpers.notAllowed(req, res);
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
if (!results.topic) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return next();
|
|
|
|
|
});
|
|
|
|
|
if (parseInt(results.topic.deleted, 10) && !results.privileges.view_deleted) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForTopic(req, res, next) {
|
|
|
|
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
|
|
|
|
return next();
|
|
|
|
|
if (!results.privileges.read) {
|
|
|
|
|
return helpers.notAllowed(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var tid = req.params.topic_id;
|
|
|
|
|
|
|
|
|
|
privileges.topics.get(tid, req.uid, function(err, userPrivileges) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
userPrivileges = results.privileges;
|
|
|
|
|
topics.getTopicWithPosts(results.topic, 'tid:' + tid + ':posts', req.uid, 0, 25, false, next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topics.getTopicWithPosts(tid, 'tid:' + tid + ':posts', req.uid, 0, 25, false, function (err, topicData) {
|
|
|
|
|
], function(err, topicData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (topicData.deleted && !userPrivileges.view_deleted) {
|
|
|
|
|
return next();
|
|
|
|
|
return callback(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topics.modifyByPrivilege(topicData.posts, userPrivileges);
|
|
|
|
@ -96,12 +86,11 @@ function generateForTopic(req, res, next) {
|
|
|
|
|
|
|
|
|
|
sendFeed(feed, res);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForUserTopics(req, res, next) {
|
|
|
|
|
function generateForUserTopics(req, res, callback) {
|
|
|
|
|
if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
|
|
|
|
|
return next();
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var userslug = req.params.userslug;
|
|
|
|
@ -111,6 +100,9 @@ function generateForUserTopics(req, res, next) {
|
|
|
|
|
user.getUidByUserslug(userslug, next);
|
|
|
|
|
},
|
|
|
|
|
function (uid, next) {
|
|
|
|
|
if (!uid) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
user.getUserFields(uid, ['uid', 'username'], next);
|
|
|
|
|
}
|
|
|
|
|
], function(err, userData) {
|
|
|
|
@ -134,6 +126,13 @@ function generateForCategory(req, res, next) {
|
|
|
|
|
}
|
|
|
|
|
var cid = req.params.category_id;
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
privileges: function(next) {
|
|
|
|
|
privileges.categories.get(cid, req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
category: function(next) {
|
|
|
|
|
categories.getCategoryById({
|
|
|
|
|
cid: cid,
|
|
|
|
|
set: 'cid:' + cid + ':tids',
|
|
|
|
@ -141,24 +140,28 @@ function generateForCategory(req, res, next) {
|
|
|
|
|
start: 0,
|
|
|
|
|
stop: 25,
|
|
|
|
|
uid: req.uid
|
|
|
|
|
}, function (err, categoryData) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}, next);
|
|
|
|
|
}
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
if (!results.privileges.read) {
|
|
|
|
|
return helpers.notAllowed(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generateTopicsFeed({
|
|
|
|
|
uid: req.uid,
|
|
|
|
|
title: categoryData.name,
|
|
|
|
|
description: categoryData.description,
|
|
|
|
|
title: results.category.name,
|
|
|
|
|
description: results.category.description,
|
|
|
|
|
feed_url: '/category/' + cid + '.rss',
|
|
|
|
|
site_url: '/category/' + categoryData.cid,
|
|
|
|
|
}, categoryData.topics, function(err, feed) {
|
|
|
|
|
site_url: '/category/' + results.category.cid,
|
|
|
|
|
}, results.category.topics, next);
|
|
|
|
|
}
|
|
|
|
|
], function(err, feed) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
sendFeed(feed, res);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function generateForRecent(req, res, next) {
|
|
|
|
@ -300,6 +303,9 @@ function generateForCategoryRecentPosts(req, res, next) {
|
|
|
|
|
var cid = req.params.category_id;
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
privileges: function(next) {
|
|
|
|
|
privileges.categories.get(cid, req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
category: function(next) {
|
|
|
|
|
categories.getCategoryData(cid, next);
|
|
|
|
|
},
|
|
|
|
@ -310,16 +316,20 @@ function generateForCategoryRecentPosts(req, res, next) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
if (!results.category) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var category = results.category;
|
|
|
|
|
var posts = results.posts;
|
|
|
|
|
if (!results.privileges.read) {
|
|
|
|
|
return helpers.notAllowed(req, res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var feed = generateForPostsFeed({
|
|
|
|
|
title: category.name + ' Recent Posts',
|
|
|
|
|
description: 'A list of recent posts from ' + category.name,
|
|
|
|
|
title: results.category.name + ' Recent Posts',
|
|
|
|
|
description: 'A list of recent posts from ' + results.category.name,
|
|
|
|
|
feed_url: '/category/' + cid + '/recentposts.rss',
|
|
|
|
|
site_url: '/category/' + cid + '/recentposts'
|
|
|
|
|
}, posts);
|
|
|
|
|
}, results.posts);
|
|
|
|
|
|
|
|
|
|
sendFeed(feed, res);
|
|
|
|
|
});
|
|
|
|
@ -355,12 +365,12 @@ function sendFeed(feed, res) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = function(app, middleware, controllers){
|
|
|
|
|
app.get('/topic/:topic_id.rss', hasTopicPrivileges, generateForTopic);
|
|
|
|
|
app.get('/category/:category_id.rss', hasCategoryPrivileges, generateForCategory);
|
|
|
|
|
app.get('/topic/:topic_id.rss', generateForTopic);
|
|
|
|
|
app.get('/category/:category_id.rss', generateForCategory);
|
|
|
|
|
app.get('/recent.rss', generateForRecent);
|
|
|
|
|
app.get('/popular.rss', generateForPopular);
|
|
|
|
|
app.get('/popular/:term.rss', generateForPopular);
|
|
|
|
|
app.get('/recentposts.rss', generateForRecentPosts);
|
|
|
|
|
app.get('/category/:category_id/recentposts.rss', hasCategoryPrivileges, generateForCategoryRecentPosts);
|
|
|
|
|
app.get('/category/:category_id/recentposts.rss', generateForCategoryRecentPosts);
|
|
|
|
|
app.get('/user/:userslug/topics.rss', generateForUserTopics);
|
|
|
|
|
};
|
|
|
|
|