Commit 87567f89 authored by Dries's avatar Dries

- Patch #310212 by justinrandell: killed in _node hook, as well as twelve sable tooth tigers.

parent 026af5df
...@@ -221,7 +221,7 @@ function blogapi_blogger_new_post($appkey, $blogid, $username, $password, $conte ...@@ -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'); $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); node_validate($edit);
if ($errors = form_get_errors()) { if ($errors = form_get_errors()) {
...@@ -273,7 +273,7 @@ function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $cont ...@@ -273,7 +273,7 @@ function blogapi_blogger_edit_post($appkey, $postid, $username, $password, $cont
$node->body = $content; $node->body = $content;
} }
node_invoke_nodeapi($node, 'blogapi edit'); node_invoke_nodeapi($node, 'blogapi_edit');
node_validate($node); node_validate($node);
if ($errors = form_get_errors()) { if ($errors = form_get_errors()) {
......
...@@ -668,110 +668,132 @@ function book_build_active_trail($book_link) { ...@@ -668,110 +668,132 @@ function book_build_active_trail($book_link) {
} }
/** /**
* Implementation of hook_nodeapi(). * Implementation of hook_nodeapi_load().
*
* Appends book navigation to all nodes in the book, and handles book outline
* insertions and updates via the node form.
*/ */
function book_nodeapi(&$node, $op, $teaser, $page) { function book_nodeapi_load(&$node, $teaser, $page) {
switch ($op) { // Note - we cannot use book_link_load() because it will call node_load().
case '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));
// 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']) { if ($info['book']) {
$info['book']['href'] = $info['book']['link_path']; $info['book']['href'] = $info['book']['link_path'];
$info['book']['title'] = $info['book']['link_title']; $info['book']['title'] = $info['book']['link_title'];
$info['book']['options'] = unserialize($info['book']['options']); $info['book']['options'] = unserialize($info['book']['options']);
return $info;
}
break;
case 'view': return $info;
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;
case 'presave': /**
// Always save a revision for non-administrators. * Implementation of hook_nodeapi_view().
if (!empty($node->book['bid']) && !user_access('administer nodes')) { */
$node->revision = 1; function book_nodeapi_view(&$node, $teaser, $page) {
} if (!$teaser) {
// Make sure a new node gets a new menu link. if (!empty($node->book['bid']) && $node->build_mode == NODE_BUILD_NORMAL) {
if (empty($node->nid)) { $node->content['book_navigation'] = array(
$node->book['mlid'] = NULL; '#markup' => theme('book_navigation', $node->book),
} '#weight' => 100,
break; );
case 'insert': if ($page) {
case 'update': menu_set_active_trail(book_build_active_trail($node->book));
if (!empty($node->book['bid'])) { menu_set_active_menu_name($node->book['menu_name']);
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);
} }
break; }
}
}
case 'delete': /**
if (!empty($node->book['bid'])) { * Implementation of hook_nodeapi_presave().
if ($node->nid == $node->book['bid']) { */
// Handle deletion of a top-level post. function book_nodeapi_presave(&$node, $teaser, $page) {
$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']); // Always save a revision for non-administrators.
while ($child = db_fetch_array($result)) { if (!empty($node->book['bid']) && !user_access('administer nodes')) {
$child_node = node_load($child['nid']); $node->revision = 1;
$child_node->book['bid'] = $child_node->nid; }
_book_update_outline($child_node); // Make sure a new node gets a new menu link.
} if (empty($node->nid)) {
} $node->book['mlid'] = NULL;
menu_link_delete($node->book['mlid']); }
db_query('DELETE FROM {book} WHERE mlid = %d', $node->book['mlid']); }
}
break;
case 'prepare': /**
// Prepare defaults for the add/edit form. * Implementation of hook_nodeapi_insert().
if (empty($node->book) && (user_access('add content to books') || user_access('administer book outlines'))) { */
$node->book = array(); 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: * Implementation of hook_nodeapi_update().
$parent = book_link_load($_GET['parent']); */
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']; * Implementation of hook_nodeapi_delete().
$node->book['plid'] = $parent['mlid']; */
$node->book['menu_name'] = $parent['menu_name']; function book_nodeapi_delete(&$node, $teaser, $page) {
} if (!empty($node->book['bid'])) {
} if ($node->nid == $node->book['bid']) {
// Set defaults. // Handle deletion of a top-level post.
$node->book += _book_link_defaults(!empty($node->nid) ? $node->nid : 'new'); $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)) {
else { $child_node = node_load($child['nid']);
if (isset($node->book['bid']) && !isset($node->book['original_bid'])) { $child_node->book['bid'] = $child_node->nid;
$node->book['original_bid'] = $node->book['bid']; _book_update_outline($child_node);
}
} }
// Find the depth limit for the parent select. }
if (isset($node->book['bid']) && !isset($node->book['parent_depth_limit'])) { menu_link_delete($node->book['mlid']);
$node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book); 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);
} }
} }
......
...@@ -552,50 +552,68 @@ function comment_form_alter(&$form, $form_state, $form_id) { ...@@ -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) { function comment_nodeapi_load(&$node, $arg = 0) {
switch ($op) { if ($node->comment != COMMENT_NODE_DISABLED) {
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));
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);
} }
return array('last_comment_timestamp' => $node->created, 'last_comment_name' => '', 'comment_count' => 0);
case 'prepare': /**
if (!isset($node->comment)) { * Implementation of hook_nodeapi_prepare().
$node->comment = variable_get("comment_$node->type", COMMENT_NODE_READ_WRITE); */
} function comment_nodeapi_prepare(&$node, $arg = 0) {
break; 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); * Implementation of hook_nodeapi_insert().
break; */
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); * Implementation of hook_nodeapi_delete().
db_query('DELETE FROM {node_comment_statistics} WHERE nid = %d', $node->nid); */
break; 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 = ''; * Implementation of hook_nodeapi_update_index().
$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)) { function comment_nodeapi_update_index(&$node, $arg = 0) {
$text .= '<h2>' . check_plain($comment->subject) . '</h2>' . check_markup($comment->comment, $comment->format, FALSE); $text = '';
} $comments = db_query('SELECT subject, comment, format FROM {comments} WHERE nid = %d AND status = %d', $node->nid, COMMENT_PUBLISHED);
return $text; 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)); * Implementation of hook_nodeapi_search_result().
return format_plural($comments, '1 comment', '@count comments'); */
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) { * Implementation of hook_nodeapi_rss_item().
return array(array('key' => 'comments', 'value' => url('node/' . $node->nid, array('fragment' => 'comments', 'absolute' => TRUE)))); */
} function comment_nodeapi_rss_item(&$node, $arg = 0) {
else { if ($node->comment != COMMENT_NODE_DISABLED) {
return array(); return array(array('key' => 'comments', 'value' => url('node/' . $node->nid, array('fragment' => 'comments', 'absolute' => TRUE))));
} }
else {
return array();
} }
} }
......
This diff is collapsed.
...@@ -277,65 +277,90 @@ function menu_block($op = 'list', $delta = '') { ...@@ -277,65 +277,90 @@ function menu_block($op = 'list', $delta = '') {
} }
/** /**
* Implementation of hook_nodeapi(). * Implementation of hook_nodeapi_insert().
*/ */
function menu_nodeapi(&$node, $op) { function menu_nodeapi_insert(&$node) {
switch ($op) { if (isset($node->menu)) {
case 'insert': $item = $node->menu;
case 'update': if (!empty($item['delete'])) {
if (isset($node->menu)) { menu_link_delete($item['mlid']);
$item = $node->menu; }
if (!empty($item['delete'])) { elseif (trim($item['link_title'])) {
menu_link_delete($item['mlid']); $item['link_title'] = trim($item['link_title']);
} $item['link_path'] = "node/$node->nid";
elseif (trim($item['link_title'])) { if (!$item['customized']) {
$item['link_title'] = trim($item['link_title']); $item['options']['attributes']['title'] = trim($node->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');
}
}
} }
break; if (!menu_link_save($item)) {
case 'delete': drupal_set_message(t('There was an error saving the menu link.'), 'error');
// 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']);
} }
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(); * Implementation of hook_nodeapi_update().
if (isset($node->nid)) { */
// Give priority to the default menu function menu_nodeapi_update(&$node) {
$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( if (isset($node->menu)) {
':path' => 'node/'. $node->nid, $item = $node->menu;
':menu_name' => $menu_name, if (!empty($item['delete'])) {
), 0, 1)); menu_link_delete($item['mlid']);
// Check all menus if a link does not exist in the default menu. }
if (!$mlid) { elseif (trim($item['link_title'])) {
$mlid = db_result(db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", array( $item['link_title'] = trim($item['link_title']);
':path' => 'node/'. $node->nid, $item['link_path'] = "node/$node->nid";
), 0, 1)); if (!$item['customized']) {
} $item['options']['attributes']['title'] = trim($node->title);
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 (!menu_link_save($item)) {
if (!isset($node->menu['parent_depth_limit'])) { drupal_set_message(t('There was an error saving the menu link.'), 'error');
$node->menu['parent_depth_limit'] = _menu_parent_depth_limit($node->menu);
} }
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);
} }
} }
......
...@@ -704,9 +704,10 @@ function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { ...@@ -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) { function node_invoke_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
$return = array(); $return = array();
foreach (module_implements('nodeapi') as $name) { $hook = 'nodeapi_' . $op;
$function = $name . '_nodeapi'; foreach (module_implements($hook) as $name) {
$result = $function($node, $op, $a3, $a4); $function = $name . '_' . $hook;
$result = $function($node, $a3, $a4);
if (isset($result) && is_array($result)) { if (isset($result) && is_array($result)) {
$return = array_merge($return, $result); $return = array_merge($return, $result);
} }
...@@ -1321,9 +1322,9 @@ function node_search($op = 'search', $keys = NULL) { ...@@ -1321,9 +1322,9 @@ function node_search($op = 'search', $keys = NULL) {
$node->body = drupal_render($node->content); $node->body = drupal_render($node->content);
// Fetch comments for snippet. // 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. // 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'); $extra = node_invoke_nodeapi($node, 'search result');
...@@ -1742,7 +1743,7 @@ function node_feed($nids = FALSE, $channel = array()) { ...@@ -1742,7 +1743,7 @@ function node_feed($nids = FALSE, $channel = array()) {
} }
// Allow modules to add additional item fields and/or modify $item // 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')))); $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) { foreach ($extra as $element) {
if (isset($element['namespace'])) { if (isset($element['namespace'])) {
......
...@@ -576,7 +576,7 @@ function node_revision_delete_confirm($form_state, $node_revision) { ...@@ -576,7 +576,7 @@ function node_revision_delete_confirm($form_state, $node_revision) {
function node_revision_delete_confirm_submit($form, &$form_state) { function node_revision_delete_confirm_submit($form, &$form_state) {
$node_revision = $form['#node_revision']; $node_revision = $form['#node_revision'];
db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node_revision->nid, $node_revision->vid); 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)); 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))); 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; $form_state['redirect'] = 'node/' . $node_revision->nid;
......
...@@ -117,53 +117,66 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = '' ...@@ -117,53 +117,66 @@ function path_set_alias($path = NULL, $alias = NULL, $pid = NULL, $language = ''
drupal_clear_path_cache(); drupal_clear_path_cache();
} }
/** /**
* Implementation of hook_nodeapi(). * Implementation of hook_nodeapi_validate().
*
* 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_nodeapi_validate(&$node, $arg) {
// Permissions are required for everything except node loading. if (user_access('create url aliases') || user_access('administer url aliases')) {
if (user_access('create url aliases') || user_access('administer url aliases') || ($op == 'load')) { if (isset($node->path)) {
$language = isset($node->language) ? $node->language : ''; $language = isset($node->language) ? $node->language : '';
switch ($op) { $node->path = trim($node->path);
case 'validate': 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))) {
if (isset($node->path)) { form_set_error('path', t('The path is already in use.'));
$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;
case 'load': /**
$path = 'node/' . $node->nid; * Implementation of hook_nodeapi_load().
$alias = drupal_get_path_alias($path, $language); */
if ($path != $alias) { function path_nodeapi_load(&$node, $arg) {
$node->path = $alias; $language = isset($node->language) ? $node->language : '';
} $path = 'node/' . $node->nid;
break; $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 * Implementation of hook_nodeapi_insert().
// the alias ahead of time. */
if (isset($node->path)) { function path_nodeapi_insert(&$node, $arg) {
path_set_alias('node/' . $node->nid, $node->path, NULL, $language); if (user_access('create url aliases') || user_access('administer url aliases')) {
} $language = isset($node->language) ? $node->language : '';
break; // 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->