mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +01:00
closes #2835
This commit is contained in:
@@ -55,7 +55,7 @@ categoriesController.popular = function(req, res, next) {
|
||||
var data = {
|
||||
topics: topics,
|
||||
'feeds:disableRSS': parseInt(meta.config['feeds:disableRSS'], 10) === 1,
|
||||
rssFeedUrl: nconf.get('relative_path') + '/popular.rss',
|
||||
rssFeedUrl: nconf.get('relative_path') + '/popular/' + (req.params.term || 'daily') + '.rss',
|
||||
breadcrumbs: helpers.buildBreadcrumbs([{text: '[[global:header.popular]]'}])
|
||||
};
|
||||
|
||||
|
||||
@@ -135,15 +135,18 @@ function generateForCategory(req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var feed = generateTopicsFeed({
|
||||
generateTopicsFeed({
|
||||
title: categoryData.name,
|
||||
description: categoryData.description,
|
||||
feed_url: '/category/' + cid + '.rss',
|
||||
site_url: '/category/' + categoryData.cid,
|
||||
}, categoryData.topics);
|
||||
|
||||
}, categoryData.topics, function(err, feed) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
sendFeed(feed, res);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function generateForRecent(req, res, next) {
|
||||
@@ -156,12 +159,32 @@ function generateForRecent(req, res, next) {
|
||||
}
|
||||
|
||||
function generateForPopular(req, res, next) {
|
||||
generateForTopics({
|
||||
var uid = req.user ? req.user.uid : 0;
|
||||
var terms = {
|
||||
daily: 'day',
|
||||
weekly: 'week',
|
||||
monthly: 'month',
|
||||
alltime: 'alltime'
|
||||
};
|
||||
var term = terms[req.params.term] || 'day';
|
||||
|
||||
topics.getPopular(term, uid, 19, function(err, topics) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
generateTopicsFeed({
|
||||
title: 'Popular Topics',
|
||||
description: 'A list of topics that are sorted by post count',
|
||||
feed_url: '/popular.rss',
|
||||
site_url: '/popular'
|
||||
}, 'topics:posts', req, res, next);
|
||||
feed_url: '/popular/' + (req.params.term || 'daily') + '.rss',
|
||||
site_url: '/popular/' + (req.params.term || 'daily')
|
||||
}, topics, function(err, feed) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
sendFeed(feed, res);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function disabledRSS(req, res, next) {
|
||||
@@ -179,13 +202,34 @@ function generateForTopics(options, set, req, res, next) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var feed = generateTopicsFeed(options, data.topics);
|
||||
|
||||
generateTopicsFeed(options, data.topics, function(err, feed) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
sendFeed(feed, res);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function generateTopicsFeed(feedOptions, topics) {
|
||||
function generateTopicsFeed(feedOptions, feedTopics, callback) {
|
||||
var tids = feedTopics.map(function(topic) {
|
||||
return topic ? topic.tid : null;
|
||||
});
|
||||
|
||||
topics.getMainPids(tids, function(err, pids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
posts.getPostsFields(pids, ['content'], function(err, posts) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
feedTopics.forEach(function(topic, index) {
|
||||
if (topic && posts[index]) {
|
||||
topic.mainPost = posts[index].content;
|
||||
}
|
||||
});
|
||||
|
||||
feedOptions.ttl = 60;
|
||||
feedOptions.feed_url = nconf.get('url') + feedOptions.feed_url;
|
||||
@@ -193,20 +237,22 @@ function generateTopicsFeed(feedOptions, topics) {
|
||||
|
||||
var feed = new rss(feedOptions);
|
||||
|
||||
if (topics.length > 0) {
|
||||
feed.pubDate = new Date(parseInt(topics[0].lastposttime, 10)).toUTCString();
|
||||
if (feedTopics.length > 0) {
|
||||
feed.pubDate = new Date(parseInt(feedTopics[0].lastposttime, 10)).toUTCString();
|
||||
}
|
||||
|
||||
topics.forEach(function(topicData) {
|
||||
feedTopics.forEach(function(topicData) {
|
||||
feed.item({
|
||||
title: topicData.title,
|
||||
description: topicData.mainPost,
|
||||
url: nconf.get('url') + '/topic/' + topicData.slug,
|
||||
author: topicData.username,
|
||||
date: new Date(parseInt(topicData.lastposttime, 10)).toUTCString()
|
||||
});
|
||||
});
|
||||
|
||||
return feed;
|
||||
callback(null, feed);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function generateForRecentPosts(req, res, next) {
|
||||
@@ -291,6 +337,7 @@ module.exports = function(app, middleware, controllers){
|
||||
app.get('/category/:category_id.rss', hasCategoryPrivileges, disabledRSS, generateForCategory);
|
||||
app.get('/recent.rss', disabledRSS, generateForRecent);
|
||||
app.get('/popular.rss', disabledRSS, generateForPopular);
|
||||
app.get('/popular/:term.rss', disabledRSS, generateForPopular);
|
||||
app.get('/recentposts.rss', disabledRSS, generateForRecentPosts);
|
||||
app.get('/category/:category_id/recentposts.rss', hasCategoryPrivileges, disabledRSS, generateForCategoryRecentPosts);
|
||||
app.get('/user/:userslug/topics.rss', disabledRSS, generateForUserTopics);
|
||||
|
||||
@@ -255,7 +255,7 @@ var async = require('async'),
|
||||
});
|
||||
};
|
||||
|
||||
Topics.getMainPosts = function(tids, uid, callback) {
|
||||
Topics.getMainPids = function(tids, callback) {
|
||||
Topics.getTopicsFields(tids, ['mainPid'], function(err, topicData) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@@ -264,7 +264,15 @@ var async = require('async'),
|
||||
var mainPids = topicData.map(function(topic) {
|
||||
return topic ? topic.mainPid : null;
|
||||
});
|
||||
callback(null, mainPids);
|
||||
});
|
||||
};
|
||||
|
||||
Topics.getMainPosts = function(tids, uid, callback) {
|
||||
Topics.getMainPids(tids, function(err, mainPids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
getMainPosts(mainPids, uid, callback);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user