diff --git a/public/src/client/topic/events.js b/public/src/client/topic/events.js index ff34985c92..f4c69a121e 100644 --- a/public/src/client/topic/events.js +++ b/public/src/client/topic/events.js @@ -69,7 +69,7 @@ define('forum/topic/events', [ }; function updatePostVotesAndUserReputation(data) { - var votes = $('li[data-pid="' + data.post.pid + '"] .votes'), + var votes = $('[data-pid="' + data.post.pid + '"] .votes'), reputationElements = $('.reputation[data-uid="' + data.post.uid + '"]'); votes.html(data.post.votes).attr('data-votes', data.post.votes); @@ -77,7 +77,7 @@ define('forum/topic/events', [ } function updateFavouriteCount(data) { - $('li[data-pid="' + data.post.pid + '"] .favouriteCount').html(data.post.reputation).attr('data-favourites', data.post.reputation); + $('[data-pid="' + data.post.pid + '"] .favouriteCount').html(data.post.reputation).attr('data-favourites', data.post.reputation); } function toggleTopicDeleteState(data) { @@ -139,14 +139,14 @@ define('forum/topic/events', [ } function onPostPurged(pid) { - $('#post-container li[data-pid="' + pid + '"]').fadeOut(500, function() { + $('#post-container [data-pid="' + pid + '"]').fadeOut(500, function() { $(this).remove(); }); postTools.updatePostCount(); } function togglePostDeleteState(data) { - var postEl = $('#post-container li[data-pid="' + data.pid + '"]'); + var postEl = $('#post-container [data-pid="' + data.pid + '"]'); if (!postEl.length) { return; @@ -166,7 +166,7 @@ define('forum/topic/events', [ } function togglePostFavourite(data) { - var favBtn = $('li[data-pid="' + data.post.pid + '"] .favourite'); + var favBtn = $('[data-pid="' + data.post.pid + '"] .favourite'); if (!favBtn.length) { return; } @@ -185,7 +185,7 @@ define('forum/topic/events', [ } function togglePostVote(data) { - var post = $('li[data-pid="' + data.post.pid + '"]'); + var post = $('[data-pid="' + data.post.pid + '"]'); post.find('.upvote').toggleClass('btn-primary upvoted', data.upvote); post.find('.downvote').toggleClass('btn-primary downvoted', data.downvote); diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index 7bd7b714ae..05bc505ae2 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -47,7 +47,7 @@ define('forum/topic/posts', [ function removeAlreadyAddedPosts() { data.posts = data.posts.filter(function(post) { - return $('#post-container li[data-pid="' + post.pid +'"]').length === 0; + return $('#post-container [data-pid="' + post.pid +'"]').length === 0; }); } @@ -59,8 +59,8 @@ define('forum/topic/posts', [ var firstPostVotes = parseInt(data.posts[0].votes, 10); var firstPostIndex = parseInt(data.posts[0].index, 10); - var firstReply = $('#post-container li.post-row[data-index!="0"]').first(); - var lastReply = $('#post-container li.post-row[data-index!="0"]').last(); + var firstReply = $('#post-container .post-row[data-index!="0"]').first(); + var lastReply = $('#post-container .post-row[data-index!="0"]').last(); if (config.topicPostSort === 'oldest_to_newest') { if (firstPostTimestamp < parseInt(firstReply.attr('data-timestamp'), 10)) { @@ -106,7 +106,7 @@ define('forum/topic/posts', [ // Save document height and position for future reference (about 5 lines down) var height = $(document).height(), scrollTop = $(document).scrollTop(), - originalPostEl = $('li[data-index="0"]'); + originalPostEl = $('.post-row[data-index="0"]'); // Insert the new post html.insertBefore(before); @@ -181,7 +181,7 @@ define('forum/topic/posts', [ function loadPostsAfter(after) { var tid = ajaxify.variables.get('topic_id'); - if (!utils.isNumber(tid) || !utils.isNumber(after) || (after === 0 && $('#post-container li.post-row[data-index="1"]').length)) { + if (!utils.isNumber(tid) || !utils.isNumber(after) || (after === 0 && $('#post-container .post-row[data-index="1"]').length)) { return; } @@ -230,13 +230,13 @@ define('forum/topic/posts', [ }; function showBottomPostBar() { - if($('#post-container .post-row').length > 1 || !$('#post-container li[data-index="0"]').length) { + if($('#post-container .post-row').length > 1 || !$('#post-container [data-index="0"]').length) { $('.bottom-post-bar').removeClass('hide'); } } function hidePostToolsForDeletedPosts(element) { - element.find('li.deleted').each(function() { + element.find('.post-row.deleted').each(function() { postTools.toggle($(this).attr('data-pid'), true); }); } diff --git a/public/src/client/users.js b/public/src/client/users.js index b96f3f5501..c3f374c4ff 100644 --- a/public/src/client/users.js +++ b/public/src/client/users.js @@ -115,11 +115,6 @@ define('forum/users', function() { var username = $('#search-user').val(); var notify = $('#user-notfound-notify'); page = page || 1; - if (!username) { - notify.html(''); - notify.parent().removeClass('btn-warning label-warning btn-success label-success'); - return; - } notify.html(''); var filters = []; diff --git a/public/src/modules/helpers.js b/public/src/modules/helpers.js index bc40bde658..e8f77a5614 100644 --- a/public/src/modules/helpers.js +++ b/public/src/modules/helpers.js @@ -4,7 +4,7 @@ // export the class if we are in a Node-like system. if (typeof module === 'object' && module.exports === exports) { - exports = module.exports/* = SemVer*/; + exports = module.exports/* = SemVer*/; } var helpers = {}; @@ -21,6 +21,11 @@ return ''; }; + helpers.stringify = function(obj) { + // Turns the incoming object into a JSON string + return JSON.stringify(obj).replace(/&/gm,"&").replace(//gm,">").replace(/"/g, '"'); + }; + // Groups helpers helpers.membershipBtn = function(groupObj) { if (groupObj.isMember) { diff --git a/public/src/modules/uploader.js b/public/src/modules/uploader.js index d2f7612c0e..6efdbd988c 100644 --- a/public/src/modules/uploader.js +++ b/public/src/modules/uploader.js @@ -49,7 +49,7 @@ define('uploader', ['csrf'], function(csrf) { }, error: function(xhr) { xhr = maybeParse(xhr); - showAlert('error', xhr.responseJSON.error); + showAlert('error', xhr.responseJSON ? xhr.responseJSON.error : 'error uploading, code : ' + xhr.status); }, uploadProgress: function(event, position, total, percent) { diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js index 17944b8370..283302b48e 100644 --- a/src/controllers/admin/users.js +++ b/src/controllers/admin/users.js @@ -31,7 +31,8 @@ usersController.banned = function(req, res, next) { }; function getUsers(set, req, res, next) { - user.getUsersFromSet(set, 0, 49, function(err, users) { + var uid = req.user ? parseInt(req.user.uid, 10) : 0; + user.getUsersFromSet(set, uid, 0, 49, function(err, users) { if (err) { return next(err); } diff --git a/src/controllers/groups.js b/src/controllers/groups.js index de8af88e07..8c29f2b397 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -57,12 +57,13 @@ groupsController.details = function(req, res, next) { }; groupsController.members = function(req, res, next) { + var uid = req.user ? parseInt(req.user.uid, 10) : 0; async.waterfall([ function(next) { groups.getGroupNameByGroupSlug(req.params.slug, next); }, function(groupName, next) { - user.getUsersFromSet('group:' + groupName + ':members', 0, 49, next); + user.getUsersFromSet('group:' + groupName + ':members', uid, 0, 49, next); }, ], function(err, users) { if (err) { diff --git a/src/controllers/users.js b/src/controllers/users.js index 0a2d4d0d67..81001d0f3a 100644 --- a/src/controllers/users.js +++ b/src/controllers/users.js @@ -14,7 +14,7 @@ usersController.getOnlineUsers = function(req, res, next) { async.parallel({ users: function(next) { - user.getUsersFromSet('users:online', 0, 49, next); + user.getUsersFromSet('users:online', uid, 0, 49, next); }, count: function(next) { var now = Date.now(); @@ -63,7 +63,7 @@ usersController.getUsersSortedByJoinDate = function(req, res, next) { usersController.getUsers = function(set, count, req, res, next) { var uid = req.user ? req.user.uid : 0; - getUsersAndCount(set, count, function(err, data) { + getUsersAndCount(set, uid, count, function(err, data) { if (err) { return next(err); } @@ -78,10 +78,10 @@ usersController.getUsers = function(set, count, req, res, next) { }); }; -function getUsersAndCount(set, count, callback) { +function getUsersAndCount(set, uid, count, callback) { async.parallel({ users: function(next) { - user.getUsersFromSet(set, 0, count - 1, next); + user.getUsersFromSet(set, uid, 0, count - 1, next); }, count: function(next) { db.getObjectField('global', 'userCount', next); @@ -102,7 +102,7 @@ usersController.getUsersForSearch = function(req, res, next) { var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20, uid = req.user ? req.user.uid : 0; - getUsersAndCount('users:joindate', resultsPerPage, function(err, data) { + getUsersAndCount('users:joindate', uid, resultsPerPage, function(err, data) { if (err) { return next(err); } diff --git a/src/favourites.js b/src/favourites.js index 6de70d33f3..fec00fd9cc 100644 --- a/src/favourites.js +++ b/src/favourites.js @@ -253,7 +253,7 @@ var async = require('async'), } if (!isFavouriting && !results.hasFavourited) { - return callback(new Error('[[error:alrady-unfavourited]]')); + return callback(new Error('[[error:already-unfavourited]]')); } async.waterfall([ diff --git a/src/groups.js b/src/groups.js index 54b1332a4b..7567c662f5 100644 --- a/src/groups.js +++ b/src/groups.js @@ -803,8 +803,12 @@ var async = require('async'), groupData = groupData.filter(function(group) { return parseInt(group.hidden, 10) !== 1 && !!group.userTitle; + }).map(function(group) { + group.createtimeISO = utils.toISOString(group.createtime); + return group; }); + var groupSets = groupData.map(function(group) { group.labelColor = group.labelColor || '#000000'; group.createtimeISO = utils.toISOString(group.createtime); diff --git a/src/search.js b/src/search.js index 86f39f6b52..b8f8ffa849 100644 --- a/src/search.js +++ b/src/search.js @@ -42,7 +42,7 @@ search.search = function(data, callback) { if (searchIn === 'posts') { searchInPosts(query, data, done); } else if (searchIn === 'users') { - searchInUsers(query, done); + searchInUsers(query, data.uid, done); } else if (searchIn === 'tags') { searchInTags(query, done); } else { @@ -291,8 +291,8 @@ function getChildrenCids(cids, uid, callback) { }); } -function searchInUsers(query, callback) { - user.search({query: query}, function(err, results) { +function searchInUsers(query, uid, callback) { + user.search({query: query, uid: uid}, function(err, results) { if (err) { return callback(err); } diff --git a/src/socket.io/admin/categories.js b/src/socket.io/admin/categories.js index 2ba036d7e0..9a9ef0ea7e 100644 --- a/src/socket.io/admin/categories.js +++ b/src/socket.io/admin/categories.js @@ -36,7 +36,7 @@ Categories.search = function(socket, data, callback) { var username = data.username, cid = data.cid; - user.search({query: username}, function(err, data) { + user.search({query: username, uid: socket.uid}, function(err, data) { if (err) { return callback(err); } diff --git a/src/socket.io/admin/user.js b/src/socket.io/admin/user.js index 3a194044ea..aab9eb02e8 100644 --- a/src/socket.io/admin/user.js +++ b/src/socket.io/admin/user.js @@ -180,7 +180,7 @@ User.deleteUsers = function(socket, uids, callback) { }; User.search = function(socket, data, callback) { - user.search({query: data.query, searchBy: data.searchBy, startsWith: false}, function(err, searchData) { + user.search({query: data.query, searchBy: data.searchBy, startsWith: false, uid: socket.uid}, function(err, searchData) { if (err) { return callback(err); } diff --git a/src/socket.io/user.js b/src/socket.io/user.js index b1e1512526..28feb5616f 100644 --- a/src/socket.io/user.js +++ b/src/socket.io/user.js @@ -67,7 +67,8 @@ SocketUser.search = function(socket, data, callback) { page: data.page, searchBy: data.searchBy, sortBy: data.sortBy, - filterBy: data.filterBy + filterBy: data.filterBy, + uid: socket.uid }, callback); }; @@ -393,7 +394,7 @@ SocketUser.loadMore = function(socket, data, callback) { var start = parseInt(data.after, 10), end = start + 19; - user.getUsersFromSet(data.set, start, end, function(err, userData) { + user.getUsersFromSet(data.set, socket.uid, start, end, function(err, userData) { if (err) { return callback(err); } diff --git a/src/topics.js b/src/topics.js index a0aeed33db..8ad164df1f 100644 --- a/src/topics.js +++ b/src/topics.js @@ -241,7 +241,9 @@ var async = require('async'), topicData.locked = parseInt(topicData.locked, 10) === 1; topicData.pinned = parseInt(topicData.pinned, 10) === 1; - plugins.fireHook('filter:topic.get', topicData, callback); + plugins.fireHook('filter:topic.get', {topic: topicData, uid: uid}, function(err, data) { + callback(err, data ? data.topic : null); + }); }); }); }; diff --git a/src/user.js b/src/user.js index b320c3f594..bd781432a0 100644 --- a/src/user.js +++ b/src/user.js @@ -221,18 +221,18 @@ var async = require('async'), } }; - User.getUsersFromSet = function(set, start, stop, callback) { + User.getUsersFromSet = function(set, uid, start, stop, callback) { async.waterfall([ function(next) { User.getUidsFromSet(set, start, stop, next); }, function(uids, next) { - User.getUsers(uids, next); + User.getUsers(uids, uid, next); } ], callback); }; - User.getUsers = function(uids, callback) { + User.getUsers = function(uids, uid, callback) { var fields = ['uid', 'username', 'userslug', 'picture', 'status', 'banned', 'postcount', 'reputation', 'email:confirmed']; plugins.fireHook('filter:users.addFields', {fields: fields}, function(err, data) { if (err) { @@ -266,11 +266,10 @@ var async = require('async'), user['email:confirmed'] = parseInt(user['email:confirmed'], 10) === 1; }); - plugins.fireHook('filter:userlist.get', {users: results.userData}, function(err, data) { + plugins.fireHook('filter:userlist.get', {users: results.userData, uid: uid}, function(err, data) { if (err) { return callback(err); } - callback(null, data.users); }); }); diff --git a/src/user/follow.js b/src/user/follow.js index c3e2cb340c..6b0c0a3973 100644 --- a/src/user/follow.js +++ b/src/user/follow.js @@ -59,7 +59,7 @@ module.exports = function(User) { return callback(err); } - User.getUsers(uids, callback); + User.getUsers(uids, uid, callback); }); } diff --git a/src/user/search.js b/src/user/search.js index ebfb08551f..a593258f11 100644 --- a/src/user/search.js +++ b/src/user/search.js @@ -14,13 +14,10 @@ module.exports = function(User) { var searchBy = data.searchBy || ['username']; var startsWith = data.hasOwnProperty('startsWith') ? data.startsWith : true; var page = data.page || 1; - - if (!query) { - return callback(null, {timing: 0, users: [], matchCount: 0, pages: []}); - } + var uid = data.uid || 0; if (searchBy.indexOf('ip') !== -1) { - return searchByIP(query, callback); + return searchByIP(query, uid, callback); } var startTime = process.hrtime(); @@ -46,7 +43,7 @@ module.exports = function(User) { matchCount = uids.length; uids = uids.slice(start, end); - User.getUsers(uids, next); + User.getUsers(uids, uid, next); }, function(userData, next) { @@ -194,14 +191,14 @@ module.exports = function(User) { } } - function searchByIP(ip, callback) { + function searchByIP(ip, uid, callback) { var start = process.hrtime(); async.waterfall([ function(next) { db.getSortedSetRevRange('ip:' + ip + ':uid', 0, -1, next); }, function(uids, next) { - User.getUsers(uids, next); + User.getUsers(uids, uid, next); }, function(users, next) { var diff = process.hrtime(start);