Merge branch 'MDL-29857-3' of git://github.com/danpoltawski/moodle
[moodle.git] / theme / formal_white / lib.php
blob27d10ba661f9b1cea55f1e937fa07d01e4521d3f
1 <?php
3 defined('MOODLE_INTERNAL') || die();
5 /**
6 * Makes our changes to the CSS
8 * @param string $css
9 * @param theme_config $theme
10 * @return string
12 function formal_white_user_settings($css, $theme) {
14 // Set the font reference size
15 if (empty($theme->settings->fontsizereference)) {
16 $fontsizereference = '13'; // default
17 } else {
18 $fontsizereference = $theme->settings->fontsizereference;
20 $css = formal_white_set_fontsizereference($css, $fontsizereference);
22 // Set the frame margin
23 if (!isset($theme->settings->framemargin)) {
24 $framemargin = 15; // default
25 } else {
26 $framemargin = $theme->settings->framemargin;
28 $css = formal_white_set_framemargin($css, $framemargin);
30 // Set the page header background color
31 if (empty($theme->settings->headerbgc)) {
32 $headerbgc = '#E3DFD4'; // default
33 } else {
34 $headerbgc = $theme->settings->headerbgc;
36 $css = formal_white_set_headerbgc($css, $headerbgc);
38 // Set the block content background color
39 if (empty($theme->settings->blockcontentbgc)) {
40 $blockcontentbgc = '#F6F6F6'; // default
41 } else {
42 $blockcontentbgc = $theme->settings->blockcontentbgc;
44 $css = formal_white_set_blockcontentbgc($css, $blockcontentbgc);
46 // Set the left block column background color
47 if (empty($theme->settings->lblockcolumnbgc)) {
48 $lblockcolumnbgc = '#E3DFD4'; // default
49 } else {
50 $lblockcolumnbgc = $theme->settings->lblockcolumnbgc;
52 $css = formal_white_set_lblockcolumnbgc($css, $lblockcolumnbgc);
54 // Set the right block column background color
55 if (empty($theme->settings->rblockcolumnbgc)) {
56 $rblockcolumnbgc = $lblockcolumnbgc; // default
57 } else {
58 $rblockcolumnbgc = $theme->settings->rblockcolumnbgc;
60 $css = formal_white_set_rblockcolumnbgc($css, $rblockcolumnbgc);
62 // set the width of the two blocks columns
63 if (!empty($theme->settings->blockcolumnwidth)) {
64 $blockcolumnwidth = $theme->settings->blockcolumnwidth;
65 } else {
66 $blockcolumnwidth = '200'; // default
68 $css = formal_white_set_blockcolumnwidth($css, $blockcolumnwidth);
70 // set blocks margin
71 if (!empty($theme->settings->blockpadding)) {
72 $blockpadding = $theme->settings->blockpadding;
73 } else {
74 $blockpadding = '8'; // default
76 $css = formal_white_set_blockpadding($css, $blockcolumnwidth, $blockpadding);
78 // set the customcss
79 if (!empty($theme->settings->customcss)) {
80 $customcss = $theme->settings->customcss;
81 } else {
82 $customcss = null;
84 $css = formal_white_set_customcss($css, $customcss);
86 return $css;
91 /**
92 * Sets the link color variable in CSS
95 function formal_white_set_fontsizereference($css, $fontsizereference) {
96 $tag = '[[setting:fontsizereference]]';
97 $css = str_replace($tag, $fontsizereference.'px', $css);
98 return $css;
101 function formal_white_set_framemargin($css, $framemargin) {
102 $tag = '[[setting:framemargin]]';
103 $css = str_replace($tag, $framemargin.'px', $css);
105 // Set .headermenu right
106 $calculated = $framemargin + 17; // 17px is the width of the frame
107 $tag = '[[calculated:headermenuright]]';
108 $css = str_replace($tag, $calculated.'px', $css);
110 return $css;
113 function formal_white_set_headerbgc($css, $headerbgc) {
114 $tag = '[[setting:headerbgc]]';
115 $css = str_replace($tag, $headerbgc, $css);
116 return $css;
119 function formal_white_set_blockcontentbgc($css, $blockcontentbgc) {
120 $tag = '[[setting:blockcontentbgc]]';
121 $css = str_replace($tag, $blockcontentbgc, $css);
122 return $css;
125 function formal_white_set_lblockcolumnbgc($css, $lblockcolumnbgc) {
126 $tag = '[[setting:lblockcolumnbgc]]';
127 $css = str_replace($tag, $lblockcolumnbgc, $css);
128 return $css;
131 function formal_white_set_rblockcolumnbgc($css, $rblockcolumnbgc) {
132 $tag = '[[setting:rblockcolumnbgc]]';
133 $css = str_replace($tag, $rblockcolumnbgc, $css);
134 return $css;
137 function formal_white_set_blockcolumnwidth($css, $blockcolumnwidth) {
138 $tag = '[[setting:blockcolumnwidth]]';
139 $css = str_replace($tag, $blockcolumnwidth.'px', $css);
141 $calculated = -2*$blockcolumnwidth;
142 $tag = '[[calculated:minusdoubleblockcolumnwidth]]';
143 $css = str_replace($tag, $calculated.'px', $css);
145 $calculated = 2*$blockcolumnwidth;
146 $tag = '[[calculated:doubleblockcolumnwidth]]';
147 $css = str_replace($tag, $calculated.'px', $css);
149 // set the min-width of the page to provide: content region min-width = block region width
150 // I do not care $framemargin because the min-width applies to #frametop that is free from $framemargin
151 // I need to add twice the width of the frame because it is inside #frametop
152 // (this code here because it HAS TO come later than $blockcolumnwidth definition)
153 $calculated = 3*$blockcolumnwidth + 34; // 34 = 2*17 (17px is the width of the frame)
154 $tag = '[[calculated:minwidth]]';
155 $css = str_replace($tag, $calculated.'px', $css);
157 return $css;
160 function formal_white_set_blockpadding($css, $blockcolumnwidth, $blockpadding) {
161 $tag = '[[setting:blockpadding]]';
162 $css = str_replace($tag, $blockpadding.'px', $css);
164 // I need to know the field width in pixel because width:100%; and width:auto; don't work as expected
165 // once $blockcolumnwidth and $blockpadding are known, $lb_fieldswidth can be applied
166 // the process has not been optimized at all but it is executed only once
167 $lb_fieldswidth = $blockcolumnwidth;
169 // #page-content .region-content {padding:[[setting:blockpadding]] [[setting:blockpadding]] 0 [[setting:blockpadding]];} in pagelayout.css
170 $lb_fieldswidth -= 2*$blockpadding;
172 // .block {border:[[static:lb_blockborderwidth]] solid #C6BDA8; [...] }
173 $lb_fieldsborderwidth = 1;
174 $tag = '[[static:lb_blockborderwidth]]'; // It is static, it is not a setting. I just hardcoded its definition here.
175 $css = str_replace($tag, $lb_fieldsborderwidth.'px', $css);
176 $lb_fieldswidth -= 2*$lb_fieldsborderwidth;
178 // .block_login .content {padding:[[static:lb_contentpadding]];}
179 $lb_fieldspadding = 4;
180 $tag = '[[static:lb_contentpadding]]'; // It is static, it is not a setting. I just hardcoded its definition here.
181 $css = str_replace($tag, $lb_fieldspadding.'px', $css);
182 $lb_fieldswidth -= 2*$lb_fieldspadding;
184 // .block_login #login_username, .block_login #login_password {margin:4px 0 4px [[static:lb_fieldsmargin]];}
185 $lb_fieldsmargin = 14;
186 $tag = '[[static:lb_fieldsmargin]]'; // It is static, it is not a setting. I just hardcoded its definition here.
187 $css = str_replace($tag, $lb_fieldsmargin.'px', $css);
188 $lb_fieldswidth -= $lb_fieldsmargin; // without 2* because it is only left margin
190 // fields default factory border: 3px
191 $lb_fieldswidth -= 2*3;
193 // leave few pixel on the right reducing once again the field length
194 $lb_fieldswidth -= 12;
196 $tag = '[[static:lb_fieldswidth]]';
197 $css = str_replace($tag, $lb_fieldswidth.'px', $css);
198 return $css;
201 function formal_white_set_customcss($css, $customcss) {
202 $tag = '[[setting:customcss]]';
203 $css = str_replace($tag, $customcss, $css);
204 return $css;