views_handler_field_user_picture_bare.inc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * @file
  4. * User Stats non-themed user picture.
  5. */
  6. /**
  7. * Bare user picture handler.
  8. */
  9. class views_handler_field_user_picture_bare extends views_handler_field_user_picture {
  10. function render($values) {
  11. if (module_exists('image')) {
  12. $output = '';
  13. // When an image style is not defined, use the image style from the account settings.
  14. $style_name = $this->options['image_style'];
  15. if (empty($style_name)) {
  16. $style_name = variable_get('user_picture_style', '');
  17. }
  18. // Load the picture file and get the uri.
  19. if ($user_picture_fid = $this->get_value($values)) {
  20. $user_picture = file_load($user_picture_fid);
  21. $user_picture_filepath = $user_picture->uri;
  22. } else {
  23. $user_picture_filepath = variable_get('user_picture_default', '');
  24. }
  25. // Return empty string when either style_name or picture are unavailable.
  26. if (empty($style_name) || empty($user_picture_filepath)) {
  27. return $output;
  28. }
  29. // Use the user name for alt attribute.
  30. $user_name = $values->{$this->aliases['name']} ? $values->{$this->aliases['name']} : variable_get('anonymous', t('Anonymous'));
  31. $alt = t("@user's picture", array('@user' => $user_name));
  32. // Output the picture with image_style.
  33. if (file_valid_uri($user_picture_filepath)) {
  34. $output = theme('image_style', array('style_name' => $style_name,'path' => $user_picture_filepath, 'alt' => $alt));
  35. }
  36. // Wrap the picture in a link to the user picture.
  37. if ($this->options['link_photo_to_profile'] && user_access('access user profiles')) {
  38. $uid = $this->get_value($values, 'uid');
  39. $output = l($output, "user/$uid", array('html' => TRUE));
  40. }
  41. return $output;
  42. }
  43. }
  44. }