2013-05-27 19:45:33 +00:00
|
|
|
define([
|
2013-10-06 14:34:40 +00:00
|
|
|
"underscore",
|
2013-05-27 19:45:33 +00:00
|
|
|
"utils",
|
2013-06-22 23:48:57 +00:00
|
|
|
"classes/Provider",
|
2013-06-10 21:22:32 +00:00
|
|
|
"helpers/wordpressHelper"
|
2013-10-06 14:34:40 +00:00
|
|
|
], function(_, utils, Provider, wordpressHelper) {
|
2013-05-16 00:19:58 +00:00
|
|
|
|
2013-06-22 23:48:57 +00:00
|
|
|
var wordpressProvider = new Provider("wordpress", "WordPress");
|
|
|
|
wordpressProvider.defaultPublishFormat = "html";
|
|
|
|
wordpressProvider.publishPreferencesInputIds = [
|
|
|
|
"wordpress-site"
|
|
|
|
];
|
2013-05-29 19:55:23 +00:00
|
|
|
|
2014-10-12 11:14:03 +00:00
|
|
|
wordpressProvider.getPublishLocationLink = function(attributes) {
|
|
|
|
return attributes.siteId && [
|
|
|
|
'https://wordpress.com/post',
|
|
|
|
attributes.siteId,
|
|
|
|
attributes.postId
|
|
|
|
].join('/');
|
|
|
|
};
|
|
|
|
|
|
|
|
wordpressProvider.publish = function(publishAttributes, frontMatter, title, content, callback) {
|
2013-10-06 14:34:40 +00:00
|
|
|
var labelList = publishAttributes.tags || [];
|
|
|
|
if(frontMatter) {
|
|
|
|
frontMatter.tags !== undefined && (labelList = frontMatter.tags);
|
|
|
|
}
|
2013-12-08 18:05:49 +00:00
|
|
|
var status = (frontMatter && frontMatter.published === false) ? 'draft' : 'publish';
|
|
|
|
var date = frontMatter && frontMatter.date;
|
2013-10-06 14:34:40 +00:00
|
|
|
_.isString(labelList) && (labelList = _.compact(labelList.split(/[\s,]/)));
|
2014-10-12 11:14:03 +00:00
|
|
|
wordpressHelper.upload(publishAttributes.site, publishAttributes.postId, labelList.join(','), status, date, title, content, function(error, siteId, postId) {
|
2013-05-29 19:55:23 +00:00
|
|
|
if(error) {
|
2014-10-12 11:14:03 +00:00
|
|
|
return callback(error);
|
2013-05-29 19:55:23 +00:00
|
|
|
}
|
2014-10-12 11:14:03 +00:00
|
|
|
publishAttributes.siteId = siteId;
|
2013-05-29 19:55:23 +00:00
|
|
|
publishAttributes.postId = postId;
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
wordpressProvider.newPublishAttributes = function(event) {
|
|
|
|
var publishAttributes = {};
|
|
|
|
publishAttributes.site = utils.getInputTextValue("#input-publish-wordpress-site", event, /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/);
|
|
|
|
publishAttributes.postId = utils.getInputTextValue("#input-publish-postid");
|
|
|
|
if(event.isPropagationStopped()) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return publishAttributes;
|
|
|
|
};
|
|
|
|
|
|
|
|
return wordpressProvider;
|
2013-05-16 00:19:58 +00:00
|
|
|
});
|