| 6 user.module | template_preprocess_user_picture(&$variables) |
| 7 user.module | template_preprocess_user_picture(&$variables) |
| 8 user.module | template_preprocess_user_picture(&$variables) |
Process variables for user-picture.tpl.php.
The $variables array contains the following arguments:
- $account
See also
File
- modules/
user/ user.module, line 826 - Enables the user registration and login system.
Code
function template_preprocess_user_picture(&$variables) {
$variables['picture'] = '';
if (variable_get('user_pictures', 0)) {
$account = $variables['account'];
if (!empty($account->picture) && file_exists($account->picture)) {
$picture = file_create_url($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'))));
$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);
}
}
}
}
Login or register to post comments
Comments
Print image without link..
It would be cool if there were an option to prevent all user image pictures as being links to the user profile page (especially the image on the user profile page, which ends up as a link to itself...)
Here's how to get rid of the link in template.php:
<?php
/**
* don't link images to profile
*/
function [YOUR THEME NAME]_preprocess_user_picture(&$variables) {
$variables['picture'] = '';
if (variable_get('user_pictures', 0)) {
$account = $variables['account'];
if (!empty($account->picture) && file_exists($account->picture)) {
$picture = file_create_url($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'))));
$variables['picture'] = theme('image', $picture, $alt, $alt, '', FALSE);
}
}
}
?>
If you have the imagecache profiles module (http://drupal.org/project/imagecache_profiles)
It would be more like this:
<?php
/**
* don't link images to profile
*/
function [YOUR THEME NAME]_preprocess_user_picture(&$variables) {
$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)) {
// Define default user picture size
$size = variable_get('user_picture_imagecache_profiles_default', 0);
}
// If on user profile page.
if (arg(0) == 'user') {
// 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 (variable_get('user_picture_imagecache_profiles', 0)) {
$size = variable_get('user_picture_imagecache_profiles', 0);
}
}
}
}
// If viewing a comment
if (is_object($account) && array_key_exists('cid', get_object_vars($account))) {
if (variable_get('user_picture_imagecache_comments', 0)) {
$size = variable_get('user_picture_imagecache_comments', 0);
}
}
// If views set an imagecache preset
if (isset($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 = is_numeric($size) ? imagecache_preset($size) : imagecache_preset_by_name($size);
if (empty($preset)) {
$variables['picture'] = $default; //theme('image', $picture, $alt, $alt, '', FALSE);
}
else {
$variables['picture'] = theme('imagecache', $preset['presetname'], $picture, $alt, $alt);
}
}
}
?>