function node_preview

7.x node.pages.inc node_preview($node)
6.x node.pages.inc node_preview($node)

Generate a node preview.

1 call to node_preview()
node_form_build_preview in drupal-6.x/modules/node/node.pages.inc
5 string references to 'node_preview'
node_configure in drupal-6.x/modules/node/node.admin.inc
Menu callback; presents general node configuration options.
node_form in drupal-6.x/modules/node/node.pages.inc
Generate the node add/edit form array.
node_form_build_preview in drupal-6.x/modules/node/node.pages.inc
node_theme in drupal-6.x/modules/node/node.module
Implementation of hook_theme()
taxonomy_form_alter in drupal-6.x/modules/taxonomy/taxonomy.module
Implementation of hook_form_alter(). Generate a form for selecting terms to associate with a node. We check for taxonomy_override_selector before loading the full vocabulary, so contrib modules can intercept before hook_form_alter and provide scalable…

File

drupal-6.x/modules/node/node.pages.inc, line 368
Page callbacks for adding, editing, deleting, and revisions management for content.

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

    $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 = empty($node->body) ? '' : node_teaser($node->body, $node->format);
      // Chop off the teaser from the body if needed.
      if (!$node->teaser_include && $node->teaser == substr($node->body, 0, strlen($node->teaser))) {
        $node->body = substr($node->body, strlen($node->teaser));
      }
    }

    // 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->build_mode = NODE_BUILD_PREVIEW;
      $output = theme('node_preview', $cloned_node);
    }
    drupal_set_title(t('Preview'));

    return $output;
  }
}