diff --git a/public/src/forum/category.js b/public/src/forum/category.js
index d6838510b7..6837399cea 100644
--- a/public/src/forum/category.js
+++ b/public/src/forum/category.js
@@ -1,8 +1,9 @@
define(function () {
- var Category = {},
- cid = templates.get('category_id');
+ var Category = {};
+
Category.init = function() {
- var room = 'category_' + cid,
+ var cid = templates.get('category_id'),
+ room = 'category_' + cid,
twitterEl = document.getElementById('twitter-intent'),
facebookEl = document.getElementById('facebook-share'),
googleEl = document.getElementById('google-share'),
@@ -85,7 +86,7 @@ define(function () {
}),
topic = $(html),
container = $('#topics-container'),
- topics = $('#topics-container').children(),
+ topics = $('#topics-container').children('.category-item'),
numTopics = topics.length;
jQuery('#topics-container, .category-sidebar').removeClass('hidden');
@@ -104,7 +105,7 @@ define(function () {
topic.hide().fadeIn('slow');
}
- socket.emit('api:categories.getRecentReplies', cid);
+ socket.emit('api:categories.getRecentReplies', templates.get('category_id'));
$('#topics-container span.timeago').timeago();
}
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index a9b70c7966..d464c7e985 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -11,18 +11,38 @@ define(function() {
deleted: templates.get('deleted'),
pinned: templates.get('pinned')
},
- topic_name = templates.get('topic_name');
+ topic_name = templates.get('topic_name'),
+ twitter_url = templates.get('twitter-intent-url'),
+ facebook_url = templates.get('facebook-share-url'),
+ google_url = templates.get('google-share-url');
jQuery('document').ready(function() {
app.addCommasToNumbers();
+
var room = 'topic_' + tid,
adminTools = document.getElementById('thread-tools');
app.enter_room(room);
+
+ $('.twitter-share').on('click', function () {
+ window.open(twitter_url, '_blank', 'width=550,height=420,scrollbars=no,status=no');
+ return false;
+ });
+
+ $('.facebook-share').on('click', function () {
+ window.open(facebook_url, '_blank', 'width=626,height=436,scrollbars=no,status=no');
+ return false;
+ });
+
+ $('.google-share').on('click', function () {
+ window.open(google_url, '_blank', 'width=500,height=570,scrollbars=no,status=no');
+ return false;
+ });
+
// Resetting thread state
if (thread_state.locked === '1') set_locked_state(true);
if (thread_state.deleted === '1') set_delete_state(true);
diff --git a/public/src/forum/unread.js b/public/src/forum/unread.js
index 13a940a91f..009e898d17 100644
--- a/public/src/forum/unread.js
+++ b/public/src/forum/unread.js
@@ -45,6 +45,7 @@ define(function() {
text += ' Click here to reload.';
$('#new-topics-alert').html(text).removeClass('hide').fadeIn('slow');
+ $('#category-no-topics').addClass('hidden');
}
socket.on('event:new_post', function(data) {
@@ -80,12 +81,13 @@ define(function() {
$('#category-no-topics').remove();
container.append(html);
+ $('span.timeago').timeago();
}
function loadMoreTopics() {
loadingMoreTopics = true;
socket.emit('api:topics.loadMoreUnreadTopics', {
- after: parseInt($('#topics-container').attr('data-next-start'), 10)
+ after: parseInt($('#topics-container').attr('data-next-start'), 10);
}, function(data) {
if (data.topics && data.topics.length) {
onTopicsLoaded(data.topics);
diff --git a/public/templates/topic.tpl b/public/templates/topic.tpl
index e09d94f9d0..d5c3309234 100644
--- a/public/templates/topic.tpl
+++ b/public/templates/topic.tpl
@@ -6,6 +6,9 @@
+
+
+
@@ -60,12 +63,18 @@
+
-
+
+
+
+
+
+
diff --git a/src/logger.js b/src/logger.js
index ab84f3dad6..eac28782d7 100644
--- a/src/logger.js
+++ b/src/logger.js
@@ -71,8 +71,9 @@ var opts = {
Logger.open = function(value) {
/* Open the streams to log to: either a path or stdout */
var stream;
- if(value)
+ if(value && fs.existsSync(value)) {
stream = fs.createWriteStream(value, {flags: 'a'});
+ }
else
stream = process.stdout;
return stream;
@@ -113,7 +114,7 @@ var opts = {
return opts.express.ofn(req,res,next);
}
else {
- return next()
+ return next();
}
}
diff --git a/src/login.js b/src/login.js
index 131ad3b94a..2a84fbca14 100644
--- a/src/login.js
+++ b/src/login.js
@@ -2,7 +2,8 @@ var user = require('./user.js'),
bcrypt = require('bcrypt'),
RDB = require('./redis.js'),
path = require('path'),
- winston = require('winston');
+ winston = require('winston'),
+ utils = require('./../public/src/utils.js');
(function(Login) {
@@ -13,12 +14,14 @@ var user = require('./user.js'),
message: 'invalid-user'
});
} else {
- user.get_uid_by_username(username, function(err, uid) {
+
+ var userslug = utils.slugify(username);
+
+ user.get_uid_by_userslug(userslug, function(err, uid) {
+
if (err) {
return next(new Error('redis-error'));
- }
-
- if (uid == null) {
+ } else if (uid == null) {
return next(new Error('invalid-user'));
}
diff --git a/src/plugins.js b/src/plugins.js
index c887c13185..51e45716b7 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -232,32 +232,13 @@ var fs = require('fs'),
});
},
showInstalled: function(callback) {
- // TODO: Also check /node_modules
var _self = this;
- localPluginPath = path.join(__dirname, '../plugins'),
npmPluginPath = path.join(__dirname, '../node_modules');
async.waterfall([
function(next) {
- async.parallel([
- function(next) {
- fs.readdir(localPluginPath, next);
- },
- function(next) {
- fs.readdir(npmPluginPath, next);
- }
- ], function(err, dirs) {
- if (err) return next(err);
-
- dirs[0] = dirs[0].map(function(file) {
- return path.join(localPluginPath, file);
- }).filter(function(file) {
- var stats = fs.statSync(file);
- if (stats.isDirectory()) return true;
- else return false;
- });
-
- dirs[1] = dirs[1].map(function(file) {
+ fs.readdir(npmPluginPath, function(err, dirs) {
+ dirs = dirs.map(function(file) {
return path.join(npmPluginPath, file);
}).filter(function(file) {
var stats = fs.statSync(file);
@@ -265,7 +246,7 @@ var fs = require('fs'),
else return false;
});
- next(err, dirs[0].concat(dirs[1]));
+ next(err, dirs);
});
},
function(files, next) {
diff --git a/src/postTools.js b/src/postTools.js
index bdf69943d6..4876d9c5b0 100644
--- a/src/postTools.js
+++ b/src/postTools.js
@@ -38,7 +38,7 @@ var RDB = require('./redis.js'),
function isOwnPost(next) {
posts.getPostField(pid, 'uid', function(author) {
if (author && parseInt(author) > 0) {
- next(null, author === uid);
+ next(null, parseInt(author, 10) === parseInt(uid, 10));
}
});
}
@@ -46,14 +46,14 @@ var RDB = require('./redis.js'),
function hasEnoughRep(next) {
user.getUserField(uid, 'reputation', function(err, reputation) {
if (err) return next(null, false);
- next(null, reputation >= meta.config['privileges:manage_content']);
+ next(null, parseInt(reputation, 10) >= parseInt(meta.config['privileges:manage_content'], 10));
});
}
async.parallel([getThreadPrivileges, isOwnPost, hasEnoughRep], function(err, results) {
callback({
- editable: results[0].editable || (results.slice(1).indexOf(true) !== -1 ? true : false),
- view_deleted: results[0].view_deleted || (results.slice(1).indexOf(true) !== -1 ? true : false)
+ editable: results[0].editable || results[1] || results[2],
+ view_deleted: results[0].view_deleted || results[1] || results[2]
});
});
}
diff --git a/src/threadTools.js b/src/threadTools.js
index e375876ef0..e757bd41e6 100644
--- a/src/threadTools.js
+++ b/src/threadTools.js
@@ -34,15 +34,15 @@ var RDB = require('./redis.js'),
function hasEnoughRep(next) {
user.getUserField(uid, 'reputation', function(err, reputation) {
if (err) return next(null, false);
- next(null, reputation >= meta.config['privileges:manage_topic']);
+ next(null, parseInt(reputation, 10) >= parseInt(meta.config['privileges:manage_topic'], 10));
});
}
async.parallel([getCategoryPrivileges, hasEnoughRep], function(err, results) {
callback({
- editable: results[0].editable || (results.slice(1).indexOf(true) !== -1 ? true : false),
- view_deleted: results[0].view_deleted || (results.slice(1).indexOf(true) !== -1 ? true : false)
+ editable: results[0].editable || results[1],
+ view_deleted: results[0].view_deleted || results[1]
});
});
}
diff --git a/src/topics.js b/src/topics.js
index ceb8f7e3ae..b40b67eb7c 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -14,6 +14,7 @@ var RDB = require('./redis.js'),
meta = require('./meta.js'),
reds = require('reds'),
topicSearch = reds.createSearch('nodebbtopicsearch'),
+ nconf = require('nconf'),
validator = require('validator');
(function(Topics) {
@@ -68,7 +69,7 @@ var RDB = require('./redis.js'),
}
function getPrivileges(next) {
- threadTools.privileges(tid, current_user, function(privData) {
+ postTools.privileges(tid, current_user, function(privData) {
next(null, privData);
});
}
@@ -213,10 +214,12 @@ var RDB = require('./redis.js'),
var unreadTids = [],
done = false;
+ function continueCondition() {
+ return unreadTids.length < 20 && !done;
+ }
+
async.whilst(
- function() {
- return unreadTids.length < 20 && !done;
- },
+ continueCondition,
function(callback) {
RDB.zrevrange('topics:recent', start, stop, function(err, tids) {
if (err)
@@ -234,12 +237,16 @@ var RDB = require('./redis.js'),
Topics.hasReadTopics(tids, uid, function(read) {
var newtids = tids.filter(function(tid, index, self) {
- return read[index] === 0;
+ return parseInt(read[index], 10) === 0;
});
unreadTids.push.apply(unreadTids, newtids);
- start = stop + 1;
- stop = start + 19;
+
+ if(continueCondition()) {
+ start = stop + 1;
+ stop = start + 19;
+ }
+
callback(null);
});
}
@@ -404,7 +411,10 @@ var RDB = require('./redis.js'),
'topic_id': tid,
'expose_tools': privileges.editable ? 1 : 0,
'posts': topicPosts,
- 'main_posts': main_posts
+ 'main_posts': main_posts,
+ 'twitter-intent-url': 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(nconf.get('url') + 'topic/' + topicData.slug) + '&text=' + encodeURIComponent(topicData.title),
+ 'facebook-share-url': 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(nconf.get('url') + 'topic/' + topicData.slug),
+ 'google-share-url': 'https://plus.google.com/share?url=' + encodeURIComponent(nconf.get('url') + 'topic/' + topicData.slug)
});
});
});