? kml.module_patch5_0
? kml_5.patch
Index: kml.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/kml/kml.info,v
retrieving revision 1.1
diff -u -p -r1.1 kml.info
--- kml.info	25 Sep 2006 13:23:41 -0000	1.1
+++ kml.info	22 Jan 2007 17:37:23 -0000
@@ -1,3 +1,5 @@
 ; $Id: kml.info,v 1.1 2006/09/25 13:23:41 geodan Exp $
 name = KML
 description = Creates KML feeds from location-enabled nodes in Drupal
+dependencies = location
+package = Location
Index: kml.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/kml/kml.module,v
retrieving revision 1.4
diff -u -p -r1.4 kml.module
--- kml.module	30 Oct 2006 09:57:03 -0000	1.4
+++ kml.module	22 Jan 2007 17:37:23 -0000
@@ -3,8 +3,8 @@
 
 /**
  * @file
- * Author: Dan Karran (geodan) <dan at karran dot net>
- * Creates KML feeds from location-enabled nodes in Drupal. For more information, visit http://geodan.org/kml-module
+ * Author: Dan Karran (geodaniel) <dan at karran dot net>
+ * Creates KML feeds from location-enabled nodes in Drupal. For more information, visit http://geodaniel.org/kml-module
  */
 
 /**
@@ -17,8 +17,8 @@ function kml_help($section = 'admin/help
       $output = t('<p>The KML module allows you to create KML feeds from Drupal for use in Google Earth. It requires the use of the location module to assign geographic locations to nodes.</p>');
       $output .= t('<p>You can</p>
 <ul>
-<li>administer KML feed options at <a href="%admin-settings-kml">administer &gt;&gt; settings &gt;&gt; kml</a>.</li>
-</ul>', array('%admin-settings-kml' => url('admin/settings/kml')));
+<li>administer KML feed options at !admin_link.</li>
+</ul>', array('!admin_link' => l('admin &raquo; settings &raquo; kml', 'admin/settings/kml', NULL, NULL, NULL, FALSE, TRUE)));
       return $output;
     case 'admin/modules#description':
       return t('Module to feed KML from Drupal to Google Earth');
@@ -38,16 +38,22 @@ function kml_perm() {
 function kml_menu($may_cache) {
   $items = array();
   if ($may_cache) {
-    $items[] = array('path' => 'kml', 'title' => t('kml'),
+    $items[] = array('path' => 'kml', 
+      'title' => t('KML'),
       'callback' => 'kml_interface',
       'access' => user_access('access kml'),
-      'type' => MENU_SUGGESTED_ITEM);
+      'type' => MENU_SUGGESTED_ITEM,
+    );
   }
   else {
-    $items[] = array('path' => 'admin/settings/kml', 'title' => t('kml'),
-      'callback' => 'kml_admin_settings',
+    $items[] = array('path' => 'admin/settings/kml', 
+      'title' => t('KML'),
+      'description' => t('Settings for the KML module'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('kml_admin_form'),
       'access' => user_access('administer kml'),
-      'type' => MENU_NORMAL_ITEM);
+      'type' => MENU_NORMAL_ITEM,
+    );
   }
 
   return $items;
@@ -61,7 +67,7 @@ function kml_interface($a = NULL, $b = N
   $sortorder = variable_get('kml_sortorder', 'asc');
   if ($a == 'node') {
     if (is_numeric($b)) {
-      $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location} l ON n.vid = l.oid WHERE n.status = 1 AND l.source != 0 AND l.type = 'node' AND n.nid = %d", $b);
+      $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location} l ON n.vid = l.eid WHERE n.status = 1 AND l.source != 0 AND l.type = 'node' AND n.nid = %d", $b);
       kml_feed($nodes,$attributes);
     }
     else if ($b == 'networklink') {
@@ -69,7 +75,7 @@ function kml_interface($a = NULL, $b = N
       kml_networklink($attributes);
     }
     else {
-      $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location} l ON n.vid = l.oid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND l.source != 0 AND l.type = 'node' ORDER BY %s %s", $sortmode, $sortorder);
+      $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location} l ON n.vid = l.eid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND l.source != 0 AND l.type = 'node' ORDER BY %s %s", $sortmode, $sortorder);
       kml_feed($nodes,$attributes);
     }
   }
@@ -84,7 +90,7 @@ function kml_interface($a = NULL, $b = N
           kml_networklink($attributes);
         }
         else {
-          $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location} l ON n.vid = l.oid INNER JOIN {term_node} tn ON n.nid = tn.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND l.source != 0 AND l.type = 'node' AND tn.tid = %d ORDER BY %s %s", $b, $sortmode, $sortorder);
+          $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location} l ON n.vid = l.eid INNER JOIN {term_node} tn ON n.nid = tn.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND l.source != 0 AND l.type = 'node' AND tn.tid = %d ORDER BY %s %s", $b, $sortmode, $sortorder);
           $attributes['title'] = 'Tag: '.$tag;
           $attributes['description'] = 'Nodes tagged with '.$tag;
           kml_feed($nodes,$attributes);
@@ -107,7 +113,7 @@ function kml_interface($a = NULL, $b = N
           kml_networklink($attributes);
         }
         else {
-          $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location} l ON n.vid = l.oid INNER JOIN {node_access} na ON n.nid = na.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND l.source != 0 AND l.type = 'node' AND na.gid = %d ORDER BY %s %s", $b, $sortmode, $sortorder);
+          $nodes = db_query("SELECT n.nid, n.created FROM {node} n INNER JOIN {location} l ON n.vid = l.eid INNER JOIN {node_access} na ON n.nid = na.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND l.source != 0 AND l.type = 'node' AND na.gid = %d ORDER BY %s %s", $b, $sortmode, $sortorder);
           $attributes['title'] = 'Group: '.$group_name;
           $attributes['description'] = 'Nodes in '.$group_name;
           kml_feed($nodes,$attributes);
@@ -148,13 +154,6 @@ function kml_interface($a = NULL, $b = N
 }
 
 /**
- * Admin settings callback
- */
-function kml_admin_settings() {
-  return system_settings_form('kml_admin_settings', kml_admin_form());
-}
-
-/**
  * Form for settings page
  */
 function kml_admin_form() {
@@ -241,54 +240,7 @@ function kml_admin_form() {
     '#description' => t("The number of seconds to wait before refreshing the Network Link after the view in Google Earth has stopped moving. Requires 'onStop' to be selected above."), 
     '#maxlength' => '2', 
     '#size' => '2');
-  return $form;
-}
-
-/**
- * Implementation of hook_form_alter()
- */
-function kml_form_alter($form_id, &$form) {
-  /* this is a check for module dependencies.  the only way we
-  can ensure this check happening when the module is initially
-  enabled is to insert the check for when the form is initially
-  built, which will also be caught when the admin/module page is
-  reloaded upon submission.  this means we never want to call this
-  function when the form has been submitted, so make sure there's
-  no $_POST. */
-  if ($form_id == 'system_modules' && !$_POST) {
-    kml_system_module_validate($form);
-  }
-}
-
-/**
- * Validates module dependencies for the module.
- *
- * @param $form The form array passed from hook_form_alter.
- * 
- * Set the $module variable to a string which is the name of the module, minus
- * the .module extension.  Set $dependencies to an array of module names which
- * the module is dependent on--each element is a string which is the module name
- * minus the .module extension.  Note that this will not check for any dependencies
- * for the modules this module depends on--only those that are explicitly listed in
- * the $dependencies array.
- */
-function kml_system_module_validate(&$form) {
-  $module = 'kml';
-  $dependencies = array('location');
-
-  foreach ($dependencies as $dependency) {
-      if (!in_array($dependency, $form['status']['#default_value'])) {
-        $missing_dependency = TRUE;
-        $missing_dependency_list[] = $dependency;
-      }
-  }
-
-  if (in_array($module, $form['status']['#default_value']) && isset($missing_dependency)) {
-    db_query("UPDATE {system} SET status = 0 WHERE type = 'module' AND name = '%s'", $module);
-    $key = array_search($module, $form['status']['#default_value']);
-    unset($form['status']['#default_value'][$key]);
-    drupal_set_message(t('The module <b>%module</b> was deactivated. It requires the following disabled/non-existant modules to function properly: <b>%dependencies</b>.', array('%module' => $module, '%dependencies' => implode(', ', $missing_dependency_list))), 'error');
-  }
+  return system_settings_form($form);
 }
 
 /**
@@ -296,17 +248,17 @@ function kml_system_module_validate(&$fo
  */
 function kml_page() {
   $content = '<p>KML feeds available from this site include:</p>' . "\n";
-  $feeds[] = theme('kml_link','kml/node/networklink') .' '. t('All content from this site');
-  if (module_exist('taxonomy')) {
+  $feeds[] = theme('kml_link', 'kml/node/networklink') .' '. t('All content from this site');
+  if (module_exists('taxonomy')) {
     $feeds[] = t('Content tagged with a particular term');
   }
-  if (module_exist('og')) {
-    $feeds[] = t('Content within a particular %group', array('%group' => l('group','og')));
+  if (module_exists('og')) {
+    $feeds[] = t('Content within a particular !group', array('!group' => l('group','og')));
   }
-  if (module_exist('search')) {
-    $feeds[] = t('Content of %search', array('%search' => l('search results','search')));
+  if (module_exists('search')) {
+    $feeds[] = t('Content of !search', array('!search' => l('search results','search')));
   }
-  $content .= theme('item_list',$feeds);
+  $content .= theme('item_list', $feeds);
   print theme('page', $content);
 }
 
@@ -358,7 +310,7 @@ function kml_block_content($block) {
     if (arg(0) == 'taxonomy' && arg(1) == 'term') {
       return theme('kml_link', 'kml/term/'. arg(2) . '/networklink');
     }
-    else if (module_exist('og') && $groupnode = og_get_group_context()) {
+    else if (module_exists('og') && $groupnode = og_get_group_context()) {
       if ($groupnode->nid == arg(1)) {  // show block only on group homepage. TODO: allow admin to choose where to show block
         return theme('kml_link', 'kml/group/'. $groupnode->nid .'/networklink');
       }
@@ -372,12 +324,12 @@ function kml_block_content($block) {
 /**
  * Implementation of hook_link(). Adds KML links to individual nodes
  */
-function kml_link($type, $node = 0, $teaser = 0) {
+function kml_link($type, $node = 0, $main = 0) {
   $links = array();
   // if node type is location enabled and has lat long info
-  if ((variable_get('location_'. $node->type, 0)) && ($node->location['source'] != 0)) {
-    if ((variable_get('kml_nodelink', 1) && ($teaser == 0)) || ((variable_get('kml_nodelink_teaser', 0) && ($teaser == 1)))) {
-      $links[] = theme('kml_link',"kml/node/$node->nid");
+  if ((variable_get('location_maxnum_'. $node->type, 0)) && ($node->location['source'] != 0)) {
+    if ((variable_get('kml_nodelink', 1) && ($main == 0)) || ((variable_get('kml_nodelink_teaser', 0) && ($main == 1)))) {
+      $links['kml_themed_link_kml'] = theme('kml_link','kml/node/'. $node->nid);
     }
   }
   return $links;
@@ -387,7 +339,11 @@ function kml_link($type, $node = 0, $tea
  * Standardised KML link
  */
 function theme_kml_link($link) {
-  return l(t('kml'), $link, array('title' => t('View location in Google Earth'), 'class' => 'kml'));
+  return array(
+    'title' => t('KML'),
+    'href' => $link,
+    'attributes' => array('title' => t('View location in Google Earth'), 'class' => 'kml')
+  );
 }
 
 /**
