From 595ff1f4b186aa90ff45a175302921527d37054c Mon Sep 17 00:00:00 2001 From: barisusakli Date: Wed, 5 Nov 2014 18:59:20 -0500 Subject: [PATCH] closes #2303 see https://community.nodebb.org/topic/3039/filter-post-parse-and-filter-post-parsesignature-changes --- src/controllers/accounts.js | 3 +-- src/messaging.js | 2 +- src/postTools.js | 36 ++++++++++++++---------------------- src/posts.js | 21 ++++++--------------- src/socket.io/modules.js | 4 ++-- src/socket.io/posts.js | 7 +++---- src/topics/create.js | 5 ++--- src/topics/posts.js | 2 +- 8 files changed, 30 insertions(+), 50 deletions(-) diff --git a/src/controllers/accounts.js b/src/controllers/accounts.js index 35e86d7f81..515dc106c4 100644 --- a/src/controllers/accounts.js +++ b/src/controllers/accounts.js @@ -173,7 +173,7 @@ accountsController.getAccount = function(req, res, next) { posts.getPostsByUid(callerUID, userData.theirid, 0, 9, next); }, signature: function(next) { - postTools.parseSignature(userData.signature, next); + postTools.parseSignature(userData, callerUID, next); } }, function(err, results) { if(err) { @@ -191,7 +191,6 @@ accountsController.getAccount = function(req, res, next) { userData.profileviews = 1; } - userData.signature = results.signature; res.render('account/profile', userData); }); }); diff --git a/src/messaging.js b/src/messaging.js index 2e1f2d7cd2..652b1c16b8 100644 --- a/src/messaging.js +++ b/src/messaging.js @@ -163,7 +163,7 @@ var db = require('./database'), } 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) { return callback(message); } diff --git a/src/postTools.js b/src/postTools.js index f9fdf52b1f..0de522ec1a 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -93,14 +93,14 @@ var winston = require('winston'), }); }); }, - content: function(next) { - PostTools.parse(postData.content, next); + postData: function(next) { + PostTools.parsePost(postData, uid, next); } }, function(err, results) { if (err) { return callback(err); } - + results.content = results.postData.content; //events.logPostEdit(uid, pid); plugins.fireHook('action:post.edit', postData); callback(null, results); @@ -137,7 +137,7 @@ var winston = require('winston'), next(); } ], function(err) { - if(err) { + if (err) { return callback(err); } @@ -149,13 +149,7 @@ var winston = require('winston'), if (err) { return callback(err); } - PostTools.parse(postData.content, function(err, parsed) { - if (err) { - return callback(err); - } - postData.content = parsed; - callback(null, postData); - }); + PostTools.parsePost(postData, uid, callback); }); } }); @@ -171,20 +165,18 @@ var winston = require('winston'), }); }; - PostTools.parse = function(raw, callback) { - parse('filter:post.parse', raw + '\n', callback); - }; + PostTools.parsePost = function(postData, uid, callback) { + postData.content = postData.content || ''; - PostTools.parseSignature = function(raw, callback) { - parse('filter:post.parseSignature', raw, callback); + plugins.fireHook('filter:parse.post', {postData: postData, uid: uid}, function(err, data) { + callback(err, data ? data.postData : null); + }); }; - function parse(hook, raw, callback) { - raw = raw || ''; + PostTools.parseSignature = function(userData, uid, callback) { + userData.signature = userData.signature || ''; - plugins.fireHook(hook, raw, function(err, parsed) { - callback(null, !err ? parsed : raw); - }); - } + plugins.fireHook('filter:parse.signature', {userData: userData, uid: uid}, callback); + }; }(exports)); diff --git a/src/posts.js b/src/posts.js index 54d01dcd30..8e0e6e3522 100644 --- a/src/posts.js +++ b/src/posts.js @@ -146,16 +146,7 @@ var async = require('async'), postData.relativeTime = utils.toISOString(postData.timestamp); postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? utils.toISOString(postData.edited) : ''; - - postTools.parse(postData.content, function(err, content) { - if(err) { - return next(err); - } - - postData.content = content; - next(null, postData); - }); - + postTools.parsePost(postData, uid, next); }, function(err, posts) { if (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({ groups: function(next) { groups.getUserGroups(uids, next); @@ -212,7 +203,7 @@ var async = require('async'), if (parseInt(meta.config.disableSignatures, 10) === 1) { return next(); } - postTools.parseSignature(userData.signature, next); + postTools.parseSignature(userData, uid, next); }, customProfileInfo: function(next) { plugins.fireHook('filter:posts.custom_profile_info', {profile: [], uid: userData.uid}, next); @@ -221,7 +212,7 @@ var async = require('async'), if (err) { return next(err); } - userData.signature = results.signature; + userData.custom_profile_info = results.customProfileInfo.profile; plugins.fireHook('filter:posts.modifyUserInfo', userData, next); @@ -335,12 +326,12 @@ var async = require('async'), return next(null, post); } - postTools.parse(post.content, function(err, content) { + postTools.parsePost(post, uid, function(err, post) { if (err) { return next(err); } - post.content = stripTags(content); + post.content = stripTags(post.content); next(null, post); }); diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js index 67f4dc9f12..c27bed191f 100644 --- a/src/socket.io/modules.js +++ b/src/socket.io/modules.js @@ -73,7 +73,7 @@ SocketModules.composer.editCheck = function(socket, pid, 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) { @@ -83,7 +83,7 @@ SocketModules.composer.renderHelp = function(socket, data, callback) { 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') { plugins.fireHook('filter:composer.help', helpText, callback); } else { diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 773bf79b45..853a9a2bf5 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -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) { - if(err) { + if (err) { return callback(err); } @@ -323,10 +323,9 @@ SocketPosts.flag = function(socket, pid, callback) { }, function(topicTitle, next) { message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topicTitle + ']]'; - postTools.parse(post.content, next); + postTools.parse(post, socket.uid, next); }, - function(postContent, next) { - post.content = postContent; + function(post, next) { groups.get('administrators', {}, next); }, function(adminGroup, next) { diff --git a/src/topics/create.js b/src/topics/create.js index 395d6fcfdf..f03aebb7b7 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -232,7 +232,7 @@ module.exports = function(Topics) { function(next) { async.parallel({ userInfo: function(next) { - posts.getUserInfoForPosts([postData.uid], next); + posts.getUserInfoForPosts([postData.uid], uid, next); }, topicInfo: function(next) { Topics.getTopicFields(tid, ['tid', 'title', 'slug', 'cid'], next); @@ -244,14 +244,13 @@ module.exports = function(Topics) { posts.getPidIndex(postData.pid, uid, next); }, content: function(next) { - postTools.parse(postData.content, next); + postTools.parsePost(postData, uid, next); } }, next); }, function(results, next) { postData.user = results.userInfo[0]; postData.topic = results.topicInfo; - postData.content = results.content; if (results.settings.followTopicsOnReply) { threadTools.follow(postData.tid, uid); diff --git a/src/topics/posts.js b/src/topics/posts.js index 67ceefe4c2..8c18ad7d7a 100644 --- a/src/topics/posts.js +++ b/src/topics/posts.js @@ -68,7 +68,7 @@ module.exports = function(Topics) { } } - posts.getUserInfoForPosts(uids, function(err, users) { + posts.getUserInfoForPosts(uids, uid, function(err, users) { if (err) { return next(err); }