more cleanup and changes to topics

v1.18.x
Baris Soner Usakli 11 years ago
parent d149622f0b
commit ea6cf3bbd5

@ -1,9 +1,15 @@
<input type="hidden" template-variable="category_id" value="{cid}" />
<input type="hidden" template-variable="category_name" value="{name}" />
<input type="hidden" template-variable="currentPage" value="{currentPage}" />
<input type="hidden" template-variable="pageCount" value="{pageCount}" />
<ol class="breadcrumb">
<li itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="{relative_path}/" itemprop="url"><span itemprop="title">[[global:home]]</span></a>
</li>
<li class="active" itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<span itemprop="title">{category_name} <a target="_blank" href="../{category_id}.rss"><i class="fa fa-rss-square"></i></a></span>
<span itemprop="title">{name} <a target="_blank" href="../{cid}.rss"><i class="fa fa-rss-square"></i></a></span>
</li>
</ol>
@ -109,7 +115,3 @@
<!-- ENDIF topics.length -->
</div>
<input type="hidden" template-variable="category_id" value="{category_id}" />
<input type="hidden" template-variable="category_name" value="{category_name}" />
<input type="hidden" template-variable="currentPage" value="{currentPage}" />
<input type="hidden" template-variable="pageCount" value="{pageCount}" />

@ -3,17 +3,17 @@
<a href="{relative_path}/" itemprop="url"><span itemprop="title">[[global:home]]</span></a>
</li>
<li class="active" itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<span itemprop="title">{category_name} <a target="_blank" href="../{category_id}.rss"><i class="fa fa-rss-square"></i></a></span>
<span itemprop="title">{name} <a target="_blank" href="../{cid}.rss"><i class="fa fa-rss-square"></i></a></span>
</li>
</ol>
<ul class="topics" itemscope itemtype="http://www.schema.org/ItemList" data-nextstart="{nextStart}">
<!-- BEGIN topics -->
<li itemprop="itemListElement">
<meta itemprop="name" content="{topics.title}">
<span class="timestamp">{topics.teaser_timestamp}</span>
<span class="timestamp">{topics.teaser.timestamp}</span>
<a href="../../topic/{topics.slug}" itemprop="url">{topics.title} ({topics.postcount})</a>
<div class="teaser">
<img class="img-thumbnail" src="{topics.teaser_userpicture}" />
<img class="img-thumbnail" src="{topics.teaser.picture}" />
<div class="clear"></div>
</div>
</li>

@ -3,10 +3,10 @@
<a href="{relative_path}/" itemprop="url"><span itemprop="title">[[global:home]]</span></a>
</li>
<li itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="{relative_path}/category/{category_slug}" itemprop="url"><span itemprop="title">{category_name}</span></a>
<a href="{relative_path}/category/{category.slug}" itemprop="url"><span itemprop="title">{category.name}</span></a>
</li>
<li class="active" itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<span itemprop="title">{topic_name} <a target="_blank" href="../{topic_id}.rss"><i class="fa fa-rss-square"></i></a></span>
<span itemprop="title">{title} <a target="_blank" href="../{tid}.rss"><i class="fa fa-rss-square"></i></a></span>
</li>
</ol>
<ul class="posts">

@ -1,11 +1,11 @@
<input type="hidden" template-variable="expose_tools" value="{expose_tools}" />
<input type="hidden" template-variable="topic_id" value="{topic_id}" />
<input type="hidden" template-variable="topic_id" value="{tid}" />
<input type="hidden" template-variable="currentPage" value="{currentPage}" />
<input type="hidden" template-variable="pageCount" value="{pageCount}" />
<input type="hidden" template-variable="locked" value="{locked}" />
<input type="hidden" template-variable="deleted" value="{deleted}" />
<input type="hidden" template-variable="pinned" value="{pinned}" />
<input type="hidden" template-variable="topic_name" value="{topic_name}" />
<input type="hidden" template-variable="topic_name" value="{title}" />
<input type="hidden" template-variable="postcount" value="{postcount}" />
<div class="topic">
@ -14,14 +14,14 @@
<a href="{relative_path}/" itemprop="url"><span itemprop="title">[[global:home]]</span></a>
</li>
<li itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<a href="{relative_path}/category/{category_slug}" itemprop="url"><span itemprop="title">{category_name}</span></a>
<a href="{relative_path}/category/{category.slug}" itemprop="url"><span itemprop="title">{category.name}</span></a>
</li>
<li class="active" itemscope="itemscope" itemtype="http://data-vocabulary.org/Breadcrumb">
<span itemprop="title">{topic_name} <a target="_blank" href="../{topic_id}.rss"><i class="fa fa-rss-square"></i></a></span>
<span itemprop="title">{title} <a target="_blank" href="../{tid}.rss"><i class="fa fa-rss-square"></i></a></span>
</li>
</ol>
<ul id="post-container" class="posts" data-tid="{topic_id}">
<ul id="post-container" class="posts" data-tid="{tid}">
<!-- BEGIN posts -->
<li class="post-row infiniteloaded" data-pid="{posts.pid}" data-uid="{posts.uid}" data-username="{posts.username}" data-userslug="{posts.userslug}" data-index="{posts.index}" data-deleted="{posts.deleted}" itemscope itemtype="http://schema.org/Comment">
<a id="post_anchor_{posts.pid}" name="{posts.pid}"></a>
@ -44,7 +44,7 @@
<img itemprop="image" src="{posts.picture}" align="left" class="img-thumbnail" width=150 height=150 />
</a>
<h3 class="main-post">
<p id="topic_title_{posts.pid}" class="topic-title" itemprop="name">{topic_name}</p>
<p id="topic_title_{posts.pid}" class="topic-title" itemprop="name">{title}</p>
</h3>
<div class="topic-buttons">

@ -59,39 +59,27 @@ var db = require('./database'),
Categories.markAsRead(cid, uid);
}
function getCategoryData(next) {
Categories.getCategoryData(cid, next);
}
function getTopics(next) {
Categories.getCategoryTopics(cid, start, end, uid, next);
}
function getPageCount(next) {
Categories.getPageCount(cid, uid, next);
}
async.parallel({
'category': getCategoryData,
'topics': getTopics,
'pageCount': getPageCount
category: function(next) {
Categories.getCategoryData(cid, next);
},
topics : function(next) {
Categories.getCategoryTopics(cid, start, end, uid, next);
},
pageCount: function(next) {
Categories.getPageCount(cid, uid, next);
}
}, function(err, results) {
if(err) {
return callback(err);
}
var category = {
'category_name': results.category.name,
'category_description': results.category.description,
'link': results.category.link,
'disabled': results.category.disabled,
'topic_row_size': 'col-md-9',
'category_id': cid,
'topics': results.topics.topics,
'nextStart': results.topics.nextStart,
'pageCount': results.pageCount,
'disableSocialButtons': meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false,
};
var category = results.category;
category.topics = results.topics.topics;
category.nextStart = results.topics.nextStart;
category.pageCount = results.pageCount;
category.disableSocialButtons = meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false;
category.topic_row_size = 'col-md-9';
callback(null, category);
});

@ -169,7 +169,8 @@ var path = require('path'),
});
app.get('/topic/:id/:slug?', function (req, res, next) {
var uid = (req.user) ? req.user.uid : 0;
var uid = req.user? parseInt(req.user.uid, 10) : 0;
var tid = req.params.id;
var page = 1;
if(req.query && req.query.page) {
page = req.query.page;
@ -187,29 +188,41 @@ var path = require('path'),
var start = (page - 1) * settings.postsPerPage;
var end = start + settings.postsPerPage - 1;
ThreadTools.privileges(req.params.id, uid, function(err, privileges) {
if (privileges.read) {
topics.getTopicWithPosts(req.params.id, uid, start, end, false, function (err, data) {
if(err) {
return next(err);
}
ThreadTools.privileges(tid, uid, function(err, privileges) {
if(err) {
return next(err);
}
if(page > data.pageCount) {
return res.send(404);
}
if(!privileges.read) {
res.send(403);
}
data.currentPage = page;
data.privileges = privileges;
topics.getTopicWithPosts(tid, uid, start, end, function (err, data) {
if(err) {
return next(err);
}
if (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) {
return res.json(404, {});
}
if(page > data.pageCount) {
return res.send(404);
}
res.json(data);
});
} else {
res.send(403);
}
if (parseInt(data.deleted, 10) === 1 && parseInt(data.expose_tools, 10) === 0) {
return res.json(404, {});
}
data.currentPage = page;
data.privileges = privileges;
if (uid) {
topics.markAsRead(tid, uid, function(err) {
topics.pushUnreadCount(uid);
});
}
topics.increaseViewCount(tid);
res.json(data);
});
});
});
});

@ -55,7 +55,7 @@
function generateForTopic(req, res, next) {
var tid = req.params.topic_id;
topics.getTopicWithPosts(tid, 0, 0, 25, true, function (err, topicData) {
topics.getTopicWithPosts(tid, 0, 0, 25, function (err, topicData) {
if (err) {
return next(err);
}
@ -65,7 +65,7 @@
var author = topicData.posts.length ? topicData.posts[0].username : '';
var feed = new rss({
title: topicData.topic_name,
title: topicData.title,
description: description,
feed_url: nconf.get('url') + '/topic/' + tid + '.rss',
site_url: nconf.get('url') + '/topic/' + topicData.slug,
@ -85,7 +85,7 @@
dateStamp = new Date(parseInt(parseInt(postData.edited, 10) === 0 ? postData.timestamp : postData.edited, 10)).toUTCString();
feed.item({
title: 'Reply to ' + topicData.topic_name + ' on ' + dateStamp,
title: 'Reply to ' + topicData.title + ' on ' + dateStamp,
description: postData.content,
url: nconf.get('url') + '/topic/' + topicData.slug + '#' + postData.pid,
author: postData.username,
@ -109,10 +109,10 @@
}
var feed = new rss({
title: categoryData.category_name,
description: categoryData.category_description,
title: categoryData.name,
description: categoryData.description,
feed_url: nconf.get('url') + '/category/' + cid + '.rss',
site_url: nconf.get('url') + '/category/' + categoryData.category_id,
site_url: nconf.get('url') + '/category/' + categoryData.cid,
ttl: 60
});

@ -217,7 +217,6 @@ SocketPosts.getFavouritedUsers = function(socket, pid, callback) {
callback(null, "");
}
console.log(data);
var max = 5; //hardcoded
var usernames = "";

@ -247,7 +247,7 @@ SocketTopics.loadMore = function(socket, data, callback) {
async.parallel({
posts: function(next) {
topics.getTopicPosts(data.tid, start, end, socket.uid, next);
topics.getTopicPosts(data.tid, start, end, socket.uid, false, next);
},
privileges: function(next) {
threadTools.privileges(data.tid, socket.uid, next);

@ -634,7 +634,7 @@ var async = require('async'),
});
};
Topics.getTopicsByTids = function(tids, cid, current_user, callback) {
Topics.getTopicsByTids = function(tids, cid, uid, callback) {
if (!Array.isArray(tids) || tids.length === 0) {
return callback(null, []);
@ -643,13 +643,13 @@ var async = require('async'),
function getTopicInfo(topicData, callback) {
async.parallel({
hasread : function (next) {
Topics.hasReadTopic(topicData.tid, current_user, next);
Topics.hasReadTopic(topicData.tid, uid, next);
},
teaser : function (next) {
Topics.getTeaser(topicData.tid, next);
},
privileges : function (next) {
categoryTools.privileges(topicData.cid, current_user, next);
categoryTools.privileges(topicData.cid, uid, next);
},
categoryData : function (next) {
categories.getCategoryFields(topicData.cid, ['name', 'slug', 'icon'], next);
@ -660,7 +660,7 @@ var async = require('async'),
function isTopicVisible(topicData, topicInfo) {
var deleted = parseInt(topicData.deleted, 10) !== 0;
return !deleted || (deleted && topicInfo.privileges.view_deleted) || parseInt(topicData.uid, 10) === parseInt(current_user, 10);
return !deleted || (deleted && topicInfo.privileges.view_deleted) || parseInt(topicData.uid, 10) === parseInt(uid, 10);
}
function loadTopic(tid, next) {
@ -686,7 +686,7 @@ var async = require('async'),
topicData.pinned = parseInt(topicData.pinned, 10) === 1;
topicData.locked = parseInt(topicData.locked, 10) === 1;
topicData.deleted = parseInt(topicData.deleted, 10) === 1;
topicData.unread = !(topicInfo.hasread && parseInt(current_user, 10) !== 0);
topicData.unread = !(topicInfo.hasread && parseInt(uid, 10) !== 0);
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
topicData.category = topicInfo.categoryData;
@ -710,78 +710,47 @@ var async = require('async'),
});
};
Topics.getTopicWithPosts = function(tid, current_user, start, end, quiet, callback) {
Topics.getTopicWithPosts = function(tid, uid, start, end, callback) {
threadTools.exists(tid, function(err, exists) {
if (err || !exists) {
return callback(err || new Error('Topic tid \'' + tid + '\' not found'));
}
// "quiet" is used for things like RSS feed updating, HTML parsing for non-js users, etc
if (!quiet) {
Topics.markAsRead(tid, current_user, function(err) {
Topics.pushUnreadCount(current_user);
});
Topics.increaseViewCount(tid);
}
function getTopicData(next) {
Topics.getTopicData(tid, next);
}
function getTopicPosts(next) {
Topics.getTopicPosts(tid, start, end, current_user, false, next);
}
function getPrivileges(next) {
threadTools.privileges(tid, current_user, next);
}
function getCategoryData(next) {
Topics.getCategoryData(tid, next);
}
function getPageCount(next) {
Topics.getPageCount(tid, current_user, next);
}
function getThreadTools(next) {
Plugins.fireHook('filter:topic.thread_tools', [], function(err, threadTools) {
next(err, threadTools);
});
}
async.parallel([getTopicData, getTopicPosts, getPrivileges, getCategoryData, getPageCount, getThreadTools], function(err, results) {
async.parallel({
topicData : function(next) {
Topics.getTopicData(tid, next);
},
posts : function(next) {
Topics.getTopicPosts(tid, start, end, uid, false, next);
},
privileges : function(next) {
threadTools.privileges(tid, uid, next);
},
category : function(next) {
Topics.getCategoryData(tid, next);
},
pageCount : function(next) {
Topics.getPageCount(tid, uid, next);
},
threadTools : function(next) {
Plugins.fireHook('filter:topic.thread_tools', [], next);
}
}, function(err, results) {
if (err) {
winston.error('[Topics.getTopicWithPosts] Could not retrieve topic data: ', err.message);
return callback(err);
}
var topicData = results[0],
privileges = results[2],
categoryData = results[3],
pageCount = results[4],
threadTools = results[5];
callback(null, {
'topic_name': topicData.title,
'category_name': categoryData.name,
'category_slug': categoryData.slug,
'locked': topicData.locked,
'deleted': topicData.deleted,
'pinned': topicData.pinned,
'timestamp': topicData.timestamp,
'slug': topicData.slug,
'thumb': topicData.thumb,
'postcount': topicData.postcount,
'viewcount': topicData.viewcount,
'pageCount': pageCount,
'unreplied': parseInt(topicData.postcount, 10) === 1,
'topic_id': tid,
'expose_tools': privileges.editable ? 1 : 0,
'thread_tools': threadTools,
'disableSocialButtons': meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false,
'posts': results[1]
});
var topicData = results.topicData;
topicData.category = results.category;
topicData.posts = results.posts;
topicData.thread_tools = results.threadTools;
topicData.pageCount = results.pageCount;
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
topicData.expose_tools = results.privileges.editable ? 1 : 0;
topicData.disableSocialButtons = meta.config.disableSocialButtons !== undefined ? parseInt(meta.config.disableSocialButtons, 10) !== 0 : false;
callback(null, topicData);
});
});
};

@ -596,7 +596,7 @@ process.on('uncaughtException', function(err) {
var start = (page - 1) * settings.topicsPerPage,
end = start + settings.topicsPerPage - 1;
topics.getTopicWithPosts(tid, uid, start, end, true, function (err, topicData) {
topics.getTopicWithPosts(tid, uid, start, end, function (err, topicData) {
if (topicData) {
if (parseInt(topicData.deleted, 10) === 1 && parseInt(topicData.expose_tools, 10) === 0) {
return next(new Error('Topic deleted'), null);
@ -642,7 +642,7 @@ process.on('uncaughtException', function(err) {
metaTags: [
{
name: "title",
content: topicData.topic_name
content: topicData.title
},
{
name: "description",
@ -650,7 +650,7 @@ process.on('uncaughtException', function(err) {
},
{
property: 'og:title',
content: topicData.topic_name
content: topicData.title
},
{
property: 'og:description',
@ -682,7 +682,7 @@ process.on('uncaughtException', function(err) {
},
{
property: 'article:section',
content: topicData.category_name
content: topicData.category.name
}
],
linkTags: [
@ -693,7 +693,7 @@ process.on('uncaughtException', function(err) {
},
{
rel: 'up',
href: nconf.get('url') + '/category/' + topicData.category_slug
href: nconf.get('url') + '/category/' + topicData.category.slug
}
]
}, function (err, header) {
@ -783,15 +783,15 @@ process.on('uncaughtException', function(err) {
metaTags: [
{
name: 'title',
content: categoryData.category_name
content: categoryData.name
},
{
property: 'og:title',
content: categoryData.category_name
content: categoryData.name
},
{
name: 'description',
content: categoryData.category_description
content: categoryData.description
},
{
property: "og:type",

@ -33,8 +33,8 @@ describe('Categories', function() {
it('should retrieve a newly created category by its ID', function(done) {
Categories.getCategoryById(categoryObj.cid, 0, -1, 0, function(err, categoryData) {
assert(categoryData);
assert.equal(categoryObj.name, categoryData.category_name);
assert.equal(categoryObj.description, categoryData.category_description);
assert.equal(categoryObj.name, categoryData.name);
assert.equal(categoryObj.description, categoryData.description);
done();
});

Loading…
Cancel
Save