'bulkupload', 'access' => user_access('upload bulk items'), 'title' => t('Upload bulk images'), 'callback' => 'drupal_get_form', 'callback arguments' => array('_imagefield_bulkupload_form'), 'type' => MENU_NORMAL_ITEM ); return $items; } /** * */ function _imagefield_bulkupload_form($form_values = NULL) { global $user; $tmpdir = $form_values['tmpdir']; if(!$tmpdir) { $tmpdir = file_directory_temp().'/bulkupload_'.$user->uid; } $img_per_pg = $form_values['img_per_pg'] ? $form_values['img_per_pg'] : 10; // Multistep Setup $step = $form_values ? $form_values['step'] + 1 : 1; $form['step'] = array( '#type' => 'hidden', '#value' => $step); $form['#multistep'] = TRUE; $form['#redirect'] = FALSE; $form['tmpdir'] = array( '#type' => 'value', '#value' => $tmpdir); // Step 1 if($step == 1) { $form['#attributes'] = array('enctype' => "multipart/form-data"); $form['file'] = array( '#type' => 'file', '#description' => t('Use an archived file, such as a zip file, or a tar.gz file.')); $type_results = db_query('SELECT nfi.type_name, nt.name title, nfi.field_name, nfi.widget_settings FROM {node_field_instance} nfi INNER JOIN {node_type} nt ON nfi.type_name=nt.type WHERE nfi.widget_type="image"'); if(db_num_rows($type_results) == 0) { return array('#value' => t('There are no content types in use with a image field type. Please contact the administrator.')); } else if(db_num_rows($type_results) == 1) { $type = db_fetch_array($type_results); $form['nodetype_title'] = array( '#type' => 'item', '#title' => t('Node Type'), '#value' => $type['title']); $form['type_name'] = array( '#type' => 'hidden', '#value' => $type['type_name']); //i.e. image2 $form['field_name'] = array( '#type' => 'hidden', '#value' => $type['field_name']); //i.e. field_image } else { while($type = db_fetch_array($type_results)) { $type_options[$type['type_name']] = $type['title']; } $form['type_name'] = array( '#type' => 'select', '#title' => 'Node Type', '#options' => $type_options); } $settings = unserialize($type['widget_settings']); $form['max_resolution'] = array( '#type' => 'textfield', '#title' => t('Maximum resolution for Images'), '#default_value' => $settings['max_resolution'] ? $settings['max_resolution'] : 0, '#size' => 15, '#maxlength' => 10, '#description' => t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.')); $form['img_per_pg'] = array( '#type' => 'select', '#title' => t('Images per Page'), '#default_value' => $img_per_pg, '#options' => array(5=>5, 10=>10, 15=>15, 20=>20, 30=>30), '#description' => t('This website has a limit of %timeout seconds before the ' .'webpage will stop loading, so there is a limitation to the number of images' .' that can be processed at a time.', array('%timeout'=>ini_get('max_execution_time')))); $form['submit'] = array( '#type' => 'submit', '#value' => t('Upload')); } else { // STEP 2 and up $form['field_name'] = array( '#type' => 'hidden', '#value' => $form_values['field_name']); $form['type_name'] = array( '#type' => 'hidden', '#value' => $form_values['type_name']); $form['max_resolution'] = array( '#type' => 'hidden', '#value' => $form_values['max_resolution']); if($handle = opendir($tmpdir)) { $form['img_per_pg'] = array( '#type' => 'select', '#title' => t('Images per Page'), '#default_value' => $img_per_pg, '#options' => array(5=>5, 10=>10, 15=>15, 20=>20, 30=>30), '#description' => t('This website has a limit of %timeout seconds before the ' .'webpage will stop loading, so there is a limitation to the number of images' .' that can be processed at a time.', array('%timeout'=>ini_get('max_execution_time')))); $form['images'] = array( '#type' => 'fieldset', '#tree' => TRUE, '#title' => t('Images')); // Traverse the image directory for titling the nodes $cnt = 0; while(++$cnt <= $img_per_pg) { if(($file = readdir($handle)) === false) break; if(!image_get_info($tmpdir.'/'.$file)) { --$cnt; continue; } // Not sure if image_scale is ideal, because it's time consuming. // 'tmp' directory is not always accessible by http, so the files // should be moved to the files directory. $thmbdir = $tmpdir.'/thumb'; file_check_directory($thmbdir,FILE_CREATE_DIRECTORY+FILE_MODIFY_PERMISSIONS); $thmbdir .= '/'; if(!image_scale($tmpdir.'/'.$file,$thmbdir.$file,140,275)) { $thumb = $tmpdir.'/'.$file; file_copy($thumb, $thmbdir.$file,FILE_EXISTS_REPLACE); } $form['images'][$file] = array( '#type' => 'textfield', '#title' => "Image Title", '#default_value' => $file, '#size' => 40, '#maxlength' => 255, '#description' => t('The title of the node created for this image.'), '#prefix' => '