From 37b85b123febcebbed546e3498c5673f104157cc Mon Sep 17 00:00:00 2001
From: Liem Khuu <liem@imagewks.com>
Date: Thu, 8 Sep 2011 11:32:44 -0400
Subject: [PATCH 1/2] Made changes to the xmlsitemap generation process, hopefully for community approval.

---
 .../contrib/xmlsitemap/xmlsitemap.generate.inc     |   51 +++----------------
 .../contrib/xmlsitemap/xmlsitemap.xmlsitemap.inc   |   21 ++++++++-
 2 files changed, 28 insertions(+), 44 deletions(-)

diff --git a/sites/all/modules/contrib/xmlsitemap/xmlsitemap.generate.inc b/sites/all/modules/contrib/xmlsitemap/xmlsitemap.generate.inc
index c6b564a..2901025 100644
--- a/sites/all/modules/contrib/xmlsitemap/xmlsitemap.generate.inc
+++ b/sites/all/modules/contrib/xmlsitemap/xmlsitemap.generate.inc
@@ -150,7 +150,7 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
   $link_count = 0;
 
   $query = db_select('xmlsitemap', 'x');
-  $query->fields('x', array('loc', 'lastmod', 'changefreq', 'changecount', 'priority', 'language', 'access', 'status'));
+  $query->fields('x');//, array('loc', 'lastmod', 'changefreq', 'changecount', 'priority', 'language', 'access', 'status'));
   $query->condition('x.access', 1);
   $query->condition('x.status', 1);
   $query->orderBy('x.language', 'DESC');
@@ -163,49 +163,14 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
   $query->range($offset, $limit);
   $links = $query->execute();
 
+  $extensions = xmlsitemap_video_get_extensions();
   while ($link = $links->fetchAssoc()) {
-    $link['language'] = $link['language'] != LANGUAGE_NONE ? xmlsitemap_language_load($link['language']) : $url_options['language'];
-    if ($url_options['alias']) {
-      $link['loc'] = xmlsitemap_get_path_alias($link['loc'], $link['language']->language);
-    }
-    $link_options = array(
-      'language' => $link['language'],
-      'xmlsitemap_link' => $link,
-      'xmlsitemap_sitemap' => $sitemap,
-    );
-    // @todo Add a separate hook_xmlsitemap_link_url_alter() here?
-    $link_url = url($link['loc'], $link_options + $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.
-    if ($link_url == $last_url) {
-      continue;
-    }
-    else {
-      $last_url = $link_url;
-      // Keep track of the total number of links written.
-      $link_count++;
-    }
-
-    $element = array();
-    $element['loc'] = $link_url;
-    if ($link['lastmod']) {
-      $element['lastmod'] = gmdate($lastmod_format, $link['lastmod']);
-      // If the link has a lastmod value, update the changefreq so that links
-      // with a short changefreq but updated two years ago show decay.
-      // We use abs() here just incase items were created on this same cron run
-      // because lastmod would be greater than REQUEST_TIME.
-      $link['changefreq'] = (abs(REQUEST_TIME - $link['lastmod']) + $link['changefreq']) / 2;
-    }
-    if ($link['changefreq']) {
-      $element['changefreq'] = xmlsitemap_get_changefreq($link['changefreq']);
-    }
-    if (isset($link['priority']) && $link['priority'] != 0.5) {
-      // Don't output the priority value for links that have 0.5 priority. This
-      // is the default 'assumed' value if priority is not included as per the
-      // sitemaps.org specification.
-      $element['priority'] = number_format($link['priority'], 1);
+    $element = new XMLSitemapElement($link, $url_options);
+    if ($element->hasEntries() && !empty($extensions['types'][$link['type']])) {
+      foreach ($extensions['types'][$link['type']] as $extension_class) {
+        $element->addExtensionData($extension_class);
+      }
+      ++$link_count;
     }
     $writer->writeSitemapElement('url', $element);
   }
diff --git a/sites/all/modules/contrib/xmlsitemap/xmlsitemap.xmlsitemap.inc b/sites/all/modules/contrib/xmlsitemap/xmlsitemap.xmlsitemap.inc
index 46ab406..13bc4ac 100644
--- a/sites/all/modules/contrib/xmlsitemap/xmlsitemap.xmlsitemap.inc
+++ b/sites/all/modules/contrib/xmlsitemap/xmlsitemap.xmlsitemap.inc
@@ -66,10 +66,16 @@ class XMLSitemapWriter extends XMLWriter {
    */
   public function getRootAttributes() {
     $attributes['xmlns'] = 'http://www.sitemaps.org/schemas/sitemap/0.9';
+    
     if (variable_get('xmlsitemap_developer_mode', 0)) {
       $attributes['xmlns:xsi'] = 'http://www.w3.org/2001/XMLSchema-instance';
       $attributes['xsi:schemaLocation'] = 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd';
     }
+    
+    // Add necessary namespaces for extensions to the XML sitemap.
+    $extensions = xmlsitemap_video_get_extensions();
+    $attributes += $extensions['namespace'];
+    
     return $attributes;
   }
 
@@ -96,7 +102,7 @@ class XMLSitemapWriter extends XMLWriter {
    * @param $element
    *   An array of the elements properties and values.
    */
-  public function writeSitemapElement($name, array &$element) {
+  /*public function writeSitemapElement($name, array &$element) {
     $this->writeElement($name, $element);
     $this->writeRaw(PHP_EOL);
 
@@ -106,6 +112,19 @@ class XMLSitemapWriter extends XMLWriter {
     if (($this->sitemapElementCount % $this->linkCountFlush) == 0) {
       $this->flush();
     }
+  }*/
+  public function writeSitemapElement($wrapper, IXMLSitemapElement &$element) {
+    $this->startElement($wrapper);
+    $element->writeElement($this);
+    $this->endElement();
+    $this->writeRaw(PHP_EOL);
+    
+    // After a certain number of elements have been added, flush the buffer
+    // to the output file.
+    $this->sitemapElementCount++;
+    if (($this->sitemapElementCount % $this->linkCountFlush) == 0) {
+      $this->flush();
+    }
   }
 
   /**
-- 
1.7.4.1


From 0fae9448bf3814f19881e9cb27003553ae150e57 Mon Sep 17 00:00:00 2001
From: Liem Khuu <liem@imagewks.com>
Date: Thu, 8 Sep 2011 13:35:17 -0400
Subject: [PATCH 2/2] Fixed some bad typos in the xmlsitemap.generate.inc file

---
 .../contrib/xmlsitemap/xmlsitemap.generate.inc     |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sites/all/modules/contrib/xmlsitemap/xmlsitemap.generate.inc b/sites/all/modules/contrib/xmlsitemap/xmlsitemap.generate.inc
index 2901025..b02045d 100644
--- a/sites/all/modules/contrib/xmlsitemap/xmlsitemap.generate.inc
+++ b/sites/all/modules/contrib/xmlsitemap/xmlsitemap.generate.inc
@@ -166,8 +166,8 @@ function xmlsitemap_generate_chunk(stdClass $sitemap, XMLSitemapWriter $writer,
   $extensions = xmlsitemap_video_get_extensions();
   while ($link = $links->fetchAssoc()) {
     $element = new XMLSitemapElement($link, $url_options);
-    if ($element->hasEntries() && !empty($extension['types'][$link->type])) {
-      foreach ($extension['types'][$link->type] as $extension_class) {
+    if ($element->hasEntries() && !empty($extensions['types'][$link['type']])) {
+      foreach ($extensions['types'][$link['type']] as $extension_class) {
         $element->addExtensionData($extension_class);
       }
       ++$link_count;
-- 
1.7.4.1

