ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
CSSBuilder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 public function __construct(
26 protected \ilObjStyleSheet $style,
27 protected string $image_dir
28 ) {
29
30 }
31
32 public function getCss(): string
33 {
34 $style = $this->style->getStyle();
35
36 $css = "";
37 $page_background = "";
38
39 $mqs = array(array("mquery" => "", "id" => 0));
40 foreach ($this->style->getMediaQueries() as $mq) {
41 $mqs[] = $mq;
42 }
43
44 // iterate all media queries
45 foreach ($mqs as $mq) {
46 if ($mq["id"] > 0) {
47 $css .= "@media " . $mq["mquery"] . " {\n";
48 }
49 reset($style);
50 foreach ($style as $tag) {
51 if ($tag[0]["mq_id"] != $mq["id"]) {
52 continue;
53 }
54 if (is_int(strpos($tag[0]["class"], "before")) && !is_int(strpos($tag[0]["class"], "::before"))) {
55 $tag[0]["class"] = str_replace(":before", "::before", $tag[0]["class"]);
56 }
57 $css .= $tag[0]["tag"] . ".ilc_" . $tag[0]["type"] . "_" . $tag[0]["class"] . "\n";
58 // echo "<br>";
59 // var_dump($tag[0]["type"]);
60 if ($tag[0]["tag"] == "td") {
61 $css .= ",th" . ".ilc_" . $tag[0]["type"] . "_" . $tag[0]["class"] . "\n";
62 }
63 if (in_array($tag[0]["tag"], array("h1", "h2", "h3"))) {
64 $css .= ",div.ilc_text_block_" . $tag[0]["class"] . "\n";
65 $css .= ",html.il-no-tiny-bg body#tinymce.ilc_text_block_" . $tag[0]["class"] . "\n";
66 }
67 if ($tag[0]["type"] == "section") { // sections can use a tags, if links are used
68 $css .= ",a.ilc_" . $tag[0]["type"] . "_" . $tag[0]["class"] . "\n";
69 }
70 if ($tag[0]["type"] == "strong") {
71 $css .= ",span.ilc_text_inline_" . $tag[0]["class"] . "\n";
72 }
73 if ($tag[0]["type"] == "em") {
74 $css .= ",span.ilc_text_inline_" . $tag[0]["class"] . "\n";
75 }
76 if ($tag[0]["type"] == "text_block") {
77 $css .= ",html.il-no-tiny-bg body#tinymce.ilc_text_block_" . $tag[0]["class"] . "\n";
78 }
79 if ($tag[0]["class"] == "VAccordCntr") {
80 $css .= ",div.ilc_va_cntr_AccordCntr\n";
81 }
82 if ($tag[0]["class"] == "VAccordICntr") {
83 $css .= ",div.ilc_va_icntr_AccordICntr\n";
84 }
85 if ($tag[0]["class"] == "VAccordICont") {
86 $css .= ",div.ilc_va_icont_AccordICont\n";
87 }
88 if ($tag[0]["class"] == "VAccordIHead") {
89 $css .= ",div.ilc_va_ihead_AccordIHead\n";
90 }
91 if ($tag[0]["class"] == "VAccordIHead:hover") {
92 $css .= ",div.ilc_va_ihead_AccordIHead:hover\n";
93 }
94 if ($tag[0]["class"] == "VAccordIHeadActive") {
95 $css .= ",div.ilc_va_iheada_AccordIHeadActive\n";
96 }
97 if ($tag[0]["class"] == "VAccordIHeadActive:hover") {
98 $css .= ",div.ilc_va_iheada_AccordIHeadActive:hover\n";
99 }
100 $css .= "{\n";
101
102 // collect table border attributes
103 $t_border = array();
104
105 foreach ($tag as $par) {
106 $cur_par = $par["parameter"];
107 $cur_val = $par["value"];
108
109 // replace named colors
110 if (is_int(strpos($cur_par, "color")) && substr(trim($cur_val), 0, 1) == "!") {
111 $cur_val = $this->style->getColorCodeForName(substr($cur_val, 1));
112 }
113
114 if ($tag[0]["type"] == "table" && is_int(strpos($par["parameter"], "border"))) {
115 $t_border[$cur_par] = $cur_val;
116 }
117
118 if (in_array($cur_par, array("background-image", "list-style-image"))) {
119 if (is_int(strpos($cur_val, "/"))) { // external
120 $cur_val = "url('" . $cur_val . "')";
121 } else { // internal
122 if ($this->image_dir == "") {
123 $cur_val = "url('images/" . $cur_val . "')";
124 } else {
125 $cur_val = "url('" . $this->image_dir . "/" . $cur_val . "')";
126 }
127 }
128 }
129
130 if ($cur_par == "opacity") {
131 $cur_val = ((int) $cur_val) / 100;
132 }
133
134 $css .= "\t" . $cur_par . ": " . $cur_val . ";\n";
135
136 // opacity fix
137 if ($cur_par == "opacity") {
138 $css .= "\t" . '-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=' . ($cur_val * 100) . ')"' . ";\n";
139 $css .= "\t" . 'filter: alpha(opacity=' . ($cur_val * 100) . ')' . ";\n";
140 $css .= "\t" . '-moz-opacity: ' . $cur_val . ";\n";
141 }
142
143 // transform fix
144 if ($cur_par == "transform") {
145 $css .= "\t" . '-webkit-transform: ' . $cur_val . ";\n";
146 $css .= "\t" . '-moz-transform: ' . $cur_val . ";\n";
147 $css .= "\t" . '-ms-transform: ' . $cur_val . ";\n";
148 }
149
150 // transform-origin fix
151 if ($cur_par == "transform-origin") {
152 $css .= "\t" . '-webkit-transform-origin: ' . $cur_val . ";\n";
153 $css .= "\t" . '-moz-transform-origin: ' . $cur_val . ";\n";
154 $css .= "\t" . '-ms-transform-origin: ' . $cur_val . ";\n";
155 }
156
157 // save page background
158 if ($tag[0]["tag"] == "div" && $tag[0]["class"] == "Page"
159 && $cur_par == "background-color") {
160 $page_background = $cur_val;
161 }
162 }
163 $css .= "}\n";
164 $css .= "\n";
165 }
166
167 if ($page_background != "") {
168 $css .= "td.ilc_Page\n";
169 $css .= "{\n";
170 $css .= "\t" . "background-color: " . $page_background . ";\n";
171 $css .= "}\n";
172 }
173 if ($mq["id"] > 0) {
174 $css .= "}\n";
175 }
176 }
177 return $css;
178 }
179
180}
__construct(protected \ilObjStyleSheet $style, protected string $image_dir)
Definition: CSSBuilder.php:25
Class ilObjStyleSheet.