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  'class' => elgg_extract_class($vars, [], 'img_class'),
50 ]);
51 
52 if (empty($icon)) {
53  return;
54 }
55 
56 $show_menu = elgg_extract('use_hover', $vars, true) && (elgg_is_admin_logged_in() || !$user->isBanned());
57 
58 $content = '';
59 
60 if ($show_menu) {
61  $content .= elgg_view('navigation/menu/user_hover/placeholder', ['entity' => $user]);
62 
63  $wrapper_class[] = 'elgg-avatar-menu';
64 
65  elgg_import_esm('icon/user/default');
66 }
67 
68 if (elgg_extract('use_link', $vars, true)) {
69  $content .= elgg_view('output/url', [
70  'href' => elgg_extract('href', $vars, $user->getURL()),
71  'text' => $icon,
72  'title' => $name,
73  'is_trusted' => true,
74  'class' => elgg_extract_class($vars, [], 'link_class'),
75  ]);
76 } else {
77  $content .= $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:58
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:156
if(empty($icon)) $show_menu
Definition: default.php:56
elgg_import_esm(string $name)
Helper functions for external files like css/js.
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:145
elgg_extract_class(array $array, array|string $existing=[], string $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:277
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24
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