view.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * View an avatar
  4. */
  5. // page owner library sets this based on URL
  6. $user = elgg_get_page_owner_entity();
  7. // Get the size
  8. $size = strtolower(get_input('size'));
  9. if (!in_array($size, array('master', 'large', 'medium', 'small', 'tiny', 'topbar'))) {
  10. $size = 'medium';
  11. }
  12. // If user doesn't exist, return default icon
  13. if (!$user) {
  14. $url = "_graphics/icons/default/{$size}.png";
  15. $url = elgg_normalize_url($url);
  16. forward($url);
  17. }
  18. $user_guid = $user->getGUID();
  19. // Try and get the icon
  20. $filehandler = new ElggFile();
  21. $filehandler->owner_guid = $user_guid;
  22. $filehandler->setFilename("profile/{$user_guid}{$size}.jpg");
  23. $success = false;
  24. try {
  25. if ($filehandler->open("read")) {
  26. if ($contents = $filehandler->read($filehandler->getSize())) {
  27. $success = true;
  28. }
  29. }
  30. } catch (InvalidParameterException $e) {
  31. elgg_log("Unable to get avatar for user with GUID $user_guid", 'ERROR');
  32. }
  33. if (!$success) {
  34. $url = "_graphics/icons/default/{$size}.png";
  35. $url = elgg_normalize_url($url);
  36. forward($url);
  37. }
  38. header("Content-type: image/jpeg", true);
  39. header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true);
  40. header("Pragma: public", true);
  41. header("Cache-Control: public", true);
  42. header("Content-Length: " . strlen($contents));
  43. echo $contents;