tested filter-type hooks, working! :)

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

@ -71,24 +71,24 @@ var fs = require('fs'),
fire_hook: function(hook, args, callback) { fire_hook: function(hook, args, callback) {
// TODO: Implement priority hook firing // TODO: Implement priority hook firing
var _self = this var _self = this
hookList = loaded_hooks[hook]; hookList = this.loaded_hooks[hook];
if(loaded_hooks[hook] && 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 + '\'');
var hookType = hook.split(':')[0]; var hookType = hook.split(':')[0];
switch(hookType) { switch(hookType) {
case 'filter': case 'filter':
// Filters only take one argument, so only args[0] will be passed in // Filters only take one argument, so only args[0] will be passed in
var returnVal = args[0]; var returnVal = (Array.isArray(args) ? args[0] : args);
async.each(hookList, function(hookObj, next) { async.each(hookList, function(hookObj, next) {
if (hookObj.callbacked) { if (hookObj.callbacked) {
_self.libraries[hookObj.id][hookObj.method](returnVal, function(err, afterVal) { _self.libraries[hookObj[0]][hookObj[1]](returnVal, function(err, afterVal) {
returnVal = afterVal; returnVal = afterVal;
next(err); next(err);
}); });
} else { } else {
returnVal = _self.libraries[hookObj.id][hookObj.method](returnVal); returnVal = _self.libraries[hookObj[0]][hookObj[1]](returnVal);
next(); next();
} }
}, function(err) { }, function(err) {

@ -7,7 +7,8 @@ var RDB = require('./redis.js'),
threadTools = require('./threadTools.js'), threadTools = require('./threadTools.js'),
postTools = require('./postTools'), postTools = require('./postTools'),
feed = require('./feed.js'), feed = require('./feed.js'),
async = require('async'); async = require('async'),
plugins = require('./plugins');
(function(Posts) { (function(Posts) {
@ -275,14 +276,13 @@ var RDB = require('./redis.js'),
} }
topics.isLocked(tid, function(locked) { topics.isLocked(tid, function(locked) {
if (!locked || locked === '0') { if (!locked || locked === '0') {
RDB.incr('global:next_post_id', function(err, pid) { RDB.incr('global:next_post_id', function(err, pid) {
RDB.handle(err); RDB.handle(err);
var timestamp = Date.now(); plugins.fire_hook('filter:save_post_content', content, function(content) {
var timestamp = Date.now(),
var postData = { postData = {
'pid': pid, 'pid': pid,
'uid': uid, 'uid': uid,
'tid': tid, 'tid': tid,
@ -361,6 +361,7 @@ var RDB = require('./redis.js'),
}); });
} }
}); });
});
} else { } else {
callback(null); callback(null);
} }

Loading…
Cancel
Save