? cck_map.patch
Index: cck_map.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_map/cck_map.inc,v
retrieving revision 1.4
diff -u -p -r1.4 cck_map.inc
--- cck_map.inc	18 Nov 2007 01:26:50 -0000	1.4
+++ cck_map.inc	28 Jan 2008 21:47:44 -0000
@@ -1,15 +1,14 @@
 <?php
 // $Id: cck_map.inc,v 1.4 2007/11/18 01:26:50 beeradb Exp $
-function theme_cck_map($node, $field, $items, $teaser, $page, $prefix){
-  $ouptut = '';
-  
-  if ($field['widget']['label'])
-    $output .= "<h3>".$field['widget']['label']."</h3>";
- 
-  //the $prefix."mapArea" div is targetted by the javascript to insert the map element in. You need an element with this id for the map to display properly.
-  $output .= "<div id='".$prefix."mapArea'  class='mapArea' style=\"width: ".$field['widget']['mapx']."px; height: ".$field['widget']['mapy']."px\"></div>";
+function theme_cck_map($node, $field, $items, $teaser, $page, $prefix) {
+  $output = '';
+
+  if (!empty($field['widget']['label'])) {
+    $output .= '<h3>'. $field['widget']['label'] .'</h3>';
+  }
+
+  // The $prefix."mapArea" div is targeted by the javascript to insert the map element in. You need an element with this id for the map to display properly.
+  $output .= '<div id="'. $prefix .'mapArea" class="mapArea" style="width: "'. $field['widget']['mapx'] .'px; height: '. $field['widget']['mapy'] .'px"></div>';
   return $output;
-  
 }
 
-?>
\ No newline at end of file
Index: cck_map.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_map/cck_map.info,v
retrieving revision 1.1
diff -u -p -r1.1 cck_map.info
--- cck_map.info	13 Nov 2007 01:09:32 -0000	1.1
+++ cck_map.info	28 Jan 2008 21:47:44 -0000
@@ -1,7 +1,7 @@
 ; $Id: cck_map.info,v 1.1 2007/11/13 01:09:32 beeradb Exp $
-name = cck_map
+name = CCK Map
 description = Allows for the placement of a google map + location markers
 package = CCK
-dependencies = content
-
+dependencies[] = content
+core = 6.x
 
Index: cck_map.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_map/cck_map.install,v
retrieving revision 1.2
diff -u -p -r1.2 cck_map.install
--- cck_map.install	16 Nov 2007 04:05:39 -0000	1.2
+++ cck_map.install	28 Jan 2008 21:47:44 -0000
@@ -2,20 +2,63 @@
 // $Id: cck_map.install,v 1.2 2007/11/16 04:05:39 beeradb Exp $
 
 /**
+ * Implementation of hook_schema().
+ */
+function cck_map_schema() {
+  $schema['cck_map'] = array(
+    'fields' => array(
+      'nid' => array(
+        'type' => 'int',
+        'not null' => TRUE),
+      'vid' => array(
+        'type' => 'int',
+        'not null' => TRUE),
+      'maplat' => array(
+        'type' => 'float',
+        'size' => 'big',
+        'not null' => TRUE,
+        'default' => 0),
+      'maplon' => array(
+        'type' => 'float',
+        'size' => 'big',
+        'not null' => TRUE,
+        'default' => 0),
+      'mapzoom' => array(
+        'type' => 'int',
+        'not null' => TRUE,
+        'default' => 0),
+      'maptype' => array(
+        'type' => 'varchar',
+        'length' => '32')),
+  );
+  return $schema;
+}
+
+/**
  * Implementation of hook_install().
  */
 function cck_map_install() {
-  switch ($GLOBALS['db_type']) {
-    case 'mysql':
-    case 'mysqli':
-      db_query("CREATE TABLE IF NOT EXISTS {cck_map} (
-        nid int NOT NULL,
-        vid int NOT NULL,
-        maplat double NOT NULL default '0',
-        maplon double NOT NULL default '0',
-        mapzoom int NOT NULL default '0',
-        maptype varchar(32)
-      ) /*!40100 DEFAULT CHARACTER SET utf8 */");
-      break;
-  }
+  drupal_install_schema('cck_map');
+  content_notify('install', 'cck_map');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function cck_map_uninstall() {
+  content_notify('uninstall', 'cck_map');
 }
+
+/**
+ * Implementation of hook_enable().
+ */
+function cck_map_enable() {
+  content_notify('enable', 'cck_map');
+}
+
+/**
+ * Implementation of hook_disable().
+ */
+function cck_map_disable() {
+  content_notify('disable', 'cck_map');
+}
\ No newline at end of file
Index: cck_map.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_map/cck_map.module,v
retrieving revision 1.11
diff -u -p -r1.11 cck_map.module
--- cck_map.module	9 Jan 2008 02:54:07 -0000	1.11
+++ cck_map.module	28 Jan 2008 21:47:44 -0000
@@ -2,284 +2,194 @@
 // $Id: cck_map.module,v 1.11 2008/01/09 02:54:07 beeradb Exp $
 
 /**
-* @file
-* These hooks are defined by field modules, modules that define a new kind
-* of field for insertion in a content type.
-*
-* Field hooks are typically called by content.module using _content_field_invoke().
-*
-* Widget module hooks are also defined here; the two go hand-in-hand, often in
-* the same module (though they are independent).
-*
-* Widget hooks are typically called by content.module using _content_widget_invoke().
-*/
-
-/**
-* @addtogroup hooks
-* @{
-*/
-
-function cck_map_menu($may_cache) {
-
-if ($may_cache) {
-  $items[] = array(
-    'path' => 'admin/settings/cck_map',
-    'title' => t('CCK Map Settings'),
+ * @file
+ * These hooks are defined by field modules, modules that define a new kind
+ * of field for insertion in a content type.
+ *
+ * Field hooks are typically called by content.module using _content_field_invoke().
+ *
+ * Widget module hooks are also defined here; the two go hand-in-hand, often in
+ * the same module (though they are independent).
+ *
+ * Widget hooks are typically called by content.module using _content_widget_invoke().
+ */
+
+/**
+ * @addtogroup hooks
+ * @{
+ */
+
+/*
+ * Implementation of hook_theme().
+ */
+function cck_map_theme() {
+  return array(
+    'cck_map' => array(
+      'arguments' => array(
+        'node' => NULL,
+        'field' => NULL,
+        'items' => NULL,
+        'teaser' => NULL,
+        'page' => NULL),
+    ),
+  );
+}
+
+/*
+ * Implementation of hook_menu().
+ */
+function cck_map_menu() {
+  $items = array();
+  $items['admin/settings/cck_map'] = array(
+    'title' => 'CCK Map Settings',
     'description' => 'Edit CCK Map Settings',
-    'callback' => 'cck_map_admin_menu',
-    'access' => user_access('administer CCK Maps'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('cck_map_settings'),
+    'access callback' => 'user_access',
+    'access arguments' => array('administer CCK Maps'),
     'type' => MENU_NORMAL_ITEM,
-    );
-  }
+  );
   return $items;
 }
 
-function cck_map_admin_menu() {
-  return drupal_get_form('cck_map_admin_form');
-  //return theme('form', $form);
-}
-
-function cck_map_admin_form() {
+/**
+ * Menu callback: CCK Map settings page
+ */
+function cck_map_settings() {
   $form = array();
   $key = variable_get('cck_map_key', '');
   $form['api_key'] = array(
     '#type' => 'textfield',
     '#title' => t('Google Maps API Key.'),
-    '#default_value' => $key
+    '#default_value' => $key,
   );
-  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
-  $form['#submit']['cck_map_admin_menu_save'] = array();
-  $form['#method'] = "POST";
-  return $form;
+  $form['#submit'][] = 'cck_map_settings_submit';
+  return system_settings_form($form);
 }
 
-function cck_map_admin_menu_save($form_id, &$form) {
-  $key = trim(check_plain($form['api_key']));
+/**
+ * Submit function for cck_map_settings()
+ */
+function cck_map_settings_submit($form, &$form_state) {
+  $key = trim(check_plain($form_state['values']['api_key']));
   variable_set('cck_map_key', $key);
 }
 
-function cck_map_form_alter($form_id, &$form) {
-
- if ($form_id == '_content_admin_field') {
-  /*  */ 
-    if ($form['field_type']['#value'] == 'map_location') {
+/**
+ * Implementation of hook_form_alter()
+ */
+function cck_map_form_alter(&$form, &$form_state, $form_id) {
+  if ($form_id == '_content_admin_field') {
+    if ($form['type']['#value'] == 'map_location') {
       unset($form['widget']['default_value_fieldset']);
-      if (!strlen($form['widget']['description']['#value']))
-        $form['widget']['description']['#value'] = "Click the map to place markers. Once placed, you can drag markers around to change their location, you may also click to edit or remove them.";
+      if (empty($form['widget']['description']['#value'])) {
+        $form['widget']['description']['#value'] = 'Click the map to place markers. Once placed, you can drag markers around to change their location, you may also click to edit or remove them.';
+      }
     }
   }
 }
 
+/**
+ * Implementation of hook_perm()
+ */
 function cck_map_perm( ) {
   return array('administer CCK Maps');
 }
 
 /**
-* Declare information about a field type.
-*
-* @return
-*   An array keyed by field type name. Each element of the array is an associative
-*   array with these keys and values:
-*   - "label": The human-readable label for the field type.
-*/
+ * Implementation of hook_field_info().
+ */
 function cck_map_field_info() {
   return array(
-  'map_location' => array('label' => 'Map Location'),
+    'map_location' => array(
+      'label' => 'Map Location'),
   );
 }
 
+
 /**
-* Handle the parameters for a field.
-*
-* @param $op
-*   The operation to be performed. Possible values:
-*   - "form": Display the field settings form.
-*   - "validate": Check the field settings form for errors.
-*   - "save": Declare which fields to save back to the database.
-*   - "database columns": Declare the columns that content.module should create
-*     and manage on behalf of the field. If the field module wishes to handle
-*     its own database storage, this should be omitted.
-*   - "filters": If content.module is managing the database storage,
-*     this operator determines what filters are available to views.
-*     They always apply to the first column listed in the "database columns"
-*     array.
-* @param $field
-*   The field on which the operation is to be performed.
-* @return
-*   This varies depending on the operation.
-*   - The "form" operation should return an array of form elements to add to
-*     the settings page.
-*   - The "validate" operation has no return value. Use form_set_error().
-*   - The "save" operation should return an array of names of form elements to
-*     be saved in the database.
-*   - The "database columns" operation should return an array keyed by column
-*     name, with arrays of column information as values. This column information
-*     must include "type", the MySQL data type of the column, and may also
-*     include a "sortable" parameter to indicate to views.module that the
-*     column contains ordered information. Details of other information that can
-*     be passed to the database layer can be found at content_db_add_column().
-*   - The "filters" operation should return an array whose values are 'filters'
-*     definitions as expected by views.module (see Views Documentation).
-*     When proving several filters, it is recommended to use the 'name'
-*     attribute in order to let the user distinguish between them. If no 'name'
-*     is specified for a filter, the key of the filter will be used instead.
-*/
+ * Implementation of hook_field_settings().
+ */
 function cck_map_field_settings($op, $field) {
   switch ($op) {
-  case 'form':
-    $form = array();
-    return $form;
   case 'save':
     return array('lat', 'lon', 'title', 'description', 'image');
-    break;
-  case 'database columns':
-    $columns = array(
-      'lat' => array('type' => 'double', 'not null' => TRUE, 'default' => 0),
-      'lon' => array('type' => 'double', 'not null' => TRUE, 'default' => 0),
-      'title' => array('type' => 'varchar(255)', 'not null' => false, 'default' => 0),
-      'description' => array('type' => 'varchar(255)', 'not null' => false, 'default' => 0),
-      'image' => array('type' => 'varchar(255)', 'not null' => false, 'default' => 0),
-    );
   
-    return $columns;
-
-  case 'filters':
-    return array();
-
-  case 'callbacks':
+  case 'database columns':
     return array(
-      'view' => CONTENT_CALLBACK_CUSTOM,
+      'lat' => array(
+        'type' => 'float',
+        'not null' => FALSE),
+      'lon' => array(
+        'type' => 'float',
+        'not null' => FALSE),
+      'title' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE),
+      'description' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE),
+      'image' => array(
+        'type' => 'varchar',
+        'length' => '255',
+        'not null' => FALSE),
     );
-    break;
   }
 }
 
 /**
-* Define the behavior of a field type.
-*
-* @param $op
-*   What kind of action is being performed. Possible values:
-*   - "load": The node is about to be loaded from the database. This hook
-*     should be used to load the field.
-*   - "view": The node is about to be presented to the user. The module
-*     should prepare and return an HTML string containing a default
-*     representation of the field.
-*   - "validate": The user has just finished editing the node and is
-*     trying to preview or submit it. This hook can be used to check or
-*     even modify the node. Errors should be set with form_set_error().
-*   - "submit": The user has just finished editing the node and the node has
-*     passed validation. This hook can be used to modify the node.
-*   - "insert": The node is being created (inserted in the database).
-*   - "update": The node is being updated.
-*   - "delete": The node is being deleted.
-* @param &$node
-*   The node the action is being performed on. This argument is passed by
-*   reference for performance only; do not modify it.
-* @param $field
-*   The field the action is being performed on.
-* @param &$items
-* An array containing the values of the field in this node. Changes to this variable will
-* be saved back to the node object.
-* Note that, in order to ensure consistency, this variable contains an array regardless of
-* whether field is set to accept multiple values or not.
-* @return
-*   This varies depending on the operation.
-*   - The "load" operation should return an object containing extra values
-*     to be merged into the node object.
-*   - The "view" operation should return a string containing an HTML
-*     representation of the field data.
-*   - The "insert", "update", "delete", "validate", and "submit" operations
-*     have no return value.
-*
-* In most cases, only "view" and "validate" are relevant operations; the rest
-* have default implementations in content_field() that usually suffice.
-*/
+ * Implementation of hook_field().
+ */
 function cck_map_field($op, &$node, $field, &$items, $teaser, $page) {
   switch ($op) {
     case 'update':
-       $rowcount = db_fetch_object(db_query("SELECT nid from {cck_map} where nid = %d and vid = %d", $node->nid, $node->vid));
-       if ($rowcount->nid) {
-         db_query("update {cck_map} set maplat = %f, maplon = %f, mapzoom = %d, maptype ='%s' where nid = %d and vid =%d", $items['maplat'], $items['maplon'], $items['mapzoom'], $items['maptype'], $node->nid, $node->vid);
-         unset($items['maplat']);
-         unset($items['maplon']);
-         unset($items['mapzoom']);
-         unset($items['maptype']);
-         break;
-       }
+      $rowcount = db_fetch_object(db_query("SELECT nid FROM {cck_map} WHERE nid = %d AND vid = %d", $node->nid, $node->vid));
+      if ($rowcount->nid) {
+        db_query("UPDATE {cck_map} SET maplat = %f, maplon = %f, mapzoom = %d, maptype ='%s' WHERE nid = %d AND vid = %d", $items['maplat'], $items['maplon'], $items['mapzoom'], $items['maptype'], $node->nid, $node->vid);
+        unset($items['maplat']);
+        unset($items['maplon']);
+        unset($items['mapzoom']);
+        unset($items['maptype']);
+        break;
+      }
+
     case 'insert':
-      db_query("insert into {cck_map} (nid, vid, maplat, maplon, mapzoom, maptype) VALUES (%d, %d, %f, %f, %d, '%s')", $node->nid, $node->vid, $items['maplat'], $items['maplon'], $items['mapzoom'], $items['maptype']);
+      db_query("INSERT INTO {cck_map} (nid, vid, maplat, maplon, mapzoom, maptype) VALUES (%d, %d, %f, %f, %d, '%s')", $node->nid, $node->vid, $items['maplat'], $items['maplon'], $items['mapzoom'], $items['maptype']);
       unset($items['maplat']);
       unset($items['maplon']);
       unset($items['mapzoom']);
       unset($items['maptype']);
       break;
-    case 'validate':
-      
-      break;
-    case 'submit':
-       break;
-    case 'view':
-      if (count($items[0]) || $field['widget']['always_display']) {
-        include_once(drupal_get_path('module', 'cck_map') .'/cck_map.inc');
-	//use cck_map_nummaps on output to avoid namespace colisions
-        static $cck_map_nummaps =0 ;
-        static $maps_js_added = false;
-    
-        //ensure that the google maps javascrip is only added once
-        if (!$maps_js_added) {
-          drupal_set_html_head("<script type='text/javascript' src='http://maps.google.com/maps?file=api&v=2&key=". variable_get('cck_map_key', '') ."'></script>" );
-          $maps_js_added = true;
-        }
-
-         
-         $prefix = str_replace("_", "-", $field['field_name']) . $cck_map_nummaps;
-         $js_prefix = str_replace("-", "_", $field['field_name']) . $cck_map_nummaps;
-   
-        drupal_add_js(drupal_get_path('module', 'cck_map') .'/cck_map.js');
-         //create the markers for this map.
-        cck_map_create_markers_js($items, $js_prefix);
-
-        $items['maplat'] ? $lat = $items['maplat'] : $lat = 0;
-        $items['maplon'] ? $lon = $items['maplon'] : $lon = 0;
-        $items['mapzoom'] ? $zoom = $items['mapzoom'] : $zoom = 0;
-        $items['maptype'] ? $maptype = $items['maptype'] : $maptype = '';
-        //google maps doesn't like relative urls for marker images. This totally sucks and I hope to fix it. I appologize.
-        $tld = $_SERVER['SERVER_NAME'];
-
-        drupal_add_js("\$(document).ready(function () {var {$js_prefix}map;{$js_prefix}map = new gmapClientController('{$prefix}',". $lat .", ". $lon .", ". $zoom .", '". $maptype ."', {$js_prefix}markers, '". $tld ."'); } );", 'inline');
-      
-        $theme = theme('cck_map', $node, $field, $items, $teaser, $page, $prefix);
-        $cck_map_nummaps++;
-        return $theme;
-      }
-      break;
+ 
     case 'load':
-      if ($node->nid) {
+      if (!empty($node->nid)) {
         $map_info = db_fetch_array(db_query("SELECT maplat, maplon, mapzoom, maptype from {cck_map} WHERE nid = %d and vid = %d", $node->nid, $node->vid));
         if (is_array($map_info)) {
           return array($field['field_name'] => array_merge($node->$field['field_name'], $map_info));
         }
       }
       else {
-        return  array($field['field_name'] => array_merge($node->$field['field_name'], array('maplat' => 0, 'maplon' => 0, 'mapzoom' => 0, 'maptype' => '')));
+        return array($field['field_name'] => array_merge($node->$field['field_name'], array('maplat' => 0, 'maplon' => 0, 'mapzoom' => 0, 'maptype' => '')));
       }
       break;
   }
 }
 
 /**
-* Declare information about a formatter.
-*
-* @return
-*   An array keyed by formatter name. Each element of the array is an associative
-*   array with these keys and values:
-*   - "label": The human-readable label for the formatter.
-*   - "field types": An array of field type names that can be displayed using
-*     this formatter.
-*/
+ * Implementation of hook_content_is_empty().
+ */
+function cck_map_content_is_empty($item, $field) {
+  echo 'empty?';
+}
+
+/**
+ * Implementation of hook_field_formatter_info().
+ */
 function cck_map_field_formatter_info() {
   return array(
-      'map_location' => array(
+    'map_location' => array(
       'label' => 'Default map output',
       'field types' => array('map_location'),
     ),
@@ -287,327 +197,264 @@ function cck_map_field_formatter_info() 
 }
 
 /**
-* Prepare an individual item for viewing in a browser.
-*
-* @param $field
-*   The field the action is being performed on.
-* @param $item
-*   An array, keyed by column, of the data stored for this item in this field.
-* @param $formatter
-*   The name of the formatter being used to display the field.
-* @param $node
-*   The node object, for context. Will be NULL in some cases.
-*   Warning : when displaying field retrieved by Views, $node will not
-*   be a "full-fledged" node object, but an object containg the data returned
-*   by the Views query (at least nid, vid, changed)
-* @return
-*   An HTML string containing the formatted item.
-*
-* In a multiple-value field scenario, this function will be called once per
-* value currently stored in the field. This function is also used as the handler
-* for viewing a field in a views.module tabular listing.
-*
-* It is important that this function at the minimum perform security
-* transformations such as running check_plain() or check_markup().
-*/
+ * Implementation of hook_field_formatter().
+ */
 function cck_map_field_formatter($field, $item, $formatter, $node) {
   return false;
 }
 
 /**
-* Declare information about a widget.
-*
-* @return
-*   An array keyed by widget name. Each element of the array is an associative
-*   array with these keys and values:
-*   - "label": The human-readable label for the widget.
-*   - "field types": An array of field type names that can be edited using
-*     this widget.
-*/
+ * Implementation of hook_widget_info().
+ */
 function cck_map_widget_info() {
   return array(
     'map_location' => array(
-    'label' => 'Map Location',
-    'field types' => array('map_location'),
+      'label' => 'Map Location',
+      'field types' => array('map_location'),
     ),
   );
 }
 
 /**
-* Handle the parameters for a widget.
-*
-* @param $op
-*   The operation to be performed. Possible values:
-*   - "form": Display the widget settings form.
-*   - "validate": Check the widget settings form for errors.
-*   - "save": Declare which pieces of information to save back to the database.
-* @param $widget
-*   The widget on which the operation is to be performed.
-* @return
-*   This varies depending on the operation.
-*   - The "form" operation should return an array of form elements to add to
-*     the settings page.
-*   - The "validate" operation has no return value. Use form_set_error().
-*   - The "save" operation should return an array of names of form elements to
-*     be saved in the database.
-*/
+ * Implementation of hook_widget_settings().
+ */
 function cck_map_widget_settings($op, $widget) {
-
   switch ($op) {
     case 'form':
       $form = array();
       $key = variable_get('cck_map_key', 0);
       
-      if (!$key) {
-        $form['alert'] = array(
-          '#value' => "<p class='error'>You must first get a google maps api key and enter it into the CCK Map settings located ". l('here', 'admin/settings/cck_map') ."</p>",
-          '#weight' => -50,
-          );
+      if (empty($key)) {
+        form_set_error('', t('You have to <a href="@link">provide a Google Maps API key</a> to use CCK Maps.', array('@link' => url('admin/settings/cck_map'))));
       }
-  /*    $form['use_image'] = array(
-        '#type' => 'checkbox',
-        '#title' => t('Use Custom Map Markers'),
-        '#default_value' => isset($widget['use_image']) ? $widget['use_image'] : 1
-      );*/
-
-       $form['use_title'] = array(
+      $form['use_title'] = array(
         '#type' => 'checkbox',
         '#title' => t('Allow Marker Titles.'),
-        '#default_value' => isset($widget['use_title']) ? $widget['use_title'] : 1
+        '#default_value' => isset($widget['use_title']) ? $widget['use_title'] : 1,
       );
-       $form['use_description'] = array(
+      $form['use_description'] = array(
         '#type' => 'checkbox',
         '#title' => t('Allow Marker Descriptions.'),
-        '#default_value' => isset($widget['use_description']) ? $widget['use_description'] : 1
+        '#default_value' => isset($widget['use_description']) ? $widget['use_description'] : 1,
       );
-
-       $form['mapx'] = array(
+      $form['mapx'] = array(
         '#type' => 'textfield',
         '#title' => t('Map output width'),
         '#default_value' => isset($widget['mapx']) ? $widget['mapx'] : 400,
-        '#description' => 'The width(in pixels) that the map is displayed to end users'
+        '#description' => t('The width (in pixels) of the map that is displayed to end users.'),
       );
-       $form['mapy'] = array(
+      $form['mapy'] = array(
         '#type' => 'textfield',
         '#title' => t('Map output height'),
         '#default_value' => isset($widget['mapy']) ? $widget['mapy'] : 300,
-        '#description' => 'The height(in pixels) that the map is displayed to end users'
+        '#description' => t('The height (in pixels) of the map that is displayed to end users.'),
       );
-
-       $form['always_display'] = array(
+      $form['always_display'] = array(
         '#type' => 'checkbox',
         '#title' => t('Display map even if no markers have been placed?'),
         '#default_value' => isset($widget['always_display']) ? $widget['always_display'] : 0,
-        '#description' => 'When selected the map will always display, regardless of whether you have placed any markers'
+        '#description' => t('When selected the map will always display, regardless of whether you have placed any markers'),
       );
-   return $form;
-    break;
-  case 'validate':
-    if (!is_numeric($widget['mapx']))
-      form_set_error('mapx', 'map width value must be numeric');
-    if (!is_numeric($widget['mapy']))
-      form_set_error('mapy', 'map height must be numeric');
+      return $form;
+    
+    case 'validate':
+      if (!is_numeric($widget['mapx'])) {
+        form_set_error('mapx', 'map width value must be numeric.');
+      }
+      if (!is_numeric($widget['mapy'])) {
+        form_set_error('mapy', 'map height must be numeric.');
+      }
+      break;
 
-    break;
-  case 'save':
-    return array('use_title', 'use_description', 'use_image', 'mapx', 'mapy', 'always_display');
-  case 'callbacks':
-    return array(
-      'default value' => CONTENT_CALLBACK_DEFAULT,
-    );
+    case 'save':
+      return array('use_title', 'use_description', 'use_image', 'mapx', 'mapy', 'always_display');
   }
 }
 
 /**
-* Define the behavior of a widget.
-*/
-function cck_map_widget($op, &$node, $field, &$items) {
-  switch ($op) {
-    case 'form':
-      static $maps_js_added = false;
+ * Implementation of hook_widget().
+ */
+function cck_map_widget(&$form, &$form_state, $field, $items, $delta = 0) {
+  static $maps_js_added = false;
   
-      //ensure that the google maps javascrip is only added once
-      if (!$maps_js_added) {
-        drupal_set_html_head("<script type='text/javascript' src='http://maps.google.com/maps?file=api&v=2&key=". variable_get('cck_map_key', '') ."'></script>" );
-        $maps_js_added = true;
-      }
+  // ensure that the google maps javascrip is only added once
+  if (!$maps_js_added) {
+    drupal_set_html_head('<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key='. variable_get('cck_map_key', '') .'"></script>');
+    $maps_js_added = true;
+  }
 
-      $prefix = str_replace("_", "-", $field['field_name']);
-      drupal_add_css(drupal_get_path('module', 'cck_map') .'/map-edit.css');
-      drupal_add_js(drupal_get_path('module', 'cck_map') .'/cck_map.js');
+  $prefix = str_replace("_", "-", $field['field_name']);
+  drupal_add_css(drupal_get_path('module', 'cck_map') .'/map-edit.css');
+  drupal_add_js(drupal_get_path('module', 'cck_map') .'/cck_map.js');
 
-      $form = array();
-      $form = _cck_map_get_control_fields($field, $items);
-      //make sure all point elements are within a span, so javascript can more easily target them for editing/deletion.
-      $points_delta = 99;
-       $form[$field['field_name']]['points_open'] = array(
-        '#value' => '<span id="'. $prefix .'markers">',
-        '#weight' => $points_delta -1
-      );
-  
-     if ($_POST[$field['field_name']]) {
-       if ($_POST[$field['field_name']]['itemcount'] > 0) {
-         $items = $_POST[$field['field_name']];
-         foreach ($items as $delta => $values) {
-            //filter out non-database control and helper fields
-            if (is_numeric($delta)) {
-               _cck_map_create_point_widget($form[$field['field_name']][$delta], $field, $values, $points_delta .".". $delta);
-            }
-          }
+  $form = array();
+  $form = _cck_map_get_control_fields($field, $items);
+  //make sure all point elements are within a span, so javascript can more easily target them for editing/deletion.
+  $points_delta = 99;
+  $form[$field['field_name']]['points_open'] = array(
+    '#value' => '<span id="'. $prefix .'markers">',
+    '#weight' => $points_delta -1
+  );
+
+  if (!empty($_POST[$field['field_name']])) {
+    if (!empty($_POST[$field['field_name']]['itemcount'])) {
+      $items = $_POST[$field['field_name']];
+      foreach ($items as $delta => $values) {
+        //filter out non-database control and helper fields
+        if (is_numeric($delta)) {
+          _cck_map_create_point_widget($form[$field['field_name']][$delta], $field, $values, $points_delta .".". $delta);
         }
-       } 
-       else {
-         foreach ($items as $delta => $values) {
-             if (is_numeric($delta)) {
-               _cck_map_create_point_widget($form[$field['field_name']][$delta], $field, $values, $points_delta .".". $delta);
-             }
-         }
-      }
-   
-      $form[$field['field_name']]['points_close'] = array(
-        '#value' => '</span>',
-        '#weight' => $points_delta + 1
-      );
-    //number of items is always 4 less than the count, due to associate map view fields
-    $form[$field['field_name']]['itemcount'] = array('#type' => 'hidden', '#value' => count($items)-4 );
-    return $form;
-    break;
-    case 'validate':
-       //gotta be careful here, 0 is a valid value for both lat or lon
-       if ($field['required'] && (!is_numeric($items[0]['lat'])|| !is_numeric($items[0]['lon']))) 
-          form_set_error($field['field_name'], $field['widget']['label'] ." requires you to place at least one marker.");
-      
-       foreach ($items as $delta => $values) {
-         //filter out non numeric map view information
-         if (is_numeric($delta))
-           if (!is_numeric($values['lat']) || !is_numeric($values['lon']))
-              unset($items[$delta]);
-       }
-     
-       break;
-    case 'process form values':
-      unset($items['markerTitle']);
-      unset($items['markerImage']);
-      unset($items['markerDescription']);
-      unset($items['itemcount']);
-      break;
+      }
+    }
+  } 
+  else {
+    foreach ($items as $delta => $values) {
+      if (is_numeric($delta)) {
+        _cck_map_create_point_widget($form[$field['field_name']][$delta], $field, $values, $points_delta .".". $delta);
+      }
+    }
+  }
+
+  $form[$field['field_name']]['points_close'] = array(
+    '#value' => '</span>',
+    '#weight' => $points_delta + 1
+  );
+  //number of items is always 4 less than the count, due to associate map view fields
+  $form[$field['field_name']]['itemcount'] = array('#type' => 'hidden', '#value' => count($items)-4 );
+  $form['#validate'][] = 'cck_map_widget_form_validate';
+  $form['#validate_field'] = $field;
+  $form['#validate_items'] = $items;
+  return $form;
+}
+
+function cck_map_widget_form_validate($form, &$form_state) {
+  $field = $form['#validate_field'];
+  $items = $form['#validate_items'];
+  //gotta be careful here, 0 is a valid value for both lat or lon
+  if (!empty($field['required']) && (!is_numeric($items[0]['lat']) || !is_numeric($items[0]['lon']))) { 
+    form_set_error($field['field_name'], $field['widget']['label'] ." requires you to place at least one marker.");
+  }
+  foreach ($items as $delta => $values) {
+    //filter out non numeric map view information
+    if (is_numeric($delta)) {
+      if (!is_numeric($values['lat']) || !is_numeric($values['lon'])) {
+        unset($items[$delta]);
+      }
+    }
   }
 }
 
 function _cck_map_create_point_widget(&$form, $field, $value, $delta) {
-      $form['#weight'] = $delta;
-      $form['lat'] = array('#type' => 'hidden', '#default_value' => $value['lat']);
-      $form['lon'] = array('#type' => 'hidden', '#default_value' => $value['lon']);
-      if ($field['widget']['use_title'])
-        $form['title'] = array('#type' => 'hidden', '#default_value' => $value['title']);
-      if ($field['widget']['use_description'])
-        $form['description'] = array('#type' => 'hidden', '#default_value' => $value['description']);
-      if ($field['widget']['use_image'])
-        $form['image'] = array('#type' => 'hidden', '#default_value' => $value['image'] );
+  $form['#weight'] = $delta;
+  $form['lat'] = array('#type' => 'hidden', '#default_value' => $value['lat']);
+  $form['lon'] = array('#type' => 'hidden', '#default_value' => $value['lon']);
+  if ($field['widget']['use_title']) {
+    $form['title'] = array('#type' => 'hidden', '#default_value' => $value['title']);
+  }
+  if ($field['widget']['use_description']) {
+    $form['description'] = array('#type' => 'hidden', '#default_value' => $value['description']);
+  }
+  if ($field['widget']['use_image']) {
+    $form['image'] = array('#type' => 'hidden', '#default_value' => $value['image']);
+  }
 }
 
 /*
-* Returns the map and some addition fields used by the javascript to add/edit markers, as well as fields about the map view which are saved outside of CCK.
-*/
+ * Returns the map and some addition fields used by the javascript to add/edit markers, as well as fields about the map view which are saved outside of CCK.
+ */
 function _cck_map_get_control_fields($field, $items) {
   $form = array();
   $prefix = str_replace("_", "-", $field['field_name']);
   //js obviously dislikes '-' characters in variable names.
   $js_prefix = str_replace("-", "_", $field['field_name']);
-   $form[$field['field_name']] = array(
-        '#type' => 'fieldset',
-        '#title' => $field['widget']['label'],
-        '#collapsible' => true, 
-        '#collapsed' => false,
-        '#weight' => $field['widget']['weight'],
-        '#attributes' => array('class' => 'cck-location-map-fieldset'),
-        '#tree' => true
-      );
-      
-      $form[$field['field_name']]['map'] = array(
-        "#value" => "<div id='". $prefix ."mapArea'  class='mapArea' style=\"width: 400px; height: 300px\"></div>", 
-        '#prefix' =>  $field['widget']['description'] ? "<p>". $field['widget']['description'] ."</p>" : '',
-        '#weight' => -15
-      );
-      
-      if ($field['widget']['use_title'] || $field['widget']['use_description'] || $field['widget']['use_image']) {
-        $form[$field['field_name']]['groupingOpen'] = array('#value' => "<div class='mapFieldGrouping'>", '#weight' => -5);
-        if ($field['widget']['use_title']) {
-          $form[$field['field_name']]['markerTitle'] = array(
-            '#type' => 'textfield',
-            '#title' => t('Marker Title'),
-            '#required' => false,
-            '#attributes' => array('class' => 'cck_map_option'),
-            '#weight' => -3
-          );        
-        }
-        
-        if ($field['widget']['use_description']) {
-            $form[$field['field_name']]['markerDescription'] = array(
-              '#type' => 'textarea',
-              '#title' => t('Marker Description'),
-              '#required' => false,
-              '#attributes' => array('class' => 'cck_map_option'),
-              '#weight' => -1
-            );    
-        }
-        $form[$field['field_name']]['openControls'] = array('#value' => '<div class="current_map_icon">');
-        if ($field['widget']['use_image']) {
-          $icon_options = array();
-          $icon_files = array("house.png" => "house", "greenflag.png" => "flag");
-          $icon_path = drupal_get_path('module', 'cck_map') ."/icons/";
-          foreach ($icon_files as $file => $description) {
-            $icon_options['/'. $icon_path . $file] = $description;
-          }
-        
-          
-          if (count($icon_options)) {
-            $form[$field['field_name']]['markerImage'] = array(
-              '#type' => 'select',
-              '#title' => t('Marker Image'),
-              '#options' => $icon_options,
-              '#attributes' => array('onchange' => "{$js_prefix}map.updateMarkerImage();"),
-              '#suffix' => '<span id="'. $prefix .'current_map_image"> </span>',
-              '#weight' => 1
-            );
-          
-          }
-          
-      }
-        $form[$field['field_name']]['edit_controls'] = array(
-          '#value' => '</div><span class="cck-map-editControls" id="'. $prefix .'editControls"></span>',
-          '#weight' => 200,
+  $form[$field['field_name']] = array(
+    '#type' => 'fieldset',
+    '#title' => $field['widget']['label'],
+    '#collapsible' => true, 
+    '#collapsed' => false,
+    '#weight' => $field['widget']['weight'],
+    '#attributes' => array('class' => 'cck-location-map-fieldset'),
+    '#tree' => true
+  );
+
+  $form[$field['field_name']]['map'] = array(
+    '#value' => '<div id="'. $prefix .'mapArea"  class="mapArea" style="width: 400px; height: 300px"></div>', 
+    '#prefix' =>  $field['widget']['description'] ? '<p>'. $field['widget']['description'] .'</p>' : '',
+    '#weight' => -15
+  );
+
+  if ($field['widget']['use_title'] || $field['widget']['use_description'] || $field['widget']['use_image']) {
+    $form[$field['field_name']]['groupingOpen'] = array('#value' => '<div class="mapFieldGrouping">', '#weight' => -5);
+    if ($field['widget']['use_title']) {
+      $form[$field['field_name']]['markerTitle'] = array(
+        '#type' => 'textfield',
+        '#title' => t('Marker Title'),
+        '#required' => false,
+        '#attributes' => array('class' => 'cck_map_option'),
+        '#weight' => -3
+      );        
+    }
+
+    if ($field['widget']['use_description']) {
+        $form[$field['field_name']]['markerDescription'] = array(
+          '#type' => 'textarea',
+          '#title' => t('Marker Description'),
+          '#required' => false,
+          '#attributes' => array('class' => 'cck_map_option'),
+          '#weight' => -1
+        );    
+    }
+    $form[$field['field_name']]['openControls'] = array('#value' => '<div class="current_map_icon">');
+    if ($field['widget']['use_image']) {
+      $icon_options = array();
+      $icon_files = array("house.png" => "house", "greenflag.png" => "flag");
+      $icon_path = drupal_get_path('module', 'cck_map') ."/icons/";
+      foreach ($icon_files as $file => $description) {
+        $icon_options['/'. $icon_path . $file] = $description;
+      }
+      if (!empty($icon_options)) {
+        $form[$field['field_name']]['markerImage'] = array(
+          '#type' => 'select',
+          '#title' => t('Marker Image'),
+          '#options' => $icon_options,
+          '#attributes' => array('onchange' => "{$js_prefix}map.updateMarkerImage();"),
+          '#suffix' => '<span id="'. $prefix .'current_map_image"> </span>',
+          '#weight' => 1
         );
-        $form[$field['field_name']]['grouping_close'] = array('#value' => "</div>", '#weight' => 250);
       }
-      
-      $field['multiple'] ? $m = 'true' : $m ='false';
-      $field['widget']['use_title'] ? $t = 'true' : $t = 'false';
-      $field['widget']['use_description'] ? $d = 'true' : $d = 'false';
-      $field['widget']['use_image'] ? $i = 'true' : $i = 'false';
-      $tld = $_SERVER['SERVER_NAME'];
-      $js = "var {$js_prefix};\$(document).ready(function() { {$js_prefix}map = new gmapAdminController('{$prefix}',". $m .", ". $t .", ". $d .", ". $i .", '". $tld ."'); });";
-      drupal_add_js($js, 'inline');
-      
-      $form[$field['field_name']]['maplon'] = array('#type' => 'hidden',
-                            '#default_value' => $items['maplon'] ? $items['maplon'] : '0');
-    
-      $form[$field['field_name']]['maplat'] = array(
-        '#type' => 'hidden',
-        '#default_value' => $items['maplat'] ? $items['maplat'] : '0',
-      );
-      $form[$field['field_name']]['mapzoom'] = array(
-        '#type' => 'hidden',
-        '#default_value' =>  $items['mapzoom'] ? $items['mapzoom'] : '0',
-      );
-
-      $form[$field['field_name']]['maptype'] = array(
-        '#type' => 'hidden',
-        '#default_value' =>  $items['maptype'] ? $items['maptype'] : '',
-      );
-     
+    }
+    $form[$field['field_name']]['edit_controls'] = array(
+      '#value' => '</div><span class="cck-map-editControls" id="'. $prefix .'editControls"></span>',
+      '#weight' => 200,
+    );
+    $form[$field['field_name']]['grouping_close'] = array('#value' => "</div>", '#weight' => 250);
+  }
 
-    return $form;
+  $field['multiple'] ? $m = 'true' : $m ='false';
+  $field['widget']['use_title'] ? $t = 'true' : $t = 'false';
+  $field['widget']['use_description'] ? $d = 'true' : $d = 'false';
+  $field['widget']['use_image'] ? $i = 'true' : $i = 'false';
+  $tld = $_SERVER['SERVER_NAME'];
+  $js = "var {$js_prefix};\$(document).ready(function() { {$js_prefix}map = new gmapAdminController('{$prefix}',". $m .", ". $t .", ". $d .", ". $i .", '". $tld ."'); });";
+  drupal_add_js($js, 'inline');
+
+  $form[$field['field_name']]['maplon'] = array(
+    '#type' => 'hidden',
+    '#default_value' => !empty($items['maplon']) ? $items['maplon'] : '0'
+  );
+  $form[$field['field_name']]['maplat'] = array(
+    '#type' => 'hidden',
+    '#default_value' => !empty($items['maplat']) ? $items['maplat'] : '0',
+  );
+  $form[$field['field_name']]['mapzoom'] = array(
+    '#type' => 'hidden',
+    '#default_value' =>  !empty($items['mapzoom']) ? $items['mapzoom'] : '0',
+  );
+  $form[$field['field_name']]['maptype'] = array(
+    '#type' => 'hidden',
+    '#default_value' =>  !empty($items['maptype']) ? $items['maptype'] : '',
+  );
+  return $form;
 }
 
 function cck_map_create_markers_js($items, $js_prefix) {
@@ -615,15 +462,15 @@ function cck_map_create_markers_js($item
   $vars ="var {$js_prefix}{$cck_map_nummaps}markers = new Array();";
   $on_load = "";
   foreach ($items as $delta => $item) {
-     if (is_numeric($delta) && $item['lat'] && $item['lon']) {
-        $on_load .= "var marker{$delta} = new Object();";
-        $on_load .= "marker{$delta}.lat = ". $item['lat'] .";";
-        $on_load .= "marker{$delta}.lon = ". $item['lon'] .";";
-        $on_load .= "marker{$delta}.title = \"". htmlentities($item['title']) ."\";";
-        $on_load .= "marker{$delta}.description = \"". htmlentities($item['description']) ."\";";
-        $on_load .= "marker{$delta}.image = '". $item['image'] ."';";
-        $on_load .= "{$js_prefix}{$cck_map_nummaps}markers[{$js_prefix}{$cck_map_nummaps}markers.length] = marker{$delta};";
-     }
+    if (is_numeric($delta) && $item['lat'] && $item['lon']) {
+      $on_load .= 'var marker{$delta} = new Object();';
+      $on_load .= 'marker{'. $delta .'}.lat = '. $item['lat'] .';';
+      $on_load .= 'marker{'. $delta .'}.lon = '. $item['lon'] .';';
+      $on_load .= 'marker{'. $delta .'}.title = "'. htmlentities($item['title']) .'";';
+      $on_load .= 'marker{'. $delta .'}.description = "'. htmlentities($item['description']) .'";';
+      $on_load .= 'marker{'. $delta .'}.image = "'. $item['image'] .'";';
+      $on_load .= "{$js_prefix}{$cck_map_nummaps}markers[{$js_prefix}{$cck_map_nummaps}markers.length] = marker{$delta};";
+    }
   }
   drupal_add_js("{$vars}\$(document).ready(function() { ". $on_load ." } ); ", 'inline');
- }
\ No newline at end of file
+}
Index: cck_map.theme
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_map/cck_map.theme,v
retrieving revision 1.1
diff -u -p -r1.1 cck_map.theme
--- cck_map.theme	13 Nov 2007 01:09:04 -0000	1.1
+++ cck_map.theme	28 Jan 2008 21:47:44 -0000
@@ -5,8 +5,7 @@ function theme_cck_map($node, $field, $i
 	drupal_add_js("/maps.google.com/maps?file=api&v=2&key=".variable_get('cck_map_key', ''));
 	drupal_add_js(drupal_get_path('module', 'cck_map') .'/cck_map.js');
 
-
-	$ouptut = '';
+	$output = '';
 	$prefix = str_replace("_", "-", $field['field_name']);
 	$jsPrefix = str_replace("-", "_", $field['field_name']);
 
@@ -24,10 +23,9 @@ function theme_cck_map($node, $field, $i
 	$tld = $_SERVER['SERVER_NAME'];
 
 	
-	$output .= "<script type=\"text/javascript\" language=\"javascript\">var {$jsPrefix}map;{$jsPrefix}map = new gmapClientController('{$prefix}',".$lat.", ".$lon.", ".$zoom.", '".$mapType."', '".$points."', '".$tld."');</script>";
+	$output .= '<script type="text/javascript" language="javascript">var {'. $jsPrefix .'}map;{'. $jsPrefix ."}map = new gmapClientController('{". $prefix ."}',". $lat .', '.$lon .', '. $zoom .", '". $mapType ."', '". $points ."', '". $tld ."');</script>";
 	
 	return $output;
 	
 }
 
-?>
\ No newline at end of file
