1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Elgg navigation library |
4
|
|
|
* Functions for managing menus and other navigational elements |
5
|
|
|
* |
6
|
|
|
* Breadcrumbs |
7
|
|
|
* Elgg uses a breadcrumb stack. The page handlers (controllers in MVC terms) |
8
|
|
|
* push the breadcrumb links onto the stack. @see elgg_push_breadcrumb() |
9
|
|
|
* |
10
|
|
|
* |
11
|
|
|
* Pagination |
12
|
|
|
* Automatically handled by Elgg when using elgg_list_entities* functions. |
13
|
|
|
* @see elgg_list_entities() |
14
|
|
|
* |
15
|
|
|
* |
16
|
|
|
* Tabs |
17
|
|
|
* @see navigation/tabs view |
18
|
|
|
* |
19
|
|
|
* |
20
|
|
|
* Menus |
21
|
|
|
* Elgg uses a single interface to manage its menus. Menu items are added with |
22
|
|
|
* {@link elgg_register_menu_item()}. This is generally used for menus that |
23
|
|
|
* appear only once per page. For dynamic menus (such as the hover |
24
|
|
|
* menu for user's avatar), a plugin hook is emitted when the menu is being |
25
|
|
|
* created. The hook is 'register', 'menu:<menu_name>'. For more details on this, |
26
|
|
|
* @see elgg_view_menu(). |
27
|
|
|
* |
28
|
|
|
* Menus supported by the Elgg core |
29
|
|
|
* Standard menus: |
30
|
|
|
* site Site navigation shown on every page. |
31
|
|
|
* page Page menu usually shown in a sidebar. Uses Elgg's context. |
32
|
|
|
* topbar Topbar menu shown on every page. The default has two sections. |
33
|
|
|
* footer Like the topbar but in the footer. |
34
|
|
|
* |
35
|
|
|
* Dynamic menus (also called just-in-time menus): |
36
|
|
|
* user_hover Avatar hover menu. The user entity is passed as a parameter. |
37
|
|
|
* entity The set of links shown in the summary of an entity. |
38
|
|
|
* river Links shown on river items. |
39
|
|
|
* owner_block Links shown for a user or group in their owner block. |
40
|
|
|
* filter The tab filter for content (all, mine, friends) |
41
|
|
|
* title The buttons shown next to a content title. |
42
|
|
|
* longtext The links shown above the input/longtext view. |
43
|
|
|
* login Menu of links at bottom of login box |
44
|
|
|
* |
45
|
|
|
* @package Elgg.Core |
46
|
|
|
* @subpackage Navigation |
47
|
|
|
*/ |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Register an item for an Elgg menu |
51
|
|
|
* |
52
|
|
|
* @warning Generally you should not use this in response to the plugin hook: |
53
|
|
|
* 'register', 'menu:<menu_name>'. If you do, you may end up with many incorrect |
54
|
|
|
* links on a dynamic menu. |
55
|
|
|
* |
56
|
|
|
* @warning A menu item's name must be unique per menu. If more than one menu |
57
|
|
|
* item with the same name are registered, the last menu item takes priority. |
58
|
|
|
* |
59
|
|
|
* @see elgg_view_menu() for the plugin hooks available for modifying a menu as |
60
|
|
|
* it is being rendered. |
61
|
|
|
* |
62
|
|
|
* @see ElggMenuItem::factory() is used to turn an array value of $menu_item into an |
63
|
|
|
* ElggMenuItem object. |
64
|
|
|
* |
65
|
|
|
* @param string $menu_name The name of the menu: site, page, userhover, |
66
|
|
|
* userprofile, groupprofile, or any custom menu |
67
|
|
|
* @param mixed $menu_item A \ElggMenuItem object or an array of options in format: |
68
|
|
|
* name => STR Menu item identifier (required) |
69
|
|
|
* text => STR Menu item display text as HTML (required) |
70
|
|
|
* href => STR Menu item URL (required) |
71
|
|
|
* false = do not create a link. |
72
|
|
|
* null = current URL. |
73
|
|
|
* "" = current URL. |
74
|
|
|
* "/" = site home page. |
75
|
|
|
* @warning If href is false, the <a> tag will |
76
|
|
|
* not appear, so the link_class will not apply. If you |
77
|
|
|
* put <a> tags in manually through the 'text' option |
78
|
|
|
* the default CSS selector .elgg-menu-$menu > li > a |
79
|
|
|
* may affect formatting. Wrap in a <span> if it does.) |
80
|
|
|
* contexts => ARR Page context strings |
81
|
|
|
* section => STR Menu section identifier |
82
|
|
|
* title => STR Menu item tooltip |
83
|
|
|
* selected => BOOL Is this menu item currently selected |
84
|
|
|
* parent_name => STR Identifier of the parent menu item |
85
|
|
|
* link_class => STR A class or classes for the <a> tag |
86
|
|
|
* item_class => STR A class or classes for the <li> tag |
87
|
|
|
* deps => STR One or more AMD modules to require |
88
|
|
|
* |
89
|
|
|
* Additional options that the view output/url takes can be |
90
|
|
|
* passed in the array. Custom options can be added by using |
91
|
|
|
* the 'data' key with the value being an associative array. |
92
|
|
|
* |
93
|
|
|
* @return bool False if the item could not be added |
94
|
|
|
* @since 1.8.0 |
95
|
|
|
*/ |
96
|
|
|
function elgg_register_menu_item($menu_name, $menu_item) { |
97
|
34 |
|
if (is_array($menu_item)) { |
98
|
34 |
|
$options = $menu_item; |
99
|
34 |
|
$menu_item = \ElggMenuItem::factory($options); |
100
|
34 |
|
if (!$menu_item) { |
|
|
|
|
101
|
|
|
$menu_item_name = elgg_extract('name', $options, 'MISSING NAME'); |
102
|
|
|
elgg_log("Unable to add menu item '{$menu_item_name}' to '$menu_name' menu", 'WARNING'); |
103
|
|
|
return false; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
34 |
|
if (!$menu_item instanceof ElggMenuItem) { |
108
|
|
|
elgg_log('Second argument of elgg_register_menu_item() must be an instance of ' |
109
|
|
|
. 'ElggMenuItem or an array of menu item factory options', 'ERROR'); |
110
|
|
|
return false; |
111
|
|
|
} |
112
|
|
|
|
113
|
34 |
|
$menus = _elgg_config()->menus; |
114
|
34 |
|
if (!$menus) { |
115
|
21 |
|
$menus = []; |
116
|
|
|
} |
117
|
|
|
|
118
|
34 |
|
$menus[$menu_name][] = $menu_item; |
119
|
34 |
|
_elgg_config()->menus = $menus; |
120
|
|
|
|
121
|
34 |
|
return true; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Remove an item from a menu |
126
|
|
|
* |
127
|
|
|
* @param string $menu_name The name of the menu |
128
|
|
|
* @param string $item_name The unique identifier for this menu item |
129
|
|
|
* |
130
|
|
|
* @return \ElggMenuItem|null |
131
|
|
|
* @since 1.8.0 |
132
|
|
|
*/ |
133
|
|
|
function elgg_unregister_menu_item($menu_name, $item_name) { |
134
|
|
|
$menus = _elgg_config()->menus; |
135
|
|
|
if (!$menus) { |
136
|
|
|
return null; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
foreach ($menus[$menu_name] as $index => $menu_object) { |
140
|
|
|
/* @var \ElggMenuItem $menu_object */ |
141
|
|
|
if ($menu_object instanceof ElggMenuItem && $menu_object->getName() == $item_name) { |
142
|
|
|
$item = $menus[$menu_name][$index]; |
143
|
|
|
unset($menus[$menu_name][$index]); |
144
|
|
|
elgg_set_config('menus', $menus); |
145
|
|
|
return $item; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return null; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Check if a menu item has been registered |
154
|
|
|
* |
155
|
|
|
* @param string $menu_name The name of the menu |
156
|
|
|
* @param string $item_name The unique identifier for this menu item |
157
|
|
|
* |
158
|
|
|
* @return bool |
159
|
|
|
* @since 1.8.0 |
160
|
|
|
*/ |
161
|
|
|
function elgg_is_menu_item_registered($menu_name, $item_name) { |
162
|
|
|
$menus = _elgg_config()->menus; |
163
|
|
|
if (!$menus) { |
164
|
|
|
return false; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
if (!isset($menus[$menu_name])) { |
168
|
|
|
return false; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
foreach ($menus[$menu_name] as $menu_object) { |
172
|
|
|
/* @var \ElggMenuItem $menu_object */ |
173
|
|
|
if ($menu_object->getName() == $item_name) { |
174
|
|
|
return true; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
return false; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get a menu item registered for a menu |
183
|
|
|
* |
184
|
|
|
* @param string $menu_name The name of the menu |
185
|
|
|
* @param string $item_name The unique identifier for this menu item |
186
|
|
|
* |
187
|
|
|
* @return ElggMenuItem|null |
188
|
|
|
* @since 1.9.0 |
189
|
|
|
*/ |
190
|
|
|
function elgg_get_menu_item($menu_name, $item_name) { |
191
|
|
|
$menus = _elgg_config()->menus; |
192
|
|
|
if (!$menus) { |
193
|
|
|
return null; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
if (!isset($menus[$menu_name])) { |
197
|
|
|
return null; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
foreach ($menus[$menu_name] as $index => $menu_object) { |
201
|
|
|
/* @var \ElggMenuItem $menu_object */ |
202
|
|
|
if ($menu_object->getName() == $item_name) { |
203
|
|
|
return $menus[$menu_name][$index]; |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
return null; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Convenience function for registering a button to the title menu |
212
|
|
|
* |
213
|
|
|
* The URL must be $handler/$name/$guid where $guid is the guid of the page owner. |
214
|
|
|
* The label of the button is "$handler:$name" so that must be defined in a |
215
|
|
|
* language file. |
216
|
|
|
* |
217
|
|
|
* This is used primarily to support adding an add content button |
218
|
|
|
* |
219
|
|
|
* @param string $handler The handler to use or null to autodetect from context |
220
|
|
|
* @param string $name Name of the button (defaults to 'add') |
221
|
|
|
* @param string $entity_type Optional entity type to be added (used to verify canWriteToContainer permission) |
222
|
|
|
* @param string $entity_subtype Optional entity subtype to be added (used to verify canWriteToContainer permission) |
223
|
|
|
* @return void |
224
|
|
|
* @since 1.8.0 |
225
|
|
|
*/ |
226
|
|
|
function elgg_register_title_button($handler = null, $name = 'add', $entity_type = 'all', $entity_subtype = 'all') { |
227
|
|
|
|
228
|
|
|
$owner = elgg_get_page_owner_entity(); |
229
|
|
|
if (!$owner) { |
|
|
|
|
230
|
|
|
// noone owns the page so this is probably an all site list page |
231
|
|
|
$owner = elgg_get_logged_in_user_entity(); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
if (($name === 'add') && ($owner instanceof ElggUser)) { |
235
|
|
|
// make sure the add link goes to the current logged in user, not the page owner |
236
|
|
|
$logged_in_user = elgg_get_logged_in_user_entity(); |
237
|
|
|
if (!empty($logged_in_user) && ($logged_in_user->guid !== $owner->guid)) { |
238
|
|
|
// change the 'owner' for the link to the current logged in user |
239
|
|
|
$owner = $logged_in_user; |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
// do we have an owner and is the current user allowed to create content here |
244
|
|
|
if (!$owner || !$owner->canWriteToContainer(0, $entity_type, $entity_subtype)) { |
245
|
|
|
return; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
$href = elgg_generate_url("$name:$entity_type:$entity_subtype", [ |
249
|
|
|
'guid' => $owner->guid, |
250
|
|
|
]); |
251
|
|
|
if (!$href) { |
252
|
|
|
if (!$handler) { |
|
|
|
|
253
|
|
|
$handler = elgg_get_context(); |
254
|
|
|
} |
255
|
|
|
$href = "$handler/$name/$owner->guid"; |
256
|
|
|
$label = elgg_echo("$handler:$name"); |
257
|
|
|
} else { |
258
|
|
|
$label = elgg_echo("$name:$entity_type:$entity_subtype"); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
// register the title menu item |
262
|
|
|
elgg_register_menu_item('title', [ |
263
|
|
|
'name' => $name, |
264
|
|
|
'icon' => $name === 'add' ? 'plus' : '', |
265
|
|
|
'href' => $href, |
266
|
|
|
'text' => $label, |
267
|
|
|
'link_class' => 'elgg-button elgg-button-action', |
268
|
|
|
]); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Adds a breadcrumb to the breadcrumbs stack. |
273
|
|
|
* |
274
|
|
|
* See elgg_get_breadcrumbs() and the navigation/breadcrumbs view. |
275
|
|
|
* |
276
|
|
|
* @param string $text The title to display. During rendering this is HTML encoded. |
277
|
|
|
* @param string $href Optional. The href for the title. During rendering links are |
278
|
|
|
* normalized via elgg_normalize_url(). |
279
|
|
|
* |
280
|
|
|
* @return void |
281
|
|
|
* @since 1.8.0 |
282
|
|
|
* @see elgg_get_breadcrumbs() |
283
|
|
|
*/ |
284
|
|
|
function elgg_push_breadcrumb($text, $href = null) { |
285
|
|
|
$breadcrumbs = (array) _elgg_config()->breadcrumbs; |
286
|
|
|
|
287
|
|
|
$breadcrumbs[] = [ |
288
|
|
|
'text' => $text, |
289
|
|
|
'href' => $href, |
290
|
|
|
]; |
291
|
|
|
|
292
|
|
|
elgg_set_config('breadcrumbs', $breadcrumbs); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Removes last breadcrumb entry. |
297
|
|
|
* |
298
|
|
|
* @return array popped breadcrumb array or empty array |
299
|
|
|
* @since 1.8.0 |
300
|
|
|
*/ |
301
|
|
|
function elgg_pop_breadcrumb() { |
302
|
|
|
$breadcrumbs = (array) _elgg_config()->breadcrumbs; |
303
|
|
|
|
304
|
|
|
if (empty($breadcrumbs)) { |
305
|
|
|
return []; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
$popped = array_pop($breadcrumbs); |
309
|
|
|
elgg_set_config('breadcrumbs', $breadcrumbs); |
310
|
|
|
|
311
|
|
|
return $popped; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* Returns all breadcrumbs as an array |
316
|
|
|
* <code> |
317
|
|
|
* [ |
318
|
|
|
* [ |
319
|
|
|
* 'text' => 'Breadcrumb title', |
320
|
|
|
* 'href' => '/path/to/page', |
321
|
|
|
* ] |
322
|
|
|
* ] |
323
|
|
|
* </code> |
324
|
|
|
* |
325
|
|
|
* Breadcrumbs are filtered through the plugin hook [prepare, breadcrumbs] before |
326
|
|
|
* being returned. |
327
|
|
|
* |
328
|
|
|
* @param array $breadcrumbs An array of breadcrumbs |
329
|
|
|
* If set, will override breadcrumbs in the stack |
330
|
|
|
* @return array |
331
|
|
|
* @since 1.8.0 |
332
|
|
|
* @see elgg_prepare_breadcrumbs() |
333
|
|
|
*/ |
334
|
|
|
function elgg_get_breadcrumbs(array $breadcrumbs = null) { |
335
|
|
|
if (!isset($breadcrumbs)) { |
336
|
|
|
// if no crumbs set, still allow hook to populate it |
337
|
|
|
$breadcrumbs = (array) _elgg_config()->breadcrumbs; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
if (!is_array($breadcrumbs)) { |
|
|
|
|
341
|
|
|
_elgg_services()->logger->error(__FUNCTION__ . ' expects breadcrumbs as an array'); |
342
|
|
|
$breadcrumbs = []; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
$params = [ |
346
|
|
|
'breadcrumbs' => $breadcrumbs, |
347
|
|
|
]; |
348
|
|
|
|
349
|
|
|
$params['identifier'] = _elgg_services()->request->getFirstUrlSegment(); |
350
|
|
|
$params['segments'] = _elgg_services()->request->getUrlSegments(); |
351
|
|
|
array_shift($params['segments']); |
352
|
|
|
|
353
|
|
|
$breadcrumbs = elgg_trigger_plugin_hook('prepare', 'breadcrumbs', $params, $breadcrumbs); |
354
|
|
|
if (!is_array($breadcrumbs)) { |
|
|
|
|
355
|
|
|
_elgg_services()->logger->error('"prepare, breadcrumbs" hook must return an array of breadcrumbs'); |
356
|
|
|
return []; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
foreach ($breadcrumbs as $key => $breadcrumb) { |
360
|
|
|
$text = elgg_extract('text', $breadcrumb, elgg_extract('title', $breadcrumb)); |
361
|
|
|
if (isset($breadcrumb['link'])) { |
362
|
|
|
elgg_deprecated_notice("Breadcrumb [{$text}] requires 'href' instead of 'link' set in the configuration", '3.0'); |
363
|
|
|
|
364
|
|
|
$breadcrumbs[$key]['href'] = $breadcrumb['link']; |
365
|
|
|
unset($breadcrumbs[$key]['link']); |
366
|
|
|
} |
367
|
|
|
if (isset($breadcrumb['title'])) { |
368
|
|
|
elgg_deprecated_notice("Breadcrumb [{$text}] requires 'text' instead of 'title' set in the configuration", '3.0'); |
369
|
|
|
|
370
|
|
|
$breadcrumbs[$key]['text'] = $breadcrumb['title']; |
371
|
|
|
unset($breadcrumbs[$key]['title']); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
// adds name for usage in menu items |
375
|
|
|
if (!isset($breadcrumb['name'])) { |
376
|
|
|
$breadcrumbs[$key]['name'] = $key; |
377
|
|
|
} |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
return $breadcrumbs; |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Prepare breadcrumbs before display. This turns titles into 100-character excerpts, and also |
385
|
|
|
* removes the last crumb if it's not a link. |
386
|
|
|
* |
387
|
|
|
* @param string $hook "prepare" |
388
|
|
|
* @param string $type "breadcrumbs" |
389
|
|
|
* @param array $breadcrumbs Breadcrumbs to be altered |
390
|
|
|
* @param array $params Hook parameters |
391
|
|
|
* |
392
|
|
|
* @return array |
393
|
|
|
* @since 1.11 |
394
|
|
|
*/ |
395
|
|
|
function elgg_prepare_breadcrumbs($hook, $type, $breadcrumbs, $params) { |
|
|
|
|
396
|
|
|
// remove last crumb if not a link |
397
|
|
|
$last_crumb = end($breadcrumbs); |
398
|
|
|
if (empty($last_crumb['href'])) { |
399
|
|
|
array_pop($breadcrumbs); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
// apply excerpt to text |
403
|
|
|
foreach (array_keys($breadcrumbs) as $i) { |
404
|
|
|
$breadcrumbs[$i]['text'] = elgg_get_excerpt($breadcrumbs[$i]['text'], 100); |
405
|
|
|
} |
406
|
|
|
return $breadcrumbs; |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* Resolves and pushes entity breadcrumbs based on named routes |
411
|
|
|
* |
412
|
|
|
* @param ElggEntity $entity Entity |
413
|
|
|
* @param bool $link_self Use entity link in the last crumb |
414
|
|
|
* |
415
|
|
|
* @return void |
416
|
|
|
*/ |
417
|
|
|
function elgg_push_entity_breadcrumbs(ElggEntity $entity, $link_self = true) { |
418
|
|
|
|
419
|
|
|
$container = $entity->getContainerEntity() ? : null; |
420
|
|
|
elgg_push_collection_breadcrumbs($entity->type, $entity->subtype, $container); |
421
|
|
|
|
422
|
|
|
$entity_url = $link_self ? $entity->getURL() : null; |
423
|
|
|
elgg_push_breadcrumb($entity->getDisplayName(), $entity_url); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Resolves and pushes collection breadcrumbs for a container |
428
|
|
|
* |
429
|
|
|
* @param string $entity_type Entity type in the collection |
430
|
|
|
* @param string $entity_subtype Entity subtype in the collection |
431
|
|
|
* @param ElggEntity|null $container Container/page owner entity |
432
|
|
|
* @param bool $friends Collection belongs to container's friends? |
433
|
|
|
* |
434
|
|
|
* @return void |
435
|
|
|
*/ |
436
|
|
|
function elgg_push_collection_breadcrumbs($entity_type, $entity_subtype, ElggEntity $container = null, $friends = false) { |
437
|
|
|
|
438
|
|
|
if ($container) { |
439
|
|
|
elgg_push_breadcrumb($container->getDisplayName(), $container->getURL()); |
440
|
|
|
|
441
|
|
|
if ($friends) { |
442
|
|
|
$collection_route = "collection:$entity_type:$entity_subtype:friends"; |
443
|
|
|
} else if ($container instanceof ElggUser) { |
444
|
|
|
$collection_route = "collection:$entity_type:$entity_subtype:owner"; |
445
|
|
|
} else if ($container instanceof ElggGroup) { |
446
|
|
|
$collection_route = "collection:$entity_type:$entity_subtype:group"; |
447
|
|
|
} else { |
448
|
|
|
$collection_route = "collection:$entity_type:$entity_subtype:container"; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
$parameters = _elgg_services()->router->resolveRouteParameters($collection_route, $container); |
452
|
|
|
if ($parameters) { |
|
|
|
|
453
|
|
|
$label = elgg_echo("collection:$entity_type:$entity_subtype"); |
454
|
|
|
if ($friends) { |
455
|
|
|
if (elgg_language_key_exists("collection:$entity_type:$entity_subtype:friends")) { |
456
|
|
|
$label = elgg_echo("collection:$entity_type:$entity_subtype:friends"); |
457
|
|
|
} else { |
458
|
|
|
$label = elgg_echo('collection:friends', [$label]); |
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
$collection_url = elgg_generate_url($collection_route, $parameters); |
462
|
|
|
elgg_push_breadcrumb($label, $collection_url); |
463
|
1 |
|
} |
464
|
|
|
} else { |
465
|
1 |
|
$label = elgg_echo("collection:$entity_type:$entity_subtype"); |
466
|
|
|
$collection_url = elgg_generate_url("collection:$entity_type:$entity_subtype:all"); |
467
|
|
|
elgg_push_breadcrumb($label, $collection_url); |
468
|
|
|
} |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* Returns default filter tabs (All, Mine, Friends) for the user |
473
|
|
|
* |
474
|
|
|
* @param string $context Context to be used to prefix tab URLs |
475
|
1 |
|
* @param string $selected Name of the selected tab |
476
|
|
|
* @param ElggUser $user User who owns the layout (defaults to logged in user) |
477
|
|
|
* @param array $vars Additional vars |
478
|
|
|
* @return ElggMenuItem[] |
479
|
|
|
* @since 2.3 |
480
|
|
|
*/ |
481
|
|
|
function elgg_get_filter_tabs($context = null, $selected = null, ElggUser $user = null, array $vars = []) { |
482
|
|
|
|
483
|
1 |
|
if (!isset($selected)) { |
484
|
|
|
$selected = 'all'; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
if (!$user) { |
488
|
|
|
$user = elgg_get_logged_in_user_entity(); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
$items = []; |
492
|
|
|
if ($user) { |
493
|
|
|
$items[] = ElggMenuItem::factory([ |
494
|
|
|
'name' => 'all', |
495
|
|
|
'text' => elgg_echo('all'), |
496
|
|
|
'href' => (isset($vars['all_link'])) ? $vars['all_link'] : "$context/all", |
497
|
|
|
'selected' => ($selected == 'all'), |
498
|
|
|
'priority' => 200, |
499
|
|
|
]); |
500
|
|
|
$items[] = ElggMenuItem::factory([ |
501
|
|
|
'name' => 'mine', |
502
|
1 |
|
'text' => elgg_echo('mine'), |
503
|
|
|
'href' => (isset($vars['mine_link'])) ? $vars['mine_link'] : "$context/owner/{$user->username}", |
504
|
1 |
|
'selected' => ($selected == 'mine'), |
505
|
|
|
'priority' => 300, |
506
|
|
|
]); |
507
|
1 |
|
} |
508
|
1 |
|
|
509
|
1 |
|
$params = [ |
510
|
1 |
|
'selected' => $selected, |
511
|
|
|
'user' => $user, |
512
|
|
|
'vars' => $vars, |
513
|
|
|
]; |
514
|
1 |
|
$items = _elgg_services()->hooks->trigger('filter_tabs', $context, $params, $items); |
515
|
1 |
|
|
516
|
|
|
return $items; |
517
|
1 |
|
} |
518
|
1 |
|
|
519
|
|
|
/** |
520
|
|
|
* Init site menu |
521
|
|
|
* |
522
|
1 |
|
* Registers custom menu items |
523
|
|
|
* |
524
|
1 |
|
* @param string $hook 'register' |
525
|
1 |
|
* @param string $type 'menu:site' |
526
|
1 |
|
* @param ElggMenuItem[] $return Menu |
527
|
|
|
* @param array $params Hook params |
528
|
|
|
* |
529
|
1 |
|
* @return ElggMenuItem[] |
530
|
|
|
* |
531
|
|
|
* @access private |
532
|
|
|
*/ |
533
|
|
|
function _elgg_site_menu_init($hook, $type, $return, $params) { |
|
|
|
|
534
|
1 |
|
$custom_menu_items = elgg_get_config('site_custom_menu_items'); |
535
|
1 |
|
|
536
|
1 |
|
if ($custom_menu_items) { |
537
|
1 |
|
// add custom menu items |
538
|
|
|
$n = 1; |
539
|
1 |
|
foreach ($custom_menu_items as $title => $url) { |
540
|
|
|
$item = new ElggMenuItem("custom$n", $title, $url); |
541
|
|
|
$return[] = $item; |
542
|
|
|
$n++; |
543
|
|
|
} |
544
|
1 |
|
} |
545
|
|
|
|
546
|
1 |
|
if (elgg_is_logged_in() && elgg_is_active_plugin('dashboard')) { |
547
|
|
|
$return[] = ElggMenuItem::factory([ |
548
|
1 |
|
'name' => 'dashboard', |
549
|
|
|
'text' => elgg_echo('dashboard'), |
550
|
1 |
|
'href' => 'dashboard', |
551
|
1 |
|
]); |
552
|
1 |
|
} |
553
|
|
|
|
554
|
|
|
return $return; |
555
|
1 |
|
} |
556
|
1 |
|
|
557
|
1 |
|
/** |
558
|
1 |
|
* Set up the site menu |
559
|
1 |
|
* |
560
|
1 |
|
* Handles default, featured, and custom menu items |
561
|
1 |
|
* |
562
|
|
|
* @param string $hook 'prepare' |
563
|
|
|
* @param string $type 'menu:site' |
564
|
1 |
|
* @param ElggMenuItem[] $return current return value |
565
|
1 |
|
* @param array $params supplied params |
566
|
|
|
* |
567
|
|
|
* @return ElggMenuItem[] |
568
|
1 |
|
* |
569
|
|
|
* @access private |
570
|
1 |
|
*/ |
571
|
|
|
function _elgg_site_menu_setup($hook, $type, $return, $params) { |
|
|
|
|
572
|
|
|
|
573
|
1 |
|
$featured_menu_names = array_values((array) elgg_get_config('site_featured_menu_names')); |
574
|
|
|
|
575
|
1 |
|
$registered = $return['default']; |
576
|
|
|
/* @var ElggMenuItem[] $registered */ |
577
|
|
|
|
578
|
|
|
$has_selected = false; |
579
|
|
|
$priority = 500; |
580
|
|
|
foreach ($registered as &$item) { |
581
|
|
|
if (in_array($item->getName(), $featured_menu_names)) { |
582
|
|
|
$featured_index = array_search($item->getName(), $featured_menu_names); |
583
|
|
|
$item->setPriority($featured_index); |
|
|
|
|
584
|
|
|
} else { |
585
|
|
|
$item->setPriority($priority); |
586
|
|
|
$priority++; |
587
|
|
|
} |
588
|
|
|
if ($item->getSelected()) { |
589
|
|
|
$has_selected = true; |
590
|
2 |
|
} |
591
|
|
|
} |
592
|
2 |
|
|
593
|
1 |
|
if (!$has_selected) { |
594
|
1 |
|
$is_selected = function ($item) { |
595
|
1 |
|
$current_url = current_page_url(); |
596
|
1 |
|
if (strpos($item->getHref(), elgg_get_site_url()) === 0) { |
597
|
1 |
|
if ($item->getName() == elgg_get_context()) { |
598
|
|
|
return true; |
599
|
1 |
|
} |
600
|
|
|
if ($item->getHref() == $current_url) { |
601
|
|
|
return true; |
602
|
|
|
} |
603
|
|
|
} |
604
|
2 |
|
|
605
|
2 |
|
return false; |
606
|
|
|
}; |
607
|
|
|
foreach ($registered as &$item) { |
608
|
|
|
if ($is_selected($item)) { |
609
|
|
|
$item->setSelected(true); |
610
|
|
|
break; |
611
|
|
|
} |
612
|
|
|
} |
613
|
2 |
|
} |
614
|
|
|
|
615
|
|
|
usort($registered, [\ElggMenuBuilder::class, 'compareByPriority']); |
616
|
|
|
|
617
|
|
|
$max_display_items = 5; |
618
|
|
|
|
619
|
|
|
$num_menu_items = count($registered); |
620
|
|
|
|
621
|
|
|
$more = []; |
622
|
|
|
if ($max_display_items && $num_menu_items > ($max_display_items + 1)) { |
623
|
|
|
$more = array_splice($registered, $max_display_items); |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
if (!empty($more)) { |
627
|
|
|
$dropdown = ElggMenuItem::factory([ |
628
|
|
|
'name' => 'more', |
629
|
1 |
|
'href' => 'javascript:void(0);', |
630
|
1 |
|
'text' => elgg_echo('more'), |
631
|
|
|
'icon_alt' => 'angle-down', |
632
|
|
|
'priority' => 999, |
633
|
|
|
]); |
634
|
1 |
|
|
635
|
1 |
|
foreach ($more as &$item) { |
636
|
1 |
|
$item->setParentName('more'); |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
$dropdown->setChildren($more); |
640
|
|
|
|
641
|
|
|
$registered[] = $dropdown; |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
$return['default'] = $registered; |
645
|
|
|
|
646
|
|
|
return $return; |
|
|
|
|
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* Prepare page menu |
651
|
|
|
* Sets the display child menu option to "toggle" if not set |
652
|
|
|
* Recursively marks parents of the selected item as selected (expanded) |
653
|
|
|
* |
654
|
|
|
* @param \Elgg\Hook $hook 'prepare', 'menu:page' |
655
|
|
|
* |
656
|
|
|
* @return ElggMenuItem[] |
657
|
|
|
* |
658
|
|
|
* @access private |
659
|
|
|
*/ |
660
|
|
|
function _elgg_page_menu_setup(\Elgg\Hook $hook) { |
661
|
|
|
$menu = $hook->getValue(); |
662
|
|
|
|
663
|
|
|
foreach ($menu as $section => $menu_items) { |
664
|
|
|
foreach ($menu_items as $menu_item) { |
665
|
|
|
if ($menu_item instanceof ElggMenuItem) { |
666
|
|
|
$child_menu_vars = $menu_item->getChildMenuOptions(); |
667
|
|
|
if (empty($child_menu_vars['display'])) { |
668
|
|
|
$child_menu_vars['display'] = 'toggle'; |
669
|
|
|
} |
670
|
|
|
$menu_item->setChildMenuOptions($child_menu_vars); |
671
|
|
|
} |
672
|
|
|
} |
673
|
|
|
} |
674
|
|
|
|
675
|
|
|
$selected_item = $hook->getParam('selected_item'); |
676
|
|
|
if ($selected_item instanceof \ElggMenuItem) { |
677
|
|
|
$parent = $selected_item->getParent(); |
678
|
|
|
while ($parent instanceof \ElggMenuItem) { |
|
|
|
|
679
|
|
|
$parent->setSelected(); |
680
|
|
|
$parent = $parent->getParent(); |
681
|
2 |
|
} |
682
|
|
|
} |
683
|
2 |
|
|
684
|
2 |
|
return $menu; |
685
|
|
|
} |
686
|
|
|
|
687
|
|
|
/** |
688
|
2 |
|
* Entity menu is list of links and info on any entity |
689
|
2 |
|
* |
690
|
2 |
|
* @param string $hook 'register' |
691
|
2 |
|
* @param string $type 'menu:entity' |
692
|
|
|
* @param ElggMenuItem[] $return current return value |
693
|
2 |
|
* @param array $params supplied params |
694
|
|
|
* |
695
|
2 |
|
* @return void|ElggMenuItem[] |
696
|
2 |
|
* |
697
|
2 |
|
* @access private |
698
|
|
|
*/ |
699
|
|
|
function _elgg_entity_menu_setup($hook, $type, $return, $params) { |
|
|
|
|
700
|
|
|
$entity = elgg_extract('entity', $params); |
701
|
2 |
|
if (!($entity instanceof \ElggObject)) { |
702
|
|
|
return; |
703
|
2 |
|
} |
704
|
|
|
|
705
|
|
|
$handler = elgg_extract('handler', $params, false); |
706
|
|
|
if ($handler) { |
707
|
2 |
|
elgg_deprecated_notice("Using 'handler' in entity menu parameters is deprecated. Use named routes instead.", '3.0'); |
708
|
|
|
|
709
|
|
|
$edit_url = "$handler/edit/{$entity->guid}"; |
710
|
|
|
|
711
|
|
|
if (elgg_action_exists("$handler/delete")) { |
712
|
|
|
$action = "$handler/delete"; |
713
|
|
|
} else { |
714
|
|
|
$action = "entity/delete"; |
715
|
|
|
} |
716
|
|
|
$delete_url = elgg_generate_action_url($action, [ |
717
|
|
|
'guid' => $entity->guid, |
718
|
|
|
]); |
719
|
|
|
} else { |
720
|
1 |
|
$edit_url = elgg_generate_entity_url($entity, 'edit'); |
721
|
1 |
|
$delete_url = elgg_generate_action_url('entity/delete', [ |
722
|
|
|
'guid' => $entity->guid, |
723
|
|
|
]); |
724
|
|
|
} |
725
|
1 |
|
|
726
|
|
|
if ($entity->canEdit() && $edit_url) { |
727
|
|
|
$return[] = \ElggMenuItem::factory([ |
728
|
1 |
|
'name' => 'edit', |
729
|
1 |
|
'icon' => 'edit', |
730
|
1 |
|
'text' => elgg_echo('edit'), |
731
|
1 |
|
'title' => elgg_echo('edit:this'), |
732
|
1 |
|
'href' => $edit_url, |
733
|
|
|
'priority' => 900, |
734
|
|
|
]); |
735
|
1 |
|
} |
736
|
1 |
|
|
737
|
1 |
|
if ($entity->canDelete() && $delete_url) { |
738
|
|
|
$return[] = \ElggMenuItem::factory([ |
739
|
1 |
|
'name' => 'delete', |
740
|
1 |
|
'icon' => 'delete', |
741
|
|
|
'text' => elgg_echo('delete'), |
742
|
|
|
'title' => elgg_echo('delete:this'), |
743
|
|
|
'href' => $delete_url, |
744
|
|
|
'confirm' => elgg_echo('deleteconfirm'), |
745
|
|
|
'priority' => 950, |
746
|
|
|
]); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
return $return; |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
/** |
753
|
1 |
|
* Moves default menu items into a dropdown |
754
|
1 |
|
* |
755
|
1 |
|
* @tip Pass 'dropdown' => false to entity menu options to render the menu inline without a dropdown |
756
|
|
|
* |
757
|
1 |
|
* @param \Elgg\Hook $hook 'prepare', 'menu:entity'|'menu:river' |
758
|
1 |
|
* |
759
|
|
|
* @return void|ElggMenuItem[] |
760
|
|
|
* |
761
|
|
|
* @access private |
762
|
|
|
*/ |
763
|
|
|
function _elgg_menu_transform_to_dropdown(\Elgg\Hook $hook) { |
764
|
|
|
$result = $hook->getValue(); |
765
|
|
|
|
766
|
|
|
$is_dropdown = $hook->getParam('dropdown', true); |
767
|
|
|
if ($is_dropdown === false) { |
768
|
|
|
return; |
769
|
|
|
} |
770
|
|
|
|
771
|
1 |
|
$items = elgg_extract('default', $result); |
772
|
|
|
if (empty($items)) { |
773
|
|
|
return; |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
$result['default'] = [ |
777
|
|
|
\ElggMenuItem::factory([ |
778
|
|
|
'name' => 'entity-menu-toggle', |
779
|
|
|
'icon' => 'ellipsis-v', |
780
|
|
|
'href' => false, |
781
|
|
|
'text' => '', |
782
|
|
|
'child_menu' => [ |
783
|
|
|
'display' => 'dropdown', |
784
|
|
|
'data-position' => json_encode([ |
785
|
|
|
'at' => 'right bottom', |
786
|
|
|
'my' => 'right top', |
787
|
|
|
'collision' => 'fit fit', |
788
|
|
|
]), |
789
|
|
|
'class' => "elgg-{$hook->getParam('name')}-dropdown-menu", |
790
|
|
|
], |
791
|
|
|
'children' => $items, |
792
|
|
|
]), |
793
|
|
|
]; |
794
|
|
|
|
795
|
|
|
return $result; |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
/** |
799
|
|
|
* Entity navigation menu is previous/next link for an entity |
800
|
|
|
* |
801
|
|
|
* @param \Elgg\Hook $hook 'register' 'menu:entity_navigation' |
802
|
|
|
* |
803
|
|
|
* @return void|ElggMenuItem[] |
804
|
|
|
* |
805
|
|
|
* @access private |
806
|
|
|
*/ |
807
|
|
|
function _elgg_entity_navigation_menu_setup(\Elgg\Hook $hook) { |
808
|
|
|
$entity = $hook->getEntityParam(); |
809
|
|
|
if (!$entity) { |
810
|
|
|
return; |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
$return = $hook->getValue(); |
814
|
|
|
|
815
|
|
|
$options = [ |
816
|
|
|
'type' => $entity->getType(), |
817
|
|
|
'subtype' => $entity->getSubtype(), |
818
|
|
|
'container_guid' => $entity->container_guid, |
819
|
|
|
'wheres' => ["e.guid != {$entity->guid}"], |
820
|
|
|
'limit' => 1, |
821
|
|
|
]; |
822
|
|
|
|
823
|
|
|
$previous_options = $options; |
824
|
|
|
$previous_options['created_time_upper'] = $entity->time_created; |
825
|
|
|
$previous_options['order_by'] = 'e.time_created DESC, e.guid DESC'; |
826
|
|
|
|
827
|
|
|
$previous = elgg_get_entities($previous_options); |
828
|
|
|
if ($previous) { |
829
|
|
|
$previous = $previous[0]; |
830
|
|
|
$return[] = \ElggMenuItem::factory([ |
831
|
|
|
'name' => 'previous', |
832
|
|
|
'text' => elgg_echo('previous'), |
833
|
|
|
'href' => $previous->getUrl(), |
834
|
|
|
'title' => $previous->getDisplayName(), |
835
|
|
|
'icon' => 'angle-double-left', |
836
|
|
|
'link_class' => 'elgg-button elgg-button-outline', |
837
|
1 |
|
'priority' => 100, |
838
|
1 |
|
]); |
839
|
1 |
|
} |
840
|
1 |
|
|
841
|
1 |
|
$next_options = $options; |
842
|
1 |
|
$next_options['created_time_lower'] = $entity->time_created; |
843
|
|
|
$next_options['order_by'] = 'e.time_created ASC, e.guid ASC'; |
844
|
|
|
|
845
|
|
|
$next = elgg_get_entities($next_options); |
846
|
1 |
|
if ($next) { |
847
|
1 |
|
$next = $next[0]; |
848
|
1 |
|
$return[] = \ElggMenuItem::factory([ |
849
|
1 |
|
'name' => 'next', |
850
|
1 |
|
'text' => elgg_echo('next'), |
851
|
|
|
'href' => $next->getUrl(), |
852
|
|
|
'title' => $next->getDisplayName(), |
853
|
1 |
|
'icon_alt' => 'angle-double-right', |
854
|
|
|
'link_class' => 'elgg-button elgg-button-outline', |
855
|
|
|
'priority' => 800, |
856
|
|
|
]); |
857
|
|
|
} |
858
|
|
|
|
859
|
|
|
return $return; |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
/** |
863
|
|
|
* Widget menu is a set of widget controls |
864
|
|
|
* |
865
|
|
|
* @param string $hook 'register' |
866
|
|
|
* @param string $type 'menu:widget' |
867
|
|
|
* @param ElggMenuItem[] $return current return value |
868
|
|
|
* @param array $params supplied params |
869
|
|
|
* |
870
|
1 |
|
* @return void|ElggMenuItem[] |
871
|
1 |
|
* |
872
|
|
|
* @access private |
873
|
|
|
*/ |
874
|
|
|
function _elgg_widget_menu_setup($hook, $type, $return, $params) { |
|
|
|
|
875
|
|
|
|
876
|
|
|
$widget = elgg_extract('entity', $params); |
877
|
|
|
if (!($widget instanceof \ElggWidget)) { |
878
|
|
|
return; |
879
|
|
|
} |
880
|
|
|
|
881
|
|
|
if ($widget->canDelete()) { |
882
|
|
|
$return[] = \ElggMenuItem::factory([ |
883
|
|
|
'name' => 'delete', |
884
|
|
|
'text' => elgg_view_icon('delete-alt'), |
885
|
|
|
'title' => elgg_echo('widget:delete', [$widget->getTitle()]), |
886
|
|
|
'href' => "action/widgets/delete?widget_guid=$widget->guid", |
887
|
|
|
'is_action' => true, |
888
|
|
|
'link_class' => 'elgg-widget-delete-button', |
889
|
|
|
'id' => "elgg-widget-delete-button-$widget->guid", |
890
|
|
|
'data-elgg-widget-type' => $widget->handler, |
891
|
|
|
'priority' => 900, |
892
|
|
|
]); |
893
|
|
|
} |
894
|
|
|
|
895
|
|
|
$show_edit = elgg_extract('show_edit', $params, $widget->canEdit()); |
896
|
|
|
if ($show_edit) { |
897
|
|
|
$return[] = \ElggMenuItem::factory([ |
898
|
|
|
'name' => 'settings', |
899
|
|
|
'text' => elgg_view_icon('settings-alt'), |
900
|
|
|
'title' => elgg_echo('widget:edit'), |
901
|
|
|
'href' => "#widget-edit-$widget->guid", |
902
|
|
|
'link_class' => "elgg-widget-edit-button", |
903
|
31 |
|
'rel' => 'toggle', |
904
|
|
|
'priority' => 800, |
905
|
31 |
|
]); |
906
|
31 |
|
} |
907
|
|
|
|
908
|
31 |
|
return $return; |
909
|
|
|
} |
910
|
31 |
|
|
911
|
31 |
|
/** |
912
|
31 |
|
* Add the register and forgot password links to login menu |
913
|
31 |
|
* |
914
|
31 |
|
* @param string $hook 'register' |
915
|
31 |
|
* @param string $type 'menu:login' |
916
|
31 |
|
* @param ElggMenuItem[] $return current return value |
917
|
|
|
* @param array $params supplied params |
918
|
31 |
|
* |
919
|
|
|
* @return ElggMenuItem[] |
920
|
31 |
|
* |
921
|
31 |
|
* @access private |
922
|
31 |
|
*/ |
923
|
31 |
|
function _elgg_login_menu_setup($hook, $type, $return, $params) { |
|
|
|
|
924
|
31 |
|
|
925
|
31 |
|
if (_elgg_config()->allow_registration) { |
926
|
31 |
|
$return[] = \ElggMenuItem::factory([ |
927
|
31 |
|
'name' => 'register', |
928
|
|
|
'href' => elgg_get_registration_url(), |
929
|
|
|
'text' => elgg_echo('register'), |
930
|
|
|
'link_class' => 'registration_link', |
931
|
31 |
|
]); |
932
|
|
|
} |
933
|
|
|
|
934
|
|
|
$return[] = \ElggMenuItem::factory([ |
935
|
31 |
|
'name' => 'forgotpassword', |
936
|
31 |
|
'href' => elgg_generate_url('account:password:reset'), |
937
|
|
|
'text' => elgg_echo('user:password:lost'), |
938
|
|
|
'link_class' => 'forgot_link', |
939
|
|
|
]); |
940
|
|
|
|
941
|
|
|
return $return; |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
/** |
945
|
|
|
* Add the RSS link to the menu |
946
|
|
|
* |
947
|
|
|
* @param string $hook 'register' |
948
|
|
|
* @param string $type 'menu:footer' |
949
|
|
|
* @param ElggMenuItem[] $return current return value |
950
|
|
|
* @param array $params supplied params |
951
|
|
|
* |
952
|
|
|
* @return void|ElggMenuItem[] |
953
|
|
|
* |
954
|
|
|
* @access private |
955
|
|
|
*/ |
956
|
|
|
function _elgg_rss_menu_setup($hook, $type, $return, $params) { |
|
|
|
|
957
|
|
|
|
958
|
|
|
if (!elgg_is_logged_in()) { |
959
|
|
|
return; |
960
|
|
|
} |
961
|
|
|
|
962
|
18 |
|
if (!_elgg_has_rss_link()) { |
963
|
18 |
|
return; |
964
|
|
|
} |
965
|
|
|
|
966
|
|
|
if (_elgg_config()->disable_rss) { |
967
|
|
|
return; |
968
|
|
|
} |
969
|
|
|
|
970
|
|
|
$return[] = ElggMenuItem::factory([ |
971
|
|
|
'name' => 'rss', |
972
|
|
|
'text' => elgg_echo('feed:rss'), |
973
|
|
|
'icon' => 'rss', |
974
|
|
|
'href' => elgg_http_add_url_query_elements(current_page_url(), [ |
975
|
|
|
'view' => 'rss', |
976
|
|
|
]), |
977
|
|
|
'title' => elgg_echo('feed:rss:title'), |
978
|
|
|
]); |
979
|
|
|
|
980
|
|
|
return $return; |
981
|
|
|
} |
982
|
|
|
|
983
|
|
|
/** |
984
|
|
|
* Navigation initialization |
985
|
|
|
* |
986
|
|
|
* @return void |
987
|
|
|
* |
988
|
|
|
* @access private |
989
|
|
|
*/ |
990
|
|
|
function _elgg_nav_init() { |
991
|
|
|
elgg_register_plugin_hook_handler('prepare', 'breadcrumbs', 'elgg_prepare_breadcrumbs'); |
992
|
|
|
|
993
|
|
|
elgg_register_plugin_hook_handler('prepare', 'menu:site', '_elgg_site_menu_setup', 999); |
994
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:site', '_elgg_site_menu_init'); |
995
|
|
|
|
996
|
|
|
elgg_register_plugin_hook_handler('prepare', 'menu:page', '_elgg_page_menu_setup', 999); |
997
|
|
|
|
998
|
|
|
elgg_register_plugin_hook_handler('prepare', 'menu:entity', '_elgg_menu_transform_to_dropdown'); |
999
|
|
|
elgg_register_plugin_hook_handler('prepare', 'menu:river', '_elgg_menu_transform_to_dropdown'); |
1000
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:entity', '_elgg_entity_menu_setup'); |
1001
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:widget', '_elgg_widget_menu_setup'); |
1002
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:login', '_elgg_login_menu_setup'); |
1003
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:footer', '_elgg_rss_menu_setup'); |
1004
|
|
|
elgg_register_plugin_hook_handler('register', 'menu:entity_navigation', '_elgg_entity_navigation_menu_setup'); |
1005
|
|
|
|
1006
|
|
|
elgg_register_plugin_hook_handler('public_pages', 'walled_garden', '_elgg_nav_public_pages'); |
1007
|
|
|
|
1008
|
|
|
if (!_elgg_config()->remove_branding) { |
1009
|
|
|
elgg_register_menu_item('footer', \ElggMenuItem::factory([ |
1010
|
|
|
'name' => 'powered', |
1011
|
|
|
'text' => elgg_echo("elgg:powered"), |
1012
|
|
|
'href' => 'http://elgg.org', |
1013
|
|
|
'title' => 'Elgg ' . elgg_get_version(true), |
|
|
|
|
1014
|
|
|
'section' => 'meta', |
1015
|
|
|
'priority' => 600, |
1016
|
|
|
])); |
1017
|
|
|
} |
1018
|
|
|
|
1019
|
|
|
elgg_register_ajax_view('navigation/menu/user_hover/contents'); |
1020
|
|
|
|
1021
|
|
|
// Using a view extension to ensure that themes that have replaced the item view |
1022
|
|
|
// still load the required AMD modules |
1023
|
|
|
elgg_extend_view('navigation/menu/elements/item', 'navigation/menu/elements/item_deps'); |
1024
|
|
|
} |
1025
|
|
|
|
1026
|
|
|
/** |
1027
|
|
|
* Extend public pages |
1028
|
|
|
* |
1029
|
|
|
* @param string $hook_name "public_pages" |
1030
|
|
|
* @param string $entity_type "walled_garden" |
1031
|
|
|
* @param string[] $return_value Paths accessible outside the "walled garden" |
1032
|
|
|
* @param mixed $params unused |
1033
|
|
|
* |
1034
|
|
|
* @return string[] |
1035
|
|
|
* @access private |
1036
|
|
|
* @since 1.11.0 |
1037
|
|
|
*/ |
1038
|
|
|
function _elgg_nav_public_pages($hook_name, $entity_type, $return_value, $params) { |
|
|
|
|
1039
|
|
|
if (is_array($return_value)) { |
|
|
|
|
1040
|
|
|
$return_value[] = 'navigation/menu/user_hover/contents'; |
1041
|
|
|
} |
1042
|
|
|
|
1043
|
|
|
return $return_value; |
1044
|
|
|
} |
1045
|
|
|
|
1046
|
|
|
/** |
1047
|
|
|
* @see \Elgg\Application::loadCore Do not do work here. Just register for events. |
1048
|
|
|
*/ |
1049
|
|
|
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) { |
|
|
|
|
1050
|
|
|
$events->registerHandler('init', 'system', '_elgg_nav_init'); |
1051
|
|
|
}; |
1052
|
|
|
|