v1.18.x
barisusakli 11 years ago
commit ab9af6202d

@ -35,12 +35,12 @@
"mkdirp": "~0.3.5", "mkdirp": "~0.3.5",
"nconf": "~0.6.7", "nconf": "~0.6.7",
"nodebb-plugin-dbsearch": "0.0.9", "nodebb-plugin-dbsearch": "0.0.9",
"nodebb-plugin-markdown": "~0.4.2", "nodebb-plugin-markdown": "~0.5.0",
"nodebb-plugin-mentions": "~0.5.0", "nodebb-plugin-mentions": "~0.5.0",
"nodebb-plugin-soundpack-default": "~0.1.1", "nodebb-plugin-soundpack-default": "~0.1.1",
"nodebb-theme-lavender": "~0.0.26", "nodebb-theme-lavender": "~0.0.26",
"nodebb-theme-vanilla": "~0.0.21", "nodebb-theme-vanilla": "~0.0.21",
"nodebb-widget-essentials": "~0.0.21", "nodebb-widget-essentials": "~0.1.0",
"npm": "^1.4.6", "npm": "^1.4.6",
"passport": "~0.2.0", "passport": "~0.2.0",
"passport-local": "0.1.6", "passport-local": "0.1.6",

@ -5,10 +5,10 @@ var fs = require('fs'),
async = require('async'), async = require('async'),
winston = require('winston'), winston = require('winston'),
nconf = require('nconf'), nconf = require('nconf'),
eventEmitter = require('events').EventEmitter,
semver = require('semver'), semver = require('semver'),
db = require('./database'), db = require('./database'),
emitter = require('./emitter'),
meta = require('./meta'), meta = require('./meta'),
utils = require('../public/src/utils'), utils = require('../public/src/utils'),
pkg = require('../package.json'); pkg = require('../package.json');
@ -24,9 +24,6 @@ var fs = require('fs'),
Plugins.initialized = false; Plugins.initialized = false;
// Events
Plugins.readyEvent = new eventEmitter();
Plugins.init = function() { Plugins.init = function() {
if (Plugins.initialized) { if (Plugins.initialized) {
return; return;
@ -47,14 +44,15 @@ var fs = require('fs'),
if (global.env === 'development') { if (global.env === 'development') {
winston.info('[plugins] Plugins OK'); winston.info('[plugins] Plugins OK');
} }
Plugins.initialized = true; Plugins.initialized = true;
Plugins.readyEvent.emit('ready'); emitter.emit('plugins:loaded');
}); });
}; };
Plugins.ready = function(callback) { Plugins.ready = function(callback) {
if (!Plugins.initialized) { if (!Plugins.initialized) {
Plugins.readyEvent.once('ready', callback); emitter.once('plugins:loaded', callback);
} else { } else {
callback(); callback();
} }
@ -271,32 +269,40 @@ var fs = require('fs'),
var method; var method;
if (data.hook && data.method && typeof data.method === 'string' && data.method.length > 0) { if (data.hook && data.method) {
data.id = id; data.id = id;
if (!data.priority) { if (!data.priority) {
data.priority = 10; data.priority = 10;
} }
method = data.method.split('.').reduce(function(memo, prop) {
if (memo !== null && memo[prop]) {
return memo[prop];
} else {
// Couldn't find method by path, aborting
return null;
}
}, Plugins.libraries[data.id]);
if (method === null) { if (typeof data.method === 'string' && data.method.length > 0) {
method = data.method.split('.').reduce(function(memo, prop) {
if (memo !== null && memo[prop]) {
return memo[prop];
} else {
// Couldn't find method by path, aborting
return null;
}
}, Plugins.libraries[data.id]);
// Write the actual method reference to the hookObj
data.method = method;
register();
} else if (typeof data.method === 'function') {
register();
} else {
winston.warn('[plugins/' + id + '] Hook method mismatch: ' + data.hook + ' => ' + data.method); winston.warn('[plugins/' + id + '] Hook method mismatch: ' + data.hook + ' => ' + data.method);
return callback();
} }
}
// Write the actual method reference to the hookObj function register() {
data.method = method;
Plugins.loadedHooks[data.hook] = Plugins.loadedHooks[data.hook] || []; Plugins.loadedHooks[data.hook] = Plugins.loadedHooks[data.hook] || [];
Plugins.loadedHooks[data.hook].push(data); Plugins.loadedHooks[data.hook].push(data);
callback(); if (typeof callback === 'function') {
callback();
}
} }
}; };
@ -319,9 +325,25 @@ var fs = require('fs'),
var hookType = hook.split(':')[0]; var hookType = hook.split(':')[0];
switch (hookType) { switch (hookType) {
case 'filter': case 'filter':
if (hook === 'filter:app.load') {
// Special case for this hook, as arguments passed in are always the same
async.each(hookList, function(hookObj, next) {
if (hookObj.method) {
hookObj.method.apply(Plugins, args.concat(next));
}
}, function(err) {
callback(err);
});
return;
}
async.reduce(hookList, args, function(value, hookObj, next) { async.reduce(hookList, args, function(value, hookObj, next) {
if (hookObj.method) { if (hookObj.method) {
if (!hookObj.hasOwnProperty('callbacked') || hookObj.callbacked === true) { if (!hookObj.hasOwnProperty('callbacked') || hookObj.callbacked === true) {
// omg, after 6 months I finally realised what this does...
// It adds the callback to the arguments passed-in, since the callback
// is defined in *this* file (the async cb), and not the hooks themselves.
var value = hookObj.method.apply(Plugins, value.concat(function() { var value = hookObj.method.apply(Plugins, value.concat(function() {
next(arguments[0], Array.prototype.slice.call(arguments, 1)); next(arguments[0], Array.prototype.slice.call(arguments, 1));
})); }));
@ -353,7 +375,9 @@ var fs = require('fs'),
} }
} }
callback.apply(Plugins, [err].concat(values)); if (callback) {
callback.apply(Plugins, [err].concat(values));
}
}); });
break; break;
case 'action': case 'action':
@ -662,4 +686,5 @@ var fs = require('fs'),
callback(err, plugins); callback(err, plugins);
}); });
}; };
}(exports)); }(exports));

@ -3,19 +3,13 @@
var bcrypt = require('bcryptjs'), var bcrypt = require('bcryptjs'),
async = require('async'), async = require('async'),
nconf = require('nconf'), nconf = require('nconf'),
winston = require('winston'),
gravatar = require('gravatar'), gravatar = require('gravatar'),
S = require('string'),
utils = require('./../public/src/utils'),
plugins = require('./plugins'), plugins = require('./plugins'),
db = require('./database'), db = require('./database'),
meta = require('./meta'), meta = require('./meta'),
groups = require('./groups'), groups = require('./groups'),
topics = require('./topics'), emitter = require('./emitter');
events = require('./events'),
emitter = require('./emitter'),
Emailer = require('./emailer');
(function(User) { (function(User) {

Loading…
Cancel
Save