-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate.php
More file actions
423 lines (350 loc) · 13.8 KB
/
template.php
File metadata and controls
423 lines (350 loc) · 13.8 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
<?php
/**
* @file
* Contains theme override functions and preprocess functions for the Boron theme.
*/
/*****************************************************************************************************************************/
/* WARNING!!!! NEVER CHANGE ANYTHING IN THIS FOLDER!!! USE A CHILD THEME! CHECK OUT "STARTER-CHILD" FOLDER FOR INSTRUCTIONS */
/*****************************************************************************************************************************
/**
* Changes the default meta content-type tag to the shorter HTML5 version
*/
function cogito_html_head_alter(&$head_elements) {
global $theme;
$head_elements['system_meta_content_type']['#attributes'] = array(
'charset' => 'utf-8'
);
//Throw an Error if foundation is not found.
if (!is_file( getcwd() . "/" . drupal_get_path('theme', 'cogito') . '/foundation/stylesheets/foundation.css' ) ) {
drupal_set_message("Foundation not found. You must install it before this theme can work. Please see the Cogito README file.", 'error', TRUE);
}
//Throw a warning if Cogito Base theme is enabled.
if ( $theme == 'cogito' ) {
drupal_set_message("Cogito is not meant to be run as an actual theme. Please consult README.txt in order to get your child theme up and running. It's REALLY easy!!", 'status', TRUE);
}
}
function cogito_preprocess_block(&$variables){
}
/**
* Implements hook_theme().
*/
function cogito_theme($existing, $type, $theme, $path) {
return array(
'cogito_header' => array(
'template' => 'header',
'render element' => 'cogito_header',
),
);
}
function cogito_preprocess_region(&$variables){
//Since we're rendering the logo etc inside the header region we will need to pass some
//variables to it
}
/**
* Implements hook_preprocess_html().
*
* @see bootstrap_html_head_alter().
*/
function cogito_preprocess_html(&$variables) {
global $theme;
global $base_path;
$root_d7 = getcwd();
// Cache path to theme for duration of this function:
$path_to_cogito = "/" . drupal_get_path('theme', 'cogito') . '/images/icons/';
$path_to_child = "/" . drupal_get_path('theme', $theme) . '/images/icons/';
$favicon =is_file( $path_to_child . 'favicon.ico' ) ? $path_to_child . 'favicon.ico' : $path_to_cogito . 'favicon.ico';
$icon57 = is_file( $root_d7 . $path_to_child . 'apple-57x57.png' ) ? $path_to_child . 'apple-57x57.png' : $path_to_cogito . 'apple-57x57.png';
$icon72 = is_file( $root_d7 . $path_to_child . 'apple-72x72.png' ) ? $path_to_child . 'apple-72x72.png' : $path_to_cogito . 'apple-72x72.png';
$icon114 =is_file( $root_d7 . $path_to_child . 'apple-114x114.png' )?$path_to_child . 'apple-114x114.png':$path_to_cogito . 'apple-114x114.png';
drupal_add_html_head_link(array('rel' => 'apple-touch-icon', 'href' => $icon57));
drupal_add_html_head_link(array('rel' => 'apple-touch-icon', 'href' => $icon72));
drupal_add_html_head_link(array('rel' => 'apple-touch-icon', 'href' => $icon114));
drupal_add_html_head_link(array('rel' => 'shortcut icon', 'href' => $favicon, 'type' => 'image/vnd.microsoft.icon'));
} // bootstrap_preprocess_html()
function cogito_preprocess_page(&$variables){
$root_d7 = getcwd();
global $base_path;
global $theme;
$path_to_cogito = "/" . drupal_get_path('theme', 'cogito');
$path_to_child = "/" . drupal_get_path('theme', $theme);
//If it's not a user uploaded logo and it's not in the child root. look in the /images folder
$logo = &$variables['logo'];
if ($logo == url(drupal_get_path('theme', $theme) . "/logo.png", array('absolute'=>TRUE))) {
if ( !is_file( $root_d7 . "/" . $path_to_child . "/logo.png") &&
is_file( $root_d7 . "/" . $path_to_child . "/images/logo.png") ){
$logo = url(drupal_get_path('theme', $theme) . "/images/logo.png");
}
}
/**
* WE need to do a little work to figure out the widths of things
*/
$page = &$variables['page'];
if ($page['sidebar_second'] && $page['sidebar_first']){
$cols = "3col";
}
elseif (!$page['sidebar_second'] && !$page['sidebar_first']){
$cols = "1col";
}
elseif ($page['sidebar_first']){
$cols = "2col_lsb";
}
elseif ($page['sidebar_second']){
$cols = "2col_rsb";
}
else {
$cols = "1col";
}
switch ($cols) {
case "2col_rsb":
$variables['rsb_size'] = "columns " . cogito_foundation_sizer(theme_get_setting('two_columns_rsb_right'));
$variables['lsb_size'] = "";
$variables['content_size'] = "columns " . cogito_foundation_sizer(theme_get_setting('two_columns_rsb_content'));
break;
case "2col_lsb":
$variables['rsb_size'] = "";
$variables['lsb_size'] = "columns " . cogito_foundation_sizer(theme_get_setting('two_columns_lsb_left')) . "pull-" . cogito_foundation_sizer(theme_get_setting('two_columns_lsb_content'));
$variables['content_size'] = "columns " . cogito_foundation_sizer(theme_get_setting('two_columns_lsb_content')) . "push-" . cogito_foundation_sizer(theme_get_setting('two_columns_lsb_left'));
break;
case "1col":
$variables['rsb_size'] = "";
$variables['lsb_size'] = "";
$variables['content_size'] = "columns " . cogito_foundation_sizer(theme_get_setting('one_column_content')) . " centered";
break;
//four is a nice small number that will still show something
default:
$variables['rsb_size'] = "columns " . cogito_foundation_sizer(theme_get_setting('three_columns_right'));
$variables['lsb_size'] = "columns " . cogito_foundation_sizer(theme_get_setting('three_columns_left')) . "pull-" . cogito_foundation_sizer(theme_get_setting('three_columns_content'));;
$variables['content_size'] = "columns " . cogito_foundation_sizer(theme_get_setting('three_columns_content')) . "push-" . cogito_foundation_sizer(theme_get_setting('three_columns_left'));;
break;
}
/**
* The header gets defined in header.tpl.php and needs access to some information
*/
$variables['cogito_header'] = theme('cogito_header', $variables);
}
/**
* Changes the search form to use the HTML5 "search" input attribute
*/
function cogito_preprocess_search_block_form(&$variables) {
$variables['search_form'] = str_replace('type="text"', 'type="search"', $variables['search_form']);
$variables['search_form'] = str_replace('class="form-submit"', 'class="form-submit button black"', $variables['search_form']);
}
function cogito_preprocess_menu_link(&$variables) {
//$variables['element']['#attributes']['class'][] = "button black";
}
/**
* Implements theme_breadcrumb().
* Return a themed breadcrumb trail.
*
* @param $breadcrumb
* An array containing the breadcrumb links.
* @return
* A string containing the breadcrumb output.
*/
function cogito_breadcrumb($variables) {
$breadcrumb = $variables['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 '';
}
/**
* Implements theme_status_messages().
*
* Squash drupal's status messages to fit with foundation
*/
function cogito_status_messages(&$variables){
$display = $variables['display'];
$output = '';
$status_heading = array(
'status' => t('Status message'),
'error' => t('Error message'),
'warning' => t('Warning message'),
);
$equiv = Array(
'status' => 'success',
'warning' => 'warning',
'error' => 'error');
foreach (drupal_get_messages($display) as $type => $messages) {
$output .= "<div class=\"messages alert-box $equiv[$type]\">\n";
if (!empty($status_heading[$type])) {
$output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
}
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
}
else {
$output .= $messages[0];
}
$output .= "<a href=\"#\" class=\"close\">×</a></div>\n";
}
return $output;
}
/**
* Helper Function: You say "3", I say "three"
*
*/
function cogito_foundation_sizer($num){
$nums = Array ("denada", "one","two", "three","four","five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve");
return $nums[$num];
}
/**
* Implements theme_pager().
*
* Drupal's pager system is terrible so this is a first stab at a rewrite.
* Basically we're squashing it into a shape that Foundation Pager likes
*/
function cogito_pager($variables) {
$tags = $variables['tags'];
$element = $variables['element'];
$parameters = $variables['parameters'];
$quantity = $variables['quantity'];
global $pager_page_array, $pager_total;
// Calculate various markers within this pager piece:
// Middle is used to "center" pages around the current page.
$pager_middle = ceil($quantity / 2);
// current is the page we are currently paged to
$pager_current = $pager_page_array[$element] + 1;
// first is the first page listed by this pager piece (re quantity)
$pager_first = $pager_current - $pager_middle + 1;
// last is the last page listed by this pager piece (re quantity)
$pager_last = $pager_current + $quantity - $pager_middle;
// max is the maximum page number
$pager_max = $pager_total[$element];
// End of marker calculations.
// Prepare for generation loop.
$i = $pager_first;
if ($pager_last > $pager_max) {
// Adjust "center" if at end of query.
$i = $i + ($pager_max - $pager_last);
$pager_last = $pager_max;
}
if ($i <= 0) {
// Adjust "center" if at start of query.
$pager_last = $pager_last + (1 - $i);
$i = 1;
}
// End of generation loop preparation.
$li_first = theme('pager_first', array('text' => (isset($tags[0]) ? $tags[0] : t('« first')), 'element' => $element, 'parameters' => $parameters));
$li_previous = theme('pager_previous', array('text' => (isset($tags[1]) ? $tags[1] : t('‹ previous')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
$li_next = theme('pager_next', array('text' => (isset($tags[3]) ? $tags[3] : t('next ›')), 'element' => $element, 'interval' => 1, 'parameters' => $parameters));
$li_last = theme('pager_last', array('text' => (isset($tags[4]) ? $tags[4] : t('last »')), 'element' => $element, 'parameters' => $parameters));
if ($pager_total[$element] > 1) {
if ($li_first) {
$items[] = array(
'class' => array('pager-first'),
'data' => $li_first,
);
}
if ($li_previous) {
$items[] = array(
'class' => array('pager-previous'),
'data' => $li_previous,
);
}
// When there is more than one page, create the pager list.
if ($i != $pager_max) {
if ($i > 1) {
$items[] = array(
'class' => array('pager-ellipsis'),
'data' => '…',
);
}
// Now generate the actual pager piece.
for ($i=1; $i <= $pager_last && $i <= $pager_max; $i++) {
if ($i < $pager_current) {
$items[] = array(
'class' => array('pager-item'),
'data' => theme('pager_previous', array('text' => $i, 'element' => $element, 'interval' => ($pager_current - $i), 'parameters' => $parameters)),
);
}
if ($i == $pager_current) {
$items[] = array(
'class' => array('current'),
'data' => "<a href='#'>$i</a>", //First person to criticize this has to fix it. It's late and I can't figure it out.
);
}
if ($i > $pager_current) {
$items[] = array(
'class' => array('pager-item'),
'data' => theme('pager_next', array('text' => $i, 'element' => $element, 'interval' => ($i - $pager_current), 'parameters' => $parameters)),
);
}
}
if ($i < $pager_max) {
$items[] = array(
'class' => array('pager-ellipsis'),
'data' => '…',
);
}
}
// End generation.
if ($li_next) {
$items[] = array(
'class' => array('pager-next'),
'data' => $li_next,
);
}
if ($li_last) {
$items[] = array(
'class' => array('pager-last'),
'data' => $li_last,
);
}
return '<div class="row cogito_paginate"><h2 class="element-invisible">' . t('Pages') . '</h2>' . theme('item_list', array(
'items' => $items,
'attributes' => array('class' => array('pagination')),
)) . "</div>";
}
}
/**
* Implements theme_button().
*
* This is how we force drupal to use Foundation's buttons
*/
function cogito_button($variables) {
$variables['element']['#attributes']['class'][] = 'nice small button black';
return theme_button($variables);
}
/**
* Implements theme_form().
*
* Forcing Drupal to use foundation's "nice" forms elements
*/
function cogito_form($variables) {
$variables['element']['#attributes']['class'][] = 'nice';
return theme_form($variables);
}
//Not working yet: need to add input-text class to all relevant inputs
function cogito_form_element($variables) {
//kpr($variables);
return theme_form_element($variables);
}