node_load

modules/node/node.module, line 696

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, $vid = array(), $reset = FALSE)

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.

▾ 45 functions call node_load()

batch_example_op_1 in developer/examples/batch_example.module
Batch operation for batch 1 : lode a node...
batch_example_op_2 in developer/examples/batch_example.module
Batch operation for batch 2 : load all nodes, 5 by five This is a multipart operation, using the
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_get_post_categories in modules/blogapi/blogapi.module
Blogging API callback. Returns a list of the taxonomy terms that are assigned to a particular 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().
blog_page_last in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of all users.
blog_page_user in modules/blog/blog.pages.inc
Menu callback; displays a Drupal page containing recent blog entries of a given user.
book_admin_edit_submit in modules/book/book.admin.inc
Handle submission of the book administrative page form.
book_export_html in modules/book/book.pages.inc
This function is called by book_export() to generate HTML for export.
book_export_traverse in modules/book/book.module
Traverse the book tree to build printable or exportable output.
book_form_node_delete_confirm_alter in modules/book/book.module
Form altering function for the confirm form for a single node deletion.
book_nodeapi in modules/book/book.module
Implementation of hook_nodeapi().
comment_form in modules/comment/comment.module
Generate the basic commenting form, for appending to a node or display on a separate page.
comment_form_add_preview in modules/comment/comment.module
Form builder; Generate and validate a comment preview form.
comment_form_submit in modules/comment/comment.module
Process comment form submissions; prepare the comment, store it, and set a redirection target.
comment_links in modules/comment/comment.module
Build command links for a comment (e.g.\ edit, reply, delete) with respect to the current user's access permissions.
comment_validate in modules/comment/comment.module
Validate comment data.
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_access_rebuild in modules/node/node.module
Rebuild the node access database. This is occasionally needed by modules that make system-wide changes to access levels.
node_delete in modules/node/node.module
Delete a node.
node_feed in modules/node/node.module
A generic function for generating RSS feeds from a set of nodes.
node_help in modules/node/node.module
Implementation of hook_help().
node_page_default in modules/node/node.module
Menu callback; Generate a listing of promoted nodes.
node_search in modules/node/node.module
Implementation of hook_search().
poll_block in modules/poll/poll.module
Implementation of hook_block().
poll_cancel in modules/poll/poll.module
Submit callback for poll_cancel_form
profile_block in modules/profile/profile.module
Implementation of hook_block().
statistics_node_tracker in modules/statistics/statistics.pages.inc
system_message_action in modules/system/system.module
A configurable Drupal action. Sends a message to the current user's screen.
system_send_email_action in modules/system/system.module
Implementation of a configurable Drupal action. Sends an email.
taxonomy_render_nodes in modules/taxonomy/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.
translation_nodeapi in modules/translation/translation.module
Implementation of hook_nodeapi().
translation_node_overview in modules/translation/translation.pages.inc
Overview page for a node's translations.
translation_path_get_translations in modules/translation/translation.module
Return paths of all translations of a node, based on its Drupal path.
upload_file_download in modules/upload/upload.module
Implementation of hook_file_download().
_node_access_rebuild_batch_operation in modules/node/node.module
Batch operation for node_access_rebuild_batch.
_node_index_node in modules/node/node.module
Index a single node.
_node_mass_update_helper in modules/node/node.admin.inc
Node Mass Update - helper function.
_node_revision_access in modules/node/node.module
_trigger_normalize_comment_context in modules/trigger/trigger.module
When an action is called in a context that does not match its type, the object that the action expects must be retrieved. For example, when an action that works on nodes is called during the comment hook, the node object is not available since the...
_trigger_normalize_user_context in modules/trigger/trigger.module
When an action is called in a context that does not match its type, the object that the action expects must be retrieved. For example, when an action that works on nodes is called during the user hook, the node object is not available since the user...

Code

<?php
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) {
      // Is the node statically cached?
      if (isset($nodes[$param])) {
        return is_object($nodes[$param]) ? drupal_clone($nodes[$param]) : $nodes[$param];
      }
    }
    $cond = 'n.nid = %d';
    $arguments[] = $param;
  }
  elseif (is_array($param)) {
    // Turn the conditions into a query.
    foreach ($param as $key => $value) {
      $cond[] = 'n.'. db_escape_table($key) ." = '%s'";
      $arguments[] = $value;
    }
    $cond = implode(' AND ', $cond);
  }
  else {
    return FALSE;
  }

  // Retrieve a field list based on the site's schema.
  $fields = drupal_schema_fields_sql('node', 'n');
  $fields = array_merge($fields, drupal_schema_fields_sql('node_revisions', 'r'));
  $fields = array_merge($fields, array('u.name', 'u.picture', 'u.data'));
  // Remove fields not needed in the query: n.vid and r.nid are redundant,
  // n.title is unnecessary because the node title comes from the
  // node_revisions table.  We'll keep r.vid, r.title, and n.nid.
  $fields = array_diff($fields, array('n.vid', 'n.title', 'r.nid'));
  $fields = implode(', ', $fields);
  // Rename timestamp field for clarity.
  $fields = str_replace('r.timestamp', 'r.timestamp AS revision_timestamp', $fields);
  // Change name of revision uid so it doesn't conflict with n.uid.
  $fields = str_replace('r.uid', 'r.uid AS revision_uid', $fields);

  // 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 '. $fields .' 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 '. $fields .' 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 && $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;
}
?>
 
 

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.