'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) { //Todo: tmpdir should be random, to avoid conflicts of multiple bulk uploads at once $tmpdir = $form_values['tmpdir'] ? $form_values['tmpdir'] : file_directory_temp().'/bulkupload'; $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 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['nodetype'] = array( '#type' => 'hidden', '#value' => $type['type_name']); $form['upload_field'] = array( '#type' => 'hidden', '#value' => $type['field_name']); } else { while($type = db_fetch_array($type_results)) { $type_options[$type['type_name']] = $type['title']; } $form['nodetype'] = array( '#type' => 'select', '#title' => 'Node Type', '#options' => $type_options); } $form['done'] = array( '#type' => 'checkbox', '#title' => t('Don\'t Edit Titles'), '#description' => t('Use filename as title for each file.')); $form['submit'] = array( '#type' => 'submit', '#value' => t('Upload')); } else { // STEP 2 and up 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(false !== ($file = readdir($handle)) && ++$cnt <= $img_per_pg) { if(image_get_info($tmpdir.'/'.$file) && strpos($file,'sm_') !== 0) { // 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. // Using 'sm_' to label thumbnails, but it might need to be changed // to a seperate directory to avoid naming collisions. if(!image_scale($tmpdir.'/'.$file,$tmpdir.'/sm_'.$file,140,275)) { $thumb = $tmpdir.'/'.$file; file_copy($thumb, $tmpdir.'/sm_'.$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' => '