diff -up ./pathauto.inc ../pathauto6x/pathauto.inc --- ./pathauto.inc 2008-06-08 00:53:31.000000000 +0200 +++ ../pathauto6x/pathauto.inc 2008-05-30 02:47:59.000000000 +0200 @@ -343,13 +343,11 @@ function pathauto_create_alias($module, * TRUE if the path already exists. */ function _pathauto_path_is_callback($path) { - static $menu = NULL; - if (is_null($menu)) { - $menu = menu_get_menu(); + $menu = menu_get_item($path); + if (isset($menu['path']) && $menu['path'] == $path) { + return TRUE; } - - // Determine the menu item containing the callback. - return isset($menu["callbacks"][$path]); + return FALSE; } /** diff -up ./pathauto.js ../pathauto6x/pathauto.js --- ./pathauto.js 2008-06-07 12:53:41.000000000 +0200 +++ ../pathauto6x/pathauto.js 2008-03-06 03:56:05.000000000 +0100 @@ -2,21 +2,21 @@ if (Drupal.jsEnabled) { $(document).ready(function() { if ($("#edit-pathauto-perform-alias").size() && $("#edit-pathauto-perform-alias").attr("checked")) { // Disable input and hide its description. $("#edit-path").attr("disabled","disabled"); - $("//#edit-path ~ div[@class=description]").hide(0); + $("#edit-path-wrapper > div.description").hide(0); } $("#edit-pathauto-perform-alias").bind("click", function() { if ($("#edit-pathauto-perform-alias").attr("checked")) { // Auto-alias checked; disable input. $("#edit-path").attr("disabled","disabled"); - $("//#edit-path ~ div[@class=description]").slideUp('slow'); + $("#edit-path-wrapper > div[@class=description]").slideUp('fast'); } else { // Auto-alias unchecked; enable input. $("#edit-path").removeAttr("disabled"); $("#edit-path")[0].focus(); - $("//#edit-path ~ div[@class=description]").slideDown('slow'); + $("#edit-path-wrapper > div[@class=description]").slideDown('fast'); } }); }); diff -up ./pathauto.module ../pathauto6x/pathauto.module --- ./pathauto.module 2008-06-08 00:53:31.000000000 +0200 +++ ../pathauto6x/pathauto.module 2008-06-08 00:57:10.000000000 +0200 @@ -134,16 +133,9 @@ function pathauto_token_values($type, $o } $values[$label .'path'] = $catpath .'/'. check_plain($category->name); $values[$label .'path-raw'] = $catpath_raw .'/'. $category->name; - - // We only do this for taxonomy because token already provides the [term] value but has problem with [cat] TODO: fix that? - if ($type == 'taxonomy') { - $values[$label] = check_plain($category->name); - $values[$label .'-raw'] = $category->name; - } - $values[$label .'alias'] = drupal_get_path_alias('taxonomy/term/'. $category->tid); if (!strncasecmp($values[$label .'alias'], 'taxonomy', 8)) { - $values[$label .'alias'] = $values[$label]; + $values[$label .'alias'] = check_plain($category->name); } } else { // Provide some defaults if they aren't set. @@ -215,12 +207,30 @@ function pathauto_nodeapi(&$node, $op, $ _pathauto_include(); if (module_exists('path')) { switch ($op) { + case 'presave': + // About to be saved (before insert/update) + if (isset($node->pathauto_perform_alias) && isset($node->old_alias) + && $node->pathauto_perform_alias && $node->path == '' && $node->old_alias != '') { + /** + * There was an old alias, but when pathauto_perform_alias was checked + * the javascript disabled the textbox which led to an empty value being + * submitted. Restoring the old path-value here prevents the Path module + * from deleting any old alias before Pathauto gets control. + */ + $node->path = $node->old_alias; + } + break; case 'insert': case 'update': // Get the specific pattern or the default - $pattern = variable_get('pathauto_node_'. $node->type .'_pattern', FALSE); - if (!$pattern) { - $pattern = variable_get('pathauto_node_pattern', FALSE); + if (!empty($node->language)) { + $pattern = variable_get('pathauto_node_'. $node->type .'_'. $node->language .'_pattern', FALSE); + } + if (!trim($pattern)) { + $pattern = variable_get('pathauto_node_'. $node->type .'_pattern', FALSE); + if (!trim($pattern)) { + $pattern = variable_get('pathauto_node_pattern', FALSE); + } } // Only do work if there's a pattern if ($pattern) { @@ -249,30 +259,41 @@ function pathauto_nodeapi(&$node, $op, $ * own aliases (Pathauto will be invisible to other users). Inserted * into the path module's fieldset in the node form. */ -function pathauto_form_alter($formid, &$form) { +function pathauto_form_alter(&$form, $form_state, $form_id) { // Only do this for node forms if (isset($form['#id']) && ($form['#id'] == 'node-form') && arg(0) == 'node') { // See if there is a pathauto pattern or default applicable - $pattern = variable_get('pathauto_node_'. $form['type']['#value'] .'_pattern', FALSE); - if (!$pattern) { - $pattern = variable_get('pathauto_node_pattern', FALSE); + if (isset($form['language'])) { + $language = isset($form['language']['#value']) ? $form['language']['#value'] : $form['language']['#default_value']; + $pattern = variable_get('pathauto_node_'. $form['type']['#value'] .'_'. $language .'_pattern', FALSE); + } + if (!trim($pattern)) { + $pattern = variable_get('pathauto_node_'. $form['type']['#value'] .'_pattern', FALSE); + if (!trim($pattern)) { + $pattern = variable_get('pathauto_node_pattern', FALSE); + } } // If there is a pattern AND the user is allowed to create aliases AND the path textbox is present on this form if ($pattern && user_access('create url aliases') && isset($form['path']['path'])) { $output = t('An alias will be generated for you. If you wish to create your own alias below, untick this option.'); if (user_access('administer pathauto')) { - $output .= t(' To control the format of the generated aliases, see the Pathauto settings.', array('@pathauto' => url('admin/settings/pathauto'))); + $output .= t(' To control the format of the generated aliases, see the Pathauto settings.', array('@pathauto' => url('admin/build/path/pathauto'))); } drupal_add_js(drupal_get_path('module', 'pathauto') .'/pathauto.js'); + $form['path']['#collapsed'] = FALSE; $form['path']['pathauto_perform_alias'] = array( '#type' => 'checkbox', '#title' => t('Automatic alias'), '#default_value' => TRUE, '#description' => $output, - '#weight' => 0 + '#weight' => -1, ); + + //For Pathauto to remember the old alias and prevent the Path-module from deleteing it when Pathauto wants to preserve it + $old_alias = $form['path']['path']['#default_value']; + $form['path']['old_alias'] = array('#type' => 'value', '#value' => $old_alias); } } } @@ -366,9 +387,9 @@ function pathauto_user($op, &$edit, &$us if (module_exists('blog')) { $new_user = $user; - $new_user->roles = isset($edit['roles']) ? $edit['roles'] : array(); + $new_user->roles = isset($edit['roles']) ? $edit['roles']: array(); $new_user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user'; // Add this back - if (user_access('edit own blog', $new_user)) { + if (user_access('create blog entries', $new_user)) { $src = 'blog/'. $user->uid; $alias = pathauto_create_alias('blog', $op, $placeholders, $src, $user->uid); } @@ -602,7 +629,6 @@ function pathauto_admin_settings() { if (isset($settings->patternitems)) { foreach ($settings->patternitems as $itemname => $itemlabel) { $variable = 'pathauto_'. $module .'_'. $itemname .'_pattern'; - $description = ''; if (!count($_POST)) { $error = _pathauto_check_pattern(variable_get($variable, $patterndefault), $settings->token_type); if ($error) { @@ -771,7 +797,7 @@ function pathauto_admin_settings_validat } /** - * Menu callback: select certain alias types to delete. + * Menu callback; select certain alias types to delete. */ function pathauto_admin_delete() { /* TODO: diff -up ./pathauto_node.inc ../pathauto6x/pathauto_node.inc --- ./pathauto_node.inc 2008-06-08 00:53:31.000000000 +0200 +++ ../pathauto6x/pathauto_node.inc 2008-05-28 18:04:35.000000000 +0200 @@ -32,9 +32,15 @@ function node_pathauto($op) { } } $settings['supportsfeeds'] = 'feed'; + + $languages = module_exists('locale') ? locale_language_list() : array(); foreach (node_get_types('names') as $node_type => $node_name) { $fieldlabel = t('Pattern for all @node_type paths', array('@node_type' => $node_name)); $settings['patternitems'][$node_type] = $fieldlabel; + foreach ($languages as $lang_code => $lang_name) { + $fieldlabel = t('Pattern for all @node_type paths in @language', array('@node_type' => $node_name, '@language' => $lang_name)); + $settings['patternitems'][$node_type .'_'. $lang_code] = $fieldlabel; + } } return (object) $settings; default: @@ -49,45 +55,49 @@ function node_pathauto_bulkupdate() { // From all node types, only attempt to update those with patterns $pattern_types = array(); - $type_where = ''; - foreach (node_get_types() as $type => $info) { - $pattern = ''; - $pattern = variable_get('pathauto_node_'. $type .'_pattern', ''); - - // If it's not set, check the default - if (!trim($pattern)) { - $pattern = variable_get('pathauto_node_pattern', ''); - } - if (trim($pattern)) { - $pattern_types[] = $type; - if (!trim($type_where)) { - $type_where = " AND (type = '%s' "; + + // If there's a default pattern we assume all types might be updated. + if (trim(variable_get('pathauto_node_pattern', ''))) { + $pattern_types = array_keys(node_get_types('names')); + } + else { + // Check first for a node specific pattern... + $languages = module_exists('locale') ? locale_language_list() : array(); + foreach (array_keys(node_get_types('names')) as $type) { + if (trim(variable_get('pathauto_node_'. $type .'_pattern', ''))) { + $pattern_types[$type] = $type; + continue; } - else { - $type_where .= " OR type = '%s'"; + // ...then for a node-language pattern. + foreach ($languages as $lang_code => $lang_name) { + if (trim(variable_get('pathauto_node_'. $type .'_'. $lang_code .'_pattern', ''))) { + $pattern_types[$type] = $type; + continue 2; + } } } } - $type_where .= ')'; - - $query = "SELECT nid, type, title, uid, created, src, dst, vid FROM {node} LEFT JOIN {url_alias} ON CONCAT('node/', CAST(nid AS CHAR)) = src WHERE src IS NULL ". $type_where; - $result = db_query_range($query, $pattern_types, 0, variable_get('pathauto_max_bulk_update', 50)); $count = 0; - $placeholders = array(); - while ($node_ref = db_fetch_object($result)) { - $node = node_load($node_ref->nid, NULL, TRUE); - $node->src = $node_ref->src; - $node->dst = $node_ref->dst; - if (module_exists('taxonomy')) { + if (count($pattern_types)) { + $query = "SELECT n.nid, n.vid, n.type, n.title, n.uid, n.created, n.language, alias.src, alias.dst FROM {node} n LEFT JOIN {url_alias} alias ON CONCAT('node/', CAST(n.nid AS CHAR)) = alias.src WHERE alias.src IS NULL AND n.type IN (". db_placeholders($pattern_types, 'varchar') .')'; + $result = db_query_range($query, $pattern_types, 0, variable_get('pathauto_max_bulk_update', 50)); + + $placeholders = array(); + while ($node_ref = db_fetch_object($result)) { + $node = node_load($node_ref->nid, NULL, TRUE); + $node->src = $node_ref->src; + $node->dst = $node_ref->dst; + if (module_exists('taxonomy')) { // Must populate the terms for the node here for the category // placeholders to work - $node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid)); - } - $placeholders = pathauto_get_placeholders('node', $node); - $src = "node/$node->nid"; - if ($alias = pathauto_create_alias('node', 'bulkupdate', $placeholders, $src, $node->nid, $node->type)) { - $count++; + $node->taxonomy = array_keys(taxonomy_node_get_terms($node)); + } + $placeholders = pathauto_get_placeholders('node', $node); + $src = "node/$node->nid"; + if ($alias = pathauto_create_alias('node', 'bulkupdate', $placeholders, $src, $node->nid, $node->type, $node->language)) { + $count++; + } } }