Index: skinr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/skinr/skinr.module,v
retrieving revision 1.42
diff -u -p -r1.42 skinr.module
--- skinr.module	16 Jan 2011 19:13:32 -0000	1.42
+++ skinr.module	25 Jan 2011 17:45:22 -0000
@@ -692,20 +692,19 @@ function skinr_skin_delete_multiple($arg
 }
 
 /**
- * Retrieves the desired skinr object.
+ * Retrieves a stored skin from the database.
  *
  * @param $theme
- *   The theme these settings apply to. If no theme name is provided, the
- *   current theme will be used.
+ *   The theme of the skin. Defaults to the current theme.
  * @param $module
- *   The module these settings apply to.
+ *   The module of the skin.
  * @param $sid
- *   The element ID these settings apply to.
+ *   The element ID of the skin.
  *
  * @return
- *   A skin object if both $module and $sid are specified. An array of skin
- *   objects if only $module is specified. An array of all skin objects for a
- *   theme if neither $module nor $sid is specified. FALSE on failure.
+ *   A skin object if both $module and $sid are specified. An array of skins
+ *   if only $module is specified. An array of all skins for a theme if neither
+ *   $module nor $sid is specified. FALSE on failure.
  *
  * @todo Rename $skin->skins to $skin->options throughout the module.
  */
@@ -716,55 +715,44 @@ function skinr_skin_load($theme = NULL, 
     $theme = skinr_current_theme();
   }
 
+  // @todo This condition is always FALSE when no $sid is passed.
   if (!isset($skins[$theme][$module][$sid])) {
-    if (!isset($skins[$theme])) {
-      $skins[$theme] = array();
-    }
-    if (isset($module) && !isset($skins[$theme][$module])) {
-      $skins[$theme][$module] = array();
+    $skins += array($theme => array());
+    if (isset($module)) {
+      $skins[$theme] += array($module => array());
     }
 
-    if (isset($module) && isset($sid)) {
-      // Fetch just this sid.
-      $result = db_query("SELECT theme, module, sid, settings, skins FROM {skinr} WHERE theme = :theme AND module = :module AND sid = :sid", array(
-        ':theme' => $theme,
-        ':module' => $module,
-        ':sid' => $sid,
-      ));
-    }
-    elseif (isset($module)) {
-      // Fetch all settings for this theme and module.
-      $result = db_query("SELECT theme, module, sid, settings, skins FROM {skinr} WHERE theme = :theme AND module = :module", array(
-        ':theme' => $theme,
-        ':module' => $module,
-      ));
+    $query = db_select('skinr', 's')
+      ->fields('s', array('theme', 'module', 'sid', 'settings', 'skins'));
+    if (isset($theme)) {
+      $query->condition('theme', $theme);
     }
-    else {
-      // Fetch all settings for this theme.
-      $result = db_query("SELECT theme, module, sid, settings, skins FROM {skinr} WHERE theme = :theme", array(
-        ':theme' => $theme,
-      ));
+    if (isset($module)) {
+      $query->condition('module', $module);
     }
-
-    foreach ($result as $skin) {
+    if (isset($sid)) {
+      $query->condition('sid', $sid);
+    }
+    foreach ($query->execute() as $skin) {
       $skin->settings = unserialize($skin->settings);
       $skin->skins = unserialize($skin->skins);
       $skins[$skin->theme][$skin->module][$skin->sid] = $skin;
     }
   }
 
-  if (!isset($sid) && isset($module)) {
-    // Return all the skinrs for the theme.
+  // Return all skins for the passed theme.
+  if (!isset($module) && !isset($sid)) {
     if (isset($skins[$theme])) {
       return $skins[$theme];
     }
   }
+  // Return all skins for the passed module.
   elseif (!isset($sid)) {
-    // Return all the skinrs for the module.
     if (isset($skins[$theme][$module])) {
       return $skins[$theme][$module];
     }
   }
+  // Return the requested skin.
   elseif (isset($skins[$theme][$module][$sid])) {
     return $skins[$theme][$module][$sid];
   }
