breadcrumbs.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Displays breadcrumbs.
  4. *
  5. * @package Elgg
  6. * @subpackage Core
  7. *
  8. * @uses $vars['breadcrumbs'] (Optional) Array of arrays with keys 'title' and 'link'
  9. * @uses $vars['class']
  10. *
  11. * @see elgg_push_breadcrumb
  12. * @see elgg_get_breadcrumbs
  13. */
  14. if (isset($vars['breadcrumbs'])) {
  15. $breadcrumbs = $vars['breadcrumbs'];
  16. } else {
  17. $breadcrumbs = elgg_get_breadcrumbs();
  18. }
  19. $class = 'elgg-menu elgg-breadcrumbs';
  20. $additional_class = elgg_extract('class', $vars, '');
  21. if ($additional_class) {
  22. $class = "$class $additional_class";
  23. }
  24. if (is_array($breadcrumbs) && count($breadcrumbs) > 0) {
  25. echo "<ul class=\"$class\">";
  26. foreach ($breadcrumbs as $breadcrumb) {
  27. // We have to escape text (without double-encoding). Titles in core plugins are HTML escaped
  28. // on input, but we can't guarantee that other users of this view and of elgg_push_breadcrumb()
  29. // will do so.
  30. if (!empty($breadcrumb['link'])) {
  31. $crumb = elgg_view('output/url', array(
  32. 'href' => $breadcrumb['link'],
  33. 'text' => $breadcrumb['title'],
  34. 'encode_text' => true,
  35. 'is_trusted' => true,
  36. ));
  37. } else {
  38. $crumb = htmlspecialchars($breadcrumb['title'], ENT_QUOTES, 'UTF-8', false);
  39. }
  40. echo "<li>$crumb</li>";
  41. }
  42. echo '</ul>';
  43. }