You are here

function node_load in Drupal 5

Same name and namespace in other branches
  1. 8 core/modules/node/node.module \node_load()
  2. 4 modules/node.module \node_load()
  3. 6 modules/node/node.module \node_load()
  4. 7 modules/node/node.module \node_load()

Load a node object from the database.

Parameters

$param: Either the nid of the node or an array of conditions to match against in the database query

$revision: Which numbered revision to load. Defaults to the current version.

$reset: Whether to reset the internal node_load cache.

Return value

A fully-populated node object.

41 calls to node_load()
blogapi_blogger_edit_post in modules/blogapi/blogapi.module
Blogging API callback. Modifies the specified blog node.
blogapi_blogger_get_post in modules/blogapi/blogapi.module
Blogging API callback. Returns a specified blog node.
blogapi_mt_publish_post in modules/blogapi/blogapi.module
Blogging API callback. Publishes the given node
blogapi_mt_set_post_categories in modules/blogapi/blogapi.module
Blogging API callback. Assigns taxonomy terms to a particular node.
blog_form in modules/blog/blog.module
Implementation of hook_form().

... See full list

File

modules/node/node.module, line 542
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_load($param = array(), $revision = NULL, $reset = NULL) {
  static $nodes = array();
  if ($reset) {
    $nodes = array();
  }
  $cachable = $revision == NULL;
  $arguments = array();
  if (is_numeric($param)) {
    if ($cachable && isset($nodes[$param])) {
      return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
    }
    $cond = 'n.nid = %d';
    $arguments[] = $param;
  }
  else {

    // Turn the conditions into a query.
    foreach ($param as $key => $value) {
      $cond[] = 'n.' . db_escape_table($key) . " = '%s'";
      $arguments[] = $value;
    }
    $cond = implode(' AND ', $cond);
  }

  // Retrieve the node.
  // No db_rewrite_sql is applied so as to get complete indexing for search.
  if ($revision) {
    array_unshift($arguments, $revision);
    $node = db_fetch_object(db_query('SELECT n.nid, r.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.nid = n.nid AND r.vid = %d WHERE ' . $cond, $arguments));
  }
  else {
    $node = db_fetch_object(db_query('SELECT n.nid, n.vid, n.type, n.status, n.created, n.changed, n.comment, n.promote, n.sticky, r.timestamp AS revision_timestamp, r.title, r.body, r.teaser, r.log, r.format, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE ' . $cond, $arguments));
  }
  if ($node->nid) {

    // Call the node specific callback (if any) and piggy-back the
    // results to the node or overwrite some values.
    if ($extra = node_invoke($node, 'load')) {
      foreach ($extra as $key => $value) {
        $node->{$key} = $value;
      }
    }
    if ($extra = node_invoke_nodeapi($node, 'load')) {
      foreach ($extra as $key => $value) {
        $node->{$key} = $value;
      }
    }
    if ($cachable) {
      $nodes[$node->nid] = is_object($node) ? drupal_clone($node) : $node;
    }
  }
  return $node;
}