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

@ -5,7 +5,8 @@ var winston = require('winston'),
module.exports = function(Plugins) {
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):

@ -52,13 +52,17 @@ module.exports = function(Posts) {
postData.ip = data.ip;
}
if (parseInt(uid, 10) === 0 && data.handle) {
if (data.handle && !parseInt(uid, 10)) {
postData.handle = data.handle;
}
plugins.fireHook('filter:post.save', 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);
},
function(next) {

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

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

@ -45,7 +45,7 @@ module.exports = function(Topics) {
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) {
topicData = data.topic;
@ -122,10 +122,13 @@ module.exports = function(Topics) {
},
function(filteredData, next) {
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) {
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) {
onNewPost(postData, data, next);

Loading…
Cancel
Save