Multiple improvements from IPPF related to layouts. (#1081)
[openemr.git] / interface / themes / themeBuilder.php
blobca86ef7a6ce64b79617a027447c2be0732238fac
1 <?php
2 /**
3 * Build custom CSS elements defined in the Admin pages.
5 * @package OpenEMR
6 * @subpackage Theme
7 * @author Robert Down <robertdown@live.com>
8 * @copyright Copyright (c) 2017 Robert Down
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
12 require_once __DIR__ . '/../globals.php';
14 $cssFile = file_get_contents('themeBuilder.css');
16 // Allowed CSS replacements
17 $variables = [
18 'font-family',
19 'font-size',
22 // Build string-replacement array
23 $re = "/%(.*)%/";
24 $matches = [];
25 preg_match_all($re, $cssFile, $matches, PREG_SET_ORDER);
27 foreach ($matches as $match) {
28 $rawString = $match[0];
29 $key = $match[1];
30 if (!array_key_exists($key, $GLOBALS)) {
31 $msg = sprintf("The key '%s' was not found in the list of global variables", $key);
32 error_log($msg);
33 continue;
36 if ($GLOBALS["{$key}"] === '__default__') {
37 $cssFile = str_replace($rawString, '', $cssFile);
38 continue;
41 if (in_array($key, $variables)) {
42 // This is a CSS variable, not a $GLOBAL value replacement
43 $globalVal = $GLOBALS["{$key}"];
44 $attribString = "{$key}: {$globalVal} !important;";
45 $cssFile = str_replace($rawString, $attribString, $cssFile);
46 } else {
47 // $GLOBAL value replacement
48 $cssFile = str_replace($rawString, $GLOBALS["{$key}"], $cssFile);
52 header('Content-Type: text/css');
53 //set headers to NOT cache a page
54 header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
55 header("Pragma: no-cache"); //HTTP 1.0
56 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
57 echo $cssFile;