-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.php
More file actions
446 lines (374 loc) · 13.7 KB
/
template.php
File metadata and controls
446 lines (374 loc) · 13.7 KB
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<?php
/**
* @file
* Contains theme override functions and process & preprocess functions for theme588
*/
// Auto-rebuild the theme registry during theme development.
if (theme_get_setting('theme588_clear_registry')) {
// Rebuild .info data.
system_rebuild_theme_data();
// Rebuild theme registry.
drupal_theme_rebuild();
}
/**
* Implements template_html_head_alter();
*
* Changes the default meta content-type tag to the shorter HTML5 version
*/
function theme588_html_head_alter(&$head_elements) {
$head_elements['system_meta_content_type']['#attributes'] = array(
'charset' => 'utf-8'
);
}
/**
* Implements template_proprocess_search_block_form().
*
* Changes the search form to use the HTML5 "search" input attribute
*/
function theme588_preprocess_search_block_form(&$vars) {
$vars['search_form'] = str_replace('type="text"', 'type="search"', $vars['search_form']);
}
/**
* Implements template_preprocess().
*/
function theme588_preprocess(&$vars, $hook) {
$vars['theme588_path'] = base_path() . path_to_theme();
}
/**
* Implements template_preprocess_html().
*/
function theme588_preprocess_html(&$vars) {
$vars['doctype'] = _theme588_doctype();
$vars['rdf'] = _theme588_rdf($vars);
// Since menu is rendered in preprocess_page we need to detect it here to add body classes
$has_main_menu = theme_get_setting('toggle_main_menu');
$has_secondary_menu = theme_get_setting('toggle_secondary_menu');
/* Add extra classes to body for more flexible theming */
if ($has_main_menu or $has_secondary_menu) {
$vars['classes_array'][] = 'with-navigation';
}
if ($has_secondary_menu) {
$vars['classes_array'][] = 'with-subnav';
}
if (!empty($vars['page']['featured'])) {
$vars['classes_array'][] = 'featured';
}
if (!empty($vars['page']['triptych_first'])
|| !empty($vars['page']['triptych_middle'])
|| !empty($vars['page']['triptych_last'])) {
$vars['classes_array'][] = 'triptych';
}
if (!empty($vars['page']['footer_firstcolumn'])
|| !empty($vars['page']['footer_secondcolumn'])
|| !empty($vars['page']['footer_thirdcolumn'])
|| !empty($vars['page']['footer_fourthcolumn'])) {
$vars['classes_array'][] = 'footer-columns';
}
if ($vars['is_admin']) {
$vars['classes_array'][] = 'admin';
}
if (!$vars['is_front']) {
// Add unique classes for each page and website section
$path = drupal_get_path_alias($_GET['q']);
$temp = explode('/', $path, 2);
$section = array_shift($temp);
$page_name = array_shift($temp);
if (isset($page_name)) {
$vars['classes_array'][] = theme588_id_safe('page-' . $page_name);
}
$vars['classes_array'][] = theme588_id_safe('section-' . $section);
// add template suggestions
$vars['theme_hook_suggestions'][] = "page__section__" . $section;
$vars['theme_hook_suggestions'][] = "page__" . $page_name;
if (arg(0) == 'node') {
if (arg(1) == 'add') {
if ($section == 'node') {
array_pop($body_classes); // Remove 'section-node'
}
$body_classes[] = 'section-node-add'; // Add 'section-node-add'
} elseif (is_numeric(arg(1)) && (arg(2) == 'edit' || arg(2) == 'delete')) {
$body_classes[] = 'section-node-' . arg(2); // Add 'section-node-edit' or 'section-node-delete'
}
}
}
}
/**
* Implements template_preprocess_page().
*/
function theme588_preprocess_page(&$vars) {
if (isset($vars['node_title'])) {
$vars['title'] = $vars['node_title'];
}
// Adding classes wether #navigation is here or not
if (!empty($vars['main_menu']) or !empty($vars['sub_menu'])) {
$vars['classes_array'][] = 'with-navigation';
}
if (!empty($vars['secondary_menu'])) {
$vars['classes_array'][] = 'with-subnav';
}
// Since the title and the shortcut link are both block level elements,
// positioning them next to each other is much simpler with a wrapper div.
if (!empty($vars['title_suffix']['add_or_remove_shortcut']) && $vars['title']) {
// Add a wrapper div using the title_prefix and title_suffix render elements.
$vars['title_prefix']['shortcut_wrapper'] = array(
'#markup' => '<div class="shortcut-wrapper clearfix">',
'#weight' => 100,
);
$vars['title_suffix']['shortcut_wrapper'] = array(
'#markup' => '</div>',
'#weight' => -99,
);
// Make sure the shortcut link is the first item in title_suffix.
$vars['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
}
if(!theme_get_setting('theme588_feed_icons')) {
$vars['feed_icons'] = '';
}
}
/**
* Implements template_preprocess_maintenance_page().
*/
function theme588_preprocess_maintenance_page(&$vars) {
// Manually include these as they're not available outside template_preprocess_page().
$vars['rdf_namespaces'] = drupal_get_rdf_namespaces();
$vars['grddl_profile'] = 'http://www.w3.org/1999/xhtml/vocab';
$vars['doctype'] = _theme588_doctype();
$vars['rdf'] = _theme588_rdf($vars);
if (!$vars['db_is_active']) {
unset($vars['site_name']);
}
drupal_add_css(drupal_get_path('theme', 'theme588') . '/css/maintenance-page.css');
}
/**
* Implements template_preprocess_node().
*
* Adds extra classes to node container for advanced theming
*/
function theme588_preprocess_node(&$vars) {
// Striping class
$vars['classes_array'][] = 'node-' . $vars['zebra'];
// Node is published
$vars['classes_array'][] = ($vars['status']) ? 'published' : 'unpublished';
// Node has comments?
$vars['classes_array'][] = ($vars['comment']) ? 'with-comments' : 'no-comments';
if ($vars['sticky']) {
$vars['classes_array'][] = 'sticky'; // Node is sticky
}
if ($vars['promote']) {
$vars['classes_array'][] = 'promote'; // Node is promoted to front page
}
if ($vars['teaser']) {
$vars['classes_array'][] = 'node-teaser'; // Node is displayed as teaser.
}
if ($vars['uid'] && $vars['uid'] === $GLOBALS['user']->uid) {
$classes[] = 'node-mine'; // Node is authored by current user.
}
$vars['submitted'] = t('Submitted by !username on ', array('!username' => $vars['name']));
$vars['submitted_date'] = t('!datetime', array('!datetime' => $vars['date']));
$vars['submitted_pubdate'] = format_date($vars['created'], 'custom', 'Y-m-d\TH:i:s');
if ($vars['view_mode'] == 'full' && node_is_page($vars['node'])) {
$vars['classes_array'][] = 'node-full';
}
}
/**
* Implements template_preprocess_block().
*/
function theme588_preprocess_block(&$vars, $hook) {
// Add a striping class.
$vars['classes_array'][] = 'block-' . $vars['zebra'];
// In the header region visually hide block titles.
if ($vars['block']->region == 'header') {
$vars['title_attributes_array']['class'][] = 'element-invisible';
}
}
/**
* Implements theme_menu_tree().
*/
function theme588_menu_tree($vars) {
return '<ul class="menu clearfix">' . $vars['tree'] . '</ul>';
}
/**
* Implements theme_field__field_type().
*/
function theme588_field__taxonomy_term_reference($vars) {
$output = '';
// Render the label, if it's not hidden.
if (!$vars['label_hidden']) {
$output .= '<h3 class="field-label">' . $vars['label'] . ': </h3>';
}
// Render the items.
$output .= ( $vars['element']['#label_display'] == 'inline') ? '<ul class="links inline">' : '<ul class="links">';
foreach ($vars['items'] as $delta => $item) {
$output .= '<li class="taxonomy-term-reference-' . $delta . '"' . $vars['item_attributes'][$delta] . '>' . drupal_render($item) . '</li>';
}
$output .= '</ul>';
// Render the top-level DIV.
$output = '<div class="' . $vars['classes'] . (!in_array('clearfix', $vars['classes_array']) ? ' clearfix' : '') . '">' . $output . '</div>';
return $output;
}
/**
* Return a themed breadcrumb trail.
*
* @param $breadcrumb
* An array containing the breadcrumb links.
* @return
* A string containing the breadcrumb output.
*/
function theme588_breadcrumb($vars) {
$breadcrumb = $vars['breadcrumb'];
// Determine if we are to display the breadcrumb.
$show_breadcrumb = theme_get_setting('breadcrumb_display');
if ($show_breadcrumb == 'yes') {
// Optionally get rid of the homepage link.
$show_breadcrumb_home = theme_get_setting('breadcrumb_home');
if (!$show_breadcrumb_home) {
array_shift($breadcrumb);
}
// Return the breadcrumb with separators.
if (!empty($breadcrumb)) {
$separator = filter_xss(theme_get_setting('breadcrumb_separator'));
$trailing_separator = $title = '';
// Add the title and trailing separator
if (theme_get_setting('breadcrumb_title')) {
if ($title = drupal_get_title()) {
$trailing_separator = $separator;
}
}
// Just add the trailing separator
elseif (theme_get_setting('breadcrumb_trailing')) {
$trailing_separator = $separator;
}
// Assemble the breadcrumb
return implode($separator, $breadcrumb) . $trailing_separator . $title;
}
}
// Otherwise, return an empty string.
return '';
}
/**
* Determine whether to show floating tabs
*
* @return bool
*/
function theme588_tabs_float() {
$float = (bool) theme_get_setting('theme588_tabs_float');
$float_node = (bool) theme_get_setting('theme588_tabs_node');
$is_node = (arg(0) === 'node' && is_numeric(arg(1)));
if ($float) {
return ($float_node) ? $is_node : TRUE;
}
return FALSE;
}
/*
* Converts a string to a suitable html ID attribute.
* Taken from "basic"
*
* http://www.w3.org/TR/html4/struct/global.html#h-7.5.2 specifies what makes a
* valid ID attribute in HTML. This function:
*
* - Ensure an ID starts with an alpha character by optionally adding an 'n'.
* - Replaces any character except A-Z, numbers, and underscores with dashes.
* - Converts entire string to lowercase.
*
* @param $string
* The string
* @return
* The converted string
*/
function theme588_id_safe($string) {
// Strip accents
$accents = '/&([A-Za-z]{1,2})(tilde|grave|acute|circ|cedil|uml|lig);/';
$string = preg_replace($accents, '$1', htmlentities(utf8_decode($string)));
// Replace with dashes anything that isn't A-Z, numbers, dashes, or underscores.
$string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
// If the first character is not a-z, add 'n' in front.
if (!ctype_lower($string{0})) { // Don't use ctype_alpha since its locale aware.
$string = 'id' . $string;
}
return $string;
}
/**
* Generate doctype for templates
*/
function _theme588_doctype() {
return (module_exists('rdf')) ? '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML+RDFa 1.1//EN"' . "\n" . '"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">' : '<!DOCTYPE html>' . "\n";
}
/**
* Generate RDF object for templates
*
* Uses RDFa attributes if the RDF module is enabled
* Lifted from Adaptivetheme for D7, full credit to Jeff Burnz
* ref: http://drupal.org/node/887600
*
* @param array $vars
*/
function _theme588_rdf($vars) {
$rdf = new stdClass();
if (module_exists('rdf')) {
$rdf->version = 'version="HTML+RDFa 1.1"';
$rdf->namespaces = $vars['rdf_namespaces'];
$rdf->profile = ' profile="' . $vars['grddl_profile'] . '"';
} else {
$rdf->version = '';
$rdf->namespaces = '';
$rdf->profile = '';
}
return $rdf;
}
/**
* Generate the HTML output for a menu link and submenu.
*
* @param $vars
* An associative array containing:
* - element: Structured array data for a menu link.
*
* @return
* A themed HTML string.
*
* @ingroup themeable
*/
function theme588_menu_link(array $vars) {
$element = $vars['element'];
$sub_menu = '';
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
// Adding a class depending on the TITLE of the link (not constant)
$element['#attributes']['class'][] = theme588_id_safe($element['#title']);
// Adding a class depending on the ID of the link (constant)
$element['#attributes']['class'][] = 'mid-' . $element['#original_link']['mlid'];
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
/**
* Override or insert variables into theme_menu_local_task().
*/
function theme588_preprocess_menu_local_task(&$vars) {
$link = & $vars['element']['#link'];
// If the link does not contain HTML already, check_plain() it now.
// After we set 'html'=TRUE the link will not be sanitized by l().
if (empty($link['localized_options']['html'])) {
$link['title'] = check_plain($link['title']);
}
$link['localized_options']['html'] = TRUE;
$link['title'] = '<span class="tab">' . $link['title'] . '</span>';
}
/**
* Duplicate of theme_menu_local_tasks() but adds clearfix to tabs.
*/
function theme588_menu_local_tasks(&$vars) {
$output = '';
if (!empty($vars['primary'])) {
$vars['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
$vars['primary']['#prefix'] .= '<ul class="tabs primary clearfix">';
$vars['primary']['#suffix'] = '</ul>';
$output .= drupal_render($vars['primary']);
}
if (!empty($vars['secondary'])) {
$vars['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
$vars['secondary']['#prefix'] .= '<ul class="tabs secondary clearfix">';
$vars['secondary']['#suffix'] = '</ul>';
$output .= drupal_render($vars['secondary']);
}
return $output;
}