default.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * Elgg user icon
  4. *
  5. * Rounded avatar corners - CSS3 method
  6. * uses avatar as background image so we can clip it with border-radius in supported browsers
  7. *
  8. * @uses $vars['entity'] The user entity. If none specified, the current user is assumed.
  9. * @uses $vars['size'] The size - tiny, small, medium or large. (medium)
  10. * @uses $vars['use_hover'] Display the hover menu? (true)
  11. * @uses $vars['use_link'] Wrap a link around image? (true)
  12. * @uses $vars['class'] Optional class added to the .elgg-avatar div
  13. * @uses $vars['img_class'] Optional CSS class added to img
  14. * @uses $vars['link_class'] Optional CSS class for the link
  15. * @uses $vars['href'] Optional override of the link href
  16. */
  17. $user = elgg_extract('entity', $vars, elgg_get_logged_in_user_entity());
  18. $size = elgg_extract('size', $vars, 'medium');
  19. $icon_sizes = elgg_get_config('icon_sizes');
  20. if (!array_key_exists($size, $icon_sizes)) {
  21. $size = 'medium';
  22. }
  23. if (!($user instanceof ElggUser)) {
  24. return;
  25. }
  26. $name = htmlspecialchars($user->name, ENT_QUOTES, 'UTF-8', false);
  27. $username = $user->username;
  28. $class = "elgg-avatar elgg-avatar-$size";
  29. if (isset($vars['class'])) {
  30. $class = "$class {$vars['class']}";
  31. }
  32. if ($user->isBanned()) {
  33. $class .= ' elgg-state-banned';
  34. $banned_text = elgg_echo('banned');
  35. $name .= " ($banned_text)";
  36. }
  37. $use_link = elgg_extract('use_link', $vars, true);
  38. $icontime = $user->icontime;
  39. if (!$icontime) {
  40. $icontime = "default";
  41. }
  42. $js = elgg_extract('js', $vars, '');
  43. if ($js) {
  44. elgg_deprecated_notice("Passing 'js' to icon views is deprecated.", 1.8, 5);
  45. }
  46. $img_class = '';
  47. if (isset($vars['img_class'])) {
  48. $img_class = $vars['img_class'];
  49. }
  50. $use_hover = elgg_extract('use_hover', $vars, true);
  51. if (isset($vars['override'])) {
  52. elgg_deprecated_notice("Use 'use_hover' rather than 'override' with user avatars", 1.8, 5);
  53. $use_hover = false;
  54. }
  55. if (isset($vars['hover'])) {
  56. // only 1.8.0 was released with 'hover' as the key
  57. $use_hover = $vars['hover'];
  58. }
  59. $icon = elgg_view('output/img', array(
  60. 'src' => $user->getIconURL($size),
  61. 'alt' => $name,
  62. 'title' => $name,
  63. 'class' => $img_class,
  64. ));
  65. $show_menu = $use_hover && (elgg_is_admin_logged_in() || !$user->isBanned());
  66. ?>
  67. <div class="<?php echo $class; ?>">
  68. <?php
  69. if ($show_menu) {
  70. $params = array(
  71. 'entity' => $user,
  72. 'username' => $username,
  73. 'name' => $name,
  74. );
  75. echo elgg_view_icon('hover-menu');
  76. echo elgg_view('navigation/menu/user_hover/placeholder', array('entity' => $user));
  77. }
  78. if ($use_link) {
  79. $class = elgg_extract('link_class', $vars, '');
  80. $url = elgg_extract('href', $vars, $user->getURL());
  81. echo elgg_view('output/url', array(
  82. 'href' => $url,
  83. 'text' => $icon,
  84. 'is_trusted' => true,
  85. 'class' => $class,
  86. ));
  87. } else {
  88. echo "<a>$icon</a>";
  89. }
  90. ?>
  91. </div>