Merge branch 'MDL-30683' of git://github.com/timhunt/moodle
[moodle.git] / theme / nonzero / lib.php
blob460fef11fa1978c1629ead95adc1b5bef8f1eef2
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * This file contains the settings for the Nonzero theme.
21 * Currently you can set the following settings:
22 * - Region pre width
23 * - Region post width
24 * - Some custom CSS
26 * @package moodlecore
27 * @copyright 2010 Dietmar Wagner
28 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 function nonzero_process_css($css, $theme) {
34 // Set the region-pre and region-post widths
35 if (!empty($theme->settings->regionprewidth) && !empty($theme->settings->regionpostwidth)) {
36 $regionprewidth = $theme->settings->regionprewidth;
37 $regionpostwidth = $theme->settings->regionpostwidth;
38 } else {
39 $regionprewidth = null;
40 $regionpostwidth = null;
42 $css = nonzero_set_regionwidths($css, $regionprewidth, $regionpostwidth);
45 // Set the custom CSS
46 if (!empty($theme->settings->customcss)) {
47 $customcss = $theme->settings->customcss;
48 } else {
49 $customcss = null;
51 $css = nonzero_set_customcss($css, $customcss);
53 // Return the CSS
54 return $css;
57 /**
58 * Sets the region width variable in CSS
60 * @param string $css
61 * @param mixed $regionwidth
62 * @return string
65 function nonzero_set_regionwidths($css, $regionprewidth, $regionpostwidth) {
66 $tag1 = '[[setting:regionprewidth]]';
67 $tag2 = '[[setting:regionpostwidth]]';
68 $tag3 = '[[setting:regionsumwidth]]';
69 $tag4 = '[[setting:regiondoublepresumwidth]]';
70 $replacement1 = $regionprewidth;
71 $replacement2 = $regionpostwidth;
72 if (is_null($replacement1) or is_null($replacement2)) {
73 $replacement1 = 200;
74 $replacement2 = 200;
76 $css = str_replace($tag1, $replacement1.'px', $css);
77 $css = str_replace($tag2, $replacement2.'px', $css);
78 $css = str_replace($tag3, ($replacement1+$replacement2).'px', $css);
79 $css = str_replace($tag4, (2*$replacement1+$replacement2).'px', $css);
80 return $css;
84 /**
85 * Sets the custom css variable in CSS
87 * @param string $css
88 * @param mixed $customcss
89 * @return string
92 function nonzero_set_customcss($css, $customcss) {
93 $tag = '[[setting:customcss]]';
94 $replacement = $customcss;
95 if (is_null($replacement)) {
96 $replacement = '';
98 $css = str_replace($tag, $replacement, $css);
99 return $css;