Elgg  Version master
default.php
Go to the documentation of this file.
1 <?php
19 $size = elgg_extract('size', $vars, 'medium');
20 
21 if (!($user instanceof ElggUser)) {
22  return;
23 }
24 
26 if (!array_key_exists($size, $icon_sizes)) {
27  $size = 'medium';
28 }
29 
30 $name = htmlspecialchars($user->getDisplayName() ?? '', ENT_QUOTES, 'UTF-8', false);
31 
33  'elgg-avatar',
34  "elgg-avatar-$size",
35 ];
37 
38 if ($user->isBanned()) {
39  $wrapper_class[] = 'elgg-state-banned';
40  $name .= ' (' . elgg_echo('banned') . ')';
41 } elseif ($user->isValidated() === false) {
42  $wrapper_class[] = 'elgg-state-banned';
43  $name .= ' (' . elgg_echo('unvalidated') . ')';
44 }
45 
46 $icon = elgg_view('output/img', [
47  'src' => $user->getIconURL($size),
48  'alt' => $name,
49  'title' => $name,
50  'class' => elgg_extract_class($vars, [], 'img_class'),
51 ]);
52 
53 if (empty($icon)) {
54  return;
55 }
56 
57 $show_menu = elgg_extract('use_hover', $vars, true) && (elgg_is_admin_logged_in() || !$user->isBanned());
58 
59 $content = '';
60 
61 if ($show_menu) {
62  $content .= elgg_view('navigation/menu/user_hover/placeholder', ['entity' => $user]);
63 
64  $wrapper_class[] = 'elgg-avatar-menu';
65 
66  elgg_require_js('icon/user/default');
67 }
68 
69 if (elgg_extract('use_link', $vars, true)) {
70  $content .= elgg_view('output/url', [
71  'href' => elgg_extract('href', $vars, $user->getURL()),
72  'text' => $icon,
73  'is_trusted' => true,
74  'class' => elgg_extract_class($vars, [], 'link_class'),
75  ]);
76 } else {
77  $content .= elgg_format_element('a', [], $icon);
78 }
79 
80 echo elgg_format_element('div', ['class' => $wrapper_class], $content);
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
$wrapper_class
Definition: default.php:32
elgg_get_icon_sizes(string $entity_type=null, string $entity_subtype=null, $type= 'icon')
Returns a configuration array of icon sizes.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
$content
Definition: default.php:59
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:276
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:177
if(empty($icon)) $show_menu
Definition: default.php:57
if(!array_key_exists($size, $icon_sizes)) $vars['size']
Definition: default.php:25
if(!$entity instanceof ElggEntity) $icon_sizes
Definition: default.php:18
$size
Definition: default.php:20
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:130
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24
elgg_require_js(string $name)
Request that Elgg load an AMD module onto the page.
if(!array_key_exists($size, $icon_sizes)) $name
Definition: default.php:30
$user
Elgg user icon.
Definition: default.php:18
if($user->isBanned()) elseif($user->isValidated()===false) $icon
Definition: default.php:46