node_load

Versions
4.6
node_load($conditions, $revision = NULL, $reset = NULL)
4.7 – 6
node_load($param = array(), $revision = NULL, $reset = NULL)
7
node_load($nid = NULL, $vid = NULL, $reset = FALSE)

Load a node object from the database.

Parameters

$conditions An array of conditions to match against in the database query. Most calls will simply use array('nid' => 52).

$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.

▾ 44 functions call node_load()

archive_page in modules/archive.module
Menu callback; lists all nodes posted on a given date.
block_list in modules/block.module
Return all blocks in the specied region for the current user. You may
blogapi_blogger_edit_post in modules/blogapi.module
Blogging API callback. Modifies the specified blog node.
blogapi_blogger_get_post in modules/blogapi.module
Blogging API callback. Returns a specified blog node.
blogap_mti_publish_post in modules/blogapi.module
Blogging API callback. Publishes the given node
blog_form in modules/blog.module
Implementation of hook_form().
blog_page_last in modules/blog.module
Displays a Drupal page containing recent blog entries of all users.
blog_page_user in modules/blog.module
Displays a Drupal page containing recent blog entries of a given user.
book_admin_save in modules/book.module
book_admin_view in modules/book.module
Display an administrative view of the hierarchy of a book.
book_admin_view_book in modules/book.module
book_outline in modules/book.module
Implementation of function book_outline() Handles all book outline operations.
book_print in modules/book.module
Menu callback; generates printer-friendly book page with all descendants.
book_print_recurse in modules/book.module
book_render in modules/book.module
Menu callback; prints a listing of all books.
comment_menu in modules/comment.module
Implementation of hook_menu().
comment_moderate in modules/comment.module
comment_preview in modules/comment.module
comment_reply in modules/comment.module
hook_search in developer/hooks/core.php
Define a custom search routine.
hook_update_index in developer/hooks/core.php
Update Drupal's full-text index for this module.
node_delete in modules/node.module
Ask for confirmation, and delete the node.
node_edit in modules/node.module
Present a node editing form.
node_feed in modules/node.module
A generic function for generating RSS feeds from a set of nodes.
node_menu in modules/node.module
Implementation of hook_menu().
node_page in modules/node.module
Menu callback; dispatches control to the appropriate operation handler.
node_page_default in modules/node.module
Generate a listing of promoted nodes.
node_revision_create in modules/node.module
Create and return a new revision of the given node.
node_revision_delete in modules/node.module
Delete the revision with specified revision number.
node_revision_overview in modules/node.module
Generate an overview table of older revisions of a node.
node_revision_rollback in modules/node.module
Roll back to the revision with the specified revision number.
node_search in modules/node.module
Implementation of hook_search().
node_update_index in modules/node.module
Implementation of hook_update_index().
poll_block in modules/poll.module
Implementation of hook_block().
poll_menu in modules/poll.module
Implementation of hook_menu().
poll_results in modules/poll.module
Callback for the 'results' tab for polls you can vote on
poll_vote in modules/poll.module
Callback for processing a vote
queue_block in modules/queue.module
Implementation of hook_block().
queue_view in modules/queue.module
Display a queued node along with voting options for it.
queue_vote in modules/queue.module
statistics_node_tracker in modules/statistics.module
taxonomy_render_nodes in modules/taxonomy.module
Accepts the result of a pager_query() call, such as that performed by taxonomy_select_nodes(), and formats each node along with a pager.
upload_file_download in modules/upload.module
_comment_update_node_statistics in modules/comment.module
Updates the comment statistics for a given node. This should be called any time a comment is added, deleted, or updated.

Code

modules/node.module, line 343

<?php
function node_load($conditions, $revision = NULL, $reset = NULL) {
  static $nodes = array();

  if ($reset) {
    $nodes = array();
  }

  $cachable = (count($conditions) == 1 && isset($conditions['nid']) && $revision == NULL);

  if ($cachable && isset($nodes[$conditions['nid']])) {
    return $nodes[$conditions['nid']];
  }

  // Turn the conditions into a query.
  foreach ($conditions as $key => $value) {
    $cond[] = 'n.'. db_escape_string($key) ." = '". db_escape_string($value) ."'";
  }

  // Retrieve the node.
  $node = db_fetch_object(db_query(db_rewrite_sql('SELECT n.*, u.uid, u.name, u.picture, u.data FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE '. implode(' AND ', $cond))));
  $node = drupal_unpack($node);

  // Unserialize the revisions and user data fields.
  if ($node->revisions) {
    $node->revisions = unserialize($node->revisions);
  }

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

  // Return the desired revision.
  if (!is_null($revision) && is_array($node->revisions[$revision])) {
   $node = $node->revisions[$revision]['node'];
  }

  if ($cachable) {
    $nodes[$conditions['nid']] = $node;
  }

  return $node;
}
?>
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.