Merge branch 'MDL-32442' of git://github.com/merrill-oakland/moodle
[moodle.git] / theme / splash / lib.php
blob191ec324c8d79dd102aaba2f0003ea1810f6cfd7
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 * 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
25 /**
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;
35 } else {
36 $regionwidth = null;
38 $css = splash_set_regionwidth($css, $regionwidth);
40 if (!empty($theme->settings->customcss)) {
41 $customcss = $theme->settings->customcss;
42 } else {
43 $customcss = null;
45 $css = splash_set_customcss($css, $customcss);
47 return $css;
50 /**
51 * Sets the region width variable in CSS
53 * @param string $css
54 * @param mixed $regionwidth
55 * @return string
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)) {
64 $replacement = 240;
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);
70 return $css;
73 /**
74 * Sets the custom css variable in CSS
76 * @param string $css
77 * @param mixed $customcss
78 * @return string
80 function splash_set_customcss($css, $customcss) {
81 $tag = '[[setting:customcss]]';
82 $replacement = $customcss;
83 if (is_null($replacement)) {
84 $replacement = '';
86 $css = str_replace($tag, $replacement, $css);
87 return $css;
90 /**
91 * Adds the JavaScript for the colour switcher to the page.
93 * @param moodle_page $page
95 function splash_initialise_colourswitcher(moodle_page $page) {
96 user_preference_allow_ajax_update('theme_splash_chosen_colour', PARAM_ALPHA);
97 $page->requires->yui_module('moodle-theme_splash-colourswitcher',
98 'M.theme_splash.initColourSwitcher', array(array('div'=>'#colourswitcher')));
102 * Gets the colour the user has selected, or the default if they have never changed
104 * @param string $default The default colour to use, normally red
105 * @return string The colour the user has selected
107 function splash_get_colour($default='red') {
108 return get_user_preferences('theme_splash_chosen_colour', $default);
112 * Checks if the user is switching colours with a refresh (JS disabled)
114 * If they are this updates the users preference in the database
116 * @return bool
118 function splash_check_colourswitch() {
119 $changecolour = optional_param('splashcolour', null, PARAM_ALPHA);
120 if (in_array($changecolour, array('red', 'green', 'blue', 'orange'))) {
121 return set_user_preference('theme_splash_chosen_colour', $changecolour);
123 return false;