Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 124 lines (114 sloc) 3.845 kb
9e390914 » epsd
2010-08-04 Adding new core theme splash MDL-23661
1 <?php
a47bff6f » samhemelryk
2010-08-11 theme-splash MDL-23674 Cleanup of the themes, numerous small changes …
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 /**
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
18 * Library functions for theme_splash
a47bff6f » samhemelryk
2010-08-11 theme-splash MDL-23674 Cleanup of the themes, numerous small changes …
19 *
20 * @package theme_splash
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
21 * @copyright 2011 Synergy Learning
a47bff6f » samhemelryk
2010-08-11 theme-splash MDL-23674 Cleanup of the themes, numerous small changes …
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25 /**
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
26 * theme_splash post process function for CSS
a47bff6f » samhemelryk
2010-08-11 theme-splash MDL-23674 Cleanup of the themes, numerous small changes …
27 * @param string $css Incoming CSS to process
28 * @param stdClass $theme The theme object
29 * @return string The processed CSS
30 */
9e390914 » epsd
2010-08-04 Adding new core theme splash MDL-23661
31 function splash_process_css($css, $theme) {
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
32
9e390914 » epsd
2010-08-04 Adding new core theme splash MDL-23661
33 if (!empty($theme->settings->regionwidth)) {
34 $regionwidth = $theme->settings->regionwidth;
35 } else {
36 $regionwidth = null;
37 }
38 $css = splash_set_regionwidth($css, $regionwidth);
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
39
9e390914 » epsd
2010-08-04 Adding new core theme splash MDL-23661
40 if (!empty($theme->settings->customcss)) {
41 $customcss = $theme->settings->customcss;
42 } else {
43 $customcss = null;
44 }
45 $css = splash_set_customcss($css, $customcss);
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
46
9e390914 » epsd
2010-08-04 Adding new core theme splash MDL-23661
47 return $css;
48 }
49
50 /**
51 * Sets the region width variable in CSS
52 *
53 * @param string $css
54 * @param mixed $regionwidth
55 * @return string
56 */
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;
65 }
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;
71 }
72
73 /**
74 * Sets the custom css variable in CSS
75 *
76 * @param string $css
77 * @param mixed $customcss
78 * @return string
79 */
80 function splash_set_customcss($css, $customcss) {
81 $tag = '[[setting:customcss]]';
82 $replacement = $customcss;
83 if (is_null($replacement)) {
84 $replacement = '';
85 }
86 $css = str_replace($tag, $replacement, $css);
87 return $css;
88 }
89
a47bff6f » samhemelryk
2010-08-11 theme-splash MDL-23674 Cleanup of the themes, numerous small changes …
90 /**
91 * Adds the JavaScript for the colour switcher to the page.
92 *
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
93 * @param moodle_page $page
a47bff6f » samhemelryk
2010-08-11 theme-splash MDL-23674 Cleanup of the themes, numerous small changes …
94 */
95 function splash_initialise_colourswitcher(moodle_page $page) {
96 user_preference_allow_ajax_update('theme_splash_chosen_colour', PARAM_ALPHA);
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
97 $page->requires->yui_module('moodle-theme_splash-colourswitcher',
98 'M.theme_splash.initColourSwitcher', array(array('div'=>'#colourswitcher')));
a47bff6f » samhemelryk
2010-08-11 theme-splash MDL-23674 Cleanup of the themes, numerous small changes …
99 }
100
101 /**
102 * Gets the colour the user has selected, or the default if they have never changed
103 *
104 * @param string $default The default colour to use, normally red
105 * @return string The colour the user has selected
106 */
107 function splash_get_colour($default='red') {
108 return get_user_preferences('theme_splash_chosen_colour', $default);
109 }
110
111 /**
112 * Checks if the user is switching colours with a refresh (JS disabled)
113 *
114 * If they are this updates the users preference in the database
115 *
116 * @return bool
117 */
118 function splash_check_colourswitch() {
119 $changecolour = optional_param('splashcolour', null, PARAM_ALPHA);
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
120 if (in_array($changecolour, array('red', 'green', 'blue', 'orange'))) {
a47bff6f » samhemelryk
2010-08-11 theme-splash MDL-23674 Cleanup of the themes, numerous small changes …
121 return set_user_preference('theme_splash_chosen_colour', $changecolour);
122 }
123 return false;
0170739a » lazydaisy
2012-02-24 MDL-31351_master theme_splash: updated version
124 }
Something went wrong with that request. Please try again.