fix link tag url

v1.18.x
Baris Usakli 8 years ago
parent ef9e656f34
commit 77994dcf69

@ -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;
var description = ''; topicData.postDeleteDuration = parseInt(meta.config.postDeleteDuration, 10) || 0;
var postAtIndex = findPost(Math.max(0, req.params.post_index - 1)); topicData.scrollToMyPost = settings.scrollToMyPost;
topicData.rssFeedUrl = nconf.get('relative_path') + '/topic/' + topicData.tid + '.rss';
if (postAtIndex && postAtIndex.content) { if (req.uid) {
description = S(postAtIndex.content).decodeHTMLEntities().stripTags().s; 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);
});
if (description.length > 255) { req.session.tids_viewed = req.session.tids_viewed || {};
description = description.substr(0, 255) + '...'; if (!req.session.tids_viewed[tid] || req.session.tids_viewed[tid] < Date.now() - 3600000) {
topics.increaseViewCount(tid);
req.session.tids_viewed[tid] = Date.now();
} }
var ogImageUrl = ''; addTags(topicData, req, res);
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) { if (req.uid) {
ogImageUrl = nconf.get('url') + ogImageUrl; topics.markAsRead([tid], req.uid, function (err, markedRead) {
if (err) {
return callback(err);
}
if (markedRead) {
topics.pushUnreadCount(req.uid);
topics.markTopicNotificationsRead([tid], req.uid);
}
});
} }
description = description.replace(/\n/g, ' '); res.render('topic', topicData);
},
res.locals.metaTags = [ ], callback);
{ };
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) { function buildBreadcrumbs(topicData, callback) {
res.locals.linkTags.push({ var breadcrumbs = [
rel: 'up', {
href: nconf.get('url') + '/category/' + topicData.category.slug, 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);
function addTags(topicData, req, res) {
function findPost(index) {
for (var i = 0; i < topicData.posts.length; i += 1) {
if (parseInt(topicData.posts[i].index, 10) === parseInt(index, 10)) {
return topicData.posts[i];
}
} }
}
var description = '';
var postAtIndex = findPost(Math.max(0, req.params.post_index - 1));
data.privileges = userPrivileges; if (postAtIndex && postAtIndex.content) {
data.topicStaleDays = parseInt(meta.config.topicStaleDays, 10) || 60; description = S(postAtIndex.content).decodeHTMLEntities().stripTags().s;
data['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1; }
data['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
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);
data.pagination.rel.forEach(function (rel) {
rel.href = nconf.get('url') + '/topic/' + data.slug + rel.href;
res.locals.linkTags.push(rel);
});
req.session.tids_viewed = req.session.tids_viewed || {}; if (description.length > 255) {
if (!req.session.tids_viewed[tid] || req.session.tids_viewed[tid] < Date.now() - 3600000) { description = description.substr(0, 255) + '...';
topics.increaseViewCount(tid); }
req.session.tids_viewed[tid] = Date.now();
}
if (req.uid) { var ogImageUrl = '';
topics.markAsRead([tid], req.uid, function (err, markedRead) { if (topicData.thumb) {
if (err) { ogImageUrl = topicData.thumb;
return callback(err); } else if (postAtIndex && postAtIndex.user && postAtIndex.user.picture) {
} ogImageUrl = postAtIndex.user.picture;
if (markedRead) { } else if (meta.config['og:image']) {
topics.pushUnreadCount(req.uid); ogImageUrl = meta.config['og:image'];
topics.markTopicNotificationsRead([tid], req.uid); } else if (meta.config['brand:logo']) {
} ogImageUrl = meta.config['brand:logo'];
}); } else {
} ogImageUrl = '/logo.png';
}
res.render('topic', data); 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,
});
}
}
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);

Loading…
Cancel
Save