? xmlsitemap-534170-2.patch
? xmlsitemap-534170.patch
Index: xmlsitemap.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xmlsitemap/xmlsitemap.inc,v
retrieving revision 1.1.2.43
diff -u -p -r1.1.2.43 xmlsitemap.inc
--- xmlsitemap.inc	18 Jan 2010 08:32:31 -0000	1.1.2.43
+++ xmlsitemap.inc	20 Jan 2010 15:50:58 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: xmlsitemap.inc,v 1.1.2.43 2010/01/18 08:32:31 davereid Exp $
+// $Id: xmlsitemap.inc,v 1.1.2.40 2009/12/23 07:34:55 davereid Exp $
 
 /**
  * @file
@@ -59,17 +59,31 @@ 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
     // since the index page (chunk 0) will also need to be generated.
     $chunk_count++;
   }
-  foreach (xmlsitemap_var('languages') as $language) {
-    for ($i = 0; $i < $chunk_count; $i++) {
-      xmlsitemap_generate($i, xmlsitemap_language_load($language));
-    }
-  }
+
+	if(module_exists('domain')) {
+		$domains = domain_domains();
+		foreach($domains AS $domain) {
+			$domain_name = "http://" . $domain['subdomain'];
+			foreach (xmlsitemap_var('languages') as $language) {
+		    for ($i = 0; $i < $chunk_count; $i++) {
+		      xmlsitemap_generate($i, $languages[$language], $domain_name);
+		    }
+		  }
+		}
+	} else {
+	  foreach (xmlsitemap_var('languages') as $language) {
+	    for ($i = 0; $i < $chunk_count; $i++) {
+	      xmlsitemap_generate($i, $languages[$language]);
+	    }
+	  }		
+	}
 
   _xmlsitemap_regenerate_after();
 }
@@ -89,7 +103,8 @@ function _xmlsitemap_regenerate_before()
   _xmlsitemap_get_memory_usage(TRUE);
 
   // Clear all cached sitemap files.
-  xmlsitemap_clear_directory();
+  $path = file_create_path(variable_get('xmlsitemap_path', 'xmlsitemap'));
+  _xmlsitemap_delete_recursive($path);
   xmlsitemap_check_directory();
 }
 
@@ -118,7 +133,8 @@ function _xmlsitemap_get_optimal_memory_
     $optimal_limit += xmlsitemap_get_chunk_size() * 500;
 
     // Add memory for storing the url aliases.
-    $aliases = db_result(db_query("SELECT COUNT(pid) FROM {url_alias}"));
+    $aliases = db_result(db_query("SELECT COUNT(pid) FROM {url_alias} WHERE language = ''"));
+    $aliases += db_result(db_query("SELECT COUNT(pid) as pid_count FROM {url_alias} WHERE language <> '' GROUP BY language ORDER BY pid_count DESC"));
     $optimal_limit += $aliases * 250;
   }
   return $optimal_limit;
@@ -173,18 +189,24 @@ function _xmlsitemap_regenerate_after() 
  *
  * @todo Revise/simplify or remove the function.
  */
-function xmlsitemap_generate($chunk = 0, $language = NULL) {
+function xmlsitemap_generate($chunk = 0, $language = NULL, $domain = NULL) {
   if (!is_numeric($chunk) || $chunk > xmlsitemap_get_chunk_count()) {
     // Don't bother translating this string.
     trigger_error('Improper condition hit in xmlsitemap_generate(). Chunk: ' . $chunk . ', Chunk Count: ' . xmlsitemap_get_chunk_count());
     return FALSE;
   }
 
+
   if (!isset($language)) {
     $language = language_default();
   }
 
-  $file = xmlsitemap_get_chunk_file($chunk, $language->language);
+	if(module_exists("domain") && !isset($domain)) {
+		$domain = domain_get_domain();		
+		$domain = "http://" . $domain['subdomain'];
+	}
+
+  $file = xmlsitemap_get_chunk_file($chunk, $language, FALSE, $domain);
 
   if (!$handle = fopen($file, 'wb')) {
     trigger_error(t('Could not open file @file for writing.', array('@file' => $file)));
@@ -193,10 +215,10 @@ function xmlsitemap_generate($chunk = 0,
 
   $status = TRUE;
   if (xmlsitemap_get_chunk_count() > 1 && !$chunk) {
-    xmlsitemap_generate_index($handle, $status, $language);
+    xmlsitemap_generate_index($handle, $status, $language, $domain);
   }
   else {
-    xmlsitemap_generate_chunk($handle, $status, $chunk, $language);
+    xmlsitemap_generate_chunk($handle, $status, $chunk, $language, $domain);
   }
   fclose($handle);
 
@@ -204,7 +226,7 @@ function xmlsitemap_generate($chunk = 0,
     trigger_error(t('Unknown error occurred while writing to file @file.', array('@file' => $file)));
   }
   elseif (xmlsitemap_var('gz')) {
-    $file_gz = xmlsitemap_get_chunk_file($chunk, $language->language, 'gz');
+    $file_gz = xmlsitemap_get_chunk_file($chunk, $language, TRUE, $domain);
     file_put_contents($file_gz, gzencode(file_get_contents($file), 9));
   }
 
@@ -259,9 +281,15 @@ function xmlsitemap_generate_chunk_heade
  * @param $language
  *   A language object for the sitemap chunk.
  */
-function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language) {
+function xmlsitemap_generate_chunk($handle, &$status, $chunk, $language, $domain = NULL) {
+  static $languages;
   $last_url = '';
 
+  if (!isset($languages)) {
+    $languages = language_list();
+    $languages[''] = language_default();
+  }
+
   $query = array(
     'SELECT'   => 'SELECT x.loc, x.lastmod, x.changefreq, x.changecount, x.priority, x.language',
     'FROM'     => 'FROM {xmlsitemap} x',
@@ -277,6 +305,11 @@ function xmlsitemap_generate_chunk($hand
 
   $sql = implode($query, ' ');
   $url_options = xmlsitemap_get_url_options(array('alias' => TRUE));
+
+	if(isset($domain)) {
+		$url_options['base_url'] = $domain;
+	}
+	
   $offset = max($chunk - 1, 0) * xmlsitemap_get_chunk_size();
   $limit = xmlsitemap_get_chunk_size();
   $query = db_query_range($sql, $args, $offset, $limit);
@@ -285,10 +318,10 @@ function xmlsitemap_generate_chunk($hand
   xmlsitemap_generate_chunk_header('urlset', $handle, $status, $language);
 
   while ($link = db_fetch_array($query)) {
-    $url_options['language'] = $link['language'] ? xmlsitemap_language_load($link['language']) : $language;
+    $url_options['language'] = $link['language'] ? $languages[$link['language']] : $language;
     $link['alias'] = xmlsitemap_get_path_alias($link['loc'], $url_options['language']->language);
     $link_url = url($link['alias'], $url_options);
-
+		
     // Skip this link if it was a duplicate of the last one.
     // @todo Figure out a way to do this before generation so we can report
     // back to the user about this.
@@ -336,16 +369,20 @@ function xmlsitemap_generate_chunk($hand
  * @param $language
  *   A language object, defaults to the default language.
  */
-function xmlsitemap_generate_index($handle, &$status, $language) {
+function xmlsitemap_generate_index($handle, &$status, $language, $domain = NULL) {
   $url_options = xmlsitemap_get_url_options(array('language' => $language, 'alias' => TRUE));
   $chunk_count = xmlsitemap_get_chunk_count(TRUE);
 
   // Add the XML header and XSL if desired.
   xmlsitemap_generate_chunk_header('sitemapindex', $handle, $status, $language);
 
+  if(isset($domain)) {
+		$domain = $domain.'-';
+	}
+
   for ($i = 1; $i <= $chunk_count; $i++) {
     $output = '<sitemap>';
-    $output .= '<loc>' . url('sitemap-' . $i . '.xml', $url_options) . '</loc>';
+    $output .= '<loc>' . url('sitemap-' . $domain . $i . '.xml', $url_options) . '</loc>';
     // @todo Use the actual lastmod value of the chunk file.
     $output .= '<lastmod>' . gmdate(DATE_W3C, REQUEST_TIME) . '</lastmod>';
     $output .= '</sitemap>' . PHP_EOL;
@@ -361,7 +398,7 @@ function xmlsitemap_generate_index($hand
 /**
  * Batch information callback.
  */
-function xmlsitemap_rebuild_batch($modules = array(), $save_custom = FALSE) {
+function xmlsitemap_rebuild_batch($modules = array(), $save_custom = FALSE, $purge = TRUE) {
   $batch = array(
     'operations' => array(),
     'finished' => 'xmlsitemap_rebuild_batch_finished',
@@ -369,8 +406,10 @@ function xmlsitemap_rebuild_batch($modul
     'file' => drupal_get_path('module', 'xmlsitemap') . '/xmlsitemap.inc',
   );
 
-  // Purge any links first.
-  $batch['operations'][] = array('xmlsitemap_rebuild_batch_clear', array($modules, $save_custom));
+  // Purge any links first, if requested.
+  if ($purge) {
+    $batch['operations'][] = array('xmlsitemap_rebuild_batch_clear', array($modules, $save_custom));
+  }
 
   // Fetch all the sitemap links and save them to the {xmlsitemap} table.
   foreach ($modules as $module) {
@@ -381,8 +420,9 @@ function xmlsitemap_rebuild_batch($modul
 
   // 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(xmlsitemap_language_load($language)));
+    $batch['operations'][] = array('xmlsitemap_rebuild_batch_generate', array($languages[$language]));
   }
   $batch['operations'][] = array('_xmlsitemap_regenerate_after', array());
 
Index: xmlsitemap.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xmlsitemap/xmlsitemap.module,v
retrieving revision 1.20.2.45.2.130
diff -u -p -r1.20.2.45.2.130 xmlsitemap.module
--- xmlsitemap.module	18 Jan 2010 08:32:31 -0000	1.20.2.45.2.130
+++ xmlsitemap.module	20 Jan 2010 15:50:59 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: xmlsitemap.module,v 1.20.2.45.2.130 2010/01/18 08:32:31 davereid Exp $
+// $Id: xmlsitemap.module,v 1.20.2.45.2.125 2009/12/23 07:28:16 davereid Exp $
 
 /**
  * @defgroup xmlsitemap XML sitemap: create sitemaps.org sitemaps.
@@ -142,18 +142,11 @@ function xmlsitemap_menu() {
  * Implements hook_cron().
  */
 function xmlsitemap_cron() {
-  // If there were no new or changed links, skip.
-  if (!variable_get('xmlsitemap_regenerate_needed', FALSE)) {
-    return;
-  }
-
-  // If the minimum sitemap lifetime hasn't been passed, skip.
-  $lifetime = REQUEST_TIME - variable_get('xmlsitemap_generated_last', 0);
-  if ($lifetime < variable_get('xmlsitemap_minimum_lifetime', 0)) {
+  if (!xmlsitemap_var('regenerate_needed')
+      || (REQUEST_TIME - xmlsitemap_var('generated_last')) < xmlsitemap_var('minimum_lifetime')) {
     return;
   }
 
-  // Regenerate the sitemap XML files.
   module_load_include('inc', 'xmlsitemap');
   xmlsitemap_regenerate();
 }
@@ -207,11 +200,12 @@ function xmlsitemap_get_sitemaps($links 
 
   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'] = xmlsitemap_language_load($language);
+      $url_options['language'] = $languages[$language];
       $sitemap = url('sitemap.xml', $url_options);
       $sitemaps[$language] = $links ? l($sitemap, $sitemap) : $sitemap;
     }
@@ -560,14 +554,19 @@ function xmlsitemap_delete_link(array $c
  * @param $chunk
  *   An integer representing the integer of the sitemap page chunk.
  * @param $language
- *   A string with a language code.
+ *   A language object, defaults to the default language.
  * @return
  *   A file path to the expected chunk file.
  *
  * @todo Move to xmlsitemap.inc
  */
-function xmlsitemap_get_chunk_file($chunk = 0, $language, $extension = 'xml') {
-  return xmlsitemap_get_directory() . "/xmlsitemap-{$language}-{$chunk}.{$extension}";
+function xmlsitemap_get_chunk_file($chunk = 0, $language, $compressed = FALSE, $domain = NULL ) {
+	$domain = "";
+	if(isset($domain)) {
+		$domain = $domain . "-";
+		$domain = str_replace("http://", "", $domain);
+	}
+  return file_create_path(xmlsitemap_var('path')) .'/xmlsitemap-' .$domain . $language->language . '-' . $chunk . ($compressed ? '.gz' : '.xml');
 }
 
 /**
@@ -907,29 +906,11 @@ function xmlsitemap_xmlsitemap_link_info
 }
 
 /**
- * @todo Remove the reset parameter when http://drupal.org/node/654752 is fixed.
- */
-function xmlsitemap_get_directory($reset = TRUE) {
-  static $directory;
-
-  if (!isset($directory) || $reset) {
-    $directory = file_create_path(variable_get('xmlsitemap_path', 'xmlsitemap'));
-  }
-
-  return $directory;
-}
-
-/**
  * Check that the sitemap files directory exists and is writable.
  */
 function xmlsitemap_check_directory() {
-  $directory = xmlsitemap_get_directory();
-  return file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
-}
-
-function xmlsitemap_clear_directory($delete = FALSE) {
-  $directory = xmlsitemap_get_directory();
-  return _xmlsitemap_delete_recursive($directory, $delete);
+  $path = file_create_path(xmlsitemap_var('path'));
+  return file_check_directory($path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
 }
 
 /**
@@ -943,7 +924,7 @@ function xmlsitemap_clear_directory($del
  * @param string $path
  *   A filepath relative to file_directory_path.
  */
-function _xmlsitemap_delete_recursive($path, $delete_root = FALSE) {
+function _xmlsitemap_delete_recursive($path) {
   if (is_file($path) || is_link($path)) {
     unlink($path);
   }
@@ -954,10 +935,10 @@ function _xmlsitemap_delete_recursive($p
         continue;
       }
       $entry_path = $path . '/' . $entry;
-      _xmlsitemap_delete_recursive($entry_path, TRUE);
+      _xmlsitemap_delete_recursive($entry_path);
     }
     $dir->close();
-    return $delete_root ? rmdir($path) : TRUE;
+    return rmdir($path);
   }
 }
 
@@ -978,22 +959,3 @@ function _xmlsitemap_get_field_type($tab
   }
   return $schema[$table]['fields'][$field]['type'];
 }
-
-/**
- * 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 = '') {
-  static $languages;
-
-  if (!isset($languages)) {
-    $languages = language_list();
-    $languages[''] = NULL;
-  }
-
-  return $languages[$language];
-}
Index: xmlsitemap.pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xmlsitemap/xmlsitemap.pages.inc,v
retrieving revision 1.1.2.32
diff -u -p -r1.1.2.32 xmlsitemap.pages.inc
--- xmlsitemap.pages.inc	18 Jan 2010 01:44:17 -0000	1.1.2.32
+++ xmlsitemap.pages.inc	20 Jan 2010 15:50:59 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: xmlsitemap.pages.inc,v 1.1.2.32 2010/01/18 01:44:17 davereid Exp $
+// $Id: xmlsitemap.pages.inc,v 1.1.2.31 2009/12/23 07:28:16 davereid Exp $
 
 /**
  * @file
@@ -16,13 +16,19 @@
 function xmlsitemap_output_chunk($chunk = 0) {
   global $language;
 
+	$domain = null;
+	if(module_exists("domain")) {
+		$domain = domain_get_domain();		
+		$domain = "http://" . $domain['subdomain'];
+	}
+	
   // @todo Remove this from the final version?
   if (isset($_GET['refresh']) && user_access('administer xmlsitemap')) {
     module_load_include('inc', 'xmlsitemap');
-    xmlsitemap_generate($chunk, $language);
+    xmlsitemap_generate($chunk, $language, $domain);
   }
 
-  $file = xmlsitemap_get_chunk_file($chunk, $language->language);
+  $file = xmlsitemap_get_chunk_file($chunk, $language, FALSE, $domain);
   xmlsitemap_output_file($file);
 }
 
