tabs.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Tab navigation
  4. *
  5. * @uses string $vars['type'] horizontal || vertical - Defaults to horizontal
  6. * @uses string $vars['class'] Additional class to add to ul
  7. * @uses array $vars['tabs'] A multi-dimensional array of tab entries in the format array(
  8. * 'text' => string, // The string between the <a></a> tags
  9. * 'href' => string, // URL for the link
  10. * 'class' => string // Class of the li element
  11. * 'id' => string, // ID of the li element
  12. * 'selected' => bool // if this tab is currently selected (applied to li element)
  13. * 'link_class' => string, // Class to pass to the link
  14. * 'link_id' => string, // ID to pass to the link
  15. * )
  16. */
  17. $options = _elgg_clean_vars($vars);
  18. $type = elgg_extract('type', $vars, 'horizontal');
  19. if ($type == 'horizontal') {
  20. $options['class'] = "elgg-tabs elgg-htabs";
  21. } else {
  22. $options['class'] = "elgg-tabs elgg-vtabs";
  23. }
  24. if (isset($vars['class'])) {
  25. $options['class'] = "{$options['class']} {$vars['class']}";
  26. }
  27. unset($options['tabs']);
  28. unset($options['type']);
  29. $attributes = elgg_format_attributes($options);
  30. if (isset($vars['tabs']) && is_array($vars['tabs']) && !empty($vars['tabs'])) {
  31. ?>
  32. <ul <?php echo $attributes; ?>>
  33. <?php
  34. foreach ($vars['tabs'] as $info) {
  35. $class = elgg_extract('class', $info, '');
  36. $id = elgg_extract('id', $info, '');
  37. $selected = elgg_extract('selected', $info, FALSE);
  38. if ($selected) {
  39. $class .= ' elgg-state-selected';
  40. }
  41. $class_str = ($class) ? "class=\"$class\"" : '';
  42. $id_str = ($id) ? "id=\"$id\"" : '';
  43. $options = $info;
  44. unset($options['class']);
  45. unset($options['id']);
  46. unset($options['selected']);
  47. if (!isset($info['href']) && isset($info['url'])) {
  48. $options['href'] = $info['url'];
  49. unset($options['url']);
  50. }
  51. if (!isset($info['text']) && isset($info['title'])) {
  52. $options['text'] = $options['title'];
  53. unset($options['title']);
  54. }
  55. if (isset($info['link_class'])) {
  56. $options['class'] = $options['link_class'];
  57. unset($options['link_class']);
  58. }
  59. if (isset($info['link_id'])) {
  60. $options['id'] = $options['link_id'];
  61. unset($options['link_id']);
  62. }
  63. $link = elgg_view('output/url', $options);
  64. echo "<li $id_str $class_str>$link</li>";
  65. }
  66. ?>
  67. </ul>
  68. <?php
  69. }