removedu if from filter:parse,post, parse strip teaser content

v1.18.x
barisusakli 10 years ago
parent 7c9e76132d
commit b268927cf9

@ -120,7 +120,7 @@ var cache = LRU({
}, },
postData: function(next) { postData: function(next) {
cache.del(postData.pid); cache.del(postData.pid);
PostTools.parsePost(postData, data.uid, next); PostTools.parsePost(postData, next);
} }
}, function(err, results) { }, function(err, results) {
if (err) { if (err) {
@ -176,7 +176,7 @@ var cache = LRU({
if (err) { if (err) {
return callback(err); return callback(err);
} }
PostTools.parsePost(postData, uid, callback); PostTools.parsePost(postData, callback);
}); });
} }
}); });
@ -192,7 +192,7 @@ var cache = LRU({
}); });
}; };
PostTools.parsePost = function(postData, uid, callback) { PostTools.parsePost = function(postData, callback) {
postData.content = postData.content || ''; postData.content = postData.content || '';
var cachedContent = cache.get(postData.pid); var cachedContent = cache.get(postData.pid);
@ -201,7 +201,7 @@ var cache = LRU({
return callback(null, postData); return callback(null, postData);
} }
plugins.fireHook('filter:parse.post', {postData: postData, uid: uid}, function(err, data) { plugins.fireHook('filter:parse.post', {postData: postData}, function(err, data) {
if (err) { if (err) {
return callback(err); return callback(err);
} }

@ -52,7 +52,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.parsePost(postData, next);
}, function(err, posts) { }, function(err, posts) {
if (err) { if (err) {
return callback(err); return callback(err);

@ -86,7 +86,7 @@ module.exports = function(Posts) {
return next(null, post); return next(null, post);
} }
postTools.parsePost(post, uid, function(err, post) { postTools.parsePost(post, function(err, post) {
if (err) { if (err) {
return next(err); return next(err);
} }

@ -232,7 +232,7 @@ SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) {
async.parallel({ async.parallel({
username: async.apply(user.getUserField, fromuid, 'username'), username: async.apply(user.getUserField, fromuid, 'username'),
topicTitle: async.apply(topics.getTopicField, postData.tid, 'title'), topicTitle: async.apply(topics.getTopicField, postData.tid, 'title'),
postObj: async.apply(postTools.parsePost, postData, postData.uid) postObj: async.apply(postTools.parsePost, postData)
}, function(err, results) { }, function(err, results) {
if (err) { if (err) {
return; return;
@ -479,7 +479,7 @@ SocketPosts.flag = function(socket, pid, callback) {
function(topic, next) { function(topic, next) {
post.topic = topic; post.topic = topic;
message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topic.title + ']]'; message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topic.title + ']]';
postTools.parsePost(post, socket.uid, next); postTools.parsePost(post, next);
}, },
function(post, next) { function(post, next) {
async.parallel({ async.parallel({

@ -245,7 +245,7 @@ module.exports = function(Topics) {
posts.getPidIndex(postData.pid, uid, next); posts.getPidIndex(postData.pid, uid, next);
}, },
content: function(next) { content: function(next) {
postTools.parsePost(postData, uid, next); postTools.parsePost(postData, next);
} }
}, next); }, next);
}, },

@ -3,11 +3,13 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async'),
S = require('string'),
db = require('../database'), db = require('../database'),
user = require('../user'), user = require('../user'),
posts = require('../posts'), posts = require('../posts'),
plugins = require('../plugins'), plugins = require('../plugins'),
postTools = require('../postTools'),
utils = require('../../public/src/utils'); utils = require('../../public/src/utils');
@ -49,21 +51,30 @@ module.exports = function(Topics) {
users[user.uid] = user; users[user.uid] = user;
}); });
var tidToPost = {}; var tidToPost = {};
postData.forEach(function(post) {
async.each(postData, function(post, next) {
post.user = users[post.uid]; post.user = users[post.uid];
post.timestamp = utils.toISOString(post.timestamp); post.timestamp = utils.toISOString(post.timestamp);
tidToPost[post.tid] = post; tidToPost[post.tid] = post;
}); postTools.parsePost(post, next);
}, function(err) {
var teasers = topics.map(function(topic, index) { if (err) {
if (tidToPost[topic.tid]) { return callback(err);
tidToPost[topic.tid].index = counts[index];
} }
return tidToPost[topic.tid]; var teasers = topics.map(function(topic, index) {
}); if (tidToPost[topic.tid]) {
tidToPost[topic.tid].index = counts[index];
plugins.fireHook('filter:teasers.get', {teasers: teasers}, function(err, data) { if (tidToPost[topic.tid].content) {
callback(err, data ? data.teasers : null); var s = S(tidToPost[topic.tid].content);
tidToPost[topic.tid].content = s.stripTags.apply(s, utils.stripTags).s;
}
}
return tidToPost[topic.tid];
});
plugins.fireHook('filter:teasers.get', {teasers: teasers}, function(err, data) {
callback(err, data ? data.teasers : null);
});
}); });
}); });
}); });

Loading…
Cancel
Save