Index: drupal/install.php =================================================================== RCS file: /cvs/drupal/drupal/install.php,v retrieving revision 1.53 diff -u -p -r1.53 install.php --- drupal/install.php 22 May 2007 07:42:36 -0000 1.53 +++ drupal/install.php 23 May 2007 23:34:36 -0000 @@ -54,8 +54,8 @@ function install_main() { $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: drupal/includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.165 diff -u -p -r1.165 bootstrap.inc --- drupal/includes/bootstrap.inc 8 May 2007 16:36:55 -0000 1.165 +++ drupal/includes/bootstrap.inc 23 May 2007 23:34:38 -0000 @@ -500,7 +500,7 @@ function page_get_cache() { */ 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 @@ function bootstrap_invoke_all($hook) { * @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: drupal/includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.641 diff -u -p -r1.641 common.inc --- drupal/includes/common.inc 15 May 2007 20:19:47 -0000 1.641 +++ drupal/includes/common.inc 23 May 2007 23:34:44 -0000 @@ -1899,6 +1899,14 @@ function _drupal_bootstrap_full() { 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: drupal/includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.196 diff -u -p -r1.196 form.inc --- drupal/includes/form.inc 16 May 2007 07:56:19 -0000 1.196 +++ drupal/includes/form.inc 23 May 2007 23:34:49 -0000 @@ -1760,7 +1760,7 @@ function form_clean_id($id = NULL) { * // 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 @@ function form_clean_id($id = NULL) { * $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: drupal/includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.167 diff -u -p -r1.167 menu.inc --- drupal/includes/menu.inc 22 May 2007 05:52:16 -0000 1.167 +++ drupal/includes/menu.inc 23 May 2007 23:34:52 -0000 @@ -416,7 +416,7 @@ function _menu_item_localize(&$item) { * * 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: drupal/includes/module.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/module.inc,v retrieving revision 1.101 diff -u -p -r1.101 module.inc --- drupal/includes/module.inc 7 May 2007 11:59:40 -0000 1.101 +++ drupal/includes/module.inc 23 May 2007 23:34: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 @@ function module_enable($module_list) { 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: drupal/includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.356 diff -u -p -r1.356 theme.inc --- drupal/includes/theme.inc 22 May 2007 19:56:00 -0000 1.356 +++ drupal/includes/theme.inc 23 May 2007 23:34:57 -0000 @@ -1520,7 +1520,7 @@ function template_preprocess_page(&$vari $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: drupal/modules/blog/blog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blog/blog.module,v retrieving revision 1.280 diff -u -p -r1.280 blog.module --- drupal/modules/blog/blog.module 30 Apr 2007 17:03:23 -0000 1.280 +++ drupal/modules/blog/blog.module 23 May 2007 23:34:58 -0000 @@ -152,7 +152,7 @@ function blog_page_user($uid) { $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 @@ 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.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 @@ function blog_form(&$node) { ** 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: drupal/modules/blogapi/blogapi.module =================================================================== RCS file: /cvs/drupal/drupal/modules/blogapi/blogapi.module,v retrieving revision 1.106 diff -u -p -r1.106 blogapi.module --- drupal/modules/blogapi/blogapi.module 30 Apr 2007 17:03:23 -0000 1.106 +++ drupal/modules/blogapi/blogapi.module 23 May 2007 23:34:59 -0000 @@ -208,7 +208,7 @@ function blogapi_blogger_new_post($appke $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 @@ function blogapi_blogger_new_post($appke } $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 @@ function blogapi_blogger_edit_post($appk 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 @@ function blogapi_blogger_edit_post($appk $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 @@ function blogapi_blogger_edit_post($appk $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 @@ function blogapi_blogger_get_post($appke return blogapi_error($user); } - $node = node_load($postid); + $node = drupal_load('node', $postid); return _blogapi_get_post($node, TRUE); } @@ -304,7 +304,7 @@ function blogapi_blogger_delete_post($ap return blogapi_error($user); } - node_delete($postid); + drupal_delete('node', $postid); return TRUE; } @@ -437,12 +437,12 @@ function blogapi_mt_set_post_categories( 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 @@ function blogap_mti_publish_post($postid 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 @@ function blogap_mti_publish_post($postid return blogapi_error(t('You do not have permission to update this post.')); } - node_save($node); + drupal_save('node', $node); return TRUE; } Index: drupal/modules/book/book.module =================================================================== RCS file: /cvs/drupal/drupal/modules/book/book.module,v retrieving revision 1.420 diff -u -p -r1.420 book.module --- drupal/modules/book/book.module 14 May 2007 13:43:34 -0000 1.420 +++ drupal/modules/book/book.module 23 May 2007 23:35:02 -0000 @@ -300,7 +300,7 @@ function book_outline($node) { */ 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 @@ function book_content($node, $teaser = F } /** - * 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($type, $nid) { */ 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 @@ function book_recurse($nid = 0, $depth = $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 @@ function book_recurse($nid = 0, $depth = $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 @@ function book_node_visitor_html_pre($nod } // 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 @@ function _book_admin_table_tree($node, $ $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 @@ function theme_book_admin_table($form) { * 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 @@ function book_admin_orphan() { 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_orphan() { 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: drupal/modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.544 diff -u -p -r1.544 comment.module --- drupal/modules/comment/comment.module 20 May 2007 07:30:03 -0000 1.544 +++ drupal/modules/comment/comment.module 23 May 2007 23:35:07 -0000 @@ -232,7 +232,7 @@ function comment_menu() { $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 @@ function comment_form_alter(&$form, $for } /** - * 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 @@ function comment_reply($node, $pid = NUL * 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 @@ function comment_save($edit) { 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); @@ -758,7 +761,7 @@ function comment_save($edit) { } // Add the comment to database. - $status = user_access('post comments without approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED; + $comment_status = user_access('post comments without approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED; $roles = variable_get('comment_roles', array()); $score = 0; @@ -786,7 +789,7 @@ function comment_save($edit) { // the part of the thread value at the proper depth. // Get the parent comment: - $parent = _comment_load($edit['pid']); + $parent = drupal_load('comment', $edit['pid']); // Strip the "/" from the end of the parent thread. $parent->thread = (string) rtrim((string) $parent->thread, '/'); @@ -820,7 +823,7 @@ function comment_save($edit) { } $edit += array('mail' => '', 'homepage' => ''); - db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['cid'], $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], $_SERVER['REMOTE_ADDR'], $edit['timestamp'], $status, $score, $users, $thread, $edit['name'], $edit['mail'], $edit['homepage']); + db_query("INSERT INTO {comments} (cid, nid, pid, uid, subject, comment, format, hostname, timestamp, status, score, users, thread, name, mail, homepage) VALUES (%d, %d, %d, %d, '%s', '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s')", $edit['cid'], $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], $_SERVER['REMOTE_ADDR'], $edit['timestamp'], $comment_status, $score, $users, $thread, $edit['name'], $edit['mail'], $edit['homepage']); _comment_update_node_statistics($edit['nid']); @@ -836,10 +839,10 @@ function comment_save($edit) { // Explain the approval queue if necessary, and then // redirect the user to the node he's commenting on. - if ($status == COMMENT_NOT_PUBLISHED) { + if ($comment_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 @@ function comment_render($node, $cid = 0) /** * 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 @@ function comment_confirm_delete_submit($ $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 @@ function comment_admin_overview_submit($ 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 @@ function comment_multiple_delete_confirm // 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 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 @@ function comment_multiple_delete_confirm /** * 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_num_new($nid, $timestam 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 @@ function comment_form($edit, $title = NU } // 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 @@ function comment_form_add_preview($form, $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_valu 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 @@ function theme_comment_view($comment, $l $comment->comment = check_markup($comment->comment, $comment->format, FALSE); // Comment API hook - comment_invoke_comment($comment, 'view'); + drupal_invoke_dataapi('comment', 'view', $comment); $output .= theme('comment', $comment, $links); } @@ -1901,7 +1901,7 @@ function theme_comment_wrapper($content) 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 @@ function _comment_delete_thread($comment 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: drupal/modules/forum/forum.module =================================================================== RCS file: /cvs/drupal/drupal/modules/forum/forum.module,v retrieving revision 1.397 diff -u -p -r1.397 forum.module --- drupal/modules/forum/forum.module 14 May 2007 13:43:36 -0000 1.397 +++ drupal/modules/forum/forum.module 23 May 2007 23:35:10 -0000 @@ -122,7 +122,7 @@ function forum_init() { } function forum_term_load($tid) { - return (array)taxonomy_get_term($tid); + return (array) drupal_load('term', $tid); } /** @@ -164,9 +164,9 @@ function forum_perm() { } /** - * 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 @@ function forum_nodeapi(&$node, $op, $tea } /** - * 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_block($op = 'list', $delt */ 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 @@ function forum_validate($node) { 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 @@ function forum_form_submit($form_values, $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 @@ function forum_form_submit($form_values, * @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 @@ function forum_link_alter(&$links, $node // 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 @@ function _forum_get_vid() { // 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 @@ function forum_get_topics($tid, $sortby, } } - $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 @@ function theme_forum_display($forums, $t 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: drupal/modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.819 diff -u -p -r1.819 node.module --- drupal/modules/node/node.module 23 May 2007 07:55:08 -0000 1.819 +++ drupal/modules/node/node.module 23 May 2007 23:35:18 -0000 @@ -513,33 +513,6 @@ function node_invoke(&$node, $hook, $a2 } /** - * 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 @@ function node_load($param = array(), $re } } - 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_load($param = array(), $re 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 @@ function node_save(&$node) { '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 @@ function node_save(&$node) { //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 @@ function node_save(&$node) { 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 @@ function node_view($node, $teaser = FALS } // 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 @@ function node_build_content($node, $teas } // 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 @@ function node_search($op = 'search', $ke $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, @@ -1438,7 +1405,7 @@ function node_filter_form() { 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') { @@ -1693,7 +1660,7 @@ function node_multiple_delete_confirm() 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.')); } @@ -1747,13 +1714,13 @@ function node_revision_overview($node) { } /** - * 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; @@ -1762,7 +1729,7 @@ function node_revision_revert($nid, $rev $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)); @@ -1776,19 +1743,19 @@ function node_revision_revert($nid, $rev } /** - * 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)); } @@ -1864,7 +1831,7 @@ function node_feed($nodes = 0, $channel $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') { @@ -1879,11 +1846,11 @@ function node_feed($nodes = 0, $channel } // 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'])) { @@ -2004,7 +1971,7 @@ function node_validate($node, $form = ar // 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) { @@ -2023,7 +1990,7 @@ function node_object_prepare(&$node) { } } node_invoke($node, 'prepare'); - node_invoke_nodeapi($node, 'prepare'); + drupal_invoke_dataapi('node', 'prepare', $node); } /** @@ -2332,16 +2299,17 @@ function node_form_submit($form_values, // 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)) { @@ -2370,7 +2338,7 @@ function node_delete_confirm($node) { */ 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'] = ''; @@ -2382,7 +2350,7 @@ function node_delete_confirm_submit($for */ 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); @@ -2390,7 +2358,7 @@ function node_delete($nid) { // 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(); @@ -2402,6 +2370,7 @@ function node_delete($nid) { 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; } /** @@ -2412,7 +2381,7 @@ function node_revisions() { $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); } @@ -2420,7 +2389,7 @@ function node_revisions() { 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)))); @@ -2454,7 +2423,7 @@ function node_page_default() { $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)); } @@ -2538,7 +2507,7 @@ function node_update_index() { 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); @@ -2547,7 +2516,7 @@ function node_update_index() { $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; } @@ -2983,7 +2952,7 @@ function node_access_rebuild() { } $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: drupal/modules/path/path.module =================================================================== RCS file: /cvs/drupal/drupal/modules/path/path.module,v retrieving revision 1.119 diff -u -p -r1.119 path.module --- drupal/modules/path/path.module 16 May 2007 13:45:16 -0000 1.119 +++ drupal/modules/path/path.module 23 May 2007 23:35:19 -0000 @@ -215,12 +215,12 @@ function path_form($edit = array('src' = } /** - * 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: drupal/modules/poll/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v retrieving revision 1.228 diff -u -p -r1.228 poll.module --- drupal/modules/poll/poll.module 14 May 2007 13:43:36 -0000 1.228 +++ drupal/modules/poll/poll.module 23 May 2007 23:35:20 -0000 @@ -62,7 +62,7 @@ function poll_block($op = 'list', $delta $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 @@ function theme_poll_bar($title, $percent * 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 @@ function poll_results() { * 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 @@ function poll_vote(&$node) { 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 @@ function poll_cancel(&$node) { 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); Index: drupal/modules/profile/profile.module =================================================================== RCS file: /cvs/drupal/drupal/modules/profile/profile.module,v retrieving revision 1.201 diff -u -p -r1.201 profile.module --- drupal/modules/profile/profile.module 14 May 2007 13:43:36 -0000 1.201 +++ drupal/modules/profile/profile.module 23 May 2007 23:35:23 -0000 @@ -144,7 +144,7 @@ function profile_block($op = 'list', $de 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())) { Index: drupal/modules/search/search.module =================================================================== RCS file: /cvs/drupal/drupal/modules/search/search.module,v retrieving revision 1.222 diff -u -p -r1.222 search.module --- drupal/modules/search/search.module 15 May 2007 05:43:16 -0000 1.222 +++ drupal/modules/search/search.module 23 May 2007 23:35:26 -0000 @@ -974,7 +974,7 @@ function search_view($type = 'node') { * - 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: drupal/modules/statistics/statistics.module =================================================================== RCS file: /cvs/drupal/drupal/modules/statistics/statistics.module,v retrieving revision 1.258 diff -u -p -r1.258 statistics.module --- drupal/modules/statistics/statistics.module 30 Apr 2007 17:03:27 -0000 1.258 +++ drupal/modules/statistics/statistics.module 23 May 2007 23:35:27 -0000 @@ -191,7 +191,7 @@ function statistics_access_log($aid) { } 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 @@ function _statistics_format_item($title, } /** - * 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: drupal/modules/system/system.module =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.module,v retrieving revision 1.481 diff -u -p -r1.481 system.module --- drupal/modules/system/system.module 23 May 2007 08:00:46 -0000 1.481 +++ drupal/modules/system/system.module 23 May 2007 23:35:35 -0000 @@ -1041,7 +1041,7 @@ function system_theme_data() { 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: drupal/modules/taxonomy/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.module,v retrieving revision 1.355 diff -u -p -r1.355 taxonomy.module --- drupal/modules/taxonomy/taxonomy.module 14 May 2007 13:43:37 -0000 1.355 +++ drupal/modules/taxonomy/taxonomy.module 23 May 2007 23:35:38 -0000 @@ -14,6 +14,14 @@ function taxonomy_perm() { } /** + * 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 @@ function taxonomy_link($type, $node = NU 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_link($type, $node = NU */ 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; } @@ -103,7 +111,7 @@ function taxonomy_menu() { 'parent' => 'admin/content/taxonomy', ); - $items['admin/content/taxonomy/edit/vocabulary/%taxonomy_vocabulary'] = array( + $items['admin/content/taxonomy/edit/vocabulary/%vocabulary'] = array( 'title' => 'Edit vocabulary', 'page callback' => 'taxonomy_admin_vocabulary_edit', 'page arguments' => array(5), @@ -129,7 +137,7 @@ function taxonomy_menu() { 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); - $items['admin/content/taxonomy/%taxonomy_vocabulary'] = array( + $items['admin/content/taxonomy/%vocabulary'] = array( 'title' => 'List terms', 'page callback' => 'taxonomy_overview_terms', 'page arguments' => array(3), @@ -137,18 +145,18 @@ function taxonomy_menu() { 'type' => MENU_CALLBACK, ); - $items['admin/content/taxonomy/%taxonomy_vocabulary/list'] = array( + $items['admin/content/taxonomy/%vocabulary/list'] = array( 'title' => 'List', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10, ); - $items['admin/content/taxonomy/%taxonomy_vocabulary/add/term'] = array( + $items['admin/content/taxonomy/%vocabulary/add/term'] = array( 'title' => 'Add term', 'page callback' => 'drupal_get_form', 'page arguments' => array('taxonomy_form_term', 3), 'type' => MENU_LOCAL_TASK, - 'parent' => 'admin/content/taxonomy/%taxonomy_vocabulary', + 'parent' => 'admin/content/taxonomy/%vocabulary', ); return $items; @@ -307,7 +315,7 @@ function taxonomy_form_vocabulary($edit 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 @@ function taxonomy_form_vocabulary_submit 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_del } function taxonomy_vocabulary_confirm_delete_submit($form_values, $form, &$form_state) { - $status = taxonomy_del_vocabulary($form_values['vid']); + $status = drupal_delete('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 @@ function taxonomy_form_term($vocabulary, * 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 @@ function taxonomy_form_term_submit($form 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 @@ function taxonomy_term_confirm_delete_su * 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 @@ function taxonomy_node_validate(&$node) $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 @@ function taxonomy_node_save($node, $term 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 @@ function taxonomy_node_save($node, $term 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($tid, $key 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 @@ function _taxonomy_term_children($tid) { * @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 @@ function taxonomy_get_term_by_name($name 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 @@ function taxonomy_select_nodes($tids = a $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 @@ function taxonomy_render_nodes($result) $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 @@ function taxonomy_render_nodes($result) } /** - * 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 @@ function taxonomy_term_page($str_tids = 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 @@ function taxonomy_admin_term_edit($tid) 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: drupal/modules/upload/upload.module =================================================================== RCS file: /cvs/drupal/drupal/modules/upload/upload.module,v retrieving revision 1.160 diff -u -p -r1.160 upload.module --- drupal/modules/upload/upload.module 14 May 2007 13:43:38 -0000 1.160 +++ drupal/modules/upload/upload.module 23 May 2007 23:35:41 -0000 @@ -275,7 +275,7 @@ function upload_file_download($file) { $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 @@ function _upload_validate(&$node) { } /** - * Implementation of hook_nodeapi(). + * Implementation of hook_node(). */ -function upload_nodeapi(&$node, $op, $teaser) { +function upload_node($op, &$node, $teaser) { switch ($op) { case 'load': diff -Nrup includes/dataapi.inc includes/dataapi.inc --- includes/dataapi.inc 1969-12-31 16:00:00.000000000 -0800 +++ includes/dataapi.inc 2007-05-23 15:35:40.312500000 -0700 @@ -0,0 +1,130 @@ + '', + '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]; +} \ No newline at end of file diff -Nrup modules/taxonomy/vocabulary.inc modules/taxonomy/vocabulary.inc --- modules/taxonomy/vocabulary.inc 1969-12-31 16:00:00.000000000 -0800 +++ modules/taxonomy/vocabulary.inc 2007-05-22 09:24:32.578125000 -0700 @@ -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]; +} \ No newline at end of file