-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.php
executable file
·309 lines (277 loc) · 8.85 KB
/
template.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
// Provide < PHP 5.3 support for the __DIR__ constant.
if (!defined('__DIR__')) {
define('__DIR__', dirname(__FILE__));
}
require_once __DIR__ . '/includes/bootstrap.inc';
require_once __DIR__ . '/includes/theme.inc';
require_once __DIR__ . '/includes/pager.inc';
require_once __DIR__ . '/includes/form.inc';
require_once __DIR__ . '/includes/admin.inc';
require_once __DIR__ . '/includes/menu.inc';
// Load module specific files in the modules directory.
$includes = file_scan_directory(__DIR__ . '/includes/modules', '/\.inc$/');
foreach ($includes as $include) {
if (module_exists($include->name)) {
require_once $include->uri;
}
}
// Auto-rebuild the theme registry during theme development.
if (theme_get_setting('bootstrap_rebuild_registry') && !defined('MAINTENANCE_MODE')) {
// Rebuild .info data.
system_rebuild_theme_data();
// Rebuild theme registry.
drupal_theme_rebuild();
}
/**
* Implements hook_theme().
*/
function bootstrap_theme(&$existing, $type, $theme, $path) {
// If we are auto-rebuilding the theme registry, warn about the feature.
if (
// Only display for site config admins.
isset($GLOBALS['user']) && function_exists('user_access') && user_access('administer site configuration')
&& theme_get_setting('bootstrap_rebuild_registry')
// Always display in the admin section, otherwise limit to three per hour.
&& (arg(0) == 'admin' || flood_is_allowed($GLOBALS['theme'] . '_rebuild_registry_warning', 3))
) {
flood_register_event($GLOBALS['theme'] . '_rebuild_registry_warning');
drupal_set_message(t('For easier theme development, the theme registry is being rebuilt on every page request. It is <em>extremely</em> important to <a href="!link">turn off this feature</a> on production websites.', array('!link' => url('admin/appearance/settings/' . $GLOBALS['theme']))), 'warning', FALSE);
}
return array(
'bootstrap_links' => array(
'variables' => array(
'links' => array(),
'attributes' => array(),
'heading' => NULL
),
),
'bootstrap_btn_dropdown' => array(
'variables' => array(
'links' => array(),
'attributes' => array(),
'type' => NULL
),
),
'bootstrap_modal' => array(
'variables' => array(
'heading' => '',
'body' => '',
'footer' => '',
'attributes' => array(),
'html_heading' => FALSE,
),
),
'bootstrap_accordion' => array(
'variables' => array(
'id' => '',
'elements' => array(),
),
),
'bootstrap_search_form_wrapper' => array(
'render element' => 'element',
),
'bootstrap_append_element' => array(
'render element' => 'element',
),
);
}
/**
* Override theme_breadrumb().
*
* Print breadcrumbs as a list, with separators.
*/
function bootstrap_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
if (!empty($breadcrumb)) {
$breadcrumbs = '<ul class="breadcrumb">';
$count = count($breadcrumb) - 1;
foreach ($breadcrumb as $key => $value) {
if ($count != $key) {
$breadcrumbs .= '<li>' . $value . '<span class="divider">/</span></li>';
}
else{
$breadcrumbs .= '<li>' . $value . '</li>';
}
}
$breadcrumbs .= '</ul>';
return $breadcrumbs;
}
}
/**
* Override or insert variables in the html_tag theme function.
*/
function bootstrap_process_html_tag(&$variables) {
$tag = &$variables['element'];
if ($tag['#tag'] == 'style' || $tag['#tag'] == 'script') {
// Remove redundant type attribute and CDATA comments.
unset($tag['#attributes']['type'], $tag['#value_prefix'], $tag['#value_suffix']);
// Remove media="all" but leave others unaffected.
if (isset($tag['#attributes']['media']) && $tag['#attributes']['media'] === 'all') {
unset($tag['#attributes']['media']);
}
}
}
/**
* Preprocess variables for page.tpl.php
*
* @see page.tpl.php
*/
function bootstrap_preprocess_page(&$variables) {
// Add information about the number of sidebars.
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
$variables['columns'] = 3;
}
elseif (!empty($variables['page']['sidebar_first'])) {
$variables['columns'] = 2;
}
elseif (!empty($variables['page']['sidebar_second'])) {
$variables['columns'] = 2;
}
else {
$variables['columns'] = 1;
}
// Primary nav
$variables['primary_nav'] = FALSE;
if ($variables['main_menu']) {
// Build links
$variables['primary_nav'] = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
// Provide default theme wrapper function
$variables['primary_nav']['#theme_wrappers'] = array('menu_tree__primary');
}
// Secondary nav
$variables['secondary_nav'] = FALSE;
if ($variables['secondary_menu']) {
// Build links
$variables['secondary_nav'] = menu_tree(variable_get('menu_secondary_links_source', 'user-menu'));
// Provide default theme wrapper function
$variables['secondary_nav']['#theme_wrappers'] = array('menu_tree__secondary');
}
}
/**
* Bootstrap theme wrapper function for the primary menu links
*/
function bootstrap_menu_tree__primary(&$variables) {
return '<ul class="menu nav">' . $variables['tree'] . '</ul>';
}
/**
* Bootstrap theme wrapper function for the secondary menu links
*/
function bootstrap_menu_tree__secondary(&$variables) {
return '<ul class="menu nav pull-right">' . $variables['tree'] . '</ul>';
}
/**
* Returns HTML for a single local action link.
*
* This function overrides theme_menu_local_action() to add the icons that ship
* with Bootstrap to the action links.
*
* @param $variables
* An associative array containing:
* - element: A render element containing:
* - #link: A menu link array with "title", "href", "localized_options", and
* "icon" keys. If "icon" is not passed, it defaults to "plus-sign".
*
* @ingroup themeable
*
* @see theme_menu_local_action().
*/
function bootstrap_menu_local_action($variables) {
$link = $variables['element']['#link'];
// Build the icon rendering element.
if (empty($link['icon'])) {
$link['icon'] = 'plus-sign';
}
$icon = '<i class="' . drupal_clean_css_identifier('icon-' . $link['icon']) . '"></i>';
// Format the action link.
$output = '<li>';
if (isset($link['href'])) {
$options = isset($link['localized_options']) ? $link['localized_options'] : array();
// If the title is not HTML, sanitize it.
if (empty($link['localized_options']['html'])) {
$link['title'] = check_plain($link['title']);
}
// Force HTML so we can add the icon rendering element.
$options['html'] = TRUE;
$output .= l($icon . $link['title'], $link['href'], $options);
}
elseif (!empty($link['localized_options']['html'])) {
$output .= $icon . $link['title'];
}
else {
$output .= $icon . check_plain($link['title']);
}
$output .= "</li>\n";
return $output;
}
/**
* Preprocess variables for region.tpl.php
*
* @see region.tpl.php
*/
function bootstrap_preprocess_region(&$variables, $hook) {
if ($variables['region'] == 'content') {
$variables['theme_hook_suggestions'][] = 'region__no_wrapper';
}
if ($variables['region'] == "sidebar_first") {
$variables['classes_array'][] = 'well';
}
}
/**
* Preprocess variables for block.tpl.php
*
* @see block.tpl.php
*/
function bootstrap_preprocess_block(&$variables, $hook) {
//$variables['classes_array'][] = 'row';
// Use a bare template for the page's main content.
if ($variables['block_html_id'] == 'block-system-main') {
$variables['theme_hook_suggestions'][] = 'block__no_wrapper';
}
$variables['title_attributes_array']['class'][] = 'block-title';
}
/**
* Override or insert variables into the block templates.
*
* @param $variables
* An array of variables to pass to the theme template.
* @param $hook
* The name of the template being rendered ("block" in this case.)
*/
function bootstrap_process_block(&$variables, $hook) {
// Drupal 7 should use a $title variable instead of $block->subject.
$variables['title'] = $variables['block']->subject;
}
/**
* Returns the correct span class for a region
*/
function _bootstrap_content_span($columns = 1) {
$class = FALSE;
switch($columns) {
case 1:
$class = 'span12';
break;
case 2:
$class = 'span9';
break;
case 3:
$class = 'span6';
break;
}
return $class;
}
/**
* Adds the search form's submit button right after the input element.
*
* @ingroup themable
*/
function bootstrap_bootstrap_search_form_wrapper(&$variables) {
$output = '<div class="input-append">';
$output .= $variables['element']['#children'];
$output .= '<button type="submit" class="btn">';
$output .= '<i class="icon-search"></i>';
$output .= '<span class="element-invisible">' . t('Search') . '</span>';
$output .= '</button>';
$output .= '</div>';
return $output;
}