diff --git a/src/categories.js b/src/categories.js
index 9833720896..95baee275e 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -335,8 +335,6 @@ var RDB = require('./redis.js'),
return;
}
- // var categories = [];
-
function getCategory(cid, callback) {
Categories.getCategoryData(cid, function(err, categoryData) {
if (err) {
@@ -348,7 +346,6 @@ var RDB = require('./redis.js'),
Categories.hasReadCategory(cid, current_user, function(hasRead) {
categoryData.badgeclass = (parseInt(categoryData.topic_count, 10) === 0 || (hasRead && current_user !== 0)) ? '' : 'badge-important';
- // categories.push(categoryData);
callback(null, categoryData);
});
});
@@ -362,11 +359,8 @@ var RDB = require('./redis.js'),
}
categories = categories.filter(function(category) {
- // Remove categories that have errored out
- if (category) return true;
- else return false;
+ return !!category;
}).sort(function(a, b) {
- // Sort categories into their defined order
return parseInt(a.order, 10) - parseInt(b.order, 10);
});
diff --git a/src/favourites.js b/src/favourites.js
index d104654469..6e6bd40990 100644
--- a/src/favourites.js
+++ b/src/favourites.js
@@ -8,17 +8,15 @@ var RDB = require('./redis.js'),
Favourites.favourite = function (pid, room_id, uid, socket) {
if (uid === 0) {
- var not_logged_in = {
- message: translator.get('topic:favourites.not_logged_in.message'),
- title: translator.get('topic:favourites.not_logged_in.title')
- };
-
- socket.emit('event:alert', {
- alert_id: 'post_favourite',
- title: not_logged_in.title,
- message: not_logged_in.message,
- type: 'danger',
- timeout: 5000
+
+ translator.mget(['topic:favourites.not_logged_in.message', 'topic:favourites.not_logged_in.title'], function(err, results) {
+ socket.emit('event:alert', {
+ alert_id: 'post_favourite',
+ title: results[1],
+ message: results[0],
+ type: 'danger',
+ timeout: 5000
+ });
});
return;
}
diff --git a/src/posts.js b/src/posts.js
index 5199be6f2d..ae6c5f53e5 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -205,10 +205,16 @@ var RDB = require('./redis.js'),
multi.exec(function (err, replies) {
async.map(replies, function(postData, _callback) {
if (postData) {
- postData.relativeTime = new Date(parseInt(postData.timestamp,10)).toISOString();
+
postData.post_rep = postData.reputation;
postData['edited-class'] = postData.editor !== '' ? '' : 'none';
- postData['relativeEditTime'] = postData.edited !== '0' ? (new Date(parseInt(postData.edited,10)).toISOString()) : '';
+ try {
+ postData.relativeTime = new Date(parseInt(postData.timestamp,10)).toISOString();
+ postData['relativeEditTime'] = postData.edited !== '0' ? (new Date(parseInt(postData.edited,10)).toISOString()) : '';
+ } catch(e) {
+ winston.err('invalid time value');
+ }
+
if (postData.uploadedImages) {
try {
@@ -359,13 +365,18 @@ var RDB = require('./redis.js'),
RDB.incr('totalpostcount');
- topics.getTopicField(tid, 'cid', function(err, cid) {
+ topics.getTopicFields(tid, ['cid', 'pinned'], function(err, topicData) {
+
RDB.handle(err);
+ var cid = topicData.cid;
+
feed.updateTopic(tid);
RDB.zadd('categories:recent_posts:cid:' + cid, timestamp, pid);
- RDB.zadd('categories:' + cid + ':tid', timestamp, tid);
+
+ if(topicData.pinned === '0')
+ RDB.zadd('categories:' + cid + ':tid', timestamp, tid);
RDB.scard('cid:' + cid + ':active_users', function(err, amount) {
if (amount > 10) {
diff --git a/src/routes/admin.js b/src/routes/admin.js
index 28d0044849..afdb47adbc 100644
--- a/src/routes/admin.js
+++ b/src/routes/admin.js
@@ -8,7 +8,8 @@ var user = require('./../user.js'),
plugins = require('../plugins'),
winston = require('winston'),
nconf = require('nconf'),
- fs = require('fs');
+ fs = require('fs'),
+ path = require('path');
(function (Admin) {
Admin.isAdmin = function (req, res, next) {
@@ -78,6 +79,54 @@ var user = require('./../user.js'),
res.send(header + app.create_route('admin/index') + templates['admin/footer']);
});
});
+
+ app.post('/uploadlogo', Admin.isAdmin, function(req, res) {
+
+ if (!req.user)
+ return res.redirect('/403');
+
+ 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;
+ }
+
+ var tempPath = req.files.userPhoto.path;
+ var extension = path.extname(req.files.userPhoto.name);
+
+ if (!extension) {
+ res.send({
+ error: 'Error uploading file! Error : Invalid extension!'
+ });
+ return;
+ }
+
+ var filename = 'site-logo' + extension;
+ var uploadPath = path.join(process.cwd(), nconf.get('upload_path'), filename);
+
+ winston.info('Attempting upload to: ' + uploadPath);
+
+ var is = fs.createReadStream(tempPath);
+ var os = fs.createWriteStream(uploadPath);
+
+ is.on('end', function () {
+ fs.unlinkSync(tempPath);
+
+ res.json({
+ path: nconf.get('upload_url') + filename
+ });
+ });
+
+ os.on('error', function (err) {
+ fs.unlinkSync(tempPath);
+ winston.err(err);
+ });
+
+ is.pipe(os);
+ });
});
@@ -89,7 +138,7 @@ var user = require('./../user.js'),
plugins.ready(function() {
plugins.fireHook('filter:admin.create_routes', custom_routes, function(err, custom_routes) {
var routes = custom_routes.routes;
-
+
for (var route in routes) {
if (routes.hasOwnProperty(route)) {
app[routes[route].method || 'get']('/admin' + routes[route].route, function(req, res) {
@@ -98,10 +147,10 @@ var user = require('./../user.js'),
res.send(header + options.content + templates['admin/footer']);
});
});
- });
+ });
}
}
- });
+ });
});
app.namespace('/api/admin', function () {
diff --git a/src/routes/user.js b/src/routes/user.js
index d31f2b1ba7..62b8560b97 100644
--- a/src/routes/user.js
+++ b/src/routes/user.js
@@ -425,7 +425,7 @@ var user = require('./../user.js'),
posts.getPostsByUid(userData.theirid, 0, 9, function (posts) {
userData.posts = posts.filter(function (p) {
- return p.deleted !== "1";
+ return p && p.deleted !== "1";
});
userData.isFollowing = isFollowing;
if (!userData.profileviews)
diff --git a/src/topics.js b/src/topics.js
index ec86fde245..ceb8f7e3ae 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -353,6 +353,7 @@ var RDB = require('./redis.js'),
return callback(new Error('Topic tid \'' + tid + '\' not found'));
Topics.markAsRead(tid, current_user);
+ Topics.increaseViewCount(tid);
function getTopicData(next) {
Topics.getTopicData(tid, function(topicData) {
@@ -399,6 +400,7 @@ var RDB = require('./redis.js'),
'pinned': topicData.pinned,
'slug': topicData.slug,
'postcount': topicData.postcount,
+ 'viewcount': topicData.viewcount,
'topic_id': tid,
'expose_tools': privileges.editable ? 1 : 0,
'posts': topicPosts,
@@ -681,6 +683,7 @@ var RDB = require('./redis.js'),
'timestamp': timestamp,
'lastposttime': 0,
'postcount': 0,
+ 'viewcount': 0,
'locked': 0,
'deleted': 0,
'pinned': 0
@@ -741,6 +744,10 @@ var RDB = require('./redis.js'),
RDB.hincrby('topic:' + tid, 'postcount', 1);
}
+ Topics.increaseViewCount = function(tid) {
+ RDB.hincrby('topic:' + tid, 'viewcount', 1);
+ }
+
Topics.isLocked = function(tid, callback) {
Topics.getTopicField(tid, 'locked', function(err, locked) {
callback(locked);
diff --git a/src/websockets.js b/src/websockets.js
index 0bce3e76b4..36df253f1a 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -157,8 +157,7 @@ module.exports.init = function(io) {
for (var i = 0; i < clients.length; ++i) {
var hs = clients[i].handshake;
-
- if (hs && !users[sessionID]) {
+ if (hs && clients[i].state.user.uid === 0) {
++anonCount;
}
}
@@ -169,27 +168,12 @@ module.exports.init = function(io) {
var anonymousCount = getAnonymousCount(roomName);
- function userList(users, anonymousCount, userCount) {
- var usernames = [];
-
- for (var i = 0, ii = users.length; i < ii; ++i) {
- usernames[i] = '
' + '' + users[i].username + '';
- }
-
- var joiner = anonymousCount + userCount == 1 ? 'is' : 'are',
- userList = anonymousCount > 0 ? usernames.concat(util.format('%d guest%s', anonymousCount, anonymousCount > 1 ? 's' : '')) : usernames,
- lastUser = userList.length > 1 ? ' and ' + userList.pop() : '';
-
- return util.format('%s%s %s browsing this thread', userList.join(', '), lastUser, joiner);
- }
-
-
if (uids.length === 0) {
- io.sockets. in (roomName).emit('api:get_users_in_room', userList([], anonymousCount, 0));
+ io.sockets. in (roomName).emit('api:get_users_in_room', { users: [], anonymousCount:0 });
} else {
- user.getMultipleUserFields(uids, ['username', 'userslug'], function(err, users) {
- if (!err)
- io.sockets. in (roomName).emit('api:get_users_in_room', userList(users, anonymousCount, users.length));
+ user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture'], function(err, users) {
+ if(!err)
+ io.sockets. in (roomName).emit('api:get_users_in_room', { users: users, anonymousCount:anonymousCount });
});
}
}
diff --git a/tests/utils.js b/tests/utils.js
new file mode 100644
index 0000000000..70643802f8
--- /dev/null
+++ b/tests/utils.js
@@ -0,0 +1,12 @@
+var assert = require('assert'),
+ utils = require('./../public/src/utils.js');
+
+
+describe("Utility Methods", function(){
+ describe("username validation", function(){
+ it("accepts latin-1 characters", function(){
+ var username = "John\"'-. Doeäâèéë1234";
+ assert(utils.isUserNameValid(username), 'invalid username');
+ });
+ });
+});