forked from NCSU-Libraries/ncsulib_foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.php
More file actions
executable file
·515 lines (442 loc) · 17.6 KB
/
template.php
File metadata and controls
executable file
·515 lines (442 loc) · 17.6 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
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
<?php
/**
* Setting custom variable htdocs root path
*/
variable_set('htdocs_root', str_replace(strrchr(DRUPAL_ROOT, "/"), "/htdocs", DRUPAL_ROOT));
/**
* Implements template_preprocess_page()
*
* The code below handles additional page template/CSS suggestions in Drupal
* and other various and sundry activities
*/
function ncsulib_foundation_preprocess_page(&$variables) {
// Add page--node_type.tpl.php suggestions
if (!empty($variables['node'])) {
$variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type;
}
// Convenience variables
if (!empty($variables['page']['sidebar_first'])){
$left = $variables['page']['sidebar_first'];
}
if (!empty($variables['page']['sidebar_second'])) {
$right = $variables['page']['sidebar_second'];
}
// Dynamic sidebars (this is critical)
if (!empty($left) && !empty($right)) {
$variables['main_grid'] = 'medium-6 push-3';
$variables['sidebar_left'] = 'pull-6';
} elseif (empty($left) && !empty($right)) {
$variables['main_grid'] = 'medium-9';
$variables['sidebar_left'] = '';
} elseif (!empty($left) && empty($right)) {
$variables['main_grid'] = 'medium-9 push-3';
$variables['sidebar_left'] = 'pull-9';
} else {
$variables['main_grid'] = 'medium-12';
}
/**
* End d.o Foundation code
*/
// Begin CSS suggestions
if (module_exists('path')) {
$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
// If the alias is a clean URL
if ($alias != $_GET['q'] || empty($variables['node'])) {
// Break the alias into its parts and iterate through the alias part by
// part
$i=0;
foreach (explode('/', $alias) as $path_part) {
if ($i==0) {
// If this is the first time through the loop, create the template
// suggestion
$template_suggestion = $path_part;
$css_suggestion = $path_part;
} elseif ($i>=1) {
if ($i==1) {
// If this is the second time through the loop, create a variable
// to append each $path_part to
$path_part_holder = $css_suggestion . '--' . $path_part;
} elseif ($i>=2) {
$path_part_holder .= '--' . $path_part;
}
// If this is the second time or more through the loop, continue to
// append the alias path to the template suggestion
$template_suggestion = $template_suggestion . '__' . $path_part;
$css_suggestions[] = $path_part_holder;
}
$i++;
}
$template_suggestion = 'page__' . $template_suggestion;
// Add the template suggestion to the template suggestions hook
$variables['theme_hook_suggestions'][] = $template_suggestion;
}
// Create the CSS suggestion(s)
if (isset($css_suggestion)) {
$css_suggestion = path_to_theme() .'/styles/core/custom/'. $css_suggestion .'.css';
// CSS suggestion for the top level alias path
$include_style[] = $css_suggestion;
// If the page resides at a deep level and more specific CSS is desired,
// add more specific page CSS suggestions
if (isset($css_suggestions)) {
foreach ($css_suggestions as $suggestion) {
$include_style[] = path_to_theme() .'/styles/core/custom/'. $suggestion .'.css';
}
}
}
// If there are CSS suggestions to include
if (isset($include_style)) {
foreach ($include_style as $included_styles) {
// Add the CSS suggestion to Drupal, add it after the 100 group which
// contains the global theme-level css
drupal_add_css($included_styles, array('group' => 101));
}
}
// End CSS suggestions
}
// Creating a single template suggestion for all pages that begin with /scrc
// allowing for overrides by more specific path-based or node id templates
// e.g. page--scrc--zoologicalhealth.tpl.php or page--node--9999.tpl.php
if (preg_match('/^scrc/', $alias)){
$arr_length = count($variables['theme_hook_suggestions']);
array_splice($variables['theme_hook_suggestions'], ($arr_length-2), 0, 'page__scrc__subpage');
}
// Add sidebard detector to the node object
if(!empty($variables['page']['sidebar_first'])){
$node_id = key($variables['page']['content']['system_main']['nodes']);
$variables['page']['content']['system_main']['nodes'][$node_id]['#node']->sidebar_first = TRUE;
}
// Add custom JS/CSS
$url_comp = explode('/', request_uri());
// just one directory deep
if (isset($url_comp[1]) && !isset($url_comp[2])) {
// for two dirs deep (ex: find/books)
switch ($url_comp[1]) {
case 'news':
drupal_add_js(path_to_theme() . '/scripts/news-event-tracking.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
}
}
// hack to remove dupes on event series page
if (isset($url_comp[2])) {
switch ($url_comp[2]) {
case 'series':
drupal_add_js(path_to_theme() . '/scripts/event-series-hack.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
}
}
// for entire directory (ex: /find)
if (isset($url_comp[1])) {
switch ($url_comp[1]) {
case 'styleguide':
drupal_add_js(path_to_theme() . '/scripts/styleguide.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
case 'news':
drupal_add_js(path_to_theme() . '/scripts/vendor/foundation/foundation.topbar.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
drupal_add_js(path_to_theme() . '/scripts/news.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
case 'nrl':
drupal_add_js(path_to_theme() . '/scripts/device-availability-by-library.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
case 'vetmed':
drupal_add_js(path_to_theme() . '/scripts/device-availability-by-library.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
case 'software':
drupal_add_js(path_to_theme() . '/scripts/software.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
case '1databases':
drupal_add_js(path_to_theme() . '/scripts/databases.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
}
if (isset($url_comp[1]) && isset($url_comp[2])) {
// for two dirs deep (ex: find/books)
switch ($url_comp[1] . '/' . $url_comp[2]) {
case 'borrow/privileges':
drupal_add_js(path_to_theme() . '/scripts/borrow-privileges.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
case 'makerspace/projects':
drupal_add_js('https://form.jotform.com/jsform/61057405269153', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
case 'spaces/music-booths-hill':
drupal_add_js(path_to_theme() . '/scripts/music-rooms.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
}
}
}
// target a specific single page
$url_comp = explode('/', request_path());
$url_comp = implode('--', $url_comp);
switch ($url_comp) {
case 'techlending':
drupal_add_js(path_to_theme() . '/scripts/vendor/foundation/foundation.equalizer.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
break;
// case 'reservearoom':
// drupal_add_js(path_to_theme() . '/scripts/reservearoom.js', array('type' => 'file', 'group' => 101, 'weight' => 1));
// break;
case 'huntlibrary--namingopportunities':
drupal_add_css(path_to_theme() . '/styles/blitzer/jquery-ui-1.10.4.custom.min.css', 'file');
drupal_add_js(path_to_theme() . '/scripts/vendor/jquery-ui-1.10.4.custom.min.js', 'file');
drupal_add_js(path_to_theme() . '/scripts/vendor/jquery.imagemapster.min.js', 'file');
drupal_add_js(path_to_theme() . '/scripts/namingopps.js', 'file');
drupal_add_js(path_to_theme() . '/scripts/vendor/jquery.tablesorter.min.js', 'file');
break;
}
// hide default 'no content' text for taxonomy terms
if(isset($variables['page']['content']['system_main']['no_content'])) {
unset($variables['page']['content']['system_main']['no_content']);
}
// overwrite 'user activity' taxonomy template page
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
$term = taxonomy_term_load(arg(2));
// $variables['theme_hook_suggestions'][] = 'page__taxonomy_' . $term->vocabulary_machine_name;
// unset all content from user activity taxonomy page
if($term->vocabulary_machine_name == 'user_activities' || $term->vocabulary_machine_name == 'services'){
unset($variables['page']['content']['system_main']['nodes']);
// unset($variables['page']['content']['system_main']['term_heading']['term']);
unset($variables['page']['content']['system_main']['pager']);
};
}
} // End tremendous template_preprocess_page function
/**
* Impelments template_preprocess_node()
*
*/
function ncsulib_foundation_preprocess_node(&$variables) {
switch ($variables['type']) {
case 'space':
drupal_add_css(path_to_theme() . '/styles/core/custom/space.css', array('group' => 101));
break;
case 'report':
drupal_add_css(path_to_theme() . '/styles/core/custom/report.css', array('group' => 101));
break;
}
// Make "node--NODETYPE--VIEWMODE.tpl.php" templates available for nodes
if ($variables['view_mode'] == 'teaser') {
$variables['theme_hook_suggestions'][] = 'node__' . $variables['node']->type . '__teaser';
$variables['theme_hook_suggestions'][] = 'node__' . $variables['node']->nid . '__teaser';
}
}
/**
* Blocks preprocessor
*
* Handles adding additional classes to the blocks on the "/upcomingevents"
* page. Adds classes to blocks on the scrc page.
*/
function ncsulib_foundation_preprocess_block(&$variables) {
// adding classes to blocks on /scrc
if ($variables['block_html_id'] == "block-aggregator-feed-8") {
$variables['classes_array'][] = 'medium-8';
$variables['classes_array'][] = 'columns';
}
if ($variables['block_html_id'] == "block-block-78"){
$variables['classes_array'][] = 'medium-3';
$variables['classes_array'][] = 'columns';
}
if ($variables['elements']['#block']->delta == "capture_and_promote-block_4") {
drupal_add_css(path_to_theme() . '/styles/core/custom/capture_and_promote-block_4.css', array('group' => 101));
}
}
/**
* Implements hook_process_HOOK()
*
* Making our resource references (css and js) themeless
*/
function ncsulib_foundation_process_html(&$vars){
foreach (array('head', 'styles', 'scripts', 'page_bottom') as $replace) {
if (!isset($vars[$replace])) {
continue;
}
$vars[$replace] = preg_replace('/(src|href|@import )(url\(|=)(")http(s?):/', '$1$2$3', $vars[$replace]);
}
$output = array(
'#type' => 'markup',
'#markup' => '<script id="embedUV" type="text/javascript" src="https://scrc.lib.ncsu.edu/sal_staging/uv-1.7.27/lib/embed.js"></script>' . "\r",
);
$vars['scripts'] .= drupal_render($output);
// kpr($variables);
//show media embed js on /scrc only
if (arg(0) == 'scrc'){
$output = array(
'#type' => 'markup',
'#markup' => '<script language="javascript" type="text/javascript" src="http://platform.linkedin.com/in.js">api_key: mykey</script>' . "\r",
);
$vars['scripts'] .= drupal_render($output);
}
}
/**
* Implements theme_menu_link()
*
* Adding Foundation 5 class for side navigation
*/
function ncsulib_foundation_menu_tree($variables) {
return '<ul class="side-nav">' . $variables['tree'] . '</ul>';
}
/**
* Implements hook_js_alter()
*/
function ncsulib_foundation_js_alter(&$javascript) {
// Remove old jQuery
unset($javascript['misc/jquery.js']);
// Unset jQuery from the jQuery Update module
unset($javascript['https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js']);
unset($javascript['https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js']);
unset($javascript['sites/all/modules/panels/js/panels.js']);
unset($javascript[0]);
}
/**
* Implements theme_breadrumb().
*
* Print breadcrumbs as a list, with separators.
*/
function ncsulib_foundation_breadcrumb($variables) {
$links = array();
$path = '';
// Get URL arguments
$arguments = explode('/', request_uri());
// Remove empty values
foreach ($arguments as $key => $value) {
if (empty($value)) {
unset($arguments[$key]);
}
}
$arguments = array_values($arguments);
// Add 'Home' link
$links[] = l(t('Home'), '<front>');
// Add other links
if (!empty($arguments)) {
foreach ($arguments as $key => $value) {
// Don't make last breadcrumb a link
if ($key == (count($arguments) - 1)) {
$links[] = drupal_get_title();
} else {
if (!empty($path)) {
$path .= '/'. $value;
} else {
$path .= $value;
}
$links[] = l(drupal_ucfirst($value), $path);
}
}
}
// Set custom breadcrumbs
drupal_set_breadcrumb($links);
// Get custom breadcrumbs
$breadcrumb = drupal_get_breadcrumb();
if (!empty($breadcrumb)) {
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
$breadcrumbs = '<h2 class="element-invisible">' . t('You are here') . '</h2>';
$breadcrumbs .= '<ul class="breadcrumbs">';
foreach ($breadcrumb as $key => $value) {
$breadcrumbs .= '<li>' . $value . '</li>';
}
$title = strip_tags(drupal_get_title());
$breadcrumbs .= '</ul>';
// only want breadcrumbs for /jobs right now
$url_components = explode('/', request_uri());
if(
$url_components[1] == 'jobs' ||
$url_components[1] == 'spaces' ||
$url_components[1] == 'social-media-archives-toolkit' ||
$url_components[1] == 'projects' ||
$url_components[1] == 'database' ||
$url_components[1] == '1databases' ||
$url_components[1] == 'software' ||
$url_components[1] == 'stories' ||
$url_components[1] == 'databases'
){
return $breadcrumbs;
} else{
return '';
}
}
}
/**
* Implements hook_form_FORM_ID_alter()
*
*/
function ncsulib_foundation_form_user_login_alter(&$form, &$form_state, $form_id) {
// Alters the text on the user login form
drupal_set_title(t('Website editing login'));
$form['name']['#title'] = t('Enter your Unity ID:');
$form['name']['#description'] = t(''); // Enter descriptive text here, if desired
$form['pass']['#title'] = t('Enter your Unity password:');
$form['pass']['#description'] = t(''); // Enter descriptive text here, if desired
}
/**
* Do we still need this?
*
*/
function ncsulib_foundation_more_link ($array) {
if (stristr($array['url'], 'aggregator')) {
return "";
}
}
/**
* Modify the output of views
*
*/
function ncsulib_foundation_views_pre_render(&$view) {
// add staff member name to page title
if ($view->name == 'staff' && $view->current_display == 'page') {
$first = $view->result[0]->_field_data['uid']['entity']->field_firstname['und'][0]['value'];
$last = $view->result[0]->_field_data['uid']['entity']->field_lastname['und'][0]['value'];
$view->build_info['title'] = $first.' '.$last;
}
// The following two loops add month and day formatted dates to events
if ($view->name == 'upcoming_events' && $view->current_display == 'block_3') {
if (!empty($view->result)) {
for ($i = 0; $i < count($view->result); $i++ ) {
// Set event url
$node = node_load($view->result[$i]->nid);
$url_data = field_get_items('node', $node, 'field_event_url');
$alias = drupal_get_path_alias('node/'.$node->nid);
if(!empty($url_data[0]['url'])) {
$view->result[$i]->event_url = $url_data[0]['url'];
} else if ($alias){
$view->result[$i]->event_url = $alias;
} else {
$view->result[$i]->event_url = '/node/'.$view->result[$i]->nid;
}
// Set event dates
$timestamp = filter_xss($view->result[$i]->field_data_field_time_field_time_value);
$timestamp2 = filter_xss($view->result[$i]->field_data_field_time_field_time_value2);
$open = strtotime($timestamp)+ncsulib_foundation_adjust_for_timezone($timestamp);
$close = strtotime($timestamp2)+ncsulib_foundation_adjust_for_timezone($timestamp2);
$view->result[$i]->date_display = (date('m j Y', $open) == date('m j Y', $close)) ? date('M j, Y', $open) : date('M j, Y', $open) . ' - ' . date('M j, Y', $close);
}
}
}
// Add stylesheet to make the related devices on tech categories look right
if ($view->name == 'devices_device' && $view->current_display == 'block_9') {
drupal_add_css(path_to_theme() . '/styles/related_devices.css');
}
// Add stylesheet to cover all dataviews block displays
if ($view->name == "dv_hours_open") {
drupal_add_css(path_to_theme() . '/styles/dataviews.css');
}
}
/**
* Helper function that adjusts date to current timezone. Especially for
* daylight savings
*/
function ncsulib_foundation_adjust_for_timezone($time){
$origin_dtz = new DateTimeZone(date_default_timezone_get());
$origin_dt = new DateTime($time, $origin_dtz);
return $origin_dtz->getOffset($origin_dt);
}
/* All fields theming funcitons */
include __DIR__ . '/fields.inc';
/* the nomarkup theme function */
function ncsulib_foundation_nomarkup($variables) {
$output = '';
// Render the items.
foreach ($variables['items'] as $delta => $item) {
$output .= drupal_render($item);
}
return $output;
}
// get url segment of url alias
function urlsegment($seg){
$url_comp = explode('/', request_path());
return $url_comp[$seg];
}