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 * Library functions for theme_splash
20 * @package theme_splash
21 * @copyright 2011 Synergy Learning
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 * theme_splash post process function for CSS
27 * @param string $css Incoming CSS to process
28 * @param stdClass $theme The theme object
29 * @return string The processed CSS
31 function splash_process_css($css, $theme) {
33 if (!empty($theme->settings
->regionwidth
)) {
34 $regionwidth = $theme->settings
->regionwidth
;
38 $css = splash_set_regionwidth($css, $regionwidth);
40 if (!empty($theme->settings
->customcss
)) {
41 $customcss = $theme->settings
->customcss
;
45 $css = splash_set_customcss($css, $customcss);
51 * Sets the region width variable in CSS
54 * @param mixed $regionwidth
57 function splash_set_regionwidth($css, $regionwidth) {
58 $tag = '[[setting:regionwidth]]';
59 $doubletag = '[[setting:regionwidthdouble]]';
60 $leftmargintag = '[[setting:leftregionwidthmargin]]';
61 $rightmargintag = '[[setting:rightregionwidthmargin]]';
62 $replacement = $regionwidth;
63 if (is_null($replacement)) {
66 $css = str_replace($tag, $replacement.'px', $css);
67 $css = str_replace($doubletag, ($replacement*2).'px', $css);
68 $css = str_replace($rightmargintag, ($replacement*3-5).'px', $css);
69 $css = str_replace($leftmargintag, ($replacement+
5).'px', $css);
74 * Sets the custom css variable in CSS
77 * @param mixed $customcss
80 function splash_set_customcss($css, $customcss) {
81 $tag = '[[setting:customcss]]';
82 $replacement = $customcss;
83 if (is_null($replacement)) {
86 $css = str_replace($tag, $replacement, $css);
91 * Adds the JavaScript for the colour switcher to the page.
93 * The colour switcher is a YUI moodle module that is located in
94 * theme/splash/yui/splash/splash.js
96 * @param moodle_page $page
98 function splash_initialise_colourswitcher(moodle_page
$page) {
99 user_preference_allow_ajax_update('theme_splash_chosen_colour', PARAM_ALPHA
);
100 $page->requires
->yui_module('moodle-theme_splash-colourswitcher', 'M.theme_splash.initColourSwitcher', array(array('div'=>'#colourswitcher')));
104 * Gets the colour the user has selected, or the default if they have never changed
106 * @param string $default The default colour to use, normally red
107 * @return string The colour the user has selected
109 function splash_get_colour($default='red') {
110 return get_user_preferences('theme_splash_chosen_colour', $default);
114 * Checks if the user is switching colours with a refresh (JS disabled)
116 * If they are this updates the users preference in the database
120 function splash_check_colourswitch() {
121 $changecolour = optional_param('splashcolour', null, PARAM_ALPHA
);
122 if (in_array($changecolour, array('red', 'green', 'blue', 'orange'))) {
123 return set_user_preference('theme_splash_chosen_colour', $changecolour);