- Patch #25634 by chx: simplified node_load().

4.7.x
Dries Buytaert 2005-07-17 18:29:32 +00:00
parent ed3bf725bb
commit 160a1e0ef8
19 changed files with 110 additions and 102 deletions

View File

@ -21,6 +21,8 @@ Drupal x.x.x, xxxx-xx-xx (development version)
- book module: - book module:
* added Docbook-like XML export functionality. * added Docbook-like XML export functionality.
* added OPML export functionality. * added OPML export functionality.
- XML-RPC:
* replaced the XML-RCP library by a better one.
- performance: - performance:
* added 'loose caching' option for high-traffic sites. * added 'loose caching' option for high-traffic sites.
* improved performance of path aliasing. * improved performance of path aliasing.

View File

@ -246,7 +246,7 @@ function archive_page($year = 0, $month = 0, $day = 0) {
$result = db_query_range($sql, $date, $date_end, 0, 20); $result = db_query_range($sql, $date, $date_end, 0, 20);
while ($nid = db_fetch_object($result)) { while ($nid = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $nid->nid)), 1); $output .= node_view(node_load($nid->nid), 1);
} }
} }
return $output; return $output;

View File

@ -246,7 +246,7 @@ function archive_page($year = 0, $month = 0, $day = 0) {
$result = db_query_range($sql, $date, $date_end, 0, 20); $result = db_query_range($sql, $date, $date_end, 0, 20);
while ($nid = db_fetch_object($result)) { while ($nid = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $nid->nid)), 1); $output .= node_view(node_load($nid->nid), 1);
} }
} }
return $output; return $output;

View File

@ -143,7 +143,7 @@ function blog_page_user($uid) {
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid); $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid);
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1); $output .= node_view(node_load($node->nid), 1);
} }
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
$output .= theme('xml_icon', url("blog/$account->uid/feed")); $output .= theme('xml_icon', url("blog/$account->uid/feed"));
@ -170,7 +170,7 @@ function blog_page_last() {
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10)); $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1); $output .= node_view(node_load($node->nid), 1);
} }
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
$output .= theme('xml_icon', url('blog/feed')); $output .= theme('xml_icon', url('blog/feed'));
@ -195,7 +195,7 @@ function blog_form(&$node) {
** database and quote it in the blog: ** database and quote it in the blog:
*/ */
if ($nid && $blog = node_load(array('nid' => $nid))) { if ($nid && $blog = node_load($nid)) {
$node->body = '<em>'. $blog->body .'</em> ['. l($blog->name, "node/$nid") .']'; $node->body = '<em>'. $blog->body .'</em> ['. l($blog->name, "node/$nid") .']';
} }

View File

@ -143,7 +143,7 @@ function blog_page_user($uid) {
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid); $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE type = 'blog' AND n.uid = %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10), 0, NULL, $account->uid);
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1); $output .= node_view(node_load($node->nid), 1);
} }
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
$output .= theme('xml_icon', url("blog/$account->uid/feed")); $output .= theme('xml_icon', url("blog/$account->uid/feed"));
@ -170,7 +170,7 @@ function blog_page_last() {
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10)); $result = pager_query(db_rewrite_sql("SELECT n.nid, n.created FROM {node} n WHERE n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"), variable_get('default_nodes_main', 10));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1); $output .= node_view(node_load($node->nid), 1);
} }
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
$output .= theme('xml_icon', url('blog/feed')); $output .= theme('xml_icon', url('blog/feed'));
@ -195,7 +195,7 @@ function blog_form(&$node) {
** database and quote it in the blog: ** database and quote it in the blog:
*/ */
if ($nid && $blog = node_load(array('nid' => $nid))) { if ($nid && $blog = node_load($nid)) {
$node->body = '<em>'. $blog->body .'</em> ['. l($blog->name, "node/$nid") .']'; $node->body = '<em>'. $blog->body .'</em> ['. l($blog->name, "node/$nid") .']';
} }

View File

@ -233,7 +233,7 @@ function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $cont
return blogapi_error($user); return blogapi_error($user);
} }
$node = node_load(array('nid' => $postid)); $node = node_load('nid' => $postid);
if (!$node) { if (!$node) {
return blogapi_error(message_na()); return blogapi_error(message_na());
} }
@ -330,7 +330,7 @@ function blogapi_metaweblog_get_post($postid, $username, $password) {
return blogapi_error($user); return blogapi_error($user);
} }
$node = node_load(array('nid' => $postid)); $node = node_load('nid' => $postid);
return _blogapi_get_post($node, true); return _blogapi_get_post($node, true);
} }
@ -469,7 +469,7 @@ function blogap_mti_publish_post($postid, $username, $password) {
if (!$user->uid) { if (!$user->uid) {
return blogapi_error($user); return blogapi_error($user);
} }
$node = node_load(array('nid' => $postid)); $node = node_load('nid' => $postid);
if (!$node) { if (!$node) {
return blogapi_error(t('Invalid post.')); return blogapi_error(t('Invalid post.'));
} }

View File

@ -233,7 +233,7 @@ function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $cont
return blogapi_error($user); return blogapi_error($user);
} }
$node = node_load(array('nid' => $postid)); $node = node_load('nid' => $postid);
if (!$node) { if (!$node) {
return blogapi_error(message_na()); return blogapi_error(message_na());
} }
@ -330,7 +330,7 @@ function blogapi_metaweblog_get_post($postid, $username, $password) {
return blogapi_error($user); return blogapi_error($user);
} }
$node = node_load(array('nid' => $postid)); $node = node_load('nid' => $postid);
return _blogapi_get_post($node, true); return _blogapi_get_post($node, true);
} }
@ -469,7 +469,7 @@ function blogap_mti_publish_post($postid, $username, $password) {
if (!$user->uid) { if (!$user->uid) {
return blogapi_error($user); return blogapi_error($user);
} }
$node = node_load(array('nid' => $postid)); $node = node_load('nid' => $postid);
if (!$node) { if (!$node) {
return blogapi_error(t('Invalid post.')); return blogapi_error(t('Invalid post.'));
} }

View File

@ -255,7 +255,7 @@ function book_outline() {
$op = $_POST['op']; $op = $_POST['op'];
$edit = $_POST['edit']; $edit = $_POST['edit'];
$node = node_load(array('nid' => arg(1))); $node = node_load(arg(1));
if ($node->nid) { if ($node->nid) {
switch ($op) { switch ($op) {
@ -759,7 +759,7 @@ function book_recurse($nid = 0, $depth = 1, $visit_pre, $visit_post) {
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $nid); $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $nid);
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// Load the node: // Load the node:
$node = node_load(array('nid' => $page->nid)); $node = node_load($page->nid);
// Take the most recent approved revision: // Take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
@ -776,7 +776,7 @@ function book_recurse($nid = 0, $depth = 1, $visit_pre, $visit_post) {
$children = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $node->nid); $children = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $node->nid);
while ($childpage = db_fetch_object($children)) { while ($childpage = db_fetch_object($children)) {
$childnode = node_load(array('nid' => $childpage->nid)); $childnode = node_load($childpage->nid);
if ($childnode->nid != $node->nid) { if ($childnode->nid != $node->nid) {
$output .= book_recurse($childnode->nid, $depth+1, $visit_pre, $visit_post); $output .= book_recurse($childnode->nid, $depth+1, $visit_pre, $visit_post);
} }
@ -969,7 +969,7 @@ function book_admin_edit_book($nid, $depth = 1) {
$rows = array(); $rows = array();
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$node = node_load(array('nid' => $node->nid)); $node = node_load($node->nid);
$rows[] = book_admin_edit_line($node, $depth); $rows[] = book_admin_edit_line($node, $depth);
$rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1)); $rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1));
} }
@ -981,7 +981,7 @@ function book_admin_edit_book($nid, $depth = 1) {
* Display an administrative view of the hierarchy of a book. * Display an administrative view of the hierarchy of a book.
*/ */
function book_admin_edit($nid, $depth = 0) { function book_admin_edit($nid, $depth = 0) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
if ($node->nid) { if ($node->nid) {
$header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3')); $header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
$rows[] = book_admin_edit_line($node); $rows[] = book_admin_edit_line($node);
@ -1003,7 +1003,7 @@ function book_admin_edit($nid, $depth = 0) {
*/ */
function book_admin_save($nid, $edit = array()) { function book_admin_save($nid, $edit = array()) {
if ($nid) { if ($nid) {
$book = node_load(array('nid' => $nid)); $book = node_load($nid);
foreach ($edit as $nid => $value) { foreach ($edit as $nid => $value) {
// Check to see whether the title needs updating: // Check to see whether the title needs updating:

View File

@ -255,7 +255,7 @@ function book_outline() {
$op = $_POST['op']; $op = $_POST['op'];
$edit = $_POST['edit']; $edit = $_POST['edit'];
$node = node_load(array('nid' => arg(1))); $node = node_load(arg(1));
if ($node->nid) { if ($node->nid) {
switch ($op) { switch ($op) {
@ -759,7 +759,7 @@ function book_recurse($nid = 0, $depth = 1, $visit_pre, $visit_post) {
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $nid); $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $nid);
while ($page = db_fetch_object($result)) { while ($page = db_fetch_object($result)) {
// Load the node: // Load the node:
$node = node_load(array('nid' => $page->nid)); $node = node_load($page->nid);
// Take the most recent approved revision: // Take the most recent approved revision:
if ($node->moderate) { if ($node->moderate) {
@ -776,7 +776,7 @@ function book_recurse($nid = 0, $depth = 1, $visit_pre, $visit_post) {
$children = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $node->nid); $children = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = %d AND n.moderate = 0 ORDER BY b.weight, n.title'), $node->nid);
while ($childpage = db_fetch_object($children)) { while ($childpage = db_fetch_object($children)) {
$childnode = node_load(array('nid' => $childpage->nid)); $childnode = node_load($childpage->nid);
if ($childnode->nid != $node->nid) { if ($childnode->nid != $node->nid) {
$output .= book_recurse($childnode->nid, $depth+1, $visit_pre, $visit_post); $output .= book_recurse($childnode->nid, $depth+1, $visit_pre, $visit_post);
} }
@ -969,7 +969,7 @@ function book_admin_edit_book($nid, $depth = 1) {
$rows = array(); $rows = array();
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$node = node_load(array('nid' => $node->nid)); $node = node_load($node->nid);
$rows[] = book_admin_edit_line($node, $depth); $rows[] = book_admin_edit_line($node, $depth);
$rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1)); $rows = array_merge($rows, book_admin_edit_book($node->nid, $depth + 1));
} }
@ -981,7 +981,7 @@ function book_admin_edit_book($nid, $depth = 1) {
* Display an administrative view of the hierarchy of a book. * Display an administrative view of the hierarchy of a book.
*/ */
function book_admin_edit($nid, $depth = 0) { function book_admin_edit($nid, $depth = 0) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
if ($node->nid) { if ($node->nid) {
$header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3')); $header = array(t('Title'), t('Weight'), array('data' => t('Operations'), 'colspan' => '3'));
$rows[] = book_admin_edit_line($node); $rows[] = book_admin_edit_line($node);
@ -1003,7 +1003,7 @@ function book_admin_edit($nid, $depth = 0) {
*/ */
function book_admin_save($nid, $edit = array()) { function book_admin_save($nid, $edit = array()) {
if ($nid) { if ($nid) {
$book = node_load(array('nid' => $nid)); $book = node_load($nid);
foreach ($edit as $nid => $value) { foreach ($edit as $nid => $value) {
// Check to see whether the title needs updating: // Check to see whether the title needs updating:

View File

@ -136,7 +136,7 @@ function comment_menu($may_cache) {
} }
else { else {
if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) { if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
$node = node_load(array('nid' => arg(2))); $node = node_load(arg(2));
if ($node->nid) { if ($node->nid) {
$items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'), $items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'),
'callback' => 'comment_reply', 'access' => node_access('view', $node), 'type' => MENU_CALLBACK); 'callback' => 'comment_reply', 'access' => node_access('view', $node), 'type' => MENU_CALLBACK);
@ -376,7 +376,7 @@ function comment_edit($cid) {
function comment_reply($nid, $pid = NULL) { function comment_reply($nid, $pid = NULL) {
// set the breadcrumb trail // set the breadcrumb trail
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
menu_set_location(array(array('path' => "node/$nid", 'title' => $node->title), array('path' => "comment/reply/$nid"))); menu_set_location(array(array('path' => "node/$nid", 'title' => $node->title), array('path' => "comment/reply/$nid")));
$output = ''; $output = '';
@ -514,7 +514,7 @@ function comment_preview($edit) {
$output .= theme('comment_view', $comment); $output .= theme('comment_view', $comment);
} }
else { else {
$output .= node_view(node_load(array('nid' => $edit['nid']))); $output .= node_view(node_load($edit['nid']));
$edit['pid'] = 0; $edit['pid'] = 0;
} }
@ -1260,7 +1260,7 @@ function comment_moderate() {
$votes[$mod->mid] = $mod->value; $votes[$mod->mid] = $mod->value;
} }
$node = node_load(array('nid' => db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', key($moderation))))); $node = node_load(db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', key($moderation))));
if (user_access('administer comments') || comment_user_can_moderate($node)) { if (user_access('administer comments') || comment_user_can_moderate($node)) {
foreach ($moderation as $cid => $vote) { foreach ($moderation as $cid => $vote) {
@ -1668,7 +1668,7 @@ function _comment_update_node_statistics($nid) {
// comments exist // comments exist
if ($count > 0) { if ($count > 0) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
$last_reply = db_fetch_object(db_query_range('SELECT cid, name, timestamp, uid FROM {comments} WHERE nid = %d AND status = %d ORDER BY cid DESC', $nid, COMMENT_PUBLISHED, 0, 1)); $last_reply = db_fetch_object(db_query_range('SELECT cid, name, timestamp, uid FROM {comments} WHERE nid = %d AND status = %d ORDER BY cid DESC', $nid, COMMENT_PUBLISHED, 0, 1));
db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $last_reply->timestamp, $last_reply->uid ? NULL : $last_reply->name, $last_reply->uid, $nid); db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $last_reply->timestamp, $last_reply->uid ? NULL : $last_reply->name, $last_reply->uid, $nid);
} }

View File

@ -136,7 +136,7 @@ function comment_menu($may_cache) {
} }
else { else {
if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) { if (arg(0) == 'comment' && arg(1) == 'reply' && is_numeric(arg(2))) {
$node = node_load(array('nid' => arg(2))); $node = node_load(arg(2));
if ($node->nid) { if ($node->nid) {
$items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'), $items[] = array('path' => 'comment/reply', 'title' => t('reply to comment'),
'callback' => 'comment_reply', 'access' => node_access('view', $node), 'type' => MENU_CALLBACK); 'callback' => 'comment_reply', 'access' => node_access('view', $node), 'type' => MENU_CALLBACK);
@ -376,7 +376,7 @@ function comment_edit($cid) {
function comment_reply($nid, $pid = NULL) { function comment_reply($nid, $pid = NULL) {
// set the breadcrumb trail // set the breadcrumb trail
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
menu_set_location(array(array('path' => "node/$nid", 'title' => $node->title), array('path' => "comment/reply/$nid"))); menu_set_location(array(array('path' => "node/$nid", 'title' => $node->title), array('path' => "comment/reply/$nid")));
$output = ''; $output = '';
@ -514,7 +514,7 @@ function comment_preview($edit) {
$output .= theme('comment_view', $comment); $output .= theme('comment_view', $comment);
} }
else { else {
$output .= node_view(node_load(array('nid' => $edit['nid']))); $output .= node_view(node_load($edit['nid']));
$edit['pid'] = 0; $edit['pid'] = 0;
} }
@ -1260,7 +1260,7 @@ function comment_moderate() {
$votes[$mod->mid] = $mod->value; $votes[$mod->mid] = $mod->value;
} }
$node = node_load(array('nid' => db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', key($moderation))))); $node = node_load(db_result(db_query('SELECT nid FROM {comments} WHERE cid = %d', key($moderation))));
if (user_access('administer comments') || comment_user_can_moderate($node)) { if (user_access('administer comments') || comment_user_can_moderate($node)) {
foreach ($moderation as $cid => $vote) { foreach ($moderation as $cid => $vote) {
@ -1668,7 +1668,7 @@ function _comment_update_node_statistics($nid) {
// comments exist // comments exist
if ($count > 0) { if ($count > 0) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
$last_reply = db_fetch_object(db_query_range('SELECT cid, name, timestamp, uid FROM {comments} WHERE nid = %d AND status = %d ORDER BY cid DESC', $nid, COMMENT_PUBLISHED, 0, 1)); $last_reply = db_fetch_object(db_query_range('SELECT cid, name, timestamp, uid FROM {comments} WHERE nid = %d AND status = %d ORDER BY cid DESC', $nid, COMMENT_PUBLISHED, 0, 1));
db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $last_reply->timestamp, $last_reply->uid ? NULL : $last_reply->name, $last_reply->uid, $nid); db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $last_reply->timestamp, $last_reply->uid ? NULL : $last_reply->name, $last_reply->uid, $nid);
} }

View File

@ -329,9 +329,8 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
/** /**
* Load a node object from the database. * Load a node object from the database.
* *
* @param $conditions * @param $param
* An array of conditions to match against in the database query. Most calls * Either the nid of the node or an array of conditions to match against in the database query
* will simply use array('nid' => 52).
* @param $revision * @param $revision
* Which numbered revision to load. Defaults to the current version. * Which numbered revision to load. Defaults to the current version.
* @param $reset * @param $reset
@ -340,26 +339,30 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
* @return * @return
* A fully-populated node object. * A fully-populated node object.
*/ */
function node_load($conditions, $revision = NULL, $reset = NULL) { function node_load($param = array(), $revision = NULL, $reset = NULL) {
static $nodes = array(); static $nodes = array();
if ($reset) { if ($reset) {
$nodes = array(); $nodes = array();
} }
$cachable = (count($conditions) == 1 && isset($conditions['nid']) && $revision == NULL); if (is_numeric($param)) {
$cachable = $revision == NULL;
if ($cachable && isset($nodes[$conditions['nid']])) { if ($cachable && $nodes[$param]) {
return $nodes[$conditions['nid']]; return $nodes[$param];
}
$cond = 'n.nid = '. $param;
} }
else {
// Turn the conditions into a query. // Turn the conditions into a query.
foreach ($conditions as $key => $value) { foreach ($conditions as $key => $value) {
$cond[] = 'n.'. db_escape_string($key) ." = '". db_escape_string($value) ."'"; $cond[] = 'n.'. db_escape_string($key) ." = '". db_escape_string($value) ."'";
}
$cond = implode(' AND ', $cond);
} }
// Retrieve the node. // 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 = 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 '. $cond)));
$node = drupal_unpack($node); $node = drupal_unpack($node);
// Unserialize the revisions and user data fields. // Unserialize the revisions and user data fields.
@ -387,7 +390,7 @@ function node_load($conditions, $revision = NULL, $reset = NULL) {
} }
if ($cachable) { if ($cachable) {
$nodes[$conditions['nid']] = $node; $nodes[$param] = $node;
} }
return $node; return $node;
@ -566,7 +569,7 @@ function node_search($op = 'search', $keys = null) {
$find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join .' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1'. (empty($where) ? '' : ' AND '. $where)); $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join .' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1'. (empty($where) ? '' : ' AND '. $where));
$results = array(); $results = array();
foreach ($find as $item) { foreach ($find as $item) {
$node = node_load(array('nid' => $item)); $node = node_load($item);
$extra = node_invoke_nodeapi($node, 'search result'); $extra = node_invoke_nodeapi($node, 'search result');
$results[] = array('link' => url('node/'. $item), $results[] = array('link' => url('node/'. $item),
'type' => node_invoke($node, 'node_name'), 'type' => node_invoke($node, 'node_name'),
@ -664,7 +667,7 @@ function node_menu($may_cache) {
} }
else { else {
if (arg(0) == 'node' && is_numeric(arg(1))) { if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1))); $node = node_load(arg(1));
if ($node->nid) { if ($node->nid) {
$items[] = array('path' => 'node/'. arg(1), 'title' => t('view'), $items[] = array('path' => 'node/'. arg(1), 'title' => t('view'),
'callback' => 'node_page', 'callback' => 'node_page',
@ -965,7 +968,7 @@ function node_types_configure($type = NULL) {
*/ */
function node_revision_overview($nid) { function node_revision_overview($nid) {
if (user_access('administer nodes')) { if (user_access('administer nodes')) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
drupal_set_title(check_plain($node->title)); drupal_set_title(check_plain($node->title));
@ -999,7 +1002,7 @@ function node_revision_create($node) {
// "Revision" is the name of the field used to indicate that we have to // "Revision" is the name of the field used to indicate that we have to
// create a new revision of a node. // create a new revision of a node.
if ($node->nid && $node->revision) { if ($node->nid && $node->revision) {
$prev = node_load(array('nid' => $node->nid)); $prev = node_load($node->nid);
$node->revisions = $prev->revisions; $node->revisions = $prev->revisions;
unset($prev->revisions); unset($prev->revisions);
$node->revisions[] = array('uid' => $user->uid, 'timestamp' => time(), 'node' => $prev, 'history' => $node->history); $node->revisions[] = array('uid' => $user->uid, 'timestamp' => time(), 'node' => $prev, 'history' => $node->history);
@ -1015,7 +1018,7 @@ function node_revision_rollback($nid, $revision) {
global $user; global $user;
if (user_access('administer nodes')) { if (user_access('administer nodes')) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
// Extract the specified revision: // Extract the specified revision:
$rev = $node->revisions[$revision]['node']; $rev = $node->revisions[$revision]['node'];
@ -1046,7 +1049,7 @@ function node_revision_rollback($nid, $revision) {
*/ */
function node_revision_delete($nid, $revision) { function node_revision_delete($nid, $revision) {
if (user_access('administer nodes')) { if (user_access('administer nodes')) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
unset($node->revisions[$revision]); unset($node->revisions[$revision]);
@ -1126,7 +1129,7 @@ function node_feed($nodes = 0, $channel = array()) {
while ($node = db_fetch_object($nodes)) { while ($node = db_fetch_object($nodes)) {
// Load the specified node: // Load the specified node:
$item = node_load(array('nid' => $node->nid)); $item = node_load($node->nid);
$link = url("node/$node->nid", NULL, NULL, 1); $link = url("node/$node->nid", NULL, NULL, 1);
// Filter and prepare node teaser // Filter and prepare node teaser
@ -1427,7 +1430,7 @@ function node_add($type) {
function node_edit($id) { function node_edit($id) {
global $user; global $user;
$node = node_load(array('nid' => $id)); $node = node_load($id);
drupal_set_title(check_plain($node->title)); drupal_set_title(check_plain($node->title));
@ -1559,7 +1562,7 @@ function node_submit(&$node) {
* Ask for confirmation, and delete the node. * Ask for confirmation, and delete the node.
*/ */
function node_delete($edit) { function node_delete($edit) {
$node = node_load(array('nid' => $edit['nid'])); $node = node_load($edit['nid']);
if (node_access('delete', $node)) { if (node_access('delete', $node)) {
@ -1610,7 +1613,7 @@ function node_page_default() {
$output = ''; $output = '';
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1); $output .= node_view(node_load($node->nid), 1);
} }
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
} }
@ -1660,7 +1663,7 @@ function node_page() {
break; break;
case 'edit': case 'edit':
if (is_numeric(arg(1))) { if (is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1))); $node = node_load(arg(1));
if ($node->nid) { if ($node->nid) {
drupal_set_title($node->title); drupal_set_title($node->title);
return node_edit(arg(1)); return node_edit(arg(1));
@ -1672,7 +1675,7 @@ function node_page() {
break; break;
case 'view': case 'view':
if (is_numeric(arg(1))) { if (is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1)), $_GET['revision']); $node = node_load(arg(1), $_GET['revision']);
if ($node->nid) { if ($node->nid) {
drupal_set_title(check_plain($node->title)); drupal_set_title(check_plain($node->title));
return node_show($node, arg(2)); return node_show($node, arg(2));
@ -1733,7 +1736,7 @@ function node_update_index() {
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$last_comment = $node->last_comment_timestamp; $last_comment = $node->last_comment_timestamp;
$node = node_load(array('nid' => $node->nid)); $node = node_load($node->nid);
// We update this variable per node in case cron times out, or if the node // We update this variable per node in case cron times out, or if the node
// cannot be indexed (PHP nodes which call drupal_goto, for example). // cannot be indexed (PHP nodes which call drupal_goto, for example).
@ -1981,4 +1984,4 @@ function node_db_rewrite_sql($query, $primary_table, $primary_field) {
* @} End of "defgroup node_access". * @} End of "defgroup node_access".
*/ */
?> ?>

View File

@ -329,9 +329,8 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
/** /**
* Load a node object from the database. * Load a node object from the database.
* *
* @param $conditions * @param $param
* An array of conditions to match against in the database query. Most calls * Either the nid of the node or an array of conditions to match against in the database query
* will simply use array('nid' => 52).
* @param $revision * @param $revision
* Which numbered revision to load. Defaults to the current version. * Which numbered revision to load. Defaults to the current version.
* @param $reset * @param $reset
@ -340,26 +339,30 @@ function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
* @return * @return
* A fully-populated node object. * A fully-populated node object.
*/ */
function node_load($conditions, $revision = NULL, $reset = NULL) { function node_load($param = array(), $revision = NULL, $reset = NULL) {
static $nodes = array(); static $nodes = array();
if ($reset) { if ($reset) {
$nodes = array(); $nodes = array();
} }
$cachable = (count($conditions) == 1 && isset($conditions['nid']) && $revision == NULL); if (is_numeric($param)) {
$cachable = $revision == NULL;
if ($cachable && isset($nodes[$conditions['nid']])) { if ($cachable && $nodes[$param]) {
return $nodes[$conditions['nid']]; return $nodes[$param];
}
$cond = 'n.nid = '. $param;
} }
else {
// Turn the conditions into a query. // Turn the conditions into a query.
foreach ($conditions as $key => $value) { foreach ($conditions as $key => $value) {
$cond[] = 'n.'. db_escape_string($key) ." = '". db_escape_string($value) ."'"; $cond[] = 'n.'. db_escape_string($key) ." = '". db_escape_string($value) ."'";
}
$cond = implode(' AND ', $cond);
} }
// Retrieve the node. // 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 = 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 '. $cond)));
$node = drupal_unpack($node); $node = drupal_unpack($node);
// Unserialize the revisions and user data fields. // Unserialize the revisions and user data fields.
@ -387,7 +390,7 @@ function node_load($conditions, $revision = NULL, $reset = NULL) {
} }
if ($cachable) { if ($cachable) {
$nodes[$conditions['nid']] = $node; $nodes[$param] = $node;
} }
return $node; return $node;
@ -566,7 +569,7 @@ function node_search($op = 'search', $keys = null) {
$find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join .' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1'. (empty($where) ? '' : ' AND '. $where)); $find = do_search($keys, 'node', 'INNER JOIN {node} n ON n.nid = i.sid '. $join .' INNER JOIN {users} u ON n.uid = u.uid', 'n.status = 1'. (empty($where) ? '' : ' AND '. $where));
$results = array(); $results = array();
foreach ($find as $item) { foreach ($find as $item) {
$node = node_load(array('nid' => $item)); $node = node_load($item);
$extra = node_invoke_nodeapi($node, 'search result'); $extra = node_invoke_nodeapi($node, 'search result');
$results[] = array('link' => url('node/'. $item), $results[] = array('link' => url('node/'. $item),
'type' => node_invoke($node, 'node_name'), 'type' => node_invoke($node, 'node_name'),
@ -664,7 +667,7 @@ function node_menu($may_cache) {
} }
else { else {
if (arg(0) == 'node' && is_numeric(arg(1))) { if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1))); $node = node_load(arg(1));
if ($node->nid) { if ($node->nid) {
$items[] = array('path' => 'node/'. arg(1), 'title' => t('view'), $items[] = array('path' => 'node/'. arg(1), 'title' => t('view'),
'callback' => 'node_page', 'callback' => 'node_page',
@ -965,7 +968,7 @@ function node_types_configure($type = NULL) {
*/ */
function node_revision_overview($nid) { function node_revision_overview($nid) {
if (user_access('administer nodes')) { if (user_access('administer nodes')) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
drupal_set_title(check_plain($node->title)); drupal_set_title(check_plain($node->title));
@ -999,7 +1002,7 @@ function node_revision_create($node) {
// "Revision" is the name of the field used to indicate that we have to // "Revision" is the name of the field used to indicate that we have to
// create a new revision of a node. // create a new revision of a node.
if ($node->nid && $node->revision) { if ($node->nid && $node->revision) {
$prev = node_load(array('nid' => $node->nid)); $prev = node_load($node->nid);
$node->revisions = $prev->revisions; $node->revisions = $prev->revisions;
unset($prev->revisions); unset($prev->revisions);
$node->revisions[] = array('uid' => $user->uid, 'timestamp' => time(), 'node' => $prev, 'history' => $node->history); $node->revisions[] = array('uid' => $user->uid, 'timestamp' => time(), 'node' => $prev, 'history' => $node->history);
@ -1015,7 +1018,7 @@ function node_revision_rollback($nid, $revision) {
global $user; global $user;
if (user_access('administer nodes')) { if (user_access('administer nodes')) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
// Extract the specified revision: // Extract the specified revision:
$rev = $node->revisions[$revision]['node']; $rev = $node->revisions[$revision]['node'];
@ -1046,7 +1049,7 @@ function node_revision_rollback($nid, $revision) {
*/ */
function node_revision_delete($nid, $revision) { function node_revision_delete($nid, $revision) {
if (user_access('administer nodes')) { if (user_access('administer nodes')) {
$node = node_load(array('nid' => $nid)); $node = node_load($nid);
unset($node->revisions[$revision]); unset($node->revisions[$revision]);
@ -1126,7 +1129,7 @@ function node_feed($nodes = 0, $channel = array()) {
while ($node = db_fetch_object($nodes)) { while ($node = db_fetch_object($nodes)) {
// Load the specified node: // Load the specified node:
$item = node_load(array('nid' => $node->nid)); $item = node_load($node->nid);
$link = url("node/$node->nid", NULL, NULL, 1); $link = url("node/$node->nid", NULL, NULL, 1);
// Filter and prepare node teaser // Filter and prepare node teaser
@ -1427,7 +1430,7 @@ function node_add($type) {
function node_edit($id) { function node_edit($id) {
global $user; global $user;
$node = node_load(array('nid' => $id)); $node = node_load($id);
drupal_set_title(check_plain($node->title)); drupal_set_title(check_plain($node->title));
@ -1559,7 +1562,7 @@ function node_submit(&$node) {
* Ask for confirmation, and delete the node. * Ask for confirmation, and delete the node.
*/ */
function node_delete($edit) { function node_delete($edit) {
$node = node_load(array('nid' => $edit['nid'])); $node = node_load($edit['nid']);
if (node_access('delete', $node)) { if (node_access('delete', $node)) {
@ -1610,7 +1613,7 @@ function node_page_default() {
$output = ''; $output = '';
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1); $output .= node_view(node_load($node->nid), 1);
} }
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
} }
@ -1660,7 +1663,7 @@ function node_page() {
break; break;
case 'edit': case 'edit':
if (is_numeric(arg(1))) { if (is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1))); $node = node_load(arg(1));
if ($node->nid) { if ($node->nid) {
drupal_set_title($node->title); drupal_set_title($node->title);
return node_edit(arg(1)); return node_edit(arg(1));
@ -1672,7 +1675,7 @@ function node_page() {
break; break;
case 'view': case 'view':
if (is_numeric(arg(1))) { if (is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1)), $_GET['revision']); $node = node_load(arg(1), $_GET['revision']);
if ($node->nid) { if ($node->nid) {
drupal_set_title(check_plain($node->title)); drupal_set_title(check_plain($node->title));
return node_show($node, arg(2)); return node_show($node, arg(2));
@ -1733,7 +1736,7 @@ function node_update_index() {
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$last_comment = $node->last_comment_timestamp; $last_comment = $node->last_comment_timestamp;
$node = node_load(array('nid' => $node->nid)); $node = node_load($node->nid);
// We update this variable per node in case cron times out, or if the node // We update this variable per node in case cron times out, or if the node
// cannot be indexed (PHP nodes which call drupal_goto, for example). // cannot be indexed (PHP nodes which call drupal_goto, for example).
@ -1981,4 +1984,4 @@ function node_db_rewrite_sql($query, $primary_table, $primary_field) {
* @} End of "defgroup node_access". * @} End of "defgroup node_access".
*/ */
?> ?>

View File

@ -203,7 +203,7 @@ function poll_menu($may_cache) {
} }
else { else {
if (arg(0) == 'node' && is_numeric(arg(1))) { if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1))); $node = node_load(arg(1));
if ($node->type == 'poll' && $node->allowvotes) { if ($node->type == 'poll' && $node->allowvotes) {
$items[] = array('path' => 'node/'. arg(1) .'/results', $items[] = array('path' => 'node/'. arg(1) .'/results',
@ -360,7 +360,7 @@ function poll_view_results(&$node, $teaser, $page, $block) {
* Callback for the 'results' tab for polls you can vote on * Callback for the 'results' tab for polls you can vote on
*/ */
function poll_results() { function poll_results() {
if ($node = node_load(array('nid' => arg(1)))) { if ($node = node_load(arg(1))) {
drupal_set_title(check_plain($node->title)); drupal_set_title(check_plain($node->title));
return node_show($node, 0); return node_show($node, 0);
} }
@ -374,7 +374,7 @@ function poll_results() {
*/ */
function poll_vote(&$node) { function poll_vote(&$node) {
$nid = arg(2); $nid = arg(2);
if ($node = node_load(array('nid' => $nid))) { if ($node = node_load($nid)) {
$edit = $_POST['edit']; $edit = $_POST['edit'];
$choice = $edit['choice']; $choice = $edit['choice'];
$vote = $_POST['vote']; $vote = $_POST['vote'];

View File

@ -203,7 +203,7 @@ function poll_menu($may_cache) {
} }
else { else {
if (arg(0) == 'node' && is_numeric(arg(1))) { if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(array('nid' => arg(1))); $node = node_load(arg(1));
if ($node->type == 'poll' && $node->allowvotes) { if ($node->type == 'poll' && $node->allowvotes) {
$items[] = array('path' => 'node/'. arg(1) .'/results', $items[] = array('path' => 'node/'. arg(1) .'/results',
@ -360,7 +360,7 @@ function poll_view_results(&$node, $teaser, $page, $block) {
* Callback for the 'results' tab for polls you can vote on * Callback for the 'results' tab for polls you can vote on
*/ */
function poll_results() { function poll_results() {
if ($node = node_load(array('nid' => arg(1)))) { if ($node = node_load(arg(1))) {
drupal_set_title(check_plain($node->title)); drupal_set_title(check_plain($node->title));
return node_show($node, 0); return node_show($node, 0);
} }
@ -374,7 +374,7 @@ function poll_results() {
*/ */
function poll_vote(&$node) { function poll_vote(&$node) {
$nid = arg(2); $nid = arg(2);
if ($node = node_load(array('nid' => $nid))) { if ($node = node_load($nid)) {
$edit = $_POST['edit']; $edit = $_POST['edit'];
$choice = $edit['choice']; $choice = $edit['choice'];
$vote = $_POST['vote']; $vote = $_POST['vote'];

View File

@ -160,7 +160,7 @@ function statistics_access_log($aid) {
} }
function statistics_node_tracker() { function statistics_node_tracker() {
if ($node = node_load(array('nid' => arg(1)))) { if ($node = node_load(arg(1))) {
$header = array( $header = array(
array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'), array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),

View File

@ -160,7 +160,7 @@ function statistics_access_log($aid) {
} }
function statistics_node_tracker() { function statistics_node_tracker() {
if ($node = node_load(array('nid' => arg(1)))) { if ($node = node_load(arg(1))) {
$header = array( $header = array(
array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'), array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'),

View File

@ -1005,7 +1005,7 @@ function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $p
function taxonomy_render_nodes($result) { function taxonomy_render_nodes($result) {
if (db_num_rows($result) > 0) { if (db_num_rows($result) > 0) {
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1); $output .= node_view(node_load($node->nid), 1);
} }
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0); $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
} }

View File

@ -1005,7 +1005,7 @@ function taxonomy_select_nodes($tids = array(), $operator = 'or', $depth = 0, $p
function taxonomy_render_nodes($result) { function taxonomy_render_nodes($result) {
if (db_num_rows($result) > 0) { if (db_num_rows($result) > 0) {
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1); $output .= node_view(node_load($node->nid), 1);
} }
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0); $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
} }