Elgg  Version 4.3
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\Hook $hook) {
24  if (!$user instanceof \ElggUser) {
25  return;
26  }
27 
28  /* @var $return MenuItems */
29  $return = $hook->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  'icon_alt' => 'angle-down',
41  'priority' => 800,
42  'section' => 'alt',
43  ]);
44 
45  $return[] = \ElggMenuItem::factory([
46  'name' => 'usersettings',
47  'icon' => 'sliders-h',
48  'text' => elgg_echo('settings'),
49  'href' => elgg_generate_url('settings:account', [
50  'username' => $user->username,
51  ]),
52  'priority' => 300,
53  'section' => 'alt',
54  'parent_name' => 'account',
55  ]);
56 
57  if ($user->isAdmin()) {
58  $return[] = \ElggMenuItem::factory([
59  'name' => 'administration',
60  'icon' => 'cogs',
61  'text' => elgg_echo('admin'),
62  'href' => 'admin',
63  'priority' => 800,
64  'section' => 'alt',
65  'parent_name' => 'account',
66  ]);
67  }
68 
69  $return[] = \ElggMenuItem::factory([
70  'name' => 'logout',
71  'icon' => 'sign-out-alt',
72  'text' => elgg_echo('logout'),
73  'href' => elgg_generate_action_url('logout'),
74  'priority' => 900,
75  'section' => 'alt',
76  'parent_name' => 'account',
77  ]);
78 
79  return $return;
80  }
81 
89  public static function registerMaintenance(\Elgg\Hook $hook) {
90  if (!elgg_is_admin_logged_in() || !_elgg_services()->config->elgg_maintenance_mode) {
91  return;
92  }
93 
94  /* @var $return MenuItems */
95  $return = $hook->getValue();
96 
97  $return[] = \ElggMenuItem::factory( [
98  'name' => 'maintenance_mode',
99  'icon' => 'wrench',
100  'text' => elgg_echo('admin:maintenance_mode:indicator_menu_item'),
101  'href' => 'admin/configure_utilities/maintenance',
102  'priority' => 900,
103  ]);
104 
105  return $return;
106  }
107 
115  public static function registerLogoutAs(\Elgg\Hook $hook) {
116  $original_user_guid = elgg_get_session()->get('login_as_original_user_guid');
117 
118  // quick return if not logged in as someone else.
119  if (!$original_user_guid) {
120  return;
121  }
122 
124  if (!$original_user instanceof \ElggUser) {
125  return;
126  }
127 
128  $icon = elgg_view('output/img', [
129  'src' => $original_user->getIconURL(['size' => 'tiny']),
130  'alt' => 'original user photo',
131  ]);
132  $icon = elgg_format_element('span', ['class' => ['elgg-avatar', 'elgg-avatar-tiny', 'elgg-anchor-icon']], $icon);
133 
134  $menu = $hook->getValue();
135 
137  'name' => 'logout_as',
138  'icon' => $icon,
139  'text' => elgg_echo('action:user:logout_as', [$original_user->getDisplayName()]),
140  'href' => elgg_generate_action_url('admin/user/logout_as'),
141  'link_class' => 'login-as-topbar',
142  'priority' => -100, // make sure it is the first
143  'section' => 'alt',
144  'parent_name' => 'account',
145  ]);
146 
147  return $menu;
148  }
149 }
$original_user_guid
Definition: login_as.php:18
get_user($guid)
Get a user object from a GUID.
Definition: users.php:20
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
elgg_generate_action_url($action, array $query=[], $add_csrf_tokens=true)
Generate an action URL.
elgg_get_session()
Gets Elgg&#39;s session object.
Definition: sessions.php:15
$menu
Admin sidebar – just outputs the page menus.
Definition: sidebar.php:6
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
static factory($options)
Create an ElggMenuItem from an associative array.
Models an event passed to hook handlers.
Definition: Hook.php:11
static registerUserLinks(\Elgg\Hook $hook)
Register menu items for the topbar menu.
Definition: Topbar.php:22
if(empty($user)) $original_user
Definition: login_as.php:17
if(function_exists('apache_get_version')) $icon
Definition: generic.php:49
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:135
elgg_generate_url($name, array $parameters=[])
Generate a URL for named route.
$user
Definition: ban.php:7
static registerLogoutAs(\Elgg\Hook $hook)
Register a action to logout out as the temporarily logged in user.
Definition: Topbar.php:115
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
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
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:179
static registerMaintenance(\Elgg\Hook $hook)
Register a link to the maintenance page.
Definition: Topbar.php:89