v1.18.x
barisusakli 9 years ago
parent b933385b76
commit 50aac3c6a4

@ -5,7 +5,8 @@ var winston = require('winston'),
module.exports = function(Plugins) { module.exports = function(Plugins) {
Plugins.deprecatedHooks = { Plugins.deprecatedHooks = {
'filter:user.custom_fields': null // remove in v1.1.0 'filter:user.custom_fields': null, // remove in v1.1.0
'filter:post.save': 'filter:post.create'
}; };
/* /*
`data` is an object consisting of (* is required): `data` is an object consisting of (* is required):

@ -52,13 +52,17 @@ module.exports = function(Posts) {
postData.ip = data.ip; postData.ip = data.ip;
} }
if (parseInt(uid, 10) === 0 && data.handle) { if (data.handle && !parseInt(uid, 10)) {
postData.handle = data.handle; postData.handle = data.handle;
} }
plugins.fireHook('filter:post.save', postData, next); plugins.fireHook('filter:post.save', postData, next);
}, },
function(postData, next) { function(postData, next) {
plugins.fireHook('filter:post.create', {post: postData, data: data}, next);
},
function(data, next) {
postData = data.post;
db.setObject('post:' + postData.pid, postData, next); db.setObject('post:' + postData.pid, postData, next);
}, },
function(next) { function(next) {

@ -1,16 +1,17 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
validator = require('validator'), var validator = require('validator');
_ = require('underscore'), var _ = require('underscore');
db = require('../database'),
topics = require('../topics'), var db = require('../database');
user = require('../user'), var topics = require('../topics');
privileges = require('../privileges'), var user = require('../user');
plugins = require('../plugins'), var privileges = require('../privileges');
cache = require('./cache'), var plugins = require('../plugins');
pubsub = require('../pubsub'), var cache = require('./cache');
utils = require('../../public/src/utils'); var pubsub = require('../pubsub');
var utils = require('../../public/src/utils');
module.exports = function(Posts) { module.exports = function(Posts) {
@ -19,7 +20,6 @@ module.exports = function(Posts) {
}); });
Posts.edit = function(data, callback) { Posts.edit = function(data, callback) {
var now = Date.now();
var postData; var postData;
var results; var results;
@ -37,23 +37,19 @@ module.exports = function(Posts) {
if (!_postData) { if (!_postData) {
return next(new Error('[[error:no-post]]')); return next(new Error('[[error:no-post]]'));
} }
postData = _postData; postData = _postData;
postData.content = data.content; postData.content = data.content;
postData.edited = now; postData.edited = Date.now();
postData.editor = data.uid; postData.editor = data.uid;
plugins.fireHook('filter:post.edit', {req: data.req, post: postData, uid: data.uid}, next); if (data.handle) {
postData.handle = data.handle;
}
plugins.fireHook('filter:post.edit', {req: data.req, post: postData, data: data, uid: data.uid}, next);
}, },
function (result, next) { function (result, next) {
postData = result.post; postData = result.post;
var updateData = { Posts.setPostFields(data.pid, postData, next);
edited: postData.edited,
editor: postData.editor,
content: postData.content
};
if (data.handle) {
updateData.handle = data.handle;
}
Posts.setPostFields(data.pid, updateData, next);
}, },
function (next) { function (next) {
async.parallel({ async.parallel({
@ -121,12 +117,14 @@ module.exports = function(Posts) {
topicData.slug = tid + '/' + (utils.slugify(title) || 'topic'); topicData.slug = tid + '/' + (utils.slugify(title) || 'topic');
} }
topicData.thumb = data.topic_thumb || ''; topicData.thumb = data.thumb || '';
data.tags = data.tags || []; data.tags = data.tags || [];
async.waterfall([ async.waterfall([
async.apply(plugins.fireHook, 'filter:topic.edit', {req: data.req, topic: topicData}), function(next) {
plugins.fireHook('filter:topic.edit', {req: data.req, topic: topicData, data: data}, next);
},
function(results, next) { function(results, next) {
db.setObject('topic:' + tid, results.topic, next); db.setObject('topic:' + tid, results.topic, next);
}, },

@ -31,16 +31,9 @@ module.exports = function(SocketPosts) {
return callback(new Error('[[error:content-too-long, ' + meta.config.maximumPostLength + ']]')); return callback(new Error('[[error:content-too-long, ' + meta.config.maximumPostLength + ']]'));
} }
posts.edit({ data.uid = socket.uid;
uid: socket.uid, data.req = websockets.reqFromSocket(socket);
handle: data.handle, posts.edit(data, function(err, result) {
pid: data.pid,
title: data.title,
content: data.content,
topic_thumb: data.topic_thumb,
tags: data.tags,
req: websockets.reqFromSocket(socket)
}, function(err, result) {
if (err) { if (err) {
return callback(err); return callback(err);
} }

@ -22,16 +22,11 @@ SocketTopics.post = function(socket, data, callback) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
topics.post({ data.uid = socket.uid;
uid: socket.uid, data.req = websockets.reqFromSocket(socket);
handle: data.handle, data.timestamp = Date.now();
title: data.title,
content: data.content, topics.post(data, function(err, result) {
cid: data.category_id,
thumb: data.topic_thumb,
tags: data.tags,
req: websockets.reqFromSocket(socket)
}, function(err, result) {
if (err) { if (err) {
return callback(err); return callback(err);
} }

@ -45,7 +45,7 @@ module.exports = function(Topics) {
topicData.thumb = data.thumb; topicData.thumb = data.thumb;
} }
plugins.fireHook('filter:topic.create', {topic: topicData}, next); plugins.fireHook('filter:topic.create', {topic: topicData, data: data}, next);
}, },
function(data, next) { function(data, next) {
topicData = data.topic; topicData = data.topic;
@ -122,10 +122,13 @@ module.exports = function(Topics) {
}, },
function(filteredData, next) { function(filteredData, next) {
data = filteredData; data = filteredData;
Topics.create({uid: data.uid, title: data.title, cid: data.cid, thumb: data.thumb, tags: data.tags, timestamp: data.timestamp}, next); Topics.create(data, next);
}, },
function(tid, next) { function(tid, next) {
posts.create({uid: data.uid, tid: tid, handle: data.handle, content: data.content, timestamp: data.timestamp, ip: data.req ? data.req.ip : null}, next); var postData = data;
postData.tid = tid;
postData.ip = data.req ? data.req.ip : null;
posts.create(postData, next);
}, },
function(postData, next) { function(postData, next) {
onNewPost(postData, data, next); onNewPost(postData, data, next);

Loading…
Cancel
Save