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/>.
18 * Classic theme callbacks.
20 * @package theme_classic
21 * @copyright 2018 Bas Brands
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 // This line protects the file from being accessed by a URL directly.
26 defined('MOODLE_INTERNAL') ||
die();
29 * Returns the main SCSS content.
31 * @param theme_config $theme The theme config object.
34 function theme_classic_get_main_scss_content($theme) {
38 $filename = !empty($theme->settings
->preset
) ?
$theme->settings
->preset
: null;
39 $fs = get_file_storage();
41 $context = context_system
::instance();
42 $scss .= file_get_contents($CFG->dirroot
. '/theme/classic/scss/classic/pre.scss');
43 if ($filename && ($presetfile = $fs->get_file($context->id
, 'theme_classic', 'preset', 0, '/', $filename))) {
44 $scss .= $presetfile->get_content();
46 // Safety fallback - maybe new installs etc.
47 $scss .= file_get_contents($CFG->dirroot
. '/theme/classic/scss/preset/default.scss');
49 $scss .= file_get_contents($CFG->dirroot
. '/theme/classic/scss/classic/post.scss');
55 * Get SCSS to prepend.
57 * @param theme_config $theme The theme config object.
60 function theme_classic_get_pre_scss($theme) {
63 // Config key => [variableName, ...].
64 'brandcolor' => ['primary'],
67 // Prepend variables first.
68 foreach ($configurable as $configkey => $targets) {
69 $value = isset($theme->settings
->{$configkey}) ?
$theme->settings
->{$configkey} : null;
73 array_map(function($target) use (&$scss, $value) {
74 $scss .= '$' . $target . ': ' . $value . ";\n";
79 if (!empty($theme->settings
->scsspre
)) {
80 $scss .= $theme->settings
->scsspre
;
87 * Inject additional SCSS.
89 * @param theme_config $theme The theme config object.
92 function theme_classic_get_extra_scss($theme) {
96 // Set the page background image.
97 $imageurl = $theme->setting_file_url('backgroundimage', 'backgroundimage');
98 if (!empty($imageurl)) {
99 $content .= '$imageurl: "' . $imageurl . '";';
100 $content .= file_get_contents($CFG->dirroot
.
101 '/theme/classic/scss/classic/body-background.scss');
104 if (!empty($theme->settings
->navbardark
)) {
105 $content .= file_get_contents($CFG->dirroot
.
106 '/theme/classic/scss/classic/navbar-dark.scss');
108 $content .= file_get_contents($CFG->dirroot
.
109 '/theme/classic/scss/classic/navbar-light.scss');
111 if (!empty($theme->settings
->scss
)) {
112 $content .= $theme->settings
->scss
;
120 * @return string compiled css
122 function theme_classic_get_precompiled_css() {
124 return file_get_contents($CFG->dirroot
. '/theme/classic/style/moodle.css');
128 * Serves any files associated with the theme settings.
130 * @param stdClass $course
131 * @param stdClass $cm
132 * @param context $context
133 * @param string $filearea
135 * @param bool $forcedownload
136 * @param array $options
139 function theme_classic_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
140 if ($context->contextlevel
== CONTEXT_SYSTEM
&& ($filearea === 'backgroundimage')) {
141 $theme = theme_config
::load('classic');
142 // By default, theme files must be cache-able by both browsers and proxies.
143 if (!array_key_exists('cacheability', $options)) {
144 $options['cacheability'] = 'public';
146 return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
148 send_file_not_found();