--- W:/ClearlyByDesign/Drupal/modules/6.x/Imaging Modules/imagecache_profiles/6.x-1.x-dev 2010-Mar-31/imagecache_profiles/imagecache_profiles.module Thu Mar 25 06:58:23 2010 +++ W:/ClearlyByDesign/Drupal/modules/6.x/Imaging Modules/imagecache_profiles/6.x-1.3/imagecache_profiles/imagecache_profiles.module Thu Apr 29 19:13:40 2010 @@ -26,6 +26,7 @@ $default = $variables['picture']; if (variable_get('user_pictures', 0)) { $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)) { @@ -37,7 +38,12 @@ // Only show profile image for profile page, and edit account form, // not user/123/relationships or other module define pages. if (arg(2) == NULL || arg(2) == 'edit') { - if (is_numeric(arg(1)) || (module_exists('me') && arg(1) == me_variable_get('me_alias'))) { + if ( ( is_numeric( arg( 1 ) ) || + ( module_exists( 'me' ) && arg( 1 ) == me_variable_get( 'me_alias' ) ) ) && + // and make sure we're looking at the profile picture, and not + // some other user pic on the page, such as in an avatar block + // on the side. + $account->profile_picture ) { if (variable_get('user_picture_imagecache_profiles', 0)) { $size = variable_get('user_picture_imagecache_profiles', 0); } @@ -51,6 +57,13 @@ } } + // If viewing a post + if (is_object($account) && array_key_exists('nid', get_object_vars($account))) { + if (variable_get('user_picture_imagecache_nodes', 0)) { + $size = variable_get('user_picture_imagecache_nodes', 0); + } + } + // If views set an imagecache preset if (isset($account->imagecache_preset)) { $size = $account->imagecache_preset; @@ -103,6 +116,14 @@ '#description' => t("This will set the picture size when viewing a user's profile page."), ); + $form['pictures']['settings']['user_picture_imagecache_nodes'] = array( + '#type' => 'select', + '#title' => t('Node picture preset'), + '#default_value' => variable_get('user_picture_imagecache_nodes', ''), + '#options' => $presets, + '#description' => t("This will set the picture size when viewing a node post."), + ); + $form['pictures']['settings']['user_picture_imagecache_comments'] = array( '#type' => 'select', '#title' => t('Comment picture preset'), @@ -116,7 +137,9 @@ '#title' => t('Default picture preset'), '#default_value' => variable_get('user_picture_imagecache_profiles_default', ''), '#options' => $presets, - '#description' => t('This will set the default user picture size throughout the site.'), + '#description' => t('This will set the default user picture size throughout the site. + This will apply to user pictures that do not appear in profile, on nodes, + or on comments, such as the user pictures shown in a block.'), ); $form['pictures']['settings']['user_picture_imagecache_profiles_min_width'] = array( @@ -184,6 +207,7 @@ function _imagecache_profiles_change_variables($preset, $delete = FALSE) { $vars = array( 'user_picture_imagecache_profiles' => t('Profile picture preset'), + 'user_picture_imagecache_nodes' => t('Node picture preset'), 'user_picture_imagecache_comments' => t('Comment picture preset'), 'user_picture_imagecache_profiles_default' => t('Default picture preset'), ); @@ -239,6 +263,13 @@ $form['picture']['picture_upload']['#description'] .= ' ' . $description; } $form['#validate'][] = 'imagecache_profiles_user_profile_form_validate'; + + // Reset the user picture as we're editing the profile, so need the larger + // profile picture. See http://drupal.org/node/760900 for more details. + $form['picture']['current_picture'] = array( + '#value' => theme('user_picture', $form['_account']['#value']), + ); + } /** @@ -261,8 +292,17 @@ * Implements hook_user(). * * Flush imagecache picture if user is updating their account picture. + * + * If user is viewing or editing a profile, set an attribute in the $account + * structure to note it for use in the imagecache_profile_preprocess_user_picture + * function. */ function imagecache_profiles_user($op, &$edit, &$account, $category = NULL) { + + if ( $account->uid > 0 ) { + $account->profile_picture = FALSE; + } + if ($op == 'submit' && $category == 'account') { if ($edit['picture_delete']) { imagecache_image_flush($account->picture); @@ -274,6 +314,12 @@ elseif ($op == 'delete' && isset($account->picture)) { imagecache_image_flush($account->picture); } + elseif ( $op == 'view' || $op == 'form' && $category == 'account' ) { + // We're about to view or edit a profile, so we must be dealing with + // a profile picutre here. See http://drupal.org/node/760900 for more details. + $account->profile_picture = TRUE; + } + } /** @@ -284,4 +330,20 @@ 'api' => 2, 'path' => drupal_get_path('module', 'imagecache_profiles') .'/views', ); +} + +/** + * Implements hook_profile_alter(). + * + * Rethemes the user picture upon viewing the profile so that it is the + * correct size per the preset. See http://drupal.org/node/760900 for more. + */ + +function imagecache_profiles_profile_alter( &$account ) { + if ( $account->profile_picture ) { + $account->content['user_picture'] = array( + '#value' => theme('user_picture', $account), + '#weight' => -10, + ); + } }