forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
themeBuilder.php
57 lines (49 loc) · 1.63 KB
/
themeBuilder.php
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
<?php
/**
* Build custom CSS elements defined in the Admin pages.
*
* @package OpenEMR
* @subpackage Theme
* @author Robert Down <[email protected]>
* @copyright Copyright (c) 2017 Robert Down
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
require_once __DIR__ . '/../globals.php';
$cssFile = file_get_contents('themeBuilder.css');
// Allowed CSS replacements
$variables = [
'font-family',
'font-size',
];
// Build string-replacement array
$re = "/%(.*)%/";
$matches = [];
preg_match_all($re, $cssFile, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$rawString = $match[0];
$key = $match[1];
if (!array_key_exists($key, $GLOBALS)) {
$msg = sprintf("The key '%s' was not found in the list of global variables", $key);
error_log($msg);
continue;
}
if ($GLOBALS["{$key}"] === '__default__') {
$cssFile = str_replace($rawString, '', $cssFile);
continue;
}
if (in_array($key, $variables)) {
// This is a CSS variable, not a $GLOBAL value replacement
$globalVal = $GLOBALS["{$key}"];
$attribString = "{$key}: {$globalVal} !important;";
$cssFile = str_replace($rawString, $attribString, $cssFile);
} else {
// $GLOBAL value replacement
$cssFile = str_replace($rawString, $GLOBALS["{$key}"], $cssFile);
}
}
header('Content-Type: text/css');
//set headers to NOT cache a page
header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
header("Pragma: no-cache"); //HTTP 1.0
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
echo $cssFile;