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_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  'priority' => 10,
122  ]);
123 
124  $return[] = \ElggMenuItem::factory([
125  'name' => 'dashboard',
126  'text' => elgg_echo('admin:dashboard'),
127  'href' => 'admin',
128  'priority' => 10,
129  'parent_name' => 'administer',
130  ]);
131 
132  $return[] = \ElggMenuItem::factory([
133  'name' => 'plugins',
134  'text' => elgg_echo('admin:plugins'),
135  'href' => elgg_generate_url('admin', ['segments' => 'plugins']),
136  'priority' => 30,
137  'parent_name' => 'administer',
138  ]);
139 
140  $return[] = \ElggMenuItem::factory([
141  'name' => 'users',
142  'text' => elgg_echo('admin:users'),
143  'href' => 'admin/users',
144  'priority' => 40,
145  'parent_name' => 'administer',
146  ]);
147 
148  $return[] = \ElggMenuItem::factory([
149  'name' => 'upgrades',
150  'text' => elgg_echo('admin:upgrades'),
151  'href' => 'admin/upgrades',
152  'priority' => 600,
153  'parent_name' => 'administer',
154  ]);
155 
156  return $return;
157  }
158 
166  public static function prepareAdminAdministerUsersChildren(\Elgg\Event $event): ?PreparedMenu {
167  if (!elgg_is_admin_logged_in()) {
168  return null;
169  }
170 
171  /* @var $result PreparedMenu */
172  $result = $event->getValue();
173 
174  $default = $result->getSection('default');
175 
176  /* @var $administer \ElggMenuItem */
177  $administer = $default->get('administer');
178  if (!$administer instanceof \ElggMenuItem || empty($administer->getChildren())) {
179  return null;
180  }
181 
182  /* @var $users \ElggMenuItem */
183  $users = null;
184  foreach ($administer->getChildren() as $child) {
185  if ($child->getID() === 'users') {
186  $users = $child;
187  break;
188  }
189  }
190 
191  if (!$users instanceof \ElggMenuItem || empty($users->getChildren())) {
192  return null;
193  }
194 
195  $children = $users->getChildren();
196 
197  $selected = $users->getSelected();
198  array_unshift($children, \ElggMenuItem::factory([
199  'name' => 'users:all',
200  'text' => elgg_echo('all'),
201  'href' => 'admin/users',
202  'parent_name' => 'users',
203  'priority' => 1,
204  'selected' => $selected,
205  ]));
206  $users->setChildren($children);
207 
208  if ($selected) {
209  $users->addItemClass('elgg-has-selected-child');
210  $users->addItemClass('elgg-state-selected');
211  }
212 
213  $users->setHref(false);
214 
215  return $result;
216  }
217 
225  public static function registerAdminConfigure(\Elgg\Event $event) {
226  if (!elgg_is_admin_logged_in()) {
227  return;
228  }
229 
230  /* @var $return MenuItems */
231  $return = $event->getValue();
232 
233  $return[] = \ElggMenuItem::factory([
234  'name' => 'configure',
235  'text' => elgg_echo('menu:page:header:configure'),
236  'href' => false,
237  'priority' => 20,
238  ]);
239 
240  $return[] = \ElggMenuItem::factory([
241  'name' => 'settings:basic',
242  'text' => elgg_echo('admin:site_settings'),
243  'href' => 'admin/site_settings',
244  'priority' => 10,
245  'parent_name' => 'configure',
246  ]);
247 
248  $return[] = \ElggMenuItem::factory([
249  'name' => 'settings:icons',
250  'text' => elgg_echo('admin:site_icons'),
251  'href' => 'admin/site_icons',
252  'priority' => 20,
253  'parent_name' => 'configure',
254  ]);
255 
256  $return[] = \ElggMenuItem::factory([
257  'name' => 'settings:theme',
258  'text' => elgg_echo('admin:theme'),
259  'href' => 'admin/theme',
260  'priority' => 25,
261  'parent_name' => 'configure',
262  ]);
263 
264  $return[] = \ElggMenuItem::factory([
265  'name' => 'security',
266  'text' => elgg_echo('admin:security'),
267  'href' => 'admin/security',
268  'priority' => 30,
269  'parent_name' => 'configure',
270  ]);
271 
272  $return[] = \ElggMenuItem::factory([
273  'name' => 'configure_utilities:maintenance',
274  'text' => elgg_echo('admin:configure_utilities:maintenance'),
275  'href' => 'admin/configure_utilities/maintenance',
276  'priority' => 40,
277  'parent_name' => 'configure',
278  ]);
279 
280  $return[] = \ElggMenuItem::factory([
281  'name' => 'configure_utilities:robots',
282  'text' => elgg_echo('admin:configure_utilities:robots'),
283  'href' => 'admin/configure_utilities/robots',
284  'priority' => 50,
285  'parent_name' => 'configure',
286  ]);
287 
288  return $return;
289  }
290 
298  public static function registerAdminUtilities(\Elgg\Event $event) {
299  if (!elgg_is_admin_logged_in()) {
300  return;
301  }
302 
303  /* @var $return MenuItems */
304  $return = $event->getValue();
305 
306  $return[] = \ElggMenuItem::factory([
307  'name' => 'utilities',
308  'text' => elgg_echo('menu:page:header:utilities'),
309  'href' => false,
310  'priority' => 30,
311  ]);
312 
313  $return[] = \ElggMenuItem::factory([
314  'name' => 'configure_utilities:menu_items',
315  'text' => elgg_echo('admin:configure_utilities:menu_items'),
316  'href' => 'admin/configure_utilities/menu_items',
317  'parent_name' => 'utilities',
318  ]);
319 
320  return $return;
321  }
322 
330  public static function registerAdminDefaultWidgets(\Elgg\Event $event) {
331  if (!elgg_is_admin_logged_in()) {
332  return;
333  }
334 
335  if (empty(elgg_trigger_event_results('get_list', 'default_widgets', [], []))) {
336  return;
337  }
338 
339  /* @var $return MenuItems */
340  $return = $event->getValue();
341 
342  $return[] = \ElggMenuItem::factory([
343  'name' => 'default_widgets',
344  'text' => elgg_echo('admin:configure_utilities:default_widgets'),
345  'href' => 'admin/configure_utilities/default_widgets',
346  'parent_name' => 'utilities',
347  ]);
348 
349  return $return;
350  }
351 
359  public static function registerAdminInformation(\Elgg\Event $event) {
360  if (!elgg_is_admin_logged_in()) {
361  return;
362  }
363 
364  /* @var $return MenuItems */
365  $return = $event->getValue();
366 
367  $return[] = \ElggMenuItem::factory([
368  'name' => 'information',
369  'text' => elgg_echo('menu:page:header:information'),
370  'href' => false,
371  'priority' => 40,
372  ]);
373 
374  $return[] = \ElggMenuItem::factory([
375  'name' => 'server',
376  'text' => elgg_echo('admin:server'),
377  'href' => 'admin/server',
378  'parent_name' => 'information',
379  'priority' => 50,
380  ]);
381 
382  $return[] = \ElggMenuItem::factory([
383  'name' => 'information:security',
384  'text' => elgg_echo('admin:security'),
385  'href' => 'admin/security/information',
386  'parent_name' => 'information',
387  'priority' => 60,
388  ]);
389 
390  $return[] = \ElggMenuItem::factory([
391  'name' => 'information:performance',
392  'text' => elgg_echo('admin:performance'),
393  'href' => 'admin/performance',
394  'parent_name' => 'information',
395  'priority' => 70,
396  ]);
397 
398  $return[] = \ElggMenuItem::factory([
399  'name' => 'statistics',
400  'text' => elgg_echo('admin:statistics'),
401  'href' => 'admin/statistics',
402  'parent_name' => 'information',
403  'priority' => 80,
404  ]);
405 
406  $return[] = \ElggMenuItem::factory([
407  'name' => 'cron',
408  'text' => elgg_echo('admin:cron'),
409  'href' => 'admin/cron',
410  'parent_name' => 'information',
411  'priority' => 90,
412  ]);
413 
414  return $return;
415  }
416 }
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
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.
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 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.
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