function path_nodeapi in Drupal 5
Same name and namespace in other branches
- 4 modules/path.module \path_nodeapi()
- 6 modules/path/path.module \path_nodeapi()
Implementation of hook_nodeapi().
Allows URL aliases for nodes to be specified at node edit time rather than through the administrative interface.
File
- modules/
path/ path.module, line 212 - Enables users to rename URLs.
Code
function path_nodeapi(&$node, $op, $arg) {
if (user_access('create url aliases') || user_access('administer url aliases') || $op == 'load') {
switch ($op) {
case 'validate':
$node->path = trim($node->path);
if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s'", $node->path, "node/{$node->nid}"))) {
form_set_error('path', t('The path is already in use.'));
}
break;
case 'load':
$path = "node/{$node->nid}";
// We don't use drupal_get_path_alias() to avoid custom rewrite functions.
// We only care about exact aliases.
$result = db_query("SELECT dst FROM {url_alias} WHERE src = '%s'", $path);
if (db_num_rows($result)) {
$node->path = db_result($result);
}
break;
case 'insert':
// Don't try to insert if path is NULL. We may have already set
// the alias ahead of time.
if ($node->path) {
path_set_alias("node/{$node->nid}", $node->path);
}
break;
case 'update':
path_set_alias("node/{$node->nid}", $node->path, $node->pid);
break;
case 'delete':
$path = "node/{$node->nid}";
if (drupal_get_path_alias($path) != $path) {
path_set_alias($path);
}
break;
}
}
}