Index: skinr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/skinr/skinr.module,v
retrieving revision 1.28
diff -u -p -F '^f' -r1.28 skinr.module
--- skinr.module	15 Oct 2010 07:06:17 -0000	1.28
+++ skinr.module	16 Oct 2010 23:04:37 -0000
@@ -404,6 +404,106 @@ function skinr_get_module_apis() {
   return $cache;
 }
 
+/**
+ * Get a list of filenames and location for skins.
+ */
+function skinr_get_skinr_files() {
+  // Find *.skinr.inc files in skins, modules and themes folders.
+  $mask = '/\.skinr.inc$/';
+  $files = drupal_system_listing($mask, 'skins');
+  $files = $files = array_merge($files, drupal_system_listing($mask, 'themes'));
+  $files = $files = array_merge($files, drupal_system_listing($mask, 'modules'));
+
+  // If our filename contains multiple dots in the extension, for example
+  // filename.skinr.inc, we need to fix the name and key.
+  $info = array();
+  foreach ($files as $skinset) {
+    $key = substr($skinset->name, 0, -6);
+    $skinset->name = $key;
+    $info[$key] = $skinset;
+  }
+
+  return $info;
+}
+
+/**
+ * Load all skins.
+ */
+function skinr_load_all_info() {
+  $info = skinr_get_skinr_files();
+
+  $return = array();
+  foreach ($info as $skinset) {
+    if (!empty($skinset)) {
+      $result = skinr_load_info($skinset->name, $skinset);
+      if (isset($result) && is_array($result)) {
+        $return = array_merge_recursive($return, $result);
+      }
+      elseif (isset($result)) {
+        $return[$skinset->name] = $result;
+      }
+    }
+  }
+
+  return $return;
+}
+
+/**
+ * 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->filename)) {
+    require_once $skinset->filename;
+
+    $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 +735,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.
@@ -708,6 +749,7 @@ function _skinr_skinset($info) {
     'skins' => array(),
   );
 
+   // @todo Account for $info->info being an array.
   if (!empty($info->info['skinr'])) {
     $path_root = dirname($info->filename);
 
@@ -731,11 +773,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) {
@@ -776,7 +813,7 @@ function _skinr_skinset($info) {
 }
 
 /**
- * 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 +848,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) {
+function skinr_skinsets() {
   $skinsets = &drupal_static(__FUNCTION__, array('theme' => array(), 'skinset' => 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 $skinset) {
+      if (file_exists($skinset->filename)) {
+        $skinset->info = unserialize($skinset->info);
+        $skinsets[$skinset->name] = $skinset;
       }
     }
 
@@ -853,8 +876,34 @@ 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.
+      // @todo Account for $skinset->info being an array.
+      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'];
@@ -867,7 +916,7 @@ function skinr_skinsets($type) {
     }
   }
 
-  return $skinsets[$type];
+  return $skinsets;
 }
 
 /**
@@ -901,8 +950,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_load_all_info();
   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;
 }
@@ -1028,19 +1089,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 +1114,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 -F '^f' -r1.14 skinr_ui.admin.inc
--- skinr_ui.admin.inc	14 Oct 2010 23:09:30 -0000	1.14
+++ skinr_ui.admin.inc	16 Oct 2010 23:04:37 -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,9 +474,8 @@ 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) {
     $extra = array();
@@ -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'],
   );
@@ -608,7 +610,7 @@ 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 $skinset) {
     if ($skinset->status) {
       $old_skinset_list[] = $skinset->name;
     }
@@ -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.14
diff -u -p -F '^f' -r1.14 skinr_ui.module
--- skinr_ui.module	15 Oct 2010 07:06:17 -0000	1.14
+++ skinr_ui.module	16 Oct 2010 23:04:37 -0000
@@ -60,17 +60,19 @@ function skinr_ui_menu() {
     'parent' => 'admin/appearance/skinr/skins',
     'weight' => -1,
   );
-  foreach (skinr_skinsets('skinset') as $skinset) {
-    $items['admin/appearance/skinr/skins/settings/'. $skinset->name] = 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),
-      'access arguments' => array('administer site configuration'),
-      'file' => 'skinr_ui.admin.inc',
-      'type' => MENU_LOCAL_TASK,
-      'parent' => 'admin/appearance/skinr/skins',
-    );
+  foreach (skinr_skinsets() as $skinset) {
+    if (!empty($skinset->type) && $skinset->type == 'skinset') {
+      $items['admin/appearance/skinr/skins/settings/'. $skinset->name] = 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),
+        'access arguments' => array('administer site configuration'),
+        'file' => 'skinr_ui.admin.inc',
+        'type' => MENU_LOCAL_TASK,
+        'parent' => 'admin/appearance/skinr/skins',
+      );
+    }
   }
 
   // Rules.
