Theme fix for magazine, MDL-24392
[moodle.git] / theme / magazine / lib.php
CommitLineData
b8fce7be
S
1<?php
2
3/**
4 * Makes our changes to the CSS
5 *
6 * @param string $css
7 * @param theme_config $theme
8 * @return string
9 */
10function magazine_process_css($css, $theme) {
11
12 // Set the link color
13 if (!empty($theme->settings->linkcolor)) {
14 $linkcolor = $theme->settings->linkcolor;
15 } else {
16 $linkcolor = null;
17 }
18 $css = magazine_set_linkcolor($css, $linkcolor);
19
20 // Set the link hover color
21 if (!empty($theme->settings->linkhover)) {
22 $linkhover = $theme->settings->linkhover;
23 } else {
24 $linkhover = null;
25 }
26 $css = magazine_set_linkhover($css, $linkhover);
27
28 // Set the main color
29 if (!empty($theme->settings->maincolor)) {
30 $maincolor = $theme->settings->maincolor;
31 } else {
32 $maincolor = null;
33 }
34 $css = magazine_set_maincolor($css, $maincolor);
35
36 // Set the main accent color
37 if (!empty($theme->settings->maincoloraccent)) {
38 $maincoloraccent = $theme->settings->maincoloraccent;
39 } else {
40 $maincoloraccent = null;
41 }
42 $css = magazine_set_maincoloraccent($css, $maincoloraccent);
43
44 // Set the main headings color
45 if (!empty($theme->settings->headingcolor)) {
46 $headingcolor = $theme->settings->headingcolor;
47 } else {
48 $headingcolor = null;
49 }
50 $css = magazine_set_headingcolor($css, $headingcolor);
51
52 // Set the block headings color
53 if (!empty($theme->settings->blockcolor)) {
54 $blockcolor = $theme->settings->blockcolor;
55 } else {
56 $blockcolor = null;
57 }
58 $css = magazine_set_blockcolor($css, $blockcolor);
59
60 // Set the forum background color
61 if (!empty($theme->settings->forumback)) {
62 $forumback = $theme->settings->forumback;
63 } else {
64 $forumback = null;
65 }
66 $css = magazine_set_forumback($css, $forumback);
67
68 // Set the body background image
69 if (!empty($theme->settings->background)) {
70 $background = $theme->settings->background;
71 } else {
72 $background = null;
73 }
74 $css = magazine_set_background($css, $background);
75
76 // Set the logo image
77 if (!empty($theme->settings->logo)) {
78 $logo = $theme->settings->logo;
79 } else {
80 $logo = null;
81 }
82 $css = magazine_set_logo($css, $logo);
83
84
85 // Return the CSS
86 return $css;
87}
88
89
90
91/**
92 * Sets the link color variable in CSS
93 *
94 */
95function magazine_set_linkcolor($css, $linkcolor) {
96 $tag = '[[setting:linkcolor]]';
97 $replacement = $linkcolor;
98 if (is_null($replacement)) {
99 $replacement = '#32529a';
100 }
101 $css = str_replace($tag, $replacement, $css);
102 return $css;
103}
104
105function magazine_set_linkhover($css, $linkhover) {
106 $tag = '[[setting:linkhover]]';
107 $replacement = $linkhover;
108 if (is_null($replacement)) {
109 $replacement = '#4e2300';
110 }
111 $css = str_replace($tag, $replacement, $css);
112 return $css;
113}
114
115function magazine_set_maincolor($css, $maincolor) {
116 $tag = '[[setting:maincolor]]';
117 $replacement = $maincolor;
118 if (is_null($replacement)) {
119 $replacement = '#002f2f';
120 }
121 $css = str_replace($tag, $replacement, $css);
122 return $css;
123}
124
125function magazine_set_maincoloraccent($css, $maincoloraccent) {
126 $tag = '[[setting:maincoloraccent]]';
127 $replacement = $maincoloraccent;
128 if (is_null($replacement)) {
129 $replacement = '#092323';
130 }
131 $css = str_replace($tag, $replacement, $css);
132 return $css;
133}
134
135function magazine_set_headingcolor($css, $headingcolor) {
136 $tag = '[[setting:headingcolor]]';
137 $replacement = $headingcolor;
138 if (is_null($replacement)) {
139 $replacement = '#4e0000';
140 }
141 $css = str_replace($tag, $replacement, $css);
142 return $css;
143}
144
145function magazine_set_blockcolor($css, $blockcolor) {
146 $tag = '[[setting:blockcolor]]';
147 $replacement = $blockcolor;
148 if (is_null($replacement)) {
149 $replacement = '#002f2f';
150 }
151 $css = str_replace($tag, $replacement, $css);
152 return $css;
153}
154
155function magazine_set_forumback($css, $forumback) {
156 $tag = '[[setting:forumback]]';
157 $replacement = $forumback;
158 if (is_null($replacement)) {
159 $replacement = '#e6e2af';
160 }
161 $css = str_replace($tag, $replacement, $css);
162 return $css;
163}
164
165function magazine_set_background($css, $background) {
166 global $OUTPUT;
167 $tag = '[[setting:background]]';
168 $replacement = $background;
169 if (is_null($replacement)) {
170 $replacement = $OUTPUT->pix_url('bg4', 'theme');
171 }
172 $css = str_replace($tag, $replacement, $css);
173 return $css;
174}
175
176function magazine_set_logo($css, $logo) {
177 global $OUTPUT;
178 $tag = '[[setting:logo]]';
179 $replacement = $logo;
180 if (is_null($replacement)) {
181 $replacement = $OUTPUT->pix_url('logo', 'theme');
182 }
183 $css = str_replace($tag, $replacement, $css);
184 return $css;
185}