1 |
87dbc3bf
|
Benjamin Luce
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
function theme_bootstrap_links($variables) {
|
11 |
|
|
$links = $variables['links'];
|
12 |
|
|
$attributes = $variables['attributes'];
|
13 |
|
|
$heading = $variables['heading'];
|
14 |
|
|
|
15 |
|
|
global $language_url;
|
16 |
|
|
$output = '';
|
17 |
|
|
|
18 |
|
|
if (count($links) > 0) {
|
19 |
|
|
$output = '';
|
20 |
|
|
$output .= '<ul' . drupal_attributes($attributes) . '>';
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
if (!empty($heading)) {
|
25 |
|
|
if (is_string($heading)) {
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
$heading = array(
|
29 |
|
|
'text' => $heading,
|
30 |
|
|
|
31 |
|
|
'level' => 'li',
|
32 |
|
|
);
|
33 |
|
|
}
|
34 |
|
|
$output .= '<' . $heading['level'];
|
35 |
|
|
if (!empty($heading['class'])) {
|
36 |
|
|
$output .= drupal_attributes(array('class' => $heading['class']));
|
37 |
|
|
}
|
38 |
|
|
$output .= '>' . check_plain($heading['text']) . '</' . $heading['level'] . '>';
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
$num_links = count($links);
|
42 |
|
|
$i = 1;
|
43 |
|
|
|
44 |
|
|
foreach ($links as $key => $link) {
|
45 |
|
|
$children = array();
|
46 |
|
|
if (isset($link['below'])) {
|
47 |
|
|
$children = $link['below'];
|
48 |
|
|
}
|
49 |
|
|
$attributes = array('class' => array($key));
|
50 |
|
|
|
51 |
|
|
if ($i == 1) {
|
52 |
|
|
$attributes['class'][] = 'first';
|
53 |
|
|
}
|
54 |
|
|
if ($i == $num_links) {
|
55 |
|
|
$attributes['class'][] = 'last';
|
56 |
|
|
}
|
57 |
|
|
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
|
58 |
|
|
&& (empty($link['language']) || $link['language']->language == $language_url->language)) {
|
59 |
|
|
$attributes['class'][] = 'active';
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
if (count($children) > 0) {
|
63 |
|
|
$attributes['class'][] = 'dropdown';
|
64 |
|
|
$link['attributes']['data-toggle'] = 'dropdown';
|
65 |
|
|
$link['attributes']['class'][] = 'dropdown-toggle';
|
66 |
|
|
}
|
67 |
|
|
|
68 |
|
|
if (!isset($link['attributes'])) {
|
69 |
|
|
$link['attributes'] = array();
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
$link['attributes'] = array_merge($link['attributes'], $attributes);
|
73 |
|
|
|
74 |
|
|
if (count($children) > 0) {
|
75 |
|
|
$link['attributes']['class'][] = 'dropdown';
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
$output .= '<li' . drupal_attributes($attributes) . '>';
|
79 |
|
|
|
80 |
|
|
if (isset($link['href'])) {
|
81 |
|
|
if (count($children) > 0) {
|
82 |
|
|
$link['html'] = TRUE;
|
83 |
|
|
$link['title'] .= ' <span class="caret"></span>';
|
84 |
|
|
$output .= '<a' . drupal_attributes($link['attributes']) . ' href="#">' . $link['title'] . '</a>';
|
85 |
|
|
}
|
86 |
|
|
else {
|
87 |
|
|
|
88 |
|
|
$output .= l($link['title'], $link['href'], $link);
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
elseif (!empty($link['title'])) {
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
if (empty($link['html'])) {
|
95 |
|
|
$link['title'] = check_plain($link['title']);
|
96 |
|
|
}
|
97 |
|
|
$span_attributes = '';
|
98 |
|
|
if (isset($link['attributes'])) {
|
99 |
|
|
$span_attributes = drupal_attributes($link['attributes']);
|
100 |
|
|
}
|
101 |
|
|
$output .= '<span' . $span_attributes . '>' . $link['title'] . '</span>';
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
$i++;
|
105 |
|
|
if (count($children) > 0) {
|
106 |
|
|
$attributes = array();
|
107 |
|
|
$attributes['class'] = array('dropdown-menu');
|
108 |
|
|
$output .= theme('bootstrap_links', array('links' => $children, 'attributes' => $attributes));
|
109 |
|
|
}
|
110 |
|
|
$output .= "</li>\n";
|
111 |
|
|
}
|
112 |
|
|
$output .= '</ul>';
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
return $output;
|
116 |
|
|
} |