Elgg  Version 6.0
Page.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Menus;
4 
7 
14 class Page {
15 
25  public static function registerAdminPluginSettings(\Elgg\Event $event) {
26  if (!elgg_in_context('admin') || !elgg_is_admin_logged_in()) {
27  return;
28  }
29 
30  $current_route = elgg_get_current_route();
31  if (elgg_extract('segments', $current_route->getMatchedParameters()) !== 'plugins' && $current_route->getName() !== 'admin:plugin_settings') {
32  return;
33  }
34 
35  // plugin settings
36  $active_plugins = elgg_get_plugins('active');
37  if (empty($active_plugins)) {
38  // nothing added because no items
39  return;
40  }
41 
42  $plugins_with_settings = [];
43 
44  foreach ($active_plugins as $plugin) {
45  $plugin_id = $plugin->getID();
46 
47  if (!elgg_view_exists("plugins/{$plugin_id}/settings")) {
48  continue;
49  }
50 
51  $plugin_name = $plugin->getDisplayName();
52  $plugins_with_settings[strtolower($plugin_name)] = [
53  'name' => "plugin:settings:{$plugin_id}",
54  'href' => elgg_generate_url('admin:plugin_settings', [
55  'plugin_id' => $plugin_id,
56  ]),
57  'text' => $plugin_name,
58  'section' => 'plugin_settings',
59  ];
60  }
61 
62  if (empty($plugins_with_settings)) {
63  return;
64  }
65 
66  /* @var $return MenuItems */
67  $return = $event->getValue();
68 
69  ksort($plugins_with_settings);
70  $priority = 0;
71  foreach ($plugins_with_settings as $plugin_item) {
72  $priority += 10;
73  $plugin_item['priority'] = $priority;
74  $return[] = \ElggMenuItem::factory($plugin_item);
75  }
76 
77  return $return;
78  }
79 
87  public static function registerUserSettings(\Elgg\Event $event) {
89  if (!$user instanceof \ElggUser || !elgg_in_context('settings') || !$user->canEdit()) {
90  return;
91  }
92 
93  /* @var $return MenuItems */
94  $return = $event->getValue();
95 
96  $return[] = \ElggMenuItem::factory([
97  'name' => '1_account',
98  'text' => elgg_echo('usersettings:user:opt:linktext'),
99  'href' => elgg_generate_url('settings:account', [
100  'username' => $user->username,
101  ]),
102  'section' => 'configure',
103  ]);
104 
105  $return[] = \ElggMenuItem::factory([
106  'name' => '1_notifications',
107  'text' => elgg_echo('usersettings:notifications:menu:page'),
108  'href' => elgg_generate_url('settings:notifications', [
109  'username' => $user->username,
110  ]),
111  'section' => 'configure',
112  ]);
113 
114  $return[] = \ElggMenuItem::factory([
115  'name' => '1_statistics',
116  'text' => elgg_echo('usersettings:statistics:opt:linktext'),
117  'href' => elgg_generate_url('settings:statistics', [
118  'username' => $user->username,
119  ]),
120  'section' => 'configure',
121  ]);
122 
123  if (elgg_get_config('trash_enabled')) {
124  $return[] = \ElggMenuItem::factory([
125  'name' => '1_trash',
126  'text' => elgg_echo('trash:menu:page'),
127  'href' => elgg_generate_url('trash:owner', [
128  'username' => $user->username,
129  ]),
130  'section' => 'configure',
131  ]);
132  }
133 
134  return $return;
135  }
136 
144  public static function registerUserSettingsPlugins(\Elgg\Event $event) {
146  if (!$user instanceof \ElggUser || !elgg_in_context('settings') || !$user->canEdit()) {
147  return;
148  }
149 
150  /* @var $return MenuItems */
151  $return = $event->getValue();
152 
153  $return[] = \ElggMenuItem::factory([
154  'name' => '1_plugins',
155  'text' => elgg_echo('usersettings:plugins:opt:linktext'),
156  'href' => false,
157  'section' => 'configure',
158  'show_with_empty_children' => false,
159  ]);
160 
161  $active_plugins = elgg_get_plugins();
162  foreach ($active_plugins as $plugin) {
163  $plugin_id = $plugin->getID();
164  if (!elgg_view_exists("plugins/{$plugin_id}/usersettings")) {
165  continue;
166  }
167 
168  $title = $plugin->getDisplayName();
169  if (elgg_language_key_exists("{$plugin_id}:usersettings:title")) {
170  $title = elgg_echo("{$plugin_id}:usersettings:title");
171  }
172 
173  $return[] = \ElggMenuItem::factory([
174  'name' => $plugin_id,
175  'text' => $title,
176  'href' => elgg_generate_url('settings:tools', [
177  'username' => $user->username,
178  'plugin_id' => $plugin_id,
179  ]),
180  'parent_name' => '1_plugins',
181  'section' => 'configure',
182  ]);
183  }
184 
185  return $return;
186  }
187 }
elgg_get_plugins(string $status= 'active')
Returns an ordered list of plugins.
Definition: plugins.php:55
$plugin
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
elgg_in_context(string $context)
Check if this context exists anywhere in the stack.
Definition: context.php:78
$title
Definition: generic.php:50
Register menu items for the page menu.
Definition: Page.php:14
static registerUserSettings(\Elgg\Event $event)
Register menu items for the user settings.
Definition: Page.php:87
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
static factory(array $options)
Create an ElggMenuItem from an associative array.
$plugin_id
Remove all user and plugin settings from the give plugin ID.
Definition: remove.php:8
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
elgg_language_key_exists(string $key, string $language= 'en')
Check if a given language key exists.
Definition: languages.php:44
$user
Definition: ban.php:7
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
elgg_get_current_route()
Get the route for the current request.
Definition: pagehandler.php:88
static registerAdminPluginSettings(\Elgg\Event $event)
Register links to the plugin settings admin section.
Definition: Page.php:25
elgg_generate_url(string $name, array $parameters=[])
Generate a URL for named route.
if(!$plugin) $plugin_name
Definition: save.php:25
static registerUserSettingsPlugins(\Elgg\Event $event)
Register menu items for the user plugin settings.
Definition: Page.php:144
elgg_view_exists(string $view, string $viewtype= '', bool $recurse=true)
Returns whether the specified view exists.
Definition: views.php:131
$priority
Models an event passed to event handlers.
Definition: Event.php:11