Index: imagecache_profiles.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache_profiles/imagecache_profiles.module,v
retrieving revision 1.5
diff -u -p -r1.5 imagecache_profiles.module
--- imagecache_profiles.module	19 Dec 2008 18:12:56 -0000	1.5
+++ imagecache_profiles.module	20 Dec 2008 00:51:03 -0000
@@ -24,7 +24,7 @@ function imagecache_profiles_help($path,
 function imagecache_profiles_preprocess_user_picture(&$variables) {
   $variables['picture'] = '';
   if (variable_get('user_pictures', 0)) {
-    $account = $variables['account'];    
+    $account = $variables['account'];
     // Determine imagecache preset to use for user profile picture
     // First let's determine if we have a default imagecache preset
     if (variable_get('user_picture_imagecache_profiles_default', 0)) {
@@ -43,7 +43,12 @@ function imagecache_profiles_preprocess_
         $size = variable_get('user_picture_imagecache_comments', 0);
       }
     }
-    
+
+    // If views set an imagecache preset
+    if ($account->imagecache_preset) {
+    	$size = $account->imagecache_preset;
+    }
+
     if (!empty($account->picture) && file_exists($account->picture)) {
       $picture = $account->picture;
     }
@@ -53,11 +58,12 @@ function imagecache_profiles_preprocess_
 
     if (isset($picture)) {
       $alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous'))));
-      if (isset($size)) {
-        $variables['picture'] = theme('imagecache', $size, $picture, $alt, $alt);
-      } else {
+      $preset = imagecache_preset($size);
+      if (empty($preset)) {
         $variables['picture'] = theme('image', $picture, $alt, $alt, '', FALSE);
-      }      
+      } else {
+        $variables['picture'] = theme('imagecache', $preset['presetname'], $picture, $alt, $alt);
+      }
       if (!empty($account->uid) && user_access('access user profiles')) {
         $attributes = array('attributes' => array('title' => t('View user profile.')), 'html' => TRUE);
         $variables['picture'] = l($variables['picture'], "user/$account->uid", $attributes);
@@ -69,21 +75,20 @@ function imagecache_profiles_preprocess_
 /**
  * Implementation of hook_form_alter().
  */
-function imagecache_profiles_form_alter(&$form, $form_state, $form_id) {  
+function imagecache_profiles_form_alter(&$form, $form_state, $form_id) {
   switch($form_id) {
     case 'user_profile_form':
       $form['#validate'][] = 'imagecache_profiles_user_profile_form_validate';
       break;
-      
+
     case 'user_admin_settings':
       // Load imagecache presets
-      $result = db_query('SELECT presetid, presetname FROM {imagecache_preset} ORDER BY presetname');
       $presets = array();
       $presets[] = '';
-      while ($data = db_fetch_object($result)) {
-        $presets[check_plain($data->presetname)] = check_plain($data->presetname);
+      foreach (imagecache_presets() as $key => $preset) {
+      	$presets[$key] = check_plain($preset['presetname']);
       }
-      
+
       $form['pictures']['settings']['user_picture_imagecache_profiles'] = array(
         '#type' => 'select',
         '#title' => t('Profile picture preset'),
@@ -91,7 +96,7 @@ function imagecache_profiles_form_alter(
         '#options' => $presets,
         '#description' => t("This will set the picture size when viewing a user's profile page."),
       );
-      
+
       $form['pictures']['settings']['user_picture_imagecache_comments'] = array(
         '#type' => 'select',
         '#title' => t('Comment picture preset'),
@@ -99,7 +104,7 @@ function imagecache_profiles_form_alter(
         '#options' => $presets,
         '#description' => t("This will set the picture size when viewing a comment post."),
       );
-      
+
       $form['pictures']['settings']['user_picture_imagecache_profiles_default'] = array(
         '#type' => 'select',
         '#title' => t('Default picture preset'),
@@ -107,7 +112,7 @@ function imagecache_profiles_form_alter(
         '#options' => $presets,
         '#description' => t('This will set the default user picture size throughout the site.'),
       );
-      
+
       $form['pictures']['settings']['user_picture_imagecache_profiles_min_width'] = array(
         '#type' => 'textfield',
         '#title' => t('Picture minimum width'),
@@ -115,7 +120,7 @@ function imagecache_profiles_form_alter(
         '#description' => t('Minimum width dimension for picture, in pixels. To prevent upscaling this value should be set to your maximum imagecache preset width.'),
         '#size' => 10,
       );
-      
+
       $form['pictures']['settings']['user_picture_imagecache_profiles_min_height'] = array(
         '#type' => 'textfield',
         '#title' => t('Picture minimum height'),
@@ -123,14 +128,14 @@ function imagecache_profiles_form_alter(
         '#description' => t('Minimum height dimension for picture, in pixels. To prevent upscaling this value should be set to your maximum imagecache preset height.'),
         '#size' => 10,
       );
-      
+
       break;
   }
 }
 
 /*
  * Custom form validation callback.
- * 
+ *
  * @todo: Investigage validate $op of hook_user()
  * as this is not working correctly for the user_profile_form.
  * See - http://drupal.org/node/239676
@@ -146,11 +151,11 @@ function imagecache_profiles_user_profil
 
 /*
  * Implements hook_user()
- * 
+ *
  * Flush imagecache picture if user is updating their
  * account picture.
  */
-function imagecache_profiles_user($op, &$edit, &$account, $category = NULL) {  
+function imagecache_profiles_user($op, &$edit, &$account, $category = NULL) {
   if ($op == 'submit' && $category == 'account') {
     if ($edit['picture_delete']) {
       imagecache_image_flush($account->picture);
@@ -159,4 +164,10 @@ function imagecache_profiles_user($op, &
       imagecache_image_flush($edit['picture']);
     }
   }
-}
\ No newline at end of file
+}
+function imagecache_profiles_views_api() {
+  return array(
+    'api' => 2,
+    'path' => drupal_get_path('module', 'imagecache_profiles') .'/views',
+  );
+}
