v1.18.x
Baris Usakli 12 years ago
parent a95582b382
commit 1e66116e1d

@ -2,19 +2,35 @@
var yourid = templates.get('yourid'),
theirid = templates.get('theirid');
function createMenu() {
var userslug = $('.account-username-box').attr('data-userslug');
var links = $('<div class="account-sub-links inline-block pull-right">\
<span id="settingsLink" class="pull-right"><a href="/users/' + userslug + '/settings">settings</a></span>\
<span id="favouritesLink" class="pull-right"><a href="/users/' + userslug + '/favourites">favourites</a></span>\
<span class="pull-right"><a href="/users/' + userslug + '/followers">followers</a></span>\
<span class="pull-right"><a href="/users/' + userslug + '/following">following</a></span>\
<span id="editLink" class="pull-right"><a href="/users/' + userslug + '/edit">edit</a></span>\
</div>');
$('.account-username-box').append(links);
}
$(document).ready(function() {
createMenu();
var editLink = $('#editLink');
var settingsLink = $('#settingsLink');
var favouritesLink = $('#favouritesLink');
if(yourid === "0") {
editLink.hide();
settingsLink.hide();
}
else if(yourid !== theirid) {
if(yourid === "0" || yourid !== theirid) {
editLink.hide();
settingsLink.hide();
favouritesLink.hide();
}
});
}());

@ -8,7 +8,7 @@
facebook_url = templates.get('facebook-share-url'),
google_url = templates.get('google-share-url'),
loadingMoreTopics = false;
app.enter_room(room);
twitterEl.addEventListener('click', function() {
@ -48,7 +48,7 @@
topic.innerHTML = html;
topic = topic.querySelector('a');
if (numTopics > 0) {
for(x=0;x<numTopics;x++) {
if (topics[x].querySelector('.icon-pushpin')) continue;
@ -75,7 +75,7 @@
var recent_replies = document.getElementById('category_recent_replies');
recent_replies.innerHTML = '';
var frag = document.createDocumentFragment(),
li = document.createElement('li');
for (var i=0,numPosts=posts.length; i<numPosts; i++) {
@ -95,7 +95,7 @@
recent_replies.appendChild(frag);
}
});
function onTopicsLoaded(topics) {
var html = templates.prepare(templates['category'].blocks['topics']).parse({ topics: topics }),
@ -106,14 +106,14 @@
container.append(html);
}
function loadMoreTopics(cid) {
loadingMoreTopics = true;
socket.emit('api:category.loadMore', {
cid: cid,
after: $('#topics-container').children().length
cid: cid,
after: $('#topics-container').children().length
}, function(data) {
if(data.topics.length) {
onTopicsLoaded(data.topics);

@ -0,0 +1,11 @@
(function() {
$(document).ready(function() {
$('.user-favourite-posts .topic-row').on('click', function() {
ajaxify.go($(this).attr('topic-url'));
});
});
}());

@ -1,20 +1,11 @@
<div class="well">
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div class="row-fluid">
<div class="span2 account-block" style="text-align: center; margin-bottom:20px;">
@ -32,26 +23,26 @@
<a id="unfollow-btn" href="#" class="btn hide">Unfollow</a>
</div>
</div>
<div class="span4">
<div class="inline-block">
<div class="account-bio-block">
<span class="account-bio-label">email</span><i class="icon-eye-close {emailClass}" title="Email hidden"></i>
<span>{email}</span>
<br/>
<span class="account-bio-label">full name</span>
<span>{fullname}</span>
<br/>
<span class="account-bio-label">website</span>
<span><a href="{website}">{website}</a></span>
<br/>
<span class="account-bio-label">location</span>
<span>{location}</span>
<br/>
<span class="account-bio-label">age</span>
<span>{age}</span>
<br/>
@ -66,20 +57,20 @@
<span class="account-bio-label">reputation</span>
<span class="formatted-number">{reputation}</span>
<br/>
<br/>
<span class="account-bio-label">posts</span>
<span class="formatted-number">{postcount}</span>
<br/>
<span class="account-bio-label">followers</span>
<span class="formatted-number">{followerCount}</span>
<br/>
<span class="account-bio-label">following</span>
<span class="formatted-number">{followingCount}</span>
<br/>
<hr/>
<span class="account-bio-label">signature</span>
<div class="post-signature">
@ -88,13 +79,13 @@
</div>
</div>
</div>
<div class="span6 user-recent-posts">
<!-- BEGIN posts -->
<div class="topic-row img-polaroid clearfix" topic-url="topic/{posts.tid}/#{posts.pid}">
<span>{posts.content}</span>
<span class="pull-right">{posts.relativeTime} ago</span>
</div>
</div>
<!-- END posts -->
</div>
</div>

@ -60,17 +60,11 @@
</div>
</div>
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a> <i class="icon-chevron-right"></i>
<a href="/users/{userslug}/edit">edit</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div class="row-fluid">
@ -171,4 +165,5 @@
<input type="hidden" template-variable="gravatarpicture" value="{gravatarpicture}" />
<input type="hidden" template-variable="uploadedpicture" value="{uploadedpicture}" />
<script type="text/javascript" src="{relative_path}/src/forum/accountheader.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/accountedit.js"></script>

@ -1,17 +1,11 @@
<div class="well">
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a> <i class="icon-chevron-right"></i>
<a href="/users/{userslug}/settings">settings</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div class="row-fluid">
@ -31,4 +25,5 @@
</div>
</div>
<script type="text/javascript" src="{relative_path}/src/forum/accountheader.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/accountsettings.js"></script>

@ -25,6 +25,7 @@
"users[^]*following": "following",
"users[^]*followers": "followers",
"users[^]*settings": "accountsettings",
"users[^]*favourites": "favourites",
"users/[^]*": "account",
"recent": "recent",

@ -0,0 +1,34 @@
<div class="well">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a>
</span>
</div>
<div id="no-favourites-notice" class="alert alert-warning {show_nofavourites}">You don't have any favourites, favourite some posts to see them here!</div>
<div class="row-fluid">
<div class="span12 user-favourite-posts">
<!-- BEGIN posts -->
<div class="topic-row img-polaroid clearfix" topic-url="topic/{posts.tid}/#{posts.pid}">
<span><strong>{posts.username}</strong> : </span>
<span>{posts.content}</span>
<div>
<span class="pull-right">{posts.relativeTime} ago</span>
</div>
</div>
<br/>
<!-- END posts -->
</div>
</div>
</div>
<script type="text/javascript" src="{relative_path}/src/forum/accountheader.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/favourites.js"></script>

@ -1,17 +1,11 @@
<div class="well">
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a> <i class="icon-chevron-right"></i>
<a href="/users/{userslug}/followers">followers</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div>
@ -32,7 +26,6 @@
<i class='icon-pencil'></i>
</div>
</div>
<!-- END followers -->
</div>
<div id="no-followers-notice" class="alert alert-warning hide">This user doesn't have any followers :(</div>

@ -1,19 +1,11 @@
<div class="well">
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a> <i class="icon-chevron-right"></i>
<a href="/users/{userslug}/following">following</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div>

@ -9,7 +9,7 @@ var RDB = require('./redis.js'),
(function(Categories) {
Categories.getCategoryById = function(category_id, current_user, callback) {
Categories.getCategoryData(category_id, function(err, categoryData) {
if (err) return callback(err);
@ -49,7 +49,7 @@ var RDB = require('./redis.js'),
next(null, topicsData);
}, category_id);
}
function getModerators(next) {
Categories.getModerators(category_id, next);
}
@ -162,16 +162,16 @@ var RDB = require('./redis.js'),
}
Categories.markAsRead = function(cid, uid) {
RDB.sadd('cid:' + cid + ':read_by_uid', uid);
RDB.sadd('cid:' + cid + ':read_by_uid', uid);
}
Categories.hasReadCategories = function(cids, uid, callback) {
var batch = RDB.multi();
for (var i=0, ii=cids.length; i<ii; i++) {
batch.sismember('cid:' + cids[i] + ':read_by_uid', uid);
batch.sismember('cid:' + cids[i] + ':read_by_uid', uid);
}
batch.exec(function(err, hasRead) {
callback(hasRead);
});
@ -180,14 +180,14 @@ var RDB = require('./redis.js'),
Categories.hasReadCategory = function(cid, uid, callback) {
RDB.sismember('cid:' + cid + ':read_by_uid', uid, function(err, hasRead) {
RDB.handle(err);
callback(hasRead);
});
});
}
Categories.getRecentReplies = function(cid, count, callback) {
RDB.zrevrange('categories:recent_posts:cid:' + cid, 0, (count<10)?10:count, function(err, pids) {
if(err) {
winston.err(err);
callback([]);
@ -199,7 +199,7 @@ var RDB = require('./redis.js'),
return;
}
posts.getPostSummaryByPids(pids, function(postData) {
posts.getPostSummaryByPids(pids, function(err, postData) {
if(postData.length > count) {
postData = postData.slice(0, count);
}
@ -214,8 +214,8 @@ var RDB = require('./redis.js'),
function movePost(pid, callback) {
posts.getPostField(pid, 'timestamp', function(timestamp) {
RDB.zrem('categories:recent_posts:cid:' + oldCid, pid);
RDB.zadd('categories:recent_posts:cid:' + cid, timestamp, pid);
RDB.zrem('categories:recent_posts:cid:' + oldCid, pid);
RDB.zadd('categories:recent_posts:cid:' + cid, timestamp, pid);
});
}
@ -240,20 +240,20 @@ var RDB = require('./redis.js'),
else callback(new Error('No category found!'));
});
}
Categories.getCategoryField = function(cid, field, callback) {
RDB.hget('category:' + cid, field, callback);
}
Categories.getCategoryFields = function(cid, fields, callback) {
RDB.hmgetObject('category:' + cid, fields, function(err, data) {
if(err === null)
if(err === null)
callback(data);
else
winston.err(err);
});
});
}
Categories.setCategoryField = function(cid, field, value) {
RDB.hset('category:' + cid, field, value);
}
@ -267,12 +267,12 @@ var RDB = require('./redis.js'),
callback({'categories' : []});
return;
}
var categories = [];
function getCategory(cid, callback) {
Categories.getCategoryData(cid, function(err, categoryData) {
if(err) {
callback(err);
return;
@ -284,20 +284,20 @@ var RDB = require('./redis.js'),
categories.push(categoryData);
callback(null);
}) ;
});
});
}
async.eachSeries(cids, getCategory, function(err) {
if(err) {
winston.err(err);
callback(null);
return;
}
callback({'categories': categories});
callback({'categories': categories});
});
};
};
}(exports));

@ -16,21 +16,23 @@ var RDB = require('./redis.js'),
return;
}
posts.getPostField(pid, 'uid', function(uid_of_poster) {
posts.getPostFields(pid, ['uid', 'timestamp'], function(postData) {
Favourites.hasFavourited(pid, uid, function(hasFavourited) {
if (hasFavourited == false) {
RDB.sadd('pid:' + pid + ':users_favourited', uid);
RDB.zadd('uid:' + uid + ':favourites', postData.timestamp, pid);
RDB.hincrby('post:' + pid, 'reputation', 1);
if (uid !== uid_of_poster) {
user.incrementUserFieldBy(uid_of_poster, 'reputation', 1, function(err, newreputation) {
RDB.zadd('users:reputation', newreputation, uid_of_poster);
if (uid !== postData.uid) {
user.incrementUserFieldBy(postData.uid, 'reputation', 1, function(err, newreputation) {
RDB.zadd('users:reputation', newreputation, postData.uid);
});
}
if (room_id) {
io.sockets.in(room_id).emit('event:rep_up', {uid: uid !== uid_of_poster ? uid_of_poster : 0, pid: pid});
io.sockets.in(room_id).emit('event:rep_up', {uid: uid !== postData.uid ? postData.uid : 0, pid: pid});
}
socket.emit('api:posts.favourite', {
@ -58,10 +60,12 @@ var RDB = require('./redis.js'),
Favourites.hasFavourited(pid, uid, function(hasFavourited) {
if (hasFavourited == true) {
RDB.srem('pid:' + pid + ':users_favourited', uid);
RDB.zrem('uid:' + uid + ':favourites', pid);
RDB.hincrby('post:' + pid, 'reputation', -1);
if (uid !== uid_of_poster) {
user.incrementUserFieldBy(uid_of_poster, 'reputation', -1, function(err, newreputation) {
RDB.zadd('users:reputation', newreputation, uid_of_poster);
@ -84,7 +88,7 @@ var RDB = require('./redis.js'),
Favourites.hasFavourited = function(pid, uid, callback) {
RDB.sismember('pid:' + pid + ':users_favourited', uid, function(err, hasFavourited) {
RDB.handle(err);
callback(hasFavourited);
});
}
@ -96,10 +100,10 @@ var RDB = require('./redis.js'),
for (var i=0, ii=pids.length; i<ii; i++) {
(function(post_id) {
Favourites.hasFavourited(post_id, uid, function(hasFavourited) {
data[post_id] = hasFavourited;
loaded ++;
if (loaded === pids.length)
if (loaded === pids.length)
callback(data);
});
}(pids[i]));

@ -18,11 +18,11 @@ var RDB = require('./redis.js'),
Posts.getPostsByTid = function(tid, start, end, callback) {
RDB.lrange('tid:' + tid + ':posts', start, end, function(err, pids) {
RDB.handle(err);
if (pids.length) {
Posts.getPostsByPids(pids, function(posts) {
Posts.getPostsByPids(pids, function(err, posts) {
callback(posts);
});
} else {
@ -30,7 +30,7 @@ var RDB = require('./redis.js'),
}
});
}
Posts.addUserInfoToPost = function(post, callback) {
user.getUserFields(post.uid, ['username', 'userslug', 'reputation', 'postcount', 'picture', 'signature', 'banned'], function(userData) {
@ -45,7 +45,7 @@ var RDB = require('./redis.js'),
if(post.editor !== '') {
user.getUserFields(post.editor, ['username', 'userslug'], function(editorData) {
post.editorname = editorData.username;
post.editorslug = editorData.userslug;
post.editorslug = editorData.userslug;
callback();
});
} else {
@ -55,9 +55,9 @@ var RDB = require('./redis.js'),
}
Posts.getPostSummaryByPids = function(pids, callback) {
var posts = [];
function getPostSummary(pid, callback) {
Posts.getPostFields(pid, ['pid', 'tid', 'content', 'uid', 'timestamp', 'deleted'], function(postData) {
if(postData.deleted === '1') {
@ -70,20 +70,20 @@ var RDB = require('./redis.js'),
if(postData.content)
postData.content = utils.strip_tags(postTools.markdownToHTML(postData.content));
postData.relativeTime = utils.relativeTime(postData.timestamp);
postData.topicSlug = topicSlug;
posts.push(postData);
posts.push(postData);
callback(null);
});
});
});
}
async.eachSeries(pids, getPostSummary, function(err) {
if(!err) {
callback(posts);
callback(null, posts);
} else {
console.log(err);
callback(err, null);
}
});
};
@ -112,7 +112,7 @@ var RDB = require('./redis.js'),
else {
console.log(err);
}
});
});
}
Posts.getPostField = function(pid, field, callback) {
@ -130,16 +130,16 @@ var RDB = require('./redis.js'),
Posts.getPostsByPids = function(pids, callback) {
var posts = [];
var posts = [];
function iterator(pid, callback) {
Posts.getPostData(pid, function(postData) {
if(postData) {
postData.relativeTime = utils.relativeTime(postData.timestamp);
postData.relativeTime = utils.relativeTime(postData.timestamp);
postData.post_rep = postData.reputation;
postData['edited-class'] = postData.editor !== '' ? '' : 'none';
postData['relativeEditTime'] = postData.edited !== '0' ? utils.relativeTime(postData.edited) : '';
postData.content = postTools.markdownToHTML(postData.content);
if(postData.uploadedImages) {
@ -155,9 +155,9 @@ var RDB = require('./redis.js'),
async.eachSeries(pids, iterator, function(err) {
if(!err) {
callback(posts);
callback(null, posts);
} else {
callback([]);
callback(err, null);
}
});
}
@ -185,7 +185,7 @@ var RDB = require('./redis.js'),
alert_id: 'post_error'
});
}
Posts.emitTooManyPostsAlert = function(socket) {
socket.emit('event:alert', {
title: 'Too many posts!',
@ -218,7 +218,7 @@ var RDB = require('./redis.js'),
Posts.get_cid_by_pid(postData.pid, function(cid) {
RDB.del('cid:' + cid + ':read_by_uid', function(err, data) {
topics.markAsRead(tid, uid);
topics.markAsRead(tid, uid);
});
});
@ -238,12 +238,12 @@ var RDB = require('./redis.js'),
postData
]
};
posts.addUserInfoToPost(socketData['posts'][0], function() {
io.sockets.in('topic_' + tid).emit('event:new_post', socketData);
io.sockets.in('recent_posts').emit('event:new_post', socketData);
});
});
callback(null, 'Reply successful');
} else {
callback(new Error('reply-error'), null);
@ -251,13 +251,13 @@ var RDB = require('./redis.js'),
});
});
};
Posts.create = function(uid, tid, content, images, callback) {
if (uid === null) {
callback(null);
return;
}
topics.isLocked(tid, function(locked) {
if (!locked || locked === '0') {
RDB.incr('global:next_post_id', function(err, pid) {
@ -277,7 +277,7 @@ var RDB = require('./redis.js'),
'deleted': 0,
'uploadedImages': ''
};
RDB.hmset('post:' + pid, postData);
topics.addPostToTopic(tid, pid);
@ -285,7 +285,7 @@ var RDB = require('./redis.js'),
topics.updateTimestamp(tid, timestamp);
RDB.incr('totalpostcount');
topics.getTopicField(tid, 'cid', function(err, cid) {
RDB.handle(err);
@ -302,9 +302,9 @@ var RDB = require('./redis.js'),
RDB.sadd('cid:' + cid + ':active_users', uid);
});
});
user.onNewPostMade(uid, tid, pid, timestamp);
});
user.onNewPostMade(uid, tid, pid, timestamp);
uploadPostImages(postData, images, function(err, uploadedImages) {
if(err) {
@ -315,9 +315,9 @@ var RDB = require('./redis.js'),
}
callback(postData);
});
plugins.fireHook('action:save_post_content', [pid, content]);
postSearch.index(content, pid);
});
});
@ -331,7 +331,7 @@ var RDB = require('./redis.js'),
var imgur = require('./imgur');
imgur.setClientID(config.imgurClientID);
var uploadedImages = [];
var uploadedImages = [];
function uploadImage(image, callback) {
imgur.upload(image.data, 'base64', function(err, data) {
@ -347,7 +347,7 @@ var RDB = require('./redis.js'),
callback(data);
}
}
});
});
}
if(!images) {
@ -363,20 +363,20 @@ var RDB = require('./redis.js'),
});
}
}
Posts.getPostsByUid = function(uid, start, end, callback) {
user.getPostIds(uid, start, end, function(pids) {
if(pids && pids.length) {
Posts.getPostsByPids(pids, function(posts) {
Posts.getPostsByPids(pids, function(err, posts) {
callback(posts);
});
}
else
callback([]);
});
});
}
Posts.getTopicPostStats = function(socket) {
@ -384,11 +384,11 @@ var RDB = require('./redis.js'),
if(err === null) {
var stats = {
topics: data[0]?data[0]:0,
posts: data[1]?data[1]:0
posts: data[1]?data[1]:0
};
socket.emit('post.stats', stats);
}
}
else
console.log(err);
});
@ -418,4 +418,19 @@ var RDB = require('./redis.js'),
});
}
Posts.getFavourites = function(uid, callback) {
RDB.zrevrange('uid:' + uid + ':favourites', 0, -1, function(err, pids) {
if(err)
return callback(err, null);
Posts.getPostSummaryByPids(pids, function(err, posts) {
if(err)
return callback(err, null);
callback(null, posts);
});
});
}
}(exports));

@ -5,7 +5,7 @@ var user = require('./../user.js'),
utils = require('./../../public/src/utils.js'),
pkg = require('../../package.json'),
meta = require('./../meta.js');
(function(Api) {
Api.create_routes = function(app) {
@ -19,11 +19,11 @@ var user = require('./../user.js'),
meta.config.getFields(['postDelay', 'minimumTitleLength', 'minimumPostLength', 'imgurClientID'], function(err, metaConfig) {
if(err) return next();
var clientConfig = require('../../public/config.json');
for (var attrname in metaConfig) {
clientConfig[attrname] = metaConfig[attrname];
for (var attrname in metaConfig) {
clientConfig[attrname] = metaConfig[attrname];
}
clientConfig['imgurClientIDSet'] = !!clientConfig['imgurClientID'];
delete clientConfig['imgurClientID'];
@ -65,7 +65,7 @@ var user = require('./../user.js'),
data = {
'login_window:spansize': 'span12',
'alternate_logins:display': 'none'
};
};
} else {
data = {
'login_window:spansize': 'span6',
@ -80,7 +80,7 @@ var user = require('./../user.js'),
res.json(data);
});
app.get('/api/register', function(req, res) {
var data = {},
login_strategies = auth.get_login_strategies(),
@ -90,7 +90,7 @@ var user = require('./../user.js'),
data = {
'register_window:spansize': 'span12',
'alternate_logins:display': 'none'
};
};
} else {
data = {
'register_window:spansize': 'span6',
@ -105,22 +105,22 @@ var user = require('./../user.js'),
res.json(data);
});
app.get('/api/topic/:id/:slug?', function(req, res) {
var uid = (req.user) ? req.user.uid : 0;
topics.getTopicWithPosts(req.params.id, uid, function(err, data) {
res.json(data);
});
});
});
app.get('/api/category/:id/:slug?', function(req, res, next) {
var uid = (req.user) ? req.user.uid : 0;
categories.getCategoryById(req.params.id, uid, function(err, data) {
if (!err)
if (!err)
res.json(data);
else
else
next();
}, req.params.id, uid);
}, req.params.id, uid);
});
app.get('/api/recent', function(req, res) {
@ -167,7 +167,7 @@ var user = require('./../user.js'),
res.status(404);
res.redirect(nconf.get('relative_path') + '/404');
}
});
});
app.get('/api/search', function(req, res) {
return res.json({
@ -194,7 +194,9 @@ var user = require('./../user.js'),
if(err)
return callback(err, null);
posts.getPostSummaryByPids(pids, function(posts) {
posts.getPostSummaryByPids(pids, function(err, posts) {
if(err)
return callback(err, null);
callback(null, posts);
});
})
@ -204,7 +206,7 @@ var user = require('./../user.js'),
search(topicSearch, function(err, tids) {
if(err)
return callback(err, null);
topics.getTopicsByTids(tids, 0, function(topics) {
callback(null, topics);
}, 0);
@ -212,7 +214,7 @@ var user = require('./../user.js'),
}
async.parallel([searchPosts, searchTopics], function(err, results) {
if (err)
if (err)
return next();
var noresults = !results[0].length && !results[1].length;
return res.json({
@ -223,7 +225,7 @@ var user = require('./../user.js'),
});
});
});
app.get('/api/reset', function(req, res) {
res.json({});
});
@ -235,7 +237,7 @@ var user = require('./../user.js'),
app.get('/api/404', function(req, res) {
res.json({});
});
app.get('/api/403', function(req, res) {
res.json({});
});

@ -9,12 +9,12 @@ var user = require('./../user.js'),
(function(User) {
User.create_routes = function(app) {
app.get('/uid/:uid', function(req, res) {
if(!req.params.uid)
return res.redirect('/404');
user.getUserData(req.params.uid, function(data) {
if(data) {
res.send(data);
@ -22,7 +22,7 @@ var user = require('./../user.js'),
res.json(404, {error:"User doesn't exist!"});
}
});
});
app.get('/users', function(req, res) {
@ -30,25 +30,25 @@ var user = require('./../user.js'),
res.send(header + app.create_route("users", "users") + templates['footer']);
});
});
app.get('/users-latest', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route("users-latest", "users") + templates['footer']);
});
});
app.get('/users-sort-posts', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route("users-sort-posts", "users") + templates['footer']);
});
});
app.get('/users-sort-reputation', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route("users-sort-reputation", "users") + templates['footer']);
});
});
app.get('/users-search', function(req, res) {
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route("users-search", "users") + templates['footer']);
@ -71,16 +71,16 @@ var user = require('./../user.js'),
res.send(header + app.create_route('users/' + req.params.userslug, 'account') + templates['footer']);
});
});
});
});
app.get('/users/:userslug/edit', function(req, res) {
if(!req.user)
return res.redirect('/403');
user.getUserField(req.user.uid, 'userslug', function(userslug) {
if(req.params.userslug && userslug === req.params.userslug) {
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/edit','accountedit') + templates['footer']);
@ -88,43 +88,43 @@ var user = require('./../user.js'),
} else {
return res.redirect('/404');
}
});
});
});
app.get('/users/:userslug/settings', function(req, res) {
if(!req.user)
return res.redirect('/403');
user.getUserField(req.user.uid, 'userslug', function(userslug) {
if(req.params.userslug && userslug === req.params.userslug) {
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/settings','accountsettings') + templates['footer']);
})
})
} else {
return res.redirect('/404');
}
});
});
});
app.post('/users/uploadpicture', function(req, res) {
if(!req.user)
return res.redirect('/403');
if(req.files.userPhoto.size > 262144) {
res.send({
error: 'Images must be smaller than 256kb!'
});
return;
}
var allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];
if(allowedTypes.indexOf(req.files.userPhoto.type) === -1) {
res.send({
error: 'Allowed image types are png, jpg and gif!'
});
return;
return;
}
user.getUserField(req.user.uid, 'uploadedpicture', function(oldpicture) {
@ -136,7 +136,7 @@ var user = require('./../user.js'),
var absolutePath = path.join(global.configuration['ROOT_DIRECTORY'], global.nconf.get('upload_path'), path.basename(oldpicture));
fs.unlink(absolutePath, function(err) {
if(err) {
if(err) {
winston.error('[%d] %s', Date.now(), + err);
}
@ -144,7 +144,7 @@ var user = require('./../user.js'),
});
});
});
function uploadUserPicture(uid, extension, tempPath, res) {
if(!extension) {
res.send({
@ -155,9 +155,9 @@ var user = require('./../user.js'),
var filename = uid + '-profileimg' + extension;
var uploadPath = path.join(global.configuration['ROOT_DIRECTORY'], global.nconf.get('upload_path'), filename);
winston.info('Attempting upload to: '+ uploadPath);
var is = fs.createReadStream(tempPath);
var os = fs.createWriteStream(uploadPath);
@ -195,24 +195,24 @@ var user = require('./../user.js'),
if(!req.user)
return res.redirect('/403');
user.get_uid_by_userslug(req.params.userslug, function(uid) {
if(!uid) {
res.redirect('/404');
return;
}
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/following','following') + templates['footer']);
});
});
});
app.get('/users/:userslug/followers', function(req, res) {
if(!req.user)
return res.redirect('/403');
user.get_uid_by_userslug(req.params.userslug, function(uid) {
if(!uid) {
res.redirect('/404');
@ -224,6 +224,22 @@ var user = require('./../user.js'),
});
});
app.get('/users/:userslug/favourites', function(req, res) {
if(!req.user)
return res.redirect('/403');
user.get_uid_by_userslug(req.params.userslug, function(uid) {
if(!uid) {
res.redirect('/404');
return;
}
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/favourites','favourites') + templates['footer']);
});
});
});
app.get('/api/users/:userslug/following', function(req, res) {
var callerUID = req.user ? req.user.uid : 0;
@ -234,7 +250,7 @@ var user = require('./../user.js'),
userData.followingCount = followingData.length;
res.json(userData);
});
} else {
res.json(404, { error: 'User not found!' }) ;
}
@ -243,7 +259,7 @@ var user = require('./../user.js'),
app.get('/api/users/:userslug/followers', function(req, res) {
var callerUID = req.user ? req.user.uid : 0;
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
if(userData) {
user.getFollowers(userData.uid, function(followersData) {
@ -253,7 +269,7 @@ var user = require('./../user.js'),
});
} else {
res.json(404, { error: 'User not found!' }) ;
}
}
});
});
@ -273,7 +289,7 @@ var user = require('./../user.js'),
res.json(404, { error: 'User not found!' }) ;
return;
}
if(uid !== callerUID || callerUID === "0") {
res.json(403, { error: 'Not allowed!' });
return;
@ -287,9 +303,39 @@ var user = require('./../user.js'),
res.json(userData);
} else {
res.json(404, { error: 'User not found!' }) ;
}
}
});
});
});
app.get('/api/users/:userslug/favourites', function(req, res, next) {
var callerUID = req.user ? req.user.uid : 0;
user.get_uid_by_userslug(req.params.userslug, function(uid) {
if(!uid) {
res.json(404, { error: 'User not found!' }) ;
return;
}
if(uid !== callerUID || callerUID === "0") {
res.json(403, { error: 'Not allowed!' });
return;
}
user.getUserFields(uid, ['username','userslug'], function(userData) {
if(userData) {
posts.getFavourites(uid, function(err, posts) {
if(err)
return next(err);
userData.posts = posts;
userData.show_nofavourites = posts.length?'hide':'show';
res.json(userData);
});
} else {
res.json(404, { error: 'User not found!' }) ;
}
});
});
});
});
app.get('/api/users/:userslug', function(req, res) {
@ -313,7 +359,7 @@ var user = require('./../user.js'),
} else {
res.json(404, { error: 'User not found!' }) ;
}
});
});
});
app.get('/api/users', getUsersSortedByJoinDate);
@ -321,14 +367,14 @@ var user = require('./../user.js'),
app.get('/api/users-sort-reputation', getUsersSortedByReputation);
app.get('/api/users-latest', getUsersSortedByJoinDate);
app.get('/api/users-search', getUsersForSearch);
function getUsersSortedByJoinDate(req, res) {
user.getUsers('users:joindate', 0, 49, function(err, data) {
res.json({ search_display: 'none', loadmore_display:'block', users:data });
});
}
function getUsersSortedByPosts(req, res) {
user.getUsers('users:postcount', 0, 49, function(err, data) {
res.json({ search_display: 'none', loadmore_display:'block', users:data });
@ -340,19 +386,19 @@ var user = require('./../user.js'),
res.json({ search_display: 'none', loadmore_display:'block', users:data });
});
}
function getUsersForSearch(req, res) {
function getUsersForSearch(req, res) {
res.json({ search_display: 'block', loadmore_display:'none', users: [] });
}
function getUserDataByUserSlug(userslug, callerUID, callback) {
user.get_uid_by_userslug(userslug, function(uid) {
if(uid === null) {
callback(null);
return;
}
user.getUserData(uid, function(data) {
if(data) {
data.joindate = utils.relativeTime(data.joindate);
@ -362,21 +408,21 @@ var user = require('./../user.js'),
} else {
data.age = new Date().getFullYear() - new Date(data.birthday).getFullYear();
}
function canSeeEmail() {
return callerUID === uid || (data.email && (data.showemail && data.showemail === "1"));
}
if(!canSeeEmail())
if(!canSeeEmail())
data.email = "";
if(callerUID === uid && (!data.showemail || data.showemail === "0"))
data.emailClass = "";
else
else
data.emailClass = "hide";
data.show_banned = data.banned === '1'?'':'hide';
data.uid = uid;
data.yourid = callerUID;
data.theirid = uid;
@ -392,7 +438,7 @@ var user = require('./../user.js'),
callback(null);
}
});
});
}

Loading…
Cancel
Save