-
Notifications
You must be signed in to change notification settings - Fork 4
/
lib.php
1564 lines (1478 loc) · 82.6 KB
/
lib.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
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Campus theme with the underlying Bootstrap theme.
*
* @package theme
* @subpackage campus
* @copyright © 2014-onwards G J Barnard in respect to modifications of the Clean theme.
* @copyright © 2014-onwards Work undertaken for David Bogner of Edulabs.org.
* @author G J Barnard - {@link http://moodle.org/user/profile.php?id=442195}
* @author Based on code originally written by Mary Evans, Bas Brands, Stuart Lamour and David Scotson.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function theme_campus_process_css($css, $theme) {
// Set custom CSS.
if (!empty($theme->settings->customcss)) {
$customcss = $theme->settings->customcss;
} else {
$customcss = null;
}
$css = theme_campus_set_customcss($css, $customcss);
return $css;
}
function theme_campus_set_customcss($css, $customcss) {
$tag = '[[setting:customcss]]';
$replacement = $customcss;
if (is_null($replacement)) {
$replacement = '';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
/**
* Get SCSS to prepend.
*
* @param theme_config $theme The theme config object.
* @return string SCSS.
*/
function theme_campus_get_pre_scss($theme) {
static $boosttheme = null;
if (empty($boosttheme)) {
$boosttheme = theme_config::load('boost'); // Needs to be the Boost theme so that we get its settings.
}
$scss = theme_boost_get_pre_scss($boosttheme);
$vars = theme_campus_sass_variables($theme);
foreach ($vars as $varkey => $varval) {
$scss .= '$' . $varkey . ':' . $varval . ';' . PHP_EOL;
}
$scss .= \theme_campus\toolbox::get_scss_file('variables-campus');
return $scss;
}
/**
* Returns the main SCSS content.
*
* @param theme_config $theme The theme config object.
* @return string SCSS.
*/
function theme_campus_get_main_scss_content($theme) {
global $CFG;
static $boosttheme = null;
if (empty($boosttheme)) {
$boosttheme = theme_config::load('boost'); // Needs to be the Boost theme so that we get its settings.
}
// This mechanism is not set in stone.
$scss = '';
$boosttheme->settings->preset = 'default.scss';
$scss .= theme_boost_get_main_scss_content($boosttheme);
$scss .= \theme_campus\toolbox::get_scss_file('bootstrapchanges');
$scss .= \theme_campus\toolbox::get_scss_file('moodlechanges');
$scss .= \theme_campus\toolbox::get_scss_file('moodleupgradechanges');
$scss .= \theme_campus\toolbox::get_scss_file('campuscustom');
return $scss;
}
/**
* Inject additional SCSS.
*
* @param theme_config $theme The theme config object.
* @return string SCSS.
*/
function theme_campus_get_extra_scss($theme) {
static $boosttheme = null;
if (empty($boosttheme)) {
$boosttheme = theme_config::load('boost'); // Needs to be the Boost theme so that we get its settings.
}
$scss = theme_boost_get_extra_scss($boosttheme);
$scss .= theme_campus_extra_sccs($theme);
// Custom SCSS. TODO.
if (!empty($theme->settings->customscss)) {
$scss .= $theme->settings->customscss;
}
return $scss;
}
/**
* Get compiled css.
*
* @return string compiled css
*/
function theme_campus_get_precompiled_css() {
global $CFG;
return file_get_contents($CFG->dirroot . '/theme/boost/style/moodle.css');
}
/**
* Extra SCSS code to inject.
*
* This will generate some SCSS code from the settings used by the user.
*
* @param theme_config $theme The theme config object.
* @return string Raw SCSS code.
*/
function theme_campus_extra_sccs($theme) {
global $CFG;
if (file_exists("{$CFG->dirroot}/theme/campus/campus-lib.php")) {
include_once($CFG->dirroot . '/theme/campus/campus-lib.php');
} else if (!empty($CFG->themedir) && file_exists("{$CFG->themedir}/campus/campus-lib.php")) {
include_once($CFG->themedir . '/campus/campus-lib.php');
}
$campuscategorytree = theme_campus_get_top_level_categories();
$content = PHP_EOL;
// Front page.
if ((!empty($theme->settings->frontpagelogo)) && (!empty($theme->settings->frontpagebackgroundimage))) {
if ((!empty($theme->settings->frontpageresponsivelogo)) && (!empty($theme->settings->frontpageresponsivebackgroundimage))) {
if ($dimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivelogo', 'frontpageresponsivelogo')) {
if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivebackgroundimage', 'frontpageresponsivebackgroundimage')) {
$backgroundwidth = $backgrounddimensions['width'];
$backgroundheight = $backgrounddimensions['height'];
} else {
$backgroundwidth = 960; // Fallback, where 960 is the value of @navbarCollapseWidth.
$backgroundheight = $dimensions['height'];
}
$totalwidth = $dimensions['width'] + $backgroundwidth;
$fplogowidth = ($dimensions['width'] / $totalwidth) * 100;
$fpabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$fpflexpaddingbottom = ($dimensions['height'] / $totalwidth) * 100;
$fpbackgroundwidth = 100 - $fplogowidth;
/* .fpresponsiveheaderlogo(@frontpageMixinLogoWidth;
@frontpageAbsoluteMixinPaddingBottom;
@frontpageFlexMixinPaddingBottom;
@frontpageMixinBackgroundWidth) */
$content .= '@include fpresponsiveheaderlogo(' . $fplogowidth . '%, ' . $fpabsolutepaddingbottom . '%, ' .
$fpflexpaddingbottom . '%, ' . $fpbackgroundwidth . '%);' . PHP_EOL;
}
}
} else {
// Theme responsive images fall back.
if (($logoresponsivedetails = theme_campus_get_theme_responsive_logo()) && ($backgroundresponsivedetails = theme_campus_get_theme_responsive_background())) {
if (($logoresponsivedetails['fullname']) && ($dimensions = getimagesize($logoresponsivedetails['fullname']))) {
// Ref: http://php.net/manual/en/function.getimagesize.php - index 0 = width and index 1 = height.
if (($backgroundresponsivedetails['fullname']) && ($backgrounddimensions = getimagesize($backgroundresponsivedetails['fullname']))) {
$backgroundwidth = $backgrounddimensions[0];
$backgroundheight = $backgrounddimensions[1];
} else {
$backgroundwidth = 960; // Fallback, where 960 is the value of @navbarCollapseWidth.
$backgroundheight = $dimensions[1];
}
$totalwidth = $dimensions[0] + $backgroundwidth;
$fplogowidth = ($dimensions[0] / $totalwidth) * 100;
$fpabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$fpflexpaddingbottom = ($dimensions[1] / $totalwidth) * 100;
$fpbackgroundwidth = 100 - $fplogowidth;
/* .fpresponsiveheaderlogo(@frontpageMixinLogoWidth;
@frontpageAbsoluteMixinPaddingBottom;
@frontpageFlexMixinPaddingBottom;
@frontpageMixinBackgroundWidth) */
$content .= '@include fpresponsiveheaderlogo(' . $fplogowidth . '%, ' . $fpabsolutepaddingbottom . '%, ' .
$fpflexpaddingbottom . '%, ' . $fpbackgroundwidth . '%);' . PHP_EOL;
}
}
}
// Course catetgory.
foreach ($campuscategorytree as $key => $value) {
$categorylogoused = false;
$cchavecustomsetting = 'coursecategoryhavecustomheader' . $key;
$ccsetting = 'coursecategorylogo' . $key;
$ccbsetting = 'coursecategorybackgroundimage' . $key;
if ((!empty($theme->settings->$cchavecustomsetting)) && (!empty($theme->settings->$ccsetting)) && (!empty($theme->settings->$ccbsetting))) {
if ($dimensions = theme_campus_get_image_dimensions($theme, $ccsetting, $ccsetting)) {
if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, $ccbsetting, $ccbsetting)) {
$backgroundwidth = $backgrounddimensions['width'];
$backgroundheight = $backgrounddimensions['height'];
} else {
if (!empty($theme->settings->pagewidthmax)) {
$backgroundwidth = $theme->settings->pagewidthmax; // Fallback, default max px of #page unless a percentage.
if ($backgroundwidth == 100) { // Percentage value, cannot use in calculation!
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
} else {
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
$backgroundheight = $dimensions['height'];
}
$totalwidth = $dimensions['width'] + $backgroundwidth;
$cclogowidth = ($dimensions['width'] / $totalwidth) * 100;
$ccabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$ccflexpaddingbottom = ($dimensions['height'] / $totalwidth) * 100;
$ccbackgroundwidth = 100 - $cclogowidth;
/* ccheaderlogo(@courseCategoryKey;
@courseCategoryMixinLogoWidth;
@courseCategoryMixinAbsolutePaddingBottom;
@courseCategoryMixinFlexPaddingBottom;
@courseCategoryMixinBackgroundWidth) */
$content .= '@include ccheaderlogo(' . $key . ', ' . $cclogowidth . '%, ' . $ccabsolutepaddingbottom . '%, ' .
$ccflexpaddingbottom . '%, ' . $ccbackgroundwidth . '%);' . PHP_EOL;
$ccsetting = 'coursecategoryresponsivelogo' . $key;
$ccbsetting = 'coursecategoryresponsivebackgroundimage' . $key;
if ((!empty($theme->settings->$ccsetting)) && (!empty($theme->settings->$ccbsetting))) {
if ($dimensions = theme_campus_get_image_dimensions($theme, $ccsetting, $ccsetting)) {
if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, $ccbsetting, $ccbsetting)) {
$backgroundwidth = $backgrounddimensions['width'];
$backgroundheight = $backgrounddimensions['height'];
} else {
$backgroundwidth = 960; // Fallback, where 960 is the value of @navbarCollapseWidth.
$backgroundheight = $dimensions['height'];
}
$totalwidth = $dimensions['width'] + $backgroundwidth;
$cclogowidth = ($dimensions['width'] / $totalwidth) * 100;
$ccabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$ccflexpaddingbottom = ($dimensions['height'] / $totalwidth) * 100;
$ccbackgroundwidth = 100 - $cclogowidth;
/* .ccresponsiveheaderlogo(@courseCategoryKey;
@courseCategoryMixinLogoWidth;
@courseCategoryMixinAbsolutePaddingBottom;
@courseCategoryMixinFlexPaddingBottom;
@courseCategoryMixinBackgroundWidth) */
$content .= '@include ccresponsiveheaderlogo(' . $key . ', ' . $cclogowidth . '%, ' . $ccabsolutepaddingbottom .
'%, ' . $ccflexpaddingbottom . '%, ' . $ccbackgroundwidth . '%);' . PHP_EOL;
}
}
$categorylogoused = true;
}
} else if ((!empty($theme->settings->frontpagelogo)) && (!empty($theme->settings->frontpagebackgroundimage))) { // Front page fall back.
if ($dimensions = theme_campus_get_image_dimensions($theme, 'frontpagelogo', 'frontpagelogo')) {
// Front page campus desktop images.
if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, 'frontpagebackgroundimage', 'frontpagebackgroundimage')) {
$backgroundwidth = $backgrounddimensions['width'];
$backgroundheight = $backgrounddimensions['height'];
} else {
if (!empty($theme->settings->pagewidthmax)) {
$backgroundwidth = $theme->settings->pagewidthmax; // Fallback, default max px of #page unless a percentage.
if ($backgroundwidth == 100) { // Percentage value, cannot use in calculation!
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
} else {
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
$backgroundheight = $dimensions['height'];
}
$totalwidth = $dimensions['width'] + $backgroundwidth;
$cclogowidth = ($dimensions['width'] / $totalwidth) * 100;
$ccabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$ccflexpaddingbottom = ($dimensions['height'] / $totalwidth) * 100;
$ccbackgroundwidth = 100 - $cclogowidth;
/* ccheaderlogo(@courseCategoryKey;
@courseCategoryMixinLogoWidth;
@courseCategoryMixinAbsolutePaddingBottom;
@courseCategoryMixinFlexPaddingBottom;
@courseCategoryMixinBackgroundWidth) */
$content .= '@include ccheaderlogo(' . $key . ', ' . $cclogowidth . '%, ' . $ccabsolutepaddingbottom . '%, ' .
$ccflexpaddingbottom . '%, ' . $ccbackgroundwidth . '%);' . PHP_EOL;
if ((!empty($theme->settings->frontpageresponsivelogo)) && (!empty($theme->settings->frontpageresponsivebackgroundimage))) {
if ($dimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivelogo', 'frontpageresponsivelogo')) {
if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivebackgroundimage', 'frontpageresponsivebackgroundimage')) {
$backgroundwidth = $backgrounddimensions['width'];
$backgroundheight = $backgrounddimensions['height'];
} else {
$backgroundwidth = 960; // Fallback, where 960 is the value of @navbarCollapseWidth.
$backgroundheight = $dimensions['height'];
}
$totalwidth = $dimensions['width'] + $backgroundwidth;
$cclogowidth = ($dimensions['width'] / $totalwidth) * 100;
$ccabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$ccflexpaddingbottom = ($dimensions['height'] / $totalwidth) * 100;
$ccbackgroundwidth = 100 - $cclogowidth;
/* ccheaderlogo(@courseCategoryKey;
@courseCategoryMixinLogoWidth;
@courseCategoryMixinAbsolutePaddingBottom;
@courseCategoryMixinFlexPaddingBottom;
@courseCategoryMixinBackgroundWidth) */
$content .= '@include ccresponsiveheaderlogo(' . $key . ', ' . $cclogowidth . '%, ' . $ccabsolutepaddingbottom .
'%, ' . $ccflexpaddingbottom . '%, ' . $ccbackgroundwidth . '%);' . PHP_EOL;
}
}
// Using front page, so use those settings.
if (!empty($theme->settings->frontpagelogoposition)) {
/* .ccheaderlogoposition(@courseCategoryKey;
@courseCategoryMixinLogoPosition;
@courseCategoryMixinPageHeadingHeaderPositionLeft;
@courseCategoryMixinPageHeadingHeaderPositionRight) */
switch ($theme->settings->frontpagelogoposition) {
case 1:
$content .= '@include ccheaderlogoposition(' . $key . ', left, auto, 50px);';
break;
case 2:
$content .= '@include ccheaderlogoposition(' . $key . ', right, 50px, auto);';
break;
}
}
}
} else if ($logodetails = theme_campus_get_theme_logo()) { // Theme images fall back.
if (($logodetails['fullname']) && ($dimensions = getimagesize($logodetails['fullname']))) {
// Ref: http://php.net/manual/en/function.getimagesize.php - index 0 = width and index 1 = height.
$backgrounddetails = theme_campus_get_theme_background();
if (($backgrounddetails['fullname']) && ($backgrounddimensions = getimagesize($backgrounddetails['fullname']))) {
$backgroundwidth = $backgrounddimensions[0];
$backgroundheight = $backgrounddimensions[1];
} else {
if (!empty($theme->settings->pagewidthmax)) {
$backgroundwidth = $theme->settings->pagewidthmax; // Fallback, default max px of #page unless a percentage.
if ($backgroundwidth == 100) { // Percentage value, cannot use in calculation!
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
} else {
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
$backgroundheight = $dimensions[1];
}
$totalwidth = $dimensions[0] + $backgroundwidth;
$cclogowidth = ($dimensions[0] / $totalwidth) * 100;
$ccabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$ccflexpaddingbottom = ($dimensions[1] / $totalwidth) * 100;
$ccbackgroundwidth = 100 - $cclogowidth;
/* ccheaderlogo(@courseCategoryKey;
@courseCategoryMixinLogoWidth;
@courseCategoryMixinAbsolutePaddingBottom;
@courseCategoryMixinFlexPaddingBottom;
@courseCategoryMixinBackgroundWidth) */
$content .= '@include ccheaderlogo(' . $key . ', ' . $cclogowidth . '%, ' . $ccabsolutepaddingbottom . '%, ' .
$ccflexpaddingbottom . '%, ' . $ccbackgroundwidth . '%);' . PHP_EOL;
// Theme responsive images fall back.
if (($logoresponsivedetails = theme_campus_get_theme_responsive_logo()) && ($backgroundresponsivedetails = theme_campus_get_theme_responsive_background())) {
if (($logoresponsivedetails['fullname']) && ($dimensions = getimagesize($logoresponsivedetails['fullname']))) {
// Ref: http://php.net/manual/en/function.getimagesize.php - index 0 = width and index 1 = height.
if (($backgroundresponsivedetails['fullname']) && ($backgrounddimensions = getimagesize($backgroundresponsivedetails['fullname']))) {
$backgroundwidth = $backgrounddimensions[0];
$backgroundheight = $backgrounddimensions[1];
} else {
$backgroundwidth = 960; // Fallback, where 960 is the value of @navbarCollapseWidth.
$backgroundheight = $dimensions[1];
}
$totalwidth = $dimensions[0] + $backgroundwidth;
$cclogowidth = ($dimensions[0] / $totalwidth) * 100;
$ccabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$ccflexpaddingbottom = ($dimensions[1] / $totalwidth) * 100;
$ccbackgroundwidth = 100 - $cclogowidth;
/* ccheaderlogo(@courseCategoryKey;
@courseCategoryMixinLogoWidth;
@courseCategoryMixinAbsolutePaddingBottom;
@courseCategoryMixinFlexPaddingBottom;
@courseCategoryMixinBackgroundWidth) */
$content .= '@include ccresponsiveheaderlogo(' . $key . ', ' . $cclogowidth . '%, ' . $ccabsolutepaddingbottom .
'%, ' . $ccflexpaddingbottom . '%, ' . $ccbackgroundwidth . '%);' . PHP_EOL;
}
}
$content .= '@include ccheaderlogoposition(' . $key . ', left, auto, 50px);' . PHP_EOL; // Theme layout uses logo on left.
}
}
if ($categorylogoused == true) {
$ccsetting = 'coursecategorybgcolour' . $key;
if (!empty($theme->settings->$ccsetting)) {
/* .ccheaderbackgroundcolour(@courseCategoryKey;
@courseCategoryMixinBackgroundColour) */
$content .= '@include ccheaderbackgroundcolour(' . $key . ', ' . $theme->settings->$ccsetting . ');' . PHP_EOL;
}
$ccsetting = 'coursecategorylogoposition' . $key;
if (!empty($theme->settings->$ccsetting)) {
/* .ccheaderlogoposition(@courseCategoryKey;
@courseCategoryMixinLogoPosition;
@courseCategoryMixinPageHeadingHeaderPositionLeft;
@courseCategoryMixinPageHeadingHeaderPositionRight) */
switch ($theme->settings->$ccsetting) {
case 1:
$content .= '@include ccheaderlogoposition(' . $key . ', left, auto, 50px);' . PHP_EOL;
break;
case 2:
$content .= '@include ccheaderlogoposition(' . $key . ', right, 50px, auto);' . PHP_EOL;
break;
}
}
}
}
return $content;
}
/**
* Returns variables for SASS.
*
* We will inject some SASS variables from the settings that the user has defined
* for the theme.
*
* @param theme_config $theme The theme config object.
* @return array of SASS variables without the $.
*/
function theme_campus_sass_variables($theme) {
$variables = [];
if (!empty($theme->settings->pagewidthmax)) {
if ($theme->settings->pagewidthmax == 100) { // Percentage value.
$variables['pageWidthMaximum'] = $theme->settings->pagewidthmax . '%';
} else {
$variables['pageWidthMaximum'] = $theme->settings->pagewidthmax . 'px';
}
}
if (!empty($theme->settings->headingfont)) {
$variables['headingsFontName'] = '"' . $theme->settings->headingfont . '"';
}
if (!empty($theme->settings->bodyfont)) {
$variables['baseFontName'] = '"' . $theme->settings->bodyfont . '"';
}
if (!empty($theme->settings->textcolour)) {
$variables['body-color'] = $theme->settings->textcolour;
}
if (!empty($theme->settings->linkcolour)) {
$variables['link-color'] = $theme->settings->linkcolour;
}
if (!empty($theme->settings->contentcolour)) {
$variables['contentColor'] = $theme->settings->contentcolour;
}
if (!empty($theme->settings->iconcolour)) {
$variables['blockIconColour'] = $theme->settings->iconcolour;
}
if (!empty($theme->settings->headingcolour)) {
$variables['headings-color'] = $theme->settings->headingcolour;
}
if (!empty($theme->settings->navbartextcolour)) {
$variables['navbarText'] = $theme->settings->navbartextcolour;
$variables['navbarBrandColor'] = $theme->settings->navbartextcolour;
}
if (!empty($theme->settings->navbarlinkcolour)) {
$variables['navbarLinkColor'] = $theme->settings->navbarlinkcolour;
}
if (!empty($theme->settings->navbariconcolour)) {
$variables['navbarIconColour'] = $theme->settings->navbariconcolour;
}
if (!empty($theme->settings->navbarbackgroundcolour)) {
$variables['navbarBackground'] = $theme->settings->navbarbackgroundcolour;
$variables['navbarBackgroundHighlight'] = $theme->settings->navbarbackgroundcolour;
}
if (!empty($theme->settings->blockheadingcolour)) {
$variables['blockHeadingColor'] = $theme->settings->blockheadingcolour;
}
if (!empty($theme->settings->blockheadingbackgroundcolour)) {
$variables['blockHeadingBackgroundColour'] = $theme->settings->blockheadingbackgroundcolour;
}
if (!empty($theme->settings->blockbackgroundcolour)) {
$variables['blockBackgroundColour'] = $theme->settings->blockbackgroundcolour;
}
if (!empty($theme->settings->blockborderoptions)) {
$blockborderthickness = (!empty($theme->settings->blockborderthickness)) ? $theme->settings->blockborderthickness : '1px';
switch ($theme->settings->blockborderoptions) {
case 1: // No border.
$variables['blockHeadingBorderTopWidth'] = '0';
$variables['blockHeadingBorderRightWidth'] = '0';
$variables['blockHeadingBorderBottomWidth'] = '0';
$variables['blockHeadingBorderLeftWidth'] = '0';
$variables['blockContentBorderTopWidth'] = '0';
$variables['blockContentBorderRightWidth'] = '0';
$variables['blockContentBorderBottomWidth'] = '0';
$variables['blockContentBorderLeftWidth'] = '0';
break;
case 2: // Border around the whole block.
$variables['blockHeadingBorderTopWidth'] = $blockborderthickness;
$variables['blockHeadingBorderRightWidth'] = $blockborderthickness;
$variables['blockHeadingBorderBottomWidth'] = '0';
$variables['blockHeadingBorderLeftWidth'] = $blockborderthickness;
$variables['blockContentBorderTopWidth'] = '0';
$variables['blockContentBorderRightWidth'] = $blockborderthickness;
$variables['blockContentBorderBottomWidth'] = $blockborderthickness;
$variables['blockContentBorderLeftWidth'] = $blockborderthickness;
break;
case 3: // Border on header only.
$variables['blockHeadingBorderTopWidth'] = $blockborderthickness;
$variables['blockHeadingBorderRightWidth'] = $blockborderthickness;
$variables['blockHeadingBorderBottomWidth'] = $blockborderthickness;
$variables['blockHeadingBorderLeftWidth'] = $blockborderthickness;
$variables['blockContentBorderTopWidth'] = '0';
$variables['blockContentBorderRightWidth'] = '0';
$variables['blockContentBorderBottomWidth'] = '0';
$variables['blockContentBorderLeftWidth'] = '0';
break;
case 4: // Border on content only.
$variables['blockHeadingBorderTopWidth'] = '0';
$variables['blockHeadingBorderRightWidth'] = '0';
$variables['blockHeadingBorderBottomWidth'] = '0';
$variables['blockHeadingBorderLeftWidth'] = '0';
$variables['blockContentBorderTopWidth'] = $blockborderthickness;
$variables['blockContentBorderRightWidth'] = $blockborderthickness;
$variables['blockContentBorderBottomWidth'] = $blockborderthickness;
$variables['blockContentBorderLeftWidth'] = $blockborderthickness;
break;
case 5: // Three horizontal lines: above header, between header/content and bottom.
$variables['blockHeadingBorderTopWidth'] = $blockborderthickness;
$variables['blockHeadingBorderRightWidth'] = '0';
$variables['blockHeadingBorderBottomWidth'] = '0';
$variables['blockHeadingBorderLeftWidth'] = '0';
$variables['blockContentBorderTopWidth'] = $blockborderthickness;
$variables['blockContentBorderRightWidth'] = '0';
$variables['blockContentBorderBottomWidth'] = $blockborderthickness;
$variables['blockContentBorderLeftWidth'] = '0';
break;
}
}
if (!empty($theme->settings->blockbordercolour)) {
$variables['blockBorderColour'] = $theme->settings->blockbordercolour;
}
if (!empty($theme->settings->blockborderstyle)) {
$variables['blockBorderStyle'] = $theme->settings->blockborderstyle;
}
if (!empty($theme->settings->themecolour)) {
$variables['bodyBackgroundAlt'] = $theme->settings->themecolour;
$variables['carouselColour'] = $theme->settings->themecolour;
$variables['carouselActiveColour'] = $theme->settings->themecolour;
}
if (!empty($theme->settings->themebackgroundcolour)) {
$variables['themeBackground'] = $theme->settings->themebackgroundcolour;
}
if (!empty($theme->settings->borderradiussmall)) {
$variables['borderRadiusSmall'] = $theme->settings->borderradiussmall;
}
if (!empty($theme->settings->borderradiusmedium)) {
$variables['border-radius'] = $theme->settings->borderradiusmedium;
}
if (!empty($theme->settings->borderradiuslarge)) {
$variables['border-radius-lg'] = $theme->settings->borderradiuslarge;
}
/*if (!empty($theme->settings->wellbackgroundcolour)) {
$variables['wellBackground'] = $theme->settings->wellbackgroundcolour;
}*/
/*if (!empty($theme->settings->alertinfotextcolour)) {
$variables['infoText'] = $theme->settings->alertinfotextcolour;
}
if (!empty($theme->settings->alertinfobackgroundcolour)) {
$variables['infoBackground'] = $theme->settings->alertinfobackgroundcolour;
}*/
if (!empty($theme->settings->navbarpageheadingmax)) {
$variables['navbarPageHeadingMax'] = $theme->settings->navbarpageheadingmax . 'px';
}
if (!empty($theme->settings->frontpagelogoposition)) {
switch ($theme->settings->frontpagelogoposition) {
case 1:
$variables['frontpagePageHeadingHeaderPositionRight'] = '50px';
break;
case 2:
$variables['frontpagePageHeadingHeaderPositionLeft'] = '50px';
break;
}
if ((!empty($theme->settings->frontpagelayout)) && ($theme->settings->frontpagelayout == 'absolutelayout')) {
switch ($theme->settings->frontpagelogoposition) {
case 1:
$variables['frontpageLogoPosition'] = 'left';
break;
case 2:
$variables['frontpageLogoPosition'] = 'right';
break;
}
}
}
if ((!empty($theme->settings->frontpagelogo)) && (!empty($theme->settings->frontpagebackgroundimage))) {
if ($dimensions = theme_campus_get_image_dimensions($theme, 'frontpagelogo', 'frontpagelogo')) {
if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, 'frontpagebackgroundimage', 'frontpagebackgroundimage')) {
$backgroundwidth = $backgrounddimensions['width'];
$backgroundheight = $backgrounddimensions['height'];
} else {
if (!empty($theme->settings->pagewidthmax)) {
$backgroundwidth = $theme->settings->pagewidthmax; // Fallback, default max px of #page unless a percentage.
if ($backgroundwidth == 100) { // Percentage value, cannot use in calculation!
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
} else {
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
$backgroundheight = $dimensions['height'];
}
$totalwidth = $dimensions['width'] + $backgroundwidth;
$fplogowidth = ($dimensions['width'] / $totalwidth) * 100;
$fpabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$fpflexpaddingbottom = ($dimensions['height'] / $totalwidth) * 100;
$fpbackgroundwidth = 100 - $fplogowidth;
$variables['frontpageLogoWidth'] = $fplogowidth . '%';
$variables['frontpageBackgroundWidth'] = $fpbackgroundwidth . '%';
// This negates the setting of the height as there is a logo. Without a logo there is no height to the header and things look bad.
$variables['frontpageHeaderHeightDefault'] = 'auto';
$variables['frontpageAbsolutePaddingBottom'] = $fpabsolutepaddingbottom . '%';
$variables['frontpageFlexPaddingBottom'] = $fpflexpaddingbottom . '%';
}
} else if ($logodetails = theme_campus_get_theme_logo()) { // Fallback to theme logo.
// http://php.net/manual/en/function.getimagesize.php - index 0 = width and index 1 = height.
if (($logodetails['fullname']) && ($dimensions = getimagesize($logodetails['fullname']))) {
$backgrounddetails = theme_campus_get_theme_background();
if (($backgrounddetails['fullname']) && ($backgrounddimensions = getimagesize($backgrounddetails['fullname']))) {
$backgroundwidth = $backgrounddimensions[0];
$backgroundheight = $backgrounddimensions[1];
} else {
if (!empty($theme->settings->pagewidthmax)) {
$backgroundwidth = $theme->settings->pagewidthmax; // Fallback, default max px of #page unless a percentage.
if ($backgroundwidth == 100) { // Percentage value, cannot use in calculation!
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
} else {
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
$backgroundheight = $dimensions[1];
}
$totalwidth = $dimensions[0] + $backgroundwidth;
$fplogowidth = ($dimensions[0] / $totalwidth) * 100;
$fpabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$fpflexpaddingbottom = ($dimensions[1] / $totalwidth) * 100;
$fpbackgroundwidth = 100 - $fplogowidth;
$variables['frontpageLogoWidth'] = $fplogowidth . '%';
$variables['frontpageBackgroundWidth'] = $fpbackgroundwidth . '%';
// This negates the setting of the height as there is a logo. Without a logo there is no height to the header and things look bad.
$variables['frontpageHeaderHeightDefault'] = 'auto';
$variables['frontpageAbsolutePaddingBottom'] = $fpabsolutepaddingbottom . '%';
$variables['frontpageFlexPaddingBottom'] = $fpflexpaddingbottom . '%';
}
}
if (!empty($theme->settings->carouseltextcolour)) {
$variables['carouselTextColour'] = $theme->settings->carouseltextcolour;
}
if (!empty($theme->settings->slidebuttoncolour)) {
$variables['slideButtonColour'] = $theme->settings->slidebuttoncolour;
}
if (!empty($theme->settings->slidebuttonhovercolour)) {
$variables['slideButtonHoverColour'] = $theme->settings->slidebuttonhovercolour;
}
// Setting 'showsettingsincourse' from Boost Campus.
if (!empty($theme->settings->slidebuttonhovercolour)) {
$variables['showSettingsIncourse'] = $theme->settings->showsettingsincourse;
}
// Setting 'incoursesettingsswitchtoroleposition' from Boost Campus.
if (!empty($theme->settings->incoursesettingsswitchtoroleposition)) {
$variables['incourseSettingsSwitchToRolePosition'] = $theme->settings->incoursesettingsswitchtoroleposition;
}
return $variables;
}
/**
* Returns variables for LESS.
*
* We will inject some LESS variables from the settings that the user has defined
* for the theme. No need to write some custom LESS for this.
*
* Ref: https://docs.moodle.org/dev/Themes_overview#Compiling_LESS_on_the_fly
*
* @param theme_config $theme The theme config object.
* @return array of LESS variables without the @.
*/
function theme_campus_less_variables($theme) {
$variables = [];
if (!empty($theme->settings->pagewidthmax)) {
if ($theme->settings->pagewidthmax == 100) { // Percentage value.
$variables['pageWidthMaximum'] = $theme->settings->pagewidthmax . '%';
} else {
$variables['pageWidthMaximum'] = $theme->settings->pagewidthmax . 'px';
}
}
if (!empty($theme->settings->headingfont)) {
$variables['headingsFontName'] = $theme->settings->headingfont;
}
if (!empty($theme->settings->bodyfont)) {
$variables['baseFontName'] = $theme->settings->bodyfont;
}
if (!empty($theme->settings->textcolour)) {
$variables['textColor'] = $theme->settings->textcolour;
}
if (!empty($theme->settings->linkcolour)) {
$variables['linkColor'] = $theme->settings->linkcolour;
}
if (!empty($theme->settings->contentcolour)) {
$variables['contentColor'] = $theme->settings->contentcolour;
}
if (!empty($theme->settings->iconcolour)) {
$variables['blockIconColour'] = $theme->settings->iconcolour;
}
if (!empty($theme->settings->headingcolour)) {
$variables['headingsColor'] = $theme->settings->headingcolour;
}
if (!empty($theme->settings->navbartextcolour)) {
$variables['navbarText'] = $theme->settings->navbartextcolour;
$variables['navbarBrandColor'] = $theme->settings->navbartextcolour;
$variables['navbarLinkColor'] = $theme->settings->navbartextcolour;
}
if (!empty($theme->settings->navbarlinkcolour)) {
$variables['dropdownLinkColorHover'] = $theme->settings->navbarlinkcolour;
$variables['navbarLinkColor'] = $theme->settings->navbarlinkcolour;
}
if (!empty($theme->settings->navbariconcolour)) {
$variables['navbarIconColour'] = $theme->settings->navbariconcolour;
}
if (!empty($theme->settings->navbarbackgroundcolour)) {
$variables['dropdownLinkBackgroundHover'] = $theme->settings->navbarbackgroundcolour;
$variables['navbarBackground'] = $theme->settings->navbarbackgroundcolour;
$variables['navbarBackgroundHighlight'] = $theme->settings->navbarbackgroundcolour;
}
if (!empty($theme->settings->blockheadingcolour)) {
$variables['blockHeadingColor'] = $theme->settings->blockheadingcolour;
}
if (!empty($theme->settings->blockheadingbackgroundcolour)) {
$variables['blockHeadingBackgroundColour'] = $theme->settings->blockheadingbackgroundcolour;
}
if (!empty($theme->settings->blockbackgroundcolour)) {
$variables['blockBackgroundColour'] = $theme->settings->blockbackgroundcolour;
}
if (!empty($theme->settings->blockborderoptions)) {
$blockborderthickness = (!empty($theme->settings->blockborderthickness)) ? $theme->settings->blockborderthickness : '1px';
switch ($theme->settings->blockborderoptions) {
case 1: // No border.
$variables['blockHeadingBorderTopWidth'] = '0';
$variables['blockHeadingBorderRightWidth'] = '0';
$variables['blockHeadingBorderBottomWidth'] = '0';
$variables['blockHeadingBorderLeftWidth'] = '0';
$variables['blockContentBorderTopWidth'] = '0';
$variables['blockContentBorderRightWidth'] = '0';
$variables['blockContentBorderBottomWidth'] = '0';
$variables['blockContentBorderLeftWidth'] = '0';
break;
case 2: // Border around the whole block.
$variables['blockHeadingBorderTopWidth'] = $blockborderthickness;
$variables['blockHeadingBorderRightWidth'] = $blockborderthickness;
$variables['blockHeadingBorderBottomWidth'] = '0';
$variables['blockHeadingBorderLeftWidth'] = $blockborderthickness;
$variables['blockContentBorderTopWidth'] = '0';
$variables['blockContentBorderRightWidth'] = $blockborderthickness;
$variables['blockContentBorderBottomWidth'] = $blockborderthickness;
$variables['blockContentBorderLeftWidth'] = $blockborderthickness;
break;
case 3: // Border on header only.
$variables['blockHeadingBorderTopWidth'] = $blockborderthickness;
$variables['blockHeadingBorderRightWidth'] = $blockborderthickness;
$variables['blockHeadingBorderBottomWidth'] = $blockborderthickness;
$variables['blockHeadingBorderLeftWidth'] = $blockborderthickness;
$variables['blockContentBorderTopWidth'] = '0';
$variables['blockContentBorderRightWidth'] = '0';
$variables['blockContentBorderBottomWidth'] = '0';
$variables['blockContentBorderLeftWidth'] = '0';
break;
case 4: // Border on content only.
$variables['blockHeadingBorderTopWidth'] = '0';
$variables['blockHeadingBorderRightWidth'] = '0';
$variables['blockHeadingBorderBottomWidth'] = '0';
$variables['blockHeadingBorderLeftWidth'] = '0';
$variables['blockContentBorderTopWidth'] = $blockborderthickness;
$variables['blockContentBorderRightWidth'] = $blockborderthickness;
$variables['blockContentBorderBottomWidth'] = $blockborderthickness;
$variables['blockContentBorderLeftWidth'] = $blockborderthickness;
break;
case 5: // Three horizontal lines: above header, between header/content and bottom.
$variables['blockHeadingBorderTopWidth'] = $blockborderthickness;
$variables['blockHeadingBorderRightWidth'] = '0';
$variables['blockHeadingBorderBottomWidth'] = '0';
$variables['blockHeadingBorderLeftWidth'] = '0';
$variables['blockContentBorderTopWidth'] = $blockborderthickness;
$variables['blockContentBorderRightWidth'] = '0';
$variables['blockContentBorderBottomWidth'] = $blockborderthickness;
$variables['blockContentBorderLeftWidth'] = '0';
break;
}
}
if (!empty($theme->settings->blockbordercolour)) {
$variables['blockBorderColour'] = $theme->settings->blockbordercolour;
}
if (!empty($theme->settings->blockborderstyle)) {
$variables['blockBorderStyle'] = $theme->settings->blockborderstyle;
}
if (!empty($theme->settings->themecolour)) {
$variables['bodyBackgroundAlt'] = $theme->settings->themecolour;
$variables['carouselColour'] = $theme->settings->themecolour;
$variables['carouselActiveColour'] = $theme->settings->themecolour;
}
if (!empty($theme->settings->themebackgroundcolour)) {
$variables['themeBackground'] = $theme->settings->themebackgroundcolour;
}
if (!empty($theme->settings->borderradiussmall)) {
$variables['borderRadiusSmall'] = $theme->settings->borderradiussmall;
}
if (!empty($theme->settings->borderradiusmedium)) {
$variables['baseBorderRadius'] = $theme->settings->borderradiusmedium;
}
if (!empty($theme->settings->borderradiuslarge)) {
$variables['borderRadiusLarge'] = $theme->settings->borderradiuslarge;
}
if (!empty($theme->settings->wellbackgroundcolour)) {
$variables['wellBackground'] = $theme->settings->wellbackgroundcolour;
}
if (!empty($theme->settings->alertinfotextcolour)) {
$variables['infoText'] = $theme->settings->alertinfotextcolour;
}
if (!empty($theme->settings->alertinfobackgroundcolour)) {
$variables['infoBackground'] = $theme->settings->alertinfobackgroundcolour;
}
if (!empty($theme->settings->navbarpageheadingmax)) {
$variables['navbarPageHeadingMax'] = $theme->settings->navbarpageheadingmax . 'px';
}
if (!empty($theme->settings->frontpagelogoposition)) {
switch ($theme->settings->frontpagelogoposition) {
case 1:
$variables['frontpagePageHeadingHeaderPositionRight'] = '50px';
break;
case 2:
$variables['frontpagePageHeadingHeaderPositionLeft'] = '50px';
break;
}
if ((!empty($theme->settings->frontpagelayout)) && ($theme->settings->frontpagelayout == 'absolutelayout')) {
switch ($theme->settings->frontpagelogoposition) {
case 1:
$variables['frontpageLogoPosition'] = 'left';
break;
case 2:
$variables['frontpageLogoPosition'] = 'right';
break;
}
}
}
if ((!empty($theme->settings->frontpagelogo)) && (!empty($theme->settings->frontpagebackgroundimage))) {
if ($dimensions = theme_campus_get_image_dimensions($theme, 'frontpagelogo', 'frontpagelogo')) {
if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, 'frontpagebackgroundimage', 'frontpagebackgroundimage')) {
$backgroundwidth = $backgrounddimensions['width'];
$backgroundheight = $backgrounddimensions['height'];
} else {
if (!empty($theme->settings->pagewidthmax)) {
$backgroundwidth = $theme->settings->pagewidthmax; // Fallback, default max px of #page unless a percentage.
if ($backgroundwidth == 100) { // Percentage value, cannot use in calculation!
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
} else {
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
$backgroundheight = $dimensions['height'];
}
$totalwidth = $dimensions['width'] + $backgroundwidth;
$fplogowidth = ($dimensions['width'] / $totalwidth) * 100;
$fpabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$fpflexpaddingbottom = ($dimensions['height'] / $totalwidth) * 100;
$fpbackgroundwidth = 100 - $fplogowidth;
$variables['frontpageLogoWidth'] = $fplogowidth . '%';
$variables['frontpageBackgroundWidth'] = $fpbackgroundwidth . '%';
// This negates the setting of the height as there is a logo. Without a logo there is no height to the header and things look bad.
$variables['frontpageHeaderHeightDefault'] = 'auto';
$variables['frontpageAbsolutePaddingBottom'] = $fpabsolutepaddingbottom . '%';
$variables['frontpageFlexPaddingBottom'] = $fpflexpaddingbottom . '%';
}
} else if ($logodetails = theme_campus_get_theme_logo()) { // Fallback to theme logo.
// http://php.net/manual/en/function.getimagesize.php - index 0 = width and index 1 = height.
if (($logodetails['fullname']) && ($dimensions = getimagesize($logodetails['fullname']))) {
$backgrounddetails = theme_campus_get_theme_background();
if (($backgrounddetails['fullname']) && ($backgrounddimensions = getimagesize($backgrounddetails['fullname']))) {
$backgroundwidth = $backgrounddimensions[0];
$backgroundheight = $backgrounddimensions[1];
} else {
if (!empty($theme->settings->pagewidthmax)) {
$backgroundwidth = $theme->settings->pagewidthmax; // Fallback, default max px of #page unless a percentage.
if ($backgroundwidth == 100) { // Percentage value, cannot use in calculation!
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
} else {
$backgroundwidth = 1680; // Fallback, where 1680 is the default max px of #page.
}
$backgroundheight = $dimensions[1];
}
$totalwidth = $dimensions[0] + $backgroundwidth;
$fplogowidth = ($dimensions[0] / $totalwidth) * 100;
$fpabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$fpflexpaddingbottom = ($dimensions[1] / $totalwidth) * 100;
$fpbackgroundwidth = 100 - $fplogowidth;
$variables['frontpageLogoWidth'] = $fplogowidth . '%';
$variables['frontpageBackgroundWidth'] = $fpbackgroundwidth . '%';
// This negates the setting of the height as there is a logo. Without a logo there is no height to the header and things look bad.
$variables['frontpageHeaderHeightDefault'] = 'auto';
$variables['frontpageAbsolutePaddingBottom'] = $fpabsolutepaddingbottom . '%';
$variables['frontpageFlexPaddingBottom'] = $fpflexpaddingbottom . '%';
}
}
if (!empty($theme->settings->carouseltextcolour)) {
$variables['carouselTextColour'] = $theme->settings->carouseltextcolour;
}
if (!empty($theme->settings->slidebuttoncolour)) {
$variables['slideButtonColour'] = $theme->settings->slidebuttoncolour;
}
if (!empty($theme->settings->slidebuttonhovercolour)) {
$variables['slideButtonHoverColour'] = $theme->settings->slidebuttonhovercolour;
}
return $variables;
}
/**
* Extra LESS code to inject.
*
* This will generate some LESS code from the settings used by the user. We cannot use
* the {@link theme_more_less_variables()} here because we need to create selectors or
* alter existing ones.
*
* @param theme_config $theme The theme config object.
* @return string Raw LESS code.
*/
function theme_campus_extra_less($theme) {
global $CFG, $OUTPUT;
if (file_exists("{$CFG->dirroot}/theme/campus/campus-lib.php")) {
include_once($CFG->dirroot . '/theme/campus/campus-lib.php');
} else if (!empty($CFG->themedir) && file_exists("{$CFG->themedir}/campus/campus-lib.php")) {
include_once($CFG->themedir . '/campus/campus-lib.php');
}
$campuscategorytree = theme_campus_get_top_level_categories();
$content = '@import "' . $CFG->dirroot . '/theme/bootstrapbase/less/moodle";';
$content .= '@import "variables-campus";';
$content .= '@import "bootstrapchanges";';
$content .= '@import "moodlechanges";';
$content .= '@import "campuschanges";';
$content .= '@import "campuscustom";';
// Front page.
if ((!empty($theme->settings->frontpagelogo)) && (!empty($theme->settings->frontpagebackgroundimage))) {
if ((!empty($theme->settings->frontpageresponsivelogo)) && (!empty($theme->settings->frontpageresponsivebackgroundimage))) {
if ($dimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivelogo', 'frontpageresponsivelogo')) {
if ($backgrounddimensions = theme_campus_get_image_dimensions($theme, 'frontpageresponsivebackgroundimage', 'frontpageresponsivebackgroundimage')) {
$backgroundwidth = $backgrounddimensions['width'];
$backgroundheight = $backgrounddimensions['height'];
} else {
$backgroundwidth = 960; // Fallback, where 960 is the value of @navbarCollapseWidth.
$backgroundheight = $dimensions['height'];
}
$totalwidth = $dimensions['width'] + $backgroundwidth;
$fplogowidth = ($dimensions['width'] / $totalwidth) * 100;
$fpabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$fpflexpaddingbottom = ($dimensions['height'] / $totalwidth) * 100;
$fpbackgroundwidth = 100 - $fplogowidth;
/* .fpresponsiveheaderlogo(@frontpageMixinLogoWidth;
@frontpageAbsoluteMixinPaddingBottom;
@frontpageFlexMixinPaddingBottom;
@frontpageMixinBackgroundWidth) */
$content .= '.fpresponsiveheaderlogo(' . $fplogowidth . '%; ' . $fpabsolutepaddingbottom . '%; ' . $fpflexpaddingbottom . '%; ' . $fpbackgroundwidth . '%);';
}
}
} else {
// Theme responsive images fall back.
if (($logoresponsivedetails = theme_campus_get_theme_responsive_logo()) && ($backgroundresponsivedetails = theme_campus_get_theme_responsive_background())) {
if (($logoresponsivedetails['fullname']) && ($dimensions = getimagesize($logoresponsivedetails['fullname']))) {
// Ref: http://php.net/manual/en/function.getimagesize.php - index 0 = width and index 1 = height.
if (($backgroundresponsivedetails['fullname']) && ($backgrounddimensions = getimagesize($backgroundresponsivedetails['fullname']))) {
$backgroundwidth = $backgrounddimensions[0];
$backgroundheight = $backgrounddimensions[1];
} else {
$backgroundwidth = 960; // Fallback, where 960 is the value of @navbarCollapseWidth.
$backgroundheight = $dimensions[1];
}
$totalwidth = $dimensions[0] + $backgroundwidth;
$fplogowidth = ($dimensions[0] / $totalwidth) * 100;
$fpabsolutepaddingbottom = ($backgroundheight / $backgroundwidth) * 100;
$fpflexpaddingbottom = ($dimensions[1] / $totalwidth) * 100;
$fpbackgroundwidth = 100 - $fplogowidth;