--- imagefield.module-5.x-2.1 Tue May 13 08:02:02 2008 +++ imagefield.module Thu Jun 12 01:08:13 2008 @@ -330,6 +330,22 @@ function imagefield_field($op, $node, $f unset($items[$delta]); } else { +// Dimm begin /////////////////////////////////////////////////////////////////////////// + if(strpos($item['filemime'],'zip') <> 0){ + + $items_unzip = imagefield_unzip_php_ext($item); + if($items_unzip){ + foreach ($items_unzip as $delta_unzip => $item_unzip) { + $items[] = imagefield_file_update($node, $item_unzip, $field); + } + + 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); } } @@ -349,6 +365,23 @@ function imagefield_field($op, $node, $f $item['flags']['delete'] = true; } +// Dimm begin /////////////////////////////////////////////////////////////////////////// +// if(strpos($item['filemime'],'zip') <> 0 || strpos($item['filemime'],'x-gzip') <> 0){ + if(strpos($item['filemime'],'zip') <> 0){ + + $items_unzip = imagefield_unzip_php_ext($item); + if($items_unzip){ + foreach ($items_unzip as $delta_unzip => $item_unzip) { + $items[] = imagefield_file_update($node, $item_unzip, $field); + } + + 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); @@ -396,6 +429,66 @@ function imagefield_field($op, $node, $f } } + + + +// Dimm begin /////////////////////////////////////////////////////////////////////////// +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_php_ext($file) { + if(substr($file['filename'],-4) == '.zip') { + $zip = zip_open($file['filepath']); + $zip_dir = file_directory_temp() . '/'; + if ($zip) { + while ($zip_entry = zip_read($zip)) { + + $filename = basename(zip_entry_name($zip_entry)); + $fp = fopen($zip_dir.basename($filename), "w+"); + + if (zip_entry_open($zip, $zip_entry, "r")) { + $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry)); + zip_entry_close($zip_entry); + } + + fwrite($fp, $buf); + fclose($fp); + + $item['flags']['delete'] = 0; + $item['alt'] = $filename; + $item['title'] = $filename; + $item['filename'] = $filename; + $item['filepath'] = file_directory_temp() . '/'. $filename; + $item['filemime'] = imagefield_mime_content_type($item['filepath']); + $item['filesize'] = filesize($item['filepath']); + $item['fid'] = 'upload'; + $item['alt'] = $filename; + $node_field_unzip[] = $item; + } + zip_close($zip); + } + } else { + drupal_set_message("Filename must end with .zip ".$file['filename'].'-'.$file['filepath']); + } +return $node_field_unzip; +} +// Dimm end /////////////////////////////////////////////////////////////////////////// + + + + + /** * Implementation of hook_widget_info(). */ @@ -600,7 +693,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 +986,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'))) { +// 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;