Skip to content

Node.js based forum software built for the modern web

closes #1412

barisusakli2ad715ead314
diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.json
index 7c8f002956..c8b647236c 100644
--- a/public/language/en_GB/global.json
+++ b/public/language/en_GB/global.json
@@ -79,5 +79,7 @@
"offline": "Offline",
"email": "Email",
- "language": "Language"
+ "language": "Language",
+
+ "guest": "Guest"
}
diff --git a/public/language/en_GB/topic.json b/public/language/en_GB/topic.json
index a53e56c9ef..d40c8ccb7b 100644
--- a/public/language/en_GB/topic.json
+++ b/public/language/en_GB/topic.json
@@ -102,5 +102,9 @@
"composer.thumb_file_label": "Or upload a file",
"composer.thumb_remove": "Clear fields",
"composer.drag_and_drop_images": "Drag and Drop Images Here",
- "composer.upload_instructions": "Upload images by dragging & dropping them."
+ "composer.upload_instructions": "Upload images by dragging & dropping them.",
+
+ "more_users_and_guests": "%1 more user(s) and %2 guest(s)",
+ "more_users": "%1 more user(s)",
+ "more_guests": "%1 more guest(s)"
}
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index 96f8db8134..3162f87f61 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -209,32 +209,38 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools',
var title = '';
if(remainingUsers && anonymousCount) {
- title = remainingUsers + ' more user(s) and ' + anonymousCount + ' guest(s)';
+ title = '[[topic:more_users_and_guests, ' + remainingUsers + ', ' + anonymousCount + ']]';
} else if(remainingUsers) {
- title = remainingUsers + ' more user(s)';
+ title = '[[topic:more_users, ' + remainingUsers + ']]';
} else {
- title = anonymousCount + ' guest(s)';
+ title = '[[topic:more_guests, ' + anonymousCount + ']]';
}
- anonLink.tooltip({
- placement: 'top',
- title: title
+ translator.translate(title, function(translated) {
+ $('.anonymous-box').tooltip({
+ placement: 'top',
+ title: translated
+ });
});
}
- // Get users who are currently replying to the topic entered
- socket.emit('modules.composer.getUsersByTid', ajaxify.variables.get('topic_id'), function(err, uids) {
- if (uids && uids.length) {
- for(var x=0;x<uids.length;x++) {
- activeEl.find('[data-uid="' + uids[x] + '"]').addClass('replying');
- }
- }
- });
+ getReplyingUsers();
}
app.populateOnlineUsers();
});
+ function getReplyingUsers() {
+ var activeEl = $('.thread_active_users');
+ socket.emit('modules.composer.getUsersByTid', ajaxify.variables.get('topic_id'), function(err, uids) {
+ if (uids && uids.length) {
+ for(var x=0;x<uids.length;x++) {
+ activeEl.find('[data-uid="' + uids[x] + '"]').addClass('replying');
+ }
+ }
+ });
+ }
+
socket.on('user.isOnline', function(err, data) {
app.populateOnlineUsers();
});
diff --git a/src/posts.js b/src/posts.js
index d35cd12e5d..ef2dffaf74 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -232,7 +232,7 @@ var db = require('./database'),
}
post.user = {
- username: userData.username || 'anonymous',
+ username: userData.username || 'Guest',
userslug: userData.userslug || '',
reputation: userData.reputation || 0,
postcount: userData.postcount || 0,
@@ -282,17 +282,11 @@ var db = require('./database'),
post.relativeTime = utils.toISOString(post.timestamp);
- async.parallel([
- function(next) {
- user.getUserFields(post.uid, ['username', 'userslug', 'picture'], function(err, userData) {
- if (err) {
- return next(err);
- }
- post.user = userData;
- next();
- });
+ async.parallel({
+ user: function(next) {
+ user.getNameSlugPicture(post.uid, next);
},
- function(next) {
+ topicCategory: function(next) {
topics.getTopicFields(post.tid, ['title', 'cid', 'slug', 'deleted'], function(err, topicData) {
if (err) {
return next(err);
@@ -305,35 +299,36 @@ var db = require('./database'),
return next(err);
}
- post.category = categoryData;
topicData.title = validator.escape(topicData.title);
- post.topic = topicData;
- next();
+
+ next(null, {topic: topicData, category: categoryData});
});
});
},
- function(next) {
+ content: function(next) {
if (!post.content) {
- return next();
+ return next(null, post.content);
}
- postTools.parse(post.content, function(err, content) {
- if(err) {
- return next(err);
- }
+ postTools.parse(post.content, next);
+ }
+ }, function(err, results) {
+ if (err) {
+ return callback(err);
+ }
- if(stripTags) {
- var s = S(content);
- post.content = s.stripTags.apply(s, utils.getTagsExcept(['img', 'i', 'p'])).s;
- } else {
- post.content = content;
- }
+ post.user = results.user;
+ post.topic = results.topicCategory.topic;
+ post.category = results.topicCategory.category;
- next();
- });
+ if (stripTags) {
+ var s = S(results.content);
+ post.content = s.stripTags.apply(s, utils.getTagsExcept(['img', 'i', 'p'])).s;
+ } else {
+ post.content = results.content;
}
- ], function(err) {
- callback(err, post);
+
+ callback(null, post);
});
}
diff --git a/src/socket.io/index.js b/src/socket.io/index.js
index c3a1484759..a6ce68e6a1 100644
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@ -102,7 +102,7 @@ Sockets.init = function(server) {
socket.broadcast.emit('user.anonConnect');
socket.emit('event:connect', {
status: 1,
- username: 'Anonymous',
+ username: '[[global:guest]]',
isAdmin: false,
uid: 0
});
diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js
index a34fda885a..8c40d0ef52 100644
--- a/src/socket.io/meta.js
+++ b/src/socket.io/meta.js
@@ -65,7 +65,7 @@ SocketMeta.updateHeader = function(socket, data, callback) {
} else {
callback(null, {
uid: 0,
- username: "Anonymous User",
+ username: '[[global:guest]]',
email: '',
picture: gravatar.url('', {
s: '24'
diff --git a/src/topics.js b/src/topics.js
index 3326cfaef9..7ff3d6e68f 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -61,22 +61,9 @@ var async = require('async'),
return callback(err || new Error('[[error:no-topic]]'));
}
- user.getUserFields(topic.uid, ['username', 'userslug', 'picture'] , function(err, userData) {
- if (err) {
- return callback(err);
- }
-
- if (!userData) {
- userData = {};
- }
-
- topic.user = {
- username: userData.username || 'Anonymous',
- userslug: userData.userslug || '',
- picture: userData.picture || gravatar.url('', {}, true)
- };
-
- callback(null, topic);
+ user.getNameSlugPicture(topic.uid, function(err, userData) {
+ topic.user = userData;
+ callback(err, topic);
});
});
};
@@ -219,7 +206,8 @@ var async = require('async'),
if (userCache[topicData.uid]) {
return next(null, userCache[topicData.uid]);
}
- user.getUserFields(topicData.uid, ['username', 'userslug', 'picture'], next);
+
+ user.getNameSlugPicture(topicData.uid, next);
}
}, function(err, topicInfo) {
if(err) {
@@ -332,18 +320,13 @@ var async = require('async'),
return callback(new Error('[[error:no-teaser]]'));
}
- user.getUserFields(postData.uid, ['username', 'userslug', 'picture'], function(err, userData) {
+ user.getNameSlugPicture(postData.uid, function(err, userData) {
if (err) {
return callback(err);
}
-
- callback(null, {
- pid: postData.pid,
- username: userData.username || 'anonymous',
- userslug: userData.userslug || '',
- picture: userData.picture || gravatar.url('', {}, true),
- timestamp: utils.toISOString(postData.timestamp)
- });
+ postData.timestamp = utils.toISOString(postData.timestamp);
+ postData.user = userData;
+ callback(null, postData);
});
});
});
diff --git a/src/user.js b/src/user.js
index 414b05b803..202b511df8 100644
--- a/src/user.js
+++ b/src/user.js
@@ -285,6 +285,20 @@ var bcrypt = require('bcryptjs'),
});
};
+ User.getNameSlugPicture = function(uid, callback) {
+ User.getUserFields(uid, ['username', 'userslug', 'picture'], function(err, data) {
+ if (err) {
+ return callback(err);
+ }
+
+ callback(null, {
+ username: data.username || '[[global:guest]]',
+ userslug: data.userslug || '',
+ picture: data.picture || gravatar.url('', {}, true)
+ });
+ });
+ };
+
User.getUidByUsername = function(username, callback) {
db.getObjectField('username:uid', username, callback);
};