Elgg  Version master
AdminHeader.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
7 
14 class AdminHeader {
15 
23  public static function register(\Elgg\Event $event) {
24  if (!elgg_is_admin_logged_in()) {
25  return;
26  }
27 
28  /* @var $return MenuItems */
29  $return = $event->getValue();
30 
32 
33  // link back to the site
34  $return[] = \ElggMenuItem::factory([
35  'name' => 'view_site',
36  'icon' => 'home',
37  'text' => elgg_echo('admin:view_site'),
38  'href' => elgg_get_site_url(),
39  'parent_name' => 'account',
40  'priority' => 100,
41  'section' => 'alt',
42  ]);
43 
44  // logout action
45  $return[] = \ElggMenuItem::factory([
46  'name' => 'admin_logout',
47  'icon' => 'sign-out-alt',
48  'text' => elgg_echo('logout'),
49  'href' => elgg_generate_action_url('logout'),
50  'parent_name' => 'account',
51  'priority' => 1000,
52  'section' => 'alt',
53  ]);
54 
55  // link to admin profile
56  $return[] = \ElggMenuItem::factory([
57  'name' => 'account',
58  'text' => elgg_echo('account'),
59  'href' => false,
60  'icon' => elgg_view('output/img', [
61  'src' => $admin->getIconURL('small'),
62  'alt' => $admin->getDisplayName(),
63  ]),
64  'link_class' => 'elgg-avatar-small',
65  'section' => 'alt',
66  ]);
67 
68  return $return;
69  }
70 
78  public static function registerMaintenance(\Elgg\Event $event) {
79  if (!elgg_is_admin_logged_in()) {
80  return;
81  }
82 
83  if (!elgg_get_config('elgg_maintenance_mode')) {
84  return;
85  }
86 
87  /* @var $return MenuItems */
88  $return = $event->getValue();
89 
90  $return[] = \ElggMenuItem::factory([
91  'name' => 'maintenance',
92  'icon' => 'warning',
93  'text' => elgg_echo('admin:configure_utilities:maintenance'),
94  'href' => 'admin/configure_utilities/maintenance',
95  'link_class' => 'elgg-maintenance-mode-warning',
96  'priority' => 700,
97  ]);
98 
99  return $return;
100  }
101 
109  public static function registerAdminAdminister(\Elgg\Event $event) {
110  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
111  return;
112  }
113 
114  /* @var $return MenuItems */
115  $return = $event->getValue();
116 
117  $return[] = \ElggMenuItem::factory([
118  'name' => 'administer',
119  'text' => elgg_echo('menu:page:header:administer'),
120  'href' => false,
121  ]);
122 
123  $return[] = \ElggMenuItem::factory([
124  'name' => 'dashboard',
125  'text' => elgg_echo('admin:dashboard'),
126  'href' => 'admin',
127  'priority' => 10,
128  'parent_name' => 'administer',
129  ]);
130 
131  $return[] = \ElggMenuItem::factory([
132  'name' => 'plugins',
133  'text' => elgg_echo('admin:plugins'),
134  'href' => elgg_generate_url('admin', ['segments' => 'plugins']),
135  'priority' => 30,
136  'parent_name' => 'administer',
137  ]);
138 
139  $return[] = \ElggMenuItem::factory([
140  'name' => 'users',
141  'text' => elgg_echo('admin:users'),
142  'href' => 'admin/users',
143  'priority' => 40,
144  'parent_name' => 'administer',
145  ]);
146 
147  $return[] = \ElggMenuItem::factory([
148  'name' => 'upgrades',
149  'text' => elgg_echo('admin:upgrades'),
150  'href' => 'admin/upgrades',
151  'priority' => 600,
152  'parent_name' => 'administer',
153  ]);
154 
155  $return[] = \ElggMenuItem::factory([
156  'name' => 'administer_utilities',
157  'text' => elgg_echo('admin:administer_utilities'),
158  'href' => false,
159  'priority' => 50,
160  'parent_name' => 'administer',
161  'show_with_empty_children' => false,
162  ]);
163 
164  return $return;
165  }
166 
174  public static function prepareAdminAdministerUsersChildren(\Elgg\Event $event): ?PreparedMenu {
175  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
176  return null;
177  }
178 
179  /* @var $result PreparedMenu */
180  $result = $event->getValue();
181 
182  $default = $result->getSection('default');
183 
184  /* @var $administer \ElggMenuItem */
185  $administer = $default->get('administer');
186  if (!$administer instanceof \ElggMenuItem || empty($administer->getChildren())) {
187  return null;
188  }
189 
190  /* @var $users \ElggMenuItem */
191  $users = null;
192  foreach ($administer->getChildren() as $child) {
193  if ($child->getID() === 'users') {
194  $users = $child;
195  break;
196  }
197  }
198 
199  if (!$users instanceof \ElggMenuItem || empty($users->getChildren())) {
200  return null;
201  }
202 
203  $children = $users->getChildren();
204 
205  $selected = $users->getSelected();
206  array_unshift($children, \ElggMenuItem::factory([
207  'name' => 'users:all',
208  'text' => elgg_echo('all'),
209  'href' => 'admin/users',
210  'parent_name' => 'users',
211  'priority' => 1,
212  'selected' => $selected,
213  ]));
214  $users->setChildren($children);
215 
216  if ($selected) {
217  $users->addItemClass('elgg-has-selected-child');
218  $users->addItemClass('elgg-state-selected');
219  }
220 
221  $users->setHref(false);
222 
223  return $result;
224  }
225 
233  public static function registerAdminConfigure(\Elgg\Event $event) {
234  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
235  return;
236  }
237 
238  /* @var $return MenuItems */
239  $return = $event->getValue();
240 
241  $return[] = \ElggMenuItem::factory([
242  'name' => 'configure',
243  'text' => elgg_echo('menu:page:header:configure'),
244  'href' => false,
245  ]);
246 
247  $return[] = \ElggMenuItem::factory([
248  'name' => 'settings:basic',
249  'text' => elgg_echo('admin:site_settings'),
250  'href' => 'admin/site_settings',
251  'priority' => 10,
252  'parent_name' => 'configure',
253  ]);
254 
255  $return[] = \ElggMenuItem::factory([
256  'name' => 'settings:icons',
257  'text' => elgg_echo('admin:site_icons'),
258  'href' => 'admin/site_icons',
259  'priority' => 20,
260  'parent_name' => 'configure',
261  ]);
262 
263  $return[] = \ElggMenuItem::factory([
264  'name' => 'security',
265  'text' => elgg_echo('admin:security'),
266  'href' => 'admin/security',
267  'priority' => 30,
268  'parent_name' => 'configure',
269  ]);
270 
271  // Utilities
272  $return[] = \ElggMenuItem::factory([
273  'name' => 'configure_utilities',
274  'text' => elgg_echo('admin:configure_utilities'),
275  'href' => false,
276  'priority' => 600,
277  'parent_name' => 'configure',
278  ]);
279  $return[] = \ElggMenuItem::factory([
280  'name' => 'configure_utilities:maintenance',
281  'text' => elgg_echo('admin:configure_utilities:maintenance'),
282  'href' => 'admin/configure_utilities/maintenance',
283  'parent_name' => 'configure_utilities',
284  ]);
285  $return[] = \ElggMenuItem::factory([
286  'name' => 'configure_utilities:menu_items',
287  'text' => elgg_echo('admin:configure_utilities:menu_items'),
288  'href' => 'admin/configure_utilities/menu_items',
289  'parent_name' => 'configure_utilities',
290  ]);
291  $return[] = \ElggMenuItem::factory([
292  'name' => 'configure_utilities:robots',
293  'text' => elgg_echo('admin:configure_utilities:robots'),
294  'href' => 'admin/configure_utilities/robots',
295  'parent_name' => 'configure_utilities',
296  ]);
297 
298  return $return;
299  }
300 
308  public static function registerAdminDefaultWidgets(\Elgg\Event $event) {
309  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
310  return;
311  }
312 
313  if (empty(elgg_trigger_event_results('get_list', 'default_widgets', [], []))) {
314  return;
315  }
316 
317  /* @var $return MenuItems */
318  $return = $event->getValue();
319 
320  $return[] = \ElggMenuItem::factory([
321  'name' => 'default_widgets',
322  'text' => elgg_echo('admin:configure_utilities:default_widgets'),
323  'href' => 'admin/configure_utilities/default_widgets',
324  'parent_name' => 'configure_utilities',
325  ]);
326 
327  return $return;
328  }
329 
337  public static function registerAdminInformation(\Elgg\Event $event) {
338  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
339  return;
340  }
341 
342  /* @var $return MenuItems */
343  $return = $event->getValue();
344 
345  $return[] = \ElggMenuItem::factory([
346  'name' => 'information',
347  'text' => elgg_echo('menu:page:header:information'),
348  'href' => false,
349  ]);
350 
351  $return[] = \ElggMenuItem::factory([
352  'name' => 'server',
353  'text' => elgg_echo('admin:server'),
354  'href' => 'admin/server',
355  'parent_name' => 'information',
356  'priority' => 50,
357  ]);
358 
359  $return[] = \ElggMenuItem::factory([
360  'name' => 'information:security',
361  'text' => elgg_echo('admin:security'),
362  'href' => 'admin/security/information',
363  'parent_name' => 'information',
364  'priority' => 60,
365  ]);
366 
367  $return[] = \ElggMenuItem::factory([
368  'name' => 'information:performance',
369  'text' => elgg_echo('admin:performance'),
370  'href' => 'admin/performance',
371  'parent_name' => 'information',
372  'priority' => 70,
373  ]);
374 
375  $return[] = \ElggMenuItem::factory([
376  'name' => 'statistics',
377  'text' => elgg_echo('admin:statistics'),
378  'href' => 'admin/statistics',
379  'parent_name' => 'information',
380  'priority' => 80,
381  ]);
382 
383  $return[] = \ElggMenuItem::factory([
384  'name' => 'cron',
385  'text' => elgg_echo('admin:cron'),
386  'href' => 'admin/cron',
387  'parent_name' => 'information',
388  'priority' => 90,
389  ]);
390 
391  return $return;
392  }
393 }
static prepareAdminAdministerUsersChildren(\Elgg\Event $event)
Prepare the users menu item in the administer section on admin pages.
$default
Definition: checkbox.php:31
elgg_generate_action_url(string $action, array $query=[], bool $add_csrf_tokens=true)
Generate an action URL.
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
static registerAdminAdminister(\Elgg\Event $event)
Add the administer section to the admin header menu.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
if(empty($user_guids)) $users
Definition: ban.php:12
elgg_in_context(string $context)
Check if this context exists anywhere in the stack.
Definition: context.php:78
$admin
Definition: useradd.php:19
static registerAdminConfigure(\Elgg\Event $event)
Add the configure section to the admin page menu.
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
static registerMaintenance(\Elgg\Event $event)
Add the maintenance link.
Definition: AdminHeader.php:78
$children
Definition: item.php:17
elgg_trigger_event_results(string $event, string $type, array $params=[], $returnvalue=null)
Triggers an event where it is expected that the mixed return value could be manipulated by event call...
Definition: events.php:117
static factory(array $options)
Create an ElggMenuItem from an associative array.
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:177
static registerAdminInformation(\Elgg\Event $event)
Add the information section to the admin page menu.
Represents a menu that has been broken down into sections, with menu hierarchy trees setup...
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
$selected
Admin helper view for tabs on the different security pages.
Definition: tabs.php:8
Register menu items for the admin_header menu.
Definition: AdminHeader.php:14
static registerAdminDefaultWidgets(\Elgg\Event $event)
Register menu items for default widgets.
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24
Models an event passed to event handlers.
Definition: Event.php:11