Index: og_files.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/og_files/Attic/og_files.module,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 og_files.module
--- og_files.module	17 May 2008 13:42:16 -0000	1.1.2.2
+++ og_files.module	5 Dec 2008 02:00:12 -0000
@@ -132,9 +132,11 @@ function og_file_list_form($gid, $path){
   
 
     
-    
+  $dir_tree_raw = array();
+
   while($file = db_fetch_object($files)) {
-    $array = explode('/',og_files_relative_path($gid,$file->filepath));
+    $filename = og_files_relative_path($gid,$file->filepath);
+    $array = explode('/', $filename);
     array_pop($array);
     if((count($array) - $virtualpath_count) > 0) { //in a subdir
 
@@ -143,39 +145,71 @@ function og_file_list_form($gid, $path){
       if (count($array) - $virtualpath_count < 2) {
         $dir_list[$array[count($array)-1]] = l($array[count($array)-1], og_files_virtual_base_path($gid).implode('/',$array));
         $dir_count++;
+        $dir_tree_raw[] = $array;
       }
 
     }
     else {
-      $file_list[$file->fid] = l($file->filename,og_files_virtual_base_path($gid).og_files_relative_path($gid,$file->filepath));
+      $dir_tree_raw[] = explode('/', dirname($filename));
+      $file_list[$file->fid] = l($file->filename,og_files_virtual_base_path($gid). $filename);
       $file_count++;
     }
   }
+  // Traverse $dir_tree_raw to $dir_tree
+  $dir_tree = array();
+  if (count($dir_tree_raw)) {
+    foreach ($dir_tree_raw as $tree) {
+      $current_dir =& $dir_tree;
+      foreach ($tree as $dir) {
+        if($dir !== '.') {
+          if (!isset($current_dir[$dir]))
+            $current_dir[$dir] = array();
+          $current_dir =& $current_dir[$dir];
+        }
+      }
+    }
+  }
 
   $form['filelist'] = array(
     '#type' => 'fieldset',
-    '#title' => '/'.og_files_relative_path($gid,$path),
+    '#title' => '/'. og_files_relative_path($gid, $path),
     '#collapsible' => true,
     '#collapsed' => false
   );
-  
+
+  $form['filelist']['tree'] = array(
+    '#type' => 'item',
+    '#value' => theme('og_files_tree', $gid, array('/' => $dir_tree), $virtualpath),
+    '#prefix' => '<div class="og_files-'. $skin .'-tree">',
+    '#suffix' => '</div>',
+  );
+
   //if($dir_count) {
-    $dir_html = theme_item_list($dir_list);
+    $dir_html = theme('item_list', $dir_list);
     $form['filelist']['folders'] = array(
-      '#prefix' => $dir_html,
+      '#prefix' => '<div class="og_files-'. $skin .'-files">'. $dir_html,
       '#type' => 'hidden'
     );
   //}
-  
+
   if($file_count) {
     $form['filelist']['files'] = array(
       '#type' => 'checkboxes',
      // '#title' => $path, //t('File list'),
       '#options' => $file_list,
+      '#suffix' => '</div>',
     );
     $form['filelist']['delete'] = array(
       '#type' => 'submit',
       '#value' => t('Delete selected files'),
+      '#prefix' => '<div class="og_files-'. $skin .'-button-delete">',
+      '#suffix' => '</div>',
+    );
+  }
+  else {
+    $form['filelist']['close-tree'] = array(
+      '#type' => 'item',
+      '#suffix' => '</div>',
     );
   }
   return $form;
@@ -302,4 +336,32 @@ function og_files_nodeapi(&$node, $op, $
       db_query('DELETE FROM {og_files} WHERE gid = %d',$node->nid);
       break;
   }
-}
\ No newline at end of file
+}
+
+function theme_og_files_tree($nid, $tree, $current_path, $base_path = '') {
+  // Get skin and add css
+  $skin = variable_get('og_files_skin', 0);
+
+  // Build tree
+  $output = '';
+  foreach ($tree as $dir => $sub_tree) {
+    $path = $base_path . $dir;
+    $link_path = og_files_virtual_base_path($nid) .
+                 ($path !== '/' ? str_replace('//', '', $path) : $base_path);
+    $path .= '/';
+    $item = array(array(
+      'data' => l($dir, $link_path),
+      'class' => 'og_files-'. $skin .'-dir'.
+                 ('//'. $current_path .'/' == $path || $path == '//' ? '_current' : ''),
+    ));
+    if (count($sub_tree)) {
+      $item['children'] = array(
+        'data' => theme('og_files_tree', $nid, $sub_tree, $current_path, $path),
+        'class' => 'og_files-'. $skin .'-subtree',
+      );
+    }
+      
+    $output .= theme('item_list', $item);
+  }
+  return $output;
+}
