=== modified file 'wikitools.module' --- wikitools.module 2008-02-25 09:23:00 +0000 +++ wikitools.module 2008-03-28 15:27:13 +0000 @@ -103,6 +103,13 @@ '#multiple' => TRUE, '#description' => t('Select the node types which will be affected by the specified options. If you select multiple node types, all nodes of these types will be searched for when a wikipath is entered. If a wikipage doesn\'t exist, an option to create any of these types will be given.'), ); + $form['wikitools_node_create_aliases'] = array( + '#type' => 'checkbox', + '#title' => t('Automatically create aliases for the wiki node types'), + '#default_value' => variable_get('wikitools_node_create_aliases', FALSE), + '#disabled' => !module_exists('path'), + '#description' => t('Using this option will cause wikitools to automatically create aliases based on the node title. If you use Pathauto, please disable it for wiki node types. You can do this by clearing both the default pattern and the pattern for each affected node type.'), + ); $form['wikitools_options'] = array( '#type' => 'checkboxes', '#title' => t('Options'), @@ -486,6 +493,13 @@ case 'validate': wikitools_node_validate($node); break; + case 'insert': + case 'update': + if (variable_get('wikitools_node_create_aliases', FALSE)) + { + wikitools_node_create_alias($node); + } + break; } } @@ -541,6 +555,33 @@ } /** + * Generate aliases for wiki node types. + */ +function wikitools_node_create_alias($node) +{ + if (wikitools_type_affected($node->type)) { + $src = "node/".$node->nid; + $dst = wikitools_wikilink_drupal_path($node->title); + + $pid = NULL; + $old_alias = NULL; + + // look-up the old alias, if there is one. + $result = db_query("SELECT pid, dst FROM {url_alias} WHERE src='%s'", $src); + if ($data = db_fetch_object($result)) { + $pid = $data->pid; + $old_alias = $data->dst; + } + + // If the alias is changed or new, then set it! + if ($dst != $old_alias) + { + path_set_alias($src, $dst, $pid); + } + } +} + +/** * Implementation of hook_form_alter(). */ function wikitools_form_alter($form_id, &$form) {