MDL-62757 themes: validate theme preset files
[moodle.git] / theme / boost / settings.php
CommitLineData
6bde9450
RW
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.
13//
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/>.
16
17/**
2ede86d7 18 * @package theme_boost
6bde9450
RW
19 * @copyright 2016 Ryan Wyllie
20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21 */
22
23defined('MOODLE_INTERNAL') || die();
24
25if ($ADMIN->fulltree) {
2ede86d7
DW
26 $settings = new theme_boost_admin_settingspage_tabs('themesettingboost', get_string('configtitle', 'theme_boost'));
27 $page = new admin_settingpage('theme_boost_general', get_string('generalsettings', 'theme_boost'));
6bde9450 28
d48dbde9 29 // Preset.
2ede86d7
DW
30 $name = 'theme_boost/preset';
31 $title = get_string('preset', 'theme_boost');
32 $description = get_string('preset_desc', 'theme_boost');
76132d1e
DW
33 $default = 'default.scss';
34
35 $context = context_system::instance();
36 $fs = get_file_storage();
37 $files = $fs->get_area_files($context->id, 'theme_boost', 'preset', 0, 'itemid, filepath, filename', false);
38
39 $choices = [];
40 foreach ($files as $file) {
41 $choices[$file->get_filename()] = $file->get_filename();
42 }
43 // These are the built in presets.
44 $choices['default.scss'] = 'default.scss';
45 $choices['plain.scss'] = 'plain.scss';
46
8040fafa 47 $setting = new admin_setting_configthemepreset($name, $title, $description, $default, $choices, 'boost');
d48dbde9
FM
48 $setting->set_updatedcallback('theme_reset_all_caches');
49 $page->add($setting);
6bde9450 50
76132d1e
DW
51 // Preset files setting.
52 $name = 'theme_boost/presetfiles';
53 $title = get_string('presetfiles','theme_boost');
54 $description = get_string('presetfiles_desc', 'theme_boost');
55
56 $setting = new admin_setting_configstoredfile($name, $title, $description, 'preset', 0,
57 array('maxfiles' => 20, 'accepted_types' => array('.scss')));
58 $page->add($setting);
59
6961f78d
CM
60 // Background image setting.
61 $name = 'theme_boost/backgroundimage';
62 $title = get_string('backgroundimage', 'theme_boost');
63 $description = get_string('backgroundimage_desc', 'theme_boost');
64 $setting = new admin_setting_configstoredfile($name, $title, $description, 'backgroundimage');
65 $setting->set_updatedcallback('theme_reset_all_caches');
66 $page->add($setting);
67
d48dbde9 68 // Variable $body-color.
b90843c8 69 // We use an empty default value because the default colour should come from the preset.
2ede86d7
DW
70 $name = 'theme_boost/brandcolor';
71 $title = get_string('brandcolor', 'theme_boost');
72 $description = get_string('brandcolor_desc', 'theme_boost');
b90843c8 73 $setting = new admin_setting_configcolourpicker($name, $title, $description, '');
d48dbde9
FM
74 $setting->set_updatedcallback('theme_reset_all_caches');
75 $page->add($setting);
6bde9450 76
d48dbde9
FM
77 // Must add the page after definiting all the settings!
78 $settings->add($page);
79
80 // Advanced settings.
2ede86d7 81 $page = new admin_settingpage('theme_boost_advanced', get_string('advancedsettings', 'theme_boost'));
d48dbde9 82
258143e3 83 // Raw SCSS to include before the content.
0e34e46f 84 $setting = new admin_setting_scsscode('theme_boost/scsspre',
258143e3 85 get_string('rawscsspre', 'theme_boost'), get_string('rawscsspre_desc', 'theme_boost'), '', PARAM_RAW);
d48dbde9
FM
86 $setting->set_updatedcallback('theme_reset_all_caches');
87 $page->add($setting);
88
258143e3 89 // Raw SCSS to include after the content.
0e34e46f 90 $setting = new admin_setting_scsscode('theme_boost/scss', get_string('rawscss', 'theme_boost'),
2ede86d7 91 get_string('rawscss_desc', 'theme_boost'), '', PARAM_RAW);
d48dbde9
FM
92 $setting->set_updatedcallback('theme_reset_all_caches');
93 $page->add($setting);
94
95 $settings->add($page);
6bde9450 96}