diff --git a/includes/locale.inc b/includes/locale.inc index 0db4d4a..b613667 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -430,8 +430,18 @@ function locale_language_url_rewrite_url(&$path, &$options) { case LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN: if ($options['language']->domain) { // Ask for an absolute URL with our modified base_url. + global $is_https; + $url_scheme = ($is_https) ? 'https://' : 'http://'; $options['absolute'] = TRUE; - $options['base_url'] = $options['language']->domain; + $options['base_url'] = $url_scheme . $options['language']->domain; + if (isset($options['https']) && variable_get('https', FALSE)) { + if ($options['https'] === TRUE) { + $options['base_url'] = str_replace('http://', 'https://', $options['base_url']); + } + elseif ($options['https'] === FALSE) { + $options['base_url'] = str_replace('https://', 'http://', $options['base_url']); + } + } } break; diff --git a/modules/locale/locale.module b/modules/locale/locale.module index caa01f2..31000ed 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -1019,11 +1019,21 @@ function locale_url_outbound_alter(&$path, &$options, $original_path) { $callbacks = array_keys($callbacks); } - + global $test_callbacks; + $test_callbacks = array( + "callbacks" => $callbacks, + "path" => $path, + "options" => $options, + ); foreach ($callbacks as $callback) { $callback($path, $options); } - + global $test_callbacks_after; + $test_callbacks_after = array( + "callbacks" => $callbacks, + "path" => $path, + "options" => $options, + ); // No language dependent path allowed in this mode. if (empty($callbacks)) { unset($options['language']); diff --git a/modules/locale/locale.test b/modules/locale/locale.test index db0bead..cf27fe1 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -2264,6 +2264,50 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase { $fields = $this->xpath('//div[@id="site-name"]//a[@rel="home" and @href=:url]//span', $args); $this->assertTrue($fields[0] == 'Drupal', t('URLs are rewritten using the browser language.')); } + + /** + * Tests url() when separate domains are used for multiple languages. + */ + function testLanguageDomain() { + // Add the Italian language. + $langcode = 'it'; + locale_add_language($langcode, 'Italian', 'Italian', LANGUAGE_LTR, 'it.example.com', '', TRUE, FALSE); + + // Enable language URL detection. + $negotiation = array_flip(array(LOCALE_LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_DEFAULT)); + language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $negotiation); + + variable_set('locale_language_negotiation_url_part', 1); + + // Build the link we're going to test based on the clean url setting. + $link = (!empty($GLOBALS['conf']['clean_url'])) ? 'it.example.com/admin' : 'it.example.com/?q=admin'; + global $is_https; + + $languages = language_list(); + + // Test URL in another language: http://it.example.com/?q=admin. + // Base path gives problems on the testbot, so $correct_link is hard-coded. + // @see UrlAlterFunctionalTest::assertUrlOutboundAlter (path.test). + $italian_url = url('admin', array('language' => $languages['it'])); + $url_scheme = ($is_https) ? 'https://' : 'http://'; + $correct_link = $url_scheme . $link; + $this->assertTrue($italian_url == $correct_link, t('The url() function returns the right url (@url) in accordance with the chosen language', array('@url' => $italian_url . " == " . $correct_link))); + + // Test https via options. + variable_set('https', TRUE); + $italian_url = url('admin', array('https' => TRUE, 'language' => $languages['it'])); + $correct_link = 'https://' . $link; + $this->assertTrue($italian_url == $correct_link, t('The url() function returns the right https url (via options) (@url) in accordance with the chosen language', array('@url' => $italian_url . " == " . $correct_link))); + variable_set('https', FALSE); + + // Test https via current url scheme. + $temp_https = $is_https; + $is_https = TRUE; + $italian_url = url('admin', array('language' => $languages['it'])); + $correct_link = 'https://' . $link; + $this->assertTrue($italian_url == $correct_link, t('The url() function returns the right url (via current url scheme) (@url) in accordance with the chosen language', array('@url' => $italian_url . " == " . $correct_link))); + $is_https = $temp_https; + } } /**