From f84ff7393a3edbfcf385fc503351bdf97c9a5065 Mon Sep 17 00:00:00 2001 From: heart Date: Fri, 31 Oct 2014 04:07:42 -0400 Subject: [PATCH 1/4] Added option to have active users similar to standard forum software --- library.js | 32 ++++++++++++++++++++++---- public/templates/admin/activeusers.tpl | 10 ++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 public/templates/admin/activeusers.tpl diff --git a/library.js b/library.js index caaa228..293748b 100644 --- a/library.js +++ b/library.js @@ -76,7 +76,29 @@ var html = Widget.templates['activeusers.tpl'], cidOrtid; - if (widget.data.cid) { + if(widget.data.global) { + async.parallel({ + users: function(next) { + user.getUsersFromSet('users:online', 0, 49, next); + }, + isAdministrator: function(next) { + user.isAdministrator(widget.uid, next); + } + }, function(err, results) { + if (err) { + return getUserData(err); + } + + if (!results.isAdministrator) { + results.users = results.users.filter(function(user) { + return user && user.status !== 'offline'; + }); + } + + results.users = results.users.map(function(a) { return a.uid; }); + getUserData(err, results.users); + }); + } else if (widget.data.cid) { cidOrtid = widget.data.cid; categories.getActiveUsers(cidOrtid, getUserData); } else if (widget.area.url.indexOf('topic') === 0) { @@ -188,8 +210,8 @@ { widget: "activeusers", name: "Active Users", - description: "List of active users in a category.", - content: Widget.templates['admin/categorywidget.tpl'] + description: "List of active users, optionally in a category.", + content: Widget.templates['admin/activeusers.tpl'] }, { widget: "moderators", @@ -244,7 +266,7 @@ var templatesToLoad = [ "recentreplies.tpl", "activeusers.tpl", "moderators.tpl", "forumstats.tpl", "recentposts.tpl", "recenttopics.tpl", "categories.tpl", "populartags.tpl", - "admin/categorywidget.tpl", "admin/forumstats.tpl", "admin/html.tpl", "admin/text.tpl", "admin/recentposts.tpl", + "admin/categorywidget.tpl", "admin/activeusers.tpl", "admin/forumstats.tpl", "admin/html.tpl", "admin/text.tpl", "admin/recentposts.tpl", "admin/recenttopics.tpl", "admin/defaultwidget.tpl", "admin/categorieswidget.tpl", "admin/populartags.tpl" ]; @@ -265,4 +287,4 @@ }; module.exports = Widget; -}(module)); \ No newline at end of file +}(module)); diff --git a/public/templates/admin/activeusers.tpl b/public/templates/admin/activeusers.tpl new file mode 100644 index 0000000..1d9d33e --- /dev/null +++ b/public/templates/admin/activeusers.tpl @@ -0,0 +1,10 @@ + +
+ + From 462721bd281c01e9f620e05678817c44b0a7de72 Mon Sep 17 00:00:00 2001 From: dwn Date: Sun, 13 Sep 2015 21:10:20 -0400 Subject: [PATCH 2/4] Fixed option to display all online users in activeusers. --- library.js | 37 +++++++++++++++++--------- public/templates/admin/activeusers.tpl | 2 +- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/library.js b/library.js index 85524bf..d3b00a8 100644 --- a/library.js +++ b/library.js @@ -58,15 +58,18 @@ callback(null, widget.data.html); }; + Widget.render + Widget.renderTextWidget = function(widget, callback) { var parseAsPost = !!widget.data.parseAsPost, text = widget.data.text; - + if (parseAsPost) { plugins.fireHook('filter:parse.raw', text, callback); } else { callback(null, text.replace(/\r\n/g, "
")); } + }; Widget.renderRecentViewWidget = function(widget, callback) { @@ -86,6 +89,14 @@ }; Widget.renderActiveUsersWidget = function(widget, callback) { + function generateHtml(users) { + html = templates.parse(html, { + active_users: users, + relative_path: nconf.get('relative_path') + }); + return html; + } + function getUserData(err, uids) { if (err) { return callback(err); @@ -98,10 +109,7 @@ return callback(err); } - html = templates.parse(html, { - active_users: users, - relative_path: nconf.get('relative_path') - }); + html = generateHtml(users); callback(err, html); }); @@ -110,27 +118,32 @@ var count = Math.max(1, widget.data.numUsers || 24); var html = Widget.templates['widgets/activeusers.tpl'], cidOrtid; var match; - if (widget.data.global) { + if (!!widget.data.global) { async.parallel({ users: function(next) { - user.getUsersFromSet('users:online', 0, 49, next); + user.getUsersFromSet('users:online', widget.uid, 0, 49, next); }, isAdministrator: function(next) { user.isAdministrator(widget.uid, next); } }, function(err, results) { if (err) { - return getUserData(err); + return callback(err); } if (!results.isAdministrator) { - results.users = results.users.filter(function(user) { - return user && user.status !== 'offline'; + results.users = results.users.filter(function(usr) { + return usr && usr.status !== 'offline'; }); } - results.users = results.users.map(function(a) { return a.uid; }); - getUserData(err, results.users); + results.users = results.users.map(function(a) { + return {'uid': a.uid, 'username': a.username, 'userslug': a.userslug, 'picture': a.picture}; + }); + + html = generateHtml(results.users); + + callback(null, html); }); } else if (widget.data.cid) { cidOrtid = widget.data.cid; diff --git a/public/templates/admin/activeusers.tpl b/public/templates/admin/activeusers.tpl index a21f20f..1d9d33e 100644 --- a/public/templates/admin/activeusers.tpl +++ b/public/templates/admin/activeusers.tpl @@ -1,5 +1,5 @@
From 5128e5e3f640803f5447b636396f3901befd3726 Mon Sep 17 00:00:00 2001 From: dwn Date: Mon, 14 Sep 2015 02:50:37 -0400 Subject: [PATCH 3/4] Fix relative path for recent posts. --- library.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.js b/library.js index d3b00a8..fdbb8f6 100644 --- a/library.js +++ b/library.js @@ -223,7 +223,7 @@ if (err) { return callback(err); } - app.render('widgets/recentposts', {posts: posts, numPosts: numPosts, cid: cid}, function(err, html) { + app.render('widgets/recentposts', {posts: posts, numPosts: numPosts, cid: cid, relative_path: nconf.get('relative_path')}, function(err, html) { translator.translate(html, function(translatedHTML) { callback(err, translatedHTML); }); From 9ee7c2fa15204d287d07ea813952e01397c81f6c Mon Sep 17 00:00:00 2001 From: dwn Date: Mon, 14 Sep 2015 16:44:30 -0400 Subject: [PATCH 4/4] converted spaces to tabs and got rid of some residual junk. --- library.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/library.js b/library.js index fdbb8f6..7f9cef0 100644 --- a/library.js +++ b/library.js @@ -58,12 +58,10 @@ callback(null, widget.data.html); }; - Widget.render - Widget.renderTextWidget = function(widget, callback) { var parseAsPost = !!widget.data.parseAsPost, text = widget.data.text; - + if (parseAsPost) { plugins.fireHook('filter:parse.raw', text, callback); } else { @@ -89,13 +87,13 @@ }; Widget.renderActiveUsersWidget = function(widget, callback) { - function generateHtml(users) { - html = templates.parse(html, { - active_users: users, - relative_path: nconf.get('relative_path') - }); - return html; - } + function generateHtml(users) { + html = templates.parse(html, { + active_users: users, + relative_path: nconf.get('relative_path') + }); + return html; + } function getUserData(err, uids) { if (err) { @@ -109,7 +107,7 @@ return callback(err); } - html = generateHtml(users); + html = generateHtml(users); callback(err, html); }); @@ -138,12 +136,12 @@ } results.users = results.users.map(function(a) { - return {'uid': a.uid, 'username': a.username, 'userslug': a.userslug, 'picture': a.picture}; - }); + return {'uid': a.uid, 'username': a.username, 'userslug': a.userslug, 'picture': a.picture}; + }); - html = generateHtml(results.users); + html = generateHtml(results.users); - callback(null, html); + callback(null, html); }); } else if (widget.data.cid) { cidOrtid = widget.data.cid;