Same name and namespace in other branches
  1. 4.6.x modules/blogapi.module \blogapi_blogger_new_post()
  2. 4.7.x modules/blogapi.module \blogapi_blogger_new_post()
  3. 5.x 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/blogapi.module
1 string reference to 'blogapi_blogger_new_post'
blogapi_xmlrpc in modules/blogapi/blogapi.module
Implementation of hook_xmlrpc().

File

modules/blogapi/blogapi.module, line 180
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);
  }
  if (($error = _blogapi_validate_blogid($blogid)) !== TRUE) {

    // Return an error if not configured type.
    return $error;
  }
  $edit = array();
  $edit['type'] = $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['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 this type of post.'));
  }
  if (user_access('administer nodes') && !isset($edit['date'])) {
    $edit['date'] = format_date(time(), 'custom', 'Y-m-d H:i:s O');
  }
  node_invoke_nodeapi($edit, 'blogapi new');
  $valid = blogapi_status_error_check($edit, $publish);
  if ($valid !== TRUE) {
    return $valid;
  }
  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', '@type: added %title using blog API.', array(
      '@type' => $node->type,
      '%title' => $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.'));
}