forked from bmbrands/theme_bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlib.php
More file actions
158 lines (139 loc) · 5.13 KB
/
lib.php
File metadata and controls
158 lines (139 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
// This file is part of The Bootstrap 3 Moodle theme
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Renderers to align Moodle's HTML with that expected by Bootstrap
*
* @package theme_bootstrap
* @copyright 2014 Bas Brands, www.basbrands.nl
* @authors Bas Brands, David Scotson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Parses CSS before it is cached.
*
* This function can make alterations and replace patterns within the CSS.
*
* @param string $css The CSS
* @param theme_config $theme The theme config object.
* @return string The parsed CSS The parsed CSS.
*/
function theme_bootstrap_process_css($css, $theme) {
$settings = get_object_vars($theme->settings);
$css = theme_bootstrap_delete_css($settings, $css);
$settings['brandcss'] = theme_bootstrap_brand_font_css($settings);
return theme_bootstrap_replace_settings($settings, $css);
}
function theme_bootstrap_delete_css($settings, $css) {
if ($settings['deletecss'] == true) {
$find[] = '/-webkit-border-radius:[^;]*;/';
$find[] = '/-webkit-box-shadow:[^;]*;/';
$find[] = '/-moz-border-radius:[^;]*;/';
$find[] = '/-moz-box-shadow:[^;]*;/';
return preg_replace($find, '', $css);
} else {
return $css;
}
}
/**
* For each setting called e.g. "customcss" this looks for the string
* "[[setting:customcss]]" in the CSS and replaces it with
* the value held in the $settings array for the key
* "customcss".
*
* @param array $settings containing setting names and values
* @param string $css The CSS
* @return string The CSS with replacements made
*/
function theme_bootstrap_replace_settings($settings, $css) {
foreach ($settings as $name => $value) {
$find[] = "[[setting:$name]]";
$replace[] = $value;
}
return str_replace($find, $replace, $css);
}
function theme_bootstrap_brand_font_css($settings) {
$fontname = $settings['brandfont'];
if ($fontname === '') {
return '';
}
$fontweight = $settings['brandfontweight'];
return ".navbar-default .navbar-brand,
.navbar-inverse .navbar-brand {
font-family: $fontname, serif;
font-weight: $fontweight;
}";
}
/**
* This function creates the dynamic HTML needed for the
* layout and then passes it back in an object so it can
* be echo'd to the page.
*
* This keeps the logic out of the layout files.
*/
function theme_bootstrap_html_for_settings($PAGE) {
$settings = $PAGE->theme->settings;
$html = new stdClass;
if ($settings->inversenavbar == true) {
$html->navbarclass = 'navbar navbar-inverse';
} else {
$html->navbarclass = 'navbar navbar-default';
}
$fluid = (!empty($PAGE->layout_options['fluid']));
if ($fluid || $settings->fluidwidth == true) {
$html->containerclass = 'container-fluid';
} else {
$html->containerclass = 'container';
}
$html->brandfontlink = theme_bootstrap_brand_font_link($settings);
return $html;
}
function theme_bootstrap_brand_font_link($settings) {
global $SITE;
$fontname = $settings->brandfont;
if ($fontname === '') {
return '';
}
$fontname = urlencode($fontname);
$text = urlencode(str_replace(' ', '', $SITE->shortname));
$fontweight = $settings->brandfontweight;
$fontitalic = '';
if ($settings->brandfontitalic == true) {
$fontitalic = 'italic';
}
return '<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family='
.$fontname.':'.$fontweight.$fontitalic.'&text='.$text.'">';
}
function bootstrap_grid($hassidepre, $hassidepost) {
if ($hassidepre && $hassidepost) {
$regions = array('content' => 'col-sm-4 col-sm-push-4 col-md-6 col-md-push-3');
$regions['pre'] = 'col-sm-4 col-sm-pull-4 col-md-3 col-md-pull-6';
$regions['post'] = 'col-sm-4 col-md-3';
} else if ($hassidepre && !$hassidepost) {
$regions = array('content' => 'col-sm-8 col-sm-push-4 col-md-9 col-md-push-3');
$regions['pre'] = 'col-sm-4 col-sm-pull-8 col-md-3 col-md-pull-9';
$regions['post'] = 'emtpy';
} else if (!$hassidepre && $hassidepost) {
$regions = array('content' => 'col-sm-8 col-md-9');
$regions['pre'] = 'empty';
$regions['post'] = 'col-sm-4 col-md-3';
} else if (!$hassidepre && !$hassidepost) {
$regions = array('content' => 'col-md-12');
$regions['pre'] = 'empty';
$regions['post'] = 'empty';
}
return $regions;
}