Elgg  Version 1.9
navigation.php
Go to the documentation of this file.
1 <?php
73 function elgg_register_menu_item($menu_name, $menu_item) {
75 
76  if (!isset($CONFIG->menus[$menu_name])) {
77  $CONFIG->menus[$menu_name] = array();
78  }
79 
80  if (is_array($menu_item)) {
81  $item = ElggMenuItem::factory($menu_item);
82  if (!$item) {
83  elgg_log("Unable to add menu item '{$menu_item['name']}' to '$menu_name' menu", 'WARNING');
84  return false;
85  }
86  } else {
87  $item = $menu_item;
88  }
89 
90  $CONFIG->menus[$menu_name][] = $item;
91  return true;
92 }
93 
103 function elgg_unregister_menu_item($menu_name, $item_name) {
104  global $CONFIG;
105 
106  if (!isset($CONFIG->menus[$menu_name])) {
107  return null;
108  }
109 
110  foreach ($CONFIG->menus[$menu_name] as $index => $menu_object) {
111  /* @var ElggMenuItem $menu_object */
112  if ($menu_object->getName() == $item_name) {
113  $item = $CONFIG->menus[$menu_name][$index];
114  unset($CONFIG->menus[$menu_name][$index]);
115  return $item;
116  }
117  }
118 
119  return null;
120 }
121 
131 function elgg_is_menu_item_registered($menu_name, $item_name) {
132  global $CONFIG;
133 
134  if (!isset($CONFIG->menus[$menu_name])) {
135  return false;
136  }
137 
138  foreach ($CONFIG->menus[$menu_name] as $menu_object) {
139  /* @var ElggMenuItem $menu_object */
140  if ($menu_object->getName() == $item_name) {
141  return true;
142  }
143  }
144 
145  return false;
146 }
147 
157 function elgg_get_menu_item($menu_name, $item_name) {
158  global $CONFIG;
159 
160  if (!isset($CONFIG->menus[$menu_name])) {
161  return null;
162  }
163 
164  foreach ($CONFIG->menus[$menu_name] as $index => $menu_object) {
165  /* @var ElggMenuItem $menu_object */
166  if ($menu_object->getName() == $item_name) {
167  return $CONFIG->menus[$menu_name][$index];
168  }
169  }
170 
171  return null;
172 }
173 
188 function elgg_register_title_button($handler = null, $name = 'add') {
189  if (elgg_is_logged_in()) {
190 
191  if (!$handler) {
193  }
194 
196  if (!$owner) {
197  // no owns the page so this is probably an all site list page
199  }
200  if ($owner && $owner->canWriteToContainer()) {
201  $guid = $owner->getGUID();
202  elgg_register_menu_item('title', array(
203  'name' => $name,
204  'href' => "$handler/$name/$guid",
205  'text' => elgg_echo("$handler:$name"),
206  'link_class' => 'elgg-button elgg-button-action',
207  ));
208  }
209  }
210 }
211 
221 function elgg_push_breadcrumb($title, $link = null) {
222  global $CONFIG;
223  if (!isset($CONFIG->breadcrumbs)) {
224  $CONFIG->breadcrumbs = array();
225  }
226 
227  // avoid key collisions.
228  $CONFIG->breadcrumbs[] = array('title' => elgg_get_excerpt($title, 100), 'link' => $link);
229 }
230 
238  global $CONFIG;
239 
240  if (is_array($CONFIG->breadcrumbs)) {
241  return array_pop($CONFIG->breadcrumbs);
242  }
243 
244  return false;
245 }
246 
254  global $CONFIG;
255 
256  if (isset($CONFIG->breadcrumbs) && is_array($CONFIG->breadcrumbs)) {
257  return $CONFIG->breadcrumbs;
258  }
259 
260  return array();
261 }
262 
271 
272  $featured_menu_names = elgg_get_config('site_featured_menu_names');
273  $custom_menu_items = elgg_get_config('site_custom_menu_items');
275  // we have featured or custom menu items
276 
277  $registered = $return['default'];
278  /* @var ElggMenuItem[] $registered */
279 
280  // set up featured menu items
281  $featured = array();
282  foreach ($featured_menu_names as $name) {
283  foreach ($registered as $index => $item) {
284  if ($item->getName() == $name) {
285  $featured[] = $item;
286  unset($registered[$index]);
287  }
288  }
289  }
290 
291  // add custom menu items
292  $n = 1;
293  foreach ($custom_menu_items as $title => $url) {
294  $item = new ElggMenuItem("custom$n", $title, $url);
295  $featured[] = $item;
296  $n++;
297  }
298 
299  $return['default'] = $featured;
300  if (count($registered) > 0) {
301  $return['more'] = $registered;
302  }
303  } else {
304  // no featured menu items set
305  $max_display_items = 5;
306 
307  // the first n are shown, rest added to more list
308  // if only one item on more menu, stick it with the rest
309  $num_menu_items = count($return['default']);
310  if ($num_menu_items > ($max_display_items + 1)) {
311  $return['more'] = array_splice($return['default'], $max_display_items);
312  }
313  }
314 
315  // check if we have anything selected
316  $selected = false;
317  foreach ($return as $section) {
318  /* @var ElggMenuItem[] $section */
319 
320  foreach ($section as $item) {
321  if ($item->getSelected()) {
322  $selected = true;
323  break 2;
324  }
325  }
326  }
327 
328  if (!$selected) {
329  // nothing selected, match name to context or match url
330  $current_url = current_page_url();
331  foreach ($return as $section_name => $section) {
332  foreach ($section as $key => $item) {
333  // only highlight internal links
334  if (strpos($item->getHref(), elgg_get_site_url()) === 0) {
335  if ($item->getName() == elgg_get_context()) {
336  $return[$section_name][$key]->setSelected(true);
337  break 2;
338  }
339  if ($item->getHref() == $current_url) {
340  $return[$section_name][$key]->setSelected(true);
341  break 2;
342  }
343  }
344  }
345  }
346  }
347 
348  return $return;
349 }
350 
356  if (elgg_is_logged_in()) {
357  $item = $params['item'];
358  /* @var ElggRiverItem $item */
359  $object = $item->getObjectEntity();
360  // add comment link but annotations cannot be commented on
361  if ($item->annotation_id == 0) {
362  if ($object->canComment()) {
363  $options = array(
364  'name' => 'comment',
365  'href' => "#comments-add-$object->guid",
366  'text' => elgg_view_icon('speech-bubble'),
367  'title' => elgg_echo('comment:this'),
368  'rel' => 'toggle',
369  'priority' => 50,
370  );
372  }
373  }
374 
375  if (elgg_is_admin_logged_in()) {
376  $options = array(
377  'name' => 'delete',
378  'href' => elgg_add_action_tokens_to_url("action/river/delete?id=$item->id"),
379  'text' => elgg_view_icon('delete'),
380  'title' => elgg_echo('river:delete'),
381  'confirm' => elgg_echo('deleteconfirm'),
382  'priority' => 200,
383  );
385  }
386  }
387 
388  return $return;
389 }
390 
396  if (elgg_in_context('widgets')) {
397  return $return;
398  }
399 
400  $entity = $params['entity'];
401  /* @var ElggEntity $entity */
402  $handler = elgg_extract('handler', $params, false);
403 
404  // access
405  if (elgg_is_logged_in()) {
406  $access = elgg_view('output/access', array('entity' => $entity));
407  $options = array(
408  'name' => 'access',
409  'text' => $access,
410  'href' => false,
411  'priority' => 100,
412  );
414  }
415 
416  if ($entity->canEdit() && $handler) {
417  // edit link
418  $options = array(
419  'name' => 'edit',
420  'text' => elgg_echo('edit'),
421  'title' => elgg_echo('edit:this'),
422  'href' => "$handler/edit/{$entity->getGUID()}",
423  'priority' => 200,
424  );
426 
427  // delete link
428  $options = array(
429  'name' => 'delete',
430  'text' => elgg_view_icon('delete'),
431  'title' => elgg_echo('delete:this'),
432  'href' => "action/$handler/delete?guid={$entity->getGUID()}",
433  'confirm' => elgg_echo('deleteconfirm'),
434  'priority' => 300,
435  );
437  }
438 
439  return $return;
440 }
441 
447 
448  $widget = $params['entity'];
449  /* @var ElggWidget $widget */
450  $show_edit = elgg_extract('show_edit', $params, true);
451 
452  $collapse = array(
453  'name' => 'collapse',
454  'text' => ' ',
455  'href' => "#elgg-widget-content-$widget->guid",
456  'link_class' => 'elgg-widget-collapse-button',
457  'rel' => 'toggle',
458  'priority' => 1,
459  );
460  $return[] = ElggMenuItem::factory($collapse);
461 
462  if ($widget->canEdit()) {
463  $delete = array(
464  'name' => 'delete',
465  'text' => elgg_view_icon('delete-alt'),
466  'title' => elgg_echo('widget:delete', array($widget->getTitle())),
467  'href' => "action/widgets/delete?widget_guid=$widget->guid",
468  'is_action' => true,
469  'link_class' => 'elgg-widget-delete-button',
470  'id' => "elgg-widget-delete-button-$widget->guid",
471  'data-elgg-widget-type' => $widget->handler,
472  'priority' => 900,
473  );
474  $return[] = ElggMenuItem::factory($delete);
475 
476  if ($show_edit) {
477  $edit = array(
478  'name' => 'settings',
479  'text' => elgg_view_icon('settings-alt'),
480  'title' => elgg_echo('widget:edit'),
481  'href' => "#widget-edit-$widget->guid",
482  'link_class' => "elgg-widget-edit-button",
483  'rel' => 'toggle',
484  'priority' => 800,
485  );
486  $return[] = ElggMenuItem::factory($edit);
487  }
488  }
489 
490  return $return;
491 }
492 
498 
499  if (elgg_get_config('allow_registration')) {
500  $return[] = ElggMenuItem::factory(array(
501  'name' => 'register',
502  'href' => 'register',
503  'text' => elgg_echo('register'),
504  'link_class' => 'registration_link',
505  ));
506  }
507 
508  $return[] = ElggMenuItem::factory(array(
509  'name' => 'forgotpassword',
510  'href' => 'forgotpassword',
511  'text' => elgg_echo('user:password:lost'),
512  'link_class' => 'forgot_link',
513  ));
514 
515  return $return;
516 }
517 
518 
523 function _elgg_nav_init() {
524  elgg_register_plugin_hook_handler('prepare', 'menu:site', '_elgg_site_menu_setup');
525  elgg_register_plugin_hook_handler('register', 'menu:river', '_elgg_river_menu_setup');
526  elgg_register_plugin_hook_handler('register', 'menu:entity', '_elgg_entity_menu_setup');
527  elgg_register_plugin_hook_handler('register', 'menu:widget', '_elgg_widget_menu_setup');
528  elgg_register_plugin_hook_handler('register', 'menu:login', '_elgg_login_menu_setup');
529 
531  'name' => 'powered',
532  'text' => elgg_echo("elgg:powered"),
533  'href' => 'http://elgg.org',
534  'title' => 'Elgg ' . elgg_get_version(true),
535  'section' => 'meta',
536  )));
537 }
538 
539 elgg_register_event_handler('init', 'system', '_elgg_nav_init');
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$custom_menu_items
Definition: save.php:21
$n
Profile fields.
Definition: list.php:9
elgg_push_breadcrumb($title, $link=null)
Adds a breadcrumb to the breadcrumbs stack.
Definition: navigation.php:221
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
Definition: sessions.php:56
elgg_unregister_menu_item($menu_name, $item_name)
Remove an item from a menu.
Definition: navigation.php:103
elgg_view_icon($name, $class= '')
View one of the elgg sprite icons.
Definition: views.php:1370
elgg_add_action_tokens_to_url($url, $html_encode=false)
Adds action tokens to URL.
Definition: elgglib.php:1277
_elgg_login_menu_setup($hook, $type, $return, $params)
Add the register and forgot password links to login menu private.
Definition: navigation.php:497
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:65
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
current_page_url()
Returns the current page&#39;s complete URL.
Definition: input.php:106
$object
Definition: upgrade.php:12
$widget
Definition: delete.php:9
elgg_get_menu_item($menu_name, $item_name)
Get a menu item registered for a menu.
Definition: navigation.php:157
$return
Definition: opendd.php:15
$guid
Removes an admin notice.
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1464
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
Definition: elgglib.php:853
_elgg_widget_menu_setup($hook, $type, $return, $params)
Widget menu is a set of widget controls private.
Definition: navigation.php:446
$url
Definition: exceptions.php:24
$title
Definition: save.php:24
$params
Definition: login.php:72
$options
Definition: index.php:14
$featured_menu_names
Definition: save.php:16
static factory($options)
Create an ElggMenuItem from an associative array.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$owner
Definition: crop.php:8
$key
Definition: summary.php:34
$item
Definition: item.php:12
global $CONFIG
$num_menu_items
Definition: save.php:20
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:273
elgg_get_breadcrumbs()
Returns all breadcrumbs as an array of array(&#39;title&#39; => &#39;Readable Title&#39;, &#39;link&#39; => &#39;URL&#39;) ...
Definition: navigation.php:253
elgg_register_title_button($handler=null, $name= 'add')
Convenience function for registering a button to the title menu.
Definition: navigation.php:188
elgg_get_context()
Get the current context.
Definition: pageowner.php:226
elgg global
Pointer to the global context.
Definition: elgglib.js:12
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:53
$type
Definition: add.php:8
elgg_register_menu_item($menu_name, $menu_item)
Register an item for an Elgg menu.
Definition: navigation.php:73
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
_elgg_entity_menu_setup($hook, $type, $return, $params)
Entity menu is list of links and info on any entity private.
Definition: navigation.php:395
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:669
elgg_log($message, $level= 'NOTICE')
Display or log a message.
Definition: elgglib.php:1083
_elgg_site_menu_setup($hook, $type, $return, $params)
Set up the site menu.
Definition: navigation.php:270
elgg_get_version($human_readable=false)
Get the current Elgg version information.
Definition: elgglib.php:1126
_elgg_nav_init()
Navigation initialization private.
Definition: navigation.php:523
elgg_get_excerpt($text, $num_chars=250)
Returns an excerpt.
Definition: output.php:72
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:32
$handler
Definition: add.php:10
$entity
Definition: delete.php:10
_elgg_river_menu_setup($hook, $type, $return, $params)
Add the comment and like links to river actions menu private.
Definition: navigation.php:355
elgg_pop_breadcrumb()
Removes last breadcrumb entry.
Definition: navigation.php:237
elgg_is_menu_item_registered($menu_name, $item_name)
Check if a menu item has been registered.
Definition: navigation.php:131
$access
Definition: save.php:15