You are here

function blogapi_blogger_new_post in Blog API 7

Same name and namespace in other branches
  1. 8 modules/blogapi_blogger/blogapi_blogger.module \blogapi_blogger_new_post()
  2. 7.2 modules/blogapi_blogger/blogapi_blogger.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 ./blogapi.module
1 string reference to 'blogapi_blogger_new_post'
blogapi_xmlrpc in ./blogapi.module
Implement hook_xmlrpc().

File

./blogapi.module, line 226
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['body'][LANGUAGE_NONE][0]['format'] = filter_default_format($user);
  $edit['status'] = $publish;

  // Check for bloggerAPI vs. metaWeblogAPI.
  if (is_array($content)) {
    $edit['title'] = $content['title'];
    $edit['body'][LANGUAGE_NONE][0]['value'] = $content['description'];
    _blogapi_mt_extra($edit, $content);
  }
  else {
    $edit['title'] = blogapi_blogger_title($content);
    $edit['body'][LANGUAGE_NONE][0]['value'] = $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(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O');
  }
  module_invoke_all('node_blogapi_new', $edit);
  $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 = (object) 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.'));
}