? .DS_Store
? kml_views.patch
Index: kml.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/kml/kml.module,v
retrieving revision 1.5.2.2
diff -u -p -r1.5.2.2 kml.module
--- kml.module	19 Mar 2007 12:14:10 -0000	1.5.2.2
+++ kml.module	12 Jul 2007 04:01:23 -0000
@@ -99,15 +99,15 @@ function kml_interface($a = NULL, $b = N
         if ($c == 'networklink') {
           /* Network link for all location-enabled nodes tagged with a certain term */
           $attributes['kml_feed'] = url('kml/term/'. $b .'/', NULL, NULL, TRUE);
-          $attributes['title'] = 'Tag: '. $tag;
-          $attributes['description'] = 'Nodes tagged with '. $tag;
+          $attributes['title'] = t('Tag: %tag', array('%tag' => $tag));
+          $attributes['description'] = t('Nodes tagged with %tag', array('%tag' => $tag));
           kml_networklink($attributes);
         }
         else {
           /* All location-enabled nodes tagged with a certain term */
           $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE n.status = 1 AND n.vid IN (SELECT l.eid FROM {location} l WHERE l.source != 0 AND l.type = 'node' AND l.eid = n.vid) AND tn.tid = %d ORDER BY %s %s", $b, $sortmode, $sortorder);
-          $attributes['title'] = 'Tag: '. $tag;
-          $attributes['description'] = 'Nodes tagged with '. $tag;
+          $attributes['title'] = t('Tag: %tag', array('%tag' => $tag));
+          $attributes['description'] = t('Nodes tagged with %tag', array('%tag' => $tag));
           kml_feed($nodes, $attributes);
         }
       }
@@ -124,15 +124,15 @@ function kml_interface($a = NULL, $b = N
         if ($c == 'networklink') {
           /* Network link for all location-enabled nodes in a certain group */
           $attributes['kml_feed'] = url('kml/group/' . $b .'/', NULL, NULL, TRUE);
-          $attributes['title'] = 'Group: '. $group_name;
-          $attributes['description'] = 'Nodes in '. $group_name;
+          $attributes['title'] = t('Group: %group', array('%group' => $group_name));
+          $attributes['description'] = t('Nodes in %group', array('%group' => $group_name));
           kml_networklink($attributes);
         }
         else {
           /* All location-enabled nodes in a certain group */
           $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {node_access} na ON n.nid = na.nid WHERE n.status = 1 AND n.vid IN (SELECT l.eid FROM {location} l WHERE l.source != 0 AND l.type = 'node' AND l.eid = n.vid) AND na.gid = %d ORDER BY %s %s", $b, $sortmode, $sortorder);
-          $attributes['title'] = 'Group: '.$group_name;
-          $attributes['description'] = 'Nodes in '. $group_name;
+          $attributes['title'] = t('Group: %group', array('%group' => $group_name));
+          $attributes['description'] = t('Nodes in %group', array('%group' => $group_name));
           kml_feed($nodes, $attributes);
         }
       }
@@ -140,6 +140,48 @@ function kml_interface($a = NULL, $b = N
         drupal_not_found();
       }
     }
+    else {
+      drupal_not_found();
+    }
+  }
+  else if ($a == 'view' && $b) {
+    if (module_exists('views')) {
+      $b = check_plain($b);
+      $view = module_invoke('views', 'get_view', $b);
+
+      if ($view->url) {
+        if ($c == 'networklink') {
+          /* Network link for nodes in a view */
+          if ($view->page_type == 'kml') {
+            // a view intended to be used as KML feed
+            $attributes['kml_feed'] = url($view->url .'/', NULL, NULL, TRUE);
+          }
+          else {
+            // any other view
+            $attributes['kml_feed'] = url('kml/view/'. $view->name .'/', NULL, NULL, TRUE);
+          }
+          $attributes['title'] = t('%view_title', array('%view_title' => $view->page_title));
+          $attributes['description'] = t('%view_description', array('%view_description' => $view->description));
+          kml_networklink($attributes);
+        }
+        else {
+          /* Invoke views module to get the page defined by the view */
+          if ($view->page_type == 'kml') {
+            print module_invoke('views', 'build_view', 'page', $view, $args);
+          }
+          else {
+            $nodes = module_invoke('views', 'build_view', 'items', $view, $args);
+            theme_kml_feed($view, $nodes['items'], 'page');
+          }
+        }
+      }
+      else {
+        drupal_not_found();
+      }
+    }
+    else {
+      drupal_not_found();
+    }
   }
   else if ($a == 'search' && $b == 'node' && $c) {
     if (module_exists('search')) {
@@ -148,15 +190,15 @@ function kml_interface($a = NULL, $b = N
       if ($d == 'networklink') {
         /* Network link for all nodes returned by a certain search */
         $attributes['kml_feed'] = url('kml/search/'. $type .'/'. $keys .'/', NULL, NULL, TRUE);
-        $attributes['title'] = 'Search: '. $keys;
-        $attributes['description'] = 'Nodes matching '. $keys;
+        $attributes['title'] = t('Search: %terms', array('%terms' => $keys));
+        $attributes['description'] = t('Nodes matching %terms', array('%terms' => $keys));
         kml_networklink($attributes);
       }
       else {
         /* All nodes returned by a certain search */
         $nodes = module_invoke($type, 'search', 'search', $keys);
-        $attributes['title'] = 'Search: '. $keys;
-        $attributes['description'] = 'Nodes matching '. $keys;
+        $attributes['title'] = t('Search: %terms', array('%terms' => $keys));
+        $attributes['description'] = t('Nodes matching %terms', array('%terms' => $keys));
         kml_feed($nodes, $attributes);
       }
     }
@@ -212,6 +254,7 @@ function kml_admin_settings() {
     '#title' => t('Sort mode'), 
     '#default_value' => variable_get('kml_sortmode', 'n.created'), 
     '#options' => $sort_modes,
+    '#description' => t('Note that this will not affect KML feeds defined through views module.'),
   );
   $form['multiple_nodes']['kml_sortorder'] = array(
     '#type' => 'radios', 
@@ -383,13 +426,43 @@ function kml_feed($nodes, $attributes = 
   $channel['link'] = $link;
   $channel['description'] = $description;
   $output = kml_format_feed($nodes, $channel);
-
-  $filename = 'nodes.kml';
+  $filename = 'nodes.kml';  // TODO: friendlier filename
   drupal_set_header('Content-Type: application/vnd.google-earth.kml+xml');
   drupal_set_header('Content-Disposition: attachment; filename="'.$filename.'"');
   print $output;
+
+  module_invoke_all('exit');
+  exit; 
+}
+
+/**
+ * Provide views plugins for creating KML feeds.
+ */
+function kml_views_style_plugins() {
+  return array(
+    'kml' => array(
+      'name' => t('KML feed'),
+      'theme' => 'kml_feed',
+      'needs_table_header' => TRUE,
+      'needs_fields' => TRUE,
+    ),
+  );
 }
 
+/**
+ * Views plugin that displays the KML feed for views
+ */
+function theme_kml_feed($view, $nodes, $type) {
+  if ($type == 'block') {
+    return;
+  }
+  $attributes['title'] = t('%view_title', array('%view_title' => $view->page_title));
+  $attributes['description'] = t('%view_description', array('%view_description' => $view->description));
+  foreach ($nodes as $node) {
+    $node_objects[]['node'] = (object)array('nid' => $node->nid);
+  }
+  kml_feed($node_objects, $attributes);
+}
 
 /**
  * A generic function for generating KML (Keyhole Markup Language for Google Earth) feeds from a set of nodes.
@@ -583,7 +656,7 @@ function kml_networklink($attributes = a
 
   $output = kml_format_networklink($title,$kml_feed,$url);
 
-  $filename = 'networklink.kml';
+  $filename = 'networklink.kml';  // TODO: friendlier name
   drupal_set_header('Content-Type: application/vnd.google-earth.kml+xml');
   drupal_set_header('Content-Disposition: attachment; filename="'.$filename.'"');
   print $output;
