--- node_images.module.bak 2009-02-03 14:45:50.000000000 +0100 +++ node_images.module 2009-09-01 03:14:59.000000000 +0200 @@ -443,7 +443,7 @@ $limits = _node_images_file_limits($user); $validators = array( - 'file_validate_is_image' => array(), + 'file_validate_extensions' => array(variable_get('node_images_extensions', 'jpg zip')), 'file_validate_image_resolution' => array($limits['resolution']), 'file_validate_size' => array($limits['file_size']), '_node_images_file_validate_name' => array(), @@ -661,30 +661,96 @@ drupal_set_message(t('You are not allowed to upload node images.'), 'error'); return FALSE; } - + if ($file = _node_images_file_upload($form, $form_state, $node)) { - $description = $form_state['values']['description']; - if (trim($description) == '') { - $parts = pathinfo($file->filename); - $description = (isset($parts['filename']) ? $parts['filename'] : substr($file->filename, 0, strrpos($file->filename, '.'))); - } - $thumb = _node_images_create_thumbnail($file->filepath); - - // If we made it this far it's safe to record this file in the database. - $file->uid = $user->uid; - $file->nid = $node->nid; - $file->timestamp = time(); - $file->thumbpath = $thumb->filepath; - $file->thumbsize = $thumb->filesize; - $file->description = $description; - $file->status = 1; - $file->weight = $form_state['values']['weight']; - $file->list = (isset($form_state['values']['list']) ? $form_state['values']['list'] : 1); - - $result = drupal_write_record('node_images', $file); - if ($result == SAVED_NEW) { - drupal_set_message(t('The image has been successfully uploaded.')); - } + + // Check if is a ZIP file + $exten = strtolower (substr($file->filename,-3)); + + if ( $exten == 'zip' ) { + + $zip = new ZipArchive; + $zipresponse = $zip->open($file->filepath); + + if ($zipresponse === TRUE) { + $dest = _node_images_get_directory('', $user, $node); + $zip->extractTo($dest.'/'); + + $numfiles = $zip->numFiles; + for($x=0;$x<$numfiles;$x++) { + $onefile = $zip->statIndex($x); + + $archivo->filename = $onefile['name']; + $archivo->filepath = $dest.'/'.$onefile['name']; + $archivo->filesize = $onefile['size']; + $archivo->filemime = 'image/jpeg'; + + $parts = pathinfo($archivo->filename); + $description = (isset($parts['filename']) ? $parts['filename'] : substr($archivo->filename, 0, strrpos($archivo->filename, '.'))); + + // The file must be an image + $info = image_get_info($archivo->filepath); + if (!$info) { + drupal_set_message( t('The zipped file !name is not a valid image.', array('!name' => $archivo->filename))); + continue; + } + + + file_validate_image_resolution(&$archivo, variable_get('node_images_large_resolution', '800x800'), variable_get('node_images_large_resolution', '800x800')); + + _node_images_file_validate_name(&$archivo); + + $thumb = _node_images_create_thumbnail($archivo->filepath); + + // If we made it this far it's safe to record this file in the database. + $archivo->uid = $user->uid; + $archivo->nid = $node->nid; + $archivo->timestamp = time(); + $archivo->thumbpath = $thumb->filepath; + $archivo->thumbsize = $thumb->filesize; + $archivo->description = $description; + $archivo->status = 1; + $archivo->weight = $form_state['values']['weight']; + $archivo->list = (isset($form_state['values']['list']) ? $form_state['values']['list'] : 1); + + $result = drupal_write_record('node_images', $archivo); + if ($result == SAVED_NEW) { + drupal_set_message($archivo->filename.t(' uploaded.')); + } + + + + } + } + $zip->close(); + // Delete the useless ZIP file + file_delete($file->filepath); // Comprobar si funciona esto. + } + else { + + $description = $form_state['values']['description']; + if (trim($description) == '') { + $parts = pathinfo($file->filename); + $description = (isset($parts['filename']) ? $parts['filename'] : substr($file->filename, 0, strrpos($file->filename, '.'))); + } + $thumb = _node_images_create_thumbnail($file->filepath); + + // If we made it this far it's safe to record this file in the database. + $file->uid = $user->uid; + $file->nid = $node->nid; + $file->timestamp = time(); + $file->thumbpath = $thumb->filepath; + $file->thumbsize = $thumb->filesize; + $file->description = $description; + $file->status = 1; + $file->weight = $form_state['values']['weight']; + $file->list = (isset($form_state['values']['list']) ? $form_state['values']['list'] : 1); + + $result = drupal_write_record('node_images', $file); + if ($result == SAVED_NEW) { + drupal_set_message(t('The image has been successfully uploaded.')); + } + } return $file; } @@ -948,9 +1014,9 @@ */ function _node_images_file_limits($user) { return array( - 'extensions' => variable_get('node_images_extensions', 'jpg jpeg gif png'), - 'file_size' => variable_get('node_images_file_limit', 1) * 1024 * 1024, - 'resolution' => variable_get('node_images_large_resolution', 0), + 'extensions' => variable_get('node_images_extensions', 'jpg zip'), + 'file_size' => variable_get('node_images_file_limit', 100) * 1024 * 1024, + 'resolution' => variable_get('node_images_large_resolution', '800x800'), ); }