forked from bmbrands/moodle-theme_elegance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
232 lines (197 loc) · 7.24 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
<?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/>.
/**
* The Elegance theme is built upon Bootstrapbase 3 (non-core).
*
* @package theme
* @subpackage theme_elegance
* @author Julian (@moodleman) Ridden
* @author Based on code originally written by G J Bernard, Mary Evans, Bas Brands, Stuart Lamour and David Scotson.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function elegance_grid($hassidepre, $hassidepost) {
if ($hassidepre && $hassidepost) {
$regions = array('content' => 'col-sm-6 col-sm-push-3');
$regions['pre'] = 'col-sm-3 col-sm-pull-6';
$regions['post'] = 'col-sm-3';
} else if ($hassidepre && !$hassidepost) {
$regions = array('content' => 'col-sm-9 col-sm-push-3');
$regions['pre'] = 'col-sm-3 col-sm-pull-9';
$regions['post'] = 'emtpy';
} else if (!$hassidepre && $hassidepost) {
$regions = array('content' => 'col-sm-9');
$regions['pre'] = 'empty';
$regions['post'] = 'col-sm-3';
} else if (!$hassidepre && !$hassidepost) {
$regions = array('content' => 'col-md-12');
$regions['pre'] = 'empty';
$regions['post'] = 'empty';
}
if ('rtl' === get_string('thisdirection', 'langconfig')) {
if ($hassidepre && $hassidepost) {
$regions['pre'] = 'col-sm-3 col-sm-push-3';
$regions['post'] = 'col-sm-3 col-sm-pull-9';
} else if ($hassidepre && !$hassidepost) {
$regions = array('content' => 'col-sm-9');
$regions['pre'] = 'col-sm-3';
$regions['post'] = 'empty';
} else if (!$hassidepre && $hassidepost) {
$regions = array('content' => 'col-sm-9 col-sm-push-3');
$regions['pre'] = 'empty';
$regions['post'] = 'col-sm-3 col-sm-pull-9';
}
}
return $regions;
}
function theme_elegance_extra_less($theme) {
}
/**
* 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.
*
* @param theme_config $theme The theme config object.
* @return array of LESS variables without the @.
*/
function theme_elegance_less_variables($theme) {
$variables = array();
$settings = $theme->settings;
$images = array('headerbg', 'bodybg', 'logo');
foreach ($images as $image) {
if (!empty($settings->$image)) {
$imagefile = $theme->setting_file_url($image, $image);
$variables[$image] = "'" . $imagefile . "'";
}
}
$textvars = array('themecolor', 'fontcolor', 'headingcolor', 'videowidth', 'transparency');
foreach ($textvars as $textvar) {
if (!empty($settings->$textvar)) {
$variables[$textvar] = $settings->$textvar;
}
}
if (!empty($settings->maxwidth)) {
$variables['maxwidth'] = $settings->maxwidth . 'px';
}
if (!empty($settings->fixednavbar)) {
$variables['navbarpadding'] = '50px';
}
foreach (range(1, 12) as $i) {
$textvar = "quicklinkiconcolor" . $i;
if (!empty($settings->$textvar)) {
$variables[$textvar] = $settings->$textvar;
}
$textvar = "quicklinkbuttoncolor" . $i;
if (!empty($settings->$textvar)) {
$variables[$textvar] = $settings->$textvar;
}
}
return $variables;
}
function theme_elegance_process_css($css, $theme) {
// Set the background image for the logo.
// Set custom CSS.
if (!empty($theme->settings->customcss)) {
$customcss = $theme->settings->customcss;
} else {
$customcss = null;
}
$css = theme_elegance_set_customcss($css, $customcss);
// Set custom Moodle Mobile CSS.
if (!empty($theme->settings->moodlemobilecss)) {
$moodlemobilecss = $theme->settings->moodlemobilecss;
} else {
$moodlemobilecss = null;
}
$css = theme_elegance_set_moodlemobilecss($css, $moodlemobilecss);
return $css;
}
/**
* Serves any files associated with the theme settings.
*
* @param stdClass $course
* @param stdClass $cm
* @param context $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @param array $options
* @return bool
*/
function theme_elegance_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
if ($context->contextlevel == CONTEXT_SYSTEM) {
$theme = theme_config::load('elegance');
if (!array_key_exists('cacheability', $options)) {
$options['cacheability'] = 'public';
}
if ($filearea === 'logo') {
return $theme->setting_file_serve('logo', $args, $forcedownload, $options);
} else if ($filearea === 'headerbg') {
return $theme->setting_file_serve('headerbg', $args, $forcedownload, $options);
} else if ($filearea === 'bodybg') {
return $theme->setting_file_serve('bodybg', $args, $forcedownload, $options);
} else if (preg_match('/bannerimage\d+/', $filearea)) {
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
} else if (preg_match('/loginimage\d+/', $filearea)) {
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
} else {
send_file_not_found();
}
} else {
send_file_not_found();
}
}
/**
* Adds any custom CSS to the CSS before it is cached.
*
* @param string $css The original CSS.
* @param string $customcss The custom CSS to add.
* @return string The CSS which now contains our custom CSS.
*/
function theme_elegance_set_customcss($css, $customcss) {
$tag = "[[setting:customcss]]";
$replacement = $customcss;
if (is_null($replacement)) {
$replacement = '';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
/**
* Adds any custom Moodle Mobile CSS to the CSS before it is cached.
*
* @param string $css The original CSS.
* @param string $moodlemobilecss The custom CSS to add.
* @return string The CSS which now contains our custom Moodle Mobile CSS.
*/
function theme_elegance_set_moodlemobilecss($css, $moodlemobilecss) {
$tag = "[[setting:moodlemobilecss]]";
$replacement = $moodlemobilecss;
if (is_null($replacement)) {
$replacement = '';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function theme_elegance_set_transparency($css, $transparency) {
$tag = '"[[setting:transparency]]"';
$replacement = $transparency;
if (is_null($replacement)) {
$replacement = '1';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}