You are here

function node_preview in Drupal 4

Same name and namespace in other branches
  1. 5 modules/node/node.module \node_preview()
  2. 6 modules/node/node.pages.inc \node_preview()
  3. 7 modules/node/node.pages.inc \node_preview()

Generate a node preview.

1 call to node_preview()
node_form_add_preview in modules/node.module
2 string references to 'node_preview'
node_configure in modules/node.module
Menu callback; presents general node configuration options.
node_form_add_preview in modules/node.module

File

modules/node.module, line 1828
The core that allows content to be submitted to the site.

Code

function node_preview($node) {
  if (node_access('create', $node) || node_access('update', $node)) {

    // Load the user's name when needed:
    if (isset($node->name)) {

      // The use of isset() is mandatory in the context of user IDs, because
      // user ID 0 denotes the anonymous user.
      if ($user = user_load(array(
        'name' => $node->name,
      ))) {
        $node->uid = $user->uid;
        $node->picture = $user->picture;
      }
      else {
        $node->uid = 0;

        // anonymous user
      }
    }
    else {
      if ($node->uid) {
        $user = user_load(array(
          'uid' => $node->uid,
        ));
        $node->name = $user->name;
        $node->picture = $user->picture;
      }
    }

    // Set the timestamps when needed:
    if ($node->date) {
      $node->created = strtotime($node->date);
    }
    $node->changed = time();

    // Extract a teaser, if it hasn't been set (e.g. by a module-provided
    // 'teaser' form item).
    if (!isset($node->teaser)) {
      $node->teaser = node_teaser($node->body, $node->format);
    }

    // Display a preview of the node:
    // Previewing alters $node so it needs to be cloned.
    if (!form_get_errors()) {
      $cloned_node = drupal_clone($node);
      $cloned_node->in_preview = TRUE;
      $output = theme('node_preview', $cloned_node);
    }
    drupal_set_title(t('Preview'));
    drupal_set_breadcrumb(array(
      l(t('Home'), NULL),
      l(t('create content'), 'node/add'),
      l(t('Submit %name', array(
        '%name' => node_get_name($node),
      )), 'node/add/' . $node->type),
    ));
    return $output;
  }
}