mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-30 18:46:01 +01:00
tested filter-type hooks, working! :)
This commit is contained in:
@@ -71,24 +71,24 @@ var fs = require('fs'),
|
||||
fire_hook: function(hook, args, callback) {
|
||||
// TODO: Implement priority hook firing
|
||||
var _self = this
|
||||
hookList = loaded_hooks[hook];
|
||||
hookList = this.loaded_hooks[hook];
|
||||
|
||||
if(loaded_hooks[hook] && Array.isArray(hookList)) {
|
||||
if (global.env === 'development') console.log('Info: [plugins] Firing hook: ' + hook);
|
||||
if(hookList && Array.isArray(hookList)) {
|
||||
if (global.env === 'development') console.log('Info: [plugins] Firing hook: \'' + hook + '\'');
|
||||
var hookType = hook.split(':')[0];
|
||||
switch(hookType) {
|
||||
case 'filter':
|
||||
// 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) {
|
||||
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;
|
||||
next(err);
|
||||
});
|
||||
} else {
|
||||
returnVal = _self.libraries[hookObj.id][hookObj.method](returnVal);
|
||||
returnVal = _self.libraries[hookObj[0]][hookObj[1]](returnVal);
|
||||
next();
|
||||
}
|
||||
}, function(err) {
|
||||
|
||||
11
src/posts.js
11
src/posts.js
@@ -7,7 +7,8 @@ var RDB = require('./redis.js'),
|
||||
threadTools = require('./threadTools.js'),
|
||||
postTools = require('./postTools'),
|
||||
feed = require('./feed.js'),
|
||||
async = require('async');
|
||||
async = require('async'),
|
||||
plugins = require('./plugins');
|
||||
|
||||
(function(Posts) {
|
||||
|
||||
@@ -275,14 +276,13 @@ var RDB = require('./redis.js'),
|
||||
}
|
||||
|
||||
topics.isLocked(tid, function(locked) {
|
||||
|
||||
if (!locked || locked === '0') {
|
||||
RDB.incr('global:next_post_id', function(err, pid) {
|
||||
RDB.handle(err);
|
||||
|
||||
var timestamp = Date.now();
|
||||
|
||||
var postData = {
|
||||
plugins.fire_hook('filter:save_post_content', content, function(content) {
|
||||
var timestamp = Date.now(),
|
||||
postData = {
|
||||
'pid': pid,
|
||||
'uid': uid,
|
||||
'tid': tid,
|
||||
@@ -361,6 +361,7 @@ var RDB = require('./redis.js'),
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user