diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-12-05 16:34:07 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-12-05 16:34:07 +0000 |
commit | 5bb6927e18d4496395dea37cc5b14bb15cb42cad (patch) | |
tree | b3142f8a63bb7defa33ddca8cb6dd23d0c306b22 | |
parent | c99dd5c2064df28932f13e5182676f281a699d48 (diff) | |
download | brdo-5bb6927e18d4496395dea37cc5b14bb15cb42cad.tar.gz brdo-5bb6927e18d4496395dea37cc5b14bb15cb42cad.tar.bz2 |
#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
-rw-r--r-- | includes/common.inc | 50 | ||||
-rw-r--r-- | includes/language.inc | 23 | ||||
-rw-r--r-- | includes/theme.inc | 1 | ||||
-rw-r--r-- | modules/node/node.admin.inc | 6 | ||||
-rw-r--r-- | modules/system/page.tpl.php | 6 | ||||
-rw-r--r-- | modules/translation/translation.module | 5 | ||||
-rw-r--r-- | themes/bluemarine/page.tpl.php | 4 | ||||
-rw-r--r-- | themes/chameleon/chameleon.theme | 2 | ||||
-rw-r--r-- | themes/garland/page.tpl.php | 2 | ||||
-rw-r--r-- | 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 '<front>' links to the default front page. if (!empty($path) && $path != '<front>') { 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 == '<front>')) ? $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 @@ <div id="logo-title"> <?php if (!empty($logo)): ?> - <a href="<?php print $base_path; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo"> + <a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo"> <img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" /> </a> <?php endif; ?> @@ -97,7 +99,7 @@ <div id="name-and-slogan"> <?php if (!empty($site_name)): ?> <h1 id="site-name"> - <a href="<?php print $base_path ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> + <a href="<?php print $front_page ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a> </h1> <?php endif; ?> 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 @@ <table border="0" cellpadding="0" cellspacing="0" id="header"> <tr> <td id="logo"> - <?php if ($logo) { ?><a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Home') ?>" /></a><?php } ?> - <?php if ($site_name) { ?><h1 class='site-name'><a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><?php print $site_name ?></a></h1><?php } ?> + <?php if ($logo) { ?><a href="<?php print $front_page ?>" title="<?php print t('Home') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Home') ?>" /></a><?php } ?> + <?php if ($site_name) { ?><h1 class='site-name'><a href="<?php print $front_page ?>" title="<?php print t('Home') ?>"><?php print $site_name ?></a></h1><?php } ?> <?php if ($site_slogan) { ?><div class='site-slogan'><?php print $site_slogan ?></div><?php } ?> </td> <td id="menu"> diff --git a/themes/chameleon/chameleon.theme b/themes/chameleon/chameleon.theme index 54799ea3e..247c87a99 100644 --- a/themes/chameleon/chameleon.theme +++ b/themes/chameleon/chameleon.theme @@ -38,7 +38,7 @@ function chameleon_page($content, $show_blocks = TRUE, $show_messages = TRUE) { $output .= " <div id=\"header\">"; if ($logo = theme_get_setting('logo')) { - $output .= " <a href=\"". base_path() ."\" title=\"". t('Home') ."\"><img src=\"$logo\" alt=\"". t('Home') ."\" /></a>"; + $output .= " <a href=\"". url() ."\" title=\"". t('Home') ."\"><img src=\"$logo\" alt=\"". t('Home') ."\" /></a>"; } if (theme_get_setting('toggle_name')) { $output .= " <h1 class=\"site-name title\">". l(variable_get('site_name', 'drupal'), "") ."</h1>"; diff --git a/themes/garland/page.tpl.php b/themes/garland/page.tpl.php index 66fa4a3f2..ec861fa41 100644 --- a/themes/garland/page.tpl.php +++ b/themes/garland/page.tpl.php @@ -38,7 +38,7 @@ $site_html = implode(' ', $site_fields); if ($logo || $site_title) { - print '<h1><a href="'. check_url($base_path) .'" title="'. $site_title .'">'; + print '<h1><a href="'. check_url($front_page) .'" title="'. $site_title .'">'; if ($logo) { print '<img src="'. check_url($logo) .'" alt="'. $site_title .'" id="logo" />'; } diff --git a/themes/pushbutton/page.tpl.php b/themes/pushbutton/page.tpl.php index c2a07d1ed..8281a4823 100644 --- a/themes/pushbutton/page.tpl.php +++ b/themes/pushbutton/page.tpl.php @@ -18,13 +18,13 @@ <tr> <td id="home" width="10%"> <?php if ($logo) : ?> - <a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><img src="<?php print($logo) ?>" alt="<?php print t('Home') ?>" border="0" /></a> + <a href="<?php print $front_page ?>" title="<?php print t('Home') ?>"><img src="<?php print($logo) ?>" alt="<?php print t('Home') ?>" border="0" /></a> <?php endif; ?> </td> <td id="site-info" width="20%"> <?php if ($site_name) : ?> - <div class='site-name'><a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><?php print($site_name) ?></a></div> + <div class='site-name'><a href="<?php print $front_page ?>" title="<?php print t('Home') ?>"><?php print($site_name) ?></a></div> <?php endif;?> <?php if ($site_slogan) : ?> <div class='site-slogan'><?php print($site_slogan) ?></div> |