mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +01:00
closes #2303
see https://community.nodebb.org/topic/3039/filter-post-parse-and-filter-post-parsesignature-changes
This commit is contained in:
@@ -173,7 +173,7 @@ accountsController.getAccount = function(req, res, next) {
|
|||||||
posts.getPostsByUid(callerUID, userData.theirid, 0, 9, next);
|
posts.getPostsByUid(callerUID, userData.theirid, 0, 9, next);
|
||||||
},
|
},
|
||||||
signature: function(next) {
|
signature: function(next) {
|
||||||
postTools.parseSignature(userData.signature, next);
|
postTools.parseSignature(userData, callerUID, next);
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if(err) {
|
if(err) {
|
||||||
@@ -191,7 +191,6 @@ accountsController.getAccount = function(req, res, next) {
|
|||||||
userData.profileviews = 1;
|
userData.profileviews = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
userData.signature = results.signature;
|
|
||||||
res.render('account/profile', userData);
|
res.render('account/profile', userData);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ var db = require('./database'),
|
|||||||
}
|
}
|
||||||
|
|
||||||
Messaging.parse = function (message, fromuid, myuid, toUserData, myUserData, isNew, callback) {
|
Messaging.parse = function (message, fromuid, myuid, toUserData, myUserData, isNew, callback) {
|
||||||
plugins.fireHook('filter:post.parse', message, function(err, parsed) {
|
plugins.fireHook('filter:parse.raw', message, function(err, parsed) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(message);
|
return callback(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,14 +93,14 @@ var winston = require('winston'),
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
content: function(next) {
|
postData: function(next) {
|
||||||
PostTools.parse(postData.content, next);
|
PostTools.parsePost(postData, uid, next);
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
results.content = results.postData.content;
|
||||||
//events.logPostEdit(uid, pid);
|
//events.logPostEdit(uid, pid);
|
||||||
plugins.fireHook('action:post.edit', postData);
|
plugins.fireHook('action:post.edit', postData);
|
||||||
callback(null, results);
|
callback(null, results);
|
||||||
@@ -137,7 +137,7 @@ var winston = require('winston'),
|
|||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if(err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,13 +149,7 @@ var winston = require('winston'),
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
PostTools.parse(postData.content, function(err, parsed) {
|
PostTools.parsePost(postData, uid, callback);
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
postData.content = parsed;
|
|
||||||
callback(null, postData);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -171,20 +165,18 @@ var winston = require('winston'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
PostTools.parse = function(raw, callback) {
|
PostTools.parsePost = function(postData, uid, callback) {
|
||||||
parse('filter:post.parse', raw + '\n', callback);
|
postData.content = postData.content || '';
|
||||||
};
|
|
||||||
|
|
||||||
PostTools.parseSignature = function(raw, callback) {
|
plugins.fireHook('filter:parse.post', {postData: postData, uid: uid}, function(err, data) {
|
||||||
parse('filter:post.parseSignature', raw, callback);
|
callback(err, data ? data.postData : null);
|
||||||
};
|
|
||||||
|
|
||||||
function parse(hook, raw, callback) {
|
|
||||||
raw = raw || '';
|
|
||||||
|
|
||||||
plugins.fireHook(hook, raw, function(err, parsed) {
|
|
||||||
callback(null, !err ? parsed : raw);
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
PostTools.parseSignature = function(userData, uid, callback) {
|
||||||
|
userData.signature = userData.signature || '';
|
||||||
|
|
||||||
|
plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback);
|
||||||
|
};
|
||||||
|
|
||||||
}(exports));
|
}(exports));
|
||||||
|
|||||||
21
src/posts.js
21
src/posts.js
@@ -146,16 +146,7 @@ var async = require('async'),
|
|||||||
|
|
||||||
postData.relativeTime = utils.toISOString(postData.timestamp);
|
postData.relativeTime = utils.toISOString(postData.timestamp);
|
||||||
postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? utils.toISOString(postData.edited) : '';
|
postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? utils.toISOString(postData.edited) : '';
|
||||||
|
postTools.parsePost(postData, uid, next);
|
||||||
postTools.parse(postData.content, function(err, content) {
|
|
||||||
if(err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
postData.content = content;
|
|
||||||
next(null, postData);
|
|
||||||
});
|
|
||||||
|
|
||||||
}, function(err, posts) {
|
}, function(err, posts) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@@ -176,7 +167,7 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Posts.getUserInfoForPosts = function(uids, callback) {
|
Posts.getUserInfoForPosts = function(uids, uid, callback) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
groups: function(next) {
|
groups: function(next) {
|
||||||
groups.getUserGroups(uids, next);
|
groups.getUserGroups(uids, next);
|
||||||
@@ -212,7 +203,7 @@ var async = require('async'),
|
|||||||
if (parseInt(meta.config.disableSignatures, 10) === 1) {
|
if (parseInt(meta.config.disableSignatures, 10) === 1) {
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
postTools.parseSignature(userData.signature, next);
|
postTools.parseSignature(userData, uid, next);
|
||||||
},
|
},
|
||||||
customProfileInfo: function(next) {
|
customProfileInfo: function(next) {
|
||||||
plugins.fireHook('filter:posts.custom_profile_info', {profile: [], uid: userData.uid}, next);
|
plugins.fireHook('filter:posts.custom_profile_info', {profile: [], uid: userData.uid}, next);
|
||||||
@@ -221,7 +212,7 @@ var async = require('async'),
|
|||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
userData.signature = results.signature;
|
|
||||||
userData.custom_profile_info = results.customProfileInfo.profile;
|
userData.custom_profile_info = results.customProfileInfo.profile;
|
||||||
|
|
||||||
plugins.fireHook('filter:posts.modifyUserInfo', userData, next);
|
plugins.fireHook('filter:posts.modifyUserInfo', userData, next);
|
||||||
@@ -335,12 +326,12 @@ var async = require('async'),
|
|||||||
return next(null, post);
|
return next(null, post);
|
||||||
}
|
}
|
||||||
|
|
||||||
postTools.parse(post.content, function(err, content) {
|
postTools.parsePost(post, uid, function(err, post) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
post.content = stripTags(content);
|
post.content = stripTags(post.content);
|
||||||
|
|
||||||
next(null, post);
|
next(null, post);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ SocketModules.composer.editCheck = function(socket, pid, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
SocketModules.composer.renderPreview = function(socket, content, callback) {
|
SocketModules.composer.renderPreview = function(socket, content, callback) {
|
||||||
plugins.fireHook('filter:post.parse', content, callback);
|
plugins.fireHook('filter:parse.raw', content, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketModules.composer.renderHelp = function(socket, data, callback) {
|
SocketModules.composer.renderHelp = function(socket, data, callback) {
|
||||||
@@ -83,7 +83,7 @@ SocketModules.composer.renderHelp = function(socket, data, callback) {
|
|||||||
return callback(new Error('help-hidden'));
|
return callback(new Error('help-hidden'));
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins.fireHook('filter:post.parse', helpText, function(err, helpText) {
|
plugins.fireHook('filter:parse.raw', helpText, function(err, helpText) {
|
||||||
if (!meta.config['composer:allowPluginHelp'] || meta.config['composer:allowPluginHelp'] === '1') {
|
if (!meta.config['composer:allowPluginHelp'] || meta.config['composer:allowPluginHelp'] === '1') {
|
||||||
plugins.fireHook('filter:composer.help', helpText, callback);
|
plugins.fireHook('filter:composer.help', helpText, callback);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ SocketPosts.edit = function(socket, data, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
postTools.edit(socket.uid, data.pid, data.title, data.content, {topic_thumb: data.topic_thumb, tags: data.tags}, function(err, results) {
|
postTools.edit(socket.uid, data.pid, data.title, data.content, {topic_thumb: data.topic_thumb, tags: data.tags}, function(err, results) {
|
||||||
if(err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,10 +323,9 @@ SocketPosts.flag = function(socket, pid, callback) {
|
|||||||
},
|
},
|
||||||
function(topicTitle, next) {
|
function(topicTitle, next) {
|
||||||
message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topicTitle + ']]';
|
message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topicTitle + ']]';
|
||||||
postTools.parse(post.content, next);
|
postTools.parse(post, socket.uid, next);
|
||||||
},
|
},
|
||||||
function(postContent, next) {
|
function(post, next) {
|
||||||
post.content = postContent;
|
|
||||||
groups.get('administrators', {}, next);
|
groups.get('administrators', {}, next);
|
||||||
},
|
},
|
||||||
function(adminGroup, next) {
|
function(adminGroup, next) {
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ module.exports = function(Topics) {
|
|||||||
function(next) {
|
function(next) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
userInfo: function(next) {
|
userInfo: function(next) {
|
||||||
posts.getUserInfoForPosts([postData.uid], next);
|
posts.getUserInfoForPosts([postData.uid], uid, next);
|
||||||
},
|
},
|
||||||
topicInfo: function(next) {
|
topicInfo: function(next) {
|
||||||
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid'], next);
|
Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid'], next);
|
||||||
@@ -244,14 +244,13 @@ module.exports = function(Topics) {
|
|||||||
posts.getPidIndex(postData.pid, uid, next);
|
posts.getPidIndex(postData.pid, uid, next);
|
||||||
},
|
},
|
||||||
content: function(next) {
|
content: function(next) {
|
||||||
postTools.parse(postData.content, next);
|
postTools.parsePost(postData, uid, next);
|
||||||
}
|
}
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function(results, next) {
|
function(results, next) {
|
||||||
postData.user = results.userInfo[0];
|
postData.user = results.userInfo[0];
|
||||||
postData.topic = results.topicInfo;
|
postData.topic = results.topicInfo;
|
||||||
postData.content = results.content;
|
|
||||||
|
|
||||||
if (results.settings.followTopicsOnReply) {
|
if (results.settings.followTopicsOnReply) {
|
||||||
threadTools.follow(postData.tid, uid);
|
threadTools.follow(postData.tid, uid);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ module.exports = function(Topics) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
posts.getUserInfoForPosts(uids, function(err, users) {
|
posts.getUserInfoForPosts(uids, uid, function(err, users) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user