Commit ceb70131 authored by Dave Reid's avatar Dave Reid

by Dave Reid: Added xmlsitemap_language_load().

parent 5287a742
......@@ -46,7 +46,7 @@ function xmlsitemap_settings_form() {
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#collapsed' => !variable_get('xmlsitemap_developer_mode', FALSE),
'#weight' => 10,
);
//$form['advanced']['xmlsitemap_gz'] = array(
......@@ -80,7 +80,8 @@ function xmlsitemap_settings_form() {
'#default_value' => $path,
'#size' => 30,
'#maxlength' => 255,
'#description' => t('Subdirectory in the directory %dir where the sitemap data will be stored. This folder <strong>must not be shared</strong> with any other Drupal site or install using XML sitemap.', array('%dir' => file_directory_path() .'/')),
'#description' => t('Subdirectory where the sitemap data will be stored. This folder <strong>must not be shared</strong> with any other Drupal site or install using XML sitemap.'),
'#field_prefix' => file_directory_path() . '/',
'#required' => TRUE,
);
$form['advanced']['xmlsitemap_base_url'] = array(
......@@ -94,7 +95,7 @@ function xmlsitemap_settings_form() {
$form['advanced']['xmlsitemap_developer_mode'] = array(
'#type' => 'checkbox',
'#title' => t('Enable developer mode.'),
'#default_value' => xmlsitemap_var('developer_mode'),
'#default_value' => variable_get('xmlsitemap_developer_mode', FALSE),
'#description' => t('Exposes additional settings intended for development.'),
);
......@@ -140,16 +141,14 @@ function xmlsitemap_settings_form() {
* checkbox.
*/
function _xmlsitemap_process_language_checkboxes($element) {
$sitemaps = xmlsitemap_get_sitemaps(TRUE);
foreach (element_children($element) as $key) {
if ($key == language_default('language')) {
$element[$key]['#disabled'] = TRUE;
$element[$key]['#default_value'] = TRUE;
$element[$key]['#weight'] = -1;
}
if (isset($sitemaps[$key])) {
$element[$key]['#description'] = $sitemaps[$key];
}
$link = url('sitemap.xml', array('absolute' => TRUE, 'language' => xmlsitemap_language_load($key)));
$element[$key]['#description'] = l($link, $link);
}
return $element;
}
......
......@@ -51,7 +51,6 @@ function xmlsitemap_regenerate() {
_xmlsitemap_regenerate_before();
// Generate the sitemap pages.
$languages = language_list();
$chunk_count = xmlsitemap_get_chunk_count(TRUE);
if ($chunk_count > 1) {
// If we have more than one chunk, we need to increment this value by one
......@@ -60,7 +59,7 @@ function xmlsitemap_regenerate() {
}
foreach (xmlsitemap_var('languages') as $language) {
for ($i = 0; $i < $chunk_count; $i++) {
xmlsitemap_generate($i, $languages[$language]);
xmlsitemap_generate($i, xmlsitemap_language_load($language));
}
}
......@@ -247,14 +246,8 @@ function xmlsitemap_generate_chunk_header($type, $handle, &$status, $language) {
* A language object for the sitemap chunk.
*/
function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
static $languages;
$last_url = '';
if (!isset($languages)) {
$languages = language_list();
$languages[LANGUAGE_NONE] = language_default();
}
$url_options = xmlsitemap_get_url_options(array('alias' => TRUE));
$query = db_select('xmlsitemap', 'x');
......@@ -275,7 +268,7 @@ function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
xmlsitemap_generate_chunk_header('urlset', $handle, $status, $language);
while ($link = $links->fetchAssoc()) {
$url_options['language'] = ($link['language'] != LANGUAGE_NONE ? $languages[$link['language']] : $language);
$url_options['language'] = ($link['language'] != LANGUAGE_NONE ? xmlsitemap_language_load($link['language']) : $language);
$link['alias'] = xmlsitemap_get_path_alias($link['loc'], $url_options['language']->language);
$link_url = url($link['alias'], $url_options);
......@@ -371,9 +364,8 @@ function xmlsitemap_rebuild_batch($modules = array(), $save_custom = FALSE) {
// Generate all the sitemap pages.
$batch['operations'][] = array('_xmlsitemap_regenerate_before', array());
$languages = language_list();
foreach (xmlsitemap_var('languages') as $language) {
$batch['operations'][] = array('xmlsitemap_rebuild_batch_generate', array($languages[$language]));
$batch['operations'][] = array('xmlsitemap_rebuild_batch_generate', array(xmlsitemap_language_load($language)));
}
$batch['operations'][] = array('_xmlsitemap_regenerate_after', array());
......
......@@ -204,12 +204,11 @@ function xmlsitemap_get_sitemaps($links = FALSE) {
if (!$sitemaps) {
$url_options = xmlsitemap_get_url_options();
$languages = language_list();
$sitemap_languages = xmlsitemap_var('languages');
natsort($sitemap_languages);
foreach ($sitemap_languages as $language) {
$url_options['language'] = $languages[$language];
$url_options['language'] = xmlsitemap_language_load($language);
$sitemap = url('sitemap.xml', $url_options);
$sitemaps[$language] = $links ? l($sitemap, $sitemap) : $sitemap;
}
......@@ -833,3 +832,22 @@ function _xmlsitemap_delete_recursive($path, $delete_root = FALSE) {
}
return file_unmanaged_delete($path);
}
/**
* Load a language object by its language code.
*
* @param $language
* A language code. If not provided the default language will be returned.
* @return
* A language object.
*/
function xmlsitemap_language_load($language = LANGUAGE_NONE) {
static $languages;
if (!isset($languages)) {
$languages = language_list();
$languages[LANGUAGE_NONE] = NULL;
}
return $languages[$language];
}
......@@ -46,17 +46,6 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
}
}
protected function getLanguageObj($langcode = LANGUAGE_NONE, $reset = FALSE) {
static $languages;
if (!isset($languages) || $reset) {
$languages = language_list('language', TRUE);
$languages[LANGUAGE_NONE] = NULL;
}
return $languages[$langcode];
}
/**
* Assert that a link is found in the sitemap.
*
......@@ -92,7 +81,7 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
$this->regenerateSitemap();
}
$this->drupalGet('sitemap.xml', array('language' => $this->getLanguageObj($language)));
$this->drupalGet('sitemap.xml', array('language' => xmlsitemap_language_load($language)));
$this->assertResponse(200);
}
......@@ -118,7 +107,7 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
protected function assertLinksInSitemap() {
$links = func_get_args();
foreach ($links as $link) {
$path = url($link['loc'], array('language' => $this->getLanguageObj($link['language']), 'absolute' => TRUE));
$path = url($link['loc'], array('language' => xmlsitemap_language_load($link['language']), 'absolute' => TRUE));
$this->assertRaw($link['loc'], t('Link %path found in the sitemap.', array('%path' => $path)));
}
}
......@@ -126,7 +115,7 @@ class XMLSitemapTestHelper extends DrupalWebTestCase {
protected function assertLinksNotInSitemap() {
$links = func_get_args();
foreach ($links as $link) {
$path = url($link['loc'], array('language' => $this->getLanguageObj($link['language']), 'absolute' => TRUE));
$path = url($link['loc'], array('language' => xmlsitemap_language_load($link['language']), 'absolute' => TRUE));
$this->assertNoRaw($link['loc'], t('Link %path not found in the sitemap.', array('%path' => $path)));
}
}
......@@ -455,9 +444,6 @@ class XMLSitemapUnitTest extends XMLSitemapTestHelper {
$this->assertEqual($user->uid, 0);
}
//function testWriteRecord() {
//}
//
//function testLoadLink() {
//}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment