function gravatar_preprocess_user_picture in Gravatar integration 7
Same name and namespace in other branches
- 6 gravatar.module \gravatar_preprocess_user_picture()
Override template_preprocess_user_picture() to display user pictures with Gravatar integration.
See also
template_preprocess_user_picture()
_gravatar_get_account_user_picture()
1 call to gravatar_preprocess_user_picture()
File
- ./
gravatar.module, line 127 - Integrates gravatar service for user pictures.
Code
function gravatar_preprocess_user_picture(&$variables) {
$variables['user_picture'] = '';
if (variable_get('user_pictures', 0)) {
// Load the full user object since it is not provided with nodes, comments,
// or views displays.
$account = _gravatar_load_account($variables['account']);
$filepath = _gravatar_get_account_user_picture($account);
if (!empty($filepath)) {
$alt = t("@user's picture", array(
'@user' => format_username($account),
));
if (module_exists('image') && file_valid_uri($filepath) && ($style = variable_get('user_picture_style', ''))) {
$variables['user_picture'] = theme('image_style', array(
'style_name' => $style,
'path' => $filepath,
'alt' => $alt,
'title' => $alt,
));
}
else {
$variables['user_picture'] = theme('image', array(
'path' => $filepath,
'alt' => $alt,
'title' => $alt,
));
}
if ($account->uid && user_access('access user profiles')) {
// Create link to the user's profile.
$attributes = array(
'title' => t('View user profile.'),
);
$variables['user_picture'] = l($variables['user_picture'], 'user/' . $account->uid, array(
'attributes' => $attributes,
'html' => TRUE,
));
}
elseif (!empty($account->homepage)) {
// If user is anonymous, create link to the commenter's homepage.
$attributes = array(
'title' => t('View user website.'),
'rel' => 'external nofollow',
);
$variables['user_picture'] = l($variables['user_picture'], $account->homepage, array(
'attributes' => $attributes,
'html' => TRUE,
));
}
}
}
}