--- imagefield.module-5.x-2.1	Tue May 13 08:02:02 2008
+++ imagefield.module	Mon May 26 15:07:28 2008
@@ -325,20 +325,50 @@ function imagefield_field($op, $node, $f
 
     // called before content.module defaults.
     case 'insert':
+// Dimm begin ///////////////////////////////////////////////////////////////////////////
+      $unzipdir_to_remove=array();
+// Dimm end ///////////////////////////////////////////////////////////////////////////
       foreach ($items as $delta => $item) {
         if ($item['flags']['delete']) {
           unset($items[$delta]);
         }
         else {
+// Dimm begin ///////////////////////////////////////////////////////////////////////////
+          if(strpos($item['filemime'],'zip') <> 0
+           || strpos($item['filemime'],'x-gzip') <> 0
+           ){
+        
+            $items_unzip = imagefield_unzip($item);
+            if($items_unzip){
+            foreach ($items_unzip as $delta_unzip => $item_unzip) {
+              $items[] = imagefield_file_update($node, $item_unzip, $field);
+            }
+
+            $unzipdir_to_remove[]=imagefield_get_unzipdir($item); // to del unzipdir
+            unlink($item['filepath']); //del *.tmp file
+            $item=array();
+            }else{
+              drupal_set_message('Extracting of the images failed: '.$item['filename']);
+            }
+          }
+// Dimm end ///////////////////////////////////////////////////////////////////////////
           $items[$delta] = imagefield_file_insert($node, $item, $field);
         }
       }
       $items = array_values(array_filter($items)); // compact deltas
       imagefield_clear_field_session($fieldname);
+// Dimm begin ///////////////////////////////////////////////////////////////////////////
+      foreach ($unzipdir_to_remove as $unzipdir) {
+        delete_unzipdir($unzipdir);
+      }
+// Dimm end ///////////////////////////////////////////////////////////////////////////
       break;
 
     // called before content.module defaults.
     case 'update':
+// Dimm begin ///////////////////////////////////////////////////////////////////////////
+      $unzipdir_to_remove=array();
+// Dimm end ///////////////////////////////////////////////////////////////////////////
       foreach ($items as $delta => $item) {
         
         // If we're dealing with a single value field, and we just received
@@ -349,6 +379,25 @@ function imagefield_field($op, $node, $f
           $item['flags']['delete'] = true;
         }
 
+// Dimm begin ///////////////////////////////////////////////////////////////////////////
+          if(strpos($item['filemime'],'zip') <> 0
+           || strpos($item['filemime'],'x-gzip') <> 0
+           ){
+        
+            $items_unzip = imagefield_unzip($item);
+            if($items_unzip){
+            foreach ($items_unzip as $delta_unzip => $item_unzip) {
+              $items[] = imagefield_file_update($node, $item_unzip, $field);
+            }
+
+            $unzipdir_to_remove[]=imagefield_get_unzipdir($item); // to del unzipdir
+            unlink($item['filepath']); //del *.tmp file
+            $item=array();
+            }else{
+              drupal_set_message('Extracting of the images failed: '.$item['filename']);
+            }
+          }
+// Dimm end ///////////////////////////////////////////////////////////////////////////
         // Update each file item.
         $items[$delta] = imagefield_file_update($node, $item, $field);
 
@@ -363,6 +412,11 @@ function imagefield_field($op, $node, $f
       }
       $items = array_values(array_filter($items)); // compact deltas
       imagefield_clear_field_session($fieldname);
+// Dimm begin ///////////////////////////////////////////////////////////////////////////
+      foreach ($unzipdir_to_remove as $unzipdir) {
+        delete_unzipdir($unzipdir);
+      }
+// Dimm end ///////////////////////////////////////////////////////////////////////////
       break;
 
     case 'delete revision':
@@ -396,6 +450,126 @@ function imagefield_field($op, $node, $f
   }
 }
 
+
+
+
+// Dimm begin ///////////////////////////////////////////////////////////////////////////
+
+function imagefield_get_unzipdir($file) {
+$tmpdir =  realpath(file_directory_path() . '/' . 'tmp');
+if  (!is_dir($tmpdir)){
+ mkdir($tmpdir,0777);
+}
+
+$slashpos=0;
+if(strrpos($file['filepath'], "/")){
+$slashpos=strrpos($file['filepath'], "/");
+}elseif(strrpos($file['filepath'], "\\")){
+$slashpos=strrpos($file['filepath'], "\\");
+}
+$tmpfilename = substr($file['filepath'],$slashpos+1);
+//$tmpfilename = substr($tmpfilename,0,strrpos($tmpfilename,'.'));
+$tmpfilename = $tmpfilename.'_dir';
+$uzipdir= $tmpdir. '/' .$tmpfilename;
+return $uzipdir;
+}
+
+function delete_unzipdir($dirname)  {
+        if  (is_dir($dirname))
+                $dir_handle  =  opendir($dirname);
+        if  (!$dir_handle)
+                return  false;
+        while($file  =  readdir($dir_handle))  {
+                if  ($file  !=  "."  &&  $file  !=  "..")  {
+                        if  (!is_dir($dirname."/".$file))
+                                unlink($dirname."/".$file);
+                        else
+                                delete_directory($dirname.'/'.$file);                       
+                }
+        }
+        closedir($dir_handle);
+        rmdir($dirname);
+        return  true;
+}
+
+function imagefield_mime_content_type($filename) 
+{ 
+if ( function_exists ( 'mime_content_type ' ) ){
+  return mime_content_type ($filename);
+}else{ 
+  $mime = array( 
+       '.jpg' => 'image/jpg', 
+       '.jpeg' => 'image/jpeg', 
+       '.gif' => 'image/gif', 
+       '.png' => 'image/png'); 
+   return $mime[strrchr($filename, '.')]; 
+}
+} 
+
+
+function imagefield_unzip($file) {
+$uzipdir = imagefield_get_unzipdir($file);
+  if(substr($file['filename'],-4) == '.zip') {
+//    $e = "z:\\usr\\bin\\unzip.exe -qq -j {$file['filepath']} -d $uzipdir";
+    $e = "unzip -qq -j {$file['filepath']} -d $uzipdir";
+//    print $e;
+  } else if(substr($file['filename'],-7) == '.tar.gz') {
+//    $e = "z:\\usr\\bin\\tar -C $uzipdir -xzf {$file['filepath']}";
+    $e = "tar -C $uzipdir -xzf {$file['filepath']}";
+//    print $e;
+  } else {
+    drupal_set_message("Filename must end with .zip or .tar.gz ".$file['filename'].'-'.$file['filepath']);
+  }
+  
+  if($e) {
+    if(is_dir($uzipdir)){
+    }elseif(mkdir($uzipdir,0777)){
+    }else{
+      drupal_set_message('Make unzip dir failed: '.$uzipdir);
+    }
+    $message = system($e);
+    if($message){
+      drupal_set_message('Extracting of the images failed: '.$message);
+    }else{
+      $i = 0;
+      if ($handle = opendir ($uzipdir)){
+      while($file = readdir($handle)){
+        if ($file != '.' && $file != '..')
+        {
+          $func[$i] = $file;    //формируем массив названий файлов с функциями
+          $i++;
+        }
+      }
+      sort ($func);
+      for ($q = 0; $q<sizeof($func); $q++)
+      {
+        $filename=$func[$q];
+        
+        $item['flags']['delete'] = 0;
+        $item['alt'] = $filename;
+        $item['title'] = $filename;
+        $item['filename'] = $filename;
+        $item['filepath'] = $uzipdir . '/'. $filename;
+        $item['filemime'] = imagefield_mime_content_type($item['filepath']);
+        $item['filesize'] = filesize($item['filepath']);
+        $item['fid'] = 'upload';
+        $item['alt'] = $filename;
+        $node_field_unzip[] = $item;
+      }
+      }else{
+        drupal_set_message('Open unzip dir failed: '.$uzipdir);
+      }
+    }
+  }
+
+return $node_field_unzip;
+}
+// Dimm end ///////////////////////////////////////////////////////////////////////////
+
+
+
+
+
 /**
  * Implementation of hook_widget_info().
  */
@@ -600,7 +774,12 @@ function _imagefield_widget_prepare_form
     //$valid_image = true;
 
     if ($valid_image) {
+//      $file = _imagefield_scale_image($file, $field['widget']['max_resolution']);
+// Dimm begin ///////////////////////////////////////////////////////////////////////////
+    if (strpos($file['filemime'], 'image/'===0)) {
       $file = _imagefield_scale_image($file, $field['widget']['max_resolution']);
+    }
+// Dimm end ///////////////////////////////////////////////////////////////////////////
 
       // Allow tokenized paths if available
       if (function_exists('token_replace')) {
@@ -888,7 +1067,10 @@ function _imagefield_widget_upload_valid
   }
 
   // Is the mime type a match for image.
-  if (strpos($file['filemime'], 'image/') !== 0) {
+//  if (strpos($file['filemime'], 'image/') !== 0) {
+// Dimm begin ///////////////////////////////////////////////////////////////////////////
+        if (!(strpos($file['filemime'],'image/') === 0 || strpos($file['filemime'],'zip') || strpos($file['filemime'],'x-gzip') )) { 
+// Dimm end ///////////////////////////////////////////////////////////////////////////
     // sorry no it isn't. do not pass go, do not collect $200.
     form_set_error($field['field_name'], t('Mime Type mismatch. Only image files may be upload. You uploaded a file with mime type: %mime', array('%mime' => $file['filemime'])));
     $valid = false;
