summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/blogapi/blogapi.module4
-rw-r--r--modules/book/book.module206
-rw-r--r--modules/comment/comment.module92
-rw-r--r--modules/forum/forum.module250
-rw-r--r--modules/menu/menu.module133
-rw-r--r--modules/node/node.module13
-rw-r--r--modules/node/node.pages.inc2
-rw-r--r--modules/path/path.module95
-rw-r--r--modules/search/search.module33
-rw-r--r--modules/statistics/statistics.module11
-rw-r--r--modules/taxonomy/taxonomy.module80
-rw-r--r--modules/translation/translation.module104
-rw-r--r--modules/trigger/trigger.module41
-rw-r--r--modules/upload/upload.module179
14 files changed, 738 insertions, 505 deletions
diff --git a/modules/blogapi/blogapi.module b/modules/blogapi/blogapi.module
index 2ae37ff83..9633c3816 100644
--- a/modules/blogapi/blogapi.module
+++ b/modules/blogapi/blogapi.module
@@ -221,7 +221,7 @@ function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $conte
$edit['date'] = format_date(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O');
}
- node_invoke_nodeapi($edit, 'blogapi new');
+ node_invoke_nodeapi($edit, 'blogapi_new');
node_validate($edit);
if ($errors = form_get_errors()) {
@@ -273,7 +273,7 @@ function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $cont
$node->body = $content;
}
- node_invoke_nodeapi($node, 'blogapi edit');
+ node_invoke_nodeapi($node, 'blogapi_edit');
node_validate($node);
if ($errors = form_get_errors()) {
diff --git a/modules/book/book.module b/modules/book/book.module
index 551a8db2a..e739df143 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -668,110 +668,132 @@ function book_build_active_trail($book_link) {
}
/**
- * Implementation of hook_nodeapi().
- *
- * Appends book navigation to all nodes in the book, and handles book outline
- * insertions and updates via the node form.
+ * Implementation of hook_nodeapi_load().
*/
-function book_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- case 'load':
- // Note - we cannot use book_link_load() because it will call node_load().
- $info['book'] = db_fetch_array(db_query('SELECT * FROM {book} b INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE b.nid = %d', $node->nid));
+function book_nodeapi_load(&$node, $teaser, $page) {
+ // Note - we cannot use book_link_load() because it will call node_load().
+ $info['book'] = db_fetch_array(db_query('SELECT * FROM {book} b INNER JOIN {menu_links} ml ON b.mlid = ml.mlid WHERE b.nid = %d', $node->nid));
- if ($info['book']) {
- $info['book']['href'] = $info['book']['link_path'];
- $info['book']['title'] = $info['book']['link_title'];
- $info['book']['options'] = unserialize($info['book']['options']);
-
- return $info;
- }
- break;
+ if ($info['book']) {
+ $info['book']['href'] = $info['book']['link_path'];
+ $info['book']['title'] = $info['book']['link_title'];
+ $info['book']['options'] = unserialize($info['book']['options']);
- case 'view':
- if (!$teaser) {
- if (!empty($node->book['bid']) && $node->build_mode == NODE_BUILD_NORMAL) {
- $node->content['book_navigation'] = array(
- '#markup' => theme('book_navigation', $node->book),
- '#weight' => 100,
- );
-
- if ($page) {
- menu_set_active_trail(book_build_active_trail($node->book));
- menu_set_active_menu_name($node->book['menu_name']);
- }
- }
- }
- break;
+ return $info;
+ }
+}
- case 'presave':
- // Always save a revision for non-administrators.
- if (!empty($node->book['bid']) && !user_access('administer nodes')) {
- $node->revision = 1;
- }
- // Make sure a new node gets a new menu link.
- if (empty($node->nid)) {
- $node->book['mlid'] = NULL;
- }
- break;
+/**
+ * Implementation of hook_nodeapi_view().
+ */
+function book_nodeapi_view(&$node, $teaser, $page) {
+ if (!$teaser) {
+ if (!empty($node->book['bid']) && $node->build_mode == NODE_BUILD_NORMAL) {
+ $node->content['book_navigation'] = array(
+ '#markup' => theme('book_navigation', $node->book),
+ '#weight' => 100,
+ );
- case 'insert':
- case 'update':
- if (!empty($node->book['bid'])) {
- if ($node->book['bid'] == 'new') {
- // New nodes that are their own book.
- $node->book['bid'] = $node->nid;
- }
- $node->book['nid'] = $node->nid;
- $node->book['menu_name'] = book_menu_name($node->book['bid']);
- _book_update_outline($node);
+ if ($page) {
+ menu_set_active_trail(book_build_active_trail($node->book));
+ menu_set_active_menu_name($node->book['menu_name']);
}
- break;
+ }
+ }
+}
- case 'delete':
- if (!empty($node->book['bid'])) {
- if ($node->nid == $node->book['bid']) {
- // Handle deletion of a top-level post.
- $result = db_query("SELECT b.nid FROM {menu_links} ml INNER JOIN {book} b on b.mlid = ml.mlid WHERE ml.plid = %d", $node->book['mlid']);
- while ($child = db_fetch_array($result)) {
- $child_node = node_load($child['nid']);
- $child_node->book['bid'] = $child_node->nid;
- _book_update_outline($child_node);
- }
- }
- menu_link_delete($node->book['mlid']);
- db_query('DELETE FROM {book} WHERE mlid = %d', $node->book['mlid']);
- }
- break;
+/**
+ * Implementation of hook_nodeapi_presave().
+ */
+function book_nodeapi_presave(&$node, $teaser, $page) {
+ // Always save a revision for non-administrators.
+ if (!empty($node->book['bid']) && !user_access('administer nodes')) {
+ $node->revision = 1;
+ }
+ // Make sure a new node gets a new menu link.
+ if (empty($node->nid)) {
+ $node->book['mlid'] = NULL;
+ }
+}
- case 'prepare':
- // Prepare defaults for the add/edit form.
- if (empty($node->book) && (user_access('add content to books') || user_access('administer book outlines'))) {
- $node->book = array();
+/**
+ * Implementation of hook_nodeapi_insert().
+ */
+function book_nodeapi_insert(&$node, $teaser, $page) {
+ if (!empty($node->book['bid'])) {
+ if ($node->book['bid'] == 'new') {
+ // New nodes that are their own book.
+ $node->book['bid'] = $node->nid;
+ }
+ $node->book['nid'] = $node->nid;
+ $node->book['menu_name'] = book_menu_name($node->book['bid']);
+ _book_update_outline($node);
+ }
+}
- if (empty($node->nid) && isset($_GET['parent']) && is_numeric($_GET['parent'])) {
- // Handle "Add child page" links:
- $parent = book_link_load($_GET['parent']);
+/**
+ * Implementation of hook_nodeapi_update().
+ */
+function book_nodeapi_update(&$node, $teaser, $page) {
+ if (!empty($node->book['bid'])) {
+ if ($node->book['bid'] == 'new') {
+ // New nodes that are their own book.
+ $node->book['bid'] = $node->nid;
+ }
+ $node->book['nid'] = $node->nid;
+ $node->book['menu_name'] = book_menu_name($node->book['bid']);
+ _book_update_outline($node);
+ }
+}
- if ($parent && $parent['access']) {
- $node->book['bid'] = $parent['bid'];
- $node->book['plid'] = $parent['mlid'];
- $node->book['menu_name'] = $parent['menu_name'];
- }
- }
- // Set defaults.
- $node->book += _book_link_defaults(!empty($node->nid) ? $node->nid : 'new');
- }
- else {
- if (isset($node->book['bid']) && !isset($node->book['original_bid'])) {
- $node->book['original_bid'] = $node->book['bid'];
- }
+/**
+ * Implementation of hook_nodeapi_delete().
+ */
+function book_nodeapi_delete(&$node, $teaser, $page) {
+ if (!empty($node->book['bid'])) {
+ if ($node->nid == $node->book['bid']) {
+ // Handle deletion of a top-level post.
+ $result = db_query("SELECT b.nid FROM {menu_links} ml INNER JOIN {book} b on b.mlid = ml.mlid WHERE ml.plid = %d", $node->book['mlid']);
+ while ($child = db_fetch_array($result)) {
+ $child_node = node_load($child['nid']);
+ $child_node->book['bid'] = $child_node->nid;
+ _book_update_outline($child_node);
}
- // Find the depth limit for the parent select.
- if (isset($node->book['bid']) && !isset($node->book['parent_depth_limit'])) {
- $node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book);
+ }
+ menu_link_delete($node->book['mlid']);
+ db_query('DELETE FROM {book} WHERE mlid = %d', $node->book['mlid']);
+ }
+}
+
+/**
+ * Implementation of hook_nodeapi_prepare().
+ */
+function book_nodeapi_prepare(&$node, $teaser, $page) {
+ // Prepare defaults for the add/edit form.
+ if (empty($node->book) && (user_access('add content to books') || user_access('administer book outlines'))) {
+ $node->book = array();
+
+ if (empty($node->nid) && isset($_GET['parent']) && is_numeric($_GET['parent'])) {
+ // Handle "Add child page" links:
+ $parent = book_link_load($_GET['parent']);
+
+ if ($parent && $parent['access']) {
+ $node->book['bid'] = $parent['bid'];
+ $node->book['plid'] = $parent['mlid'];
+ $node->book['menu_name'] = $parent['menu_name'];
}
- break;
+ }
+ // Set defaults.
+ $node->book += _book_link_defaults(!empty($node->nid) ? $node->nid : 'new');
+ }
+ else {
+ if (isset($node->book['bid']) && !isset($node->book['original_bid'])) {
+ $node->book['original_bid'] = $node->book['bid'];
+ }
+ }
+ // Find the depth limit for the parent select.
+ if (isset($node->book['bid']) && !isset($node->book['parent_depth_limit'])) {
+ $node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book);
}
}
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index d020f8d31..4f3e6dff9 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -552,50 +552,68 @@ function comment_form_alter(&$form, $form_state, $form_id) {
}
/**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_nodeapi_load().
*/
-function comment_nodeapi(&$node, $op, $arg = 0) {
- switch ($op) {
- case 'load':
- if ($node->comment != COMMENT_NODE_DISABLED) {
- return db_fetch_array(db_query("SELECT last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid = %d", $node->nid));
- }
- return array('last_comment_timestamp' => $node->created, 'last_comment_name' => '', 'comment_count' => 0);
+function comment_nodeapi_load(&$node, $arg = 0) {
+ if ($node->comment != COMMENT_NODE_DISABLED) {
+ return db_fetch_array(db_query("SELECT last_comment_timestamp, last_comment_name, comment_count FROM {node_comment_statistics} WHERE nid = %d", $node->nid));
+ }
+ return array('last_comment_timestamp' => $node->created, 'last_comment_name' => '', 'comment_count' => 0);
+}
- case 'prepare':
- if (!isset($node->comment)) {
- $node->comment = variable_get("comment_$node->type", COMMENT_NODE_READ_WRITE);
- }
- break;
+/**
+ * Implementation of hook_nodeapi_prepare().
+ */
+function comment_nodeapi_prepare(&$node, $arg = 0) {
+ if (!isset($node->comment)) {
+ $node->comment = variable_get("comment_$node->type", COMMENT_NODE_READ_WRITE);
+ }
+}
- case 'insert':
- db_query('INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) VALUES (%d, %d, NULL, %d, 0)', $node->nid, $node->changed, $node->uid);
- break;
+/**
+ * Implementation of hook_nodeapi_insert().
+ */
+function comment_nodeapi_insert(&$node, $arg = 0) {
+ db_query('INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) VALUES (%d, %d, NULL, %d, 0)', $node->nid, $node->changed, $node->uid);
+}
- case 'delete':
- db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid);
- db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
- break;
+/**
+ * Implementation of hook_nodeapi_delete().
+ */
+function comment_nodeapi_delete(&$node, $arg = 0) {
+ db_query('DELETE FROM {comments} WHERE nid = %d', $node->nid);
+ db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid);
+}
- case 'update index':
- $text = '';
- $comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = %d', $node->nid, COMMENT_PUBLISHED);
- while ($comment = db_fetch_object($comments)) {
- $text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, FALSE);
- }
- return $text;
+/**
+ * Implementation of hook_nodeapi_update_index().
+ */
+function comment_nodeapi_update_index(&$node, $arg = 0) {
+ $text = '';
+ $comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = %d', $node->nid, COMMENT_PUBLISHED);
+ while ($comment = db_fetch_object($comments)) {
+ $text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, FALSE);
+ }
+ return $text;
+}
- case 'search result':
- $comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid));
- return format_plural($comments, '1 comment', '@count comments');
+/**
+ * Implementation of hook_nodeapi_search_result().
+ */
+function comment_nodeapi_search_result(&$node, $arg = 0) {
+ $comments = db_result(db_query('SELECT comment_count FROM {node_comment_statistics} WHERE nid = %d', $node->nid));
+ return format_plural($comments, '1 comment', '@count comments');
+}
- case 'rss item':
- if ($node->comment != COMMENT_NODE_DISABLED) {
- return array(array('key' => 'comments', 'value' => url('node/' . $node->nid, array('fragment' => 'comments', 'absolute' => TRUE))));
- }
- else {
- return array();
- }
+/**
+ * Implementation of hook_nodeapi_rss_item().
+ */
+function comment_nodeapi_rss_item(&$node, $arg = 0) {
+ if ($node->comment != COMMENT_NODE_DISABLED) {
+ return array(array('key' => 'comments', 'value' => url('node/' . $node->nid, array('fragment' => 'comments', 'absolute' => TRUE))));
+ }
+ else {
+ return array();
}
}
diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index 1588a1b4c..035f11bd3 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -156,133 +156,197 @@ function forum_init() {
}
/**
- * Implementation of hook_nodeapi().
+ * _forum_nodeapi_check_node_type
+ *
+ * @param mixed $node
+ * @param mixed $vocabulary
+ * @access protected
+ * @return bool
*/
-function forum_nodeapi(&$node, $op, $teaser, $page) {
+function _forum_nodeapi_check_node_type($node, $vocabulary) {
// We are going to return if $node->type is not one of the node
// types assigned to the forum vocabulary. If forum_nav_vocabulary
// is undefined or the vocabulary does not exist, it clearly cannot
// be assigned to $node->type, so return to avoid E_ALL warnings.
- $vid = variable_get('forum_nav_vocabulary', '');
- $vocabulary = taxonomy_vocabulary_load($vid);
if (empty($vocabulary)) {
- return;
+ return FALSE;
}
// Operate only on node types assigned for the forum vocabulary.
if (!in_array($node->type, $vocabulary->nodes)) {
- return;
+ return FALSE;
}
- switch ($op) {
- case 'view':
- if ($page && taxonomy_node_get_terms_by_vocabulary($node, $vid) && $tree = taxonomy_get_tree($vid)) {
- // Get the forum terms from the (cached) tree
- foreach ($tree as $term) {
- $forum_terms[] = $term->tid;
- }
- foreach ($node->taxonomy as $term_id => $term) {
- if (in_array($term_id, $forum_terms)) {
- $node->tid = $term_id;
- }
- }
- // Breadcrumb navigation
- $breadcrumb[] = l(t('Home'), NULL);
- $breadcrumb[] = l($vocabulary->name, 'forum');
- if ($parents = taxonomy_get_parents_all($node->tid)) {
- $parents = array_reverse($parents);
- foreach ($parents as $p) {
- $breadcrumb[] = l($p->name, 'forum/' . $p->tid);
- }
- }
- drupal_set_breadcrumb($breadcrumb);
+ return TRUE;
+}
- if (!$teaser) {
- $node->content['forum_navigation'] = array(
- '#markup' => theme('forum_topic_navigation', $node),
- '#weight' => 100,
- );
+/**
+ * Implementation of hook_nodeapi_view().
+ */
+function forum_nodeapi_view(&$node, $teaser, $page) {
+ $vid = variable_get('forum_nav_vocabulary', '');
+ $vocabulary = taxonomy_vocabulary_load($vid);
+ if (_forum_nodeapi_check_node_type($node, $vocabulary)) {
+ if ($page && taxonomy_node_get_terms_by_vocabulary($node, $vid) && $tree = taxonomy_get_tree($vid)) {
+ // Get the forum terms from the (cached) tree
+ foreach ($tree as $term) {
+ $forum_terms[] = $term->tid;
+ }
+ foreach ($node->taxonomy as $term_id => $term) {
+ if (in_array($term_id, $forum_terms)) {
+ $node->tid = $term_id;
}
}
- break;
-
- case 'prepare':
- if (empty($node->nid)) {
- // New topic
- $node->taxonomy[arg(3)]->vid = $vid;
- $node->taxonomy[arg(3)]->tid = arg(3);
+ // Breadcrumb navigation
+ $breadcrumb[] = l(t('Home'), NULL);
+ $breadcrumb[] = l($vocabulary->name, 'forum');
+ if ($parents = taxonomy_get_parents_all($node->tid)) {
+ $parents = array_reverse($parents);
+ foreach ($parents as $p) {
+ $breadcrumb[] = l($p->name, 'forum/' . $p->tid);
+ }
}
- break;
+ drupal_set_breadcrumb($breadcrumb);
- // Check in particular that only a "leaf" term in the associated taxonomy
- // vocabulary is selected, not a "container" term.
- case 'validate':
- if ($node->taxonomy) {
- // Extract the node's proper topic ID.
- $vocabulary = $vid;
- $containers = variable_get('forum_containers', array());
- 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_term_load($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)));
- }
- }
- }
+ if (!$teaser) {
+ $node->content['forum_navigation'] = array(
+ '#markup' => theme('forum_topic_navigation', $node),
+ '#weight' => 100,
+ );
}
- break;
+ }
+ }
+}
- // Assign forum taxonomy when adding a topic from within a forum.
- case 'presave':
- // Make sure all fields are set properly:
- $node->icon = !empty($node->icon) ? $node->icon : '';
+/**
+ * Implementation of hook_nodeapi_prepare().
+ */
+function forum_nodeapi_prepare(&$node, $teaser, $page) {
+ $vid = variable_get('forum_nav_vocabulary', '');
+ $vocabulary = taxonomy_vocabulary_load($vid);
+ if (_forum_nodeapi_check_node_type($node, $vocabulary)) {
+ if (empty($node->nid)) {
+ // New topic
+ $node->taxonomy[arg(3)]->vid = $vid;
+ $node->taxonomy[arg(3)]->tid = arg(3);
+ }
+ }
+}
- if ($node->taxonomy && $tree = taxonomy_get_tree($vid)) {
- // Get the forum terms from the (cached) tree if we have a taxonomy.
- foreach ($tree as $term) {
- $forum_terms[] = $term->tid;
- }
- foreach ($node->taxonomy as $term_id) {
- if (in_array($term_id, $forum_terms)) {
- $node->tid = $term_id;
+/**
+ * Implementation of hook_nodeapi_validate().
+ *
+ * Check in particular that only a "leaf" term in the associated taxonomy.
+ */
+function forum_nodeapi_validate(&$node, $teaser, $page) {
+ $vid = variable_get('forum_nav_vocabulary', '');
+ $vocabulary = taxonomy_vocabulary_load($vid);
+ if (_forum_nodeapi_check_node_type($node, $vocabulary)) {
+ // vocabulary is selected, not a "container" term.
+ if ($node->taxonomy) {
+ // Extract the node's proper topic ID.
+ $vocabulary = $vid;
+ $containers = variable_get('forum_containers', array());
+ 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_term_load($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)));
}
}
- $old_tid = db_result(db_query_range("SELECT t.tid FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.nid = %d ORDER BY t.vid DESC", $node->nid, 0, 1));
- if ($old_tid && isset($node->tid) && ($node->tid != $old_tid) && !empty($node->shadow)) {
- // A shadow copy needs to be created. Retain new term and add old term.
- $node->taxonomy[] = $old_tid;
- }
}
- break;
+ }
+ }
+}
- case 'update':
- if (empty($node->revision) && db_result(db_query('SELECT tid FROM {forum} WHERE nid=%d', $node->nid))) {
- if (!empty($node->tid)) {
- db_query('UPDATE {forum} SET tid = %d WHERE vid = %d', $node->tid, $node->vid);
- }
- // The node is removed from the forum.
- else {
- db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid);
+/**
+ * Implementation of hook_nodeapi_presave().
+ *
+ * Assign forum taxonomy when adding a topic from within a forum.
+ */
+function forum_nodeapi_presave(&$node, $teaser, $page) {
+ $vid = variable_get('forum_nav_vocabulary', '');
+ $vocabulary = taxonomy_vocabulary_load($vid);
+ if (_forum_nodeapi_check_node_type($node, $vocabulary)) {
+ // Make sure all fields are set properly:
+ $node->icon = !empty($node->icon) ? $node->icon : '';
+
+ if ($node->taxonomy && $tree = taxonomy_get_tree($vid)) {
+ // Get the forum terms from the (cached) tree if we have a taxonomy.
+ foreach ($tree as $term) {
+ $forum_terms[] = $term->tid;
+ }
+ foreach ($node->taxonomy as $term_id) {
+ if (in_array($term_id, $forum_terms)) {
+ $node->tid = $term_id;
}
- break;
}
- // Deliberate no break -- for new revisions and for previously unassigned terms we need an insert.
+ $old_tid = db_result(db_query_range("SELECT t.tid FROM {term_node} t INNER JOIN {node} n ON t.vid = n.vid WHERE n.nid = %d ORDER BY t.vid DESC", $node->nid, 0, 1));
+ if ($old_tid && isset($node->tid) && ($node->tid != $old_tid) && !empty($node->shadow)) {
+ // A shadow copy needs to be created. Retain new term and add old term.
+ $node->taxonomy[] = $old_tid;
+ }
+ }
+ }
+}
- case 'insert':
+/**
+ * Implementation of hook_nodeapi_update().
+ */
+function forum_nodeapi_update(&$node, $teaser, $page) {
+ $vid = variable_get('forum_nav_vocabulary', '');
+ $vocabulary = taxonomy_vocabulary_load($vid);
+ if (_forum_nodeapi_check_node_type($node, $vocabulary)) {
+ if (empty($node->revision) && db_result(db_query('SELECT tid FROM {forum} WHERE nid=%d', $node->nid))) {
+ if (!empty($node->tid)) {
+ db_query('UPDATE {forum} SET tid = %d WHERE vid = %d', $node->tid, $node->vid);
+ }
+ // The node is removed from the forum.
+ else {
+ db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid);
+ }
+ }
+ else {
if (!empty($node->tid)) {
db_query('INSERT INTO {forum} (tid, vid, nid) VALUES (%d, %d, %d)', $node->tid, $node->vid, $node->nid);
}
- break;
+ }
+ }
+}
- case 'delete':
- db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid);
- break;
+/**
+ * Implementation of hook_nodeapi_insert().
+ */
+function forum_nodeapi_insert(&$node, $teaser, $page) {
+ $vid = variable_get('forum_nav_vocabulary', '');
+ $vocabulary = taxonomy_vocabulary_load($vid);
+ if (_forum_nodeapi_check_node_type($node, $vocabulary)) {
+ if (!empty($node->tid)) {
+ db_query('INSERT INTO {forum} (tid, vid, nid) VALUES (%d, %d, %d)', $node->tid, $node->vid, $node->nid);
+ }
+ }
+}
- case 'load':
- return db_fetch_array(db_query('SELECT tid AS forum_tid FROM {forum} WHERE vid = %d', $node->vid));
+/**
+ * Implementation of hook_nodeapi_delete().
+ */
+function forum_nodeapi_delete(&$node, $teaser, $page) {
+ $vid = variable_get('forum_nav_vocabulary', '');
+ $vocabulary = taxonomy_vocabulary_load($vid);
+ if (_forum_nodeapi_check_node_type($node, $vocabulary)) {
+ db_query('DELETE FROM {forum} WHERE nid = %d', $node->nid);
}
+}
- return;
+/**
+ * Implementation of hook_nodeapi_load().
+ */
+function forum_nodeapi_load(&$node, $teaser, $page) {
+ $vid = variable_get('forum_nav_vocabulary', '');
+ $vocabulary = taxonomy_vocabulary_load($vid);
+ if (_forum_nodeapi_check_node_type($node, $vocabulary)) {
+ return db_fetch_array(db_query('SELECT tid AS forum_tid FROM {forum} WHERE vid = %d', $node->vid));
+ }
}
/**
diff --git a/modules/menu/menu.module b/modules/menu/menu.module
index f3fb6e8b2..f812785d5 100644
--- a/modules/menu/menu.module
+++ b/modules/menu/menu.module
@@ -277,65 +277,90 @@ function menu_block($op = 'list', $delta = '') {
}
/**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_nodeapi_insert().
*/
-function menu_nodeapi(&$node, $op) {
- switch ($op) {
- case 'insert':
- case 'update':
- if (isset($node->menu)) {
- $item = $node->menu;
- if (!empty($item['delete'])) {
- menu_link_delete($item['mlid']);
- }
- elseif (trim($item['link_title'])) {
- $item['link_title'] = trim($item['link_title']);
- $item['link_path'] = "node/$node->nid";
- if (!$item['customized']) {
- $item['options']['attributes']['title'] = trim($node->title);
- }
- if (!menu_link_save($item)) {
- drupal_set_message(t('There was an error saving the menu link.'), 'error');
- }
- }
+function menu_nodeapi_insert(&$node) {
+ if (isset($node->menu)) {
+ $item = $node->menu;
+ if (!empty($item['delete'])) {
+ menu_link_delete($item['mlid']);
+ }
+ elseif (trim($item['link_title'])) {
+ $item['link_title'] = trim($item['link_title']);
+ $item['link_path'] = "node/$node->nid";
+ if (!$item['customized']) {
+ $item['options']['attributes']['title'] = trim($node->title);
}
- break;
- case 'delete':
- // Delete all menu module links that point to this node.
- $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu'", array(':path' => 'node/'. $node->nid));
- while ($m = db_fetch_array($result)) {
- menu_link_delete($m['mlid']);
+ if (!menu_link_save($item)) {
+ drupal_set_message(t('There was an error saving the menu link.'), 'error');
}
- break;
- case 'prepare':
- if (empty($node->menu)) {
- // Prepare the node for the edit form so that $node->menu always exists.
- $menu_name = variable_get('menu_default_node_menu', 'main-menu');
- $item = array();
- if (isset($node->nid)) {
- // Give priority to the default menu
- $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", array(
- ':path' => 'node/'. $node->nid,
- ':menu_name' => $menu_name,
- ), 0, 1));
- // Check all menus if a link does not exist in the default menu.
- if (!$mlid) {
- $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", array(
- ':path' => 'node/'. $node->nid,
- ), 0, 1));
- }
- if ($mlid) {
- $item = menu_link_load($mlid);
- }
- }
- // Set default values.
- $node->menu = $item + array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu_name, 'weight' => 0, 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0, 'customized' => 0);
+ }
+ }
+}
+
+/**
+ * Implementation of hook_nodeapi_update().
+ */
+function menu_nodeapi_update(&$node) {
+ if (isset($node->menu)) {
+ $item = $node->menu;
+ if (!empty($item['delete'])) {
+ menu_link_delete($item['mlid']);
+ }
+ elseif (trim($item['link_title'])) {
+ $item['link_title'] = trim($item['link_title']);
+ $item['link_path'] = "node/$node->nid";
+ if (!$item['customized']) {
+ $item['options']['attributes']['title'] = trim($node->title);
}
- // Find the depth limit for the parent select.
- if (!isset($node->menu['parent_depth_limit'])) {
- $node->menu['parent_depth_limit'] = _menu_parent_depth_limit($node->menu);
+ if (!menu_link_save($item)) {
+ drupal_set_message(t('There was an error saving the menu link.'), 'error');
}
- break;
+ }
+ }
+}
+
+/**
+ * Implementation of hook_nodeapi_delete().
+ */
+function menu_nodeapi_delete(&$node) {
+ // Delete all menu module links that point to this node.
+ $result = db_query("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu'", array(':path' => 'node/'. $node->nid));
+ while ($m = db_fetch_array($result)) {
+ menu_link_delete($m['mlid']);
+ }
+}
+
+/**
+ * Implementation of hook_nodeapi_prepare().
+ */
+function menu_nodeapi_prepare(&$node) {
+ if (empty($node->menu)) {
+ // Prepare the node for the edit form so that $node->menu always exists.
+ $menu_name = variable_get('menu_default_node_menu', 'main-menu');
+ $item = array();
+ if (isset($node->nid)) {
+ // Give priority to the default menu
+ $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", array(
+ ':path' => 'node/'. $node->nid,
+ ':menu_name' => $menu_name,
+ ), 0, 1));
+ // Check all menus if a link does not exist in the default menu.
+ if (!$mlid) {
+ $mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", array(
+ ':path' => 'node/'. $node->nid,
+ ), 0, 1));
+ }
+ if ($mlid) {
+ $item = menu_link_load($mlid);
+ }
+ }
+ // Set default values.
+ $node->menu = $item + array('link_title' => '', 'mlid' => 0, 'plid' => 0, 'menu_name' => $menu_name, 'weight' => 0, 'options' => array(), 'module' => 'menu', 'expanded' => 0, 'hidden' => 0, 'has_children' => 0, 'customized' => 0);
+ }
+ // Find the depth limit for the parent select.
+ if (!isset($node->menu['parent_depth_limit'])) {
+ $node->menu['parent_depth_limit'] = _menu_parent_depth_limit($node->menu);
}
}
diff --git a/modules/node/node.module b/modules/node/node.module
index 9a14b4c7c..e9f635694 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -704,9 +704,10 @@ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) {
*/
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);
+ $hook = 'nodeapi_' . $op;
+ foreach (module_implements($hook) as $name) {
+ $function = $name . '_' . $hook;
+ $result = $function($node, $a3, $a4);
if (isset($result) && is_array($result)) {
$return = array_merge($return, $result);
}
@@ -1321,9 +1322,9 @@ function node_search($op = 'search', $keys = NULL) {
$node->body = drupal_render($node->content);
// Fetch comments for snippet.
- $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
+ $node->body .= module_invoke('comment', 'nodeapi', $node, 'update_index');
// Fetch terms for snippet.
- $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');
+ $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update_index');
$extra = node_invoke_nodeapi($node, 'search result');
@@ -1742,7 +1743,7 @@ function node_feed($nids = FALSE, $channel = array()) {
}
// Allow modules to add additional item fields and/or modify $item
- $extra = node_invoke_nodeapi($item, 'rss item');
+ $extra = node_invoke_nodeapi($item, 'rss_item');
$extra = array_merge($extra, array(array('key' => 'pubDate', 'value' => gmdate('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'])) {
diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc
index 1194e320f..bdf2d1930 100644
--- a/modules/node/node.pages.inc
+++ b/modules/node/node.pages.inc
@@ -576,7 +576,7 @@ function node_revision_delete_confirm($form_state, $node_revision) {
function node_revision_delete_confirm_submit($form, &$form_state) {
$node_revision = $form['#node_revision'];
db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node_revision->nid, $node_revision->vid);
- node_invoke_nodeapi($node_revision, 'delete revision');
+ node_invoke_nodeapi($node_revision, 'delete_revision');
watchdog('content', '@type: deleted %title revision %revision.', array('@type' => $node_revision->type, '%title' => $node_revision->title, '%revision' => $node_revision->vid));
drupal_set_message(t('Revision from %revision-date of @type %title has been deleted.', array('%revision-date' => format_date($node_revision->revision_timestamp), '@type' => node_get_types('name', $node_revision), '%title' => $node_revision->title)));
$form_state['redirect'] = 'node/' . $node_revision->nid;
diff --git a/modules/path/path.module b/modules/path/path.module
index e3eaa8de4..78933bcb5 100644
--- a/modules/path/path.module
+++ b/modules/path/path.module
@@ -117,53 +117,66 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = ''
drupal_clear_path_cache();
}
-
/**
- * Implementation of hook_nodeapi().
- *
- * Allows URL aliases for nodes to be specified at node edit time rather
- * than through the administrative interface.
+ * Implementation of hook_nodeapi_validate().
*/
-function path_nodeapi(&$node, $op, $arg) {
- // Permissions are required for everything except node loading.
- if (user_access('create url aliases') || user_access('administer url aliases') || ($op == 'load')) {
- $language = isset($node->language) ? $node->language : '';
- switch ($op) {
- case 'validate':
- if (isset($node->path)) {
- $node->path = trim($node->path);
- if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path, "node/$node->nid", $language))) {
- form_set_error('path', t('The path is already in use.'));
- }
- }
- break;
+function path_nodeapi_validate(&$node, $arg) {
+ if (user_access('create url aliases') || user_access('administer url aliases')) {
+ if (isset($node->path)) {
+ $language = isset($node->language) ? $node->language : '';
+ $node->path = trim($node->path);
+ if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s' AND language = '%s'", $node->path, "node/$node->nid", $language))) {
+ form_set_error('path', t('The path is already in use.'));
+ }
+ }
+ }
+}
- case 'load':
- $path = 'node/' . $node->nid;
- $alias = drupal_get_path_alias($path, $language);
- if ($path != $alias) {
- $node->path = $alias;
- }
- break;
+/**
+ * Implementation of hook_nodeapi_load().
+ */
+function path_nodeapi_load(&$node, $arg) {
+ $language = isset($node->language) ? $node->language : '';
+ $path = 'node/' . $node->nid;
+ $alias = drupal_get_path_alias($path, $language);
+ if ($path != $alias) {
+ $node->path = $alias;
+ }
+}
- case 'insert':
- // Don't try to insert if path is NULL. We may have already set
- // the alias ahead of time.
- if (isset($node->path)) {
- path_set_alias('node/' . $node->nid, $node->path, NULL, $language);
- }
- break;
+/**
+ * Implementation of hook_nodeapi_insert().
+ */
+function path_nodeapi_insert(&$node, $arg) {
+ if (user_access('create url aliases') || user_access('administer url aliases')) {
+ $language = isset($node->language) ? $node->language : '';
+ // Don't try to insert if path is NULL. We may have already set
+ // the alias ahead of time.
+ if (isset($node->path)) {
+ path_set_alias('node/' . $node->nid, $node->path, NULL, $language);
+ }
+ }
+}
- case 'update':
- path_set_alias('node/' . $node->nid, isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language);
- break;
+/**
+ * Implementation of hook_nodeapi_update().
+ */
+function path_nodeapi_update(&$node, $arg) {
+ if (user_access('create url aliases') || user_access('administer url aliases')) {
+ $language = isset($node->language) ? $node->language : '';
+ path_set_alias('node/' . $node->nid, isset($node->path) ? $node->path : NULL, isset($node->pid) ? $node->pid : NULL, $language);
+ }
+}
- case 'delete':
- $path = 'node/' . $node->nid;
- if (drupal_get_path_alias($path) != $path) {
- path_set_alias($path);
- }
- break;
+/**
+ * Implementation of hook_nodeapi_delete().
+ */
+function path_nodeapi_delete(&$node, $arg) {
+ if (user_access('create url aliases') || user_access('administer url aliases')) {
+ $language = isset($node->language) ? $node->language : '';
+ $path = 'node/' . $node->nid;
+ if (drupal_get_path_alias($path) != $path) {
+ path_set_alias($path);
}
}
}
diff --git a/modules/search/search.module b/modules/search/search.module
index 022914116..245c5ee33 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -626,24 +626,25 @@ function search_touch_node($nid) {
}
/**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_nodeapi_update_index().
*/
-function search_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
- switch ($op) {
- // Transplant links to a node into the target node.
- case 'update index':
- $result = db_query("SELECT caption FROM {search_node_links} WHERE nid = %d", $node->nid);
- $output = array();
- while ($link = db_fetch_object($result)) {
- $output[] = $link->caption;
- }
- return '<a>(' . implode(', ', $output) . ')</a>';
- // Reindex the node when it is updated. The node is automatically indexed
- // when it is added, simply by being added to the node table.
- case 'update':
- search_touch_node($node->nid);
- break;
+function search_nodeapi_update_index(&$node, $teaser = NULL, $page = NULL) {
+ // Transplant links to a node into the target node.
+ $result = db_query("SELECT caption FROM {search_node_links} WHERE nid = %d", $node->nid);
+ $output = array();
+ while ($link = db_fetch_object($result)) {
+ $output[] = $link->caption;
}
+ return '<a>(' . implode(', ', $output) . ')</a>';
+}
+
+/**
+ * Implementation of hook_nodeapi_update().
+ */
+function search_nodeapi_update(&$node, $teaser = NULL, $page = NULL) {
+ // Reindex the node when it is updated. The node is automatically indexed
+ // when it is added, simply by being added to the node table.
+ search_touch_node($node->nid);
}
/**
diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module
index 42d4b6782..b830b20fd 100644
--- a/modules/statistics/statistics.module
+++ b/modules/statistics/statistics.module
@@ -317,14 +317,11 @@ function _statistics_format_item($title, $path) {
}
/**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_nodeapi_delete().
*/
-function statistics_nodeapi(&$node, $op, $arg = 0) {
- switch ($op) {
- case 'delete':
- // clean up statistics table when node is deleted
- db_query('DELETE FROM {node_counter} WHERE nid = %d', $node->nid);
- }
+function statistics_nodeapi_delete(&$node, $arg = 0) {
+ // clean up statistics table when node is deleted
+ db_query('DELETE FROM {node_counter} WHERE nid = %d', $node->nid);
}
/**
diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module
index be11c08c6..97ab280e3 100644
--- a/modules/taxonomy/taxonomy.module
+++ b/modules/taxonomy/taxonomy.module
@@ -1175,44 +1175,64 @@ function taxonomy_render_nodes($result) {
}
/**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_nodeapi_load().
*/
-function taxonomy_nodeapi($node, $op, $arg = 0) {
- switch ($op) {
- case 'load':
- $output['taxonomy'] = taxonomy_node_get_terms($node);
- return $output;
+function taxonomy_nodeapi_load($node, $arg = 0) {
+ $output['taxonomy'] = taxonomy_node_get_terms($node);
+ return $output;
+}
- case 'insert':
- if (!empty($node->taxonomy)) {
- taxonomy_node_save($node, $node->taxonomy);
- }
- break;
+/**
+ * Implementation of hook_nodeapi_insert().
+ */
+function taxonomy_nodeapi_insert($node, $arg = 0) {
+ if (!empty($node->taxonomy)) {
+ taxonomy_node_save($node, $node->taxonomy);
+ }
+}
- case 'update':
- if (!empty($node->taxonomy)) {
- taxonomy_node_save($node, $node->taxonomy);
- }
- break;
+/**
+ * Implementation of hook_nodeapi_update().
+ */
+function taxonomy_nodeapi_update($node, $arg = 0) {
+ if (!empty($node->taxonomy)) {
+ taxonomy_node_save($node, $node->taxonomy);
+ }
+}
- case 'delete':
- taxonomy_node_delete($node);
- break;
+/**
+ * Implementation of hook_nodeapi_delete().
+ */
+function taxonomy_nodeapi_delete($node, $arg = 0) {
+ taxonomy_node_delete($node);
+}
- case 'delete revision':
- taxonomy_node_delete_revision($node);
- break;
+/**
+ * Implementation of hook_nodeapi_delete_revision().
+ */
+function taxonomy_nodeapi_delete_revision($node, $arg = 0) {
+ taxonomy_node_delete_revision($node);
+}
- case 'validate':
- taxonomy_node_validate($node);
- break;
+/**
+ * Implementation of hook_nodeapi_validate().
+ */
+function taxonomy_nodeapi_validate($node, $arg = 0) {
+ taxonomy_node_validate($node);
+}
- case 'rss item':
- return taxonomy_rss_item($node);
+/**
+ * Implementation of hook_nodeapi_rss_item().
+ */
+function taxonomy_nodeapi_rss_item($node, $arg = 0) {
+ return taxonomy_rss_item($node);
+}
- case 'update index':
- return taxonomy_node_update_index($node);
- }
+/**
+ * Implementation of hook_nodeapi_update_index().
+ */
+function taxonomy_nodeapi_update_index($node, $arg = 0) {
+ return taxonomy_node_update_index($node);
}
/**
diff --git a/modules/translation/translation.module b/modules/translation/translation.module
index 79d746e6d..c91a556f2 100644
--- a/modules/translation/translation.module
+++ b/modules/translation/translation.module
@@ -181,65 +181,75 @@ function translation_link($type, $node = NULL, $teaser = FALSE) {
}
/**
- * Implementation of hook_nodeapi().
- *
- * Manages translation information for nodes.
+ * Implementation of hook_nodeapi_prepare().
*/
-function translation_nodeapi(&$node, $op, $teaser, $page) {
+function translation_nodeapi_prepare(&$node, $teaser, $page) {
// Only act if we are dealing with a content type supporting translations.
- if (!translation_supported_type($node->type)) {
- return;
+ if (translation_supported_type($node->type)) {
+ if (empty($node->nid) && isset($_GET['translation']) && isset($_GET['language']) &&
+ ($source_nid = $_GET['translation']) && ($language = $_GET['language']) &&
+ (user_access('translate content'))) {
+ // We are translating a node from a source node, so
+ // load the node to be translated and populate fields.
+ $node->language = $language;
+ $node->translation_source = node_load($source_nid);
+ $node->title = $node->translation_source->title;
+ $node->body = $node->translation_source->body;
+ // Let every module add custom translated fields.
+ node_invoke_nodeapi($node, 'prepare translation');
+ }
}
+}
- switch ($op) {
- case 'prepare':
- if (empty($node->nid) && isset($_GET['translation']) && isset($_GET['language']) &&
- ($source_nid = $_GET['translation']) && ($language = $_GET['language']) &&
- (user_access('translate content'))) {
- // We are translating a node from a source node, so
- // load the node to be translated and populate fields.
- $node->language = $language;
- $node->translation_source = node_load($source_nid);
- $node->title = $node->translation_source->title;
- $node->body = $node->translation_source->body;
- // Let every module add custom translated fields.
- node_invoke_nodeapi($node, 'prepare translation');
+/**
+ * Implementation of hook_nodeapi_insert().
+ */
+function translation_nodeapi_insert(&$node, $teaser, $page) {
+ // Only act if we are dealing with a content type supporting translations.
+ if (translation_supported_type($node->type)) {
+ if (!empty($node->translation_source)) {
+ if ($node->translation_source->tnid) {
+ // Add node to existing translation set.
+ $tnid = $node->translation_source->tnid;
}
- break;
-
- case 'insert':
- if (!empty($node->translation_source)) {
- if ($node->translation_source->tnid) {
- // Add node to existing translation set.
- $tnid = $node->translation_source->tnid;
- }
- else {
- // Create new translation set, using nid from the source node.
- $tnid = $node->translation_source->nid;
- db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->translation_source->nid);
- }
- db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->nid);
+ else {
+ // Create new translation set, using nid from the source node.
+ $tnid = $node->translation_source->nid;
+ db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->translation_source->nid);
}
- break;
+ db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->nid);
+ }
+ }
+}
- case 'update':
- if (isset($node->translation) && $node->translation && !empty($node->language) && $node->tnid) {
- // Update translation information.
- db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $node->tnid, $node->translation['status'], $node->nid);
- if (!empty($node->translation['retranslate'])) {
- // This is the source node, asking to mark all translations outdated.
- db_query("UPDATE {node} SET translate = 1 WHERE tnid = %d AND nid <> %d", $node->tnid, $node->nid);
- }
+/**
+ * Implementation of hook_nodeapi_update().
+ */
+function translation_nodeapi_update(&$node, $teaser, $page) {
+ // Only act if we are dealing with a content type supporting translations.
+ if (translation_supported_type($node->type)) {
+ if (isset($node->translation) && $node->translation && !empty($node->language) && $node->tnid) {
+ // Update translation information.
+ db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $node->tnid, $node->translation['status'], $node->nid);
+ if (!empty($node->translation['retranslate'])) {
+ // This is the source node, asking to mark all translations outdated.
+ db_query("UPDATE {node} SET translate = 1 WHERE tnid = %d AND nid <> %d", $node->tnid, $node->nid);
}
- break;
-
- case 'delete':
- translation_remove_from_set($node);
- break;
+ }
}
}
/**
+ * Implementation of hook_nodeapi_delete().
+ */
+function translation_nodeapi_delete(&$node, $teaser, $page) {
+ // Only act if we are dealing with a content type supporting translations.
+ if (translation_supported_type($node->type)) {
+ translation_remove_from_set($node);
+ }
+}
+
+/**
* Remove a node from its translation set (if any)
* and update the set accordingly.
*/
diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module
index e59d33851..bc127a8b4 100644
--- a/modules/trigger/trigger.module
+++ b/modules/trigger/trigger.module
@@ -200,9 +200,11 @@ function _trigger_normalize_node_context($type, $node) {
}
/**
- * Implementation of hook_nodeapi().
+ * Simple wrapper function to make user hooks work with new entry points.
+ *
+ * @TODO: Take advantage of the new API and reorganise/remove this function.
*/
-function trigger_nodeapi(&$node, $op, $a3, $a4) {
+function _trigger_nodeapi(&$node, $op, $a3, $a4) {
// Keep objects for reuse so that changes actions make to objects can persist.
static $objects;
// Prevent recursion by tracking which operations have already been called.
@@ -239,6 +241,41 @@ function trigger_nodeapi(&$node, $op, $a3, $a4) {
}
}
}
+
+/**
+ * Implementation of hook_nodeapi_view().
+ */
+function trigger_nodeapi_view(&$node, $a3, $a4) {
+ _trigger_nodeapi($node, 'view', $a3, $a4);
+}
+
+/**
+ * Implementation of hook_nodeapi_update().
+ */
+function trigger_nodeapi_update(&$node, $a3, $a4) {
+ _trigger_nodeapi($node, 'update', $a3, $a4);
+}
+
+/**
+ * Implementation of hook_nodeapi_presave().
+ */
+function trigger_nodeapi_presave(&$node, $a3, $a4) {
+ _trigger_nodeapi($node, 'presave', $a3, $a4);
+}
+
+/**
+ * Implementation of hook_nodeapi_insert().
+ */
+function trigger_nodeapi_insert(&$node, $a3, $a4) {
+ _trigger_nodeapi($node, 'insert', $a3, $a4);
+}
+
+/**
+ * Implementation of hook_nodeapi_delete().
+ */
+function trigger_nodeapi_delete(&$node, $a3, $a4) {
+ _trigger_nodeapi($node, 'delete', $a3, $a4);
+}
/**
* When an action is called in a context that does not match its type,
diff --git a/modules/upload/upload.module b/modules/upload/upload.module
index a2bfac99c..7f989bfb9 100644
--- a/modules/upload/upload.module
+++ b/modules/upload/upload.module
@@ -263,90 +263,115 @@ function upload_form_alter(&$form, $form_state, $form_id) {
}
/**
- * Implementation of hook_nodeapi().
+ * Implementation of hook_nodeapi_load().
*/
-function upload_nodeapi(&$node, $op, $teaser) {
- switch ($op) {
-
- case 'load':
- $output = '';
- if (variable_get("upload_$node->type", 1) == 1) {
- $output['files'] = upload_load($node);
- return $output;
- }
- break;
-
- case 'view':
- if (isset($node->files) && user_access('view uploaded files')) {
- // Add the attachments list to node body with a heavy
- // weight to ensure they're below other elements
- if (count($node->files)) {
- if (!$teaser && user_access('view uploaded files')) {
- $node->content['files'] = array(
- '#markup' => theme('upload_attachments', $node->files),
- '#weight' => 50,
- );
- }
- }
- }
- break;
-
- case 'prepare':
- // Initialize $_SESSION['upload_files'] if no post occurred.
- // This clears the variable from old forms and makes sure it
- // is an array to prevent notices and errors in other parts
- // of upload.module.
- if (!$_POST) {
- $_SESSION['upload_files'] = array();
- }
- break;
+function upload_nodeapi_load(&$node, $teaser) {
+ if (variable_get("upload_$node->type", 1) == 1) {
+ $output = array('files' => upload_load($node));
+ return $output;
+ }
+}
- case 'insert':
- case 'update':
- if (user_access('upload files')) {
- upload_save($node);
- }
- break;
-
- case 'delete':
- upload_delete($node);
- break;
-
- case 'delete revision':
- upload_delete_revision($node);
- break;
-
- case 'search result':
- return isset($node->files) && is_array($node->files) ? format_plural(count($node->files), '1 attachment', '@count attachments') : NULL;
-
- case 'rss item':
- if (is_array($node->files)) {
- $files = array();
- foreach ($node->files as $file) {
- if ($file->list) {
- $files[] = $file;
- }
- }
- if (count($files) > 0) {
- // RSS only allows one enclosure per item
- $file = array_shift($files);
- return array(
- array(
- 'key' => 'enclosure',
- 'attributes' => array(
- 'url' => file_create_url($file->filepath),
- 'length' => $file->filesize,
- 'type' => $file->filemime
- )
- )
- );
- }
+/**
+ * Implementation of hook_nodeapi_view().
+ */
+function upload_nodeapi_view(&$node, $teaser) {
+ if (isset($node->files) && user_access('view uploaded files')) {
+ // Add the attachments list to node body with a heavy
+ // weight to ensure they're below other elements
+ if (count($node->files)) {
+ if (!$teaser && user_access('view uploaded files')) {
+ $node->content['files'] = array(
+ '#markup' => theme('upload_attachments', $node->files),
+ '#weight' => 50,
+ );
}
- return array();
+ }
+ }
+}
+
+/**
+ * Implementation of hook_nodeapi_prepare().
+ */
+function upload_nodeapi_prepare(&$node, $teaser) {
+ // Initialize $_SESSION['upload_files'] if no post occurred.
+ // This clears the variable from old forms and makes sure it
+ // is an array to prevent notices and errors in other parts
+ // of upload.module.
+ if (!$_POST) {
+ $_SESSION['upload_files'] = array();
+ }
+}
+
+/**
+ * Implementation of hook_nodeapi_insert().
+ */
+function upload_nodeapi_insert(&$node, $teaser) {
+ if (user_access('upload files')) {
+ upload_save($node);
}
}
/**
+ * Implementation of hook_nodeapi_update().
+ */
+function upload_nodeapi_update(&$node, $teaser) {
+ if (user_access('upload files')) {
+ upload_save($node);
+ }
+}
+
+/**
+ * Implementation of hook_nodeapi_delete().
+ */
+function upload_nodeapi_delete(&$node, $teaser) {
+ upload_delete($node);
+}
+
+/**
+ * Implementation of hook_nodeapi_delete_revision().
+ */
+function upload_nodeapi_delete_revision(&$node, $teaser) {
+ upload_delete_revision($node);
+}
+
+/**
+ * Implementation of hook_nodeapi_search_result().
+ */
+function upload_nodeapi_search_result(&$node, $teaser) {
+ return isset($node->files) && is_array($node->files) ? format_plural(count($node->files), '1 attachment', '@count attachments') : NULL;
+}
+
+/**
+ * Implementation of hook_nodeapi_rss_item().
+ */
+function upload_nodeapi_rss_item(&$node, $teaser) {
+ if (is_array($node->files)) {
+ $files = array();
+ foreach ($node->files as $file) {
+ if ($file->list) {
+ $files[] = $file;
+ }
+ }
+ if (count($files) > 0) {
+ // RSS only allows one enclosure per item
+ $file = array_shift($files);
+ return array(
+ array(
+ 'key' => 'enclosure',
+ 'attributes' => array(
+ 'url' => file_create_url($file->filepath),
+ 'length' => $file->filesize,
+ 'type' => $file->filemime
+ )
+ )
+ );
+ }
+ }
+ return array();
+}
+
+/**
* Displays file attachments in table
*
* @ingroup themeable