From 261e445c35a16936876329063e5dfc7a5e3c4db6 Mon Sep 17 00:00:00 2001
From: Michael Mechlis <you@example.com>
Date: Thu, 11 Mar 2010 10:29:50 +0200
Subject: [PATCH] mobile

---
 sites/all/modules/xmlsitemap/xmlsitemap.admin.inc |    6 ++++++
 sites/all/modules/xmlsitemap/xmlsitemap.pages.inc |   16 +++++++++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/sites/all/modules/xmlsitemap/xmlsitemap.admin.inc b/sites/all/modules/xmlsitemap/xmlsitemap.admin.inc
index 63abf98..0734686 100644
--- a/sites/all/modules/xmlsitemap/xmlsitemap.admin.inc
+++ b/sites/all/modules/xmlsitemap/xmlsitemap.admin.inc
@@ -53,6 +53,12 @@ function xmlsitemap_settings() {
     '#default_value' => variable_get('xmlsitemap_use_stylesheet', FALSE),
     '#description' => t('Specify a xml stylesheet for the sitemap?'),
   );
+  $form['general']['xmlsitemap_mobile'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Display as mobile sitemap'),
+    '#default_value' => variable_get('xmlsitemap_mobile', 0),
+    '#description' => t('Dispaly sitemap in mobile format'),
+  );
   $form['frontpage'] = array(
     '#type' => 'fieldset',
     '#title' => t('Front page'),
diff --git a/sites/all/modules/xmlsitemap/xmlsitemap.pages.inc b/sites/all/modules/xmlsitemap/xmlsitemap.pages.inc
index dda1c14..4096c71 100644
--- a/sites/all/modules/xmlsitemap/xmlsitemap.pages.inc
+++ b/sites/all/modules/xmlsitemap/xmlsitemap.pages.inc
@@ -96,6 +96,7 @@ function xmlsitemap_output($chunk = NULL) {
   $headers = array("Content-type: text/xml; charset=utf-8");
   if (isset($chunk)) {
     if ($chunk < $link_count / $chunk_size) {
+      
       file_transfer("$parent_directory/xsm-$id-$chunk.xml", $headers);
     }
   }
@@ -166,14 +167,20 @@ function _xmlsitemap_check_cache_files() {
  *  0).
  */
 function _xmlsitemap_create_cache_chunk($fp, $chunk_size, $chunk = 0) {
+  $is_mobile = variable_get('xmlsitemap_mobile', 0);
   fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?>' . "\n");
   if ($xsl = _xmlsitemap_xsl()) {
     fwrite($fp, '<?xml-stylesheet type="text/xsl" href="' . $xsl . '" ?>' . "\n");
   }
   fwrite($fp, '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"' . "\n");
-  fwrite($fp, '  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n");
-  fwrite($fp, '  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' . "\n");
-  fwrite($fp, '  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n");
+  if ($is_mobile) {
+    fwrite($fp, '  xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0">' . "\n");
+  }else{
+    fwrite($fp, '  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . "\n");
+    fwrite($fp, '  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9' . "\n");
+    fwrite($fp, '  http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n");
+  }
+
   $start = $chunk * $chunk_size;
   $links = db_query_range("SELECT xsm.loc, xsm.module, xsm.type, xsm.id, xsm.sid, xsm.changed, xsm.changefreq, xsm.priority". xmlsitemap_sitemap_query() ."ORDER BY xsm.priority DESC, xsm.changed DESC, xsm.changefreq, xsm.loc", $start, $chunk_size);
   while ($link = db_fetch_object($links)) {
@@ -198,6 +205,9 @@ function _xmlsitemap_create_cache_chunk($fp, $chunk_size, $chunk = 0) {
       $link->output .= "\t<lastmod>". gmdate(DATE_W3C, $link->changed) ."</lastmod>\n";
       $link->output .= "\t<changefreq>". xmlsitemap_sitemap_frequency($link->changefreq) ."</changefreq>\n";
       $link->output .= "\t<priority>". number_format($link->priority, 1) ."</priority>\n";
+      if ($is_mobile) {
+      	$link->output .= "\t<mobile:mobile/>\n";
+      }
       $link->output .= "</url>\n";
       fwrite($fp, $link->output);
     }
-- 
1.6.4.2

