From 63419d7ca9d248350faae31e0386a508c8c360f3 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Fri, 25 Oct 2013 15:35:48 -0400 Subject: [PATCH 01/14] fix for reputation checks for manage content and manage threads --- src/postTools.js | 6 +++--- src/threadTools.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/postTools.js b/src/postTools.js index bdf69943d6..d75c2da1dc 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -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], + view_deleted: results[0].view_deleted || results[1] }); }); } 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] }); }); } From f3f280d00879e7dd4b6bd4f010c146b5eb13bbe8 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Fri, 25 Oct 2013 16:02:18 -0400 Subject: [PATCH 02/14] another fix to priv --- src/postTools.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/postTools.js b/src/postTools.js index d75c2da1dc..b84b5a2b9f 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -52,8 +52,8 @@ var RDB = require('./redis.js'), async.parallel([getThreadPrivileges, isOwnPost, hasEnoughRep], function(err, results) { callback({ - editable: results[0].editable || results[1], - view_deleted: results[0].view_deleted || results[1] + editable: results[0].editable || results[1] || results[2], + view_deleted: results[0].view_deleted || results[1] || results[2] }); }); } From 6eadf67add543a3502f16cb04ee3fc1365c07d94 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 25 Oct 2013 16:56:18 -0400 Subject: [PATCH 03/14] another privilege fix --- src/postTools.js | 2 +- src/topics.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/postTools.js b/src/postTools.js index b84b5a2b9f..c92b98bcd1 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -52,7 +52,7 @@ var RDB = require('./redis.js'), async.parallel([getThreadPrivileges, isOwnPost, hasEnoughRep], function(err, results) { callback({ - editable: results[0].editable || results[1] || results[2], + editable: results[1] || results[2], view_deleted: results[0].view_deleted || results[1] || results[2] }); }); diff --git a/src/topics.js b/src/topics.js index ceb8f7e3ae..6095a70ca1 100644 --- a/src/topics.js +++ b/src/topics.js @@ -68,7 +68,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); }); } From 1af98835b16e6c08ce30e92008874ebf1682fa0f Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 25 Oct 2013 18:00:08 -0400 Subject: [PATCH 04/14] added share buttons to main post --- public/src/forum/topic.js | 22 +++++++++++++++++++++- public/templates/topic.tpl | 15 ++++++++++++--- src/topics.js | 6 +++++- 3 files changed, 38 insertions(+), 5 deletions(-) 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/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 @@ + + +
+ + +
+ + +
- - - + + +
diff --git a/src/topics.js b/src/topics.js index 6095a70ca1..f436776335 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) { @@ -404,7 +405,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) }); }); }); From 865e5ae3a392dbe7b3e1955620188151cf327255 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 25 Oct 2013 18:08:23 -0400 Subject: [PATCH 05/14] closes #448 --- src/login.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/login.js b/src/login.js index 131ad3b94a..6387101248 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,7 +14,11 @@ 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) { + console.log(err, uid); if (err) { return next(new Error('redis-error')); } From fba1f7ae051639d98916b1aac6f26d8005f3e0bb Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Fri, 25 Oct 2013 18:09:07 -0400 Subject: [PATCH 06/14] removed console.log --- src/login.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/login.js b/src/login.js index 6387101248..2a84fbca14 100644 --- a/src/login.js +++ b/src/login.js @@ -18,12 +18,10 @@ var user = require('./user.js'), var userslug = utils.slugify(username); user.get_uid_by_userslug(userslug, function(err, uid) { - console.log(err, uid); + if (err) { return next(new Error('redis-error')); - } - - if (uid == null) { + } else if (uid == null) { return next(new Error('invalid-user')); } From 97c5f6009ddfcdbaf0ad2438b814836b7fb6337e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 26 Oct 2013 18:26:30 -0400 Subject: [PATCH 07/14] closes #455 --- src/plugins.js | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) 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) { From 99812c33e7725cfa289886b91a530d9f3c72a695 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sat, 26 Oct 2013 19:00:34 -0400 Subject: [PATCH 08/14] closes #454 --- src/postTools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/postTools.js b/src/postTools.js index c92b98bcd1..b84b5a2b9f 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -52,7 +52,7 @@ var RDB = require('./redis.js'), async.parallel([getThreadPrivileges, isOwnPost, hasEnoughRep], function(err, results) { callback({ - editable: results[1] || results[2], + editable: results[0].editable || results[1] || results[2], view_deleted: results[0].view_deleted || results[1] || results[2] }); }); From 52f198481ba81912e7775c1bde7d1b2f9fffbf08 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sat, 26 Oct 2013 20:19:42 -0400 Subject: [PATCH 09/14] closes #456, if the file path doesnt exists logger was crashing --- src/logger.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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(); } } From 82e14eef3588bbaaa45d09b6814e118777449d51 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Sun, 27 Oct 2013 23:29:53 -0400 Subject: [PATCH 10/14] closes #458 --- src/postTools.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/postTools.js b/src/postTools.js index b84b5a2b9f..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)); } }); } From afc0e25b26359a9eb5ff3e7b3770c1e0abd88681 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 28 Oct 2013 00:08:44 -0400 Subject: [PATCH 11/14] closes #463 --- public/src/forum/unread.js | 3 ++- src/topics.js | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/public/src/forum/unread.js b/public/src/forum/unread.js index 13a940a91f..4ab4d3280a 100644 --- a/public/src/forum/unread.js +++ b/public/src/forum/unread.js @@ -80,12 +80,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/src/topics.js b/src/topics.js index f436776335..b40b67eb7c 100644 --- a/src/topics.js +++ b/src/topics.js @@ -214,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) @@ -235,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); }); } From 78a3dd68ea1ca747d8d05dc3ee6751b229d68649 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Mon, 28 Oct 2013 00:27:18 -0400 Subject: [PATCH 12/14] hide the no topics warning when a new topic is posted on /unread --- public/src/forum/unread.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/src/forum/unread.js b/public/src/forum/unread.js index 4ab4d3280a..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) { From 7613f02effdcc8751532e23c9b095defe7fcceec Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Mon, 28 Oct 2013 10:27:03 -0400 Subject: [PATCH 13/14] closes #457 --- public/src/forum/category.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/forum/category.js b/public/src/forum/category.js index d6838510b7..a5bfc4a250 100644 --- a/public/src/forum/category.js +++ b/public/src/forum/category.js @@ -85,7 +85,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'); From b5a953b16ce639c4fa0be550f24e5d08fec3d084 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Mon, 28 Oct 2013 10:36:39 -0400 Subject: [PATCH 14/14] fixes topics going into wrong category --- public/src/forum/category.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/public/src/forum/category.js b/public/src/forum/category.js index a5bfc4a250..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'), @@ -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(); }