--- module_installer/module_installer.module	2007-02-05 01:23:14.000000000 -0500
+++ module_theme_installer/module_theme_installer.module	2007-02-13 21:53:22.000000000 -0500
@@ -1,18 +1,26 @@
 <?php
 
-function module_installer_help($section) {
+function module_theme_installer_help($section) {
   switch ($section) {
     case 'admin/modules#description':
-      return t('Provides an interface in admin area for installing contrib modules.');
+      return t('Provides an interface in admin area for installing contrib modules and themes.');
   }
 }
 
-function module_installer_menu($may_cache) {
+function module_theme_installer_menu($may_cache) {
   $items = array();
 
   $items[] = array('path' => 'admin/modules/install',
                    'title' => t('install new module'),
-                   'callback' => 'module_installer_install_form',
+                   'callback' => 'module_theme_installer_install_form',
+                   'callback arguments' => 'module',
+                   'access' => user_access('administer site configuration'),
+                   'type' => MENU_NORMAL_ITEM,
+             );
+  $items[] = array('path' => 'admin/themes/install',
+                   'title' => t('install new theme'),
+                   'callback' => 'module_theme_installer_install_form',
+                   'callback arguments' => 'theme',
                    'access' => user_access('administer site configuration'),
                    'type' => MENU_NORMAL_ITEM,
              );
@@ -20,43 +28,83 @@
   return($items);
 }
 
-function module_installer_settings() { 
-  $form['module_installer_path_wget'] = array( 
-    '#type' => 'textfield', 
-    '#title' => t('Full path to wget'), 
-    '#default_value' => variable_get('module_installer_path_wget', 'wget'), 
-    '#size' => 20, 
-    '#maxlength' => 255, 
-    '#description' => t('The full local path to wget, such as /usr/local/bin/wget.  If unsure, use the default of wget alone.'), 
-  ); 
-  $form['module_installer_path_download'] = array( 
-    '#type' => 'textfield', 
-    '#title' => t('Download Directory'), 
-    '#default_value' => variable_get('module_installer_path_download', 'files'), 
-    '#size' => 20,
-    '#maxlength' => 255,
-    '#description' => t('Where to download the tarball module packages.  Should not end in a slash.'), 
-  ); 
-
-  $form['module_installer_path_install'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Install Directory'),
-    '#default_value' => variable_get('module_installer_path_install', 'modules/contrib'),
-    '#size' => 20,
-    '#maxlength' => 255,
-    '#description' => t('The parent directory in which to unpack the tarball.'),
+function module_theme_installer_settings() { 
+  $form['module_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Module installer settings'),
   );
-  $form['module_installer_cleanup'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Cleanup Download?'),
-    '#default_value' => variable_get('module_installer_cleanup', 1),
-    '#description' => t('If checked, the .tar.gz file will be deleted after being unpacked.'),
+    $form['module_settings']['module_installer_path_wget'] = array( 
+      '#type' => 'textfield', 
+      '#title' => t('Full path to wget'), 
+      '#default_value' => variable_get('module_installer_path_wget', 'wget'), 
+      '#size' => 20, 
+      '#maxlength' => 255, 
+      '#description' => t('The full local path to wget, such as /usr/local/bin/wget.  If unsure, use the default of wget alone.'), 
+    ); 
+    $form['module_settings']['module_installer_path_download'] = array( 
+      '#type' => 'textfield', 
+      '#title' => t('Download Directory'), 
+      '#default_value' => variable_get('module_installer_path_download', 'files'), 
+      '#size' => 20,
+      '#maxlength' => 255,
+      '#description' => t('Where to download the tarball module packages.  Should not end in a slash.'), 
+    ); 
+
+    $form['module_settings']['module_installer_path_install'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Install Directory'),
+      '#default_value' => variable_get('module_installer_path_install', 'modules'),
+      '#size' => 20,
+      '#maxlength' => 255,
+      '#description' => t('The parent directory in which to unpack the tarball.'),
+    );
+    $form['module_settings']['module_installer_cleanup'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Cleanup Download?'),
+      '#default_value' => variable_get('module_installer_cleanup', 1),
+      '#description' => t('If checked, the .tar.gz file will be deleted after being unpacked.'),
+    );
+
+  $form['theme_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Theme installer settings'),
   );
+    $form['theme_settings']['theme_installer_path_wget'] = array( 
+      '#type' => 'textfield', 
+      '#title' => t('Full path to wget'), 
+      '#default_value' => variable_get('theme_installer_path_wget', 'wget'), 
+      '#size' => 20, 
+      '#maxlength' => 255, 
+      '#description' => t('The full local path to wget, such as /usr/local/bin/wget.  If unsure, use the default of wget alone.'), 
+    ); 
+    $form['theme_settings']['theme_installer_path_download'] = array( 
+      '#type' => 'textfield', 
+      '#title' => t('Download Directory'), 
+      '#default_value' => variable_get('theme_installer_path_download', 'files'), 
+      '#size' => 20,
+      '#maxlength' => 255,
+      '#description' => t('Where to download the tarball theme packages.  Should not end in a slash.'), 
+    ); 
+
+    $form['theme_settings']['theme_installer_path_install'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Install Directory'),
+      '#default_value' => variable_get('theme_installer_path_install', 'themes'),
+      '#size' => 20,
+      '#maxlength' => 255,
+      '#description' => t('The parent directory in which to unpack the tarball.'),
+    );
+    $form['theme_settings']['theme_installer_cleanup'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Cleanup Download?'),
+      '#default_value' => variable_get('theme_installer_cleanup', 1),
+      '#description' => t('If checked, the .tar.gz file will be deleted after being unpacked.'),
+    );
 
   return $form; 
 } 
 
-function module_installer_install_form() {
+function module_theme_installer_install_form($arg) { /* $arg tells us whether it's a module or a theme */
   $form['url'] = array(
      '#type' => 'textfield',
      '#title' => t('URL of tar.gz module package'),
@@ -66,14 +114,25 @@
      '#type' => 'submit',
      '#value' => t('Install'),
   );
+  
+  $form['type'] = array(
+    '#type' => 'hidden',
+    '#value' => t($arg), /* tell module_theme_installer_install_form_submit() whether we're installing a module or theme */
+  );
 
-  $output = drupal_get_form('module_installer_install_form', $form);
+  $output = drupal_get_form('module_theme_installer_install_form', $form);
   return $output;
 }
 
-function module_installer_install_form_submit($form_id, $form_values) {
-  $destination_path = variable_get('module_installer_path_download', 'files');
-  $modules_dir =  variable_get('module_installer_path_install', 'modules/contrib');
+function module_theme_installer_install_form_submit($form_id, $form_values) {
+
+  if($form_values['type'] == 'module') {
+    $destination_path = variable_get('module_installer_path_download', 'files');
+    $modules_dir =  variable_get('module_installer_path_install', 'modules');
+  } else if ($form_values['type'] == 'theme') {
+    $destination_path = variable_get('theme_installer_path_download', 'files');
+    $themes_dir = variable_get('theme_installer_path_install', 'themes');
+  }
   $basename = basename($form_values['url']);
 
   $exec_cmd = "wget -P" . $destination_path . " " . $form_values['url'];
@@ -88,21 +147,40 @@
   }
 
   // we are using rename to move the file
-  if (!rename($destination_path."/".$basename, $modules_dir."/".$basename)) {
-    drupal_set_message("Unable to move $basename to $modules_dir/$basename", 'error');
-    return;
+  if($form_values['type'] == 'module') {
+    if (!rename($destination_path."/".$basename, $modules_dir."/".$basename)) {
+      drupal_set_message("Unable to move $basename to $modules_dir/$basename", 'error');
+      return;
+    }
+
+    $exec_cmd = "tar -C " . $modules_dir . " -zxf " . $modules_dir."/".$basename;
+    exec($exec_cmd, $exec_output, $exec_return_var);
+    // TODO: check that tar actually worked
+    drupal_set_message("Module " . $basename . " installed.");
+
+    if (variable_get('module_installer_cleanup', 1) == 1) {
+      unlink($modules_dir."/".$basename);
+      // TODO: check that unlink actually worked
+      drupal_set_message("$basename deleted");
+    }
+  } else if ($form_values['type'] == 'theme') {
+    if (!rename($destination_path."/".$basename, $themes_dir."/".$basename)) {
+      drupal_set_message("Unable to move $basename to $modules_dir/$basename", 'error');
+      return;
+    }
+    $exec_cmd = "tar -C " . $themes_dir . " -zxf " . $themes_dir."/".$basename;
+    exec($exec_cmd, $exec_output, $exec_return_var);
+    // TODO: check that tar actually worked
+    drupal_set_message("Theme " . $basename . " installed.");
+
+    if (variable_get('theme_installer_cleanup', 1) == 1) {
+      unlink($themes_dir."/".$basename);
+      // TODO: check that unlink actually worked
+      drupal_set_message("$basename deleted");
+    }   
   }
 
-  $exec_cmd = "tar -C " . $modules_dir . " -zxf " . $modules_dir."/".$basename;
-  exec($exec_cmd, $exec_output, $exec_return_var);
-  // TODO: check that tar actually worked
-  drupal_set_message("Module " . $basename . " installed.");
 
-  if (variable_get('module_installer_cleanup', 0) == 1) {
-    unlink($modules_dir."/".$basename);
-    // TODO: check that unlink actually worked
-    drupal_set_message("$basename deleted");
-  }   
 
   // the following block of code can be used instead of wget on some systems
   // depending on server configuration.  Ideally, setup would allow the user
