View source
<?php
function imagecache_profiles_help($path, $arg) {
switch ($path) {
case 'admin/help#imagecache_profiles':
return t('Utilizes image styles for user profile pictures.');
}
}
function imagecache_profiles_preprocess_user_picture(&$variables) {
if (variable_get('user_pictures', 0)) {
$account = $variables['account'];
if (!empty($account->picture)) {
if (is_numeric($account->picture)) {
$account->picture = file_load($account->picture);
}
if (!empty($account->picture->uri)) {
$filepath = $account->picture->uri;
}
}
elseif (variable_get('user_picture_default', '')) {
$filepath = variable_get('user_picture_default', '');
}
if (isset($variables['user_picture_style'])) {
$style = $variables['user_picture_style'];
}
elseif (isset($account->picture->style_name)) {
$style = $account->picture->style_name;
}
elseif (isset($account->user_picture_style)) {
$style = $account->user_picture_style;
}
if (isset($filepath) && file_valid_uri($filepath) && !empty($style) && $style != variable_get('user_picture_style', '')) {
$alt = t("@user's picture", array(
'@user' => format_username($account),
));
$variables['user_picture'] = theme('image_style', array(
'style_name' => $style,
'path' => $filepath,
'alt' => $alt,
'title' => $alt,
));
if (!empty($account->uid) && user_access('access user profiles')) {
$attributes = array(
'attributes' => array(
'title' => t('View user profile.'),
),
'html' => TRUE,
);
$variables['user_picture'] = l($variables['user_picture'], "user/{$account->uid}", $attributes);
}
}
}
}
function imagecache_profiles_form_user_admin_settings_alter(&$form, $form_state) {
$presets = image_style_options(TRUE);
$form['personalization']['pictures']['settings']['user_picture_style_profiles'] = array(
'#type' => 'select',
'#title' => t('Profile picture display style'),
'#default_value' => variable_get('user_picture_style_profiles', ''),
'#options' => $presets,
'#description' => t("This will set the picture size when viewing a user's profile page."),
);
$form['personalization']['pictures']['settings']['user_picture_style_comments'] = array(
'#type' => 'select',
'#title' => t('Comment picture display style'),
'#default_value' => variable_get('user_picture_style_comments', ''),
'#options' => $presets,
'#description' => t("This will set the picture size when viewing a comment post."),
);
$form['personalization']['pictures']['settings']['user_picture_style_nodes'] = array(
'#type' => 'select',
'#title' => t('Node picture display style'),
'#default_value' => variable_get('user_picture_style_nodes', ''),
'#options' => $presets,
'#description' => t("This will set the picture size when viewing a node post."),
);
$form['personalization']['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['personalization']['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,
);
}
function imagecache_profiles_file_validate($file) {
if (!empty($file->source) && $file->source == 'picture_upload') {
$width = variable_get('user_picture_imagecache_profiles_min_width', 0);
$height = variable_get('user_picture_imagecache_profiles_min_height', 0);
$minimum_dimensions = $width . 'x' . $height;
return file_validate_image_resolution($file, 0, $minimum_dimensions);
}
}
function imagecache_profiles_image_style_delete($style) {
imagecache_profiles_image_style_save($style);
}
function imagecache_profiles_image_style_save($style) {
if (isset($style['old_name'])) {
$vars = array(
'user_picture_style_profiles',
'user_picture_style_comments',
'user_picture_style_nodes',
);
foreach ($vars as $var) {
if ($style['old_name'] == variable_get($var)) {
variable_set($var, $style['name']);
}
}
}
}
function imagecache_profiles_user_view_alter(&$build) {
if (isset($build['user_picture']['#markup']) && ($style = variable_get('user_picture_style_profiles', ''))) {
$picture = theme('user_picture', array(
'account' => $build['#account'],
'user_picture_style' => $style,
));
$build['user_picture']['#markup'] = $picture;
}
}
function imagecache_profiles_comment_view($comment) {
if (theme_get_setting('toggle_comment_user_picture')) {
if (!empty($comment->uid) && !isset($comment->picture)) {
$comment->picture = db_query("SELECT picture FROM {users} WHERE uid = :uid", array(
':uid' => $comment->uid,
))
->fetchField();
}
if ($style = variable_get('user_picture_style_comments', '')) {
$comment->user_picture_style = $style;
}
}
}
function imagecache_profiles_node_view($node, $view_mode) {
if ($style = variable_get('user_picture_style_nodes', '')) {
$node->user_picture_style = $style;
}
}
function imagecache_profiles_views_api() {
return array(
'api' => 2,
);
}
function imagecache_profiles_views_data_alter(&$data) {
$data['users']['picture']['field']['handler'] = 'imagecache_profiles_handler_field_user_picture';
}