Elgg  Version 6.1
AdminHeader.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
8 use Elgg\Values;
9 
16 class AdminHeader {
17 
25  public static function register(\Elgg\Event $event) {
26  if (!elgg_is_admin_logged_in()) {
27  return;
28  }
29 
30  /* @var $return MenuItems */
31  $return = $event->getValue();
32 
34 
35  $online_users_count = max(1, elgg_count_entities([
36  'type' => 'user',
37  'wheres' => [
38  function(QueryBuilder $qb, $main_alias) {
39  return $qb->compare("{$main_alias}.last_action", '>=', Values::normalizeTimestamp('-10 minutes'), ELGG_VALUE_TIMESTAMP);
40  }
41  ],
42  ]));
43 
44  $return[] = \ElggMenuItem::factory([
45  'name' => 'online_users_count',
46  'icon' => 'user',
47  'text' => false,
48  'title' => elgg_echo('admin:statistics:label:numonline'),
49  'badge' => elgg_format_element('span', ['title' => $online_users_count], Values::shortFormatOutput($online_users_count)),
50  'deps' => ['admin/users/online'],
51  'href' => 'admin/users/online',
52  'priority' => 10,
53  'section' => 'alt',
54  ]);
55 
56  // link back to the site
57  $return[] = \ElggMenuItem::factory([
58  'name' => 'view_site',
59  'icon' => 'home',
60  'text' => elgg_echo('admin:view_site'),
61  'href' => elgg_get_site_url(),
62  'parent_name' => 'account',
63  'priority' => 100,
64  'section' => 'alt',
65  ]);
66 
67  // logout action
68  $return[] = \ElggMenuItem::factory([
69  'name' => 'admin_logout',
70  'icon' => 'sign-out-alt',
71  'text' => elgg_echo('logout'),
72  'href' => elgg_generate_action_url('logout'),
73  'parent_name' => 'account',
74  'priority' => 1000,
75  'section' => 'alt',
76  ]);
77 
78  // link to admin profile
79  $return[] = \ElggMenuItem::factory([
80  'name' => 'account',
81  'text' => elgg_echo('account'),
82  'href' => false,
83  'icon' => elgg_view('output/img', [
84  'src' => $admin->getIconURL('small'),
85  'alt' => $admin->getDisplayName(),
86  ]),
87  'link_class' => 'elgg-avatar-small',
88  'section' => 'alt',
89  ]);
90 
91  return $return;
92  }
93 
101  public static function registerMaintenance(\Elgg\Event $event) {
102  if (!elgg_is_admin_logged_in()) {
103  return;
104  }
105 
106  if (!elgg_get_config('elgg_maintenance_mode')) {
107  return;
108  }
109 
110  /* @var $return MenuItems */
111  $return = $event->getValue();
112 
113  $return[] = \ElggMenuItem::factory([
114  'name' => 'maintenance',
115  'icon' => 'warning',
116  'text' => elgg_echo('admin:configure_utilities:maintenance'),
117  'href' => 'admin/configure_utilities/maintenance',
118  'link_class' => 'elgg-maintenance-mode-warning',
119  'priority' => 700,
120  ]);
121 
122  return $return;
123  }
124 
132  public static function registerAdminAdminister(\Elgg\Event $event) {
133  if (!elgg_is_admin_logged_in()) {
134  return;
135  }
136 
137  /* @var $return MenuItems */
138  $return = $event->getValue();
139 
140  $return[] = \ElggMenuItem::factory([
141  'name' => 'administer',
142  'text' => elgg_echo('menu:page:header:administer'),
143  'href' => false,
144  'priority' => 10,
145  ]);
146 
147  $return[] = \ElggMenuItem::factory([
148  'name' => 'dashboard',
149  'text' => elgg_echo('admin:dashboard'),
150  'href' => 'admin',
151  'priority' => 10,
152  'parent_name' => 'administer',
153  ]);
154 
155  $return[] = \ElggMenuItem::factory([
156  'name' => 'plugins',
157  'text' => elgg_echo('admin:plugins'),
158  'href' => elgg_generate_url('admin', ['segments' => 'plugins']),
159  'priority' => 30,
160  'parent_name' => 'administer',
161  ]);
162 
163  $return[] = \ElggMenuItem::factory([
164  'name' => 'users',
165  'text' => elgg_echo('admin:users'),
166  'href' => 'admin/users',
167  'priority' => 40,
168  'parent_name' => 'administer',
169  ]);
170 
171  $return[] = \ElggMenuItem::factory([
172  'name' => 'upgrades',
173  'text' => elgg_echo('admin:upgrades'),
174  'href' => 'admin/upgrades',
175  'priority' => 600,
176  'parent_name' => 'administer',
177  ]);
178 
179  return $return;
180  }
181 
189  public static function prepareAdminAdministerUsersChildren(\Elgg\Event $event): ?PreparedMenu {
190  if (!elgg_is_admin_logged_in()) {
191  return null;
192  }
193 
194  /* @var $result PreparedMenu */
195  $result = $event->getValue();
196 
197  $default = $result->getSection('default');
198 
199  /* @var $administer \ElggMenuItem */
200  $administer = $default->get('administer');
201  if (!$administer instanceof \ElggMenuItem || empty($administer->getChildren())) {
202  return null;
203  }
204 
205  /* @var $users \ElggMenuItem */
206  $users = null;
207  foreach ($administer->getChildren() as $child) {
208  if ($child->getID() === 'users') {
209  $users = $child;
210  break;
211  }
212  }
213 
214  if (!$users instanceof \ElggMenuItem || empty($users->getChildren())) {
215  return null;
216  }
217 
218  $children = $users->getChildren();
219 
220  $selected = $users->getSelected();
221  array_unshift($children, \ElggMenuItem::factory([
222  'name' => 'users:all',
223  'text' => elgg_echo('all'),
224  'href' => 'admin/users',
225  'parent_name' => 'users',
226  'priority' => 1,
227  'selected' => $selected,
228  ]));
229  $users->setChildren($children);
230 
231  if ($selected) {
232  $users->addItemClass('elgg-has-selected-child');
233  $users->addItemClass('elgg-state-selected');
234  }
235 
236  $users->setHref(false);
237 
238  return $result;
239  }
240 
248  public static function registerAdminConfigure(\Elgg\Event $event) {
249  if (!elgg_is_admin_logged_in()) {
250  return;
251  }
252 
253  /* @var $return MenuItems */
254  $return = $event->getValue();
255 
256  $return[] = \ElggMenuItem::factory([
257  'name' => 'configure',
258  'text' => elgg_echo('menu:page:header:configure'),
259  'href' => false,
260  'priority' => 20,
261  ]);
262 
263  $return[] = \ElggMenuItem::factory([
264  'name' => 'settings:basic',
265  'text' => elgg_echo('admin:site_settings'),
266  'href' => 'admin/site_settings',
267  'priority' => 10,
268  'parent_name' => 'configure',
269  ]);
270 
271  $return[] = \ElggMenuItem::factory([
272  'name' => 'settings:icons',
273  'text' => elgg_echo('admin:site_icons'),
274  'href' => 'admin/site_icons',
275  'priority' => 20,
276  'parent_name' => 'configure',
277  ]);
278 
279  $return[] = \ElggMenuItem::factory([
280  'name' => 'settings:theme',
281  'text' => elgg_echo('admin:theme'),
282  'href' => 'admin/theme',
283  'priority' => 25,
284  'parent_name' => 'configure',
285  ]);
286 
287  $return[] = \ElggMenuItem::factory([
288  'name' => 'security',
289  'text' => elgg_echo('admin:security'),
290  'href' => 'admin/security',
291  'priority' => 30,
292  'parent_name' => 'configure',
293  ]);
294 
295  $return[] = \ElggMenuItem::factory([
296  'name' => 'configure_utilities:maintenance',
297  'text' => elgg_echo('admin:configure_utilities:maintenance'),
298  'href' => 'admin/configure_utilities/maintenance',
299  'priority' => 40,
300  'parent_name' => 'configure',
301  ]);
302 
303  $return[] = \ElggMenuItem::factory([
304  'name' => 'configure_utilities:robots',
305  'text' => elgg_echo('admin:configure_utilities:robots'),
306  'href' => 'admin/configure_utilities/robots',
307  'priority' => 50,
308  'parent_name' => 'configure',
309  ]);
310 
311  return $return;
312  }
313 
321  public static function registerAdminUtilities(\Elgg\Event $event) {
322  if (!elgg_is_admin_logged_in()) {
323  return;
324  }
325 
326  /* @var $return MenuItems */
327  $return = $event->getValue();
328 
329  $return[] = \ElggMenuItem::factory([
330  'name' => 'utilities',
331  'text' => elgg_echo('menu:page:header:utilities'),
332  'href' => false,
333  'priority' => 30,
334  ]);
335 
336  $return[] = \ElggMenuItem::factory([
337  'name' => 'configure_utilities:menu_items',
338  'text' => elgg_echo('admin:configure_utilities:menu_items'),
339  'href' => 'admin/configure_utilities/menu_items',
340  'parent_name' => 'utilities',
341  ]);
342 
343  return $return;
344  }
345 
353  public static function registerAdminDefaultWidgets(\Elgg\Event $event) {
354  if (!elgg_is_admin_logged_in()) {
355  return;
356  }
357 
358  if (empty(elgg_trigger_event_results('get_list', 'default_widgets', [], []))) {
359  return;
360  }
361 
362  /* @var $return MenuItems */
363  $return = $event->getValue();
364 
365  $return[] = \ElggMenuItem::factory([
366  'name' => 'default_widgets',
367  'text' => elgg_echo('admin:configure_utilities:default_widgets'),
368  'href' => 'admin/configure_utilities/default_widgets',
369  'parent_name' => 'utilities',
370  ]);
371 
372  return $return;
373  }
374 
382  public static function registerAdminInformation(\Elgg\Event $event) {
383  if (!elgg_is_admin_logged_in()) {
384  return;
385  }
386 
387  /* @var $return MenuItems */
388  $return = $event->getValue();
389 
390  $return[] = \ElggMenuItem::factory([
391  'name' => 'information',
392  'text' => elgg_echo('menu:page:header:information'),
393  'href' => false,
394  'priority' => 40,
395  ]);
396 
397  $return[] = \ElggMenuItem::factory([
398  'name' => 'server',
399  'text' => elgg_echo('admin:server'),
400  'href' => 'admin/server',
401  'parent_name' => 'information',
402  'priority' => 50,
403  ]);
404 
405  $return[] = \ElggMenuItem::factory([
406  'name' => 'information:security',
407  'text' => elgg_echo('admin:security'),
408  'href' => 'admin/security/information',
409  'parent_name' => 'information',
410  'priority' => 60,
411  ]);
412 
413  $return[] = \ElggMenuItem::factory([
414  'name' => 'information:performance',
415  'text' => elgg_echo('admin:performance'),
416  'href' => 'admin/performance',
417  'parent_name' => 'information',
418  'priority' => 70,
419  ]);
420 
421  $return[] = \ElggMenuItem::factory([
422  'name' => 'statistics',
423  'text' => elgg_echo('admin:statistics'),
424  'href' => 'admin/statistics',
425  'parent_name' => 'information',
426  'priority' => 80,
427  ]);
428 
429  $return[] = \ElggMenuItem::factory([
430  'name' => 'cron',
431  'text' => elgg_echo('admin:cron'),
432  'href' => 'admin/cron',
433  'parent_name' => 'information',
434  'priority' => 90,
435  ]);
436 
437  return $return;
438  }
439 }
static prepareAdminAdministerUsersChildren(\Elgg\Event $event)
Prepare the users menu item in the administer section on admin pages.
$default
Definition: checkbox.php:30
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
Saves user notification settings.
if(empty($user_guids)) $users
Definition: ban.php:12
$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.
Database abstraction query builder.
$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 Menu Item.
static registerAdminUtilities(\Elgg\Event $event)
Add the utilities section to the admin page menu.
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
static registerAdminInformation(\Elgg\Event $event)
Add the information section to the admin page menu.
static normalizeTimestamp($time)
Returns timestamp value of the time representation.
Definition: Values.php:63
static shortFormatOutput($n, $precision=0)
Use to convert large positive numbers in to short form like 1K, 1M, 1B or 1T Example: shortFormatOutp...
Definition: Values.php:211
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:518
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
const ELGG_VALUE_TIMESTAMP
Definition: constants.php:115
Register menu items for the admin_header menu.
Definition: AdminHeader.php:16
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_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
$qb
Definition: queue.php:12
Models an event passed to event handlers.
Definition: Event.php:11