? exif-geotag_and_E_ALL_fixes.20090929.patch
Index: CHANGES.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/exif/Attic/CHANGES.txt,v
retrieving revision 1.1.2.8
diff -u -p -r1.1.2.8 CHANGES.txt
--- CHANGES.txt	28 Sep 2009 06:52:42 -0000	1.1.2.8
+++ CHANGES.txt	28 Sep 2009 11:27:18 -0000
@@ -10,6 +10,11 @@ ACKNOWLEDGEMENTS
 
 CHANGES LOG
 -----------
+2009/09/24 dman
+* Cleaned up PHP E_ALL notices (undefined variables) in a few places, including exif.class
+* Typo in exif_nodeapi()
+* Applied fix for array-structured Geo tags http://drupal.org/node/473140
+
 2009/09/24
 * Applied Drupal Code styles
 
Index: exif.class.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/exif/Attic/exif.class.php,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 exif.class.php
--- exif.class.php	28 Sep 2009 06:52:42 -0000	1.1.2.4
+++ exif.class.php	28 Sep 2009 11:27:18 -0000
@@ -40,7 +40,7 @@ Class Exif {
 
     foreach ($arCckFields as $field) {
       $ar = explode("_", $field['field_name']);
-      if(in_array($ar[1], $arSections) && $ar[0] == 'field'){
+      if ($ar[0] == 'field' && isset($ar[1]) && in_array($ar[1], $arSections)) {
         unset($ar[0]);
         $section = $ar[1];
         unset($ar[1]);
@@ -60,15 +60,16 @@ Class Exif {
     if (!file_exists($file)) {
       return array();
     }
+    // TODO should check valid image type. Currently throws warnings on PNGs
     $exif = exif_read_data($file, 0);
     $arSmallExif = array();
-    foreach ($exif as $key => $value) {
+    foreach ((array)$exif as $key => $value) {
       $arSmallExif[strtolower($key)] = $value;
     }
     $info = array();
 
     foreach ($arTagNames as $tagName) {
-      if ($tagName['section'] != 'iptc') {
+      if ($tagName['section'] != 'iptc' && !empty($arSmallExif[$tagName['tag']])) {
         $info[$tagName['section'] .'_'. $tagName['tag']] = $arSmallExif[$tagName['tag']];
       }
     }
@@ -79,7 +80,7 @@ Class Exif {
   public function readIPTCTags($file,$arTagNames=array()) {
     $humanReadableKey = $this->getHumanReadableIPTCkey();
     $size = GetImageSize ($file, $infoImage);
-    $iptc = iptcparse($infoImage["APP13"]);
+    $iptc = empty($infoImage["APP13"]) ? array() : iptcparse($infoImage["APP13"]);
     $arSmallIPTC = array();
     if (is_array($iptc)) {
       foreach($iptc as $key => $value)
Index: exif.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/exif/exif.module,v
retrieving revision 1.9.2.8
diff -u -p -r1.9.2.8 exif.module
--- exif.module	28 Sep 2009 06:52:42 -0000	1.9.2.8
+++ exif.module	28 Sep 2009 11:27:19 -0000
@@ -64,20 +64,20 @@ function exif_admin_settings_form() {
 /**
  * implementation of hook_nodeapi
  */
-function exif_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+function exif_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
 
   if ($teaser) {
     return;
   }
 
-
   switch ($op) {
     case 'insert':
     case 'update':
-      $info = content_types($node->type);
-      $fields = $info['fields'];
+    case 'presave':
 
       if (_exif_check_for_exif_data($node->type)) {
+        $info = content_types($node->type);
+        $fields = $info['fields'];
         $exif = _exif_get_class();
 
         //get all the fields that will be filled with exif data
@@ -89,7 +89,7 @@ function exif_nodeapi(&$node, $op, $a3 =
         $fid = db_result(db_query("SELECT fid FROM {files} WHERE filepath = '%s'", $image_path));
         $file = file_create_path($image_path);
 
-        $data1 = $exif->readExifTags($file, $ar_exif_fields);
+        $data1 = _exif_reformat($exif->readExifTags($file, $ar_exif_fields));
         $data2 = $exif->readIPTCTags($file, $ar_exif_fields);
         $data = array_merge($data1, $data2);
 
@@ -174,12 +174,15 @@ function exif_admin_settings() {
   $filepath = drupal_get_path('module', 'exif') .'/sample.jpg';
   $exif = _exif_get_class();
   $ar_exif = read_exif_data($filepath, 0, TRUE);
+  // CCK field names must be lowercase
+  $ar_exif = array_change_key_case($ar_exif, CASE_LOWER);
 
   $out = '';
   $rows1 = array();
   $help = t('This would be the keyword for your CCK field.');
   foreach ($ar_exif as $key => $value) {
     if (is_array($value)) {
+      $value = _exif_reformat($value);
       $rows1[] = array('data' => array($key, $help), 'class' => 'tag_type');
       foreach ($value as $key2 => $value2) {
         $rows1[] = array('data' => array($key2, check_plain(utf8_encode($value2))));
@@ -211,11 +214,65 @@ function exif_admin_settings() {
 
   $rows = array_merge($rows1, $rows2);
   $header = array(t('Key'), t('Value'));
-  $out .= theme('table', $header, $rows);
+  $out .= theme('table', $header, $rows, array('id' => 'exif-fields'));
+  // TODO Prevent binary data values from busting the page layout
   return $out;
 }
 
+ 
+
+/**
+ * Helper function to reformat fields where required.
+ * 
+ * Some values (lat/lon) break down into structures, not strings.
+ * Dates should be parsed nicely.
+ */
+function _exif_reformat($data) {
+  $date_array = array('datetimeoriginal', 'datetime', 'datetimedigitized');
+
+  // Make the key lowercase as CCK field names must be
+  $data = array_change_key_case($data, CASE_LOWER);
 
+  foreach ($data as $key => &$value) {
+    if (is_array($value))  {
+      $value = array_change_key_case($value, CASE_LOWER);
+    }
+    if ($key == 'gpslatitude') {
+      $value = _exif_DMS2D($value, $data['gpslatituderef']);
+    } 
+    elseif ($key == 'gpslongitude') {
+      $value = _exif_DMS2D($value, $data['gpslongituderef']);
+    } 
+    elseif (in_array($key, $date_array)) {
+      // In case we get a datefield, we need to reformat it to the ISO 8601 standard:
+      // which will look something like 2004-02-12T15:19:21
+      $date_time = explode(" ", $value);
+      $date_time[0] = str_replace(":", "-", $date_time[0]);
+      if (variable_get('exif_granularity', 0) == 1) {
+        $date_time[1] = "00:00:00";
+      }
+      $value = implode("T", $date_time);
+    }
+  }
+  return $data;
+}
+
+/**
+ * Helper function to change GPS co-ords into decimals.
+ */
+function _exif_DMS2D($value, $ref) {
+  $parts = split('/', $value[0]);
+  $dec = $parts[0] / $parts[1];
+
+  $parts = split('/', $value[1]);
+  $dec += ($parts[0] / $parts[1]) / 60;
+
+  $parts = split('/', $value[2]);
+  $dec += ($parts[0] / $parts[1]) / 3600;
+
+  if ($ref == 'S' || $ref == 'W') $dec *= -1;
+  return $dec;
+}
 
 /**
  * Helper function to get the exif class
