forked from eduridden/moodle-theme_elegance
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlib.php
196 lines (169 loc) · 6.35 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
<?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 theme boost.
*
* @package theme
* @subpackage theme_elegance
* @author Julian (@moodleman) Ridden
* @copyright 2019 Bas Brands <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Returns the main SCSS content.
*
* @param theme_config $theme The theme config object.
* @return string
*/
function theme_elegance_get_main_scss_content($theme) {
global $CFG;
$scss = file_get_contents($CFG->dirroot . '/theme/elegance/scss/variables.scss');
$scss .= file_get_contents($CFG->dirroot . '/theme/boost/scss/fontawesome.scss');
$scss .= file_get_contents($CFG->dirroot . '/theme/boost/scss/bootstrap.scss');
$scss .= file_get_contents($CFG->dirroot . '/theme/boost/scss/moodle.scss');
$scss .= file_get_contents($CFG->dirroot . '/theme/elegance/scss/post.scss');
return $scss;
}
/**
* 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_elegance_get_pre_scss($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] = "url('" . $imagefile . "')";
}
}
$textvars = array('themecolor', 'fontcolor', 'headingcolor', 'videowidth', 'transparency', 'bodycolor');
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';
}
if (!empty($settings->loginbgnumber)) {
if ($settings->loginbgnumber > 0) {
$variables['loginbgcolor'] = 'transparent';
$variables['loginbg'] = 'none';
}
}
if (!empty($settings->bodybgconfig)) {
switch($settings->bodybgconfig) {
case 1:
$variables['bodybgrepeat'] = 'repeat';
$variables['bodybgposition'] = 'initial';
$variables['bodybgsize'] = 'initial';
$variables['bodybgattach'] = 'initial';
break;
case 2:
$variables['bodybgrepeat'] = 'no-repeat';
$variables['bodybgposition'] = 'fixed center center';
$variables['bodybgsize'] = 'cover';
$variables['bodybgattach'] = 'fixed';
break;
case 3:
$variables['bodybgrepeat'] = 'no-repeat';
$variables['bodybgposition'] = 'fixed center center';
$variables['bodybgsize'] = 'cover';
$variables['bodybgattach'] = 'scroll';
break;
}
}
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;
}
}
$scss = '';
foreach ($variables as $key => $value) {
$scss .= "$" . $key . ": " . $value . ";\n";
}
return $scss;
}
function theme_elegance_process_css($css, $theme) {
global $CFG;
// 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 if (preg_match('/marketingimage\d+/', $filearea)) {
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
} else {
send_file_not_found();
}
} else {
send_file_not_found();
}
}