Index: skinr.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/skinr/skinr.info,v
retrieving revision 1.4
diff -u -p -r1.4 skinr.info
--- skinr.info	16 Oct 2010 22:22:17 -0000	1.4
+++ skinr.info	22 Oct 2010 04:43:49 -0000
@@ -5,6 +5,8 @@ description = Provides a way to define a
 package = Skinr
 core = 7.x
 
+dependencies[] = ctools
+
 files[] = skinr.module
 files[] = skinr.handlers.inc
 files[] = modules/block.skinr.inc
Index: skinr.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/skinr/skinr.install,v
retrieving revision 1.9
diff -u -p -r1.9 skinr.install
--- skinr.install	19 Oct 2010 18:30:31 -0000	1.9
+++ skinr.install	22 Oct 2010 04:43:49 -0000
@@ -112,7 +112,7 @@ function skinr_schema() {
         'not null' => TRUE,
         'default' => '',
       ),
-      'name' => array(
+      'machine_name' => array(
         'description' => 'The name of the item; e.g. skinset.',
         'type' => 'varchar',
         'length' => 255,
@@ -134,7 +134,7 @@ function skinr_schema() {
     ),
     'primary key' => array('filename'),
     'indexes' => array(
-      'name' => array('name'),
+      'machine_name' => array('machine_name'),
     ),
   );
 
@@ -383,3 +383,13 @@ function skinr_update_7003() {
     db_create_table('skinr_skins', $schema['skinr_skins']);
   }
 }
+
+function skinr_update_7004() {
+  $ret = array();
+  
+  if (db_table_exists('skinr_skinsets')) {
+    db_change_field($ret, 'skinr_skinsets', 'name', 'machine_name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
+  }
+
+  return $ret;
+}
\ No newline at end of file
Index: skinr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/skinr/skinr.module,v
retrieving revision 1.28
diff -u -p -r1.28 skinr.module
--- skinr.module	15 Oct 2010 07:06:17 -0000	1.28
+++ skinr.module	22 Oct 2010 04:43:50 -0000
@@ -1,6 +1,47 @@
 <?php
 // $Id: skinr.module,v 1.28 2010/10/15 07:06:17 jgirlygirl Exp $
 
+define('SKINR_MINIMUM_VERSION', 2);
+define('SKINR_VERSION', 2);
+
+// -----------------------------------------------------------------------
+// CTools hook implementations.
+
+/**
+ * Implementation of hook_include_api().
+ */
+function skinr_include_api() {
+  ctools_include('plugins');
+  return ctools_plugin_api_include('skinr', 'skins', SKINR_MINIMUM_VERSION, SKINR_VERSION);
+}
+
+/**
+ * Implementation of hook_include_api().
+ *
+ * @todo When this is done, we should probably also move the handlers to a ctools plugins.
+ */
+function skinr_ctools_plugin_type() {
+  return array(
+    'skins' => array(
+      'load themes' => TRUE, // Allow themes to also contains skins plugins
+      'cache' => TRUE,
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_ctools_plugin_directory().
+ */
+function skinr_ctools_plugin_directory($owner, $plugin_type) {
+  if ($owner == 'skinr') {
+    return 'plugins/' . $plugin_type;
+  }
+}
+
+// -----------------------------------------------------------------------
+// End of CTools hook implementations.
+
+
 /**
  * Implementation of hook_help().
  */
@@ -68,7 +109,7 @@ function skinr_preprocess(&$variables, $
         $data = array(
           'hook' => $hook,
           'variables' => &$variables,
-          'skin' => &$extracted,
+          'skins' => &$extracted,
         );
         drupal_alter('skinr_preprocess', $data);
       }
@@ -108,10 +149,9 @@ function skinr_skin_extract($module, $si
   // Allow other modules to alter the skinr skins array.
   // @todo Fix this to work with skinr ui.
   drupal_alter('skinr_skins', $skins, $module, $sids, $settings);
-
   $extracted['css'] = skinr_skin_get_files($skins, 'css', $theme);
   $extracted['js'] = skinr_skin_get_files($skins, 'js', $theme);
-
+  
   // Add template files.
   if (!empty($skins['_template'])) {
     $extracted['template'] = $skins['_template'];
@@ -144,7 +184,6 @@ function skinr_skin_get_files($skins, $t
 
   $info = skinr_skin_data();
   $files = array();
-
   if ($type == 'css') {
     foreach ($skins as $skin => $classes) {
       // Add custom CSS files.
@@ -237,7 +276,6 @@ function skinr_skin_get_files($skins, $t
       }
     }
   }
-
   return $files;
 }
 
@@ -404,6 +442,88 @@ function skinr_get_module_apis() {
   return $cache;
 }
 
+/**
+ * Load all skins.
+ */
+function skinr_get_skins() {
+  ctools_include('plugins');
+  $skinsets = ctools_get_plugins('skinr', 'skins');
+
+  foreach ($skinsets as $key => $skinset) {
+    $skinsets[$key] += skinr_skins_default();
+
+    // Give the screenshot proper path information.
+    if (!empty($skinset['screenshot'])) {
+      $skinsets[$key]['screenshot'] = $skinsets[$key]['path'] . '/' . $skinsets[$key]['screenshot'];
+    }
+    
+    // Give all css and js files proper path information.
+    _skinr_add_paths_to_files($skinsets[$key]['skinr'], $skinsets[$key]['path']);
+
+    // Invoke hook_skinr_info_alter() to give installed modules a chance to
+    // modify the data in the .skinr.inc files if necessary.
+    drupal_alter('skinr_info', $skinsets[$key], $skinsets[$key]);
+  }
+  
+  return $skinsets;
+}
+
+/**
+ * Load a skin.
+ */
+function skinr_load_info($skin, $skinset = NULL) {
+  if (is_null($skinset)) {
+    $info = skinr_get_skinr_files();
+    if (!empty($info[$skin])) {
+      $skinset = $info[$skin];
+    }
+    else {
+      return FALSE;
+    }
+  }
+
+  if (is_file($skinset->uri)) {
+    require_once $skinset->uri;
+
+    $function = $skinset->name .'_skinr_info';
+    $skinset->info = call_user_func_array($function, array());
+    if (!isset($skinset->info)) {
+      return FALSE;
+    }
+    if (!is_array($skinset->info)) {
+      $skinset->info = array($skinset->info);
+    }
+
+    foreach ($skinset->info as $key => $info) {
+      $skinset->info[$key] += skinr_skins_default();
+
+      // Give the screenshot proper path information.
+      if (!empty($skinset->info[$key]['screenshot'])) {
+        $skinset->info[$key]['screenshot'] = dirname($skinset->filename) .'/'. $skinset->info[$key]['screenshot'];
+      }
+
+      // Give all css and js files proper path information.
+      _skinr_add_paths_to_files($skinset->info[$key]['skinr'], dirname($skinset->filename));
+
+      // Invoke hook_skinr_info_alter() to give installed modules a chance to
+      // modify the data in the .skinr.inc files if necessary.
+      drupal_alter('skinr_info', $skinset->info[$key], $skinset);
+
+      // @todo In the future we might want to disable the below code to allow
+      //       multiple skinsets in a single file. This would require
+      //       substantial re-writing of certain pieces of code.
+      $skinset->info = $skinset->info[$key];
+      break;
+      // End code to remove.
+    }
+
+    return $skinset;
+  }
+  else {
+    return FALSE;
+  }
+}
+
 // -----------------------------------------------------------------------
 // Skinr data handling functions.
 
@@ -635,69 +755,10 @@ function skinr_skin_default() {
 }
 
 /**
- * Retrieves all the Skinr skins from theme parents. Theme skins
- * will override any skins of the same name from its parents.
- */
-function skinr_inherited_skins($theme) {
-  $themes = list_themes();
-
-  $all_skins = $skins = array();
-  $base_theme = (!empty($themes[$theme]->info['base theme'])) ? $themes[$theme]->info['base theme'] : '';
-  while ($base_theme) {
-    $all_skins[] = (!empty($themes[$base_theme]->info['skinr'])) ? (array)$themes[$base_theme]->info['skinr'] : array();
-    $base_theme = (!empty($themes[$base_theme]->info['base theme'])) ? $themes[$base_theme]->info['base theme'] : '';
-  }
-  array_reverse($all_skins);
-  foreach ($all_skins as $new_skin) {
-    $skins = array_merge($skins, $new_skin);
-  }
-  return $skins;
-}
-
-/**
- * Helper function to scan and collect skin .info data.
+ * Helper function to process a skin or theme .skinr.inc file.
  *
- * @return
- *   An associative array of skins information.
- */
-function _skinr_rebuild_skinset_data() {
-  // Find skins.
-  $mask = '/\.info$/';
-  $directory = 'skins';
-  $skinsets = drupal_system_listing($mask, $directory, 'name', 0);
-
-  // Find skins in theme folders.
-  $themes = list_themes();
-  foreach ($themes as $theme) {
-    $dir = dirname($theme->filename) . '/' . $directory;
-    $skinsets = array_merge($skinsets, file_scan_directory($dir, $mask, array('.', '..', 'CVS'), 0, TRUE, 'name', 1));
-  }
-
-  // Set defaults for skinset info.
-  $defaults = skinr_skins_default();
-
-  foreach ($skinsets as $key => $skinset) {
-    $skinsets[$key]->filename = $skinset->uri;
-    $skinsets[$key]->info = drupal_parse_info_file($skinset->uri) + $defaults;
-
-    // Give the screenshot proper path information.
-    if (!empty($skinsets[$key]->info['screenshot'])) {
-      $skinsets[$key]->info['screenshot'] = dirname($skinsets[$key]->uri) . '/' . $skinsets[$key]->info['screenshot'];
-    }
-
-    // Invoke hook_skinr_info_alter() to give installed modules a chance to
-    // modify the data in the .info files if necessary.
-    $type = 'skinset';
-    drupal_alter('skinr_info', $skinsets[$key]->info, $skinsets[$key], $type);
-    
-    // @todo Give the stylesheets and scripts proper path information, or leave 'till later?
-  }
-
-  return $skinsets;
-}
-
-/**
- * Helper function to process a skin or theme .info file.
+ * @param $info
+ *    Needs to be documented.
  *
  * @return
  *    A skinset.
@@ -731,11 +792,6 @@ function _skinr_skinset($info) {
       }
     }
 
-    // Inherit skins from parent theme, if inherit_skins is set to true.
-    if (!empty($skinset['options']['inherit_skins'])) {
-      $skinr_info = array_merge(skinr_inherited_skins($info->name), $skinr_info);
-    }
-
     $defaults = skinr_skin_default();
 
     foreach ($skinr_info as $id => $skin) {
@@ -754,29 +810,51 @@ function _skinr_skinset($info) {
         'scripts' => isset($skin['scripts']) ? $skin['scripts'] : $defaults['scripts'],
         'weight' => isset($skin['weight']) ? $skin['weight'] : $defaults['weight'],
       );
+    }
+  }
 
-      // Give the stylesheets proper path information.
-      $skinset['skins'][$id]['stylesheets'] = _skinr_add_path_to_files($skinset['skins'][$id]['stylesheets'], $path_root, 'css');
+  return $skinset;
+}
 
-      // Give the scripts proper path information.
-      $skinset['skins'][$id]['scripts'] = _skinr_add_path_to_files($skinset['skins'][$id]['scripts'], $path_root, 'js');
+/**
+ * Helper function to prepend a path to the data from a .skinr.inc file.
+ *
+ * @param $skinr_info
+ *   An array as returned from hook_skinr_info() to which the paths will be added.
+ * @param $path_root
+ *   The path to prepend.
+ */
+function _skinr_add_paths_to_files(&$skinr_info, $path_root) {
+  foreach ($skinr_info as $id => $skin) {
+    if (!is_array($skin)) {
+      continue;
+    }
+
+    // Give the stylesheets proper path information.
+    if (!empty($skin['stylesheets'])) {
+      $skinr_info[$id]['stylesheets'] = _skinr_add_path_to_files($skin['stylesheets'], $path_root, 'css');
+    }
 
-      foreach ($skinset['skins'][$id]['options'] as $oid => $option) {
-        if (isset($option['stylesheets'])) {
-          $skinset['skins'][$id]['options'][$oid]['stylesheets'] = _skinr_add_path_to_files($option['stylesheets'], $path_root, 'css');
+    // Give the scripts proper path information.
+    if (!empty($skin['scripts'])) {
+      $skinr_info[$id]['scripts'] = _skinr_add_path_to_files($skin['scripts'], $path_root, 'js');
+    }
+
+    if (!empty($skin['options'])) {
+      foreach ($skin['options'] as $oid => $option) {
+        if (!empty($option['stylesheets'])) {
+          $skinr_info[$id]['options'][$oid]['stylesheets'] = _skinr_add_path_to_files($option['stylesheets'], $path_root, 'css');
         }
         if (isset($option['scripts'])) {
-          $skinset['skins'][$id]['options'][$oid]['scripts'] = _skinr_add_path_to_files($option['scripts'], $path_root, 'js');
+          $skinr_info[$id]['options'][$oid]['scripts'] = _skinr_add_path_to_files($option['scripts'], $path_root, 'js');
         }
       }
     }
   }
-
-  return $skinset;
 }
 
 /**
- * Helper function to prepend a path to an array of stylesheets or scripts in a .info file.
+ * Helper function to prepend a path to an array of stylesheets or scripts in a .skinr.inc file.
  *
  * @param $files
  *   A an array of filenames that need the path prepended.
@@ -811,40 +889,26 @@ function _skinr_add_path_to_files($files
 }
 
 /**
- * Helper function to process an array of skins or themes .info files.
+ * Helper function to process an array of skins or themes .skinr.inc files.
  *
- * @param $type
- *   Either 'theme' or 'skinset'.
+ * @param $refresh
+ *   Whether to reload the list of skinsets from the database or not.
  *
  * @return
  *    An array of skinsets.
  */
-function skinr_skinsets($type) {
-  $skinsets = &drupal_static(__FUNCTION__, array('theme' => array(), 'skinset' => array()));
+function skinr_skinsets() {
+  $skinsets = &drupal_static(__FUNCTION__, array());
   // @todo drupal_static_reset('skinr_skinsets');
 
-  if (empty($skinsets[$type])) {
+  if (empty($skinsets)) {
     $themes = list_themes();
 
-    if ($type == 'theme') {
-      foreach ($themes as $theme) {
-        $skinset = new StdClass();
-        $skinset->filename = $theme->filename;
-        $skinset->name = $theme->name;
-        $skinset->status = $theme->status ? 1 : 0;
-        $skinset->info = $theme->info;
-
-        $skinsets[$type][$skinset->name] = $skinset;
-      }
-    }
-    elseif ($type == 'skinset') {
-      $result = db_query("SELECT * FROM {skinr_skinsets}");
-      foreach ($result as $skinset) {
-        if (file_exists($skinset->filename)) {
-          $skinset->info = unserialize($skinset->info);
-
-          $skinsets[$type][$skinset->name] = $skinset;
-        }
+    $result = db_query("SELECT * FROM {skinr_skinsets}");
+    foreach ($result as $key => $skinset) {
+      if (file_exists($skinset->filename)) {
+        $skinset->info = unserialize($skinset->info);
+        $skinsets[$key] = $skinset;
       }
     }
 
@@ -853,21 +917,46 @@ function skinr_skinsets($type) {
       $default_status[$theme->name] = $theme->name;
     }
 
-    foreach ($skinsets[$type] as $key => $skinset) {
-      $skinset->type = $type;
+    foreach ($skinsets as $key => $skinset) {
+      if (isset($themes[$key])) {
+        $skinset->type = 'theme';
+        $skinset->status = !empty($theme->status) ? 1 : 0;
+      }
+      else {
+        $skinset->type = 'skinset';
+      }
+
+      // Inherit skins from base theme, if inherit_skins is set to true.
+      if (!empty($skinset->info['skinr']['options']['inherit_skins'])) {
+        // Merge base theme and current.
+        $inheriting = TRUE;
+        $merged_skins = array();
+        $current_skinset = $skinset;
+        while ($inheriting) {
+          $inheriting = FALSE;
+          if (!empty($current_skinset->info['base theme'])) {
+            if (!empty($skinsets[$current_skinset->info['base theme']])) {
+              $current_skinset = $skinsets[$current_skinset->info['base theme']];
+              $merged_skins = array_merge($current_skinset->info['skinr'], $merged_skins);
+              $inheriting = TRUE;
+            }
+          }
+        }
+        $skinset->info['skinr'] = array_merge($merged_skins, $skinset->info['skinr']);
+      }
 
       $additional = _skinr_skinset($skinset);
       $skinset->options = $additional['options'];
       $skinset->skins = $additional['skins'];
 
-      $statuses = skinr_skinset_statuses($skinset->name);
+      $statuses = skinr_skinset_statuses($key);
       foreach ($skinset->skins as $skin_name => $skin) {
         $skinset->skins[$skin_name]['status'] = !empty($statuses[$skin_name]) ? $statuses[$skin_name] : $default_status;
       }
     }
   }
 
-  return $skinsets[$type];
+  return $skinsets;
 }
 
 /**
@@ -901,8 +990,20 @@ function skinr_skinset_statuses($skinset
  *   Array of all available skinsets and their data.
  */
 function skinr_rebuild_skinset_data() {
-  $skinsets = _skinr_rebuild_skinset_data();
+  $skinsets = skinr_get_skins();
   skinr_get_files_database($skinsets);
+
+  $themes = list_themes();
+  foreach ($skinsets as $key => $skinset) {
+    if (isset($themes[$key])) {
+      $skinset['status'] = !empty($themes[$key]->status) ? 1 : 0;
+      $skinset['type'] = 'theme';
+    }
+    else {
+      $skinset['type'] = 'skinset';
+    }
+  }
+
   skinr_update_files_database($skinsets);
   return $skinsets;
 }
@@ -923,19 +1024,28 @@ function skinr_flush_caches() {
  */
 function skinr_get_files_database(&$files) {
   // Extract current files from database.
-  $result = db_query("SELECT filename, name, status FROM {skinr_skinsets}");
-  foreach ($result as $file) {
-    if (isset($files[$file->name]) && is_object($files[$file->name])) {
-      $file->uri = $file->filename;
-      foreach ($file as $key => $value) {
-        if (!isset($files[$file->name]) || !isset($files[$file->name]->$key)) {
-          $files[$file->name]->$key = $value;
+  $result = db_query("SELECT  * FROM {skinr_skinsets}");
+  foreach ($result as $key => $file) {
+    if ($entry = _skinr_get_file_by_key($files, $file->machine_name)) {
+      if (isset($files[$entry]) && is_array($files[$entry])) {
+        $file->uri = $file->filename;
+        foreach ($file as $key => $value) {
+          $files[$entry][$key] = $value;
         }
       }
     }
   }
 }
 
+function _skinr_get_file_by_key(&$files, $key) {
+  foreach ($files as $xkey => $file) {
+    if ($xkey == $key) {
+      return $xkey;
+    }
+  }
+  return FALSE;
+}
+
 /**
  * Updates the records in the skinr_skinsets table based on the files array.
  *
@@ -948,14 +1058,15 @@ function skinr_update_files_database(&$f
   // Add all files that need to be deleted to a DatabaseCondition.
   $delete = db_or();
   foreach ($result as $file) {
-    if (isset($files[$file->name]) && is_object($files[$file->name])) {
+    $entry = _skinr_get_file_by_key($files, $file->machine_name);
+    if (isset($files[$entry]) && is_array($files[$entry])) {
       // Keep the old filename from the database in case the file has moved.
       $old_filename = $file->filename;
 
       $updated_fields = array();
 
       // Handle info specially, compare the serialized value.
-      $serialized_info = serialize($files[$file->name]->info);
+      $serialized_info = serialize($files[$entry]);
       if ($serialized_info != $file->info) {
         $updated_fields['info'] = $serialized_info;
       }
@@ -963,8 +1074,8 @@ function skinr_update_files_database(&$f
 
       // Scan remaining fields to find only the updated values.
       foreach ($file as $key => $value) {
-        if (isset($files[$file->name]->$key) && $files[$file->name]->$key != $value) {
-          $updated_fields[$key] = $files[$file->name]->$key;
+        if (isset($files[$entry][$key]) && $files[$entry][$key] != $value) {
+          $updated_fields[$key] = $files[$entry][$key];
         }
       }
 
@@ -977,7 +1088,7 @@ function skinr_update_files_database(&$f
       }
 
       // Indicate that the file exists already.
-      $files[$file->name]->exists = TRUE;
+      $files[$entry]['exists'] = TRUE;
     }
     else {
       // File is not found in file system, so delete record from the system table.
@@ -993,20 +1104,22 @@ function skinr_update_files_database(&$f
   }
 
   // All remaining files are not in the system table, so we need to add them.
-  $query = db_insert('skinr_skinsets')->fields(array('filename', 'name', 'info'));
-  foreach($files as &$file) {
-    if (isset($file->exists)) {
-      unset($file->exists);
+  $query = db_insert('skinr_skinsets')->fields(array('filename', 'machine_name', 'info'));
+  foreach($files as $machine_name => &$file) {
+    if (isset($file['exists'])) {
+      unset($file['exists']);
     }
     else {
       $query->values(array(
-        'filename' => $file->uri,
-        'name' => $file->name,
-        'info' => serialize($file->info),
+        'filename' => $file['path'] . '/' . $file['file'],
+        'machine_name' => $machine_name,
+        'info' => serialize($file),
+        'status' => 0,
       ));
-      $file->status = 0;
+      $file['status'] = 0;
     }
   }
+  
   $query->execute();
 
   // If any module or theme was moved to a new location, we need to reset the
@@ -1028,19 +1141,20 @@ function skinr_skin_data() {
   $cache = &drupal_static(__FUNCTION__);
 
   if (is_null($cache)) {
-    $skins_skinsets  = skinr_skinsets('skinset');
-    $themes_skinsets = skinr_skinsets('theme');
+    $skinsets = skinr_skinsets();
 
     // Need to merge all skins skinsets into a single list of skins.
     // Also merge in the groups information.
     $additional_skins = array();
     $groups = array();
-    foreach ($skins_skinsets as $key => $skinset) {
-      if (!empty($skinset->skins) && $skinset->status == 1) {
-        $additional_skins += $skinset->skins;
-      }
-      if (!empty($skinset->options['groups'])) {
-        $groups += $skinset->options['groups'];
+    foreach ($skinsets as $key => $skinset) {
+      if ($skinset->type == 'skinset') {
+        if (!empty($skinset->skins) && $skinset->status == 1) {
+          $additional_skins += $skinset->skins;
+        }
+        if (!empty($skinset->options['groups'])) {
+          $groups += $skinset->options['groups'];
+        }
       }
     }
 
@@ -1052,16 +1166,18 @@ function skinr_skin_data() {
         continue;
       }
 
-      if (isset($themes_skinsets[$theme->name])) {
-        $cache[$theme->name] = $themes_skinsets[$theme->name];
+      if (!empty($skinsets[$theme->name])) {
+        $cache[$theme->name] = $skinsets[$theme->name];
         $cache[$theme->name]->skins += $additional_skins;
         $cache[$theme->name]->options['groups'] += $groups;
       }
       else {
-        $cache[$theme->name] = array(
-          'options' => array('groups' => $groups),
-          'skins' => $additional_skins,
-        );
+        $cache[$theme->name] = new StdClass();
+        $cache[$theme->name]->name = $theme->name;
+        $cache[$theme->name]->status = 1;
+        $cache[$theme->name]->type = 'theme';
+        $cache[$theme->name]->skins = $additional_skins;
+        $cache[$theme->name]->options = array('groups' => $groups);
       }
     }
   }
Index: skinr_ui.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/skinr/skinr_ui.admin.inc,v
retrieving revision 1.14
diff -u -p -r1.14 skinr_ui.admin.inc
--- skinr_ui.admin.inc	14 Oct 2010 23:09:30 -0000	1.14
+++ skinr_ui.admin.inc	22 Oct 2010 04:43:50 -0000
@@ -117,6 +117,10 @@ function skinr_ui_filter_form() {
 /**
  * Returns HTML for a skinr administration filter selector.
  *
+ * @todo
+ *   This needs to used theme_exposed_filters(). This code is atrocious and also
+ *   gone from Drupal 7.
+ *
  * @param $variables
  *   An associative array containing:
  *   - form: A render element representing the form.
@@ -139,14 +143,14 @@ function theme_skinr_ui_filters($variabl
 
   if (!empty($form['status']) && count(element_children($form['status']))) {
     $output .= '<dl class="multiselect">' . (!empty($form['current']) ? '<dt><em>' . t('and') . '</em> ' . t('where') . '</dt>' : '');
-  
+
     $output .= '<dd>';
-  
+
     foreach (element_children($form['status']) as $key) {
       $output .= drupal_render($form['status'][$key]);
     }
     $output .= '</dd>';
-  
+
     $output .= '</dl>';
   }
   $output .= drupal_render($form['actions']);
@@ -470,16 +474,15 @@ function skinr_ui_admin_skinsets($form, 
 
   uasort($skinsets, 'skinr_ui_sort_by_info_name');
 
-
   $form['skinsets'] = array('#tree' => TRUE);
-  
+
   // Iterate through each of the skinsets.
-  foreach ($skinsets as $name => $skinset) {
+  foreach ($skinsets as $key => $skinset) {
     $extra = array();
-    $extra['enabled'] = (bool) $skinset->status;
+    $extra['enabled'] = (bool) $skinset['status'];
 
     // Generate link for skinset's configuration page
-    $configure_link = menu_get_item('admin/appearance/skinr/skins/settings/'. $name);
+    $configure_link = menu_get_item('admin/appearance/skinr/skins/settings/'. $key);
     if ($configure_link['access']) {
       $extra['links']['configure'] = array(
         '#type' => 'link',
@@ -490,7 +493,7 @@ function skinr_ui_admin_skinsets($form, 
     }
 
     // Create a row entry for this skinset.
-    $form['skinsets'][$skinset->info['package']][$skinset->name] = _skinr_ui_admin_skinsets_build_row($skinset->info, $extra);
+    $form['skinsets'][$skinset['package']][$key] = _skinr_ui_admin_skinsets_build_row($skinset, $extra);
   }
 
   // Add basic information to the fieldsets.
@@ -537,7 +540,6 @@ function _skinr_ui_admin_skinsets_build_
   $form['screenshot'] = array(
     '#markup' => file_exists($info['screenshot']) ? theme('image', array('path' => $info['screenshot'], 'alt' => t('Screenshot for %theme theme', array('%theme' => $info['name'])), 'attributes' => array('class' => 'screenshot'), 'getsize' => FALSE)) : t('no screenshot'),
   );
-  
   $form['name'] = array(
     '#markup' => $info['name'],
   );
@@ -599,7 +601,7 @@ function _skinr_ui_admin_skinsets_build_
  * Helper function to sort skinsets by the name in their .info file.
  */
 function skinr_ui_sort_by_info_name($a, $b) {
-  return strcasecmp($a->info['name'], $b->info['name']);
+  return strcasecmp($a['name'], $b['name']);
 }
 
 /**
@@ -608,20 +610,20 @@ function skinr_ui_sort_by_info_name($a, 
 function skinr_ui_admin_skinsets_submit($form, &$form_state) {
   // Store list of previously enabled themes and disable all themes.
   $old_skinset_list = $new_skinset_list = array();
-  foreach (skinr_skinsets('skinset') as $skinset) {
+  foreach (skinr_skinsets() as $key => $skinset) {
     if ($skinset->status) {
-      $old_skinset_list[] = $skinset->name;
+      $old_skinset_list[] = $key;
     }
   }
   db_query("UPDATE {skinr_skinsets} SET status = 0");
 
   foreach ($form_state['values']['skinsets'] as $category) {
-    foreach ($category as $name => $choice) {
+    foreach ($category as $machine_name => $choice) {
       if ($choice['enable']) {
-        $new_theme_list[] = $name;
+        $new_theme_list[] = $machine_name;
         db_update('skinr_skinsets')
           ->fields(array('status' => 1))
-          ->condition('name', $name)
+          ->condition('machine_name', $machine_name)
           ->execute();
       }
     }
@@ -725,27 +727,31 @@ function theme_skinr_ui_admin_skinsets_i
 function skinr_ui_admin_skinsets_settings($form, $form_state, $skinset_name) {
   $form = array();
 
-  $skinsets = skinr_skinsets('skinset');
+  $skinsets = skinr_skinsets();
   if (!empty($skinsets[$skinset_name])) {
     $skinset = $skinsets[$skinset_name];
-  
+
     $themes = list_themes();
+    $use_themes = array();
     ksort($themes);
-  
+
     $form['skins'] = array('#tree' => TRUE);
-    
+
     // Iterate through each of the skinsets.
     foreach ($skinset->skins as $name => $skin) {
       foreach ($themes as $theme) {
-        if (!$theme->status) {
+        if (!$theme->status || ($skinset->type == 'theme' && $skinset->name != $theme->name)) {
           continue;
         }
-        
+        $use_themes[$theme->name] = $theme->info['name'];
+
         // Create a row entry for this skinset.
         $form['skins'][$theme->name][$name] = _skinr_ui_admin_skinsets_settings_build_row($skin, $theme->name);
       }
     }
-  
+
+    $form['#themes'] = $use_themes;
+
     // Add basic information to the fieldsets.
     $current_theme = skinr_current_theme(TRUE);
     foreach (element_children($form['skins']) as $theme_name) {
@@ -868,7 +874,6 @@ function theme_skinr_ui_admin_skinsets_s
  * Process skinr_ui_admin_skinsets_settings form submissions.
  */
 function skinr_ui_admin_skinsets_settings_submit($form, &$form_state) {
-  dpm($form_state['values']);
   if ($form_state['values']['op'] == t('Save configuration')) {
     $statuses = array();
     foreach ($form_state['values']['skins'] as $theme => $skins) {
Index: skinr_ui.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/skinr/skinr_ui.module,v
retrieving revision 1.15
diff -u -p -r1.15 skinr_ui.module
--- skinr_ui.module	17 Oct 2010 18:39:12 -0000	1.15
+++ skinr_ui.module	22 Oct 2010 04:43:51 -0000
@@ -69,14 +69,14 @@ function skinr_ui_menu() {
   // @see http://drupal.org/node/320303
   $skinsets = array();
   if (in_array('skinr', module_list())) {
-    $skinsets = skinr_skinsets('skinset');
+    $skinsets = skinr_skinsets();
   }
-  foreach ($skinsets as $skinset) {
-    $items['admin/appearance/skinr/skins/settings/'. $skinset->name] = array(
+  foreach ($skinsets as $key => $skinset) {
+    $items['admin/appearance/skinr/skins/settings/'. $key] = array(
       'title' => $skinset->info['name'],
       'description' => 'Manage which options are available for each Skin when changing Skinr settings.',
       'page callback' => 'drupal_get_form',
-      'page arguments' => array('skinr_ui_admin_skinsets_settings', $skinset->name),
+      'page arguments' => array('skinr_ui_admin_skinsets_settings', $key),
       'access arguments' => array('administer site configuration'),
       'file' => 'skinr_ui.admin.inc',
       'type' => MENU_LOCAL_TASK,
