mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
fix link tag url
This commit is contained in:
@@ -15,7 +15,7 @@ var helpers = require('./helpers');
|
|||||||
var pagination = require('../pagination');
|
var pagination = require('../pagination');
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
|
|
||||||
var topicsController = {};
|
var topicsController = module.exports;
|
||||||
|
|
||||||
topicsController.get = function (req, res, callback) {
|
topicsController.get = function (req, res, callback) {
|
||||||
var tid = req.params.topic_id;
|
var tid = req.params.topic_id;
|
||||||
@@ -134,170 +134,173 @@ topicsController.get = function (req, res, callback) {
|
|||||||
plugins.fireHook('filter:controllers.topic.get', { topicData: topicData, uid: req.uid }, next);
|
plugins.fireHook('filter:controllers.topic.get', { topicData: topicData, uid: req.uid }, next);
|
||||||
},
|
},
|
||||||
function (data, next) {
|
function (data, next) {
|
||||||
var breadcrumbs = [
|
buildBreadcrumbs(data.topicData, next);
|
||||||
{
|
|
||||||
text: data.topicData.category.name,
|
|
||||||
url: nconf.get('relative_path') + '/category/' + data.topicData.category.slug,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: data.topicData.title,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
helpers.buildCategoryBreadcrumbs(data.topicData.category.parentCid, function (err, crumbs) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
data.topicData.breadcrumbs = crumbs.concat(breadcrumbs);
|
|
||||||
next(null, data.topicData);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
function (topicData, next) {
|
function (topicData) {
|
||||||
function findPost(index) {
|
topicData.privileges = userPrivileges;
|
||||||
for (var i = 0; i < topicData.posts.length; i += 1) {
|
topicData.topicStaleDays = parseInt(meta.config.topicStaleDays, 10) || 60;
|
||||||
if (parseInt(topicData.posts[i].index, 10) === parseInt(index, 10)) {
|
topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
||||||
return topicData.posts[i];
|
topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
|
||||||
|
topicData['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
|
||||||
|
topicData.bookmarkThreshold = parseInt(meta.config.bookmarkThreshold, 10) || 5;
|
||||||
|
topicData.postEditDuration = parseInt(meta.config.postEditDuration, 10) || 0;
|
||||||
|
topicData.postDeleteDuration = parseInt(meta.config.postDeleteDuration, 10) || 0;
|
||||||
|
topicData.scrollToMyPost = settings.scrollToMyPost;
|
||||||
|
topicData.rssFeedUrl = nconf.get('relative_path') + '/topic/' + topicData.tid + '.rss';
|
||||||
|
if (req.uid) {
|
||||||
|
topicData.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken;
|
||||||
|
}
|
||||||
|
topicData.postIndex = req.params.post_index;
|
||||||
|
topicData.pagination = pagination.create(currentPage, pageCount, req.query);
|
||||||
|
topicData.pagination.rel.forEach(function (rel) {
|
||||||
|
rel.href = nconf.get('url') + '/topic/' + topicData.slug + rel.href;
|
||||||
|
res.locals.linkTags.push(rel);
|
||||||
|
});
|
||||||
|
|
||||||
|
req.session.tids_viewed = req.session.tids_viewed || {};
|
||||||
|
if (!req.session.tids_viewed[tid] || req.session.tids_viewed[tid] < Date.now() - 3600000) {
|
||||||
|
topics.increaseViewCount(tid);
|
||||||
|
req.session.tids_viewed[tid] = Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
addTags(topicData, req, res);
|
||||||
|
|
||||||
|
if (req.uid) {
|
||||||
|
topics.markAsRead([tid], req.uid, function (err, markedRead) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
if (markedRead) {
|
||||||
|
topics.pushUnreadCount(req.uid);
|
||||||
|
topics.markTopicNotificationsRead([tid], req.uid);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
var description = '';
|
|
||||||
var postAtIndex = findPost(Math.max(0, req.params.post_index - 1));
|
|
||||||
|
|
||||||
if (postAtIndex && postAtIndex.content) {
|
|
||||||
description = S(postAtIndex.content).decodeHTMLEntities().stripTags().s;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (description.length > 255) {
|
|
||||||
description = description.substr(0, 255) + '...';
|
|
||||||
}
|
|
||||||
|
|
||||||
var ogImageUrl = '';
|
|
||||||
if (topicData.thumb) {
|
|
||||||
ogImageUrl = topicData.thumb;
|
|
||||||
} else if (postAtIndex && postAtIndex.user && postAtIndex.user.picture) {
|
|
||||||
ogImageUrl = postAtIndex.user.picture;
|
|
||||||
} else if (meta.config['og:image']) {
|
|
||||||
ogImageUrl = meta.config['og:image'];
|
|
||||||
} else if (meta.config['brand:logo']) {
|
|
||||||
ogImageUrl = meta.config['brand:logo'];
|
|
||||||
} else {
|
|
||||||
ogImageUrl = '/logo.png';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof ogImageUrl === 'string' && ogImageUrl.indexOf('http') === -1) {
|
|
||||||
ogImageUrl = nconf.get('url') + ogImageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
description = description.replace(/\n/g, ' ');
|
|
||||||
|
|
||||||
res.locals.metaTags = [
|
|
||||||
{
|
|
||||||
name: 'title',
|
|
||||||
content: topicData.titleRaw,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'description',
|
|
||||||
content: description,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:title',
|
|
||||||
content: topicData.titleRaw,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:description',
|
|
||||||
content: description,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:type',
|
|
||||||
content: 'article',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:image',
|
|
||||||
content: ogImageUrl,
|
|
||||||
noEscape: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'og:image:url',
|
|
||||||
content: ogImageUrl,
|
|
||||||
noEscape: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'article:published_time',
|
|
||||||
content: utils.toISOString(topicData.timestamp),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'article:modified_time',
|
|
||||||
content: utils.toISOString(topicData.lastposttime),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
property: 'article:section',
|
|
||||||
content: topicData.category ? topicData.category.name : '',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
res.locals.linkTags = [
|
|
||||||
{
|
|
||||||
rel: 'alternate',
|
|
||||||
type: 'application/rss+xml',
|
|
||||||
href: nconf.get('url') + '/topic/' + tid + '.rss',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (topicData.category) {
|
|
||||||
res.locals.linkTags.push({
|
|
||||||
rel: 'up',
|
|
||||||
href: nconf.get('url') + '/category/' + topicData.category.slug,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res.render('topic', topicData);
|
||||||
|
},
|
||||||
|
], callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
function buildBreadcrumbs(topicData, callback) {
|
||||||
|
var breadcrumbs = [
|
||||||
|
{
|
||||||
|
text: topicData.category.name,
|
||||||
|
url: nconf.get('relative_path') + '/category/' + topicData.category.slug,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: topicData.title,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
helpers.buildCategoryBreadcrumbs(topicData.category.parentCid, next);
|
||||||
|
},
|
||||||
|
function (crumbs, next) {
|
||||||
|
topicData.breadcrumbs = crumbs.concat(breadcrumbs);
|
||||||
next(null, topicData);
|
next(null, topicData);
|
||||||
},
|
},
|
||||||
], function (err, data) {
|
], callback);
|
||||||
if (err) {
|
}
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
data.privileges = userPrivileges;
|
function addTags(topicData, req, res) {
|
||||||
data.topicStaleDays = parseInt(meta.config.topicStaleDays, 10) || 60;
|
function findPost(index) {
|
||||||
data['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
|
for (var i = 0; i < topicData.posts.length; i += 1) {
|
||||||
data['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
|
if (parseInt(topicData.posts[i].index, 10) === parseInt(index, 10)) {
|
||||||
data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
|
return topicData.posts[i];
|
||||||
data.bookmarkThreshold = parseInt(meta.config.bookmarkThreshold, 10) || 5;
|
}
|
||||||
data.postEditDuration = parseInt(meta.config.postEditDuration, 10) || 0;
|
|
||||||
data.postDeleteDuration = parseInt(meta.config.postDeleteDuration, 10) || 0;
|
|
||||||
data.scrollToMyPost = settings.scrollToMyPost;
|
|
||||||
data.rssFeedUrl = nconf.get('relative_path') + '/topic/' + data.tid + '.rss';
|
|
||||||
if (req.uid) {
|
|
||||||
data.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken;
|
|
||||||
}
|
}
|
||||||
data.postIndex = req.params.post_index;
|
}
|
||||||
data.pagination = pagination.create(currentPage, pageCount, req.query);
|
var description = '';
|
||||||
data.pagination.rel.forEach(function (rel) {
|
var postAtIndex = findPost(Math.max(0, req.params.post_index - 1));
|
||||||
rel.href = nconf.get('url') + '/topic/' + data.slug + rel.href;
|
|
||||||
res.locals.linkTags.push(rel);
|
if (postAtIndex && postAtIndex.content) {
|
||||||
|
description = S(postAtIndex.content).decodeHTMLEntities().stripTags().s;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (description.length > 255) {
|
||||||
|
description = description.substr(0, 255) + '...';
|
||||||
|
}
|
||||||
|
|
||||||
|
var ogImageUrl = '';
|
||||||
|
if (topicData.thumb) {
|
||||||
|
ogImageUrl = topicData.thumb;
|
||||||
|
} else if (postAtIndex && postAtIndex.user && postAtIndex.user.picture) {
|
||||||
|
ogImageUrl = postAtIndex.user.picture;
|
||||||
|
} else if (meta.config['og:image']) {
|
||||||
|
ogImageUrl = meta.config['og:image'];
|
||||||
|
} else if (meta.config['brand:logo']) {
|
||||||
|
ogImageUrl = meta.config['brand:logo'];
|
||||||
|
} else {
|
||||||
|
ogImageUrl = '/logo.png';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof ogImageUrl === 'string' && ogImageUrl.indexOf('http') === -1) {
|
||||||
|
ogImageUrl = nconf.get('url') + ogImageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
description = description.replace(/\n/g, ' ');
|
||||||
|
res.locals.metaTags = [
|
||||||
|
{
|
||||||
|
name: 'title',
|
||||||
|
content: topicData.titleRaw,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'description',
|
||||||
|
content: description,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:title',
|
||||||
|
content: topicData.titleRaw,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:description',
|
||||||
|
content: description,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:type',
|
||||||
|
content: 'article',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:image',
|
||||||
|
content: ogImageUrl,
|
||||||
|
noEscape: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'og:image:url',
|
||||||
|
content: ogImageUrl,
|
||||||
|
noEscape: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'article:published_time',
|
||||||
|
content: utils.toISOString(topicData.timestamp),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'article:modified_time',
|
||||||
|
content: utils.toISOString(topicData.lastposttime),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
property: 'article:section',
|
||||||
|
content: topicData.category ? topicData.category.name : '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
res.locals.linkTags = [
|
||||||
|
{
|
||||||
|
rel: 'alternate',
|
||||||
|
type: 'application/rss+xml',
|
||||||
|
href: topicData.rssFeedUrl,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (topicData.category) {
|
||||||
|
res.locals.linkTags.push({
|
||||||
|
rel: 'up',
|
||||||
|
href: nconf.get('url') + '/category/' + topicData.category.slug,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
req.session.tids_viewed = req.session.tids_viewed || {};
|
}
|
||||||
if (!req.session.tids_viewed[tid] || req.session.tids_viewed[tid] < Date.now() - 3600000) {
|
|
||||||
topics.increaseViewCount(tid);
|
|
||||||
req.session.tids_viewed[tid] = Date.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.uid) {
|
|
||||||
topics.markAsRead([tid], req.uid, function (err, markedRead) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
if (markedRead) {
|
|
||||||
topics.pushUnreadCount(req.uid);
|
|
||||||
topics.markTopicNotificationsRead([tid], req.uid);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
res.render('topic', data);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
topicsController.teaser = function (req, res, next) {
|
topicsController.teaser = function (req, res, next) {
|
||||||
var tid = req.params.topic_id;
|
var tid = req.params.topic_id;
|
||||||
@@ -363,5 +366,3 @@ topicsController.pagination = function (req, res, callback) {
|
|||||||
res.json(paginationData);
|
res.json(paginationData);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = topicsController;
|
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ describe('feeds', function () {
|
|||||||
|
|
||||||
it('should not allow access if token is correct but has no privilege', function (done) {
|
it('should not allow access if token is correct but has no privilege', function (done) {
|
||||||
privileges.categories.rescind(['read'], cid, 'registered-users', function (err) {
|
privileges.categories.rescind(['read'], cid, 'registered-users', function (err) {
|
||||||
|
assert.ifError(err);
|
||||||
request(nconf.get('url') + '/category/' + cid + '.rss?uid=' + fooUid + '&token=' + rssToken, { }, function (err, res, body) {
|
request(nconf.get('url') + '/category/' + cid + '.rss?uid=' + fooUid + '&token=' + rssToken, { }, function (err, res, body) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(res.statusCode, 200);
|
assert.equal(res.statusCode, 200);
|
||||||
|
|||||||
Reference in New Issue
Block a user