You are here

function imagecache_profiles_preprocess_user_picture in ImageCache Profiles 7

Same name and namespace in other branches
  1. 6 imagecache_profiles.module \imagecache_profiles_preprocess_user_picture()

Overrides process variables for user-picture.tpl.php

originally built by template_preprocess_user_picture() locate in core user.module.

The $variables array contains the following arguments:

  • $account

See also

user-picture.tpl.php

File

./imagecache_profiles.module, line 24

Code

function imagecache_profiles_preprocess_user_picture(&$variables) {
  if (variable_get('user_pictures', 0)) {
    $account = $variables['account'];
    if (!empty($account->picture)) {

      // @TODO: Ideally this function would only be passed file objects, but
      // since there's a lot of legacy code that JOINs the {users} table to
      // {node} or {comments} and passes the results into this function if we
      // a numeric value in the picture field we'll assume it's a file id
      // and load it for them. Once we've got user_load_multiple() and
      // comment_load_multiple() functions the user module will be able to load
      // the picture files in mass during the object's load process.
      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);
      }
    }
  }
}