forked from dualcube/moodle-theme_rocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
executable file
·324 lines (323 loc) · 11.5 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<?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/>.
/**
* @package theme
* @subpackage rocket
* @copyright Julian Ridden
* @maintaned by 2014 Dualcube {@link http://dualcube.com/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function rocket_process_css($css, $theme) {
// Set the theme background and highlites.
if (!empty($theme->settings->themecolor)) {
$themecolor = $theme->settings->themecolor;
} else {
$themecolor = null;
}
$css = rocket_set_themecolor($css, $themecolor);
// Set the theme trim color.
if (!empty($theme->settings->themetrimcolor)) {
$themetrimcolor = $theme->settings->themetrimcolor;
} else {
$themetrimcolor = null;
}
$css = rocket_set_themetrimcolor($css, $themetrimcolor);
// Set the custommenu color.
if (!empty($theme->settings->menucolor)) {
$menucolor = $theme->settings->menucolor;
} else {
$menucolor = null;
}
$css = rocket_set_menucolor($css, $menucolor);
// Set the custommenu hover color.
if (!empty($theme->settings->menuhovercolor)) {
$menuhovercolor = $theme->settings->menuhovercolor;
} else {
$menuhovercolor = null;
}
$css = rocket_set_menuhovercolor($css, $menuhovercolor);
// Set the custommenu trim color.
if (!empty($theme->settings->menutrimcolor)) {
$menutrimcolor = $theme->settings->menutrimcolor;
} else {
$menutrimcolor = null;
}
$css = rocket_set_menutrimcolor($css, $menutrimcolor);
// Set the custommenu link color.
if (!empty($theme->settings->menulinkcolor)) {
$menulinkcolor = $theme->settings->menulinkcolor;
} else {
$menulinkcolor = null;
}
$css = rocket_set_menulinkcolor($css, $menulinkcolor);
// Set the content link color.
if (!empty($theme->settings->contentlinkcolor)) {
$contentlinkcolor = $theme->settings->contentlinkcolor;
} else {
$contentlinkcolor = null;
}
$css = rocket_set_contentlinkcolor($css, $contentlinkcolor);
// Set the block link color.
if (!empty($theme->settings->blocklinkcolor)) {
$blocklinkcolor = $theme->settings->blocklinkcolor;
} else {
$blocklinkcolor = null;
}
$css = rocket_set_blocklinkcolor($css, $blocklinkcolor);
// Set the background image for the logo.
$logo = $theme->setting_file_url('logo', 'logo');
$css = rocket_set_logo($css, $logo);
// Set Banner Image.
$setting = 'bannerimage';
// Creates the url for image file which is then served up by 'theme_rocket_pluginfile' below.
$banner = $theme->setting_file_url($setting, $setting);
$css = rocket_set_banner($css, $banner, $setting);
// Set the banner height.
if (!empty($theme->settings->bannerheight)) {
$bannerheight = $theme->settings->bannerheight;
} else {
$bannerheight = null;
}
$css = rocket_set_bannerheight($css, $bannerheight);
// Set the screenwidth.
if (!empty($theme->settings->screenwidth)) {
$screenwidth = $theme->settings->screenwidth;
} else {
$screenwidth = null;
}
$css = rocket_set_screenwidth($css, $screenwidth);
// Toggle AutoHide functionality.
if (!empty($theme->settings->autohide)) {
$autohide = $theme->settings->autohide;
} else {
$autohide = null;
}
// Toggle Bootstrap functionality.
if (!empty($theme->settings->bootstrap)) {
$bootstrap = $theme->settings->bootstrap;
} else {
$bootstrap = null;
}
// Allow for additional custom CSS from admins.
if (!empty($theme->settings->customcss)) {
$customcss = $theme->settings->customcss;
} else {
$customcss = null;
}
$css = rocket_set_customcss($css, $customcss);
return $css;
}
function rocket_set_themecolor($css, $themecolor) {
$tag = '[[setting:themecolor]]';
$replacement = $themecolor;
if (is_null($replacement)) {
$replacement = '#5faff2';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_themetrimcolor($css, $themetrimcolor) {
$tag = '[[setting:themetrimcolor]]';
$replacement = $themetrimcolor;
if (is_null($replacement)) {
$replacement = '#660000';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_menucolor($css, $menucolor) {
$tag = '[[setting:menucolor]]';
$replacement = $menucolor;
if (is_null($replacement)) {
$replacement = '#76777c';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_menuhovercolor($css, $menuhovercolor) {
$tag = '[[setting:menuhovercolor]]';
$replacement = $menuhovercolor;
if (is_null($replacement)) {
$replacement = '#919193';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_menulinkcolor($css, $menulinkcolor) {
$tag = '[[setting:menulinkcolor]]';
$replacement = $menulinkcolor;
if (is_null($replacement)) {
$replacement = '#ffffff';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_contentlinkcolor($css, $contentlinkcolor) {
$tag = '[[setting:contentlinkcolor]]';
$replacement = $contentlinkcolor;
if (is_null($replacement)) {
$replacement = '#006699';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_blocklinkcolor($css, $blocklinkcolor) {
$tag = '[[setting:blocklinkcolor]]';
$replacement = $blocklinkcolor;
if (is_null($replacement)) {
$replacement = '#333333';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_menutrimcolor($css, $menutrimcolor) {
$tag = '[[setting:menutrimcolor]]';
$replacement = $menutrimcolor;
if (is_null($replacement)) {
$replacement = '#4c4c4c';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function theme_rocket_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
if ($context->contextlevel == CONTEXT_SYSTEM and $filearea === 'logo') {
$theme = theme_config::load('rocket');
return $theme->setting_file_serve('logo', $args, $forcedownload, $options);
} else if ($context->contextlevel == CONTEXT_SYSTEM and $filearea === 'bannerimage') {
$theme = theme_config::load('rocket');
return $theme->setting_file_serve('bannerimage', $args, $forcedownload, $options);
} else {
send_file_not_found();
}
}
function rocket_set_logo($css, $logo) {
global $OUTPUT;
$tag = '[[setting:logo]]';
$replacement = $logo;
if (is_null($replacement)) {
$replacement = $OUTPUT->pix_url('logo/'.$setting, 'theme');
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_banner($css, $banner, $setting) {
global $OUTPUT;
$tag = '[[setting:banner]]';
$replacement = $banner;
if (is_null($replacement)) {
// Get default image from themes 'images' folder of the name in $setting.
$replacement = $OUTPUT->pix_url('banner/'.$setting, 'theme');
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_bannerheight($css, $bannerheight) {
$tag = '[[setting:bannerheight]]';
$replacement = $bannerheight;
if (is_null($replacement)) {
$replacement = '250';
}
$css = str_replace($tag, ($replacement - 5).'px', $css);
return $css;
}
function rocket_set_screenwidth($css, $screenwidth) {
$tag = '[[setting:screenwidth]]';
$breadcrumbwidth = '[[setting:breadcrumbwidth]]';
$screenwidthmargintag = '[[setting:screenwidthmargintag]]';
$replacement = $screenwidth;
if (is_null($replacement)) {
$replacement = '1000';
}
if ( $screenwidth == "1000" ) {
$css = str_replace($tag, $replacement.'px', $css);
$css = str_replace($screenwidthmargintag, ($replacement + 5).'px', $css);
$css = str_replace($breadcrumbwidth, ($replacement - 470).'px', $css);
}
if ( $replacement == "97" ) {
$css = str_replace($tag, $replacement.'%', $css);
$css = str_replace($breadcrumbwidth, '50%', $css);
}
return $css;
}
function rocket_set_autohide($css, $autohide) {
$tag = '[[setting:autohide]]';
$replacement = $autohide;
if (is_null($replacement)) {
$replacement = 'enable';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_bootstrap($css, $bootstrap) {
$tag = '[[setting:bootstrap]]';
$replacement = $bootstrap;
if (is_null($replacement)) {
$replacement = 'disable';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
function rocket_set_customcss($css, $customcss) {
$tag = '[[setting:customcss]]';
$replacement = $customcss;
if (is_null($replacement)) {
$replacement = '';
}
$css = str_replace($tag, $replacement, $css);
return $css;
}
/**
* get_performance_output() override get_peformance_info()
* in moodlelib.php. Returns a string
* values ready for use.
*
* This function was created by Lei Zhang and was originally used in the decaf theme
* @return string
*/
function rocket_performance_output($param) {
$html = '<div class="performanceinfo"><ul>';
if (isset($param['realtime'])) $html .= '<li><a class="red" href="#"><var>'.$param['realtime'].' secs</var><span>Load Time</span></a></li>';
if (isset($param['memory_total'])) $html .= '<li><a class="orange" href="#"><var>'.display_size($param['memory_total']).'</var><span>Memory Used</span></a></li>';
if (isset($param['includecount'])) $html .= '<li><a class="blue" href="#"><var>'.$param['includecount'].' Files </var><span>Included</span></a></li>';
if (isset($param['dbqueries'])) $html .= '<li><a class="purple" href="#"><var>'.$param['dbqueries'].' </var><span>DB Read/Write</span></a></li>';
$html .= '</ul></div>';
return $html;
}
/**
* Generate updated custommenu with enroled courses listed
*/
class transmuted_custom_menu_item extends custom_menu_item {
public function __construct(custom_menu_item $menunode) {
parent::__construct($menunode->get_text(), $menunode->get_url(), $menunode->get_title(), $menunode->get_sort_order(), $menunode->get_parent());
$this->children = $menunode->get_children();
$matches = array();
if (preg_match('/^\[\[([a-zA-Z0-9\-\_\:]+)\]\]$/', $this->text, $matches)) {
try {
$this->text = get_string($matches[1], 'theme_rocket');
} catch (Exception $e) {
$this->text = $matches[1];
}
}
$matches = array();
if (preg_match('/^\[\[([a-zA-Z0-9\-\_\:]+)\]\]$/', $this->title, $matches)) {
try {
$this->title = get_string($matches[1], 'theme_rocket');
} catch (Exception $e) {
$this->title = $matches[1];
}
}
}
}