Index: install.php =================================================================== RCS file: /cvs/drupal/drupal/install.php,v retrieving revision 1.52 diff -u -r1.52 install.php --- install.php 17 May 2007 06:35:05 -0000 1.52 +++ install.php 21 May 2007 03:58:38 -0000 @@ -54,8 +54,8 @@ $module_list['system']['filename'] = 'modules/system/system.module'; $module_list['filter']['filename'] = 'modules/filter/filter.module'; module_list(TRUE, FALSE, FALSE, $module_list); - drupal_load('module', 'system'); - drupal_load('module', 'filter'); + drupal_load_file('module', 'system'); + drupal_load_file('module', 'filter'); // Decide which profile to use. if (!empty($_GET['profile'])) { Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.165 diff -u -r1.165 bootstrap.inc --- includes/bootstrap.inc 8 May 2007 16:36:55 -0000 1.165 +++ includes/bootstrap.inc 21 May 2007 03:58:43 -0000 @@ -500,7 +500,7 @@ */ function bootstrap_invoke_all($hook) { foreach (module_list(TRUE, TRUE) as $module) { - drupal_load('module', $module); + drupal_load_file('module', $module); module_invoke($module, $hook); } } @@ -517,7 +517,7 @@ * @return * TRUE if the item is loaded or has already been loaded. */ -function drupal_load($type, $name) { +function drupal_load_file($type, $name) { static $files = array(); if (isset($files[$type][$name])) { Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.641 diff -u -r1.641 common.inc --- includes/common.inc 15 May 2007 20:19:47 -0000 1.641 +++ includes/common.inc 21 May 2007 05:46:31 -0000 @@ -1899,6 +1899,14 @@ require_once './includes/unicode.inc'; require_once './includes/image.inc'; require_once './includes/form.inc'; + // Allow for custom dataapi handling methods. + // Must come after file.inc. + if (variable_get('drupal_dataapi_include', '') && file_exists(variable_get('drupal_dataapi_include', ''))) { + require_once './' . variable_get('drupal_dataapi_include', ''); + } + else { + require_once './includes/dataapi.inc'; + } // Set the Drupal custom error handler. set_error_handler('drupal_error_handler'); // Emit the correct charset HTTP header. Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.196 diff -u -r1.196 form.inc --- includes/form.inc 16 May 2007 07:56:19 -0000 1.196 +++ includes/form.inc 21 May 2007 05:10:18 -0000 @@ -1760,7 +1760,7 @@ * // 1 (or no value explicitly set) means the operation is finished * // and the batch processing can continue to the next operation. * - * $node = node_load(array('uid' => $uid, 'type' => $type)); + * $node = drupal_load('node', array('uid' => $uid, 'type' => $type)); * $context['results'][] = $node->nid .' : '. $node->title; * $context['message'] = $node->title; * } @@ -1775,7 +1775,7 @@ * $limit = 5; * $result = db_query_range("SELECT nid FROM {node} WHERE nid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit); * while ($row = db_fetch_array($result)) { - * $node = node_load($row['nid'], NULL, TRUE); + * $node = drupal_load('node', $row['nid'], NULL, TRUE); * $context['results'][] = $node->nid .' : '. $node->title; * $context['sandbox']['progress']++; * $context['sandbox']['current_node'] = $node->nid; Index: includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.166 diff -u -r1.166 menu.inc --- includes/menu.inc 16 May 2007 13:45:16 -0000 1.166 +++ includes/menu.inc 21 May 2007 05:10:30 -0000 @@ -408,7 +408,7 @@ * * When a user arrives on a page such as node/5, this function determines * what "5" corresponds to, by inspecting the page's menu path definition, - * node/%node. This will call node_load(5) to load the corresponding node + * node/%node. This will call drupal_load('node', 5) to load the corresponding node * object. * * It also works in reverse, to allow the display of tabs and menu items which Index: includes/module.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/module.inc,v retrieving revision 1.101 diff -u -r1.101 module.inc --- includes/module.inc 7 May 2007 11:59:40 -0000 1.101 +++ includes/module.inc 21 May 2007 03:58:53 -0000 @@ -11,7 +11,7 @@ */ function module_load_all() { foreach (module_list(TRUE, FALSE) as $module) { - drupal_load('module', $module); + drupal_load_file('module', $module); } } @@ -208,7 +208,7 @@ if ($existing->status === '0') { module_load_install($module); db_query("UPDATE {system} SET status = 1, throttle = 0 WHERE type = 'module' AND name = '%s'", $module); - drupal_load('module', $module); + drupal_load_file('module', $module); $invoke_modules[] = $module; } } Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.355 diff -u -r1.355 theme.inc --- includes/theme.inc 6 May 2007 05:47:51 -0000 1.355 +++ includes/theme.inc 21 May 2007 05:16:36 -0000 @@ -1517,7 +1517,7 @@ $variables['title'] = drupal_get_title(); if ((arg(0) == 'node') && is_numeric(arg(1))) { - $variables['node'] = node_load(arg(1)); + $variables['node'] = drupal_load('node', arg(1)); } // Build a list of suggested template files in order of specificity. One Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.261 diff -u -r1.261 block.module --- modules/block/block.module 20 May 2007 16:40:20 -0000 1.261 +++ modules/block/block.module 21 May 2007 03:59:15 -0000 @@ -632,9 +632,9 @@ * Allow users to decide which custom blocks to display when they visit * the site. */ -function block_user($type, $edit, &$user, $category = NULL) { +function block_user($op, &$user, $edit, $category = NULL) { global $user; - switch ($type) { + switch ($op) { case 'form': if ($category == 'account') { $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN (%s) OR r.rid IS NULL) ORDER BY b.weight, b.module", implode(',', array_keys($user->roles))); Index: modules/blog/blog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blog/blog.module,v retrieving revision 1.280 diff -u -r1.280 blog.module --- modules/blog/blog.module 30 Apr 2007 17:03:23 -0000 1.280 +++ modules/blog/blog.module 21 May 2007 05:10:59 -0000 @@ -152,7 +152,7 @@ $result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.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)) { - $output .= node_view(node_load($node->nid), 1); + $output .= node_view(drupal_load('node', $node->nid), 1); } $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); drupal_add_feed(url('blog/'. $account->uid .'/feed'), t('RSS - !title', array('!title' => $title))); @@ -175,7 +175,7 @@ $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.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10)); while ($node = db_fetch_object($result)) { - $output .= node_view(node_load($node->nid), 1); + $output .= node_view(drupal_load('node', $node->nid), 1); } $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); drupal_add_feed(url('blog/feed'), t('RSS - blogs')); @@ -198,7 +198,7 @@ ** database and quote it in the blog: */ - if ($nid && $blog = node_load($nid)) { + if ($nid && $blog = drupal_load('node', $nid)) { $node->body = ''. $blog->body .' ['. l($blog->name, "node/$nid") .']'; } Index: modules/blogapi/blogapi.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blogapi/blogapi.module,v retrieving revision 1.106 diff -u -r1.106 blogapi.module --- modules/blogapi/blogapi.module 30 Apr 2007 17:03:23 -0000 1.106 +++ modules/blogapi/blogapi.module 21 May 2007 05:47:58 -0000 @@ -208,7 +208,7 @@ $edit['date'] = format_date(time(), 'custom', 'Y-m-d H:i:s O'); } - node_invoke_nodeapi($edit, 'blogapi new'); + drupal_invoke_dataapi('node', 'blogapi new', $edit); node_validate($edit); if ($errors = form_get_errors()) { @@ -216,7 +216,7 @@ } $node = node_submit($edit); - node_save($node); + drupal_save('node', $node); if ($node->nid) { watchdog('content', '@type: added %title using blog API.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); // blogger.newPost returns a string so we cast the nid to a string by putting it in double quotes: @@ -237,7 +237,7 @@ return blogapi_error($user); } - $node = node_load($postid); + $node = drupal_load('node', $postid); if (!$node) { return blogapi_error(t('n/a')); } @@ -261,7 +261,7 @@ $node->body = $content; } - node_invoke_nodeapi($node, 'blogapi edit'); + drupal_invoke_dataapi('node', 'blogapi edit', $node); node_validate($node); if ($errors = form_get_errors()) { @@ -272,7 +272,7 @@ $node->date = format_date($node->created, 'custom', 'Y-m-d H:i:s O'); } $node = node_submit($node); - node_save($node); + drupal_save('node', $node); if ($node->nid) { watchdog('content', '@type: updated %title using blog API.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); return TRUE; @@ -290,7 +290,7 @@ return blogapi_error($user); } - $node = node_load($postid); + $node = drupal_load('node', $postid); return _blogapi_get_post($node, TRUE); } @@ -304,7 +304,7 @@ return blogapi_error($user); } - node_delete($postid); + drupal_delete('node', $postid); return TRUE; } @@ -437,12 +437,12 @@ return blogapi_error($user); } - $node = node_load($postid); + $node = drupal_load('node', $postid); $node->taxonomy = array(); foreach ($categories as $category) { $node->taxonomy[] = $category['categoryId']; } - node_save($node); + drupal_save('node', $node); return TRUE; } @@ -472,7 +472,7 @@ if (!$user->uid) { return blogapi_error($user); } - $node = node_load($postid); + $node = drupal_load('node', $postid); if (!$node) { return blogapi_error(t('Invalid post.')); } @@ -482,7 +482,7 @@ return blogapi_error(t('You do not have permission to update this post.')); } - node_save($node); + drupal_save('node', $node); return TRUE; } Index: modules/book/book.module =================================================================== RCS file: /cvs/drupal/drupal/modules/book/book.module,v retrieving revision 1.420 diff -u -r1.420 book.module --- modules/book/book.module 14 May 2007 13:43:34 -0000 1.420 +++ modules/book/book.module 21 May 2007 05:48:07 -0000 @@ -300,7 +300,7 @@ */ function book_outline_submit($form_values, $form, &$form_state) { $op = $form_values['op']; - $node = node_load($form_values['nid']); + $node = drupal_load('node', $form_values['nid']); switch ($op) { case t('Add to book outline'): @@ -424,11 +424,11 @@ } /** - * Implementation of hook_nodeapi(). + * Implementation of hook_node(). * * Appends book navigation to all nodes in the book. */ -function book_nodeapi(&$node, $op, $teaser, $page) { +function book_node($op, &$node, $teaser, $page) { switch ($op) { case 'load': return db_fetch_array(db_query('SELECT parent, weight FROM {book} WHERE vid = %d', $node->vid)); @@ -681,7 +681,7 @@ */ function book_export_html($nid, $depth) { if (user_access('see printer-friendly version')) { - $node = node_load($nid); + $node = drupal_load('node', $nid); for ($i = 1; $i < $depth; $i++) { $content .= "
\n"; } @@ -737,7 +737,7 @@ $result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND n.nid = %d ORDER BY b.weight, n.title'), $nid); while ($page = db_fetch_object($result)) { // Load the node: - $node = node_load($page->nid); + $node = drupal_load('node', $page->nid); if ($node) { if (function_exists($visit_pre)) { @@ -749,7 +749,7 @@ $children = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE n.status = 1 AND b.parent = %d ORDER BY b.weight, n.title'), $node->nid); while ($childpage = db_fetch_object($children)) { - $childnode = node_load($childpage->nid); + $childnode = drupal_load('node', $childpage->nid); if ($childnode->nid != $node->nid) { $output .= book_recurse($childnode->nid, $depth + 1, $visit_pre, $visit_post); } @@ -796,7 +796,7 @@ } // Allow modules to make their own additions to the node. - node_invoke_nodeapi($node, 'print'); + drupal_invoke_dataapi('node', 'print', $node); $output .= "
nid ."\" class=\"section-$depth\">\n"; $output .= "

". check_plain($node->title) ."

\n"; @@ -847,7 +847,7 @@ $children = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.weight FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = %d ORDER BY b.weight, n.title'), $node->nid); while ($child = db_fetch_object($children)) { - $form = array_merge($form, _book_admin_table_tree(node_load($child->nid), $depth + 1)); + $form = array_merge($form, _book_admin_table_tree(drupal_load('node', $child->nid), $depth + 1)); } return $form; @@ -876,7 +876,7 @@ * Display an administrative view of the hierarchy of a book. */ function book_admin_edit($nid) { - $node = node_load($nid); + $node = drupal_load('node', $nid); if ($node->nid) { drupal_set_title(check_plain($node->title)); $form = array(); @@ -909,7 +909,7 @@ if (count($pages)) { foreach ($pages as $page) { if ($page->parent && empty($pages[$page->parent])) { - $orphans[] = node_load($page->nid); + $orphans[] = drupal_load('node', $page->nid); } } } @@ -933,20 +933,20 @@ function book_admin_edit_submit($form_values, $form, &$form_state) { foreach ($form_values['table'] as $row) { - $node = node_load($row['nid']); + $node = drupal_load('node', $row['nid']); if ($row['title'] != $node->title || $row['weight'] != $node->weight) { $node->title = $row['title']; $node->weight = $row['weight']; - node_save($node); + drupal_save('node', $node); watchdog('content', 'book: updated %title.', array('%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); } } if (is_numeric(arg(3))) { // Updating pages in a single book. - $book = node_load(arg(3)); + $book = drupal_load('node', arg(3)); drupal_set_message(t('Updated book %title.', array('%title' => $book->title))); } else { Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.544 diff -u -r1.544 comment.module --- modules/comment/comment.module 20 May 2007 07:30:03 -0000 1.544 +++ modules/comment/comment.module 21 May 2007 05:48:24 -0000 @@ -232,7 +232,7 @@ $items['comment/delete'] = array( 'title' => 'Delete comment', - 'page callback' => 'comment_delete', + 'page callback' => 'comment_process_delete', 'access arguments' => array('administer comments'), 'type' => MENU_CALLBACK, ); @@ -454,10 +454,10 @@ } /** - * Implementation of hook_nodeapi(). + * Implementation of hook_node(). * */ -function comment_nodeapi(&$node, $op, $arg = 0) { +function comment_node($op, &$node, $arg = 0) { switch ($op) { case 'load': return db_fetch_array(db_query("SELECT last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid = %d", $node->nid)); @@ -733,11 +733,13 @@ * If the comment is successfully saved the comment ID is returned. If the comment * is not saved, FALSE is returned. */ -function comment_save($edit) { +function comment_save(&$edit) { global $user; if (user_access('post comments') && (user_access('administer comments') || node_comment_mode($edit['nid']) == COMMENT_NODE_READ_WRITE)) { if (!form_get_errors()) { if ($edit['cid']) { + $status = SAVED_UPDATED; + // Update the comment in the database. db_query("UPDATE {comments} SET status = %d, timestamp = %d, subject = '%s', comment = '%s', format = %d, uid = %d, name = '%s', mail = '%s', homepage = '%s' WHERE cid = %d", $edit['status'], $edit['timestamp'], $edit['subject'], $edit['comment'], $edit['format'], $edit['uid'], $edit['name'], $edit['mail'], $edit['homepage'], $edit['cid']); @@ -750,6 +752,7 @@ watchdog('content', 'Comment: updated %subject.', array('%subject' => $edit['subject']), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], array('fragment' => 'comment-'. $edit['cid']))); } else { + $status = SAVED_NEW; // Check for duplicate comments. Note that we have to use the // validated/filtered data to perform such check. $duplicate = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE pid = %d AND nid = %d AND subject = '%s' AND comment = '%s'", $edit['pid'], $edit['nid'], $edit['subject'], $edit['comment']), 0); @@ -839,7 +842,7 @@ if ($status == COMMENT_NOT_PUBLISHED) { drupal_set_message(t('Your comment has been queued for moderation by site administrators and will be published after approval.')); } - return $edit['cid']; + return $status; } else { return FALSE; @@ -1100,7 +1103,7 @@ /** * Menu callback; delete a comment. */ -function comment_delete($cid = NULL) { +function comment_process_delete($cid = NULL) { $comment = db_fetch_object(db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE c.cid = %d', $cid)); $comment->name = $comment->uid ? $comment->registered_name : $comment->name; @@ -1135,7 +1138,7 @@ $comment = $form['#comment']; // Delete comment and its replies. - _comment_delete_thread($comment); + drupal_delete('comment', $comment); _comment_update_node_statistics($comment->nid); @@ -1250,10 +1253,10 @@ if ($value) { // perform the update action, then refresh node statistics db_query($query, $cid); - $comment = _comment_load($cid); + $comment = drupal_load('comment', $cid); _comment_update_node_statistics($comment->nid); // Allow modules to respond to the updating of a comment. - comment_invoke_comment($comment, $form_values['operation']); + drupal_invoke_dataapi('comment', $comment, $form_values['operation']); // Add an entry to the watchdog log. watchdog('content', 'Comment: updated %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid))); } @@ -1302,7 +1305,7 @@ // array_filter() returns only elements with actual values $comment_counter = 0; foreach (array_filter($edit['comments']) as $cid => $value) { - $comment = _comment_load($cid); + $comment = drupal_load('comment', $cid); if (is_object($comment) && is_numeric($comment->cid)) { $subject = db_result(db_query('SELECT subject FROM {comments} WHERE cid = %d', $cid)); $form['comments'][$cid] = array('#type' => 'hidden', '#value' => $cid, '#prefix' => '
  • ', '#suffix' => check_plain($subject) .'
  • '); @@ -1329,8 +1332,8 @@ function comment_multiple_delete_confirm_submit($form_values, $form, &$form_state) { if ($form_values['confirm']) { foreach ($form_values['comments'] as $cid => $value) { - $comment = _comment_load($cid); - _comment_delete_thread($comment); + $comment = drupal_load('comment', $cid); + drupal_delete('comment', $comment); _comment_update_node_statistics($comment->nid); } cache_clear_all(); @@ -1346,7 +1349,7 @@ /** * Load the entire comment by cid. */ -function _comment_load($cid) { +function comment_load($cid) { return db_fetch_object(db_query('SELECT * FROM {comments} WHERE cid = %d', $cid)); } @@ -1401,9 +1404,6 @@ function comment_validate($edit) { global $user; - // Invoke other validation handlers - comment_invoke_comment($edit, 'validate'); - if (isset($edit['date'])) { // As of PHP 5.1.0, strtotime returns FALSE upon failure instead of -1. if (strtotime($edit['date']) <= 0) { @@ -1619,7 +1619,7 @@ } // Graft in extra form additions - $form = array_merge($form, comment_invoke_comment($form, 'form')); + $form = array_merge($form, drupal_invoke_dataapi('comment', 'form', $form)); return $form; } @@ -1675,7 +1675,7 @@ $output .= theme('comment_view', $comment); } else { - $form['#suffix'] = node_view(node_load($edit['nid'])); + $form['#suffix'] = node_view(drupal_load('node', $edit['nid'])); $edit['pid'] = 0; } @@ -1723,8 +1723,8 @@ function comment_form_submit(&$form_values, $form, &$form_state) { $form_values = _comment_form_submit($form_values); - if ($cid = comment_save($form_values)) { - $form_state['redirect'] = array('node/'. $form_values['nid'], NULL, "comment-$cid"); + if (drupal_save('comment', $form_values)) { + $form_state['redirect'] = array('node/'. $form_values['nid'], NULL, 'comment-'. $form_values['cid']); return; } } @@ -1760,7 +1760,7 @@ $comment->comment = check_markup($comment->comment, $comment->format, FALSE); // Comment API hook - comment_invoke_comment($comment, 'view'); + drupal_invoke_dataapi('view', $comment); $output .= theme('comment', $comment, $links); } @@ -1901,7 +1901,7 @@ return '
    '. $content .'
    '; } -function _comment_delete_thread($comment) { +function comment_delete($comment) { if (!is_object($comment) || !is_numeric($comment->cid)) { watchdog('content', 'Can not delete non-existent comment.', WATCHDOG_WARNING); return; @@ -1911,14 +1911,13 @@ db_query('DELETE FROM {comments} WHERE cid = %d', $comment->cid); watchdog('content', 'Comment: deleted %subject.', array('%subject' => $comment->subject)); - comment_invoke_comment($comment, 'delete'); - // Delete the comment's replies $result = db_query('SELECT c.*, u.name AS registered_name, u.uid FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid WHERE pid = %d', $comment->cid); while ($comment = db_fetch_object($result)) { $comment->name = $comment->uid ? $comment->registered_name : $comment->name; - _comment_delete_thread($comment); + drupal_delete('comment', $comment); } + return SAVED_DELETED; } /** Index: modules/contact/contact.module =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.module,v retrieving revision 1.84 diff -u -r1.84 contact.module --- modules/contact/contact.module 14 May 2007 13:43:35 -0000 1.84 +++ modules/contact/contact.module 21 May 2007 05:17:54 -0000 @@ -114,7 +114,7 @@ * * Allows the user the option of enabling/disabling his personal contact form. */ -function contact_user($type, &$edit, &$user, $category = NULL) { +function contact_user($type, &$user, &$edit, $category = NULL) { if ($type == 'form' && $category == 'account') { $form['contact'] = array('#type' => 'fieldset', '#title' => t('Contact settings'), Index: modules/forum/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v retrieving revision 1.397 diff -u -r1.397 forum.module --- modules/forum/forum.module 14 May 2007 13:43:36 -0000 1.397 +++ modules/forum/forum.module 21 May 2007 06:16:15 -0000 @@ -122,7 +122,7 @@ } function forum_term_load($tid) { - return (array)taxonomy_get_term($tid); + return (array) drupal_load('term', $tid); } /** @@ -164,9 +164,9 @@ } /** - * Implementation of hook_nodeapi(). + * Implementation of hook_node(). */ -function forum_nodeapi(&$node, $op, $teaser, $page) { +function forum_node($op, &$node, $teaser, $page) { switch ($op) { case 'delete revision': db_query('DELETE FROM {forum} WHERE vid = %d', $node->vid); @@ -175,21 +175,21 @@ } /** - * Implementation of hook_taxonomy(). + * Implementation of hook_dataapi(). */ -function forum_taxonomy($op, $type, $term = NULL) { - if ($op == 'delete' && $term['vid'] == _forum_get_vid()) { +function forum_dataapi($type, $op, $object = NULL) { + if ($op == 'delete' && $object['vid'] == _forum_get_vid()) { switch ($type) { case 'term': - $results = db_query('SELECT f.nid FROM {forum} f WHERE f.tid = %d', $term['tid']); + $results = db_query('SELECT f.nid FROM {forum} f WHERE f.tid = %d', $object['tid']); while ($node = db_fetch_object($results)) { // node_delete will also remove any association with non-forum vocabularies. - node_delete($node->nid); + drupal_delete('node', $node->nid); } // For containers, remove the tid from the forum_containers variable. $containers = variable_get('forum_containers', array()); - $key = array_search($term['tid'], $containers); + $key = array_search($object['tid'], $containers); if ($key !== FALSE) { unset($containers[$key]); } @@ -318,7 +318,7 @@ */ function forum_view(&$node, $teaser = FALSE, $page = FALSE) { if ($page) { - $vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', '')); + $vocabulary = drupal_load('vocabulary', variable_get('forum_nav_vocabulary', '')); // Breadcrumb navigation $breadcrumb = array(); $breadcrumb[] = array('path' => 'forum', 'title' => $vocabulary->name); @@ -389,7 +389,7 @@ foreach ($node->taxonomy as $term) { if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) { if (in_array($term, $containers)) { - $term = taxonomy_get_term($term); + $term = drupal_load('term', $term); form_set_error('taxonomy', t('The item %forum is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name))); } } @@ -578,7 +578,7 @@ $type = t('forum'); } - $status = taxonomy_save_term($form_values); + $status = drupal_save('term', $form_values); switch ($status) { case SAVED_NEW: if ($container) { @@ -602,7 +602,7 @@ * @param $tid ID of the term to be deleted */ function forum_confirm_delete($tid) { - $term = taxonomy_get_term($tid); + $term = drupal_load('term', $tid); $form['tid'] = array('#type' => 'value', '#value' => $tid); $form['name'] = array('#type' => 'value', '#value' => $term->name); @@ -697,7 +697,7 @@ // Link back to the forum and not the taxonomy term page. We'll only // do this if the taxonomy term in question belongs to forums. $tid = str_replace('taxonomy/term/', '', $link['href']); - $term = taxonomy_get_term($tid); + $term = drupal_load('term', $tid); if ($term->vid == _forum_get_vid()) { $links[$module]['href'] = str_replace('taxonomy/term', 'forum', $link['href']); } @@ -717,7 +717,7 @@ // Create the forum vocabulary. Assign the vocabulary a low weight so // it will appear first in forum topic create and edit forms. $edit = array('name' => t('Forums'), 'multiple' => 0, 'required' => 1, 'hierarchy' => 1, 'relations' => 0, 'module' => 'forum', 'weight' => -10, 'nodes' => array('forum' => 1)); - taxonomy_save_vocabulary($edit); + drupal_save('vocabulary', $edit); $vid = $edit['vid']; } variable_set('forum_nav_vocabulary', $vid); @@ -831,7 +831,7 @@ } } - $term = taxonomy_get_term($tid); + $term = drupal_load('term', $tid); $sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f, {node} n WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = %d AND n.uid = u.uid AND n.vid = f.vid"); $sql .= tablesort_sql($forum_topic_list_header, 'n.sticky DESC,'); @@ -916,7 +916,7 @@ global $user; // forum list, topics list, topic browser and 'add new topic' link - $vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', '')); + $vocabulary = drupal_load('vocabulary', variable_get('forum_nav_vocabulary', '')); $title = $vocabulary->name; // Breadcrumb navigation: Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.817 diff -u -r1.817 node.module --- modules/node/node.module 20 May 2007 16:46:03 -0000 1.817 +++ modules/node/node.module 21 May 2007 05:49:33 -0000 @@ -513,33 +513,6 @@ } /** - * Invoke a hook_nodeapi() operation in all modules. - * - * @param &$node - * A node object. - * @param $op - * A string containing the name of the nodeapi operation. - * @param $a3, $a4 - * Arguments to pass on to the hook, after the $node and $op arguments. - * @return - * The returned value of the invoked hooks. - */ -function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { - $return = array(); - foreach (module_implements('nodeapi') as $name) { - $function = $name .'_nodeapi'; - $result = $function($node, $op, $a3, $a4); - if (isset($result) && is_array($result)) { - $return = array_merge($return, $result); - } - else if (isset($result)) { - $return[] = $result; - } - } - return $return; -} - -/** * Load a node object from the database. * * @param $param @@ -596,7 +569,7 @@ } } - if ($extra = node_invoke_nodeapi($node, 'load')) { + if ($extra = drupal_invoke_dataapi('node', 'load', $node)) { foreach ($extra as $key => $value) { $node->$key = $value; } @@ -615,19 +588,17 @@ function node_save(&$node) { global $user; - $node->is_new = FALSE; - // Apply filters to some default node fields: if (empty($node->nid)) { // Insert a new node. - $node->is_new = TRUE; - + $status = SAVED_NEW; $node->nid = db_next_id('{node}_nid'); $node->vid = db_next_id('{node_revisions}_vid'); } else { + $status = SAVED_UPDATED; // We need to ensure that all node fields are filled. - $node_current = node_load($node->nid); + $node_current = drupal_load('node', $node->nid); foreach ($node as $field => $data) { $node_current->$field = $data; } @@ -655,7 +626,7 @@ 'title' => "'%s'", 'body' => "'%s'", 'teaser' => "'%s'", 'timestamp' => '%d', 'uid' => '%d', 'format' => '%d'); - if (!empty($node->log) || $node->is_new || $node->revision) { + if (!empty($node->log) || $status == SAVED_NEW || $node->revision) { // Only store the log message if there's something to store; this prevents // existing log messages from being unintentionally overwritten by a blank // message. A new revision will have an empty log message (or $node->log). @@ -675,7 +646,7 @@ //Generate the node table query and the //the node_revisions table query - if ($node->is_new) { + if ($status == SAVED_NEW) { $node_query = 'INSERT INTO {node} ('. implode(', ', array_keys($node_table_types)) .') VALUES ('. implode(', ', $node_table_types) .')'; $revisions_query = 'INSERT INTO {node_revisions} ('. implode(', ', array_keys($revisions_table_types)) .') VALUES ('. implode(', ', $revisions_table_types) .')'; } @@ -704,20 +675,16 @@ db_query($revisions_query, $revisions_table_values); // Call the node specific callback (if any): - if ($node->is_new) { - node_invoke($node, 'insert'); - node_invoke_nodeapi($node, 'insert'); - } - else { - node_invoke($node, 'update'); - node_invoke_nodeapi($node, 'update'); - } + $op = ($status == SAVED_NEW) ? 'insert' : 'update'; + node_invoke($node, $op); // Update the node access table for this node. node_access_acquire_grants($node); // Clear the cache so an anonymous poster can see the node being added or updated. cache_clear_all(); + + return $status; } /** @@ -758,7 +725,7 @@ } // Allow modules to modify the fully-built node. - node_invoke_nodeapi($node, 'alter', $teaser, $page); + drupal_invoke_dataapi('node', 'alter', $node, $teaser, $page); return theme('node', $node, $teaser, $page); } @@ -815,7 +782,7 @@ } // Allow modules to make their own additions to the node. - node_invoke_nodeapi($node, 'view', $teaser, $page); + drupal_invoke_dataapi('node', 'view', $node, $teaser, $page); return $node; } @@ -977,16 +944,16 @@ $results = array(); foreach ($find as $item) { // Build the node body. - $node = node_load($item->sid); + $node = drupal_load('node', $item->sid); $node = node_build_content($node, FALSE, FALSE); $node->body = drupal_render($node->content); // Fetch comments for snippet - $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index'); + $node->body .= module_invoke('comment', 'node', $node, 'update index'); // Fetch terms for snippet - $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index'); + $node->body .= module_invoke('taxonomy', 'node', $node, 'update index'); - $extra = node_invoke_nodeapi($node, 'search result'); + $extra = drupal_invoke_dataapi('node', 'search result', $node); $results[] = array('link' => url('node/'. $item->sid, array('absolute' => TRUE)), 'type' => node_get_types('name', $node), 'title' => $node->title, @@ -1004,7 +971,7 @@ /** * Implementation of hook_user(). */ -function node_user($op, &$edit, &$user) { +function node_user($op, &$user, &$edit) { if ($op == 'delete') { db_query('UPDATE {node} SET uid = 0 WHERE uid = %d', $user->uid); db_query('UPDATE {node_revisions} SET uid = 0 WHERE uid = %d', $user->uid); @@ -1434,7 +1401,7 @@ list($type, $value) = $filter; if ($type == 'category') { // Load term name from DB rather than search and parse options array. - $value = module_invoke('taxonomy', 'get_term', $value); + $value = drupal_load('term', $value); $value = $value->name; } else if ($type == 'language') { @@ -1689,7 +1656,7 @@ function node_multiple_delete_confirm_submit($form_values, $form, &$form_state) { if ($form_values['confirm']) { foreach ($form_values['nodes'] as $nid => $value) { - node_delete($nid); + drupal_delete('node', $nid); } drupal_set_message(t('The items have been deleted.')); } @@ -1743,13 +1710,13 @@ } /** - * Revert to the revision with the specified revision number. A node and nodeapi "update" event is triggered + * Revert to the revision with the specified revision number. A node and hook_node "update" event is triggered * (via the node_save() call) when a revision is reverted. */ function node_revision_revert($nid, $revision) { global $user; - $node = node_load($nid, $revision); + $node = drupal_load('node', $nid, $revision); if ((user_access('revert revisions') || user_access('administer nodes')) && node_access('update', $node)) { if ($node->vid) { $node->revision = 1; @@ -1758,7 +1725,7 @@ $node->taxonomy = array_keys($node->taxonomy); } - node_save($node); + drupal_save('node', $node); drupal_set_message(t('%title has been reverted back to the revision from %revision-date', array('%revision-date' => format_date($node->revision_timestamp), '%title' => $node->title))); watchdog('content', '@type: reverted %title revision %revision.', array('@type' => $node->type, '%title' => $node->title, '%revision' => $revision)); @@ -1772,19 +1739,19 @@ } /** - * Delete the revision with specified revision number. A "delete revision" nodeapi event is invoked when a + * Delete the revision with specified revision number. A "delete revision" hook_node event is invoked when a * revision is deleted. */ function node_revision_delete($nid, $revision) { if (user_access('administer nodes')) { - $node = node_load($nid); + $node = drupal_load('node', $nid); if (node_access('delete', $node)) { // Don't delete the current revision if ($revision != $node->vid) { - $node = node_load($nid, $revision); + $node = drupal_load('node', $nid, $revision); db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $nid, $revision); - node_invoke_nodeapi($node, 'delete revision'); + drupal_invoke_dataapi('node', 'delete revision', $node); drupal_set_message(t('Deleted %title revision %revision.', array('%title' => $node->title, '%revision' => $revision))); watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node->type, '%title' => $node->title, '%revision' => $revision)); } @@ -1860,7 +1827,7 @@ $items = ''; while ($node = db_fetch_object($nodes)) { // Load the specified node: - $item = node_load($node->nid); + $item = drupal_load('node', $node->nid); $link = url("node/$node->nid", array('absolute' => TRUE)); if ($item_length != 'title') { @@ -1875,11 +1842,11 @@ } // Allow modules to change $node->teaser before viewing. - node_invoke_nodeapi($item, 'view', $teaser, FALSE); + drupal_invoke_dataapi('node', 'view', $item, $teaser, FALSE); } // Allow modules to add additional item fields and/or modify $item - $extra = node_invoke_nodeapi($item, 'rss item'); + $extra = drupal_invoke_dataapi('node', 'rss item', $item); $extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => date('r', $item->created)), array('key' => 'dc:creator', 'value' => $item->name), array('key' => 'guid', 'value' => $item->nid .' at '. $base_url, 'attributes' => array('isPermaLink' => 'false')))); foreach ($extra as $element) { if (isset($element['namespace'])) { @@ -2000,7 +1967,7 @@ // Do node-type-specific validation checks. node_invoke($node, 'validate', $form); - node_invoke_nodeapi($node, 'validate', $form); + drupal_invoke_dataapi('node', 'validate', $node, $form); } function node_form_validate($form_values, $form, &$form_state) { @@ -2019,7 +1986,7 @@ } } node_invoke($node, 'prepare'); - node_invoke_nodeapi($node, 'prepare'); + drupal_invoke_dataapi('node', 'prepare', $node); } /** @@ -2328,16 +2295,17 @@ // Fix up the node when required: $node = node_submit($form_values); + $status = drupal_save('node', $node); // Prepare the node's body: - if ($node->nid) { - node_save($node); - watchdog('content', '@type: updated %title.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); - drupal_set_message(t('The %post has been updated.', array('%post' => node_get_types('name', $node)))); - } - else { - node_save($node); - watchdog('content', '@type: added %title.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); - drupal_set_message(t('Your %post has been created.', array('%post' => node_get_types('name', $node)))); + switch ($status) { + case SAVED_UPDATED: + watchdog('content', '@type: updated %title.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $node->nid)); + drupal_set_message(t('The %post has been updated.', array('%post' => node_get_types('name', $node)))); + break; + case SAVED_NEW: + watchdog('content', '@type: added %title.', array('@type' => $node->type, '%title' => $node->title), WATCHDOG_NOTICE, l(t('view'), "node/$node->nid")); + drupal_set_message(t('Your %post has been created.', array('%post' => node_get_types('name', $node)))); + break; } if ($node->nid) { if (node_access('view', $node)) { @@ -2366,7 +2334,7 @@ */ function node_delete_confirm_submit($form_values, $form, &$form_state) { if ($form_values['confirm']) { - node_delete($form_values['nid']); + drupal_delete('node', $form_values['nid']); } $form_state['redirect'] = ''; @@ -2378,7 +2346,7 @@ */ function node_delete($nid) { - $node = node_load($nid); + $node = drupal_load('node', $nid); if (node_access('delete', $node)) { db_query('DELETE FROM {node} WHERE nid = %d', $node->nid); @@ -2386,7 +2354,7 @@ // Call the node-specific callback (if any): node_invoke($node, 'delete'); - node_invoke_nodeapi($node, 'delete'); + drupal_invoke_dataapi('node', 'delete', $node); // Clear the cache so an anonymous poster can see the node being deleted. cache_clear_all(); @@ -2398,6 +2366,7 @@ drupal_set_message(t('%title has been deleted.', array('%title' => $node->title))); watchdog('content', '@type: deleted %title.', array('@type' => $node->type, '%title' => $node->title)); } + return SAVED_DELETED; } /** @@ -2408,7 +2377,7 @@ $op = arg(4) ? arg(4) : 'overview'; switch ($op) { case 'overview': - $node = node_load(arg(1)); + $node = drupal_load('node', arg(1)); if ((user_access('view revisions') || user_access('administer nodes')) && node_access('view', $node)) { return node_revision_overview($node); } @@ -2416,7 +2385,7 @@ return; case 'view': if (is_numeric(arg(3))) { - $node = node_load(arg(1), arg(3)); + $node = drupal_load('node', arg(1), arg(3)); if ($node->nid) { if ((user_access('view revisions') || user_access('administer nodes')) && node_access('view', $node)) { drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp)))); @@ -2450,7 +2419,7 @@ $output = ''; while ($node = db_fetch_object($result)) { - $output .= node_view(node_load($node->nid), 1); + $output .= node_view(drupal_load('node', $node->nid), 1); } $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); } @@ -2534,7 +2503,7 @@ while ($node = db_fetch_object($result)) { $last_change = $node->last_change; $last_nid = $node->nid; - $node = node_load($node->nid); + $node = drupal_load('node', $node->nid); // Build the node body. $node = node_build_content($node, FALSE, FALSE); @@ -2543,7 +2512,7 @@ $text = '

    '. check_plain($node->title) .'

    '. $node->body; // Fetch extra data normally not visible - $extra = node_invoke_nodeapi($node, 'update index'); + $extra = drupal_invoke_dataapi('node', 'update index', $node); foreach ($extra as $t) { $text .= $t; } @@ -2979,7 +2948,7 @@ } $result = db_query("SELECT nid FROM {node}"); while ($node = db_fetch_object($result)) { - node_access_acquire_grants(node_load($node->nid, NULL, TRUE)); + node_access_acquire_grants(drupal_load('node', $node->nid, NULL, TRUE)); } } else { Index: modules/path/path.module =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.module,v retrieving revision 1.119 diff -u -r1.119 path.module --- modules/path/path.module 16 May 2007 13:45:16 -0000 1.119 +++ modules/path/path.module 21 May 2007 04:01:36 -0000 @@ -215,12 +215,12 @@ } /** - * Implementation of hook_nodeapi(). + * Implementation of hook_node(). * * Allows URL aliases for nodes to be specified at node edit time rather * than through the administrative interface. */ -function path_nodeapi(&$node, $op, $arg) { +function path_node($op, &$node, $arg) { if (user_access('create url aliases') || user_access('administer url aliases')) { switch ($op) { case 'validate': Index: modules/poll/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v retrieving revision 1.228 diff -u -r1.228 poll.module --- modules/poll/poll.module 14 May 2007 13:43:36 -0000 1.228 +++ modules/poll/poll.module 21 May 2007 04:01:43 -0000 @@ -62,7 +62,7 @@ $sql = db_rewrite_sql("SELECT MAX(n.created) FROM {node} n INNER JOIN {poll} p ON p.nid = n.nid WHERE n.status = 1 AND p.active = 1"); $timestamp = db_result(db_query($sql)); if ($timestamp) { - $poll = node_load(array('type' => 'poll', 'created' => $timestamp, 'status' => 1)); + $poll = drupal_load('node', array('type' => 'poll', 'created' => $timestamp, 'status' => 1)); if ($poll->nid) { $poll = poll_view($poll, TRUE, FALSE, TRUE); @@ -479,7 +479,7 @@ * Callback for the 'results' tab for polls you can vote on */ function poll_results() { - if ($node = node_load(arg(1))) { + if ($node = drupal_load('node', arg(1))) { drupal_set_title(check_plain($node->title)); return node_show($node, 0); } @@ -492,7 +492,7 @@ * Callback for the 'votes' tab for polls you can see other votes on */ function poll_votes() { - if ($node = node_load(arg(1))) { + if ($node = drupal_load('node', arg(1))) { drupal_set_title(check_plain($node->title)); $output = t('This table lists all the recorded votes for this poll. If anonymous users are allowed to vote, they will be identified by the IP address of the computer they used when they voted.'); @@ -522,7 +522,7 @@ global $user; $nid = arg(1); - if ($node = node_load($nid)) { + if ($node = drupal_load('node', $nid)) { $edit = $_POST; $choice = $edit['choice']; $vote = $_POST['vote']; @@ -567,7 +567,7 @@ global $user; $nid = arg(2); - if ($node = node_load($nid)) { + if ($node = drupal_load('node', $nid)) { if ($node->type == 'poll' && $node->allowvotes == FALSE) { if ($user->uid) { db_query('DELETE FROM {poll_votes} WHERE nid = %d and uid = %d', $node->nid, $user->uid); @@ -656,7 +656,7 @@ /** * Implementation of hook_user(). */ -function poll_user($op, &$edit, &$user) { +function poll_user($op, &$user, &$edit) { if ($op == 'delete') { db_query('UPDATE {poll_votes} SET uid = 0 WHERE uid = %d', $user->uid); } Index: modules/profile/profile.module =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v retrieving revision 1.201 diff -u -r1.201 profile.module --- modules/profile/profile.module 14 May 2007 13:43:36 -0000 1.201 +++ modules/profile/profile.module 21 May 2007 05:18:30 -0000 @@ -144,7 +144,7 @@ if (user_access('access user profiles')) { $output = ''; if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL)) { - $node = node_load(arg(1)); + $node = drupal_load('node', arg(1)); $account = user_load(array('uid' => $node->uid)); if ($use_fields = variable_get('profile_block_author_fields', array())) { @@ -181,7 +181,7 @@ /** * Implementation of hook_user(). */ -function profile_user($type, &$edit, &$user, $category = NULL) { +function profile_user($type, &$user, &$edit, $category = NULL) { switch ($type) { case 'load': return profile_load_profile($user); Index: modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.222 diff -u -r1.222 search.module --- modules/search/search.module 15 May 2007 05:43:16 -0000 1.222 +++ modules/search/search.module 21 May 2007 05:49:45 -0000 @@ -974,7 +974,7 @@ * - Specifically for searching nodes, you can implement nodeapi('update index') * and nodeapi('search result'). However, note that the search system already * indexes all visible output of a node, i.e. everything displayed normally - * by hook_view() and hook_nodeapi('view'). This is usually sufficient. + * by hook_view() and hook_dataapi('node', 'view'). This is usually sufficient. * You should only use this mechanism if you want additional, non-visible data * to be indexed. * - Implement hook_search(). This will create a search tab for your module on Index: modules/statistics/statistics.module =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.module,v retrieving revision 1.258 diff -u -r1.258 statistics.module --- modules/statistics/statistics.module 30 Apr 2007 17:03:27 -0000 1.258 +++ modules/statistics/statistics.module 21 May 2007 05:18:38 -0000 @@ -166,7 +166,7 @@ /** * Implementation of hook_user(). */ -function statistics_user($op, &$edit, &$user) { +function statistics_user($op, &$user, &$edit) { if ($op == 'delete') { db_query('UPDATE {accesslog} SET uid = 0 WHERE uid = %d', $user->uid); } @@ -191,7 +191,7 @@ } function statistics_node_tracker() { - if ($node = node_load(arg(1))) { + if ($node = drupal_load('node', arg(1))) { $header = array( array('data' => t('Time'), 'field' => 'a.timestamp', 'sort' => 'desc'), @@ -547,9 +547,9 @@ } /** - * Implementation of hook_nodeapi(). + * Implementation of hook_node(). */ -function statistics_nodeapi(&$node, $op, $arg = 0) { +function statistics_node($op, &$node, $arg = 0) { switch ($op) { case 'delete': // clean up statistics table when node is deleted Index: modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.478 diff -u -r1.478 system.module --- modules/system/system.module 17 May 2007 07:28:42 -0000 1.478 +++ modules/system/system.module 21 May 2007 05:15:48 -0000 @@ -359,7 +359,7 @@ * * Allows users to individually set their theme and time zone. */ -function system_user($type, $edit, &$user, $category = NULL) { +function system_user($type, &$user, $edit, $category = NULL) { if ($type == 'form' && $category == 'account') { $form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), isset($edit['theme']) ? $edit['theme'] : NULL, 2); @@ -1093,7 +1093,7 @@ foreach ($engines as $engine) { // Insert theme engine into system table drupal_get_filename('theme_engine', $engine->name, $engine->filename); - drupal_load('theme_engine', $engine->name); + drupal_load_file('theme_engine', $engine->name); db_query("INSERT INTO {system} (name, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', %d, %d, %d)", $engine->name, 'theme_engine', $engine->filename, 1, 0, 0); } Index: modules/taxonomy/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v retrieving revision 1.355 diff -u -r1.355 taxonomy.module --- modules/taxonomy/taxonomy.module 14 May 2007 13:43:37 -0000 1.355 +++ modules/taxonomy/taxonomy.module 21 May 2007 05:13:22 -0000 @@ -14,6 +14,14 @@ } /** + * Implementation of hook_init(). + */ +function taxonomy_init() { + include_once('vocabulary.inc'); + include_once('term.inc'); +} + +/** * Implementation of hook_theme() */ function taxonomy_theme() { @@ -43,7 +51,7 @@ foreach ($node->taxonomy as $term) { // On preview, we get tids. if (is_numeric($term)) { - $term = taxonomy_get_term($term); + $term = drupal_load('term', $term); } $links['taxonomy_term_'. $term->tid] = array( 'title' => $term->name, @@ -71,7 +79,7 @@ */ function taxonomy_term_path($term) { - $vocabulary = taxonomy_vocabulary_load($term->vid); + $vocabulary = drupal_load('vocabulary', $term->vid); if ($vocabulary->module != 'taxonomy' && $path = module_invoke($vocabulary->module, 'term_path', $term)) { return $path; } @@ -307,7 +315,7 @@ function taxonomy_form_vocabulary_submit($form_values, $form, &$form_state) { // Fix up the nodes array to remove unchecked nodes. $form_values['nodes'] = array_filter($form_values['nodes']); - switch (taxonomy_save_vocabulary($form_values)) { + switch (drupal_save('vocabulary', $form_values)) { case SAVED_NEW: drupal_set_message(t('Created new vocabulary %name.', array('%name' => $form_values['name']))); watchdog('taxonomy', 'Created new vocabulary %name.', array('%name' => $form_values['name']), WATCHDOG_NOTICE, l(t('edit'), 'admin/content/taxonomy/edit/vocabulary/'. $form_values['vid'])); @@ -323,63 +331,8 @@ return; } -function taxonomy_save_vocabulary(&$edit) { - $edit['nodes'] = empty($edit['nodes']) ? array() : $edit['nodes']; - - if (!empty($edit['vid']) && !empty($edit['name'])) { - db_query("UPDATE {vocabulary} SET name = '%s', description = '%s', help = '%s', multiple = %d, required = %d, hierarchy = %d, relations = %d, tags = %d, weight = %d, module = '%s' WHERE vid = %d", $edit['name'], $edit['description'], $edit['help'], $edit['multiple'], $edit['required'], $edit['hierarchy'], $edit['relations'], $edit['tags'], $edit['weight'], isset($edit['module']) ? $edit['module'] : 'taxonomy', $edit['vid']); - db_query("DELETE FROM {vocabulary_node_types} WHERE vid = %d", $edit['vid']); - foreach ($edit['nodes'] as $type => $selected) { - db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type); - } - module_invoke_all('taxonomy', 'update', 'vocabulary', $edit); - $status = SAVED_UPDATED; - } - else if (!empty($edit['vid'])) { - $status = taxonomy_del_vocabulary($edit['vid']); - } - else { - $edit['vid'] = db_next_id('{vocabulary}_vid'); - db_query("INSERT INTO {vocabulary} (vid, name, description, help, multiple, required, hierarchy, relations, tags, weight, module) VALUES (%d, '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, '%s')", $edit['vid'], $edit['name'], isset($edit['description']) ? $edit['description'] : NULL, isset($edit['help']) ? $edit['help'] : NULL, $edit['multiple'], $edit['required'], $edit['hierarchy'], $edit['relations'], isset($edit['tags']) ? $edit['tags'] : NULL, $edit['weight'], isset($edit['module']) ? $edit['module'] : 'taxonomy'); - foreach ($edit['nodes'] as $type => $selected) { - db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $edit['vid'], $type); - } - module_invoke_all('taxonomy', 'insert', 'vocabulary', $edit); - $status = SAVED_NEW; - } - - cache_clear_all(); - - return $status; -} - -/** - * Delete a vocabulary. - * - * @param $vid - * A vocabulary ID. - * @return - * Constant indicating items were deleted. - */ -function taxonomy_del_vocabulary($vid) { - $vocabulary = (array) taxonomy_vocabulary_load($vid); - - db_query('DELETE FROM {vocabulary} WHERE vid = %d', $vid); - db_query('DELETE FROM {vocabulary_node_types} WHERE vid = %d', $vid); - $result = db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vid); - while ($term = db_fetch_object($result)) { - taxonomy_del_term($term->tid); - } - - module_invoke_all('taxonomy', 'delete', 'vocabulary', $vocabulary); - - cache_clear_all(); - - return SAVED_DELETED; -} - function taxonomy_vocabulary_confirm_delete($vid) { - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = drupal_load('vocabulary', $vid); $form['type'] = array('#type' => 'value', '#value' => 'vocabulary'); $form['vid'] = array('#type' => 'value', '#value' => $vid); @@ -394,7 +347,7 @@ } function taxonomy_vocabulary_confirm_delete_submit($form_values, $form, &$form_state) { - $status = taxonomy_del_vocabulary($form_values['vid']); + $status = drupal_selete('vocabulary', $form_values['vid']); drupal_set_message(t('Deleted vocabulary %name.', array('%name' => $form_values['name']))); watchdog('taxonomy', 'Deleted vocabulary %name.', array('%name' => $form_values['name']), WATCHDOG_NOTICE); $form_state['redirect'] = 'admin/content/taxonomy'; @@ -480,7 +433,7 @@ * Accept the form submission for a taxonomy term and save the result. */ function taxonomy_form_term_submit($form_values, $form, &$form_state) { - switch (taxonomy_save_term($form_values)) { + switch (drupal_save('term', $form_values)) { case SAVED_NEW: drupal_set_message(t('Created new term %term.', array('%term' => $form_values['name']))); watchdog('taxonomy', 'Created new term %term.', array('%term' => $form_values['name']), WATCHDOG_NOTICE, l(t('edit'), 'admin/content/taxonomy/edit/term/'. $form_values['tid'])); @@ -496,126 +449,8 @@ return; } -/** - * Helper function for taxonomy_form_term_submit(). - * - * @param $form_values - * @return - * Status constant indicating if term was inserted or updated. - */ -function taxonomy_save_term(&$form_values) { - $form_values += array( - 'description' => '', - 'weight' => 0 - ); - - if (!empty($form_values['tid']) && $form_values['name']) { - db_query("UPDATE {term_data} SET name = '%s', description = '%s', weight = %d WHERE tid = %d", $form_values['name'], $form_values['description'], $form_values['weight'], $form_values['tid']); - $hook = 'update'; - $status = SAVED_UPDATED; - } - else if (!empty($form_values['tid'])) { - return taxonomy_del_term($form_values['tid']); - } - else { - $form_values['tid'] = db_next_id('{term_data}_tid'); - db_query("INSERT INTO {term_data} (tid, name, description, vid, weight) VALUES (%d, '%s', '%s', %d, %d)", $form_values['tid'], $form_values['name'], $form_values['description'], $form_values['vid'], $form_values['weight']); - $hook = 'insert'; - $status = SAVED_NEW; - } - - db_query('DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d', $form_values['tid'], $form_values['tid']); - if (!empty($form_values['relations'])) { - foreach ($form_values['relations'] as $related_id) { - if ($related_id != 0) { - db_query('INSERT INTO {term_relation} (tid1, tid2) VALUES (%d, %d)', $form_values['tid'], $related_id); - } - } - } - - db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $form_values['tid']); - if (!isset($form_values['parent']) || empty($form_values['parent'])) { - $form_values['parent'] = array(0); - } - if (is_array($form_values['parent'])) { - foreach ($form_values['parent'] as $parent) { - if (is_array($parent)) { - foreach ($parent as $tid) { - db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $form_values['tid'], $tid); - } - } - else { - db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $form_values['tid'], $parent); - } - } - } - else { - db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $form_values['tid'], $form_values['parent']); - } - - db_query('DELETE FROM {term_synonym} WHERE tid = %d', $form_values['tid']); - if (!empty($form_values['synonyms'])) { - foreach (explode ("\n", str_replace("\r", '', $form_values['synonyms'])) as $synonym) { - if ($synonym) { - db_query("INSERT INTO {term_synonym} (tid, name) VALUES (%d, '%s')", $form_values['tid'], chop($synonym)); - } - } - } - - if (isset($hook)) { - module_invoke_all('taxonomy', $hook, 'term', $form_values); - } - - cache_clear_all(); - - return $status; -} - -/** - * Delete a term. - * - * @param $tid - * The term ID. - * @return - * Status constant indicating deletion. - */ -function taxonomy_del_term($tid) { - $tids = array($tid); - while ($tids) { - $children_tids = $orphans = array(); - foreach ($tids as $tid) { - // See if any of the term's children are about to be become orphans: - if ($children = taxonomy_get_children($tid)) { - foreach ($children as $child) { - // If the term has multiple parents, we don't delete it. - $parents = taxonomy_get_parents($child->tid); - if (count($parents) == 1) { - $orphans[] = $child->tid; - } - } - } - - $term = (array) taxonomy_get_term($tid); - - db_query('DELETE FROM {term_data} WHERE tid = %d', $tid); - db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $tid); - db_query('DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d', $tid, $tid); - db_query('DELETE FROM {term_synonym} WHERE tid = %d', $tid); - db_query('DELETE FROM {term_node} WHERE tid = %d', $tid); - - module_invoke_all('taxonomy', 'delete', 'term', $term); - } - - $tids = $orphans; - } - - cache_clear_all(); - - return SAVED_DELETED; -} - function taxonomy_term_confirm_delete($tid) { - $term = taxonomy_get_term($tid); + $term = drupal_load('term', $tid); $form['type'] = array('#type' => 'value', '#value' => 'term'); $form['name'] = array('#type' => 'value', '#value' => $term->name); @@ -641,7 +476,7 @@ * Generate a form element for selecting terms from a vocabulary. */ function taxonomy_form($vid, $value = 0, $help = NULL, $name = 'taxonomy') { - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = drupal_load('vocabulary', $vid); $help = ($help) ? $help : $vocabulary->help; if ($vocabulary->required) { $blank = 0; @@ -799,7 +634,7 @@ $terms = $node->taxonomy; if (!empty($terms['tags'])) { foreach ($terms['tags'] as $vid => $vid_value) { - $vocabulary = taxonomy_vocabulary_load($vid); + $vocabulary = drupal_load('vocabulary', $vid); if (empty($vocabulary->tags)) { // see form_get_error $key = implode('][', $element['#parents']); // on why this is the key @@ -830,7 +665,7 @@ foreach ($typed_terms as $typed_term) { // See if the term exists in the chosen vocabulary // and return the tid; otherwise, add a new record. - $possibilities = taxonomy_get_term_by_name($typed_term); + $possibilities = taxonomy_term_load_by_name($typed_term); $typed_term_tid = NULL; // tid match, if any. foreach ($possibilities as $possibility) { if ($possibility->vid == $vid) { @@ -840,7 +675,7 @@ if (!$typed_term_tid) { $edit = array('vid' => $vid, 'name' => $typed_term); - $status = taxonomy_save_term($edit); + $status = drupal_save('term', $edit); $typed_term_tid = $edit['tid']; } @@ -938,7 +773,7 @@ function taxonomy_get_parents_all($tid) { $parents = array(); if ($tid) { - $parents[] = taxonomy_get_term($tid); + $parents[] = drupal_load('term', $tid); $n = 0; while ($parent = taxonomy_get_parents($parents[$n]->tid)) { $parents = array_merge($parents, $parent); @@ -1121,7 +956,7 @@ * @return * An array of matching term objects. */ -function taxonomy_get_term_by_name($name) { +function taxonomy_term_load_by_name($name) { $db_result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t WHERE LOWER('%s') LIKE LOWER(t.name)", 't', 'tid'), trim($name)); $result = array(); while ($term = db_fetch_object($db_result)) { @@ -1131,54 +966,6 @@ return $result; } -/** - * Return the vocabulary object matching a vocabulary ID. - * - * @param $vid - * The vocabulary's ID - * - * @return Object - * The vocabulary object with all of its metadata. - * Results are statically cached. - */ -function taxonomy_vocabulary_load($vid) { - static $vocabularies = array(); - - if (!array_key_exists($vid, $vocabularies)) { - $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid); - $node_types = array(); - while ($voc = db_fetch_object($result)) { - if (!empty($voc->type)) { - $node_types[] = $voc->type; - } - unset($voc->type); - $voc->nodes = $node_types; - $vocabularies[$vid] = $voc; - } - } - - return $vocabularies[$vid]; -} - -/** - * Return the term object matching a term ID. - * - * @param $tid - * A term's ID - * - * @return Object - * A term object. Results are statically cached. - */ -function taxonomy_get_term($tid) { - static $terms = array(); - - if (!isset($terms[$tid])) { - $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid)); - } - - return $terms[$tid]; -} - function _taxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) { $tree = taxonomy_get_tree($vocabulary_id); $options = array(); @@ -1245,7 +1032,7 @@ $depth = NULL; } foreach ($tids as $index => $tid) { - $term = taxonomy_get_term($tid); + $term = drupal_load('term', $tid); $tree = taxonomy_get_tree($term->vid, $tid, -1, $depth); $descendant_tids[] = array_merge(array($tid), array_map('_taxonomy_get_tid_from_term', $tree)); } @@ -1286,7 +1073,7 @@ $output = ''; if (db_num_rows($result) > 0) { while ($node = db_fetch_object($result)) { - $output .= node_view(node_load($node->nid), 1); + $output .= node_view(drupal_load('node', $node->nid), 1); } $output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0); } @@ -1297,9 +1084,9 @@ } /** - * Implementation of hook_nodeapi(). + * Implementation of hook_node(). */ -function taxonomy_nodeapi($node, $op, $arg = 0) { +function taxonomy_node($op, &$node, $arg = 0) { switch ($op) { case 'load': $output['taxonomy'] = taxonomy_node_get_terms($node); @@ -1416,7 +1203,7 @@ break; case 'feed': - $term = taxonomy_get_term($tids[0]); + $term = drupal_load('term', $tids[0]); $channel['link'] = url('taxonomy/term/'. $str_tids .'/'. $depth, array('absolute' => TRUE)); $channel['title'] = variable_get('site_name', 'Drupal') .' - '. $title; $channel['description'] = $term->description; @@ -1451,7 +1238,7 @@ if ($_POST['op'] == t('Delete') || $_POST['confirm']) { return drupal_get_form('taxonomy_term_confirm_delete', $tid); } - if ($term = (array)taxonomy_get_term($tid)) { + if ($term = (array)drupal_load('term', $tid)) { return drupal_get_form('taxonomy_form_term', $term['vid'], $term); } return drupal_not_found(); Index: modules/upload/upload.module =================================================================== RCS file: /cvs/drupal/drupal/modules/upload/upload.module,v retrieving revision 1.160 diff -u -r1.160 upload.module --- modules/upload/upload.module 14 May 2007 13:43:38 -0000 1.160 +++ modules/upload/upload.module 21 May 2007 04:02:43 -0000 @@ -275,7 +275,7 @@ $result = db_query("SELECT f.* FROM {files} f WHERE filepath = '%s'", $file); if ($file = db_fetch_object($result)) { if (user_access('view uploaded files')) { - $node = node_load($file->nid); + $node = drupal_load('node', $file->nid); if (node_access('view', $node)) { $type = mime_header_encode($file->filemime); return array( @@ -482,9 +482,9 @@ } /** - * Implementation of hook_nodeapi(). + * Implementation of hook_node(). */ -function upload_nodeapi(&$node, $op, $teaser) { +function upload_node($op, &$node, $teaser) { switch ($op) { case 'load': --- includes/dataapi.inc +++ includes/dataapi.inc @@ -0,0 +1,143 @@ + '', + 'weight' => 0 + ); + + if (!empty($term['tid']) && $term['name']) { + db_query("UPDATE {term_data} SET name = '%s', description = '%s', weight = %d WHERE tid = %d", $term['name'], $term['description'], $term['weight'], $term['tid']); + $status = SAVED_UPDATED; + } + else if (!empty($term['tid'])) { + return drupal_delete('term', $term['tid']); + } + else { + $term['tid'] = db_next_id('{term_data}_tid'); + db_query("INSERT INTO {term_data} (tid, name, description, vid, weight) VALUES (%d, '%s', '%s', %d, %d)", $term['tid'], $term['name'], $term['description'], $term['vid'], $term['weight']); + $status = SAVED_NEW; + } + + db_query('DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d', $term['tid'], $term['tid']); + if (!empty($term['relations'])) { + foreach ($term['relations'] as $related_id) { + if ($related_id != 0) { + db_query('INSERT INTO {term_relation} (tid1, tid2) VALUES (%d, %d)', $term['tid'], $related_id); + } + } + } + + db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $term['tid']); + if (!isset($term['parent']) || empty($term['parent'])) { + $term['parent'] = array(0); + } + if (is_array($term['parent'])) { + foreach ($term['parent'] as $parent) { + if (is_array($parent)) { + foreach ($parent as $tid) { + db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $term['tid'], $tid); + } + } + else { + db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $term['tid'], $parent); + } + } + } + else { + db_query('INSERT INTO {term_hierarchy} (tid, parent) VALUES (%d, %d)', $term['tid'], $term['parent']); + } + + db_query('DELETE FROM {term_synonym} WHERE tid = %d', $term['tid']); + if (!empty($term['synonyms'])) { + foreach (explode ("\n", str_replace("\r", '', $term['synonyms'])) as $synonym) { + if ($synonym) { + db_query("INSERT INTO {term_synonym} (tid, name) VALUES (%d, '%s')", $term['tid'], chop($synonym)); + } + } + } + + cache_clear_all(); + + return $status; +} + +/** + * Delete a term. + * + * @param $tid + * The term ID. + * @return + * Status constant indicating deletion. + */ +function term_delete($tid) { + $tids = array($tid); + while ($tids) { + $children_tids = $orphans = array(); + foreach ($tids as $tid) { + // See if any of the term's children are about to be become orphans: + if ($children = taxonomy_get_children($tid)) { + foreach ($children as $child) { + // If the term has multiple parents, we don't delete it. + $parents = taxonomy_get_parents($child->tid); + if (count($parents) == 1) { + $orphans[] = $child->tid; + } + } + } + + $term = (array) drupal_load('term', $tid); + + db_query('DELETE FROM {term_data} WHERE tid = %d', $tid); + db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $tid); + db_query('DELETE FROM {term_relation} WHERE tid1 = %d OR tid2 = %d', $tid, $tid); + db_query('DELETE FROM {term_synonym} WHERE tid = %d', $tid); + db_query('DELETE FROM {term_node} WHERE tid = %d', $tid); + } + + $tids = $orphans; + } + + cache_clear_all(); + + return SAVED_DELETED; +} + +/** + * Return the term object matching a term ID. + * + * @param $tid + * A term's ID + * + * @return Object + * A term object. Results are statically cached. + */ +function term_load($tid) { + static $terms = array(); + + if (!isset($terms[$tid])) { + $terms[$tid] = db_fetch_object(db_query('SELECT * FROM {term_data} WHERE tid = %d', $tid)); + } + + return $terms[$tid]; +} --- modules/taxonomy/vocabulary.inc +++ modules/taxonomy/vocabulary.inc @@ -0,0 +1,95 @@+ $selected) { + db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $vocabulary['vid'], $type); + } + $status = SAVED_UPDATED; + } + else if (!empty($vocabulary['vid'])) { + $status = drupal_delete('vocabulary', $vocabulary['vid']); + } + else { + $vocabulary['vid'] = db_next_id('{vocabulary}_vid'); + db_query("INSERT INTO {vocabulary} (vid, name, description, help, multiple, required, hierarchy, relations, tags, weight, module) VALUES (%d, '%s', '%s', '%s', %d, %d, %d, %d, %d, %d, '%s')", $vocabulary['vid'], $vocabulary['name'], isset($vocabulary['description']) ? $vocabulary['description'] : NULL, isset($vocabulary['help']) ? $vocabulary['help'] : NULL, $vocabulary['multiple'], $vocabulary['required'], $vocabulary['hierarchy'], $vocabulary['relations'], isset($vocabulary['tags']) ? $vocabulary['tags'] : NULL, $vocabulary['weight'], isset($vocabulary['module']) ? $vocabulary['module'] : 'taxonomy'); + foreach ($vocabulary['nodes'] as $type => $selected) { + db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $vocabulary['vid'], $type); + } + $status = SAVED_NEW; + } + + cache_clear_all(); + + return $status; +} + +/** + * Delete a vocabulary. + * + * @param $vid + * A vocabulary ID. + * @return + * Constant indicating items were deleted. + */ +function vocabulary_delete($vid) { + $vocabulary = (array) drupal_load('vocabulary', $vid); + + db_query('DELETE FROM {vocabulary} WHERE vid = %d', $vid); + db_query('DELETE FROM {vocabulary_node_types} WHERE vid = %d', $vid); + $result = db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vid); + while ($term = db_fetch_object($result)) { + drupal_delete('term', $term->tid); + } + + cache_clear_all(); + + return SAVED_DELETED; +} + +/** + * Return the vocabulary object matching a vocabulary ID. + * + * @param $vid + * The vocabulary's ID + * + * @return Object + * The vocabulary object with all of its metadata. + * Results are statically cached. + */ +function vocabulary_load($vid) { + + static $vocabularies = array(); + + if (!array_key_exists($vid, $vocabularies)) { + $result = db_query('SELECT v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE v.vid = %d ORDER BY v.weight, v.name', $vid); + $node_types = array(); + while ($voc = db_fetch_object($result)) { + if (!empty($voc->type)) { + $node_types[] = $voc->type; + } + unset($voc->type); + $voc->nodes = $node_types; + $vocabularies[$vid] = $voc; + } + } + + return $vocabularies[$vid]; +}