🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

nodebb-plugin-shoutbox

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodebb-plugin-shoutbox - npm Package Compare versions

Comparing version

to
0.0.6

public/notif.mp3

191

library.js

@@ -16,2 +16,4 @@ var async = require('async'),

'name': "Shoutbox",
'icon': 'fa-bullhorn',
'setting_prefix': 'shoutbox:',
'global': {

@@ -21,4 +23,3 @@ 'route': '/shoutbox'

'admin': {
'route': '/plugins/shoutbox',
'icon': 'fa-bullhorn'
'route': '/plugins/shoutbox'
},

@@ -30,2 +31,7 @@ 'config_keys': ['headerlink','pageposition','shoutlimit'],

'shoutlimit': 25
},
'setting_keys': ['sound', 'notification'],
'setting_defaults': {
'sound': true,
'notification': true
}

@@ -36,5 +42,5 @@ });

Shoutbox.config = {
'get': function(key) {
"get": function(key) {
if (constants.config_keys.indexOf(key) !== -1) {
return Meta.config['shoutbox:' + key] || constants.config_defaults[key];
return Meta.config[constants.setting_prefix + key] || constants.config_defaults[key];
}

@@ -49,7 +55,7 @@ }

"global": {
addNavigation: function(custom_header, callback) {
"addNavigation": function(custom_header, callback) {
if (Shoutbox.config.get('headerlink') === '1') {
custom_header.navigation.push({
"class": "",
"iconClass": "fa fa-fw fa-bullhorn",
"iconClass": "fa fa-fw " + constants.icon,
"route": constants.global.route,

@@ -61,54 +67,37 @@ "text": constants.name

},
addRoute: function(custom_routes, callback) {
function getBaseTemplate(next) {
fs.readFile(path.resolve(__dirname, '../../public/templates/home.tpl'), function (err, template) {
next(err, template);
"addRoute": function(custom_routes, callback) {
fs.readFile(path.resolve(__dirname, './partials/shoutbox.tpl'), function (err, partial) {
custom_routes.routes.push({
route: constants.global.route,
method: "get",
options: function(req, res, callback) {
callback({
req: req,
res: res,
content: '<script> \
ajaxify.initialLoad = true; \
templates.ready(function(){ajaxify.go("shoutbox", null, true);}); \
</script>'
});
}
});
}
function getPartial(next) {
fs.readFile(path.resolve(__dirname, './partials/shoutbox.tpl'), function (err, template) {
next(err, template);
custom_routes.api.push({
route: constants.global.route,
method: "get",
callback: function(req, res, callback) {
callback({});
}
});
}
async.parallel([getBaseTemplate, getPartial], function(err, results) {
var template = results[0],
partial = results[1];
// todo: this line should become a templates.js method, ie. templates.replaceBLock(blockname, partial);
if (Shoutbox.config.get('pageposition') === "top") {
template = template.toString().replace(/<div class="row home"/g, partial + "$&");
} else if (Shoutbox.config.get('pageposition') === "bottom") {
template = template.toString().replace(/<div class="row footer-stats"/g, partial + "$&");
} else {
template = template;
}
custom_routes.templates.push({
"template": "home.tpl",
"content": template
"template": "shoutbox.tpl",
"content": partial
});
fs.readFile(path.resolve(__dirname, './partials/shoutbox.tpl'), function (err, tpl) {
custom_routes.routes.push({
route: constants.global.route,
method: "get",
options: function(req, res, callback) {
callback({
req: req,
res: res,
content: tpl
});
}
});
callback(null, custom_routes);
});
callback(null, custom_routes);
});
},
addScripts: function(scripts, callback) {
"addScripts": function(scripts, callback) {
return scripts.concat([

@@ -120,6 +109,6 @@ 'plugins/nodebb-plugin-shoutbox/js/main.js'

"admin": {
addNavigation: function(custom_header, callback) {
"addNavigation": function(custom_header, callback) {
custom_header.plugins.push({
"route": constants.admin.route,
"icon": constants.admin.icon,
"icon": constants.icon,
"name": constants.name

@@ -130,3 +119,3 @@ });

},
addRoute: function(custom_routes, callback) {
"addRoute": function(custom_routes, callback) {
fs.readFile(path.join(__dirname, './partials/admin.tpl'), function(err, tpl) {

@@ -176,3 +165,3 @@ custom_routes.routes.push({

var msg = S(data.message).stripTags().s;
User.getUserField(socket.uid, 'username', function(err, username) {
User.getMultipleUserFields([socket.uid], ['username', 'picture', 'userslug'], function(err, userData) {
if(err) {

@@ -182,7 +171,10 @@ return;

Shoutbox.backend.parse(socket.uid, username, msg, function(err, parsed) {
userData = userData[0];
userData.uid = socket.uid;
Shoutbox.backend.parse(msg, userData, true, function(err, parsed) {
Shoutbox.backend.addShout(socket.uid, msg, function(err, message) {
SocketIndex.server.sockets.in('global').emit('event:shoutbox.receive', {
fromuid: message.fromuid,
username: username,
username: userData.username,
content: parsed,

@@ -209,8 +201,5 @@ sid: message.sid,

"edit": function(socket, data, callback) {
console.log(data);
console.log(typeof(data.sid));
if (typeof(data.sid) === 'string' && typeof(data.user) === 'string') {
var msg = S(data.edited).stripTags().s;
Shoutbox.backend.editShout(data.sid, msg, socket.uid, data.user, function(err, result) {
console.log(result);
if (result !== false) {

@@ -227,2 +216,9 @@ SocketIndex.server.sockets.in('global').emit('event:shoutbox.edit', {

},
"saveSetting": function(socket, data, callback) {
if (!data.key || !socket.uid) {
return callback(null, false);
}
var key = constants.setting_prefix + data.key;
User.setUserField(socket.uid, key, data.value, callback);
},
"removeAll": function(socket, data, callback) {

@@ -240,3 +236,3 @@ if (data !== null && data !== undefined) {

},
"get_users": function(socket, data, callback){
"getUsers": function(socket, data, callback){
var users = Object.keys(SocketIndex.getConnectedClients());

@@ -251,8 +247,26 @@ User.getMultipleUserFields(users, ['username'], function(err, usersData) {

"getConfig": function(socket, data, callback) {
User.isAdministrator(socket.uid, function(err, isAdmin) {
User.getUserFields(socket.uid, constants.setting_keys.map(function(e) {
return constants.setting_prefix + e;
}), function(err, result) {
callback(null, {
'maxShouts': parseInt(Shoutbox.config.get('shoutlimit'), 10),
'isAdmin': isAdmin
'pagePosition': Shoutbox.config.get('pageposition'),
'settings': result
});
});
},
"getPartial": function(socket, data, callback) {
fs.readFile(path.resolve(__dirname, './partials/shoutbox.tpl'), function (err, partial) {
callback(err, partial.toString());
});
},
"getOriginalShout": function(socket, data, callback) {
if (data.sid && data.sid.length > 0) {
Shoutbox.backend.getShout(data.sid, function(err, shout) {
if (err) {
return callback(err);
}
return callback(null, shout.content);
});
}
}

@@ -283,2 +297,10 @@ }

},
"getShout": function(sid, callback) {
db.getObject('shout:' + sid, function(err, shout) {
if (err) {
return callback(err);
}
return callback(null, shout);
});
},
"getShouts": function(start, end, callback) {

@@ -304,4 +326,6 @@ db.getListRange('shouts', start, end, function(err, sids) {

}
User.getUserField(message.fromuid, 'username', function(err, username) {
Shoutbox.backend.parse(message.fromuid, username, message.content, function(err, parsed) {
User.getMultipleUserFields([message.fromuid], ['username', 'picture', 'userslug'], function(err, userData) {
userData = userData[0];
userData.uid = message.fromuid;
Shoutbox.backend.parse(message.content, userData, false, function(err, parsed) {
message.content = parsed;

@@ -324,14 +348,31 @@ message.sid = sid;

},
"parse": function (uid, username, message, callback) {
"parse": function(message, userData, isNew, callback) {
Plugins.fireHook('filter:post.parse', message, function(err, parsed) {
User.isAdministrator(uid, function(err, isAdmin) {
User.isAdministrator(userData.uid, function(err, isAdmin) {
var username,
picture,
userclass = "shoutbox-user";
if (isAdmin) {
username = "<span class='shoutbox-user-admin'>" + username + "</span>: ";
//putTogether(username, message);
} else {
username = "<span class='shoutbox-user'>" + username + "</span>: ";
userclass += " shoutbox-user-admin";
}
//var result = parsed.replace("<p>", "<p>" + username + ": ");
var result = username + parsed;
callback(null, result);
username = '<a href="/user/' + userData.userslug + '" ' +
'class="' + userclass + '">' + userData.username + '</a>: ';
picture = '<img class="shoutbox-user-image" src="' + userData.picture + '">';
var shoutData = {
message: message,
parsed: parsed,
fromuid: userData.uid,
myuid: userData.uid,
toUserData: userData,
myUserData: userData,
isNew: isNew,
parsedMessage: picture + username + parsed
};
Plugins.fireHook('filter:messaging.parse', shoutData, function(err, messageData) {
callback(null, messageData.parsedMessage);
});
});

@@ -370,4 +411,8 @@ });

}
Shoutbox.backend.parse(uid, username, msg, function(err, result) {
return callback(null, result);
User.getMultipleUserFields([fromuid], ['username', 'picture', 'userslug'], function(err, userData) {
userData = userData[0];
userData.uid = fromuid;
Shoutbox.backend.parse(msg, userData, false, function(err, result) {
return callback(null, result);
});
});

@@ -374,0 +419,0 @@ });

{
"name": "nodebb-plugin-shoutbox",
"version": "0.0.5",
"version": "0.0.6",
"description": "NodeBB Shoutbox Plugin",

@@ -25,4 +25,5 @@ "main": "library.js",

"async": "~0.2.9",
"path": "~0.4.9"
"path": "~0.4.9",
"string": "~1.8.0"
}
}
$(document).ready(function() {
if (document.location.pathname === "/shoutbox") {
requirejs([
'plugins/nodebb-plugin-shoutbox/js/shoutbox.js'
], function(shoutBox) {
shoutBox.base.init();
shoutBox.base.showUserPanel();
});
}
$(document).bind('DOMNodeInserted', function(event) {
// todo improve this
if (event.target.className == 'row shoutbox-row') {
$(window).on('action:ajaxify.end', function(e, data) {
if (data.url === "" || data.url === "shoutbox") {
requirejs([
'plugins/nodebb-plugin-shoutbox/js/shoutbox.js'
], function(shoutBox) {
shoutBox.base.init();
shoutBox.base.init(data.url);
if (data.url === "shoutbox") {
shoutBox.base.showUserPanel();
}
});

@@ -19,0 +12,0 @@ }

@@ -17,3 +17,7 @@ define(['string'], function(S) {

"edit": "modules.shoutbox.edit",
"get_users": "modules.shoutbox.get_users",
"save_settings": "modules.shoutbox.saveSetting",
"get_users": "modules.shoutbox.getUsers",
"get_orig_shout": "modules.shoutbox.getOriginalShout",
"get_partial": "modules.shoutbox.getPartial",
"get_config": "modules.shoutbox.getConfig",
"onreceive": "event:shoutbox.receive",

@@ -25,14 +29,12 @@ "ondelete": "event:shoutbox.delete",

"anonMessage": "You must be logged in to view the shoutbox!",
"emptyMessage": "The shoutbox is empty, start shouting!"
"emptyMessage": "The shoutbox is empty, start shouting!",
"settings-prefix": "shoutbox-settings-"
};
module.base = {
"init": function(callback) {
box.utils.checkAnon(function(isAnon) {
"init": function(url, callback) {
function load(callback) {
var shoutBox = module.base.getShoutPanel();
if (isAnon) {
box.utils.hideInputs();
box.utils.showAnonMessage(shoutBox);
} else {
box.utils.getConfig();
if (shoutBox.length > 0) {
box.utils.parseSettings(shoutBox);
box.utils.registerHandlers(shoutBox);

@@ -42,8 +44,22 @@ box.base.getShouts(shoutBox);

box.vars.loaded = true;
if (callback) {
callback();
}
}
box.utils.checkAnon(function(isAnon) {
if(!isAnon) {
if (url === "") {
box.utils.createShoutbox(function(success) {
if (success) {
load(callback);
}
});
} else {
load(callback);
}
}
});
},
"showUserPanel": function() {

@@ -54,11 +70,8 @@ module.base.getUsersPanel().parent().removeClass('hidden');

},
"hasLoaded": function() {
return box.vars.loaded;
},
"getShoutPanel": function() {
return $('#shoutbox');
},
"getUsersPanel": function() {

@@ -97,5 +110,5 @@ return $('#shoutbox-users');

var options = '';
if (shout.fromuid === app.uid || box.vars.config.isAdmin === true) {
options += '<button type="button" class="shoutbox-shout-option shoutbox-shout-option-close close pull-right fa fa-times" aria-hidden="true"></button>';
options += '<button type="button" class="shoutbox-shout-option shoutbox-shout-option-edit close pull-right fa fa-pencil" aria-hidden="true"></button>';
if (shout.fromuid === app.uid || app.isAdmin === true) {
options += '<a href="#" class="shoutbox-shout-option shoutbox-shout-option-close pull-right fa fa-times"></a>';
options += '<a href="#" class="shoutbox-shout-option shoutbox-shout-option-edit pull-right fa fa-pencil"></a>';
}

@@ -126,2 +139,19 @@ var content = '<span class="shoutbox-shout-content">' + shout.content + '</span>';

box.utils = {
"createShoutbox": function(callback) {
box.utils.getConfig(function() {
socket.emit(box.vars.sockets.get_partial, function(err, partial) {
var loc = box.vars.config.pagePosition;
if (loc !== 'none' && !err) {
if (loc === 'top') {
$(partial).insertBefore('.home');
} else if (loc === 'bottom') {
$(partial).insertBefore('.footer-stats');
}
callback(true);
} else {
callback(false);
}
});
});
},
"checkAnon": function(callback) {

@@ -139,7 +169,34 @@ if (app.uid === null) {

},
"getConfig": function() {
socket.emit('modules.shoutbox.getConfig', function(err, config) {
"getConfig": function(callback) {
socket.emit(box.vars.sockets.get_config, function(err, config) {
box.vars.config = config;
if(callback) {
callback();
}
});
},
"parseSettings": function(shoutBox) {
var settings = box.vars.config.settings;
var s = {};
if (!settings) {
return;
}
for(var key in settings) {
if (settings.hasOwnProperty(key)) {
var value = settings[key];
var k = key.split(':')[1];
s[k] = value;
var el = shoutBox.find('#shoutbox-settings-' + k + ' span');
if (value) {
el.removeClass('fa-times').addClass('fa-check');
} else {
el.removeClass('fa-check').addClass('fa-times');
}
}
}
box.vars.config.settings = s;
},
"getSetting": function(key) {
return box.vars.config.settings[key];
},
"startUserPoll": function() {

@@ -152,5 +209,8 @@ if(box.vars.userCheckIntervalId === 0) {

},
"hideInputs": function() {
$('#shoutbox').find('.btn-group, .input-group').hide();
"hideInputs": function(shoutBox) {
shoutBox.find('.btn-group, .input-group').hide();
},
"hideShoutbox": function(shoutBox) {
shoutBox.addClass('hidden');
},
"registerHandlers": function(shoutBox) {

@@ -214,2 +274,3 @@ box.utils.addActionHandlers(shoutBox);

});
return false;
}

@@ -226,14 +287,17 @@ },

cur = $(shout).find('.shoutbox-shout-content').html().split(': ')[1];
bootbox.prompt("Enter edited message", function(result) {
if (result === cur || result === null) {
return;
}
socket.emit(box.vars.sockets.edit, {"sid": sid, "user": user, "edited": result}, function (err, result) {
if (result === true) {
app.alertSuccess("Successfully edited shout!");
} else if (err) {
app.alertError("Error editing shout: " + err, 3000);
socket.emit(box.vars.sockets.get_orig_shout, {"sid": sid}, function(err, orig) {
bootbox.prompt("Enter edited message", function(result) {
if (result === cur || result === null) {
return;
}
});
}).find('.bootbox-input').val(cur);
socket.emit(box.vars.sockets.edit, {"sid": sid, "user": user, "edited": result}, function (err, result) {
if (result === true) {
app.alertSuccess("Successfully edited shout!");
} else if (err) {
app.alertError("Error editing shout: " + err, 3000);
}
});
}).find('.bootbox-input').val(orig);
});
return false;
}

@@ -362,2 +426,25 @@ },

}
},
"settings": {
"register": function(shoutBox) {
shoutBox.off('click', '#shoutbox-settings-menu a').on('click', '#shoutbox-settings-menu a', this.handle);
},
"handle": function(e) {
var el = $(e.currentTarget),
statusEl = el.find('span'),
key = el.attr('id').split(box.vars['settings-prefix'])[1],
status = statusEl.hasClass('fa-check');
if (status) {
statusEl.removeClass('fa-check').addClass('fa-times');
} else {
statusEl.removeClass('fa-times').addClass('fa-check');
}
box.vars.config.settings[key] = !status;
socket.emit(box.vars.sockets.save_settings, {"key": key, "value": !status}, function(err, result) {
if (err || result === false) {
app.alertError("Error saving settings!!");
}
});
return false;
}
}

@@ -376,3 +463,8 @@ };

module.box.addShout(module.base.getShoutPanel(), data);
app.alternatingTitle(box.vars.titleAlert.replace(/%u/g, data.username));
if (box.utils.getSetting('notification')) {
app.alternatingTitle(box.vars.titleAlert.replace(/%u/g, data.username));
}
if (box.utils.getSetting('sound')) {
$('#shoutbox-sounds-notification')[0].play();
}
}

@@ -379,0 +471,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet