'user_access', 'access arguments' => array('use multiple upload'), 'title' => 'Imagex upload', 'page callback' => 'node_gallery_imagex_upload_image', 'type' => MENU_CALLBACK ); $items['node_gallery_imagex/get'] = array( 'title' => 'Imagex thumbs', 'access callback' => 'user_access', 'access arguments' => array('use multiple upload'), 'type' => MENU_CALLBACK, 'page callback' => 'node_gallery_imagex_js' ); $items['node_gallery_imagex'] = array( 'title' => 'Upload images', 'access callback' => 'user_access', 'access arguments' => array('use multiple upload'), 'type' => MENU_CALLBACK, 'page callback' => 'node_gallery_imagex_upload_page' ); return $items; } /** * Implementation of hook_form_alter(). * */ function node_gallery_imagex_form_alter(&$form, &$form_state, $form_id){ if($form_id == 'node_gallery_upload_form' && user_access('use multiple upload')){ //Get some js to hide forms /* drupal_add_js(drupal_get_path('module','node_gallery_imagex').'/hide.js'); $form['imagex_hide'] = array( '#type' => 'checkbox', '#title' => t('Hide multiple upload'), '#default_value' => variable_get('imagex_hide', FALSE), '#weight' => -9, );*/ $gid = arg(1); unset($form['upload_wrapper']); $form['imagex']['upload'] = array( '#prefix' => '
', '#value' => node_gallery_imagex_upload_page($gid), '#suffix' => '
', ); } } /*********************************************************************************** * CALLBACKS ***********************************************************************************/ /** * Callback for the imagex/imagex page which simply displays the applet for uploading * of images * * @return String (Contains HTML for displaying of the applet) */ function node_gallery_imagex_upload_page($gid){ //we need to get some informations from our gallery here $gallery = node_load($gid, NULL, TRUE); $config = node_gallery_get_config($gallery->type); $notes = node_gallery_upload_limits($config); //We need the image file extensions here $image_files = str_replace(' ', ',', $config['upload_limits']['general']['file_extension']); // If we're lookin' at this page, then chuffin heck, we need t'JavaScript & CSS drupal_add_js(drupal_get_path('module','node_gallery_imagex').'/node_gallery_imagex.js'); drupal_add_css(drupal_get_path('module','node_gallery_imagex').'/node_gallery_imagex.css'); return '

'.t('Drop images into the box below, or click the "Add" button, and select the images you\'d like to upload').t($notes). '

'; } /** * Callback for the upload destination. This is where images are sent to by the applet. * This page is NOT designed to be viewed by humans/browsers. */ function node_gallery_imagex_upload_image(){ // Output a postlet error if the user isn't allowed to upload. if (!user_access('use multiple upload')){ ?> POSTLET REPLY POSTLET:NO POSTLET:SERVER ERROR POSTLET:ABORT ALL END POSTLET REPLY POSTLET REPLY POSTLET:YES END POSTLET REPLY POSTLET REPLY POSTLET:NO POSTLET:TOO LARGE POSTLET:ABORT THIS END POSTLET REPLY POSTLET REPLY POSTLET:NO POSTLET:FILE TYPE NOT ALLOWED POSTLET:ABORT THIS END POSTLET REPLY POSTLET REPLY POSTLET:NO POSTLET:SERVER ERROR POSTLET:ABORT ALL END POSTLET REPLY '

'.t('The following images have been uploaded to this gallery.') .'

'.node_gallery_imagex_get_thumbs_html())); exit(); } /* * Just a test to see if we can create node_gallery_images */ function node_gallery_imagex_create_node_from($filepath, $title = NULL, $body = '', $taxonomy = NULL) { global $user; $gid = arg(2); //get our gallery $gallery = node_load($gid, NULL, TRUE); //We need the config here $config = node_gallery_get_config($gallery->type); if (!user_access('use multiple upload')) { return FALSE; } // Build the node. $node = new stdClass(); $node->type = $config['image_type']; $node->uid = $user->uid; $node->name = $user->name; $node->title = isset($title) ? $title : basename($filepath); $node->body = $body; // Set the node's defaults... (copied this from node and comment.module) $node_options = variable_get('node_options_'. $node->type, array('status', 'promote')); $node->status = in_array('status', $node_options); $node->promote = in_array('promote', $node_options); if (module_exists('comment')) { $node->comment = variable_get("comment_$node->type", COMMENT_NODE_READ_WRITE); } if (module_exists('taxonomy')) { $node->taxonomy = $taxonomy; } //save the file $file = $filepath; //check if it is a valid image make this a node_gallery check up $info = image_get_info($filepath); if (!$info || empty($info['extension'])) { print t('Only JPEG, PNG and GIF images are allowed.'); } // Get the file size $details = stat($file); $filesize = $details['size']; // Get the path to your Gallery directory copy if (!empty($gallery->config['gallery_directory'])) { $gallery_directory = strtr($gallery->config['gallery_directory'], array('%uid' => $user->uid, '%username' => $user->name, '%gid' => $gallery->nid, '%gallery_name' => $gallery->title)); // validate the path if (module_exists('transliteration')) { module_load_include('inc', 'transliteration'); $dest_array = array_filter(explode('/', $gallery_directory)); foreach ($dest_array as $key => $dir) { $dest_array[$key] = transliteration_clean_filename($dir); } $validated_path = implode('/', $dest_array); } else { $validated_path = preg_replace('/[^a-zA-Z0-9._]/', '', str_replace(' ', '_', $gallery_directory)); } //check directory $directory = rtrim(file_directory_path() .'/'. $validated_path, '/\\'); if (!is_dir($directory)) { mkdir($directory, 0777, TRUE); } file_check_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); //Make the destination $dest = $directory; } else { //If gallery->config is empty get the default file path $dest = file_directory_path(); } // Copy the file to the Drupal files directory if(!file_copy($file,$dest)) { echo "Failed to move file: $file.\n"; return; } else { // file_move might change the name of the file $name = basename($file); } // Build the file object $file_obj = new stdClass(); $file_obj->filename = $name; $file_obj->filepath = $file; $file_obj->filemime = file_get_mimetype($name); $file_obj->filesize = $filesize; $file_obj->filesource = $name; $file_obj->description = $file_obj->filename; $file_obj->weight = 0; $file_obj->gid = $node->nid; // get the $user->uid $file_obj->uid = $user->uid; $file_obj->status = FILE_STATUS_TEMPORARY; $file_obj->timestamp = time(); $file_obj->list = 1; $file_obj->new = true; // Save file to files table drupal_write_record('files', $file_obj); // change file status to permanent file_set_status($file_obj,1); // Attach the file object to your node $node->images[$file_obj->fid] = $file_obj; // Save the node. $node = node_submit($node); node_save($node); //We save the image to node_galleries $nid = $node->nid; $fid = $file_obj->fid; $weight = 0; $is_cover = 0; $sql="INSERT INTO {node_galleries} (gid, nid, fid, weight, is_cover) VALUES ('%d', '%d','%d','%d','%d')"; $result = db_query($sql, $gid, $nid, $fid, $weight, $is_cover); return $node; } /*********************************************************************************** * HELPER FUNCTIONS ***********************************************************************************/ /** * Following gets an HTML formatted list of images that the current user has uploaded, * and not edited. It can also optionally show only images uploaded in the last x minutes * * @return String (Formatted HTML) */ function node_gallery_imagex_get_thumbs_html(){ global $user; $gid = arg(2); $result = db_query("SELECT nid FROM {node_galleries} WHERE gid = %d", $gid); $html = ''; $html .= '' ; while($node = db_fetch_object($result)){ $image = node_load($node->nid); $html .= '
'.l(theme('imagecache', 'node-gallery-thumbnail', $image->filepath, $alt, $image->title, array('class' => 'blockimage')),'node/'.$node->nid.'/edit', array('html'=>TRUE, 'attributes'=>array('target'=>'_self'))).'
'; } return $html; }