Index: filebrowser.module
===================================================================
--- filebrowser.module	(.../vendor-sources-6.x/filebrowser/filebrowser.module)	(revision 3)
+++ filebrowser.module	(.../sites/segedletek/d6/sites/all/modules/filebrowser/filebrowser.module)	(revision 35)
@@ -635,7 +635,12 @@
       'arguments' => array (
         'node' => NULL
       )
-    )
+    ),
+    'filebrowser_filename' => array (
+      'arguments' => array (
+        'data' => NULL
+      )
+    )    
   );
 }
 
@@ -664,6 +669,13 @@
  */
 function filebrowser_menu() {
   $items= array ();
+  
+  $items['swfupload'] = array(
+    'page callback' => 'filebrowser_swfupload',
+    'type' => MENU_CALLBACK,
+    'access arguments' => array(FILEBROWSER_UPLOAD),
+  );
+  
   $items['filebrowser_download/%node']= array (
     'page callback' => '_filebrowser_download_callback',
     'page arguments' => array (
@@ -698,6 +710,115 @@
 }
 
 /**
+ * Works around the flash player cookie bug
+ */
+function filebrowser_boot() {
+  foreach (array_keys($_POST) as $key) {
+    if (substr($key, 0, 4) == "SESS") {
+      if(!isset($_COOKIE[$key])) {
+        $_COOKIE[$key] = $_POST[$key];
+      }
+      session_id($_POST[$key]);
+      session_decode(sess_read($_POST[$key]));
+    }
+  }  
+}
+
+/**
+ * This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case)
+ * (from gilthans)
+ */
+function _filebrowser_let_to_num($v){ 
+  $l = substr($v, -1);
+  $ret = substr($v, 0, -1);
+  switch(strtoupper($l)){
+  case 'P':
+      $ret *= 1024;
+  case 'T':
+      $ret *= 1024;
+  case 'G':
+      $ret *= 1024;
+  case 'M':
+      $ret *= 1024;
+  case 'K':
+      $ret *= 1024;
+      break;
+  }
+  return $ret;
+}
+
+/**
+ * Determines the maximum upload size in bytes.
+ */
+function _filebrowser_max_upload_size() {
+  return min(_filebrowser_let_to_num(ini_get('post_max_size')), _filebrowser_let_to_num(ini_get('upload_max_filesize')));
+}
+
+/**
+ * Post handler for SWFUpload
+ */
+function filebrowser_swfupload()
+{
+  $target_path = $_POST['target_path'];
+  if ( substr($target_path, -1) !== '/' ) {
+    $target_path .= '/';
+  }
+
+  if (isset($_FILES['Filedata']) && $_FILES['Filedata']['name'] && is_uploaded_file($_FILES['Filedata']['tmp_name']) && $_FILES['files']['error'] == UPLOAD_ERR_OK ) {
+    $destination = $target_path . $_FILES['Filedata']['name'];
+    
+    if ( file_check_location($target_path, file_directory_path()) && file_check_directory($target_path) ) {    
+      if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $destination)) {
+        drupal_set_message(t('Successful upload.'));
+      } else {
+        drupal_set_message(t('Upload failed.'), 'error');
+      }
+    }
+  }
+}
+
+/**
+ * Initializes the javascript part of the swfupload support.
+ */
+function filebrowser_swfupload_init_js($node) {
+  if ( !user_access(FILEBROWSER_UPLOAD) ) {
+    return FALSE;
+  }
+  
+  $swfupload_path = drupal_get_path("module", "filebrowser").'/swfupload/';
+  $swfupload_flash = $swfupload_path . 'swfupload.swf';
+  $required_js = array('swfupload.js', 'swfupload.queue.js', 'swfupload.speed.js', 'swfupload.cookies.js', 'swfupload.support.js' );
+  
+  foreach ( $required_js as $js ) {
+    $path = $swfupload_path . $js;
+    if ( file_exists( $path ) ) {
+      drupal_add_js( $path );
+    } else {
+      return FALSE;
+    }
+  }  
+    
+  drupal_add_js( array( 'swfupload_upload_url' => base_path() . 'swfupload',
+                        'swfupload_button_url' => base_path() . $swfupload_path . '/upload.png',
+                        'swfupload_flash_url' => base_path() . $swfupload_flash  ,
+                        'swfupload_size_limit' => _filebrowser_max_upload_size(),
+                        'swfupload_target_path' => _filebrowser_current_full_path($node),
+                        ),
+                        'setting' );
+  
+  return TRUE;
+}
+
+function filebrowser_swfupload_html() {
+  $fset_output = '<div id="swfupload-button"></div><div id="swfupload-status-text"></div>';
+  $fset_output .= '<div class="maximum-size">'.t('Maximum file size is @size.', array( '@size' => format_size( _filebrowser_max_upload_size() ) )).'</div>';
+  $fset_output .= '<input type="button" value="'.t('Cancel').'" id="swfupload-cancel" disabled="disabled" />';    
+    
+  $fieldset = array( '#title' => t('Mass upload'), '#value' => $fset_output, '#collapsible' => TRUE, '#collapsed' => TRUE );    
+  return theme('fieldset', $fieldset);
+}
+
+/**
  * hook_view implementation
  */
 function filebrowser_view($node, $teaser= FALSE, $page= FALSE) {
@@ -740,21 +861,92 @@
 
     // Insert download form content part
     if (!empty ($node->allow_files_upload) && user_access(FILEBROWSER_UPLOAD)) {
-      $form= drupal_get_form('filebrowser_upload_form', $node);
-      $node->content['filebrowser_upload']= array (
+      
+      if ( filebrowser_swfupload_init_js($node) ) {
+        $node->content['filebrowser_swfupload']= array (
+          '#value' => filebrowser_swfupload_html(),
+          '#weight' => 2
+        );
+      } else {      
+        $form= drupal_get_form('filebrowser_upload_form', $node);
+        $node->content['filebrowser_upload']= array (
+          '#value' => $form,
+          '#weight' => 2
+        );
+      }
+      
+      $form= drupal_get_form('filebrowser_make_directory_form', $node);
+      $node->content['filebrowser_make_directory']= array (
         '#value' => $form,
         '#weight' => 2
-      );
+      );      
     }
   }
   return $node;
 }
 
 /**
+ * Make directory form.
+ *
+ */
+
+function filebrowser_make_directory_form($form_state, $node)
+{
+  $form['#node'] = $node;
+  $form['#redirect'] = array( 'node/'.$node->nid, 'path='.$_GET['path'] );
+  
+  $form['filebrowser_makedir'] = array (
+    '#type' => 'fieldset',
+    '#title' => t('Make Directory'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#description' => t('The directory will be created in the current directory.'),
+    '#weight' => 30
+  );  
+  
+  $form['filebrowser_makedir']['directory_name']= array (
+    '#type' => 'textfield',
+    '#title' => t('Name'),
+    '#size' => 40,
+    '#required' => TRUE,
+    '#prefix' => '<div class="container-inline">',
+  );  
+  
+  $form['filebrowser_makedir']['submit'] = array (
+    '#type' => 'submit',
+    '#value' => t('Create'),
+    '#suffix' => '</div>',    
+  );
+  
+  return $form;
+}
+
+function filebrowser_make_directory_form_validate($form, &$form_state) {
+  $node = $form['#node'];
+  $full_path = file_create_path( _filebrowser_current_full_path($node) . $form_state['values']['directory_name'] );
+  
+  if ( $full_path ) {
+    if ( file_exists($full_path) ) {
+      form_set_error('directory_name', t("This directory already exists."));
+    } else {
+      $form_state['values']['full_path'] = $full_path;
+    }
+  } else {
+    form_set_error('directory_name', t('Invalid directory name.'));
+  }
+}
+
+function filebrowser_make_directory_form_submit($form, &$form_state) {
+  $full_path = $form_state['values']['full_path'];  
+  file_check_directory( $full_path, TRUE, 'directory_name' );
+}
+
+/**
  * Upload form. 
  */
 function filebrowser_upload_form($form_state, $node) {
   $form= array ();
+  $form['#redirect'] = array( 'node/'.$node->nid, 'path='.$_GET['path'] );
   $form['filebrowser_uploads']= array (
     '#type' => 'fieldset',
     '#title' => t('File Upload'),
@@ -901,13 +1093,6 @@
 }
 
 /**
- * Originaly a file.inc Drupal function modified.
- *
- * @param unknown_type $file_name
- * @param unknown_type $mapping
- */
-
-/**
  * Theme a directory listing of files in a system directory.
  *
  * @param array $files An array of data of files in this directory.
@@ -940,8 +1125,7 @@
     );
 
     // add filename
-    $unsorted_rows[$file_name][]= '<a href="'.
-    $data['url'].'">'. ($data['display-name'] == '..' ? t('Go up') : $data['display-name']).'</a>'.theme('mark', $data['status']);
+    $unsorted_rows[$file_name][]= theme('filebrowser_filename', $data);
 
     // add optional colunmns
     $is_used= array ();
@@ -1079,6 +1263,10 @@
   return $output;
 }
 
+function theme_filebrowser_filename($data) {
+  return '<a href="'.$data['url'].'">'. ($data['display-name'] == '..' ? t('Go up') : $data['display-name']).'</a>'.theme('mark', $data['status']);
+}
+
 function theme_filebrowser_page_title($node) {
   return !empty ($node->title) ? $node->title : '';
 }
