From 5bb6927e18d4496395dea37cc5b14bb15cb42cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= Date: Wed, 5 Dec 2007 16:34:07 +0000 Subject: #196410 report by daniel.soneira, patch by myself, tested by Freso: several fixes to url() generation and path aliasing, fixing path aliases for node paths and front page links in themes --- includes/common.inc | 50 ++++++++++++++++++++++------------ includes/language.inc | 23 ++++++++-------- includes/theme.inc | 1 + modules/node/node.admin.inc | 6 ++-- modules/system/page.tpl.php | 6 ++-- modules/translation/translation.module | 5 ++-- themes/bluemarine/page.tpl.php | 4 +-- themes/chameleon/chameleon.theme | 2 +- themes/garland/page.tpl.php | 2 +- themes/pushbutton/page.tpl.php | 4 +-- 10 files changed, 62 insertions(+), 41 deletions(-) diff --git a/includes/common.inc b/includes/common.inc index fe41d29ce..a6128675d 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1220,6 +1220,15 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL * Whether the given path is an alias already. * 'external' * Whether the given path is an external URL. + * 'language' + * An optional language object. Used to build the URL to link to and + * look up the proper alias for the link. + * 'base_url' + * Only used internally, to modify the base URL when a language dependent + * URL requires so. + * 'prefix' + * Only used internally, to modify the path when a language dependent URL + * requires so. * @return * A string containing a URL to the given path. * @@ -1233,6 +1242,7 @@ function url($path = NULL, $options = array()) { 'query' => '', 'absolute' => FALSE, 'alias' => FALSE, + 'prefix' => '' ); if (!isset($options['external'])) { // Return an external link if $path contains an allowed absolute URL. @@ -1297,33 +1307,39 @@ function url($path = NULL, $options = array()) { // The special path '' links to the default front page. if (!empty($path) && $path != '') { if (!$options['alias']) { - $path = drupal_get_path_alias($path, isset($options['langcode']) ? $options['langcode'] : ''); + $path = drupal_get_path_alias($path, isset($options['language']) ? $options['language']->language : ''); } if (function_exists('custom_url_rewrite_outbound')) { // Modules may alter outbound links by reference. custom_url_rewrite_outbound($path, $options, $original_path); } - $path = drupal_urlencode($path); - if (!$clean_url) { - if ($options['query']) { - return $base . $script .'?q='. $path .'&'. $options['query'] . $options['fragment']; - } - else { - return $base . $script .'?q='. $path . $options['fragment']; - } + $path = drupal_urlencode($options['prefix'] . $path); + } + else { + // Will be empty if there is no language prefix. + $path = trim($options['prefix'], '/'); + } + + if ($clean_url) { + // With Clean URLs. + if ($options['query']) { + return $base . $path .'?'. $options['query'] . $options['fragment']; } else { - if ($options['query']) { - return $base . $path .'?'. $options['query'] . $options['fragment']; - } - else { - return $base . $path . $options['fragment']; - } + return $base . $path . $options['fragment']; } } else { - if ($options['query']) { - return $base . $script .'?'. $options['query'] . $options['fragment']; + // Without Clean URLs. + $variables = array(); + if (!empty($path)) { + $variables[] = 'q='. $path; + } + if (!empty($options['query'])) { + $variables[] = $options['query']; + } + if ($query = join('&', $variables)) { + return $base . $script .'?'. $query . $options['fragment']; } else { return $base . $options['fragment']; diff --git a/includes/language.inc b/includes/language.inc index de4ef393a..c36ba7c01 100644 --- a/includes/language.inc +++ b/includes/language.inc @@ -103,37 +103,36 @@ function language_url_rewrite(&$path, &$options) { if (!$options['external']) { // Language can be passed as an option, or we go for current language. - $path_language = isset($options['language']) ? $options['language'] : $language; + if (!isset($options['language'])) { + $options['language'] = $language; + } + switch (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE)) { - case LANGUAGE_NEGOTIATION_NONE: + // No language dependent path allowed in this mode. + unset($options['language']); break; case LANGUAGE_NEGOTIATION_DOMAIN: - if ($path_language->domain) { + if ($options['language']->domain) { // Ask for an absolute URL with our modified base_url. $options['absolute'] = TRUE; - $options['base_url'] = $path_language->domain; - // Ensure that path alias generation will use this language. - $options['langcode'] = $path_language->language; + $options['base_url'] = $options['language']->domain; } break; case LANGUAGE_NEGOTIATION_PATH_DEFAULT: $default = language_default(); - if ($path_language->language == $default->language) { + if ($options['language']->language == $default->language) { break; } // Intentionally no break here. case LANGUAGE_NEGOTIATION_PATH: - if (isset($path_language->prefix) && $path_language->prefix) { - // Ensure that path alias generation will use this language. - $options['langcode'] = $path_language->language; - $path = (empty($path) || ($path == '')) ? $path_language->prefix : $path_language->prefix .'/'. $path; + if (!empty($options['language']->prefix)) { + $options['prefix'] = $options['language']->prefix .'/'; } break; - } } } diff --git a/includes/theme.inc b/includes/theme.inc index e46f7f411..04271ae1c 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -1701,6 +1701,7 @@ function template_preprocess_page(&$variables) { } $variables['head_title'] = implode(' | ', $head_title); $variables['base_path'] = base_path(); + $variables['front_page'] = url(); $variables['breadcrumb'] = theme('breadcrumb', drupal_get_breadcrumb()); $variables['feed_icons'] = drupal_get_feeds(); $variables['footer_message'] = filter_xss_admin(variable_get('site_footer', FALSE)); diff --git a/modules/node/node.admin.inc b/modules/node/node.admin.inc index f4b7e85aa..d665233c5 100644 --- a/modules/node/node.admin.inc +++ b/modules/node/node.admin.inc @@ -380,16 +380,18 @@ function node_admin_nodes() { '#submit' => array('node_admin_nodes_submit'), ); + $languages = language_list(); $destination = drupal_get_destination(); $nodes = array(); while ($node = db_fetch_object($result)) { $nodes[$node->nid] = ''; - $form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid) .' '. theme('mark', node_mark($node->nid, $node->changed))); + $options = empty($node->language) ? array() : array('language' => $languages[$node->language]); + $form['title'][$node->nid] = array('#value' => l($node->title, 'node/'. $node->nid, $options) .' '. theme('mark', node_mark($node->nid, $node->changed))); $form['name'][$node->nid] = array('#value' => check_plain(node_get_types('name', $node))); $form['username'][$node->nid] = array('#value' => theme('username', $node)); $form['status'][$node->nid] = array('#value' => ($node->status ? t('published') : t('not published'))); if ($multilanguage) { - $form['language'][$node->nid] = array('#value' => empty($node->language) ? t('Language neutral') : module_invoke('locale', 'language_name', $node->language)); + $form['language'][$node->nid] = array('#value' => empty($node->language) ? t('Language neutral') : t($languages[$node->language]->name)); } $form['operations'][$node->nid] = array('#value' => l(t('edit'), 'node/'. $node->nid .'/edit', array('query' => $destination))); } diff --git a/modules/system/page.tpl.php b/modules/system/page.tpl.php index cbbd84a40..8a110e18a 100644 --- a/modules/system/page.tpl.php +++ b/modules/system/page.tpl.php @@ -32,6 +32,8 @@ * path, whether the user is logged in, and so on. * * Site identity: + * - $front_page: The URL of the front page. Use this instead of $base_path, + * when linking to the front page. This includes the language domain or prefix. * - $logo: The path to the logo image, as defined in theme configuration. * - $site_name: The name of the site, empty when display has been disabled * in theme settings. @@ -89,7 +91,7 @@
- @@ -97,7 +99,7 @@

- +

diff --git a/modules/translation/translation.module b/modules/translation/translation.module index 466bedb63..a26b3973c 100644 --- a/modules/translation/translation.module +++ b/modules/translation/translation.module @@ -164,11 +164,12 @@ function translation_link($type, $node = NULL, $teaser = FALSE) { if ($type == 'node' && ($node->tnid) && $translations = translation_node_get_translations($node->tnid)) { // Do not show link to the same node. unset($translations[$node->language]); - $languages = locale_language_list('native'); + $languages = language_list(); foreach ($translations as $language => $translation) { $links["node_translation_$language"] = array( - 'title' => $languages[$language], + 'title' => $languages[$language]->native, 'href' => "node/$translation->nid", + 'language' => $languages[$language], 'attributes' => array('title' => $translation->title, 'class' => 'translation-link') ); } diff --git a/themes/bluemarine/page.tpl.php b/themes/bluemarine/page.tpl.php index a75fa744a..acd717bf7 100644 --- a/themes/bluemarine/page.tpl.php +++ b/themes/bluemarine/page.tpl.php @@ -16,8 +16,8 @@