Elgg  Version 6.1
Topbar.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
6 
13 class Topbar {
14 
22  public static function registerUserLinks(\Elgg\Event $event) {
24  if (!$user instanceof \ElggUser) {
25  return;
26  }
27 
28  /* @var $return MenuItems */
29  $return = $event->getValue();
30 
31  $return[] = \ElggMenuItem::factory([
32  'name' => 'account',
33  'icon' => elgg_view('output/img', [
34  'src' => $user->getIconURL('small'),
35  'alt' => $user->getDisplayName(),
36  ]),
37  'text' => elgg_echo('account'),
38  'href' => false,
39  'link_class' => 'elgg-avatar-small',
40  'priority' => 800,
41  'section' => 'alt',
42  ]);
43 
44  $return[] = \ElggMenuItem::factory([
45  'name' => 'usersettings',
46  'icon' => 'sliders-h',
47  'text' => elgg_echo('settings'),
48  'href' => elgg_generate_url('settings:account', [
49  'username' => $user->username,
50  ]),
51  'priority' => 300,
52  'section' => 'alt',
53  'parent_name' => 'account',
54  ]);
55 
56  if ($user->isAdmin()) {
57  $return[] = \ElggMenuItem::factory([
58  'name' => 'administration',
59  'icon' => 'cogs',
60  'text' => elgg_echo('admin'),
61  'href' => 'admin',
62  'priority' => 800,
63  'section' => 'alt',
64  'parent_name' => 'account',
65  ]);
66  }
67 
68  $return[] = \ElggMenuItem::factory([
69  'name' => 'logout',
70  'icon' => 'sign-out-alt',
71  'text' => elgg_echo('logout'),
72  'href' => elgg_generate_action_url('logout'),
73  'priority' => 900,
74  'section' => 'alt',
75  'parent_name' => 'account',
76  ]);
77 
78  return $return;
79  }
80 
88  public static function registerMaintenance(\Elgg\Event $event) {
89  if (!elgg_is_admin_logged_in() || !_elgg_services()->config->elgg_maintenance_mode) {
90  return;
91  }
92 
93  /* @var $return MenuItems */
94  $return = $event->getValue();
95 
96  $return[] = \ElggMenuItem::factory( [
97  'name' => 'maintenance_mode',
98  'icon' => 'wrench',
99  'text' => elgg_echo('admin:maintenance_mode:indicator_menu_item'),
100  'href' => 'admin/configure_utilities/maintenance',
101  'priority' => 900,
102  ]);
103 
104  return $return;
105  }
106 
114  public static function registerLogoutAs(\Elgg\Event $event) {
115  $original_user_guid = elgg_get_session()->get('login_as_original_user_guid');
116 
117  // quick return if not logged in as someone else.
118  if (!$original_user_guid) {
119  return;
120  }
121 
123  if (!$original_user instanceof \ElggUser) {
124  return;
125  }
126 
127  $icon = elgg_view('output/img', [
128  'src' => $original_user->getIconURL(['size' => 'tiny']),
129  'alt' => 'original user photo',
130  ]);
131  $icon = elgg_format_element('span', ['class' => ['elgg-avatar', 'elgg-avatar-tiny', 'elgg-anchor-icon']], $icon);
132 
133  $menu = $event->getValue();
134 
136  'name' => 'logout_as',
137  'icon' => $icon,
138  'text' => elgg_echo('action:user:logout_as', [$original_user->getDisplayName()]),
139  'href' => elgg_generate_action_url('admin/user/logout_as'),
140  'link_class' => 'login-as-topbar',
141  'priority' => -100, // make sure it is the first
142  'section' => 'alt',
143  'parent_name' => 'account',
144  ]);
145 
146  return $menu;
147  }
148 }
$original_user_guid
Definition: login_as.php:18
elgg_generate_action_url(string $action, array $query=[], bool $add_csrf_tokens=true)
Generate an action URL.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
elgg_get_session()
Gets Elgg&#39;s session object.
Definition: sessions.php:15
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
static factory(array $options)
Create an ElggMenuItem from an associative array.
if(!$user instanceof\ElggUser) $original_user
Definition: login_as.php:17
static registerMaintenance(\Elgg\Event $event)
Register a link to the maintenance page.
Definition: Topbar.php:88
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
if(function_exists('apache_get_version')) $icon
Definition: generic.php:49
static registerLogoutAs(\Elgg\Event $event)
Register a action to logout out as the temporarily logged in user.
Definition: Topbar.php:114
$user
Definition: ban.php:7
$menu
Form body for setting up site menu.
Definition: save.php:7
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
static registerUserLinks(\Elgg\Event $event)
Register menu items for the topbar menu.
Definition: Topbar.php:22
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24
Register menu items to the topbar menu.
Definition: Topbar.php:13
Models an event passed to event handlers.
Definition: Event.php:11
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:306