cid) { if (variable_get('user_picture_imagecache_comments', 0)) { $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; } else if (variable_get('user_picture_default', '')) { $picture = variable_get('user_picture_default', ''); } if (isset($picture)) { $alt = t("@user's picture", array('@user' => $account->name ? $account->name : variable_get('anonymous', t('Anonymous')))); $preset = imagecache_preset($size); if (empty($preset)) { $variables['picture'] = $default;//theme('image', $picture, $alt, $alt, '', FALSE); } else { $variables['picture'] = theme('image', $picture, $alt, $alt, '', FALSE); } 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); } } } } /** * Implementation of hook_form_alter(). */ 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); } $form['pictures']['settings']['user_picture_imagecache_profiles'] = array( '#type' => 'select', '#title' => t('Profile picture preset'), '#default_value' => variable_get('user_picture_imagecache_profiles', ''), '#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'), '#default_value' => variable_get('user_picture_imagecache_comments', ''), '#options' => $presets, '#description' => t("This will set the picture size when viewing a comment post."), ); $form['pictures']['settings']['user_picture_imagecache_tiny'] = array( '#type' => 'select', '#title' => t('Tiny picture preset'), '#default_value' => variable_get('user_picture_imagecache_middle', ''), '#options' => $presets, '#description' => t('This will set the tiny user picture size throughout the site.'), ); $form['pictures']['settings']['user_picture_imagecache_profiles_default'] = array( '#type' => 'select', '#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.'), ); $form['pictures']['settings']['user_picture_imagecache_profiles_min_width'] = array( '#type' => 'textfield', '#title' => t('Picture minimum width'), '#default_value' => variable_get('user_picture_imagecache_profiles_min_width', ''), '#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'), '#default_value' => variable_get('user_picture_imagecache_profiles_min_height', ''), '#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 */ function imagecache_profiles_user_profile_form_validate($form, &$form_state) { if (isset($form_state['values']['picture'])) { $image_info = image_get_info($form_state['values']['picture']); if ($image_info['width'] < variable_get('user_picture_imagecache_profiles_min_width', 0) || $image_info['height'] < variable_get('user_picture_imagecache_profiles_min_height', 0)) { form_set_error('picture_upload', t('Your picture must be at least @min_user_picture_width pixels wide and @min_user_picture_height pixels tall (your image was @width x @height pixels).', array('@min_user_picture_width' => variable_get('user_picture_imagecache_profiles_min_width', 0), '@min_user_picture_height' => variable_get('user_picture_imagecache_profiles_min_height', 0), '@width' => $image_info['width'], '@height' => $image_info['height']))); } } } /* * Implements hook_user() * * Flush imagecache picture if user is updating their * account picture. */ function imagecache_profiles_user($op, &$edit, &$account, $category = NULL) { if ($op == 'submit' && $category == 'account') { if ($edit['picture_delete']) { imagecache_image_flush($account->picture); } if (isset($edit['picture'])) { imagecache_image_flush($edit['picture']); } } }