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 $prefixer = new theme_boost\autoprefixer
($tree);
39 * Inject additional SCSS.
41 * @param theme_config $theme The theme config object.
44 function theme_boost_get_extra_scss($theme) {
46 $imageurl = $theme->setting_file_url('backgroundimage', 'backgroundimage');
48 // Sets the background image, and its settings.
49 if (!empty($imageurl)) {
50 $content .= 'body { ';
51 $content .= "background-image: url('$imageurl'); background-size: cover;";
55 // Always return the background image with the scss when we have it.
56 return !empty($theme->settings
->scss
) ?
$theme->settings
->scss
. ' ' . $content : $content;
60 * Serves any files associated with the theme settings.
62 * @param stdClass $course
64 * @param context $context
65 * @param string $filearea
67 * @param bool $forcedownload
68 * @param array $options
71 function theme_boost_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
72 if ($context->contextlevel
== CONTEXT_SYSTEM
&& ($filearea === 'logo' ||
$filearea === 'backgroundimage')) {
73 $theme = theme_config
::load('boost');
74 // By default, theme files must be cache-able by both browsers and proxies.
75 if (!array_key_exists('cacheability', $options)) {
76 $options['cacheability'] = 'public';
78 return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
80 send_file_not_found();
85 * Returns the main SCSS content.
87 * @param theme_config $theme The theme config object.
90 function theme_boost_get_main_scss_content($theme) {
94 $filename = !empty($theme->settings
->preset
) ?
$theme->settings
->preset
: null;
95 $fs = get_file_storage();
97 $context = context_system
::instance();
98 if ($filename == 'default.scss') {
99 $scss .= file_get_contents($CFG->dirroot
. '/theme/boost/scss/preset/default.scss');
100 } else if ($filename == 'plain.scss') {
101 $scss .= file_get_contents($CFG->dirroot
. '/theme/boost/scss/preset/plain.scss');
102 } else if ($filename && ($presetfile = $fs->get_file($context->id
, 'theme_boost', 'preset', 0, '/', $filename))) {
103 $scss .= $presetfile->get_content();
105 // Safety fallback - maybe new installs etc.
106 $scss .= file_get_contents($CFG->dirroot
. '/theme/boost/scss/preset/default.scss');
115 * @return string compiled css
117 function theme_boost_get_precompiled_css() {
119 return file_get_contents($CFG->dirroot
. '/theme/boost/style/moodle.css');
123 * Get SCSS to prepend.
125 * @param theme_config $theme The theme config object.
128 function theme_boost_get_pre_scss($theme) {
133 // Config key => [variableName, ...].
134 'brandcolor' => ['primary'],
137 // Prepend variables first.
138 foreach ($configurable as $configkey => $targets) {
139 $value = isset($theme->settings
->{$configkey}) ?
$theme->settings
->{$configkey} : null;
143 array_map(function($target) use (&$scss, $value) {
144 $scss .= '$' . $target . ': ' . $value . ";\n";
145 }, (array) $targets);
149 if (!empty($theme->settings
->scsspre
)) {
150 $scss .= $theme->settings
->scsspre
;
153 if (!empty($theme->settings
->fontsize
)) {
154 $scss .= '$font-size-base: ' . (1 / 100 * $theme->settings
->fontsize
) . "rem !default;\n";