blogapi_blogger_new_post

Versions
4.6 – 6
blogapi_blogger_new_post($appkey, $blogid, $username, $password, $content, $publish)

Blogging API callback. Inserts a new blog post as a node.

Code

modules/blogapi.module, line 176

<?php
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;
  }

  $node = node_validate($edit);

  if ($errors = form_get_errors()) {
    return blogapi_error(implode("\n", $errors));
  }

  if (!node_access('create', $node)) {
    return blogapi_error(message_access());
  }

  $nid = node_save($node);
  if ($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/$nid"));
    // blogger.newPost returns a string
    return "$nid";
  }

  return blogapi_error(t('Error storing post.'));
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.