Index: exif.class.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/exif/Attic/exif.class.php,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 exif.class.php
--- exif.class.php	5 Feb 2009 20:11:53 -0000	1.1.2.2
+++ exif.class.php	9 Jul 2009 14:15:41 -0000
@@ -1,75 +1,98 @@
 <?php
-//$Id:
+//$Id$:
 
 /**
- * 
- * @author Raphael Schär
+ * @author Raphael SchÃ¤r
+ * @file
  * This is a helper class to handle the whole data processing of exif
  *
  */
 Class Exif {
-	static private $instance = null;
+  static private $instance = NULL;
 
-	/**
-	 * We are implementing a singleton pattern
-	 */
-	private function __construct() {
-	}
-
-	public function getInstance() {
-		if(is_null(self::$instance)) {
-			self::$instance = new self;
-		}
-		return self::$instance;
-	}
-	
-	/**
-	 * Going through all the fields that have been created for a given node type
-	 * and try to figure out which match the naming convention -> so that we know
-	 * which exif information we have to read
-	 * 
-	 * Naming convention are: field_exif_xxx (xxx would be the name of the exif
-	 * tag to read
-	 * 
-	 * @param $arCckFields array of CCK fields
-	 * @return array a list of exif tags to read for this image
-	 */
-	public function getExifFields($arCckFields=array()){
-		$arSections = array('exif','file','computed','ifd0','gps','winxp');
-		$arExif = array();
-		
-		foreach ($arCckFields as $field){
-			$ar = explode("_",$field['field_name']);
-			if(in_array($ar[1],$arSections) && $ar[0] == 'field'){
-				unset($ar[0]);
-				$section = $ar[1];
-				unset($ar[1]);
-				$arExif[] = array('section'=>$section,'tag'=>implode("_",$ar));
-			}
-		}
-		return $arExif;
-	}
-	
-	/**
-	 * Read the Information from a picture according to the fields specified in CCK
-	 * @param $file
-	 * @param $arTagNames
-	 * @return array
-	 */
-	public function readExifTags($file,$arTagNames=array()){
-		if(!file_exists($file)){
-			return array();
-		}
-		$exif = exif_read_data($file,0);
-		$arSmallExif = array();
-		foreach ($exif as $key => $value) {
-			$arSmallExif[strtolower($key)] = $value;
-		}
-		$info = array();
-		foreach ($arTagNames as $tagName) {
-			$info[$tagName['tag']] = $arSmallExif[$tagName['tag']];
-		}
-		return $info;
-	}
+  /**
+   * We are implementing a singleton pattern
+   */
+  private function __construct() {
+  }
+
+  public function getInstance() {
+    if (is_null(self::$instance)) {
+      self::$instance = new self;
+    }
+    return self::$instance;
+  }
+
+  /**
+   * Going through all the fields that have been created for a given node type
+   * and try to figure out which match the naming convention -> so that we know
+   * which exif information we have to read
+   *
+   * Naming convention are: field_exif_xxx (xxx would be the name of the exif
+   * tag to read
+   *
+   * @param $arCckFields array of CCK fields
+   * @return array a list of exif tags to read for this image
+   */
+  public function getExifFields($arCckFields=array()) {
+    $arSections = array('exif', 'file', 'computed', 'ifd0', 'gps', 'winxp');
+    $arExif = array();
+
+    foreach ($arCckFields as $field) {
+      $ar = explode("_", $field['field_name']);
+      if (in_array($ar[1], $arSections) && $ar[0] == 'field') {
+        unset($ar[0]);
+        $section = $ar[1];
+        unset($ar[1]);
+        $arExif[] = array('section' => $section, 'tag' => implode("_", $ar));
+      }
+    }
+    return $arExif;
+  }
+
+  /**
+    * Read the Information from a picture according to the fields specified in CCK
+    * @param $file
+    * @param $arTagNames
+    * @return array
+    */
+  public function readExifTags($file, $arTagNames = array()) {
+    if (!file_exists($file)) {
+      return array();
+    }
+    $data = exif_read_data($file, 0, TRUE); // Third argument forces all data to be returned as arrays.
+
+    $cck_fields = array();
+
+    foreach ($arTagNames as $cck_field) {
+      $cck_fields[] = $cck_field['section'] .'_'. $cck_field['tag'];
+    }
+
+    $exif_tags = array(); // This is what we'll be returning
+
+    foreach ($data as $section => $fields) {
+      foreach ($fields as $key => $value) {
+        $field = strtolower($section .'_'. $key);
+        if (in_array($field, $cck_fields)) {
+          // Moved the date checking stuff from exif_nodeapi to here.
+          // This way, this function always returns ready-to-use data.
+          // Otherwise we may as well just use exif_read_data.
+          $date_array = array('datetimeoriginal', 'datetime', 'datetimedigitized');
+          // Incase we get a datefield, we need to reformat it to the ISO 8601 standard:
+          // which will look something like 2004-02-12T15:19:21
+          if (in_array(strtolower($key), $date_array)) {
+            $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);
+          }
+          $exif_tags[$field] = $value;
+        }
+      }
+    }
+    return $exif_tags;
+  }
 
 }
\ No newline at end of file
Index: exif.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/exif/exif.install,v
retrieving revision 1.4.2.2
diff -u -p -r1.4.2.2 exif.install
--- exif.install	29 Jan 2009 16:52:07 -0000	1.4.2.2
+++ exif.install	9 Jul 2009 14:15:41 -0000
@@ -1,10 +1,15 @@
 <?php
-// $Id:
+// $Id$:
 
+/**
+ * @file
+ * Install file for EXIF module.
+ * Changes weight of exif module so its code executes before other modules.
+ */
 
 /**
  * Implementation of hook_install().
  */
 function exif_install() {
-	db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", -10,'exif');
+  db_query("UPDATE {system} SET weight = %d WHERE name = '%s'", -10, 'exif');
 }
Index: exif.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/exif/exif.module,v
retrieving revision 1.9.2.6
diff -u -p -r1.9.2.6 exif.module
--- exif.module	13 Apr 2009 11:57:49 -0000	1.9.2.6
+++ exif.module	9 Jul 2009 14:15:42 -0000
@@ -1,123 +1,107 @@
 <?php
-// $Id:
+// $Id$:
 
 /**
- * @author: Raphael Schär - www.rapsli.ch, www.schaerwebdesign.ch
+ * @file
+ * Imports EXIF data into CCK fields.
+ *
+ * @author: Raphael SchÃ¤r - www.rapsli.ch, www.schaerwebdesign.ch
  */
 
-function exif_menu(){
-	$items['admin/settings/exif'] = array(
+function exif_menu() {
+  $items['admin/settings/exif'] = array(
       'title' => 'Exif',
       'page callback' => 'exif_admin_settings',
       'access arguments' => array('administer site configuration'),
       'description' => t('Display available fields'),
-	  'access callback' => 'user_access',
-	  'type' => MENU_NORMAL_ITEM,
-	);
-	$items['admin/settings/exif/general'] = array(
+    'access callback' => 'user_access',
+    'type' => MENU_NORMAL_ITEM,
+  );
+  $items['admin/settings/exif/general'] = array(
       'title' => 'Exif',
       'page callback' => 'exif_admin_settings',
       'access arguments' => array('administer site configuration'),
       'description' => t('Display available fields'),
-	  'access callback' => 'user_access',
-	  'type' => MENU_LOCAL_TASK,
-	);
-	$items['admin/settings/exif/config'] = array(
+    'access callback' => 'user_access',
+    'type' => MENU_LOCAL_TASK,
+  );
+  $items['admin/settings/exif/config'] = array(
       'title' => 'Config',
       'page callback' => 'drupal_get_form',
-	  'page arguments' => array('exif_admin_settings_form'),
+    'page arguments' => array('exif_admin_settings_form'),
       'access arguments' => array('administer site configuration'),
       'description' => t('Some Settings'),
-	  'access callback' => 'user_access',
-	  'type' => MENU_LOCAL_TASK,
-	);
-
-
-	return $items;
-}
-
-function exif_admin_settings_form(){
-	$forms = array();
-	$forms['exif_granularity'] = array(
-		'#type'	=>	'select',
-		'#title'=>	t('Granularity'),
-		'#options'=> array(0=>t('Default'),1=>('Day')),
-		'#default_value'=>variable_get('exif_granularity',0),
-		'#description'=>t('If a timestamp is select (for example the date the picture was taken), you can specify here how granular the timestamp should be. If you select default it will just take whatever is available in the picture. If you select Day, the Date saved will look something like 13-12-2008. This can be useful if you want to use some kind of grouping on the data.'),
-	);
-
-	$all_nodetypes = node_get_types();
-	$all_nt = array();
-	foreach($all_nodetypes as $item){
-		$all_nt[$item->type] = $item->name;
-	}
-	$forms['exif_nodetypes'] = array(
-		'#type'	=>	'checkboxes',
-		'#title'=>	t('Nodetypes'),
-		'#options'=> $all_nt,
-		'#default_value'=>variable_get('exif_nodetypes',array()),
-		'#description'=> t('Select nodetypes which should be checked for exif data. Incase the nodetypes contains more than one filefield, make sure that the imagefield is the first one!!!!'),
-	);
-	
-	return system_settings_form($forms);
-}
-/**
- * implementation of hook_nodeapi
- */
-function exif_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){
-
-	if ($teaser) {
-		return;
-	}
-
-	
-	switch ($op) {
-		
-		case 'insert':
-		case 'update':
-			$info = content_types($node->type);
-			$fields = $info['fields'];
-
-			if(_exif_check_for_exif_data($node->type)){
-				$exif = _exif_get_class();
-
-				//get all the fields that will be filled with exif data
-				$ar_exif_fields = $exif->getExifFields($fields);
-
-				//get the path to the image
-				$image_path = _exif_get_image_path($fields,$node);
-
-				$fid = db_result(db_query("SELECT fid FROM {files} WHERE filepath = '%s'", $image_path));
-				$file = file_create_path($image_path);
-
-				$data = $exif->readExifTags($file,$ar_exif_fields);
-				
-				// prepare data to be stored in CCK
-				$i = 0;
-				foreach ($data as $key => $value) {
-					$field_name = 'field_' . $ar_exif_fields[$i]['section'] . '_' . $key;
-					$tmp = $node->$field_name;
-					
-					$date_array = array('datetimeoriginal','datetime','datetimedigitized');
-					//incase we get a datefield, we need to reformat it to the ISO 8601 standard:
-					//which will look something like 2004-02-12T15:19:21
-					if(in_array($key,$date_array)){
-						$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);
-						//dsm($value,$key);
-					}
-					$tmp[0]['value'] = $value;
-					
-					$node->$field_name = $tmp;
-					$i++;
-				}
-			}
-			break;
-	}
+    'access callback' => 'user_access',
+    'type' => MENU_LOCAL_TASK,
+  );
+
+
+  return $items;
+}
+
+function exif_admin_settings_form() {
+  $forms = array();
+  $forms['exif_granularity'] = array(
+    '#type' => 'select',
+    '#title' => t('Granularity'),
+    '#options' => array(0 => t('Default'), 1 => ('Day')),
+    '#default_value' => variable_get('exif_granularity', 0),
+    '#description' => t('If a timestamp is select (for example the date the picture was taken), you can specify here how granular the timestamp should be. If you select default it will just take whatever is available in the picture. If you select Day, the Date saved will look something like 13-12-2008. This can be useful if you want to use some kind of grouping on the data.'),
+  );
+
+  $all_nodetypes = node_get_types();
+  $all_nt = array();
+  foreach ($all_nodetypes as $item) {
+    $all_nt[$item->type] = $item->name;
+  }
+  $forms['exif_nodetypes'] = array(
+    '#type' => 'checkboxes',
+    '#title' => t('Nodetypes'),
+    '#options' => $all_nt,
+    '#default_value' => variable_get('exif_nodetypes', array()),
+    '#description' => t('Select nodetypes which should be checked for exif data. Incase the nodetypes contains more than one filefield, make sure that the imagefield is the first one!!!!'),
+  );
+
+  return system_settings_form($forms);
+}
+/**
+ * Implementation of hook_nodeapi().
+ */
+function exif_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
+
+  if ($teaser) {
+    return;
+  }
+
+  switch ($op) {
+    case 'insert':
+    case 'update':
+      $info = content_types($node->type);
+      $fields = $info['fields'];
+
+      if (_exif_check_for_exif_data($node->type)) {
+        $exif = _exif_get_class();
+
+        //get all the fields that will be filled with exif data
+        $ar_exif_fields = $exif->getExifFields($fields);
+        //get the path to the image
+        $image_path = _exif_get_image_path($fields, $node);
+
+        $fid = db_result(db_query("SELECT fid FROM {files} WHERE filepath = '%s'", $image_path));
+        $file = file_create_path($image_path);
+
+        $data = $exif->readExifTags($file, $ar_exif_fields);
+
+        // prepare data to be stored in CCK
+        foreach ($data as $key => $value) {
+          $field_name = 'field_'. $key;
+          $tmp = $node->$field_name;
+          $tmp[0]['value'] = $value;
+          $node->$field_name = $tmp;
+        }
+      }
+    break;
+  }
 }
 
 /**
@@ -126,19 +110,19 @@ function exif_nodeapi(&$node, $op, $a3 =
  * @param $fields fields from this content type
  * @return boolean
  */
-function _exif_check_for_exif_data($node_type){
-	
-	$new_types = array();
-	//fill up array with checked nodetypes
-	foreach (variable_get('exif_nodetypes',array()) as $type){
-		if($type != "0" ){
-			$new_types[] = $type;
-		}
-	}
-	if(in_array($node_type,$new_types)){
-		return TRUE;
-	}
-	return FALSE;
+function _exif_check_for_exif_data($node_type) {
+
+  $new_types = array();
+  //fill up array with checked nodetypes
+  foreach (variable_get('exif_nodetypes', array()) as $type) {
+    if ($type != "0" ) {
+      $new_types[] = $type;
+    }
+  }
+  if (in_array($node_type, $new_types)) {
+    return TRUE;
+  }
+  return FALSE;
 }
 
 /**
@@ -150,45 +134,45 @@ function _exif_check_for_exif_data($node
  * @param $node
  * @return unknown_type
  */
-function _exif_get_image_path($fields,&$node){
-	if($node->type == 'image'){
-		return $node->images[IMAGE_ORIGINAL];
-	}
-
-	foreach ($fields as $field) {
-		if($field['type'] == 'filefield'){
-			$tmp = $node->$field['field_name'];
-			return $tmp[0]['filepath'];
-		}
-	}
-	return null;
+function _exif_get_image_path($fields, &$node) {
+  if ($node->type == 'image') {
+    return $node->images[IMAGE_ORIGINAL];
+  }
+
+  foreach ($fields as $field) {
+    if ($field['type'] == 'filefield') {
+      $tmp = $node->$field['field_name'];
+      return $tmp[0]['filepath'];
+    }
+  }
+  return NULL;
 }
 
 /**
  * Just some help page. Gives you an overview over the available tags
  * @return string html
  */
-function exif_admin_settings(){
-	drupal_add_css(drupal_get_path('module','exif') . '/exif.css');
-	$filepath = drupal_get_path('module','exif') . '/sample.jpg';
-
-	$ar_exif = read_exif_data($filepath,0,true);
-
-	$out = '';
-	$rows = array();
-	$help = t('This would be the keyword for your CCK field.');
-	foreach ($ar_exif as $key => $value){
-		if(is_array($value)){
-			$rows[] = array('data'=>array($key,$help),'class'=>'tag_type');
-			foreach($value as $key2 => $value2){
-				$rows[] = array('data'=>array($key2,check_plain(utf8_encode($value2))));
-			}
-		}
-
-	}
-	$header = array(t('Key'),t('Value'));
-	$out .= theme('table',$header,$rows);
-	return $out;
+function exif_admin_settings() {
+  drupal_add_css(drupal_get_path('module', 'exif') .'/exif.css');
+  $filepath = drupal_get_path('module', 'exif') .'/sample.jpg';
+
+  $ar_exif = read_exif_data($filepath, 0, TRUE);
+
+  $out = '';
+  $rows = array();
+  $help = t('This would be the keyword for your CCK field.');
+  foreach ($ar_exif as $key => $value) {
+    if (is_array($value)) {
+      $rows[] = array('data' => array($key, $help), 'class' => 'tag_type');
+      foreach ($value as $key2 => $value2) {
+        $rows[] = array('data' => array($key2, check_plain(utf8_encode($value2))));
+      }
+    }
+
+  }
+  $header = array(t('Key'), t('Value'));
+  $out .= theme('table', $header, $rows);
+  return $out;
 }
 
 
@@ -197,8 +181,8 @@ function exif_admin_settings(){
  * Helper function to get the exif class
  * @return Exif
  */
-function _exif_get_class(){
-	include_once drupal_get_path('module','exif').'/exif.class.php';
-	$exif = Exif::getInstance();
-	return $exif;
+function _exif_get_class() {
+  include_once drupal_get_path('module', 'exif') .'/exif.class.php';
+  $exif = Exif::getInstance();
+  return $exif;
 }
