|
|
@ -18,21 +18,22 @@ var winston = require('winston'),
|
|
|
|
|
|
|
|
|
|
|
|
(function(PostTools) {
|
|
|
|
(function(PostTools) {
|
|
|
|
|
|
|
|
|
|
|
|
PostTools.edit = function(uid, pid, title, content, options, callback) {
|
|
|
|
PostTools.edit = function(data, callback) {
|
|
|
|
options = options || {};
|
|
|
|
var options = data.options || {},
|
|
|
|
|
|
|
|
title = data.title.trim();
|
|
|
|
|
|
|
|
|
|
|
|
async.waterfall([
|
|
|
|
async.waterfall([
|
|
|
|
function (next) {
|
|
|
|
function (next) {
|
|
|
|
privileges.posts.canEdit(pid, uid, next);
|
|
|
|
privileges.posts.canEdit(data.pid, data.uid, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(canEdit, next) {
|
|
|
|
function(canEdit, next) {
|
|
|
|
if (!canEdit) {
|
|
|
|
if (!canEdit) {
|
|
|
|
return next(new Error('[[error:no-privileges]]'));
|
|
|
|
return next(new Error('[[error:no-privileges]]'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
posts.getPostData(pid, next);
|
|
|
|
posts.getPostData(data.pid, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function(postData, next) {
|
|
|
|
function(postData, next) {
|
|
|
|
postData.content = content;
|
|
|
|
postData.content = data.content;
|
|
|
|
plugins.fireHook('filter:post.save', postData, next);
|
|
|
|
plugins.fireHook('filter:post.save', postData, next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
], function(err, postData) {
|
|
|
|
], function(err, postData) {
|
|
|
@ -42,15 +43,15 @@ var winston = require('winston'),
|
|
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
async.parallel({
|
|
|
|
post: function(next) {
|
|
|
|
post: function(next) {
|
|
|
|
posts.setPostFields(pid, {
|
|
|
|
posts.setPostFields(data.pid, {
|
|
|
|
edited: Date.now(),
|
|
|
|
edited: Date.now(),
|
|
|
|
editor: uid,
|
|
|
|
editor: data.uid,
|
|
|
|
content: postData.content
|
|
|
|
content: postData.content
|
|
|
|
}, next);
|
|
|
|
}, next);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
topic: function(next) {
|
|
|
|
topic: function(next) {
|
|
|
|
var tid = postData.tid;
|
|
|
|
var tid = postData.tid;
|
|
|
|
posts.isMain(pid, function(err, isMainPost) {
|
|
|
|
posts.isMain(data.pid, function(err, isMainPost) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|
return next(err);
|
|
|
|
return next(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -64,11 +65,9 @@ var winston = require('winston'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
title = title.trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var topicData = {
|
|
|
|
var topicData = {
|
|
|
|
tid: tid,
|
|
|
|
tid: tid,
|
|
|
|
mainPid: pid,
|
|
|
|
mainPid: data.pid,
|
|
|
|
title: title,
|
|
|
|
title: title,
|
|
|
|
slug: tid + '/' + utils.slugify(title)
|
|
|
|
slug: tid + '/' + utils.slugify(title)
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -96,7 +95,7 @@ var winston = require('winston'),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
postData: function(next) {
|
|
|
|
postData: function(next) {
|
|
|
|
PostTools.parsePost(postData, uid, next);
|
|
|
|
PostTools.parsePost(postData, data.uid, next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, function(err, results) {
|
|
|
|
}, function(err, results) {
|
|
|
|
if (err) {
|
|
|
|
if (err) {
|
|
|
|