'Image FUpload', 'page callback' => 'fupload_filetransfer', 'access callback' => TRUE, // must be examined later 'type' => MENU_CALLBACK, ); $items['fupload/js/deletequeue/%'] = array( 'title' => 'Image FUpload', 'page callback' => 'fupload_empty_queue', 'page arguments' => array(3), 'access arguments' => array('mass upload images'), 'type' => MENU_CALLBACK, ); $items['node/add/%image_node_type/list_images'] = array( 'title' => 'Edit Captions', 'access arguments' => array('edit captions'), 'page callback' => 'drupal_get_form', 'page arguments' => array('fupload_list_images_image', 2), 'type' => MENU_CALLBACK, 'file' => 'includes/images.previewlist.image.inc', ); $items['node/add/%image_node_type/list_imagefields'] = array( 'title' => 'Edit Captions', 'access arguments' => array('edit captions'), 'page callback' => 'drupal_get_form', 'page arguments' => array('fupload_list_images_imagefield', 2), 'type' => MENU_CALLBACK, 'file' => 'includes/images.previewlist.imagefield.inc', ); return $items; } /** * Menu callback; loads a image node type object */ function image_node_type_load($node_type, $simple_check = FALSE) { $image_node_types = variable_get('image_node_types', array()); // test if given node type is image (field) node type $node_type = str_replace("-", "_", $node_type); // simple check without checking url arguments if ($simple_check && isset($image_node_types[$node_type])) return $node_type; if (isset($image_node_types[$node_type])) { if (arg(3) == "list_imagefields" && $image_node_types[$node_type]['type'] == "cck") { return $node_type; } elseif (arg(3) == "list_images" && $image_node_types[$node_type]['type'] == "image") { return $node_type; } else { return FALSE; } } else { return FALSE; } } /** * returns a identifier for images so that their status (current step) can easily be set */ function image_fupload_image_status($field_name, $status = IMAGE_UNMACHINED) { switch ($status) { case IMAGE_NOT_COMPLETED: return ""; break; default: return $field_name ."/" .$status; break; } } /** * Implementation of hook_perm(). */ function image_fupload_perm() { return array('mass upload images', 'edit captions'); } /** * Implementation of hook_help */ function image_fupload_help($path, $arg) { switch ($path) { case 'admin/help#image_fupload': $output = '
'. t("The Image FUpload module is used to provide an alternate upload form to image module itself.") .'
'; $output .= ''. t("This is a great advantage because multiple images can be selected with one click which are automatically uploaded and processed without any further user interaction. Additionally, this module fully integrates in image module. Consequently, all settings made by image module are observed (thumb creation, file size limit etc.).") .'
'; $output .= '' .t("Image FUpload administration allows to define some characters which are replaced in the node title by a whitespace. In addition to that, the option can be selected to show a link to the original upload form to those users whose browser doesn't support this Flash / JS solution.") . '
'; $output .= t('You can
'. t('For more information please read the configuration and customization handbook Image FUpload page.', array('!image' => 'http://www.drupal.org/handbook/modules/image/')) .'
'; return $output; } } /** * Implementation of hook_theme() registry. */ function image_fupload_theme() { return array( 'swfupload_settings' => array( 'template' => 'swfupload-settings', 'arguments' => array('modulepath' => NULL, 'uploadpath' => NULL, 'maxfilesize' => NULL, 'fileextensions' => NULL, 'sessionid' => NULL, 'uploadlimit' => NULL, 'nodetype' => NULL, 'fieldname' => NULL, 'field_required' => NULL, 'storage_mode' => NULL, 'redirect_url' => NULL), ), 'fupload_create_filename' => array( 'arguments' => array('image' => NULL, 'replacements' => NULL), ), 'fupload_imagepreview_image' => array( 'arguments' => array('image' => NULL, 'image_info' => NULL, 'node_image' => NULL, 'attributes' => NULL), 'file' => 'includes/images.previewlist.image.inc', ), ); } function fupload_filetransfer() { // huh.. swfUpload sends some data...let's see global $user; $sid = $_POST['PHPSESSID']; $node_type = check_plain($_POST['nodetype']); $field_name = check_plain($_POST['fieldname']); // validate given session id $result = db_query("SELECT * FROM {sessions} WHERE sid = '%s' AND hostname = '%s' LIMIT 1", $sid, ip_address()); $upload_user = db_fetch_object($result); // Get users profile $user = user_load(array('uid' => $upload_user->uid)); // Do some checks before upload $field_access = FALSE; if (!empty($upload_user) && !empty($node_type) && !empty($field_name)) { // user valid? node_type & field_name received? // Check if given node_type & field_name combination is possible for user switch ($node_type) { case "image": // image node type if ($field_name == "images") { $field_access = node_access('create', $node_type, $user); // get suitable validators for our upload: image module $validators = array( 'file_validate_is_image' => array(), 'file_validate_size' => array(variable_get('image_max_upload_size', 800) * 1024), ); } break; default: // probably cck image node type if (module_exists('content')) { if (image_node_type_load($node_type, TRUE) && ($field = content_fields($field_name, $node_type))) { $field_access = node_access('create', $node_type, $user); // also get suitable validators for our upload: cck imagefield module $validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field)); } } break; } } if (user_access('mass upload images', $user) && $field_access) { // Adapt to drupal files structure $_FILES['files']['name']['image'] = $_FILES['Filedata']['name']; $_FILES['files']['type']['image'] = $_FILES['Filedata']['type']; $_FILES['files']['tmp_name']['image'] = $_FILES['Filedata']['tmp_name']; $_FILES['files']['error']['image'] = $_FILES['Filedata']['error']; $_FILES['files']['size']['image'] = $_FILES['Filedata']['size']; // do some checks via transliteration module if available if (module_exists('transliteration')) { require_once(drupal_get_path('module', 'transliteration') .'/transliteration.inc'); $_FILES['files']['name']['image'] = transliteration_clean_filename($_FILES['Filedata']['name']); } if ($file = file_save_upload('image', $validators)) { $image = image_get_info($file->filepath); // Get real mime-type if(!db_query("UPDATE {files} SET filename = '%s', filemime = '%s' WHERE fid = %d", image_fupload_image_status($field_name, IMAGE_UNMACHINED), $image['mime_type'], $file->fid)) { drupal_json(array('status' => FALSE, 'data' => t('A database related problem appeared during upload. Please inform the site administrator if this is a permanent problem.'))); exit; } // Get all status messages and add them to server message for swfUpload --> inform client $messages = drupal_get_messages('status'); drupal_json(array('status' => TRUE, 'data' => t('Complete. !messages', array('!messages' => (!empty($messages['status']) ? implode(' ', $messages['status']) : ''))))); // Reply a status message to satisfy swfUpload } else { // Get responsible error messages and send it to swfUpload $messages = form_get_errors(); drupal_json(array('status' => FALSE, 'data' => t('Upload failed: !errors', array('!errors' => implode(' ', $messages))))); } } else { drupal_access_denied(); } } function fupload_empty_queue($field_name) { global $user; // Set "processed" flag so that these images aren't processed again; images are deleted later by cron (--> temporary files) db_query("UPDATE {files} SET filename = '%s' WHERE uid = %d AND status = %d AND filename = '%s'", image_fupload_image_status(check_plain($field_name), IMAGE_PROCESSED), $user->uid, FILE_STATUS_TEMPORARY, image_fupload_image_status(check_plain($field_name), IMAGE_UNMACHINED)); // Output message to user via AJAX drupal_set_message(); drupal_set_message(t('All queued images were deleted.'), 'warning'); drupal_json(array('status' => TRUE, 'data' => theme('status_messages'))); } function theme_fupload_create_filename($image, $replacements = NULL) { // Get filename out of filepath $filename = trim(basename($image->filepath), ' '); $length1 = strlen(strrchr($filename, '.')); $length2 = strlen($filename); $image_name = ucfirst(substr($filename, 0, ($length2 - $length1))); // Remove some given (userdefined) elements if (is_null($replacements)) $replacements = variable_get('fupload_title_replacements', '_;{;}'); $image_name = str_replace(explode(';', $replacements), ' ', $image_name); return $image_name; } /** * Helper function which emulates "node_form_validate" of node.pages.inc * Need this because body causes validation error with some settings, but I don't need a body field, later yes =) */ function fupload_node_form_validate($form, &$form_state) { $node = (object)$form_state['values']; $node->body = NULL; // Little Hack to disable body validation node_validate($node, $form); } /** * This function allows to validate a file on given $validator functions. * This code is taken from file_save_upload (D 6.4) (22.09.2008) * * @param object $file * @param array $validators * @return Boolean * returns TRUE, if validation was successful, otherwise FALSE */ function file_validate($file, $validators = array()) { // Call the validation functions. $errors = array(); foreach ($validators as $function => $args) { array_unshift($args, $file); $errors = array_merge($errors, call_user_func_array($function, $args)); } // Check for validation errors. if (!empty($errors)) { $message = t('The selected file %name could not be uploaded.', array('%name' => $file->filename)); if (count($errors) > 1) { $message .= '