sticking to style guide for method names (camelcase)

v1.18.x
Julian Lam 12 years ago
parent 25a1d25108
commit 34bb9dddb5

@ -1,9 +1,10 @@
var fs = require('fs'), var fs = require('fs'),
path = require('path'), path = require('path'),
RDB = require('./redis.js'), RDB = require('./redis.js'),
async = require('async'),
plugins = { plugins = {
libraries: [], libraries: [],
loaded_hooks: {}, loadedHooks: {},
init: function() { init: function() {
if (this.initialized) return; if (this.initialized) return;
if (global.env === 'development') console.log('Info: [plugins] Initializing plugins system'); if (global.env === 'development') console.log('Info: [plugins] Initializing plugins system');
@ -28,7 +29,7 @@ var fs = require('fs'),
_self.libraries[pluginData.id] = require(path.join(pluginPath, pluginData.library)); _self.libraries[pluginData.id] = require(path.join(pluginPath, pluginData.library));
if (pluginData.hooks) { if (pluginData.hooks) {
for(var x=0,numHooks=pluginData.hooks.length;x<numHooks;x++) { for(var x=0,numHooks=pluginData.hooks.length;x<numHooks;x++) {
_self.register_hook(pluginData.id, pluginData.hooks[x]); _self.registerHook(pluginData.id, pluginData.hooks[x]);
} }
} }
if (global.env === 'development') console.log('Info: [plugins] Loaded plugin: ' + pluginData.id); if (global.env === 'development') console.log('Info: [plugins] Loaded plugin: ' + pluginData.id);
@ -52,26 +53,26 @@ var fs = require('fs'),
}); });
}, },
initialized: false, initialized: false,
register_hook: function(id, data) { registerHook: function(id, data) {
/* /*
`data` is an object consisting of (* is required): `data` is an object consisting of (* is required):
`data.hook`*, the name of the NodeBB hook `data.hook`*, the name of the NodeBB hook
`data.method`*, the method called in that plugin `data.method`*, the method called in that plugin
`data.callbacked`, whether or not the hook expects a callback (true), or a return (false). (Default: false) `data.callbacked`, whether or not the hook expects a callback (true), or a return (false). Only used for filters. (Default: false)
(Not implemented) `data.priority`, the relative priority of the method when it is eventually called (default: 10) (Not implemented) `data.priority`, the relative priority of the method when it is eventually called (default: 10)
*/ */
var _self = this; var _self = this;
if (data.hook && data.method) { if (data.hook && data.method) {
_self.loaded_hooks[data.hook] = _self.loaded_hooks[data.hook] || []; _self.loadedHooks[data.hook] = _self.loadedHooks[data.hook] || [];
_self.loaded_hooks[data.hook].push([id, data.method]); _self.loadedHooks[data.hook].push([id, data.method]);
if (global.env === 'development') console.log('Info: [plugins] Hook registered: ' + data.hook + ' will call ' + id); if (global.env === 'development') console.log('Info: [plugins] Hook registered: ' + data.hook + ' will call ' + id);
} else return; } else return;
}, },
fire_hook: function(hook, args, callback) { fireHook: function(hook, args, callback) {
// TODO: Implement priority hook firing // TODO: Implement priority hook firing
var _self = this var _self = this
hookList = this.loaded_hooks[hook]; hookList = this.loadedHooks[hook];
if(hookList && Array.isArray(hookList)) { if(hookList && Array.isArray(hookList)) {
if (global.env === 'development') console.log('Info: [plugins] Firing hook: \'' + hook + '\''); if (global.env === 'development') console.log('Info: [plugins] Firing hook: \'' + hook + '\'');
@ -100,7 +101,9 @@ var fs = require('fs'),
}); });
break; break;
case 'action': case 'action':
async.each(hookList, function(hookObj) {
_self.libraries[hookObj[0]][hookObj[1]].apply(_self.libraries[hookObj[0]], args);
});
break; break;
default: default:
// Do nothing... // Do nothing...

@ -5,7 +5,8 @@ var RDB = require('./redis.js'),
user = require('./user.js'), user = require('./user.js'),
async = require('async'), async = require('async'),
utils = require('../public/src/utils'); utils = require('../public/src/utils'),
plugins = require('./plugins');
(function(PostTools) { (function(PostTools) {
PostTools.isMain = function(pid, tid, callback) { PostTools.isMain = function(pid, tid, callback) {
@ -71,7 +72,10 @@ var RDB = require('./redis.js'),
PostTools.privileges(pid, uid, function(privileges) { PostTools.privileges(pid, uid, function(privileges) {
if (privileges.editable) { if (privileges.editable) {
plugins.fireHook('filter:save_post_content', content, function(parsedContent) {
content = parsedContent;
success(); success();
});
} }
}); });
} }

@ -280,7 +280,7 @@ var RDB = require('./redis.js'),
RDB.incr('global:next_post_id', function(err, pid) { RDB.incr('global:next_post_id', function(err, pid) {
RDB.handle(err); RDB.handle(err);
plugins.fire_hook('filter:save_post_content', content, function(content) { plugins.fireHook('filter:save_post_content', content, function(content) {
var timestamp = Date.now(), var timestamp = Date.now(),
postData = { postData = {
'pid': pid, 'pid': pid,
@ -343,6 +343,8 @@ var RDB = require('./redis.js'),
}); });
} }
plugins.fireHook('action:save_post_content', [content])
if(!images) { if(!images) {
postData.uploadedImages = JSON.stringify(uploadedImages); postData.uploadedImages = JSON.stringify(uploadedImages);
Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages); Posts.setPostField(pid, 'uploadedImages', postData.uploadedImages);

Loading…
Cancel
Save