You are here

function node_submit in Drupal 6

Same name and namespace in other branches
  1. 4 modules/node.module \node_submit()
  2. 5 modules/node/node.module \node_submit()
  3. 7 modules/node/node.module \node_submit()

Prepares a node for saving by populating teaser, author, and creation date.

Parameters

object|array $node: A node object or array.

Return value

A validated node object with a populated teaser, author, and creation date.

3 calls to node_submit()
blogapi_blogger_edit_post in modules/blogapi/blogapi.module
Blogging API callback. Modifies the specified blog node.
blogapi_blogger_new_post in modules/blogapi/blogapi.module
Blogging API callback. Inserts a new blog post as a node.
node_form_submit_build_node in modules/node/node.pages.inc
Build a node by processing submitted form values and prepare for a form rebuild.

File

modules/node/node.module, line 833
The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.

Code

function node_submit($node) {
  global $user;

  // Convert the node to an object, if necessary.
  $node = (object) $node;

  // Generate the teaser, but only if it hasn't been set (e.g. by a
  // module-provided 'teaser' form item).
  if (!isset($node->teaser)) {
    if (isset($node->body)) {
      $node->teaser = node_teaser($node->body, isset($node->format) ? $node->format : NULL);

      // Chop off the teaser from the body if needed. The teaser_include
      // property might not be set (eg. in Blog API postings), so only act on
      // it, if it was set with a given value.
      if (isset($node->teaser_include) && !$node->teaser_include && $node->teaser == substr($node->body, 0, strlen($node->teaser))) {
        $node->body = substr($node->body, strlen($node->teaser));
      }
    }
    else {
      $node->teaser = '';
      $node->format = 0;
    }
  }
  if (user_access('administer nodes')) {

    // Populate the "authored by" field.
    if ($account = user_load(array(
      'name' => $node->name,
    ))) {
      $node->uid = $account->uid;
    }
    else {
      $node->uid = 0;
    }
  }
  $node->created = !empty($node->date) ? strtotime($node->date) : time();
  $node->validated = TRUE;
  return $node;
}