-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtemplate.php
895 lines (781 loc) · 29 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
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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
<?php
/**
* @file
* Theme function overrides.
*/
/*******************************************************************************
* Alter functions: modify renderable structures before used.
******************************************************************************/
/**
* Implements hook_form_FORM_ID_alter().
*/
function borg_form_user_register_form_alter(&$form, &$form_state) {
$help = t('Already have an account?') . ' ' . l(t('Log in instead'), 'user/login') . '.';
$form['login'] = array(
'#type' => 'help',
'#markup' => $help,
'#weight' => -100,
);
// Remove description text from password.
unset($form['account']['pass']['#description']);
// Fix the description text for email address.
$form['account']['mail']['#description'] = t('This e-mail address is not made public and will only be used if you choose to receive messages.');
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function borg_form_user_login_alter(&$form, &$form_state) {
$help = t('Don\'t have an account yet?') . ' ' . l(t('Create one now'), 'user/register') . '.';
$form['login'] = array(
'#type' => 'help',
'#markup' => $help,
'#weight' => -100,
);
// Add a forgot password link, since tabs are removed.
$form['actions']['forgot'] = array(
'#markup' => '<small>' . l(t('Forgot password?'), 'user/password') . '</small>',
'#weight' => 10,
);
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Removes useless description text from log in form, adds additional links.
*/
function borg_form_user_pass_alter(&$form, &$form_state) {
// Add a log in link, since tabs are removed.
$form['actions']['forgot'] = array(
'#markup' => '<small>' . l(t('Log in'), 'user/login') . '</small>',
'#weight' => 10,
);
}
/**
* Implements hook_menu_alter().
*
* Removes tabs from the log in and password pages.
*/
function borg_menu_alter(&$items) {
$items['user/login']['type'] = MENU_CALLBACK;
$items['user/pasword']['type'] = MENU_CALLBACK;
$items['node']['page callback'] = 'backdrop_not_found';
}
/*******************************************************************************
* Preprocess functions: prepare variables for templates.
******************************************************************************/
/**
* Prepares variables for page templates.
* @see page.tpl.php
*/
function borg_preprocess_page(&$variables) {
$arg0 = check_plain(arg(0));
$arg1 = check_plain(arg(1));
$arg2 = check_plain(arg(2));
// Add the Source Sans Pro font.
$source_sans = 'https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700';
backdrop_add_css($source_sans, array('type' => 'external'));
// Add FontAwesome.
$font_awesome = 'https://use.fontawesome.com/baf3c35582.js';
backdrop_add_js($font_awesome, array('type' => 'external'));
// Add ForkAwesome.
$fork_awesome = 'https://cdn.jsdelivr.net/npm/[email protected]/css/fork-awesome.min.css';
$attributes = array(
'integrity' => 'sha256-XoaMnoYC5TH6/+ihMEnospgm0J1PM/nioxbOUdnM8HY=',
'crossorigin' => 'anonymous',
);
backdrop_add_css($fork_awesome, array('type' => 'external', 'attributes' => $attributes));
// Add a body class based on the admin bar.
if (module_exists('admin_bar') && user_access('admin_bar')) {
$variables['classes'][] = 'admin-bar';
}
$path = backdrop_get_path('theme', 'borg');
// Add Flexslider to the front page only.
if (backdrop_is_front_page()) {
backdrop_add_css($path . '/css/page-front.css');
}
elseif ($arg0 == 'support') {
if ($arg1 == 'services') {
backdrop_add_css($path . '/css/page-services.css');
}
}
elseif ($arg0 == 'modules' || $arg0 == 'themes' || $arg0 == 'layouts') {
$variables['classes'][] = 'project-search';
backdrop_add_css($path . '/css/page-project-search.css');
}
elseif ($arg0 == 'user') {
if ($arg1 == 'login') {
$variables['classes'][] = 'user-form';
$variables['classes'][] = 'user-login';
}
if ($arg1 == 'register') {
$variables['classes'][] = 'user-form';
$variables['classes'][] = 'user-reister';
}
elseif ($arg1 == 'password') {
$variables['classes'][] = 'user-form';
$variables['classes'][] = 'user-password';
}
else {
global $user;
if ($user->uid == 0 && !$arg1) {
$variables['classes'][] = 'user-form';
$variables['classes'][] = 'user-login';
}
elseif (is_numeric($arg1) && !$arg2 || ($user->uid)) {
$variables['classes'][] = 'profile-page';
backdrop_add_css($path . '/css/page-profile.css');
}
}
}
// Add a class based on the node ID...
if ($arg0 == 'node' && is_numeric($arg1) && !$arg2) {
$variables['classes'][] = 'node-' . $arg1;
}
// ...or add classes based on args.
elseif ($arg0) {
$variables['classes'][] = $arg0;
if ($arg1) {
$variables['classes'][] = $arg0 . '-' . $arg1;
if ($arg2) {
$variables['classes'][] = $arg0 . '-' . $arg1 . '-' . $arg2;
}
}
}
}
/**
* Prepares variables for layout templates.
* @see layout.tpl.php
*/
function borg_preprocess_layout(&$variables) {
$arg0 = check_plain(arg(0));
$arg1 = check_plain(arg(1));
$arg2 = check_plain(arg(2));
$variables['wrap_attributes'] = array('class' => array('l-wrapper'));
if ($arg0 == 'user' && !is_numeric($arg1)) {
$variables['tabs'] = FALSE;
}
// Special handling for header image.
if ($arg0 == 'user' && is_numeric($arg1) && !$arg2) {
// Check to see if there is a profile image.
$account = user_load($arg1); // Entity cache should save us here?
if (isset($account->field_header_photo[LANGUAGE_NONE][0]['uri'])) {
// Generate an image at the correct size.
$image = image_style_url('header', $account->field_header_photo[LANGUAGE_NONE][0]['uri']);
$variables['wrap_attributes']['style'] = 'background-image: url(' . $image . ')';
// Add an addidional class.
$variables['wrap_attributes']['class'][] = 'has-background';
}
}
}
/**
* Preprocess header templates.
* @see header.tpl.php
*/
function borg_preprocess_header(&$variables) {
$path = backdrop_get_path('theme', 'borg');
$variables['logo'] = theme('image', array('uri' => $path . '/logo-inverse.png'));
// Remove Backdrop CMS from the site name in the header template.
if ($variables['site_name'] && strstr($variables['site_name'], 'Backdrop CMS')) {
$variables['site_name'] = trim(str_replace('Backdrop CMS', '', $variables['site_name']));
}
}
/**
* Preprocess views exposed form templates.
* @see views-exposed-form.tpl.php
*/
function borg_preprocess_views_exposed_form(&$variables) {
if (substr($variables['form']['#id'], 0, 26) == 'views-exposed-form-modules'){
// Update search field
$search_field_key = '';
$search_type = check_plain(arg(0));
if (!empty($variables['form']['keys'])){
$search_field_key = 'keys';
}
elseif (!empty($variables['form']['title'])){
$search_field_key = 'title';
}
if (!empty($search_field_key)){
// Boo divitis
unset($variables['form'][$search_field_key]['#theme_wrappers']);
// Add placeholder text
$variables['form'][$search_field_key]['#attributes']['placeholder'] = t('Search '. $search_type .'...');
// Re-render field
$variables['widgets']['filter-'. $search_field_key]->widget = render($variables['form'][$search_field_key]);
}
}
}
/**
* Prepare variables for node templates.
* @see node.tpl.php
*/
function borg_preprocess_node(&$variables){
// Add missing node type suggestion.
array_unshift($variables['theme_hook_suggestions'], 'node__' . $variables['node']->type);
// Add theme hook suggestions for view mode.
if ($variables['view_mode'] != 'full') {
array_unshift($variables['theme_hook_suggestions'], 'node__' . $variables['view_mode']);
}
if ($variables['view_mode'] == 'project_search') {
$node = $variables['node']; // Nice shorthand.
// Set column sizes for each view-mode.
$variables['classes_col1'] = array('col-md-4', 'col-md-push-8');
$variables['classes_col2'] = array('col-md-8', 'col-md-pull-4');
if ($node->type == 'project_theme') {
$variables['classes_col1'] = array('col-md-6', 'col-md-push-6');
$variables['classes_col2'] = array('col-md-6', 'col-md-pull-6');
}
// Move the image into the sidebar.
$variables['image'] = backdrop_render($variables['content']['field_image']);
// Start a place for footer info.
$footer_links = array();
// Add some statistics info for the footer.
if (isset($variables['content']['field_download_count'])) {
$count = backdrop_render($variables['content']['field_download_count']);
$footer_links['count']['data'] = $count;
}
if (isset($variables['content']['project_usage'])) {
$variables['content']['project_usage']['#weight'] = 10;
$usage = backdrop_render($variables['content']['project_usage']);
$footer_links['usage']['data'] = $usage;
}
// Add a more info link to content.
$variables['content']['more'] = array(
'#type' => 'link',
'#title' => t('More details'),
'#href' => url('node/' . $node->nid, array('absolute' => TRUE)),
'#attributes' => array('class' => array('button', 'button-small', 'more-details')),
'#weight' => 10,
);
// Get the recomended release info.
$release = FALSE;
$result = views_get_view_result('project_release_download_table', 'recommended', $node->nid);
if (count($result) == 1) {
$release = reset($result);
}
if ($release) {
// Add the latest release version.
$version = array(
'#type' => 'markup',
'#markup' => '<span>' . t('Version: <strong>@version</strong>', array('@version' => $release->project_release_node_version)) . '</span>',
);
$footer_links['version']['data'] = backdrop_render($version);
// Add the latest release date.
$date = format_date($release->node_project_release_supported_versions_created, 'short');
$latest = array(
'#type' => 'markup',
'#markup' => '<span class="release-date">' . t('Released: <strong>@date</strong>', array('@date' => $date)) . '</span>',
);
$footer_links['latest']['data'] = backdrop_render($latest);
// Add an area for download info.
$variables['download'] = array();
// Add download link.
$variables['download']['button'] = array(
'#type' => 'link',
'#title' => t('Download'),
'#href' => $release->project_release_node_download_link,
'#attributes' => array('class' => array('button', 'button-small')),
'#weight' => -11,
);
// Add download file size.
$variables['download']['size'] = array(
'#type' => 'markup',
'#markup' => '<span class="download-size"><span>' . format_size($release->project_release_node_download_size) . '</span></span>',
'#weight' => -10,
);
}
// Put release info in a list.
$variables['footer_info'] = array(
'#theme' => 'item_list',
'#items' => $footer_links,
);
}
if ($variables['type'] == 'project_module' || $variables['type'] == 'project_theme' || $variables['type'] == 'project_layout') {
if ($variables['view_mode'] == 'teaser') {
if (isset($variables['content']['links'])) {
$old_title = $variables['content']['links']['node']['#links']['node-readmore']['title'];
$new_title = str_replace('Read more', 'More details', $old_title);
unset($variables['content']['links']);
}
}
}
// For blog posts.
if ($variables['type'] == 'post') {
// Load the author.
$author = user_load($variables['uid']);
$lang = $author->langcode;
// Change the username to a real name.
if (!empty($author->field_name[$lang])) {
$variables['name'] = l($author->field_name[$lang][0]['safe_value'], 'user/' . $author->uid);
}
// Get the profile photo if the field exists.
$variables['user_picture'] = '';
if (property_exists($author, 'field_photo')) {
if (!empty($author->field_photo)) {
$uri = $author->field_photo[$lang][0]['uri'];
$variables['user_picture'] = theme('image_style', array(
'style_name' => 'headshot_small', 'uri' => $uri));
}
}
}
// Change the submitted by language for all nodes.
$variables['submitted'] = t('Posted by !username on !datetime', array(
'!username' => $variables['name'], '!datetime' => $variables['date']));
}
/**
* Prepare variables for comment templates.
* @see comment.tpl.php
*/
function borg_preprocess_comment(&$variables){
// Change text to "Comment from".
$variables['submitted'] = str_replace('Submitted by', 'Comment from', $variables['submitted']);
// Get the headshot photo from the field.
$author = user_load($variables['comment']->uid);
if (!empty($author->field_photo)) {
$langcode = $author->langcode;
$uri = $author->field_photo[$langcode][0]['uri'];
$variables['user_picture'] = theme('image_style', array('style_name' => 'headshot_small', 'uri' => $uri));
}
}
/**
* Prepares variables for all RSS rows.
*/
function borg_preprocess_views_view_row_rss(&$variables) {
$view = &$variables['view'];
$item = &$variables['row'];
// Un-escpape the previously escaped title to prevent double escaping.
$variables['title'] = decode_entities($item->title);
// Add a special class to the featured image to optimize for Feedly.
$view->result[0]->field_field_image[0]['rendered']['#item']['attributes']['class'] = array('webfeedsFeaturedVisual');
// Add an image tag to the top of the description.
$image = backdrop_render($view->result[0]->field_field_image[0]['rendered']);
$complete_description = '<![CDATA[' . $image . '<br/>' . $item->description . ']]>';
$item->description = $complete_description;
$variables['description'] = $complete_description;
}
/**
* Prepares variables for views grid templates.
* @see views-view-grid.tpl.php
*/
function borg_preprocess_views_view_grid(&$variables) {
$view = $variables['view'];
// Add bootstrap grid instead of legacy table.
if ($view->style_plugin->options['deprecated_table']) {
$cols = $view->style_plugin->options['columns'];
$rows = $variables['rows'];
// These views have the columns stay wider at smaller screensizes.
$sm_grid_views = array(); // @todo
if (in_array($view->name, $sm_grid_views)) {
$column_classes = array(
1 => 'col-sm-12',
2 => 'col-sm-6',
3 => 'col-sm-4',
4 => 'col-sm-3',
5 => 'col-sm-5ths',
6 => 'col-sm-2',
);
}
else {
$column_classes = array(
1 => 'col-md-12',
2 => 'col-md-6',
3 => 'col-md-4',
4 => 'col-md-3',
5 => 'col-md-5ths',
6 => 'col-md-2',
);
}
$col_class = $column_classes[$cols];
// Apply the radix classes
foreach ($rows as $row_number => $row) {
$variables['row_classes'][$row_number][] = 'row';
$variables['row_classes'][$row_number][] = 'row-fluid';
foreach ($rows[$row_number] as $column_number => $item) {
$variables['column_classes'][$row_number][$column_number][] = $col_class;
}
}
$variables['classes'][] = 'container-fluid';
}
}
/**
* Prepares variables for book navigation templates.
* @see book-navigation.tpl.php
*/
function borg_preprocess_book_navigation(&$variables) {
$book_link = $variables['book_link'];
if ($book_link['mlid']) {
// Change the previous link.
if ($previous = _borg_book_prev($book_link)) {
$previous_href = url($previous['href']);
backdrop_add_html_head_link(array('rel' => 'prev', 'href' => $previous_href));
$variables['prev_url'] = $previous_href;
$variables['prev_title'] = check_plain($previous['title']);
}
// Change the next link.
if ($next = _borg_book_next($book_link)) {
$next_href = url($next['href']);
backdrop_add_html_head_link(array('rel' => 'next', 'href' => $next_href));
$variables['next_url'] = $next_href;
$variables['next_title'] = check_plain($next['title']);
}
}
// Re-check the has links status since it was altered above.
$variables['has_links'] = FALSE;
// Link variables to filter for values and set state of the flag variable.
$links = array('prev_url', 'prev_title', 'parent_url', 'parent_title', 'next_url', 'next_title');
foreach ($links as $link) {
if (isset($variables[$link])) {
// Flag when there is a value.
$variables['has_links'] = TRUE;
}
else {
// Set empty to prevent notices.
$variables[$link] = '';
}
}
}
/******************************************************************************
* Theme function overrides
******************************************************************************/
/**
* Replaces book_prev().
*/
function _borg_book_prev($book_link) {
// If the parent is zero, we are at the start of a book.
if ($book_link['plid'] == 0) {
return NULL;
}
$flat = book_get_flat_menu($book_link);
// Remove child pages from next/prev links.
foreach ($flat as $key => $item) {
if ($item['depth'] > 2) {
unset($flat[$key]);
}
}
$current = NULL;
foreach ($flat as $key => $current) {
if ($key != $book_link['mlid']) {
$previous = $current;
}
}
return $previous;
}
/**
* Replaces book_next().
*/
function _borg_book_next($book_link) {
$flat = book_get_flat_menu($book_link);
// Remove child pages from next/prev links.
foreach ($flat as $key => $item) {
if ($item['depth'] > 2) {
unset($flat[$key]);
}
}
foreach ($flat as $key => $current) {
if ($key == $book_link['mlid']) {
return current($flat);
}
}
}
/**
* Overrides theme_form_element().
*/
function borg_form_element($variables) {
$element = &$variables['element'];
// This function is invoked as theme wrapper, but the rendered form element
// may not necessarily have been processed by form_builder().
$element += array(
'#title_display' => 'before',
'#wrapper_attributes' => array(),
);
$attributes = $element['#wrapper_attributes'];
// Add element #id for #type 'item'.
if (isset($element['#markup']) && !empty($element['#id'])) {
$attributes['id'] = $element['#id'];
}
// Add element's #type and #name as class to aid with JS/CSS selectors.
$attributes['class'][] = 'form-item';
if (!empty($element['#type'])) {
$attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
}
if (!empty($element['#name'])) {
$attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
}
// Add a class for disabled elements to facilitate cross-browser styling.
if (!empty($element['#attributes']['disabled'])) {
$attributes['class'][] = 'form-disabled';
}
$output = '<div' . backdrop_attributes($attributes) . '>' . "\n";
// If #title is not set, we don't display any label or required marker.
if (!isset($element['#title'])) {
$element['#title_display'] = 'none';
}
$prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
$suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
switch ($element['#title_display']) {
case 'before':
case 'invisible':
if ($element['#type'] == 'textarea' || $element['#type'] == 'checkboxes' || $element['#type'] == 'radios' ||
(array_key_exists('#field_name', $element) && $element['#field_name'] == 'field_expertise')) {
$output .= ' ' . theme('form_element_label', $variables);
if (!empty($element['#description'])) {
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
}
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
}
else {
$output .= ' ' . theme('form_element_label', $variables);
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
if (!empty($element['#description'])) {
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
}
}
break;
case 'after':
$output .= ' ' . $prefix . $element['#children'] . $suffix;
$output .= ' ' . theme('form_element_label', $variables) . "\n";
if (!empty($element['#description'])) {
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
}
break;
case 'none':
case 'attribute':
if ($element['#type'] == 'password') {
// Output no label and no required marker, only the children.
if (!empty($element['#description'])) {
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
}
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
}
else {
// Output no label and no required marker, only the children.
$output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
if (!empty($element['#description'])) {
$output .= '<div class="description">' . $element['#description'] . "</div>\n";
}
}
break;
}
$output .= "</div>\n";
return $output;
}
/**
* Overrides theme_socialfield_drag_components().
*/
function borg_socialfield_drag_components($variables) {
$element = $variables['element'];
backdrop_add_tabledrag('socialfield-table', 'order', 'sibling', 'item-row-weight');
$services = config_get('socialfield.settings', 'services');
$header = array(t($element['#title']), '', '', '');
$rows = array();
$index = 0;
for ($i=0; $i<$element['#num_elements']; $i++) {
while (!isset($element['element_' . $index])) {
// There is no element with this index. Moving on to the next possible element.
$index++;
}
$current_element = $element['element_' . $index];
$rows[] = array(
'data' => array(
'<div class="social-links">' .
'<span class="socialfield socialfield-' . $current_element['#service'] . '">' .
'<i class="icon ' . $services[$current_element['#service']]['icon'] . '">' . t($services[$current_element['#service']]['name']) . '</i>' .
'</span>' .
'</div>',
backdrop_render($current_element['url']),
backdrop_render($current_element['weight']),
backdrop_render($current_element['operation']),
),
'class' => array('draggable'),
'weight' => $current_element['weight']['#value'],
);
$index++;
}
// Sorting elements by their weight.
backdrop_sort($rows, array('weight'));
$output = theme('table', array(
'header' => $header,
'rows' => $rows,
'attributes' => array(
'id' => 'socialfield-table',
),
));
$output .= '<div class="description">' . backdrop_render($element['description']) . '</div>';
$output .= backdrop_render($element['add_one_social']);
return $output;
}
/**
* Overrides theme_menu_tree().
*/
function borg_menu_tree__user_menu($variables) {
$variables['attributes']['class'][] = 'closed';
global $user;
$output = '<nav class="borg-greeting">';
$output .= ' <ul class="borg-user-menu">';
$output .= ' <li class=top>';
if ($user->uid) {
$greeting = t('Hi @name!', array('@name' => $user->name));
$output .= ' <a href="#" id="greeting" class="greeting">' . $greeting . '</a>';
}
else {
$output .= ' <a href="#" id="greeting" class="greeting">' . t('Welcome!') . '</a>';
}
$output .= ' <ul' . backdrop_attributes($variables['attributes']) . '>' . $variables['tree'] . '</ul>';
$output .= ' </li>';
$output .= ' </ul>';
$output .= ' <a class="icon" title="Code on GitHub" href="https://github.com/backdrop/backdrop"><i class="fa fa-github fa-2x" aria-hidden="true"></i></a>';
$output .= ' <a class="icon" title="Live Chat on Zulip" href="https://backdrop.zulipchat.com/#narrow/stream/218635-Backdrop"><i class="fa fa-commenting fa-2x" aria-hidden="true"></i></a>';
$output .= ' <a class="icon" title="Updates from our Newsletter" href="https://backdropcms.org/newsletter"><i class="fa fa-envelope fa-2x" aria-hidden="true"></i></a>';
$output .= '</nav>';
return $output;
}
/**
* Overrides theme_feed_icon().
*/
function borg_feed_icon($variables) {
$text = t('Subscribe to !feed-title', array('!feed-title' => $variables['title']));
$image = '<i class="fa fa-rss-square"></i><span class="element-invisible">' . $text . '</span>';
return l($image, $variables['url'], array('html' => TRUE, 'attributes' => array('class' => array('feed-icon'), 'title' => $text)));
}
/**
* Overrides theme_menu_local_tasks().
*/
function borg_menu_local_tasks($variables) {
$arg0 = check_plain(arg(0));
$arg1 = check_plain(arg(1));
$arg2 = check_plain(arg(2));
$output = '';
if (!empty($variables['primary'])) {
// Remove the releases tab.
if ($arg0 == 'node' && is_numeric($arg1) && !$arg2) {
foreach ($variables['primary'] as $key => $link) {
if (strstr($link['#link']['path'], '/releases')) {
unset($variables['primary'][$key]);
}
}
}
if (count($variables['primary']) > 1) {
$variables['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
$variables['primary']['#prefix'] .= '<ul class="tabs primary">';
$variables['primary']['#suffix'] = '</ul>';
$output .= backdrop_render($variables['primary']);
}
}
if (!empty($variables['secondary'])) {
$variables['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
$variables['secondary']['#prefix'] .= '<ul class="tabs secondary">';
$variables['secondary']['#suffix'] = '</ul>';
$output .= backdrop_render($variables['secondary']);
}
return $output;
}
/**
* Theme function
*
* @param $service
* Icon for appropriate service.
* @param $link
* URL where link should point.
* @param $title
* Title attribute for the link tag.
*
* @return
* Linked icon with wrapper markup.
*/
function borg_on_the_web_item($variables) {
$service = $variables['service'];
$link = $variables['link'];
$icon = $variables['icon'];
$size = $variables['size'];
$title = $variables['title'];
$link_classes = $variables['classes'];
$icon_classes = $variables['icon_classes'];
$config = config('on_the_web.settings');
$type = $config->get('type');
$target = $config->get('target');
if ($type == 'anchor') {
// Add a new link class for SVG masks.
$link_classes[] = 'otw-svg-mask';
}
// Determine attributes for the link
$attributes = array(
'class' => $link_classes,
'title' => $title,
'aria-label' => $title,
'rel' => 'nofollow',
);
if ($target == TRUE) {
$attributes['target'] = '_blank';
$attributes['aria-label'] .= ' (' . t('opens in new window') . ')';
}
$text = '';
if ($type == 'font') {
// Add the font awesome icon classes with support for v5.
$icon_classes[] = $icon;
$icon_classes[] = 'fa-fw';
if ((!module_exists('font_awesome') && $config->get('version') == '5.x.x')
|| (module_exists('font_awesome') && config_get('font_awesome.settings', 'fontawesome') == 'v5')) {
if (!in_array('fas', $icon_classes)) {
$icon_classes[] = 'fab';
}
}
else {
$icon_classes[] = 'fa';
}
// Add the font awesome size classes.
if ($size == 'lg') {
$icon_classes[] = 'fa-3x';
}
else {
$icon_classes[] = 'fa-2x';
}
$text = '<i aria-hidden="true" class="' . implode(' ', $icon_classes) . '"></i>';
}
elseif ($type == 'image') {
$text = '<img src="' . $icon . '" />';
}
elseif ($type == 'anchor') {
$style = '';
//$style = 'background: transparent url(' . $icon . ') no-repeat top left;';
//$style .= ' -webkit-mask-image: url(' . $icon . ');';
$style .= ' mask-image: url(' . $icon . ');';
$attributes['style'] = $style;
}
$options = array('attributes' => $attributes, 'html' => TRUE);
return l($text, $link, $options);
}
/**
* Overrides theme_github_info().
*/
function borg_github_info($variables) {
$url = 'https://github.com/' . $variables['github_path'];
$clone_url = $url . '.git';
if ($variables['github_path'] != 'backdrop/backdrop') {
$items = array(
l(t('Project page'), $url),
l(t('Issue Queue'), $url . '/issues'),
l(t('Documentation'), $url . '/wiki'),
);
}
else {
$items = array(
l(t('Project page'), $url),
l(t('Issue Queue'), $url . '-issues/issues'),
l(t('Documentation'), 'user-guide'),
);
}
$list = theme('item_list', array('items' => $items, 'title' => t('GitHub')));
$clone = '<div class="github-clone">';
$clone .= '<label class="github-clone-label">' . t('Clone URL') . '</label>';
$clone .= '<input type="text" readonly="" aria-label="Clone this repository at ' . $clone_url . '" value="' . $clone_url . '">';
$clone .= '</div>';
return $list . $clone;
}
/**
* Overrides theme_system_powered_by().
*/
function borg_system_powered_by() {
$output = '<div class="drop-lounging"></div>';
$output .= '<span>';
$output .= t('Powered by <a href="@poweredby">Backdrop CMS</a>', array('@poweredby' => 'https://backdropcms.org'));
$output .= '</span>';
return $output;
}