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