Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
/**
18
 * Classic theme callbacks.
19
 *
20
 * @package    theme_classic
21
 * @copyright  2018 Bas Brands
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
// This line protects the file from being accessed by a URL directly.
26
defined('MOODLE_INTERNAL') || die();
27
 
28
/**
29
 * Returns the main SCSS content.
30
 *
31
 * @param theme_config $theme The theme config object.
32
 * @return string
33
 */
34
function theme_classic_get_main_scss_content($theme) {
35
    global $CFG;
36
 
37
    $scss = '';
38
    $filename = !empty($theme->settings->preset) ? $theme->settings->preset : null;
39
    $fs = get_file_storage();
40
 
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();
45
    } else {
46
        // Safety fallback - maybe new installs etc.
47
        $scss .= file_get_contents($CFG->dirroot . '/theme/classic/scss/preset/default.scss');
48
    }
49
    $scss .= file_get_contents($CFG->dirroot . '/theme/classic/scss/classic/post.scss');
50
 
51
    return $scss;
52
}
53
 
54
/**
55
 * Get SCSS to prepend.
56
 *
57
 * @param theme_config $theme The theme config object.
58
 * @return array
59
 */
60
function theme_classic_get_pre_scss($theme) {
61
    $scss = '';
62
    $configurable = [
63
        // Config key => [variableName, ...].
64
        'brandcolor' => ['primary'],
65
    ];
66
 
67
    // Prepend variables first.
68
    foreach ($configurable as $configkey => $targets) {
69
        $value = isset($theme->settings->{$configkey}) ? $theme->settings->{$configkey} : null;
70
        if (empty($value)) {
71
            continue;
72
        }
73
        array_map(function($target) use (&$scss, $value) {
74
            $scss .= '$' . $target . ': ' . $value . ";\n";
75
        }, (array) $targets);
76
    }
77
 
1441 ariadna 78
    // Add a new variable to indicate that we are running behat.
79
    if (defined('BEHAT_SITE_RUNNING')) {
80
        $scss .= "\$behatsite: true;\n";
81
    }
82
 
1 efrain 83
    // Prepend pre-scss.
84
    if (!empty($theme->settings->scsspre)) {
85
        $scss .= $theme->settings->scsspre;
86
    }
87
 
88
    return $scss;
89
}
90
 
91
/**
92
 * Inject additional SCSS.
93
 *
94
 * @param theme_config $theme The theme config object.
95
 * @return string
96
 */
97
function theme_classic_get_extra_scss($theme) {
98
    global $CFG;
99
    $content = '';
100
 
101
    // Set the page background image.
102
    $imageurl = $theme->setting_file_url('backgroundimage', 'backgroundimage');
103
    if (!empty($imageurl)) {
104
        $content .= '$imageurl: "' . $imageurl . '";';
105
        $content .= file_get_contents($CFG->dirroot .
106
            '/theme/classic/scss/classic/body-background.scss');
107
    }
108
 
109
    // Sets the login background image.
110
    $loginbackgroundimageurl = $theme->setting_file_url('loginbackgroundimage', 'loginbackgroundimage');
111
    if (!empty($loginbackgroundimageurl)) {
112
        $content .= 'body.pagelayout-login #page { ';
113
        $content .= "background-image: url('$loginbackgroundimageurl'); background-size: cover;";
114
        $content .= ' }';
115
    }
116
 
117
    if (!empty($theme->settings->navbardark)) {
118
        $content .= file_get_contents($CFG->dirroot .
119
            '/theme/classic/scss/classic/navbar-dark.scss');
120
    } else {
121
        $content .= file_get_contents($CFG->dirroot .
122
            '/theme/classic/scss/classic/navbar-light.scss');
123
    }
124
    if (!empty($theme->settings->scss)) {
125
        $content .= $theme->settings->scss;
126
    }
127
    return $content;
128
}
129
 
130
/**
131
 * Get compiled css.
132
 *
133
 * @return string compiled css
134
 */
135
function theme_classic_get_precompiled_css() {
136
    global $CFG;
137
    return file_get_contents($CFG->dirroot . '/theme/classic/style/moodle.css');
138
}
139
 
140
/**
141
 * Serves any files associated with the theme settings.
142
 *
143
 * @param stdClass $course
144
 * @param stdClass $cm
145
 * @param context $context
146
 * @param string $filearea
147
 * @param array $args
148
 * @param bool $forcedownload
149
 * @param array $options
150
 * @return bool
151
 */
152
function theme_classic_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
153
    if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'backgroundimage' || $filearea === 'loginbackgroundimage')) {
154
        $theme = theme_config::load('classic');
155
        // By default, theme files must be cache-able by both browsers and proxies.
156
        if (!array_key_exists('cacheability', $options)) {
157
            $options['cacheability'] = 'public';
158
        }
159
        return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
160
    } else {
161
        send_file_not_found();
162
    }
163
}