allow core to tap into NodeBB's hook system, closes #989

v1.18.x
psychobunny 11 years ago
parent e10307426d
commit 423da904de

@ -269,28 +269,34 @@ 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);
@ -680,4 +686,5 @@ var fs = require('fs'),
callback(err, plugins); callback(err, plugins);
}); });
}; };
}(exports)); }(exports));

Loading…
Cancel
Save