Elgg  Version 4.3
Page.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
7 
14 class Page {
15 
23  public static function registerAdminAdminister(\Elgg\Hook $hook) {
24  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
25  return;
26  }
27 
28  /* @var $return MenuItems */
29  $return = $hook->getValue();
30 
31  $return[] = \ElggMenuItem::factory([
32  'name' => 'dashboard',
33  'text' => elgg_echo('admin:dashboard'),
34  'href' => 'admin',
35  'priority' => 10,
36  'section' => 'administer',
37  ]);
38 
39  $return[] = \ElggMenuItem::factory([
40  'name' => 'plugins',
41  'text' => elgg_echo('admin:plugins'),
42  'href' => 'admin/plugins',
43  'priority' => 30,
44  'section' => 'administer',
45  ]);
46 
47  $return[] = \ElggMenuItem::factory([
48  'name' => 'users',
49  'text' => elgg_echo('admin:users'),
50  'href' => 'admin/users',
51  'priority' => 40,
52  'section' => 'administer',
53  ]);
54 
55  $return[] = \ElggMenuItem::factory([
56  'name' => 'upgrades',
57  'text' => elgg_echo('admin:upgrades'),
58  'href' => 'admin/upgrades',
59  'priority' => 600,
60  'section' => 'administer',
61  ]);
62 
63  $return[] = \ElggMenuItem::factory([
64  'name' => 'administer_utilities',
65  'text' => elgg_echo('admin:administer_utilities'),
66  'href' => false,
67  'priority' => 50,
68  'section' => 'administer',
69  'show_with_empty_children' => false,
70  ]);
71 
72  return $return;
73  }
74 
82  public static function prepareAdminAdministerUsersChildren(\Elgg\Hook $hook): ?PreparedMenu {
83  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
84  return null;
85  }
86 
87  /* @var $result PreparedMenu */
88  $result = $hook->getValue();
89 
90  $administer = $result->getSection('administer');
91  /* @var $users \ElggMenuItem */
92  $users = $administer->get('users');
93  if (!$users instanceof \ElggMenuItem || empty($users->getChildren())) {
94  return null;
95  }
96 
97  $children = $users->getChildren();
98 
99  $selected = $users->getSelected();
100  array_unshift($children, \ElggMenuItem::factory([
101  'name' => 'users:all',
102  'text' => elgg_echo('all'),
103  'href' => 'admin/users',
104  'priority' => 1,
105  'selected' => $selected,
106  ]));
107  $users->setChildren($children);
108 
109  if ($selected) {
110  $users->addItemClass('elgg-has-selected-child');
111  $users->addItemClass('elgg-state-selected');
112  }
113 
114  $users->setHref(false);
115 
116  return $result;
117  }
118 
126  public static function registerAdminConfigure(\Elgg\Hook $hook) {
127  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
128  return;
129  }
130 
131  /* @var $return MenuItems */
132  $return = $hook->getValue();
133 
134  $return[] = \ElggMenuItem::factory([
135  'name' => 'settings:basic',
136  'text' => elgg_echo('admin:site_settings'),
137  'href' => 'admin/site_settings',
138  'priority' => 10,
139  'section' => 'configure',
140  ]);
141 
142  $return[] = \ElggMenuItem::factory([
143  'name' => 'settings:icons',
144  'text' => elgg_echo('admin:site_icons'),
145  'href' => 'admin/site_icons',
146  'priority' => 20,
147  'section' => 'configure',
148  ]);
149 
150  $return[] = \ElggMenuItem::factory([
151  'name' => 'security',
152  'text' => elgg_echo('admin:security'),
153  'href' => 'admin/security',
154  'priority' => 30,
155  'section' => 'configure',
156  ]);
157 
158  // Utilities
159  $return[] = \ElggMenuItem::factory([
160  'name' => 'configure_utilities',
161  'text' => elgg_echo('admin:configure_utilities'),
162  'href' => false,
163  'priority' => 600,
164  'section' => 'configure',
165  ]);
166  $return[] = \ElggMenuItem::factory([
167  'name' => 'configure_utilities:maintenance',
168  'text' => elgg_echo('admin:configure_utilities:maintenance'),
169  'href' => 'admin/configure_utilities/maintenance',
170  'section' => 'configure',
171  'parent_name' => 'configure_utilities',
172  ]);
173  $return[] = \ElggMenuItem::factory([
174  'name' => 'configure_utilities:menu_items',
175  'text' => elgg_echo('admin:configure_utilities:menu_items'),
176  'href' => 'admin/configure_utilities/menu_items',
177  'section' => 'configure',
178  'parent_name' => 'configure_utilities',
179  ]);
180  $return[] = \ElggMenuItem::factory([
181  'name' => 'configure_utilities:robots',
182  'text' => elgg_echo('admin:configure_utilities:robots'),
183  'href' => 'admin/configure_utilities/robots',
184  'section' => 'configure',
185  'parent_name' => 'configure_utilities',
186  ]);
187 
188  return $return;
189  }
190 
198  public static function registerAdminDefaultWidgets(\Elgg\Hook $hook) {
199  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
200  return;
201  }
202 
203  if (empty(elgg_trigger_plugin_hook('get_list', 'default_widgets', null, []))) {
204  return;
205  }
206 
207  /* @var $return MenuItems */
208  $return = $hook->getValue();
209 
210  $return[] = \ElggMenuItem::factory([
211  'name' => 'default_widgets',
212  'text' => elgg_echo('admin:configure_utilities:default_widgets'),
213  'href' => 'admin/configure_utilities/default_widgets',
214  'section' => 'configure',
215  'parent_name' => 'configure_utilities',
216  ]);
217 
218  return $return;
219  }
220 
228  public static function registerAdminInformation(\Elgg\Hook $hook) {
229  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
230  return;
231  }
232 
233  /* @var $return MenuItems */
234  $return = $hook->getValue();
235 
236  $return[] = \ElggMenuItem::factory([
237  'name' => 'server',
238  'text' => elgg_echo('admin:server'),
239  'href' => 'admin/server',
240  'section' => 'information',
241  'priority' => 50,
242  ]);
243 
244  $return[] = \ElggMenuItem::factory([
245  'name' => 'information:security',
246  'text' => elgg_echo('admin:security'),
247  'href' => 'admin/security/information',
248  'section' => 'information',
249  'priority' => 60,
250  ]);
251 
252  $return[] = \ElggMenuItem::factory([
253  'name' => 'information:performance',
254  'text' => elgg_echo('admin:performance'),
255  'href' => 'admin/performance',
256  'section' => 'information',
257  'priority' => 70,
258  ]);
259 
260  $return[] = \ElggMenuItem::factory([
261  'name' => 'statistics',
262  'text' => elgg_echo('admin:statistics'),
263  'href' => 'admin/statistics',
264  'section' => 'information',
265  'priority' => 80,
266  ]);
267 
268  $return[] = \ElggMenuItem::factory([
269  'name' => 'cron',
270  'text' => elgg_echo('admin:cron'),
271  'href' => 'admin/cron',
272  'section' => 'information',
273  'priority' => 90,
274  ]);
275 
276  return $return;
277  }
278 
288  public static function registerAdminPluginSettings(\Elgg\Hook $hook) {
289  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
290  return;
291  }
292 
293  // plugin settings
294  $active_plugins = elgg_get_plugins('active');
295  if (empty($active_plugins)) {
296  // nothing added because no items
297  return;
298  }
299 
300  $plugins_with_settings = [];
301 
302  foreach ($active_plugins as $plugin) {
303  $plugin_id = $plugin->getID();
304 
305  if (!elgg_view_exists("plugins/{$plugin_id}/settings") ) {
306  continue;
307  }
308  $plugin_name = $plugin->getDisplayName();
309  $plugins_with_settings[strtolower($plugin_name)] = [
310  'name' => "plugin:settings:{$plugin_id}",
311  'href' => elgg_generate_url('admin:plugin_settings', [
312  'plugin_id' => $plugin_id,
313  ]),
314  'text' => $plugin_name,
315  'parent_name' => 'plugin_settings',
316  'section' => 'configure',
317  ];
318  }
319 
320  if (empty($plugins_with_settings)) {
321  return;
322  }
323 
324  /* @var $return MenuItems */
325  $return = $hook->getValue();
326 
327  $return[] = \ElggMenuItem::factory([
328  'name' => 'plugin_settings',
329  'text' => elgg_echo('admin:plugin_settings'),
330  'href' => false,
331  'section' => 'configure',
332  ]);
333 
334  ksort($plugins_with_settings);
335  $priority = 0;
336  foreach ($plugins_with_settings as $plugin_item) {
337  $priority += 10;
338  $plugin_item['priority'] = $priority;
339  $return[] = \ElggMenuItem::factory($plugin_item);
340  }
341 
342  return $return;
343  }
344 
352  public static function registerUserSettings(\Elgg\Hook $hook) {
354  if (!$user instanceof \ElggUser || !elgg_in_context('settings') || !$user->canEdit()) {
355  return;
356  }
357 
358  /* @var $return MenuItems */
359  $return = $hook->getValue();
360 
361  $return[] = \ElggMenuItem::factory([
362  'name' => '1_account',
363  'text' => elgg_echo('usersettings:user:opt:linktext'),
364  'href' => elgg_generate_url('settings:account', [
365  'username' => $user->username,
366  ]),
367  'section' => 'configure',
368  ]);
369 
370  $return[] = \ElggMenuItem::factory([
371  'name' => '1_notifications',
372  'text' => elgg_echo('usersettings:notifications:menu:page'),
373  'href' => elgg_generate_url('settings:notifications', [
374  'username' => $user->username,
375  ]),
376  'section' => 'configure',
377  ]);
378 
379  $return[] = \ElggMenuItem::factory([
380  'name' => '1_statistics',
381  'text' => elgg_echo('usersettings:statistics:opt:linktext'),
382  'href' => elgg_generate_url('settings:statistics', [
383  'username' => $user->username,
384  ]),
385  'section' => 'configure',
386  ]);
387 
388  return $return;
389  }
390 
398  public static function registerUserSettingsPlugins(\Elgg\Hook $hook) {
400  if (!$user instanceof \ElggUser || !elgg_in_context('settings') || !$user->canEdit()) {
401  return;
402  }
403 
404  /* @var $return MenuItems */
405  $return = $hook->getValue();
406 
407  $return[] = \ElggMenuItem::factory([
408  'name' => '1_plugins',
409  'text' => elgg_echo('usersettings:plugins:opt:linktext'),
410  'href' => false,
411  'section' => 'configure',
412  'show_with_empty_children' => false,
413  ]);
414 
415  $active_plugins = elgg_get_plugins();
416  foreach ($active_plugins as $plugin) {
417  $plugin_id = $plugin->getID();
418  if (!elgg_view_exists("plugins/{$plugin_id}/usersettings")) {
419  continue;
420  }
421 
422  $title = $plugin->getDisplayName();
423  if (elgg_language_key_exists("{$plugin_id}:usersettings:title")) {
424  $title = elgg_echo("{$plugin_id}:usersettings:title");
425  }
426 
427  $return[] = \ElggMenuItem::factory([
428  'name' => $plugin_id,
429  'text' => $title,
430  'href' => elgg_generate_url('settings:tools', [
431  'username' => $user->username,
432  'plugin_id' => $plugin_id,
433  ]),
434  'parent_name' => '1_plugins',
435  'section' => 'configure',
436  ]);
437  }
438 
439  return $return;
440  }
441 
449  public static function registerAvatarEdit(\Elgg\Hook $hook) {
450  $user = $hook->getParam('entity', elgg_get_page_owner_entity());
451  if (!$user instanceof \ElggUser || !$user->canEdit() || !elgg_in_context('settings')) {
452  return;
453  }
454 
455  /* @var $return MenuItems */
456  $return = $hook->getValue();
457 
458  $return[] = \ElggMenuItem::factory([
459  'name' => 'edit_avatar',
460  'text' => elgg_echo('avatar:edit'),
461  'href' => elgg_generate_entity_url($user, 'edit', 'avatar'),
462  'section' => '1_profile',
463  ]);
464 
465  return $return;
466  }
467 }
elgg_language_key_exists($key, $language= 'en')
Check if a given language key exists.
Definition: languages.php:46
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
Definition: views.php:152
elgg_get_plugins(string $status= 'active')
Returns an ordered list of plugins.
Definition: plugins.php:55
$plugin
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
$title
Definition: generic.php:50
static registerUserSettingsPlugins(\Elgg\Hook $hook)
Register menu items for the user plugin settings.
Definition: Page.php:398
Register menu items for the page menu.
Definition: Page.php:14
static registerAdminAdminister(\Elgg\Hook $hook)
Add the administer section to the admin page menu.
Definition: Page.php:23
static registerAdminConfigure(\Elgg\Hook $hook)
Add the configure section to the admin page menu.
Definition: Page.php:126
$children
Definition: item.php:17
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
$plugin_id
Remove all user and plugin settings from the give plugin ID.
Definition: remove.php:8
static registerUserSettings(\Elgg\Hook $hook)
Register menu items for the user settings.
Definition: Page.php:352
static registerAdminDefaultWidgets(\Elgg\Hook $hook)
Register menu items for default widgets.
Definition: Page.php:198
static factory($options)
Create an ElggMenuItem from an associative array.
Models an event passed to hook handlers.
Definition: Hook.php:11
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: context.php:78
static registerAdminInformation(\Elgg\Hook $hook)
Add the information section to the admin page menu.
Definition: Page.php:228
elgg_generate_url($name, array $parameters=[])
Generate a URL for named route.
$user
Definition: ban.php:7
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:380
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
Represents a menu that has been broken down into sections, with menu hierarchy trees setup...
static prepareAdminAdministerUsersChildren(\Elgg\Hook $hook)
Prepare the users menu item in the administer section on admin pages.
Definition: Page.php:82
$selected
Admin helper view for tabs on the different security pages.
Definition: tabs.php:8
static registerAvatarEdit(\Elgg\Hook $hook)
Add a link to the avatar edit page.
Definition: Page.php:449
if(!$plugin) $plugin_name
Definition: save.php:25
static registerAdminPluginSettings(\Elgg\Hook $hook)
Register links to the plugin settings.
Definition: Page.php:288
elgg_generate_entity_url(ElggEntity $entity, $resource= 'view', $subresource=null, array $parameters=[])
Generate entity URL from a named route.
$priority