MDL-29614 theme_formal_white: Change the way Formal White theme shrinks pages
[moodle.git] / theme / formal_white / lib.php
CommitLineData
57bfc29a
AB
1<?php
2
4afb01db 3defined('MOODLE_INTERNAL') || die();
4
57bfc29a
AB
5/**
6 * Makes our changes to the CSS
7 *
8 * @param string $css
9 * @param theme_config $theme
10 * @return string
11 */
4afb01db 12function formal_white_user_settings($css, $theme) {
13
b396e167 14 // Set the font reference size
15 if (empty($theme->settings->fontsizereference)) {
16 $fontsizereference = '13'; // default
17 } else {
18 $fontsizereference = $theme->settings->fontsizereference;
19 }
20 $css = formal_white_set_fontsizereference($css, $fontsizereference);
21
1bc47427
K
22 // Set the frame margin
23 if (!isset($theme->settings->framemargin)) {
24 $framemargin = 15; // default
25 } else {
26 $framemargin = $theme->settings->framemargin;
27 }
28 $css = formal_white_set_framemargin($css, $framemargin);
29
0e412e87 30 // Set the page header background color
31 if (empty($theme->settings->headerbgc)) {
ec140757 32 $headerbgc = '#E3DFD4'; // default
0e412e87 33 } else {
34 $headerbgc = $theme->settings->headerbgc;
35 }
36 $css = formal_white_set_headerbgc($css, $headerbgc);
37
4afb01db 38 // Set the block content background color
39 if (empty($theme->settings->blockcontentbgc)) {
b396e167 40 $blockcontentbgc = '#F6F6F6'; // default
4afb01db 41 } else {
42 $blockcontentbgc = $theme->settings->blockcontentbgc;
43 }
44 $css = formal_white_set_blockcontentbgc($css, $blockcontentbgc);
57bfc29a 45
b396e167 46 // Set the left block column background color
47 if (empty($theme->settings->lblockcolumnbgc)) {
48 $lblockcolumnbgc = '#E3DFD4'; // default
57bfc29a 49 } else {
b396e167 50 $lblockcolumnbgc = $theme->settings->lblockcolumnbgc;
57bfc29a 51 }
b396e167 52 $css = formal_white_set_lblockcolumnbgc($css, $lblockcolumnbgc);
57bfc29a 53
b396e167 54 // Set the right block column background color
55 if (empty($theme->settings->rblockcolumnbgc)) {
56 $rblockcolumnbgc = $lblockcolumnbgc; // default
57bfc29a 57 } else {
b396e167 58 $rblockcolumnbgc = $theme->settings->rblockcolumnbgc;
57bfc29a 59 }
b396e167 60 $css = formal_white_set_rblockcolumnbgc($css, $rblockcolumnbgc);
57bfc29a 61
b396e167 62 // set the width of the two blocks columns
4afb01db 63 if (!empty($theme->settings->blockcolumnwidth)) {
64 $blockcolumnwidth = $theme->settings->blockcolumnwidth;
57bfc29a 65 } else {
4afb01db 66 $blockcolumnwidth = '200'; // default
57bfc29a 67 }
4afb01db 68 $css = formal_white_set_blockcolumnwidth($css, $blockcolumnwidth);
57bfc29a 69
b396e167 70 // set the customcss
71 if (!empty($theme->settings->customcss)) {
72 $customcss = $theme->settings->customcss;
73 } else {
74 $customcss = null;
75 }
76 $css = formal_white_set_customcss($css, $customcss);
77
57bfc29a
AB
78 return $css;
79}
80
4afb01db 81
82
57bfc29a 83/**
4afb01db 84 * Sets the link color variable in CSS
57bfc29a 85 *
57bfc29a 86 */
b396e167 87function formal_white_set_fontsizereference($css, $fontsizereference) {
88 $tag = '[[setting:fontsizereference]]';
89 $css = str_replace($tag, $fontsizereference.'px', $css);
90 return $css;
91}
92
1bc47427
K
93function formal_white_set_framemargin($css, $framemargin) {
94 $tag = '[[setting:framemargin]]';
95 $css = str_replace($tag, $framemargin.'px', $css);
96
97 // Set .headermenu right
98 $tag = '[[setting:headermenuright]]';
99 $css = str_replace($tag, ($framemargin+17).'px', $css); // 17px is the width of the frame
100
101 return $css;
102}
103
0e412e87 104function formal_white_set_headerbgc($css, $headerbgc) {
105 $tag = '[[setting:headerbgc]]';
106 $css = str_replace($tag, $headerbgc, $css);
107 return $css;
108}
109
4afb01db 110function formal_white_set_blockcontentbgc($css, $blockcontentbgc) {
111 $tag = '[[setting:blockcontentbgc]]';
112 $css = str_replace($tag, $blockcontentbgc, $css);
57bfc29a
AB
113 return $css;
114}
115
b396e167 116function formal_white_set_lblockcolumnbgc($css, $lblockcolumnbgc) {
117 $tag = '[[setting:lblockcolumnbgc]]';
118 $css = str_replace($tag, $lblockcolumnbgc, $css);
57bfc29a
AB
119 return $css;
120}
121
b396e167 122function formal_white_set_rblockcolumnbgc($css, $rblockcolumnbgc) {
123 $tag = '[[setting:rblockcolumnbgc]]';
124 $css = str_replace($tag, $rblockcolumnbgc, $css);
0e412e87 125 return $css;
4afb01db 126}
127
128function formal_white_set_blockcolumnwidth($css, $blockcolumnwidth) {
0e412e87 129 $tag = '[[setting:blockcolumnwidth]]';
130 $css = str_replace($tag, $blockcolumnwidth.'px', $css);
4afb01db 131
0e412e87 132 $tag = '[[setting:minusdoubleblockcolumnwidth]]';
133 $css = str_replace($tag, (-2*$blockcolumnwidth).'px', $css);
4afb01db 134
0e412e87 135 $tag = '[[setting:doubleblockcolumnwidth]]';
136 $css = str_replace($tag, (2*$blockcolumnwidth).'px', $css);
4afb01db 137
1bc47427
K
138 // set the min-width of the page to provide: content region min-width = block region width
139 // I do not care $framemargin because the min-width applies to #frametop that is free from $framemargin
140 // I need to add twice the width of the frame because it is inside #frametop
141 // (this code here because it HAS TO come later than $blockcolumnwidth definition)
142 $tag = '[[setting:minwidth]]';
143 $css = str_replace($tag, (3*$blockcolumnwidth + 34).'px', $css); // 34 = 2*17 (17px is the width of the frame)
144
0e412e87 145 return $css;
b396e167 146}
147
148function formal_white_set_customcss($css, $customcss) {
149 $tag = '[[setting:customcss]]';
150 $css = str_replace($tag, $customcss, $css);
151 return $css;
ec140757 152}