MDL-56629 dataformat_html: Adding UTF-8 charset
[moodle.git] / theme / boost / lib.php
blobe662f64c939502b766a321e5f2b4f6aaa9713cc1
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * Theme functions.
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();
27 /**
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);
35 $prefixer->prefix();
38 /**
39 * Inject additional SCSS.
41 * @param theme_config $theme The theme config object.
42 * @return string
44 function theme_boost_get_extra_scss($theme) {
45 return !empty($theme->settings->scss) ? $theme->settings->scss : '';
48 /**
49 * Returns the main SCSS content.
51 * @param theme_config $theme The theme config object.
52 * @return string
54 function theme_boost_get_main_scss_content($theme) {
55 global $CFG;
57 $scss = '';
58 $filename = !empty($theme->settings->preset) ? $theme->settings->preset : null;
59 $fs = get_file_storage();
61 $context = context_system::instance();
62 if ($filename == 'default.scss') {
63 $scss .= file_get_contents($CFG->dirroot . '/theme/boost/scss/preset/default.scss');
64 } else if ($filename == 'plain.scss') {
65 $scss .= file_get_contents($CFG->dirroot . '/theme/boost/scss/preset/plain.scss');
66 } else if ($filename && ($presetfile = $fs->get_file($context->id, 'theme_boost', 'preset', 0, '/', $filename))) {
67 $scss .= $presetfile->get_content();
68 } else {
69 // Safety fallback - maybe new installs etc.
70 $scss .= file_get_contents($CFG->dirroot . '/theme/boost/scss/preset/default.scss');
73 return $scss;
76 /**
77 * Get SCSS to prepend.
79 * @param theme_config $theme The theme config object.
80 * @return array
82 function theme_boost_get_pre_scss($theme) {
83 global $CFG;
85 $scss = '';
86 $configurable = [
87 // Config key => [variableName, ...].
88 'brandcolor' => ['brand-primary'],
91 // Prepend variables first.
92 foreach ($configurable as $configkey => $targets) {
93 $value = isset($theme->settings->{$configkey}) ? $theme->settings->{$configkey} : null;
94 if (empty($value)) {
95 continue;
97 array_map(function($target) use (&$scss, $value) {
98 $scss .= '$' . $target . ': ' . $value . ";\n";
99 }, (array) $targets);
102 // Prepend pre-scss.
103 if (!empty($theme->settings->scsspre)) {
104 $scss .= $theme->settings->scsspre;
107 return $scss;