function blogapi_edit_post in Blog API 7.2
Service allback for metaWeblog.editPost
4 calls to blogapi_edit_post()
- blogapi_blogger_edit_post in modules/
blogapi_blogger/ blogapi_blogger.module - Service callback for blogger.editPost
- blogapi_metaweblog_edit_post in modules/
blogapi_metaweblog/ blogapi_metaweblog.module - Service allback for metaWeblog.editPost
- blogapi_movabletype_publish_post in modules/
blogapi_movabletype/ blogapi_movabletype.module - Service callback for mt.publishPost
- blogapi_movabletype_set_post_categories in modules/
blogapi_movabletype/ blogapi_movabletype.module - Service callback for mt.setPostCategories @TODO rewrite this callback, because I'm afraid it's too complicated now :(
File
- ./
blogapi.module, line 434 - Enable users to post using applications that support BlogAPIs.
Code
function blogapi_edit_post($postid, $username, $password, $content, $publish = 1) {
// Validate the user.
$user = blogapi_validate_user($username, $password);
$old_node = node_load($postid);
$new_node = new stdClass();
if (!$old_node) {
return services_error(t('Node @nid not found', array(
'@nid' => $postid,
)), 404);
}
if (!node_access('update', $old_node, $user)) {
return services_error(t('You do not have permission to update this post.'), 403);
}
// Save the original status for validation of permissions.
$new_node->status = $publish;
$new_node->type = $old_node->type;
$xmlrpc = xmlrpc_server_get();
$api = $xmlrpc->message->methodname;
$type = explode(".", $api);
$apiType = $type[0];
// $content can be empty sometimes, in mt.publishPost for example
if (!empty($content)) {
// Let the teaser be re-generated.
unset($old_node->teaser);
if (is_string($content) || !empty($content['title'])) {
$new_node->title = is_string($content) ? blogapi_blogger_extract_title($content) : $content['title'];
}
if (is_string($content) || !empty($content['description'])) {
$lang = $old_node->language;
if ($apiType === "metaWeblog" || $apiType === "movabletype") {
$new_node->body[$lang][0]['value'] = is_string($content) ? blogapi_blogger_extract_body($content) : $content['description'];
}
else {
$new_node->body[LANGUAGE_NONE][0]['value'] = is_string($content) ? blogapi_blogger_extract_body($content) : $content['description'];
}
}
if (empty($content['date']) && user_access('administer nodes')) {
$new_node->date = format_date($old_node->created, 'custom', 'Y-m-d H:i:s O');
}
if (!empty($content['taxonomies'])) {
foreach ($content['taxonomies'] as $field_name => $field) {
$new_node->{$field_name} = $field;
}
}
if (function_exists('_blogapi_mt_extra') && is_array($content)) {
_blogapi_mt_extra($new_node, $content);
}
}
return blogapi_submit_node($new_node, $old_node);
}