2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @package theme_boost
21 * @copyright 2016 Frédéric Massart - FMCorz.net
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
28 * Post process the CSS tree.
30 * @param string $tree The CSS tree.
31 * @param theme_config $theme The theme config object.
33 function theme_boost_css_tree_post_processor($tree, $theme) {
34 error_log('theme_boost_css_tree_post_processor() is deprecated. Required' .
35 'prefixes for Bootstrap are now in theme/boost/scss/moodle/prefixes.scss');
36 $prefixer = new theme_boost\autoprefixer
($tree);
41 * Inject additional SCSS.
43 * @param theme_config $theme The theme config object.
46 function theme_boost_get_extra_scss($theme) {
48 $imageurl = $theme->setting_file_url('backgroundimage', 'backgroundimage');
50 // Sets the background image, and its settings.
51 if (!empty($imageurl)) {
52 $content .= '@media (min-width: 768px) {';
53 $content .= 'body { ';
54 $content .= "background-image: url('$imageurl'); background-size: cover;";
58 // Sets the login background image.
59 $loginbackgroundimageurl = $theme->setting_file_url('loginbackgroundimage', 'loginbackgroundimage');
60 if (!empty($loginbackgroundimageurl)) {
61 $content .= 'body.pagelayout-login #page { ';
62 $content .= "background-image: url('$loginbackgroundimageurl'); background-size: cover;";
66 // Always return the background image with the scss when we have it.
67 return !empty($theme->settings
->scss
) ?
"{$theme->settings->scss} \n {$content}" : $content;
71 * Serves any files associated with the theme settings.
73 * @param stdClass $course
75 * @param context $context
76 * @param string $filearea
78 * @param bool $forcedownload
79 * @param array $options
82 function theme_boost_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
83 if ($context->contextlevel
== CONTEXT_SYSTEM
&& ($filearea === 'logo' ||
$filearea === 'backgroundimage' ||
84 $filearea === 'loginbackgroundimage')) {
85 $theme = theme_config
::load('boost');
86 // By default, theme files must be cache-able by both browsers and proxies.
87 if (!array_key_exists('cacheability', $options)) {
88 $options['cacheability'] = 'public';
90 return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
92 send_file_not_found();
97 * Get the current user preferences that are available
101 function theme_boost_user_preferences(): array {
103 'drawer-open-block' => [
104 'type' => PARAM_BOOL
,
105 'null' => NULL_NOT_ALLOWED
,
107 'permissioncallback' => [core_user
::class, 'is_current_user'],
109 'drawer-open-index' => [
110 'type' => PARAM_BOOL
,
111 'null' => NULL_NOT_ALLOWED
,
113 'permissioncallback' => [core_user
::class, 'is_current_user'],
119 * Returns the main SCSS content.
121 * @param theme_config $theme The theme config object.
124 function theme_boost_get_main_scss_content($theme) {
128 $filename = !empty($theme->settings
->preset
) ?
$theme->settings
->preset
: null;
129 $fs = get_file_storage();
131 $context = context_system
::instance();
132 if ($filename == 'default.scss') {
133 $scss .= file_get_contents($CFG->dirroot
. '/theme/boost/scss/preset/default.scss');
134 } else if ($filename == 'plain.scss') {
135 $scss .= file_get_contents($CFG->dirroot
. '/theme/boost/scss/preset/plain.scss');
136 } else if ($filename && ($presetfile = $fs->get_file($context->id
, 'theme_boost', 'preset', 0, '/', $filename))) {
137 $scss .= $presetfile->get_content();
139 // Safety fallback - maybe new installs etc.
140 $scss .= file_get_contents($CFG->dirroot
. '/theme/boost/scss/preset/default.scss');
149 * @return string compiled css
151 function theme_boost_get_precompiled_css() {
153 return file_get_contents($CFG->dirroot
. '/theme/boost/style/moodle.css');
157 * Get SCSS to prepend.
159 * @param theme_config $theme The theme config object.
162 function theme_boost_get_pre_scss($theme) {
167 // Config key => [variableName, ...].
168 'brandcolor' => ['primary'],
171 // Prepend variables first.
172 foreach ($configurable as $configkey => $targets) {
173 $value = isset($theme->settings
->{$configkey}) ?
$theme->settings
->{$configkey} : null;
177 array_map(function($target) use (&$scss, $value) {
178 $scss .= '$' . $target . ': ' . $value . ";\n";
179 }, (array) $targets);
183 if (!empty($theme->settings
->scsspre
)) {
184 $scss .= $theme->settings
->scsspre
;