function blogapi_blogger_new_post in Drupal 4
Same name and namespace in other branches
- 5 modules/blogapi/blogapi.module \blogapi_blogger_new_post()
- 6 modules/blogapi/blogapi.module \blogapi_blogger_new_post()
Blogging API callback. Inserts a new blog post as a node.
1 call to blogapi_blogger_new_post()
- blogapi_metaweblog_new_post in modules/
blogapi.module
1 string reference to 'blogapi_blogger_new_post'
- blogapi_xmlrpc in modules/
blogapi.module - Implementation of hook_xmlrpc().
File
- modules/
blogapi.module, line 186 - Enable users to post using applications that support XML-RPC blog APIs.
Code
function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $content, $publish) {
$user = blogapi_validate_user($username, $password);
if (!$user->uid) {
return blogapi_error($user);
}
$edit = array();
$edit['type'] = _blogapi_blogid($blogid);
// get the node type defaults
$node_type_default = variable_get('node_options_' . $edit['type'], array(
'status',
'promote',
));
$edit['uid'] = $user->uid;
$edit['name'] = $user->name;
$edit['promote'] = in_array('promote', $node_type_default);
$edit['comment'] = variable_get('comment_' . $edit['type'], 2);
$edit['moderate'] = in_array('moderate', $node_type_default);
$edit['revision'] = in_array('revision', $node_type_default);
$edit['format'] = FILTER_FORMAT_DEFAULT;
$edit['status'] = $publish;
// check for bloggerAPI vs. metaWeblogAPI
if (is_array($content)) {
$edit['title'] = $content['title'];
$edit['body'] = $content['description'];
_blogapi_mt_extra($edit, $content);
}
else {
$edit['title'] = blogapi_blogger_title($content);
$edit['body'] = $content;
}
if (!node_access('create', $edit['type'])) {
return blogapi_error(t('You do not have permission to create the type of post you wanted to create.'));
}
if (user_access('administer nodes') && !isset($edit['date'])) {
$edit['date'] = format_date(time(), 'custom', 'Y-m-d H:i:s O');
}
node_validate($edit);
if ($errors = form_get_errors()) {
return blogapi_error(implode("\n", $errors));
}
$node = node_submit($edit);
node_save($node);
if ($node->nid) {
watchdog('content', t('%type: added %title using blog API.', array(
'%type' => '<em>' . t($node->type) . '</em>',
'%title' => theme('placeholder', $node->title),
)), WATCHDOG_NOTICE, l(t('view'), "node/{$node->nid}"));
// blogger.newPost returns a string so we cast the nid to a string by putting it in double quotes:
return "{$node->nid}";
}
return blogapi_error(t('Error storing post.'));
}