ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjStyleSheet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
5require_once "./Services/Object/classes/class.ilObject.php";
6
16{
17 public $style;
18
19 public static $num_unit = array("px", "em", "ex", "%", "pt", "pc", "in", "mm", "cm");
20 public static $num_unit_no_perc = array("px", "em", "ex", "pt", "pc", "in", "mm", "cm");
21
22 // css parameters and their attribute values, input type and group
23 public static $parameter = array(
24 "font-size" => array(
25 "values" => array("xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "smaller", "larger"),
26 "input" => "fontsize",
27 "group" => "text"),
28 "font-family" => array(
29 "values" => array(),
30 "input" => "text",
31 "group" => "text"),
32 "font-style" => array(
33 "values" => array("italic", "oblique", "normal"),
34 "input" => "select",
35 "group" => "text"),
36 "font-weight" => array(
37 "values" => array("bold", "normal", "bolder", "lighter"),
38 "input" => "select",
39 "group" => "text"),
40 "font-variant" => array(
41 "values" => array("small-caps", "normal"),
42 "input" => "select",
43 "group" => "text"),
44 "word-spacing" => array(
45 "values" => array(),
46 "input" => "numeric_no_perc",
47 "group" => "text"),
48 "letter-spacing" => array(
49 "values" => array(),
50 "input" => "numeric_no_perc",
51 "group" => "text"),
52 "text-decoration" => array(
53 "values" => array("underline", "overline", "line-through", "blink", "none"),
54 "input" => "select",
55 "group" => "text"),
56 "text-transform" => array(
57 "values" => array("capitalize", "uppercase", "lowercase", "none"),
58 "input" => "select",
59 "group" => "text"),
60 "color" => array(
61 "values" => array(),
62 "input" => "color",
63 "group" => "text"),
64 "text-indent" => array(
65 "values" => array(),
66 "input" => "numeric",
67 "group" => "text"),
68 "line-height" => array(
69 "values" => array(),
70 "input" => "numeric",
71 "group" => "text"),
72 "vertical-align" => array(
73 "values" => array("top", "middle", "bottom", "baseline", "sub", "super",
74 "text-top", "text-bottom"),
75 "input" => "select",
76 "group" => "text"),
77 "text-align" => array(
78 "values" => array("left", "center", "right", "justify"),
79 "input" => "select",
80 "group" => "text"),
81 "white-space" => array(
82 "values" => array("normal", "pre", "nowrap"),
83 "input" => "select",
84 "group" => "text"),
85 "margin" => array(
86 "values" => array(),
87 "input" => "trbl_numeric",
88 "subpar" => array("margin", "margin-top", "margin-right",
89 "margin-bottom", "margin-left"),
90 "group" => "margin_and_padding"),
91 "padding" => array(
92 "values" => array(),
93 "input" => "trbl_numeric",
94 "subpar" => array("padding", "padding-top", "padding-right",
95 "padding-bottom", "padding-left"),
96 "group" => "margin_and_padding"),
97 "border-width" => array(
98 "values" => array("thin", "medium", "thick"),
99 "input" => "border_width",
100 "subpar" => array("border-width", "border-top-width", "border-right-width",
101 "border-bottom-width", "border-left-width"),
102 "group" => "border"),
103 "border-color" => array(
104 "values" => array(),
105 "input" => "trbl_color",
106 "subpar" => array("border-color", "border-top-color", "border-right-color",
107 "border-bottom-color", "border-left-color"),
108 "group" => "border"),
109 "border-style" => array(
110 "values" => array("none", "hidden", "dotted", "dashed", "solid", "double",
111 "groove", "ridge", "inset", "outset"),
112 "input" => "border_style",
113 "subpar" => array("border-style", "border-top-style", "border-right-style",
114 "border-bottom-style", "border-left-style"),
115 "group" => "border"),
116
117 "background-color" => array(
118 "values" => array(),
119 "input" => "color",
120 "group" => "background"),
121 "background-image" => array(
122 "values" => array(),
123 "input" => "background_image",
124 "group" => "background"),
125 "background-repeat" => array(
126 "values" => array("repeat", "repeat-x", "repeat-y", "no-repeat"),
127 "input" => "select",
128 "group" => "background"),
129 "background-attachment" => array(
130 "values" => array("fixed", "scroll"),
131 "input" => "select",
132 "group" => "background"),
133 "background-position" => array(
134 "values" => array("horizontal" => array("left", "center", "right"),
135 "vertical" => array("top", "center", "bottom")),
136 "input" => "background_position",
137 "group" => "background"),
138
139 "position" => array(
140 "values" => array("absolute", "fixed", "relative", "static"),
141 "input" => "select",
142 "group" => "positioning"),
143 "top" => array(
144 "values" => array(),
145 "input" => "numeric",
146 "group" => "positioning"),
147 "bottom" => array(
148 "values" => array(),
149 "input" => "numeric",
150 "group" => "positioning"),
151 "left" => array(
152 "values" => array(),
153 "input" => "numeric",
154 "group" => "positioning"),
155 "right" => array(
156 "values" => array(),
157 "input" => "numeric",
158 "group" => "positioning"),
159 "width" => array(
160 "values" => array(),
161 "input" => "numeric",
162 "group" => "positioning"),
163 "height" => array(
164 "values" => array(),
165 "input" => "numeric",
166 "group" => "positioning"),
167 "min-height" => array(
168 "values" => array(),
169 "input" => "numeric",
170 "group" => "positioning"),
171 "float" => array(
172 "values" => array("left", "right", "none"),
173 "input" => "select",
174 "group" => "positioning"),
175 "overflow" => array(
176 "values" => array("visible", "hidden", "scroll", "auto"),
177 "input" => "select",
178 "group" => "positioning"),
179 "opacity" => array(
180 "values" => array(),
181 "input" => "percentage",
182 "group" => "special"),
183 "transform" => array(
184 "values" => array("rotate(90deg)", "rotate(180deg)", "rotate(270deg)"),
185 "input" => "select",
186 "group" => "special"),
187 "transform-origin" => array(
188 "values" => array( "horizontal" => array("left", "center", "right"),
189 "vertical" => array("top", "center", "bottom")),
190 "input" => "background_position",
191 "group" => "special"),
192 "cursor" => array(
193 "values" => array("auto", "default", "crosshair", "pointer", "move",
194 "n-resize", "ne-resize", "e-resize", "se-resize", "s-resize", "sw-resize",
195 "w-resize", "nw-resize", "text", "wait", "help"),
196 "input" => "select",
197 "group" => "special"),
198 "clear" => array(
199 "values" => array("both","left","right","none"),
200 "input" => "select",
201 "group" => "special"),
202
203 "list-style-type.ol" => array(
204 "values" => array("decimal","lower-roman","upper-roman",
205 "lower-alpha", "upper-alpha", "lower-greek", "hebrew",
206 "decimal-leading-zero", "cjk-ideographic", "hiragana",
207 "katakana", "hiragana-iroha", "katakana-iroha", "none"),
208 "input" => "select",
209 "group" => "ol"),
210 "list-style-type.ul" => array(
211 "values" => array("disc","circle","square",
212 "none"),
213 "input" => "select",
214 "group" => "ul"),
215 "list-style-image.ul" => array(
216 "values" => array(),
217 "input" => "background_image",
218 "group" => "ul"),
219 "list-style-position.ol" => array(
220 "values" => array("inside","outside"),
221 "input" => "select",
222 "group" => "ol"),
223 "list-style-position.ul" => array(
224 "values" => array("inside","outside"),
225 "input" => "select",
226 "group" => "ul"
227 ),
228 "border-collapse" => array(
229 "values" => array("collapse","separate"),
230 "input" => "select",
231 "group" => "table"
232 ),
233 "caption-side" => array(
234 "values" => array("top","bottom","left","right"),
235 "input" => "select",
236 "group" => "table"
237 )
238 );
239
240 // filter groups of properties that should only be
241 // displayed with matching tag (group -> tags)
242 public static $filtered_groups =
243 array("ol" => array("ol"), "ul" => array("ul"),
244 "table" => array("table"), "positioning" => array("h1", "h2", "h3", "div", "img", "table", "a", "figure"));
245
246 // style types and their super type
247 public static $style_super_types = array(
248 "text_block" => array("text_block", "heading1", "heading2", "heading3", "code_block"),
249 "text_inline" => array("text_inline", "sub", "sup", "code_inline"),
250 "section" => array("section"),
251 "link" => array("link"),
252 "table" => array("table", "table_cell", "table_caption"),
253 "list" => array("list_o", "list_u", "list_item"),
254 "flist" => array("flist_cont", "flist_head", "flist", "flist_li", "flist_a"),
255 "media" => array("media_cont", "media_caption", "iim", "marker"),
256 "tabs" => array("va_cntr", "va_icntr", "va_ihead", "va_iheada", "va_ihcap", "va_icont",
257 "ha_cntr", "ha_icntr", "ha_ihead", "ha_iheada", "ha_ihcap", "ha_icont", "ca_cntr", "ca_icntr", "ca_ihead", "ca_icont"),
258 "question" => array("question", "qtitle", "qanswer", "qinput", "qlinput", "qsubmit", "qfeedr", "qfeedw",
259 "qimg", "qordul", "qordli", "qimgd", "qetitem", "qetcorr", "qover"),
260 "page" => array("page_frame", "page_cont", "page_title", "page_fn",
261 "page_tnav", "page_bnav", "page_lnav", "page_rnav", "page_lnavlink", "page_rnavlink",
262 "page_lnavimage", "page_rnavimage"),
263 "glo" => array("glo_overlay", "glo_ovtitle", "glo_ovclink", "glo_ovuglink", "glo_ovuglistlink"),
264 "sco" => array("sco_title", "sco_keyw", "sco_desc", "sco_desct", "sco_obj", "sco_objt", "sco_fmess"),
265 "rte" => array("rte_menu", "rte_mlink", "rte_tree", "rte_node", "rte_tlink","rte_status",
266 "rte_tul", "rte_tli", "rte_texp", "rte_tclink", "rte_drag")
267 );
268
269 // these types are expandable, i.e. the user can define new style classes
270 public static $expandable_types = array(
271 "text_block", "text_inline", "section", "media_cont", "table", "table_cell", "flist_li", "table_caption",
272 "list_o", "list_u",
273 "va_cntr", "va_icntr", "va_ihead", "va_iheada", "va_ihcap", "va_icont",
274 "ha_cntr", "ha_icntr", "ha_ihead", "ha_iheada", "ha_ihcap", "ha_icont",
275 "ca_cntr", "ca_icntr", "ca_ihead", "ca_icont"
276 );
277
278 // these types can be hidden in the content editor
279 public static $hideable_types = array(
280 "table", "table_cell"
281 );
282
283 // tag that are used by style types
284 public static $assigned_tags = array(
285 "text_block" => "div",
286 "heading1" => "h1",
287 "heading2" => "h2",
288 "heading3" => "h3",
289 "code_block" => "pre",
290 "text_inline" => "span",
291 "code_inline" => "code",
292 "sup" => "sup",
293 "sub" => "sub",
294 "section" => "div",
295 "link" => "a",
296 "table" => "table",
297 "table_cell" => "td",
298 "table_caption" => "caption",
299 "media_cont" => "figure",
300 "media_caption" => "div",
301 "iim" => "div",
302 "marker" => "a",
303 "glo_overlay" => "div",
304 "glo_ovtitle" => "h1",
305 "glo_ovclink" => "a",
306 "glo_ovuglink" => "a",
307 "glo_ovuglistlink" => "a",
308 "sco_title" => "div",
309 "sco_keyw" => "div",
310 "sco_desc" => "div",
311 "sco_obj" => "div",
312 "sco_desct" => "div",
313 "sco_objt" => "div",
314 "sco_fmess" => "div",
315 "rte_menu" => "div",
316 "rte_mlink" => "a",
317 "rte_tree" => "div",
318 "rte_tclink" => "a",
319 "rte_drag" => "div",
320 "rte_node" => "div",
321 "rte_status" => "div",
322 "rte_tlink" => "a",
323 "rte_tul" => "div",
324 "rte_tli" => "div",
325 "rte_texp" => "a",
326 "list_o" => "ol",
327 "list_u" => "ul",
328 "list_item" => "li",
329 "flist_cont" => "div",
330 "flist_head" => "div",
331 "flist" => "ul",
332 "flist_li" => "li",
333 "flist_a" => "a",
334 "question" => "div",
335 "qtitle" => "div",
336 "qanswer" => "div",
337 "qimg" => "img",
338 "qimgd" => "a",
339 "qordul" => "ul",
340 "qordli" => "li",
341 "qetitem" => "a",
342 "qetcorr" => "span",
343 "qinput" => "input",
344 "qlinput" => "textarea",
345 "qsubmit" => "input",
346 "qfeedr" => "div",
347 "qfeedw" => "div",
348 "qover" => "div",
349 "page_frame" => "div",
350 "page_cont" => "div",
351 "page_fn" => "div",
352 "page" => "div",
353 "page_tnav" => "div",
354 "page_bnav" => "div",
355 "page_lnav" => "div",
356 "page_rnav" => "div",
357 "page_lnavlink" => "a",
358 "page_rnavlink" => "a",
359 "page_lnavimage" => "img",
360 "page_rnavimage" => "img",
361 "page_title" => "h1",
362 "va_cntr" => "div",
363 "va_icntr" => "div",
364 "va_icont" => "div",
365 "va_ihead" => "div",
366 "va_iheada" => "div",
367 "va_ihcap" => "div",
368 "ha_cntr" => "div",
369 "ha_icntr" => "div",
370 "ha_icont" => "div",
371 "ha_iheada" => "div",
372 "ha_ihcap" => "div",
373 "ha_ihead" => "div",
374 "ca_cntr" => "div",
375 "ca_icntr" => "div",
376 "ca_ihead" => "div",
377 "ca_icont" => "div"
378 );
379
380 // pseudo classes
381 public static $pseudo_classes =
382 array("a" => array("hover"), "div" => array("hover"), "img" => array("hover"));
383
384 // core styles these styles MUST exists -> see also basic_style/style.xml
385 public static $core_styles = array(
386 array("type" => "text_block", "class" => "Standard"),
387 array("type" => "text_block", "class" => "List"),
388 array("type" => "text_block", "class" => "TableContent"),
389 array("type" => "code_block", "class" => "Code"),
390 array("type" => "heading1", "class" => "Headline1"),
391 array("type" => "heading2", "class" => "Headline2"),
392 array("type" => "heading3", "class" => "Headline3"),
393 array("type" => "text_inline", "class" => "Comment"),
394 array("type" => "text_inline", "class" => "Emph"),
395 array("type" => "text_inline", "class" => "Quotation"),
396 array("type" => "text_inline", "class" => "Strong"),
397 array("type" => "text_inline", "class" => "Accent"),
398 array("type" => "text_inline", "class" => "Important"),
399 array("type" => "code_inline", "class" => "CodeInline"),
400 array("type" => "sup", "class" => "Sup"),
401 array("type" => "sub", "class" => "Sub"),
402 array("type" => "link", "class" => "IntLink"),
403 array("type" => "link", "class" => "ExtLink"),
404 array("type" => "link", "class" => "FootnoteLink"),
405 array("type" => "link", "class" => "FileLink"),
406 array("type" => "link", "class" => "GlossaryLink"),
407 array("type" => "media_cont", "class" => "MediaContainer"),
408 array("type" => "media_cont", "class" => "MediaContainerMax50"),
409 array("type" => "media_cont", "class" => "MediaContainerFull100"),
410 array("type" => "table", "class" => "StandardTable"),
411 array("type" => "media_caption", "class" => "MediaCaption"),
412 array("type" => "iim", "class" => "ContentPopup"),
413 array("type" => "marker", "class" => "Marker"),
414 array("type" => "page_frame", "class" => "PageFrame"),
415 array("type" => "page_cont", "class" => "PageContainer"),
416 array("type" => "page", "class" => "Page"),
417 array("type" => "page_tnav", "class" => "TopNavigation"),
418 array("type" => "page_bnav", "class" => "BottomNavigation"),
419 array("type" => "page_lnav", "class" => "LeftNavigation"),
420 array("type" => "page_rnav", "class" => "RightNavigation"),
421 array("type" => "page_lnavlink", "class" => "LeftNavigationLink"),
422 array("type" => "page_rnavlink", "class" => "RightNavigationLink"),
423 array("type" => "page_lnavimage", "class" => "LeftNavigationImage"),
424 array("type" => "page_rnavimage", "class" => "RightNavigationImage"),
425 array("type" => "page_fn", "class" => "Footnote"),
426 array("type" => "page_title", "class" => "PageTitle"),
427 array("type" => "glo_overlay", "class" => "GlossaryOverlay"),
428 array("type" => "glo_ovtitle", "class" => "GlossaryOvTitle"),
429 array("type" => "glo_ovclink", "class" => "GlossaryOvCloseLink"),
430 array("type" => "glo_ovuglink", "class" => "GlossaryOvUnitGloLink"),
431 array("type" => "glo_ovuglistlink", "class" => "GlossaryOvUGListLink"),
432 array("type" => "sco_title", "class" => "Title"),
433 array("type" => "sco_desc", "class" => "Description"),
434 array("type" => "sco_desct", "class" => "DescriptionTop"),
435 array("type" => "sco_keyw", "class" => "Keywords"),
436 array("type" => "sco_obj", "class" => "Objective"),
437 array("type" => "sco_objt", "class" => "ObjectiveTop"),
438 array("type" => "sco_fmess", "class" => "FinalMessage"),
439 array("type" => "rte_menu", "class" => "RTEMenu"),
440 array("type" => "rte_menu", "class" => "RTELogo"),
441 array("type" => "rte_menu", "class" => "RTELinkBar"),
442 array("type" => "rte_mlink", "class" => "RTELink"),
443 array("type" => "rte_mlink", "class" => "RTELinkDisabled"),
444 array("type" => "rte_tree", "class" => "RTETree"),
445 array("type" => "rte_node", "class" => "RTECourse"),
446 array("type" => "rte_node", "class" => "RTEChapter"),
447 array("type" => "rte_node", "class" => "RTESco"),
448 array("type" => "rte_node", "class" => "RTEAsset"),
449 array("type" => "rte_node", "class" => "RTECourseDisabled"),
450 array("type" => "rte_node", "class" => "RTEChapterDisabled"),
451 array("type" => "rte_node", "class" => "RTEScoDisabled"),
452 array("type" => "rte_node", "class" => "RTEAssetDisabled"),
453 array("type" => "rte_status", "class" => "RTEAsset"),
454 array("type" => "rte_status", "class" => "RTECompleted"),
455 array("type" => "rte_status", "class" => "RTENotAttempted"),
456 array("type" => "rte_status", "class" => "RTERunning"),
457 array("type" => "rte_status", "class" => "RTEIncomplete"),
458 array("type" => "rte_status", "class" => "RTEPassed"),
459 array("type" => "rte_status", "class" => "RTEFailed"),
460 array("type" => "rte_status", "class" => "RTEBrowsed"),
461 array("type" => "rte_tlink", "class" => "RTETreeLink"),
462 array("type" => "rte_tlink", "class" => "RTETreeLinkDisabled"),
463 array("type" => "rte_tlink", "class" => "RTETreeCurrent"),
464 array("type" => "rte_tul", "class" => "RTETreeList"),
465 array("type" => "rte_tli", "class" => "RTETreeItem"),
466 array("type" => "rte_texp", "class" => "RTETreeExpanded"),
467 array("type" => "rte_texp", "class" => "RTETreeCollapsed"),
468 array("type" => "rte_tree", "class" => "RTETreeControl"),
469 array("type" => "rte_tclink", "class" => "RTETreeControlLink"),
470 array("type" => "rte_drag", "class" => "RTEDragBar"),
471 array("type" => "list_o", "class" => "NumberedList"),
472 array("type" => "list_u", "class" => "BulletedList"),
473 array("type" => "list_item", "class" => "StandardListItem"),
474 array("type" => "question", "class" => "Standard"),
475 array("type" => "question", "class" => "SingleChoice"),
476 array("type" => "question", "class" => "MultipleChoice"),
477 array("type" => "question", "class" => "TextQuestion"),
478 array("type" => "question", "class" => "OrderingQuestion"),
479 array("type" => "question", "class" => "MatchingQuestion"),
480 array("type" => "question", "class" => "ImagemapQuestion"),
481 array("type" => "question", "class" => "ErrorText"),
482 array("type" => "question", "class" => "TextSubset"),
483 array("type" => "question", "class" => "ClozeTest"),
484 array("type" => "qtitle", "class" => "Title"),
485 array("type" => "qanswer", "class" => "Answer"),
486 array("type" => "qimg", "class" => "QuestionImage"),
487 array("type" => "qimgd", "class" => "ImageDetailsLink"),
488 array("type" => "qordul", "class" => "OrderList"),
489 array("type" => "qordli", "class" => "OrderListItem"),
490 array("type" => "qordul", "class" => "OrderListHorizontal"),
491 array("type" => "qordli", "class" => "OrderListItemHorizontal"),
492 array("type" => "qetitem", "class" => "ErrorTextItem"),
493 array("type" => "qetitem", "class" => "ErrorTextSelected"),
494 array("type" => "qetcorr", "class" => "ErrorTextCorrected"),
495 array("type" => "qinput", "class" => "TextInput"),
496 array("type" => "qlinput", "class" => "LongTextInput"),
497 array("type" => "qsubmit", "class" => "Submit"),
498 array("type" => "qfeedr", "class" => "FeedbackRight"),
499 array("type" => "qfeedw", "class" => "FeedbackWrong"),
500 array("type" => "qover", "class" => "Correct"),
501 array("type" => "qover", "class" => "Inorrect"),
502 array("type" => "qover", "class" => "StatusMessage"),
503 array("type" => "qover", "class" => "WrongAnswersMessage"),
504 array("type" => "flist_cont", "class" => "FileListContainer"),
505 array("type" => "flist_head", "class" => "FileListHeading"),
506 array("type" => "flist", "class" => "FileList"),
507 array("type" => "flist_li", "class" => "FileListItem"),
508 array("type" => "flist_a", "class" => "FileListItemLink")
509 );
510
511 public static $templates = array(
512 "table" => array(
513 "table" => "table",
514 "caption" => "table_caption",
515 "row_head" => "table_cell",
516 "row_foot" => "table_cell",
517 "col_head" => "table_cell",
518 "col_foot" => "table_cell",
519 "odd_row" => "table_cell",
520 "even_row" => "table_cell",
521 "odd_col" => "table_cell",
522 "even_col" => "table_cell"),
523 "vaccordion" => array(
524 "va_cntr" => "va_cntr",
525 "va_icntr" => "va_icntr",
526 "va_ihead" => "va_ihead",
527 "va_iheada" => "va_iheada",
528 "va_ihcap" => "va_ihcap",
529 "va_icont" => "va_icont"
530 ),
531 "haccordion" => array(
532 "ha_cntr" => "ha_cntr",
533 "ha_icntr" => "ha_icntr",
534 "ha_ihead" => "ha_ihead",
535 "ha_iheada" => "ha_iheada",
536 "ha_ihcap" => "ha_ihcap",
537 "ha_icont" => "ha_icont"
538 ),
539 "carousel" => array(
540 "ca_cntr" => "ca_cntr",
541 "ca_icntr" => "ca_icntr",
542 "ca_ihead" => "ca_ihead",
543 "ca_icont" => "ca_icont"
544 )
545 );
546
547 // basic style xml file, image directory and dom
548 protected static $basic_style_file = "./libs/ilias/Style/basic_style/style.xml";
549 protected static $basic_style_zip = "./libs/ilias/Style/basic_style/style.zip";
550 protected static $basic_style_image_dir = "./libs/ilias/Style/basic_style/images";
551 protected static $basic_style_dom;
552
559 public function __construct($a_id = 0, $a_call_by_reference = false)
560 {
561 global $DIC;
562
563 $this->db = $DIC->database();
564 $this->lng = $DIC->language();
565 $this->type = "sty";
566 $this->style = array();
567 if ($a_call_by_reference) {
568 $this->ilias->raiseError("Can't instantiate style object via reference id.", $this->ilias->error_obj->FATAL);
569 }
570
571 parent::__construct($a_id, false);
572 }
573
579 public static function getBasicZipPath() : string
580 {
582 }
583
587 public function setRefId($a_ref_id)
588 {
589 $this->ilias->raiseError("Operation ilObjStyleSheet::setRefId() not allowed.", $this->ilias->error_obj->FATAL);
590 }
591
595 public function getRefId()
596 {
597 return "";
598 //$this->ilias->raiseError("Operation ilObjStyleSheet::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
599 }
600
604 public function putInTree($a_parent_ref)
605 {
606 $this->ilias->raiseError("Operation ilObjStyleSheet::putInTree() not allowed.", $this->ilias->error_obj->FATAL);
607 }
608
612 public function createReference()
613 {
614 $this->ilias->raiseError("Operation ilObjStyleSheet::createReference() not allowed.", $this->ilias->error_obj->FATAL);
615 }
616
620 public function setUpToDate($a_up_to_date = true)
621 {
622 $this->up_to_date = $a_up_to_date;
623 }
624
628 public function getUpToDate()
629 {
630 return $this->up_to_date;
631 }
632
636 public function setScope($a_scope)
637 {
638 $this->scope = $a_scope;
639 }
640
644 public function getScope()
645 {
646 return $this->scope;
647 }
648
652 public static function _writeUpToDate($a_id, $a_up_to_date)
653 {
654 global $DIC;
655
656 $ilDB = $DIC->database();
657
658 $q = "UPDATE style_data SET uptodate = " .
659 $ilDB->quote((int) $a_up_to_date, "integer") .
660 " WHERE id = " . $ilDB->quote($a_id, "integer");
661 $ilDB->manipulate($q);
662 }
663
667 public static function _lookupUpToDate($a_id)
668 {
669 global $DIC;
670
671 $ilDB = $DIC->database();
672
673 $q = "SELECT uptodate FROM style_data " .
674 " WHERE id = " . $ilDB->quote($a_id, "integer");
675 $res = $ilDB->query($q);
676 $sty = $ilDB->fetchAssoc($res);
677
678 return (boolean) $sty["uptodate"];
679 }
680
684 public static function _writeStandard($a_id, $a_std)
685 {
686 global $DIC;
687
688 $ilDB = $DIC->database();
689
690 $q = "UPDATE style_data SET standard = " .
691 $ilDB->quote((int) $a_std, "integer") .
692 " WHERE id = " . $ilDB->quote($a_id, "integer");
693 $ilDB->manipulate($q);
694 }
695
699 public static function _writeScope($a_id, $a_scope)
700 {
701 global $DIC;
702
703 $ilDB = $DIC->database();
704
705 $q = "UPDATE style_data SET category = " .
706 $ilDB->quote((int) $a_scope, "integer") .
707 " WHERE id = " . $ilDB->quote($a_id, "integer");
708 $ilDB->manipulate($q);
709 }
710
714 public static function _lookupStandard($a_id)
715 {
716 global $DIC;
717
718 $ilDB = $DIC->database();
719
720 $q = "SELECT * FROM style_data " .
721 " WHERE id = " . $ilDB->quote($a_id, "integer");
722 $res = $ilDB->query($q);
723 $sty = $ilDB->fetchAssoc($res);
724
725 return (boolean) $sty["standard"];
726 }
727
731 public static function _writeActive($a_id, $a_active)
732 {
733 global $DIC;
734
735 $ilDB = $DIC->database();
736
737 $q = "UPDATE style_data SET active = " .
738 $ilDB->quote((int) $a_active, "integer") .
739 " WHERE id = " . $ilDB->quote($a_id, "integer");
740 $ilDB->manipulate($q);
741 }
742
746 public static function _lookupActive($a_id)
747 {
748 global $DIC;
749
750 $ilDB = $DIC->database();
751
752 $q = "SELECT * FROM style_data " .
753 " WHERE id = " . $ilDB->quote($a_id, "integer");
754 $res = $ilDB->query($q);
755 $sty = $ilDB->fetchAssoc($res);
756
757 return (boolean) $sty["active"];
758 }
759
763 public static function _getStandardStyles(
764 $a_exclude_default_style = false,
765 $a_include_deactivated = false,
766 $a_scope = 0
767 ) {
768 global $DIC;
769
770 $ilDB = $DIC->database();
771 $ilSetting = $DIC->settings();
772 $tree = $DIC->repositoryTree();
773
774 $default_style = $ilSetting->get("default_content_style_id");
775
776 $and_str = "";
777 if (!$a_include_deactivated) {
778 $and_str = " AND active = 1";
779 }
780
781 $q = "SELECT * FROM style_data " .
782 " WHERE standard = 1" . $and_str;
783 $res = $ilDB->query($q);
784 $styles = array();
785 while ($sty = $ilDB->fetchAssoc($res)) {
786 if (!$a_exclude_default_style || $default_style != $sty["id"]) {
787 // check scope
788 if ($a_scope > 0 && $sty["category"] > 0) {
789 if ($tree->isInTree($sty["category"]) &&
790 $tree->isInTree($a_scope)) {
791 $path = $tree->getPathId($a_scope);
792 if (!in_array($sty["category"], $path)) {
793 continue;
794 }
795 }
796 }
797 $styles[$sty["id"]] = ilObject::_lookupTitle($sty["id"]);
798 }
799 }
800
801 return $styles;
802 }
803
804
809 public static function _getClonableContentStyles()
810 {
811 global $DIC;
812
813 $ilAccess = $DIC->access();
814 $ilDB = $DIC->database();
815
816 $clonable_styles = array();
817
818 $q = "SELECT * FROM style_data";
819 $style_set = $ilDB->query($q);
820 while ($style_rec = $ilDB->fetchAssoc($style_set)) {
821 $clonable = false;
822 if ($style_rec["standard"] == 1) {
823 if ($style_rec["active"] == 1) {
824 $clonable = true;
825 }
826 } else {
827 include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
828 $obj_ids = ilObjContentObject::_lookupContObjIdByStyleId($style_rec["id"]);
829 if (count($obj_ids) == 0) {
830 $obj_ids = self::lookupObjectForStyle($style_rec["id"]);
831 }
832 foreach ($obj_ids as $id) {
834 foreach ($ref as $ref_id) {
835 if ($ilAccess->checkAccess("write", "", $ref_id)) {
836 $clonable = true;
837 }
838 }
839 }
840 }
841 if ($clonable) {
842 $clonable_styles[$style_rec["id"]] =
843 ilObject::_lookupTitle($style_rec["id"]);
844 }
845 }
846
847 asort($clonable_styles);
848
849 return $clonable_styles;
850 }
851
855 public function assignMetaData(&$a_meta_data)
856 {
857 $this->meta_data = $a_meta_data;
858 }
859
863 public static function _getBasicStyleDom()
864 {
865 if (!is_object(self::$basic_style_dom)) {
866 self::$basic_style_dom = new DOMDocument();
867 self::$basic_style_dom->load(self::$basic_style_file);
868 }
869
871 }
872
876 public function &getMetaData()
877 {
878 return $this->meta_data;
879 }
880
885 public static function getBasicImageDir()
886 {
888 }
889
890
894 public function create($a_from_style = 0, $a_import_mode = false)
895 {
897
898 parent::create();
899
900 if ($a_from_style == 0) {
901 if (!$a_import_mode) {
902 // copy styles from basic style
903 $this->createFromXMLFile(self::$basic_style_file, true);
904
905 // copy images from basic style
906 $this->createImagesDirectory();
908 self::$basic_style_image_dir,
909 $this->getImagesDirectory()
910 );
911 } else {
912 // add style_data record
913 $q = "INSERT INTO style_data (id, uptodate, category) VALUES " .
914 "(" . $ilDB->quote($this->getId(), "integer") . ", 0," .
915 $ilDB->quote((int) $this->getScope(), "integer") . ")";
916 $ilDB->manipulate($q);
918 }
919 } else {
920 // get style parameter records
921 $def = array();
922 $q = "SELECT * FROM style_parameter WHERE style_id = " .
923 $ilDB->quote($a_from_style, "integer");
924 $par_set = $ilDB->query($q);
925 while ($par_rec = $ilDB->fetchAssoc($par_set)) {
926 $def[] = array("tag" => $par_rec["tag"], "class" => $par_rec["class"],
927 "parameter" => $par_rec["parameter"], "value" => $par_rec["value"],
928 "type" => $par_rec["type"], "mq_id" => $par_rec["mq_id"], "custom" => $par_rec["custom"]);
929 }
930
931 // get style characteristics records
932 $chars = array();
933 $q = "SELECT * FROM style_char WHERE style_id = " .
934 $ilDB->quote($a_from_style, "integer");
935 $par_set = $ilDB->query($q);
936 while ($par_rec = $ilDB->fetchAssoc($par_set)) {
937 $chars[] = array("type" => $par_rec["type"], "characteristic" => $par_rec["characteristic"]);
938 }
939
940
941 // copy media queries
942 $from_style = new ilObjStyleSheet($a_from_style);
943 $mqs = $from_style->getMediaQueries();
944 $mq_mapping = array();
945 foreach ($mqs as $mq) {
946 $nid = $this->addMediaQuery($mq["mquery"]);
947 $mq_mapping[$mq["id"]] = $nid;
948 }
949
950 // default style settings
951 foreach ($def as $sty) {
952 $id = $ilDB->nextId("style_parameter");
953 $q = "INSERT INTO style_parameter (id, style_id, tag, class, parameter, value, type, mq_id, custom) VALUES " .
954 "(" .
955 $ilDB->quote($id, "integer") . "," .
956 $ilDB->quote($this->getId(), "integer") . "," .
957 $ilDB->quote($sty["tag"], "text") . "," .
958 $ilDB->quote($sty["class"], "text") . "," .
959 $ilDB->quote($sty["parameter"], "text") . "," .
960 $ilDB->quote($sty["value"], "text") . "," .
961 $ilDB->quote($sty["type"], "text") . "," .
962 $ilDB->quote((int) $mq_mapping[$sty["mq_id"]], "integer") . "," .
963 $ilDB->quote($sty["custom"], "integer") .
964 ")";
965 $ilDB->manipulate($q);
966 }
967
968 // insert style characteristics
969 foreach ($chars as $char) {
970 $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES " .
971 "(" . $ilDB->quote($this->getId(), "integer") . "," .
972 $ilDB->quote($char["type"], "text") . "," .
973 $ilDB->quote($char["characteristic"], "text") . ")";
974 $ilDB->manipulate($q);
975 }
976
977 // add style_data record
978 $q = "INSERT INTO style_data (id, uptodate, category) VALUES " .
979 "(" . $ilDB->quote($this->getId(), "integer") . ", 0," .
980 $ilDB->quote((int) $this->getScope(), "integer") . ")";
981 $ilDB->manipulate($q);
982
983 // copy images
984 $this->createImagesDirectory();
986 $from_style->getImagesDirectory(),
987 $this->getImagesDirectory()
988 );
989
990 // copy colors
991 $colors = $from_style->getColors();
992 foreach ($colors as $c) {
993 $this->addColor($c["name"], $c["code"]);
994 }
995
996 // copy templates
998 foreach ($tcts as $tct => $v) {
999 $templates = $from_style->getTemplates($tct);
1000 foreach ($templates as $t) {
1001 $this->addTemplate($tct, $t["name"], $t["classes"]);
1002 }
1003 }
1004 }
1005
1006 $this->read();
1007 if (!$a_import_mode) {
1008 $this->writeCSSFile();
1009 }
1010 }
1011
1015 public function deleteCharacteristic($a_type, $a_tag, $a_class)
1016 {
1017 $ilDB = $this->db;
1018
1019 // check, if characteristic is not a core style
1021 if (empty($core_styles[$a_type . "." . $a_tag . "." . $a_class])) {
1022 // delete characteristic record
1023 $st = $ilDB->manipulateF(
1024 "DELETE FROM style_char WHERE style_id = %s AND type = %s AND characteristic = %s",
1025 array("integer", "text", "text"),
1026 array($this->getId(), $a_type, $a_class)
1027 );
1028
1029 // delete parameter records
1030 $st = $ilDB->manipulateF(
1031 "DELETE FROM style_parameter WHERE style_id = %s AND tag = %s AND type = %s AND class = %s",
1032 array("integer", "text", "text", "text"),
1033 array($this->getId(), $a_tag, $a_type, $a_class)
1034 );
1035 }
1036
1037 $this->setUpToDate(false);
1038 $this->_writeUpToDate($this->getId(), false);
1039 }
1040
1044 public function characteristicExists($a_char, $a_style_type)
1045 {
1046 $ilDB = $this->db;
1047
1048 $set = $ilDB->queryF(
1049 "SELECT style_id FROM style_char WHERE style_id = %s AND characteristic = %s AND type = %s",
1050 array("integer", "text", "text"),
1051 array($this->getId(), $a_char, $a_style_type)
1052 );
1053 if ($rec = $ilDB->fetchAssoc($set)) {
1054 return true;
1055 }
1056 return false;
1057 }
1058
1062 public function addCharacteristic($a_type, $a_char, $a_hidden = false)
1063 {
1064 $ilDB = $this->db;
1065
1066 // delete characteristic record
1067 $ilDB->manipulateF(
1068 "INSERT INTO style_char (style_id, type, characteristic, hide)" .
1069 " VALUES (%s,%s,%s,%s) ",
1070 array("integer", "text", "text", "integer"),
1071 array($this->getId(), $a_type, $a_char, $a_hidden)
1072 );
1073
1074 $this->setUpToDate(false);
1075 $this->_writeUpToDate($this->getId(), false);
1076 }
1077
1084 public function copyCharacteristic(
1085 $a_from_style_id,
1086 $a_from_type,
1087 $a_from_char,
1088 $a_to_char
1089 ) {
1090 $ilDB = $this->db;
1091
1092 if (!$this->characteristicExists($a_to_char, $a_from_type)) {
1093 $this->addCharacteristic($a_from_type, $a_to_char);
1094 }
1095 $this->deleteStyleParOfChar($a_from_type, $a_to_char);
1096
1097 $from_style = new ilObjStyleSheet($a_from_style_id);
1098
1099 // todo fix using mq_id
1100 $pars = $from_style->getParametersOfClass($a_from_type, $a_from_char);
1101
1102 $colors = array();
1103 foreach ($pars as $p => $v) {
1104 if (substr($v, 0, 1) == "!") {
1105 $colors[] = substr($v, 1);
1106 }
1107 $this->replaceStylePar(
1108 ilObjStyleSheet::_determineTag($a_from_type),
1109 $a_to_char,
1110 $p,
1111 $v,
1112 $a_from_type
1113 );
1114 }
1115
1116 // copy colors
1117 foreach ($colors as $c) {
1118 if (!$this->colorExists($c)) {
1119 $this->addColor($c, $from_style->getColorCodeForName($c));
1120 }
1121 }
1122 }
1123
1127 public function getCharacteristics($a_type = "", $a_no_hidden = false, $a_include_core = true)
1128 {
1129 $chars = array();
1130
1131 if ($a_type == "") {
1132 $chars = $this->chars;
1133 }
1134 if (is_array($this->chars_by_type[$a_type])) {
1135 foreach ($this->chars_by_type[$a_type] as $c) {
1136 if ($a_include_core || !self::isCoreStyle($a_type, $c)) {
1137 $chars[] = $c;
1138 }
1139 }
1140 }
1141
1142 if ($a_no_hidden) {
1143 foreach ($chars as $k => $char) {
1144 if ($a_type == "" && $this->hidden_chars[$char["type"] . ":" . $char["class"]]) {
1145 unset($chars[$k]);
1146 } elseif ($this->hidden_chars[$a_type . ":" . $char]) {
1147 unset($chars[$k]);
1148 }
1149 }
1150 }
1151
1152 return $chars;
1153 }
1154
1158 public function setCharacteristics($a_chars)
1159 {
1160 $this->chars = $a_chars;
1161 // $this->chars_by_type[$a_type];
1162 }
1163
1167 public function saveHideStatus($a_type, $a_char, $a_hide)
1168 {
1169 $ilDB = $this->db;
1170
1171 $ilDB->manipulate(
1172 "UPDATE style_char SET " .
1173 " hide = " . $ilDB->quote((int) $a_hide, "integer") .
1174 " WHERE style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
1175 " type = " . $ilDB->quote($a_type, "text") . " AND " .
1176 " characteristic = " . $ilDB->quote($a_char, "text")
1177 );
1178 }
1179
1183 public function getHideStatus($a_type, $a_char)
1184 {
1185 $ilDB = $this->db;
1186
1187 $set = $ilDB->query(
1188 "SELECT hide FROM style_char " .
1189 " WHERE style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
1190 " type = " . $ilDB->quote($a_type, "text") . " AND " .
1191 " characteristic = " . $ilDB->quote($a_char, "text")
1192 );
1193 $rec = $ilDB->fetchAssoc($set);
1194
1195 return $rec["hide"];
1196 }
1197
1204 public function ilClone()
1205 {
1206 $lng = $this->lng;
1207
1208 $lng->loadLanguageModule("style");
1209
1210 $new_obj = new ilObjStyleSheet();
1211 $new_obj->setTitle($this->getTitle() . " (" . $lng->txt("sty_acopy") . ")");
1212 $new_obj->setType($this->getType());
1213 $new_obj->setDescription($this->getDescription());
1214 $new_obj->create($this->getId());
1215
1216 $new_obj->writeStyleSetting(
1217 "disable_auto_margins",
1218 $this->lookupStyleSetting("disable_auto_margins")
1219 );
1220
1221 return $new_obj->getId();
1222 }
1223
1227 public function copyImagesToDir($a_target)
1228 {
1229 ilUtil::rCopy($this->getImagesDirectory(), $a_target);
1230 }
1231
1241 public function addParameter($a_tag, $a_par, $a_type, $a_mq_id = 0, $a_custom = false)
1242 {
1243 $ilDB = $this->db;
1244
1245 $avail_params = $this->getAvailableParameters();
1246 $tag = explode(".", $a_tag);
1247 $value = $avail_params[$a_par][0];
1248 $id = $ilDB->nextId("style_parameter");
1249 $q = "INSERT INTO style_parameter (id,style_id, type, tag, class, parameter, value, mq_id, custom) VALUES " .
1250 "(" .
1251 $ilDB->quote($id, "integer") . "," .
1252 $ilDB->quote($this->getId(), "integer") . "," .
1253 $ilDB->quote($a_type, "text") . "," .
1254 $ilDB->quote($tag[0], "text") . "," .
1255 $ilDB->quote($tag[1], "text") . "," .
1256 $ilDB->quote($a_par, "text") . "," .
1257 $ilDB->quote($value, "text") . "," .
1258 $ilDB->quote($a_mq_id, "integer") . "," .
1259 $ilDB->quote($a_custom, "integer") .
1260 ")";
1261 $ilDB->manipulate($q);
1262 $this->read();
1263 $this->writeCSSFile();
1264 }
1265
1270 public function createImagesDirectory()
1271 {
1273 }
1274
1279 public static function _createImagesDirectory($a_style_id)
1280 {
1281 global $DIC;
1282
1283 $ilErr = $DIC["ilErr"];
1284
1285 $sty_data_dir = ilUtil::getWebspaceDir() . "/sty";
1286 ilUtil::makeDir($sty_data_dir);
1287 if (!is_writable($sty_data_dir)) {
1288 $ilErr->raiseError("Style data directory (" . $sty_data_dir
1289 . ") not writeable.", $ilErr->FATAL);
1290 }
1291
1292 $style_dir = $sty_data_dir . "/sty_" . $a_style_id;
1293 ilUtil::makeDir($style_dir);
1294 if (!@is_dir($style_dir)) {
1295 $ilErr->raiseError("Creation of style directory failed (" .
1296 $style_dir . ").", $ilErr->FATAL);
1297 }
1298
1299 // create images subdirectory
1300 $im_dir = $style_dir . "/images";
1301 ilUtil::makeDir($im_dir);
1302 if (!@is_dir($im_dir)) {
1303 $ilErr->raiseError("Creation of Import Directory failed (" .
1304 $im_dir . ").", $ilErr->FATAL);
1305 }
1306
1307 // create thumbnails directory
1308 $thumb_dir = $style_dir . "/images/thumbnails";
1309 ilUtil::makeDir($thumb_dir);
1310 if (!@is_dir($thumb_dir)) {
1311 $ilErr->raiseError("Creation of Import Directory failed (" .
1312 $thumb_dir . ").", $ilErr->FATAL);
1313 }
1314 }
1315
1319 public function getImagesDirectory()
1320 {
1322 }
1323
1327 public static function _getImagesDirectory($a_style_id)
1328 {
1329 return ilUtil::getWebspaceDir() . "/sty/sty_" . $a_style_id .
1330 "/images";
1331 }
1332
1336 public function getThumbnailsDirectory()
1337 {
1338 return $this->getImagesDirectory() .
1339 "/thumbnails";
1340 }
1341
1345 public function getImages()
1346 {
1347 $dir = $this->getImagesDirectory();
1348 $images = array();
1349 if (is_dir($dir)) {
1350 $entries = ilUtil::getDir($dir);
1351 foreach ($entries as $entry) {
1352 if (substr($entry["entry"], 0, 1) == ".") {
1353 continue;
1354 }
1355 if ($entry["type"] != "dir") {
1356 $images[] = $entry;
1357 }
1358 }
1359 }
1360
1361 return $images;
1362 }
1363
1367 public function uploadImage($a_file)
1368 {
1369 $this->createImagesDirectory();
1371 $a_file["tmp_name"],
1372 $a_file["name"],
1373 $this->getImagesDirectory() . "/" . $a_file["name"]
1374 );
1376 $this->getImagesDirectory() . "/" . $a_file["name"],
1377 $this->getThumbnailsDirectory() . "/" . $a_file["name"],
1378 75,
1379 75
1380 );
1381 }
1382
1386 public function deleteImage($a_file)
1387 {
1388 if (is_file($this->getImagesDirectory() . "/" . $a_file)) {
1389 unlink($this->getImagesDirectory() . "/" . $a_file);
1390 }
1391 if (is_file($this->getThumbnailsDirectory() . "/" . $a_file)) {
1392 unlink($this->getThumbnailsDirectory() . "/" . $a_file);
1393 }
1394 }
1395
1401 public function deleteParameter($a_id)
1402 {
1403 $ilDB = $this->db;
1404
1405 $q = "DELETE FROM style_parameter WHERE id = " .
1406 $ilDB->quote($a_id, "integer");
1407 $ilDB->query($q);
1408 }
1409
1419 public function deleteStylePar($a_tag, $a_class, $a_par, $a_type, $a_mq_id = 0, $a_custom = false)
1420 {
1421 $ilDB = $this->db;
1422
1423 $q = "DELETE FROM style_parameter WHERE " .
1424 " style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
1425 " tag = " . $ilDB->quote($a_tag, "text") . " AND " .
1426 " class = " . $ilDB->quote($a_class, "text") . " AND " .
1427 " mq_id = " . $ilDB->quote($a_mq_id, "integer") . " AND " .
1428 " custom = " . $ilDB->quote($a_custom, "integer") . " AND " .
1429 " " . $ilDB->equals("type", $a_type, "text", true) . " AND " .
1430 " parameter = " . $ilDB->quote($a_par, "text");
1431
1432 $ilDB->manipulate($q);
1433 }
1434
1444 public function deleteCustomStylePars($a_tag, $a_class, $a_type, $a_mq_id = 0)
1445 {
1446 $ilDB = $this->db;
1447
1448 $q = "DELETE FROM style_parameter WHERE " .
1449 " style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
1450 " tag = " . $ilDB->quote($a_tag, "text") . " AND " .
1451 " class = " . $ilDB->quote($a_class, "text") . " AND " .
1452 " mq_id = " . $ilDB->quote($a_mq_id, "integer") . " AND " .
1453 " custom = " . $ilDB->quote(1, "integer") . " AND " .
1454 " " . $ilDB->equals("type", $a_type, "text", true);
1455
1456 $ilDB->manipulate($q);
1457 }
1458
1467 public function deleteStyleParOfChar($a_type, $a_class)
1468 {
1469 $ilDB = $this->db;
1470
1471 $q = "DELETE FROM style_parameter WHERE " .
1472 " style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
1473 " class = " . $ilDB->quote($a_class, "text") . " AND " .
1474 " " . $ilDB->equals("type", $a_type, "text", true);
1475
1476 $ilDB->manipulate($q);
1477 }
1478
1479
1483 public function delete()
1484 {
1485 $ilDB = $this->db;
1486
1487 // delete object
1488 parent::delete();
1489
1490 // check whether this style is global default
1491 $def_style = $this->ilias->getSetting("default_content_style_id");
1492 if ($def_style == $this->getId()) {
1493 $this->ilias->deleteSetting("default_content_style_id");
1494 }
1495
1496 // check whether this style is global fixed
1497 $fixed_style = $this->ilias->getSetting("fixed_content_style_id");
1498 if ($fixed_style == $this->getId()) {
1499 $this->ilias->deleteSetting("fixed_content_style_id");
1500 }
1501
1502 // delete style parameter
1503 $q = "DELETE FROM style_parameter WHERE style_id = " .
1504 $ilDB->quote($this->getId(), "integer");
1505 $ilDB->manipulate($q);
1506
1507 // delete style file
1508 $css_file_name = ilUtil::getWebspaceDir() . "/css/style_" . $this->getId() . ".css";
1509 if (is_file($css_file_name)) {
1510 unlink($css_file_name);
1511 }
1512
1513 // delete media queries
1514 $ilDB->manipulate(
1515 "DELETE FROM sty_media_query WHERE " .
1516 " style_id = " . $ilDB->quote($this->getId(), "integer")
1517 );
1518
1519 // delete entries in learning modules
1520 include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
1522
1523 // delete style data record
1524 $q = "DELETE FROM style_data WHERE id = " .
1525 $ilDB->quote($this->getId(), "integer");
1526 $ilDB->manipulate($q);
1527 }
1528
1529
1533 public function read()
1534 {
1535 $ilDB = $this->db;
1536
1537 parent::read();
1538
1539 $q = "SELECT * FROM style_parameter WHERE style_id = " .
1540 $ilDB->quote($this->getId(), "integer") . " ORDER BY tag, class, type, mq_id ";
1541 $style_set = $ilDB->query($q);
1542 $ctag = "";
1543 $cclass = "";
1544 $ctype = "";
1545 $cmq_id = 0;
1546 $this->style = array();
1547 // workaround for bug #17586, see also http://stackoverflow.com/questions/3066356/multiple-css-classes-properties-overlapping-based-on-the-order-defined
1548 // e.g. ha_iheada must be written after ha_ihead, since they are acting on the same dom node
1549 // styles that must be added at the end
1550 $this->end_styles = array();
1551 while ($style_rec = $ilDB->fetchAssoc($style_set)) {
1552 if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass
1553 || $style_rec["type"] != $ctype || $style_rec["mq_id"] != $cmq_id) {
1554 // add current tag array to style array
1555 if (is_array($tag)) {
1556 if (in_array($ctype, array("ha_iheada", "va_iheada"))) {
1557 $this->end_styles[] = $tag;
1558 } else {
1559 $this->style[] = $tag;
1560 }
1561 }
1562 $tag = array();
1563 }
1564 $ctag = $style_rec["tag"];
1565 $cclass = $style_rec["class"];
1566 $ctype = $style_rec["type"];
1567 $cmq_id = $style_rec["mq_id"];
1568 $tag[] = $style_rec;
1569 // added $cmq_id
1570 $this->style_class[$ctype][$cclass][$cmq_id][$style_rec["parameter"]] = $style_rec["value"];
1571 }
1572 if (is_array($tag)) {
1573 $this->style[] = $tag;
1574 }
1575 foreach ($this->end_styles as $s) {
1576 $this->style[] = $s;
1577 }
1578 //var_dump($this->style_class);
1579 $q = "SELECT * FROM style_data WHERE id = " .
1580 $ilDB->quote($this->getId(), "integer");
1581 $res = $ilDB->query($q);
1582 $sty = $ilDB->fetchAssoc($res);
1583 $this->setUpToDate((boolean) $sty["uptodate"]);
1584 $this->setScope($sty["category"]);
1585
1586 // get style characteristics records
1587 $this->chars = array();
1588 $this->chars_by_type = array();
1589 $q = "SELECT * FROM style_char WHERE style_id = " .
1590 $ilDB->quote($this->getId(), "integer") .
1591 " ORDER BY type ASC, characteristic ASC";
1592 $par_set = $ilDB->query($q);
1593 while ($par_rec = $ilDB->fetchAssoc($par_set)) {
1594 $this->chars[] = array("type" => $par_rec["type"], "class" => $par_rec["characteristic"], "hide" => $par_rec["hide"]);
1595 $this->chars_by_type[$par_rec["type"]][] = $par_rec["characteristic"];
1596 if ($par_rec["hide"]) {
1597 $this->hidden_chars[$par_rec["type"] . ":" . $par_rec["characteristic"]] = true;
1598 }
1599 }
1600 // var_dump($this->style); exit;
1601 }
1602
1606 public function writeCSSFile($a_target_file = "", $a_image_dir = "")
1607 {
1608 $style = $this->getStyle();
1609
1610 if (!is_dir(ilUtil::getWebspaceDir() . "/css")) {
1612 }
1613
1614 if ($a_target_file == "") {
1615 $css_file_name = ilUtil::getWebspaceDir() . "/css/style_" . $this->getId() . ".css";
1616 } else {
1617 $css_file_name = $a_target_file;
1618 }
1619 $css_file = fopen($css_file_name, "w");
1620
1621 $page_background = "";
1622
1623 $mqs = array(array("mquery" => "", "id" => 0));
1624 foreach ($this->getMediaQueries() as $mq) {
1625 $mqs[] = $mq;
1626 }
1627
1628 // iterate all media queries
1629 foreach ($mqs as $mq) {
1630 if ($mq["id"] > 0) {
1631 fwrite($css_file, "@media " . $mq["mquery"] . " {\n");
1632 }
1633 reset($style);
1634 foreach ($style as $tag) {
1635 if ($tag[0]["mq_id"] != $mq["id"]) {
1636 continue;
1637 }
1638 fwrite($css_file, $tag[0]["tag"] . ".ilc_" . $tag[0]["type"] . "_" . $tag[0]["class"] . "\n");
1639 // echo "<br>";
1640 // var_dump($tag[0]["type"]);
1641 if ($tag[0]["tag"] == "td") {
1642 fwrite($css_file, ",th" . ".ilc_" . $tag[0]["type"] . "_" . $tag[0]["class"] . "\n");
1643 }
1644 if (in_array($tag[0]["tag"], array("h1", "h2", "h3"))) {
1645 fwrite($css_file, ",div.ilc_text_block_" . $tag[0]["class"] . "\n");
1646 fwrite($css_file, ",html.il-no-tiny-bg body#tinymce.ilc_text_block_" . $tag[0]["class"] . "\n");
1647 }
1648 if ($tag[0]["type"] == "section") { // sections can use a tags, if links are used
1649 fwrite($css_file, ",a.ilc_" . $tag[0]["type"] . "_" . $tag[0]["class"] . "\n");
1650 }
1651 if ($tag[0]["type"] == "text_block") {
1652 fwrite($css_file, ",html.il-no-tiny-bg body#tinymce.ilc_text_block_" . $tag[0]["class"] . "\n");
1653 }
1654 fwrite($css_file, "{\n");
1655
1656 // collect table border attributes
1657 $t_border = array();
1658
1659 foreach ($tag as $par) {
1660 $cur_par = $par["parameter"];
1661 $cur_val = $par["value"];
1662
1663 // replace named colors
1664 if (is_int(strpos($cur_par, "color")) && substr(trim($cur_val), 0, 1) == "!") {
1665 $cur_val = $this->getColorCodeForName(substr($cur_val, 1));
1666 }
1667
1668 if ($tag[0]["type"] == "table" && is_int(strpos($par["parameter"], "border"))) {
1669 $t_border[$cur_par] = $cur_val;
1670 }
1671
1672 if (in_array($cur_par, array("background-image", "list-style-image"))) {
1673 if (is_int(strpos($cur_val, "/"))) { // external
1674 $cur_val = "url(" . $cur_val . ")";
1675 } else { // internal
1676 if ($a_image_dir == "") {
1677 $cur_val = "url(../sty/sty_" . $this->getId() . "/images/" . $cur_val . ")";
1678 } else {
1679 $cur_val = "url(" . $a_image_dir . "/" . $cur_val . ")";
1680 }
1681 }
1682 }
1683
1684 if ($cur_par == "opacity") {
1685 $cur_val = ((int) $cur_val) / 100;
1686 }
1687
1688 fwrite($css_file, "\t" . $cur_par . ": " . $cur_val . ";\n");
1689
1690 // IE6 fix for minimum height
1691 /*
1692 if ($cur_par == "min-height") {
1693 fwrite($css_file, "\t" . "height" . ": " . "auto !important" . ";\n");
1694 fwrite($css_file, "\t" . "height" . ": " . $cur_val . ";\n");
1695 }*/
1696
1697 // opacity fix
1698 if ($cur_par == "opacity") {
1699 fwrite($css_file, "\t" . '-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=' . ($cur_val * 100) . ')"' . ";\n");
1700 fwrite($css_file, "\t" . 'filter: alpha(opacity=' . ($cur_val * 100) . ')' . ";\n");
1701 fwrite($css_file, "\t" . '-moz-opacity: ' . $cur_val . ";\n");
1702 }
1703
1704 // transform fix
1705 if ($cur_par == "transform") {
1706 fwrite($css_file, "\t" . '-webkit-transform: ' . $cur_val . ";\n");
1707 fwrite($css_file, "\t" . '-moz-transform: ' . $cur_val . ";\n");
1708 fwrite($css_file, "\t" . '-ms-transform: ' . $cur_val . ";\n");
1709 }
1710
1711 // transform-origin fix
1712 if ($cur_par == "transform-origin") {
1713 fwrite($css_file, "\t" . '-webkit-transform-origin: ' . $cur_val . ";\n");
1714 fwrite($css_file, "\t" . '-moz-transform-origin: ' . $cur_val . ";\n");
1715 fwrite($css_file, "\t" . '-ms-transform-origin: ' . $cur_val . ";\n");
1716 }
1717
1718 // save page background
1719 if ($tag[0]["tag"] == "div" && $tag[0]["class"] == "Page"
1720 && $cur_par == "background-color") {
1721 $page_background = $cur_val;
1722 }
1723 }
1724 fwrite($css_file, "}\n");
1725 fwrite($css_file, "\n");
1726
1727 // use table border attributes for th td as well
1728 /* if ($tag[0]["type"] == "table")
1729 {
1730 if (count($t_border) > 0)
1731 {
1732 fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." th,".
1733 $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." td\n");
1734 fwrite ($css_file, "{\n");
1735 foreach ($t_border as $p => $v)
1736 {
1737 // fwrite ($css_file, "\t".$p.": ".$v.";\n");
1738 }
1739 fwrite ($css_file, "}\n");
1740 fwrite ($css_file, "\n");
1741 }
1742 }*/
1743 }
1744
1745 if ($page_background != "") {
1746 fwrite($css_file, "td.ilc_Page\n");
1747 fwrite($css_file, "{\n");
1748 fwrite($css_file, "\t" . "background-color: " . $page_background . ";\n");
1749 fwrite($css_file, "}\n");
1750 }
1751 if ($mq["id"] > 0) {
1752 fwrite($css_file, "}\n");
1753 }
1754 }
1755 fclose($css_file);
1756 // exit;
1757 $this->setUpToDate(true);
1758 $this->_writeUpToDate($this->getId(), true);
1759 }
1760
1767 public static function getEffectiveContentStyleId($a_style_id, $a_type = "")
1768 {
1769 global $DIC;
1770
1771 $ilSetting = $DIC->settings();
1772
1773 // check global fixed content style
1774 $fixed_style = $ilSetting->get("fixed_content_style_id");
1775 if ($fixed_style > 0) {
1776 $a_style_id = $fixed_style;
1777 }
1778
1779 // check global default style
1780 if ($a_style_id <= 0) {
1781 $a_style_id = $ilSetting->get("default_content_style_id");
1782 }
1783
1784 if ($a_style_id > 0 && ilObject::_lookupType($a_style_id) == "sty") {
1785 return $a_style_id;
1786 }
1787
1788 return 0;
1789 }
1790
1797 public function getParametersOfClass($a_type, $a_class, $a_mq_id = 0)
1798 {
1799 if (is_array($this->style_class[$a_type][$a_class][$a_mq_id])) {
1800 return $this->style_class[$a_type][$a_class][$a_mq_id];
1801 }
1802 return array();
1803 }
1804
1810 public static function getContentStylePath($a_style_id, $add_random = true, $add_token = true)
1811 {
1812 global $DIC;
1813
1814 $ilSetting = $DIC->settings();
1815
1816 $random = new \ilRandom();
1817 $rand = $random->int(1, 999999);
1818
1819
1820 // check global fixed content style
1821 $fixed_style = $ilSetting->get("fixed_content_style_id");
1822 if ($fixed_style > 0) {
1823 $a_style_id = $fixed_style;
1824 }
1825
1826 // check global default style
1827 if ($a_style_id <= 0) {
1828 $a_style_id = $ilSetting->get("default_content_style_id");
1829 }
1830
1831 if ($a_style_id > 0 && ilObject::_exists($a_style_id)) {
1832 // check whether file is up to date
1833 if (!ilObjStyleSheet::_lookupUpToDate($a_style_id)) {
1834 $style = new ilObjStyleSheet($a_style_id);
1835 $style->writeCSSFile();
1836 }
1837
1838 $path = ilUtil::getWebspaceDir("output") . "/css/style_" . $a_style_id . ".css";
1839 if ($add_random) {
1840 $path .= "?dummy=$rand";
1841 }
1842 if ($add_token) {
1843 require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
1844 $path = ilWACSignedPath::signFile($path);
1845 }
1846
1847 return $path;
1848 } else { // todo: work this out
1849 return "./Services/COPage/css/content.css";
1850 }
1851 }
1852
1858 public static function getContentPrintStyle()
1859 {
1860 return "./Services/COPage/css/print_content.css";
1861 }
1862
1868 public static function getSyntaxStylePath()
1869 {
1870 return "./Services/COPage/css/syntaxhighlight.css";
1871 }
1872
1878 public static function getPlaceHolderStylePath()
1879 {
1880 return "./Services/COPage/css/placeholder.css";
1881 }
1882
1883 public function update()
1884 {
1885 $ilDB = $this->db;
1886
1887 parent::update();
1888 $this->read(); // this could be done better
1889 $this->writeCSSFile();
1890
1891 $q = "UPDATE style_data " .
1892 "SET category = " . $ilDB->quote((int) $this->getScope(), "integer") .
1893 " WHERE id = " . $ilDB->quote($this->getId(), "integer");
1894 $ilDB->manipulate($q);
1895 }
1896
1903 public function updateStyleParameter($a_id, $a_value)
1904 {
1905 $ilDB = $this->db;
1906
1907 $q = "UPDATE style_parameter SET VALUE = " .
1908 $ilDB->quote($a_value, "text") . " WHERE id = " .
1909 $ilDB->quote($a_id, "integer");
1910 $style_set = $ilDB->manipulate($q);
1911 }
1912
1917 // todo: search for usages, add mq_id
1918 public function replaceStylePar($a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id = 0, $a_custom = false)
1919 {
1920 ilObjStyleSheet::_replaceStylePar($this->getId(), $a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id, $a_custom);
1921 }
1922
1923 public static function _replaceStylePar($style_id, $a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id = 0, $a_custom = false)
1924 {
1925 global $DIC;
1926
1927 $ilDB = $DIC->database();
1928
1929 $q = "SELECT * FROM style_parameter WHERE " .
1930 " style_id = " . $ilDB->quote($style_id, "integer") . " AND " .
1931 " tag = " . $ilDB->quote($a_tag, "text") . " AND " .
1932 " class = " . $ilDB->quote($a_class, "text") . " AND " .
1933 " mq_id = " . $ilDB->quote($a_mq_id, "integer") . " AND " .
1934 " custom = " . $ilDB->quote($a_custom, "integer") . " AND " .
1935 " " . $ilDB->equals("type", $a_type, "text", true) . " AND " .
1936 " parameter = " . $ilDB->quote($a_par, "text");
1937
1938 $set = $ilDB->query($q);
1939
1940 if ($rec = $set->fetchRow()) {
1941 $q = "UPDATE style_parameter SET " .
1942 " value = " . $ilDB->quote($a_val, "text") . " WHERE " .
1943 " style_id = " . $ilDB->quote($style_id, "integer") . " AND " .
1944 " tag = " . $ilDB->quote($a_tag, "text") . " AND " .
1945 " class = " . $ilDB->quote($a_class, "text") . " AND " .
1946 " mq_id = " . $ilDB->quote($a_mq_id, "integer") . " AND " .
1947 " custom = " . $ilDB->quote($a_custom, "integer") . " AND " .
1948 " " . $ilDB->equals("type", $a_type, "text", true) . " AND " .
1949 " parameter = " . $ilDB->quote($a_par, "text");
1950
1951 $ilDB->manipulate($q);
1952 } else {
1953 $id = $ilDB->nextId("style_parameter");
1954 $q = "INSERT INTO style_parameter (id, value, style_id, tag, class, type, parameter, mq_id, custom) VALUES " .
1955 " (" .
1956 $ilDB->quote($id, "integer") . "," .
1957 $ilDB->quote($a_val, "text") . "," .
1958 " " . $ilDB->quote($style_id, "integer") . "," .
1959 " " . $ilDB->quote($a_tag, "text") . "," .
1960 " " . $ilDB->quote($a_class, "text") . "," .
1961 " " . $ilDB->quote($a_type, "text") . "," .
1962 " " . $ilDB->quote($a_par, "text") . "," .
1963 " " . $ilDB->quote($a_mq_id, "integer") . "," .
1964 " " . $ilDB->quote($a_custom, "integer") .
1965 ")";
1966
1967 $ilDB->manipulate($q);
1968 }
1969 }
1970
1971
1975 public function getStyle()
1976 {
1977 return $this->style;
1978 }
1979
1983 public function setStyle($a_style)
1984 {
1985 $this->style = $a_style;
1986 }
1987
1988
1995 public function handleXmlString($a_str)
1996 {
1997 return str_replace("&", "&amp;", $a_str);
1998 }
1999
2004 public function getXML()
2005 {
2006 $xml .= "<StyleSheet>\n";
2007
2008 // title and description
2009 $xml .= "<Title>" . $this->handleXmlString($this->getTitle()) . "</Title>";
2010 $xml .= "<Description>" . $this->handleXmlString($this->getDescription()) . "</Description>\n";
2011
2012 // style classes
2013 foreach ($this->chars as $char) {
2014 $xml .= "<Style Tag=\"" . ilObjStyleSheet::_determineTag($char["type"]) .
2015 "\" Type=\"" . $char["type"] . "\" Class=\"" . $char["class"] . "\">\n";
2016 foreach ($this->style as $style) {
2017 if ($style[0]["type"] == $char["type"] && $style[0]["class"] == $char["class"]) {
2018 foreach ($style as $tag) {
2019 $xml .= "<StyleParameter Name=\"" . $tag["parameter"] . "\" Value=\"" . $tag["value"] . "\" Custom=\"" . $tag["custom"] . "\" />\n";
2020 }
2021 }
2022 }
2023 $xml .= "</Style>\n";
2024 }
2025
2026 // colors
2027 foreach ($this->getColors() as $color) {
2028 $xml .= "<StyleColor Name=\"" . $color["name"] . "\" Code=\"" . $color["code"] . "\"/>\n";
2029 }
2030
2031 // templates
2033 foreach ($tcts as $tct => $v) {
2034 $ts = $this->getTemplates($tct);
2035
2036 foreach ($ts as $t) {
2037 $xml .= "<StyleTemplate Type=\"" . $tct . "\" Name=\"" . $t["name"] . "\">\n";
2038 foreach ($t["classes"] as $ct => $c) {
2039 if ($c != "") {
2040 $xml .= "<StyleTemplateClass ClassType=\"" . $ct . "\" Class=\"" . $c . "\"/>\n";
2041 }
2042 }
2043 $xml .= "</StyleTemplate>\n";
2044 }
2045 }
2046
2047
2048 $xml .= "</StyleSheet>";
2049 //echo "<pre>".htmlentities($xml)."</pre>"; exit;
2050 return $xml;
2051 }
2052
2053
2057 public function createExportDirectory()
2058 {
2059 $sty_data_dir = ilUtil::getDataDir() . "/sty";
2060 ilUtil::makeDir($sty_data_dir);
2061 if (!is_writable($sty_data_dir)) {
2062 $this->ilias->raiseError("Style data directory (" . $sty_data_dir
2063 . ") not writeable.", $this->ilias->error_obj->FATAL);
2064 }
2065
2066 $style_dir = $sty_data_dir . "/sty_" . $this->getId();
2067 ilUtil::makeDir($style_dir);
2068 if (!@is_dir($style_dir)) {
2069 $this->ilias->raiseError("Creation of style directory failed (" .
2070 $style_dir . ").", $this->ilias->error_obj->FATAL);
2071 }
2072
2073 // create export subdirectory
2074 $ex_dir = $style_dir . "/export";
2075 ilUtil::makeDir($ex_dir);
2076 if (!@is_dir($ex_dir)) {
2077 $this->ilias->raiseError("Creation of Import Directory failed (" .
2078 $ex_dir . ").", $this->ilias->error_obj->FATAL);
2079 }
2080
2081 return $ex_dir;
2082 }
2083
2087 public function cleanExportDirectory()
2088 {
2089 $sty_data_dir = ilUtil::getDataDir() . "/sty";
2090 $style_dir = $sty_data_dir . "/sty_" . $this->getId();
2091 // create export subdirectory
2092 $ex_dir = $style_dir . "/export";
2093
2094 if (is_dir($ex_dir)) {
2095 ilUtil::delDir($ex_dir, true);
2096 }
2097 }
2098
2099
2104 {
2105 $ex_dir = $this->createExportDirectory();
2106 $ex_sub_dir = $ex_dir . "/" . $this->getExportSubDir();
2107 ilUtil::makeDir($ex_sub_dir);
2108 if (!is_writable($ex_sub_dir)) {
2109 $this->ilias->raiseError("Style data directory (" . $ex_sub_dir
2110 . ") not writeable.", $this->ilias->error_obj->FATAL);
2111 }
2112 $ex_sub_images_dir = $ex_sub_dir . "/images";
2113 ilUtil::makeDir($ex_sub_images_dir);
2114 if (!is_writable($ex_sub_images_dir)) {
2115 $this->ilias->raiseError("Style data directory (" . $ex_sub_images_dir
2116 . ") not writeable.", $this->ilias->error_obj->FATAL);
2117 }
2118 }
2119
2123 public function setExportSubDir($a_dir)
2124 {
2125 $this->export_sub_dir = $a_dir;
2126 }
2127
2131 public function getExportSubDir()
2132 {
2133 if ($this->export_sub_dir == "") {
2134 return "sty_" . $this->getId();
2135 } else {
2136 return $this->export_sub_dir;
2137 }
2138 }
2139
2145 public function export()
2146 {
2147 $this->cleanExportDirectory();
2148 $ex_dir = $this->createExportDirectory();
2149 $this->createExportSubDirectory();
2150 $this->exportXML($ex_dir . "/" . $this->getExportSubDir());
2151 //echo "-".$this->getImagesDirectory()."-".$ex_dir."/".$this->getExportSubDir()."/images"."-";
2153 $this->getImagesDirectory(),
2154 $ex_dir . "/" . $this->getExportSubDir() . "/images"
2155 );
2156 if (is_file($ex_dir . "/" . $this->getExportSubDir() . ".zip")) {
2157 unlink($ex_dir . "/" . $this->getExportSubDir() . ".zip");
2158 }
2160 $ex_dir . "/" . $this->getExportSubDir(),
2161 $ex_dir . "/" . $this->getExportSubDir() . ".zip"
2162 );
2163
2164 return $ex_dir . "/" . $this->getExportSubDir() . ".zip";
2165 }
2166
2170 public function exportXML($a_dir)
2171 {
2172 $file = $a_dir . "/style.xml";
2173
2174 // open file
2175 if (!($fp = @fopen($file, "w"))) {
2176 die("<b>Error</b>: Could not open \"" . $file . "\" for writing" .
2177 " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
2178 }
2179
2180 // set file permissions
2181 chmod($file, 0770);
2182
2183 // write xml data into the file
2184 fwrite($fp, $this->getXML());
2185
2186 // close file
2187 fclose($fp);
2188 }
2189
2193 public function createImportDirectory()
2194 {
2195 $sty_data_dir = ilUtil::getDataDir() . "/sty";
2196 ilUtil::makeDir($sty_data_dir);
2197 if (!is_writable($sty_data_dir)) {
2198 $this->ilias->raiseError("Style data directory (" . $sty_data_dir
2199 . ") not writeable.", $this->ilias->error_obj->FATAL);
2200 }
2201
2202 $style_dir = $sty_data_dir . "/sty_" . $this->getId();
2203 ilUtil::makeDir($style_dir);
2204 if (!@is_dir($style_dir)) {
2205 $this->ilias->raiseError("Creation of style directory failed (" .
2206 $style_dir . ").", $this->ilias->error_obj->FATAL);
2207 }
2208
2209 // create import subdirectory
2210 $im_dir = $style_dir . "/import";
2211 ilUtil::makeDir($im_dir);
2212 if (!@is_dir($im_dir)) {
2213 $this->ilias->raiseError("Creation of Import Directory failed (" .
2214 $im_dir . ").", $this->ilias->error_obj->FATAL);
2215 }
2216
2217 return $im_dir;
2218 }
2219
2223 public function import($a_file)
2224 {
2225 parent::create();
2226
2227 $im_dir = $this->createImportDirectory();
2228
2229 // handle uploaded files
2230 if (is_array($a_file)) {
2232 $a_file["tmp_name"],
2233 $a_file["name"],
2234 $im_dir . "/" . $a_file["name"]
2235 );
2236 $file_name = $a_file["name"];
2237 } else { // handle not directly uploaded files
2238 $pi = pathinfo($a_file);
2239 $file_name = $pi["basename"];
2240 copy($a_file, $im_dir . "/" . $file_name);
2241 }
2242 $file = pathinfo($file_name);
2243
2244 // unzip file
2245 if (strtolower($file["extension"] == "zip")) {
2246 ilUtil::unzip($im_dir . "/" . $file_name);
2247 $subdir = basename($file["basename"], "." . $file["extension"]);
2248 if (!is_dir($im_dir . "/" . $subdir)) {
2249 $subdir = "style"; // check style subdir
2250 }
2251 $xml_file = $im_dir . "/" . $subdir . "/style.xml";
2252 } else { // handle xml file directly (old style)
2253 $xml_file = $im_dir . "/" . $file_name;
2254 }
2255
2256 // load information from xml file
2257 //echo "-$xml_file-";
2258 $this->createFromXMLFile($xml_file, true);
2259
2260 // copy images
2261 $this->createImagesDirectory();
2262 if (is_dir($im_dir . "/" . $subdir . "/images")) {
2264 $im_dir . "/" . $subdir . "/images",
2265 $this->getImagesDirectory()
2266 );
2267 }
2268
2270 $this->read();
2271 $this->writeCSSFile();
2272 }
2273
2278 public function createFromXMLFile($a_file, $a_skip_parent_create = false)
2279 {
2280 $ilDB = $this->db;
2281
2282 $this->is_3_10_skin = false;
2283
2284 if (!$a_skip_parent_create) {
2285 parent::create();
2286 }
2287 include_once("./Services/Style/Content/classes/class.ilStyleImportParser.php");
2288 $importParser = new ilStyleImportParser($a_file, $this);
2289 $importParser->startParsing();
2290
2291 // store style parameter
2292 foreach ($this->style as $style) {
2293 foreach ($style as $tag) {
2294 $id = $ilDB->nextId("style_parameter");
2295
2296 // migrate old table PageFrame/PageContainer to div
2297 if (in_array($tag["class"], array("PageFrame", "PageContainer")) &&
2298 $tag["tag"] == "table") {
2299 $tag["tag"] = "div";
2300 if ($tag["parameter"] == "width" && $tag["value"] == "100%") {
2301 continue;
2302 }
2303 }
2304
2305 $q = "INSERT INTO style_parameter (id,style_id, tag, class, parameter, type, value, custom) VALUES " .
2306 "(" .
2307 $ilDB->quote($id, "integer") . "," .
2308 $ilDB->quote($this->getId(), "integer") . "," .
2309 $ilDB->quote($tag["tag"], "text") . "," .
2310 $ilDB->quote($tag["class"], "text") . "," .
2311 $ilDB->quote($tag["parameter"], "text") . "," .
2312 $ilDB->quote($tag["type"], "text") . "," .
2313 $ilDB->quote($tag["value"], "text") . "," .
2314 $ilDB->quote((bool) $tag["custom"], "integer") .
2315 ")";
2316 $ilDB->manipulate($q);
2317 }
2318 }
2319
2320 // store characteristics
2321 $this->is_3_10_skin = true;
2322 if (is_array($this->chars)) {
2323 foreach ($this->chars as $char) {
2324 if ($char["type"] != "") {
2325 $s = substr($char["class"], strlen($char["class"]) - 6);
2326 if ($s != ":hover") {
2327 $ilDB->replace(
2328 "style_char",
2329 array(
2330 "style_id" => array("integer", $this->getId()),
2331 "type" => array("text", $char["type"]),
2332 "characteristic" => array("text", $char["class"])),
2333 array("hide" => array("integer", 0))
2334 );
2335 /*
2336 $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
2337 "(".$ilDB->quote($this->getId(), "integer").",".
2338 $ilDB->quote($char["type"], "text").",".
2339 $ilDB->quote($char["class"], "text").")";
2340 $ilDB->manipulate($q);*/
2341 $this->is_3_10_skin = false;
2342 }
2343 }
2344 }
2345 }
2346
2347 // add style_data record
2348 $q = "INSERT INTO style_data (id, uptodate) VALUES " .
2349 "(" . $ilDB->quote($this->getId(), "integer") . ", 0)";
2350 $ilDB->manipulate($q);
2351
2352 $this->update();
2353 $this->read();
2354
2355 if ($this->is_3_10_skin) {
2356 $this->do_3_10_Migration();
2357 }
2358 //$this->writeCSSFile();
2359 }
2360
2364 public function getStyleParameterGroups()
2365 {
2366 $groups = array();
2367
2368 foreach (self::$parameter as $parameter => $props) {
2369 $groups[$props["group"]][] = $parameter;
2370 }
2371 return $groups;
2372 }
2373
2374 public static function _getStyleParameterInputType($par)
2375 {
2376 $input = self::$parameter[$par]["input"];
2377 return $input;
2378 }
2379
2380 public static function _getStyleParameterSubPar($par)
2381 {
2382 $subpar = self::$parameter[$par]["subpar"];
2383 return $subpar;
2384 }
2385
2386 public static function _getStyleParameters($a_tag = "")
2387 {
2388 if ($a_tag == "") {
2389 return self::$parameter;
2390 }
2391 $par = array();
2392 foreach (self::$parameter as $k => $v) {
2393 if (is_array(self::$filtered_groups[$v["group"]]) &&
2394 !in_array($a_tag, self::$filtered_groups[$v["group"]])) {
2395 continue;
2396 }
2397 $par[$k] = $v;
2398 }
2399 return $par;
2400 }
2401
2402 public static function _getFilteredGroups()
2403 {
2405 }
2406
2407 public static function _getStyleParameterNumericUnits($a_no_percentage = false)
2408 {
2409 if ($a_no_percentage) {
2411 }
2412 return self::$num_unit;
2413 }
2414
2415 public static function _getStyleParameterValues($par)
2416 {
2417 return self::$parameter[$par]["values"];
2418 }
2419
2420 /*static function _getStyleTypes()
2421 {
2422 return self::$style_types;
2423 }*/
2424
2425 public static function _getStyleSuperTypes()
2426 {
2428 }
2429
2430 public static function _isExpandable($a_type)
2431 {
2432 return in_array($a_type, self::$expandable_types);
2433 }
2434
2435 public static function _isHideable($a_type)
2436 {
2437 return in_array($a_type, self::$hideable_types);
2438 }
2439
2440 public static function _getStyleSuperTypeForType($a_type)
2441 {
2442 foreach (self::$style_super_types as $s => $t) {
2443 if (in_array($a_type, $t)) {
2444 return $s;
2445 }
2446 if ($a_type == $s) {
2447 return $s;
2448 }
2449 }
2450 }
2451
2455 public static function _getCoreStyles()
2456 {
2457 $c_styles = array();
2458 foreach (self::$core_styles as $cstyle) {
2459 $c_styles[$cstyle["type"] . "." . ilObjStyleSheet::_determineTag($cstyle["type"]) . "." . $cstyle["class"]]
2460 = array("type" => $cstyle["type"],
2461 "tag" => ilObjStyleSheet::_determineTag($cstyle["type"]),
2462 "class" => $cstyle["class"]);
2463 }
2464 return $c_styles;
2465 }
2466
2473 public static function isCoreStyle($a_type, $a_class)
2474 {
2475 foreach (self::$core_styles as $s) {
2476 if ($s["type"] == $a_type && $s["class"] == $a_class) {
2477 return true;
2478 }
2479 }
2480 return false;
2481 }
2482
2483
2487 public static function _getTemplateClassTypes($a_template_type = "")
2488 {
2489 if ($a_template_type == "") {
2490 return self::$templates;
2491 }
2492
2493 return self::$templates[$a_template_type];
2494 }
2495
2496
2497 public static function _getPseudoClasses($tag)
2498 {
2499 return self::$pseudo_classes[$tag];
2500 }
2501
2502 public function determineTemplateStyleClassType($t, $k)
2503 {
2504 return self::$templates[$t][$k];
2505 }
2506
2507 public static function _determineTag($a_type)
2508 {
2509 return self::$assigned_tags[$a_type];
2510 }
2511
2515 public static function getAvailableParameters()
2516 {
2517 $pars = array();
2518 foreach (self::$parameter as $p => $v) {
2519 $pars[$p] = $v["values"];
2520 }
2521
2522 return $pars;
2523 }
2524
2525
2529 public static function _addMissingStyleClassesToStyle($a_id)
2530 {
2531 $styles = array(array("id" => $a_id));
2533 }
2534
2539 public static function _addMissingStyleClassesToAllStyles($a_styles = "")
2540 {
2541 global $DIC;
2542
2543 $ilDB = $DIC->database();
2544
2545 if ($a_styles == "") {
2546 $styles = ilObject::_getObjectsDataForType("sty");
2547 } else {
2548 $styles = $a_styles;
2549 }
2552
2553 // get all core image files
2554 $core_images = array();
2555 $core_dir = self::$basic_style_image_dir;
2556 if (is_dir($core_dir)) {
2557 $dir = opendir($core_dir);
2558 while ($file = readdir($dir)) {
2559 if (substr($file, 0, 1) != "." && is_file($core_dir . "/" . $file)) {
2560 $core_images[] = $file;
2561 }
2562 }
2563 }
2564
2565 foreach ($styles as $style) {
2566 $id = $style["id"];
2567
2568 foreach ($core_styles as $cs) {
2569 // check, whether core style class exists
2570 $set = $ilDB->queryF(
2571 "SELECT * FROM style_char WHERE style_id = %s " .
2572 "AND type = %s AND characteristic = %s",
2573 array("integer", "text", "text"),
2574 array($id, $cs["type"], $cs["class"])
2575 );
2576
2577 // if not, add core style class
2578 if (!($rec = $ilDB->fetchAssoc($set))) {
2579 $ilDB->manipulateF(
2580 "INSERT INTO style_char (style_id, type, characteristic) " .
2581 " VALUES (%s,%s,%s) ",
2582 array("integer", "text", "text"),
2583 array($id, $cs["type"], $cs["class"])
2584 );
2585
2586 $xpath = new DOMXPath($bdom);
2587 $par_nodes = $xpath->query("/StyleSheet/Style[@Tag = '" . $cs["tag"] . "' and @Type='" .
2588 $cs["type"] . "' and @Class='" . $cs["class"] . "']/StyleParameter");
2589 foreach ($par_nodes as $par_node) {
2590 // check whether style parameter exists
2591 $set = $ilDB->queryF(
2592 "SELECT * FROM style_parameter WHERE style_id = %s " .
2593 "AND type = %s AND class = %s AND tag = %s AND parameter = %s",
2594 array("integer", "text", "text", "text", "text"),
2595 array($id, $cs["type"], $cs["class"],
2596 $cs["tag"], $par_node->getAttribute("Name"))
2597 );
2598
2599 // if not, create style parameter
2600 if (!($rec = $ilDB->fetchAssoc($set))) {
2601 $spid = $ilDB->nextId("style_parameter");
2602 $st = $ilDB->manipulateF(
2603 "INSERT INTO style_parameter (id, style_id, type, class, tag, parameter, value) " .
2604 " VALUES (%s,%s,%s,%s,%s,%s,%s)",
2605 array("integer", "integer", "text", "text", "text", "text", "text"),
2606 array($spid, $id, $cs["type"], $cs["class"], $cs["tag"],
2607 $par_node->getAttribute("Name"), $par_node->getAttribute("Value"))
2608 );
2609 }
2610 }
2611 }
2612 }
2613
2614 // now check, whether some core image files are missing
2617 reset($core_images);
2618 foreach ($core_images as $cim) {
2619 if (!is_file($imdir . "/" . $cim)) {
2620 copy($core_dir . "/" . $cim, $imdir . "/" . $cim);
2621 }
2622 }
2623 }
2624 }
2625
2626 //
2627 // Color management
2628 //
2629
2633 public function do_3_10_Migration()
2634 {
2635 $ilDB = $this->db;
2636
2637 $this->do_3_9_Migration($this->getId());
2638
2639 //include_once("./Services/Migration/DBUpdate_1385/classes/class.ilStyleMigration.php");
2640 //ilStyleMigration::addMissingStyleCharacteristics($this->getId());
2641
2642 $this->do_3_10_CharMigration($this->getId());
2643
2644 // style_char: type for characteristic
2645 $st = $ilDB->prepareManip("UPDATE style_char SET type = ? WHERE characteristic = ?" .
2646 " AND style_id = ? ", array("text", "text", "integer"));
2647 $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2648 $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2649 $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2650 $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2651 $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2652 $ilDB->execute($st, array("page_cont", "Page", $this->getId()));
2653
2654 // style_parameter: type for class
2655 $st = $ilDB->prepareManip("UPDATE style_parameter SET type = ? WHERE class = ?" .
2656 " AND style_id = ? ", array("text", "text", "integer"));
2657 $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2658 $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2659 $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2660 $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2661 $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2662 $ilDB->execute($st, array("table", "Page", $this->getId()));
2663
2664 $st = $ilDB->prepareManip("UPDATE style_parameter SET tag = ? WHERE class = ?" .
2665 " AND style_id = ? ", array("text", "text", "integer"));
2666 $ilDB->execute($st, array("div", "MediaCaption", $this->getId()));
2667
2668 // style_char: characteristic for characteristic
2669 $st = $ilDB->prepareManip("UPDATE style_char SET characteristic = ? WHERE characteristic = ?" .
2670 " AND style_id = ? ", array("text", "text", "integer"));
2671 $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2672 $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2673
2674 // style_parameter: class for class
2675 $st = $ilDB->prepareManip("UPDATE style_parameter SET class = ? WHERE class = ?" .
2676 " AND style_id = ? ", array("text", "text", "integer"));
2677 $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2678 $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2679
2680 // force rewriting of container style
2681 $st = $ilDB->prepareManip("DELETE FROM style_char WHERE type = ?" .
2682 " AND style_id = ? ", array("text", "integer"));
2683 $ilDB->execute($st, array("page_cont", $this->getId()));
2684 $st = $ilDB->prepareManip("DELETE FROM style_parameter WHERE type = ?" .
2685 " AND style_id = ? ", array("text", "integer"));
2686 $ilDB->execute($st, array("page_cont", $this->getId()));
2687 }
2688
2695 public function do_3_10_CharMigration($a_id = "")
2696 {
2697 $ilDB = $this->db;
2698
2699 $add_str = "";
2700 if ($a_id != "") {
2701 $add_str = " AND style_id = " . $ilDB->quote($a_id, "integer");
2702 }
2703
2704 $set = $ilDB->query($q = "SELECT DISTINCT style_id, tag, class FROM style_parameter WHERE " .
2705 $ilDB->equals("type", "", "text", true) . " " . $add_str);
2706
2707 while ($rec = $ilDB->fetchAssoc($set)) {
2708 // derive types from tag
2709 $types = array();
2710 switch ($rec["tag"]) {
2711 case "div":
2712 case "p":
2713 if (in_array($rec["class"], array("Headline3", "Headline1",
2714 "Headline2", "TableContent", "List", "Standard", "Remark",
2715 "Additional", "Mnemonic", "Citation", "Example"))) {
2716 $types[] = "text_block";
2717 }
2718 if (in_array($rec["class"], array("Block", "Remark",
2719 "Additional", "Mnemonic", "Example", "Excursus", "Special"))) {
2720 $types[] = "section";
2721 }
2722 if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation"))) {
2723 $types[] = "page";
2724 }
2725 break;
2726
2727 case "td":
2728 $types[] = "table_cell";
2729 break;
2730
2731 case "a":
2732 if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink"))) {
2733 $types[] = "link";
2734 }
2735 break;
2736
2737 case "span":
2738 $types[] = "text_inline";
2739 break;
2740
2741 case "table":
2742 $types[] = "table";
2743 break;
2744 }
2745
2746 // check if style_char set exists
2747 foreach ($types as $t) {
2748 // check if second type already exists
2749 $set4 = $ilDB->queryF(
2750 "SELECT * FROM style_char " .
2751 " WHERE style_id = %s AND type = %s AND characteristic = %s",
2752 array("integer", "text", "text"),
2753 array($rec["style_id"], $t, $rec["class"])
2754 );
2755 if ($rec4 = $ilDB->fetchAssoc($set4)) {
2756 // ok
2757 } else {
2758 //echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
2759 $ilDB->manipulateF(
2760 "INSERT INTO style_char " .
2761 " (style_id, type, characteristic) VALUES " .
2762 " (%s,%s,%s) ",
2763 array("integer", "text", "text"),
2764 array($rec["style_id"], $t, $rec["class"])
2765 );
2766 }
2767 }
2768
2769 // update types
2770 if ($rec["type"] == "") {
2771 if (count($types) > 0) {
2772 $ilDB->manipulateF(
2773 "UPDATE style_parameter SET type = %s " .
2774 " WHERE style_id = %s AND class = %s AND " . $ilDB->equals("type", "", "text", true),
2775 array("text", "integer", "text"),
2776 array($types[0], $rec["style_id"], $rec["class"])
2777 );
2778 //echo "<br>3-".$types[0]."-".$rec["style_id"]."-".$rec["class"]."-";
2779
2780 // links extra handling
2781 if ($types[0] == "link") {
2782 $ilDB->manipulateF(
2783 "UPDATE style_parameter SET type = %s " .
2784 " WHERE style_id = %s AND (class = %s OR class = %s) AND " . $ilDB->equals("type", "", "text", true),
2785 array("text", "integer", "text", "text"),
2786 array($types[0], $rec["style_id"], $rec["class"] . ":visited",
2787 $rec["class"] . ":hover")
2788 );
2789 }
2790 }
2791
2792 if (count($types) == 2) {
2793 // select all records of first type and add second type
2794 // records if necessary.
2795 $set2 = $ilDB->queryF(
2796 "SELECT * FROM style_parameter " .
2797 " WHERE style_id = %s AND class = %s AND type = %s",
2798 array("integer", "text", "text"),
2799 array($rec["style_id"], $rec["class"], $types[0])
2800 );
2801 while ($rec2 = $ilDB->fetchAssoc($set2)) {
2802 // check if second type already exists
2803 $set3 = $ilDB->queryF(
2804 "SELECT * FROM style_parameter " .
2805 " WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
2806 array("integer", "text", "text", "text", "text"),
2807 array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"])
2808 );
2809 if ($rec3 = $ilDB->fetchAssoc($set3)) {
2810 // ok
2811 } else {
2812 $nid = $ilDB->nextId("style_parameter");
2813 $ilDB->manipulateF(
2814 "INSERT INTO style_parameter " .
2815 " (id, style_id, tag, class, parameter, value, type) VALUES " .
2816 " (%s, %s,%s,%s,%s,%s,%s) ",
2817 array("integer", "integer", "text", "text", "text", "text", "text"),
2818 array($nid, $rec2["style_id"], $rec2["tag"], $rec2["class"],
2819 $rec2["parameter"], $rec2["value"], $types[1])
2820 );
2821 }
2822 }
2823 }
2824 }
2825 }
2826 }
2827
2831 public function do_3_9_Migration($a_id)
2832 {
2833 $ilDB = $this->db;
2834
2835 $classes = array("Example", "Additional", "Citation", "Mnemonic", "Remark");
2836 $pars = array("margin-top", "margin-bottom");
2837
2838 foreach ($classes as $curr_class) {
2839 foreach ($pars as $curr_par) {
2840 $res2 = $ilDB->queryF(
2841 "SELECT id FROM style_parameter WHERE style_id = %s" .
2842 " AND tag = %s AND class= %s AND parameter = %s",
2843 array("integer", "text", "text", "text"),
2844 array($a_id, "p", $curr_class, $curr_par)
2845 );
2846 if ($row2 = $ilDB->fetchAssoc($res2)) {
2847 $ilDB->manipulateF(
2848 "UPDATE style_parameter SET value= %s WHERE id = %s",
2849 array("text", "integer"),
2850 array("10px", $row2["id"])
2851 );
2852 } else {
2853 $nid = $ilDB->nextId("style_parameter");
2854 $ilDB->manipulateF(
2855 "INSERT INTO style_parameter " .
2856 "(id, style_id, tag, class, parameter,value) VALUES (%s,%s,%s,%s,%s,%s)",
2857 array("integer", "integer", "text", "text", "text", "text"),
2858 array($nid, $a_id, "div", $curr_class, $curr_par, "10px")
2859 );
2860 }
2861 }
2862 }
2863
2864 $ilDB->manipulateF(
2865 "UPDATE style_parameter SET tag = %s WHERE tag = %s and style_id = %s",
2866 array("text", "text", "integer"),
2867 array("div", "p", $a_id)
2868 );
2869 }
2870
2874
2878 public function getColors()
2879 {
2880 $ilDB = $this->db;
2881
2882 $set = $ilDB->query("SELECT * FROM style_color WHERE " .
2883 "style_id = " . $ilDB->quote($this->getId(), "integer") . " " .
2884 "ORDER BY color_name");
2885
2886 $colors = array();
2887 while ($rec = $ilDB->fetchAssoc($set)) {
2888 $colors[] = array(
2889 "name" => $rec["color_name"],
2890 "code" => $rec["color_code"]
2891 );
2892 }
2893
2894 return $colors;
2895 }
2896
2900 public function addColor($a_name, $a_code)
2901 {
2902 $ilDB = $this->db;
2903
2904 $ilDB->manipulate("INSERT INTO style_color (style_id, color_name, color_code)" .
2905 " VALUES (" .
2906 $ilDB->quote($this->getId(), "integer") . "," .
2907 $ilDB->quote($a_name, "text") . "," .
2908 $ilDB->quote($a_code, "text") .
2909 ")");
2910 }
2911
2915 public function updateColor($a_name, $a_new_name, $a_code)
2916 {
2917 $ilDB = $this->db;
2918
2919 // todo: update names in parameters as well
2920
2921 $ilDB->manipulate("UPDATE style_color SET " .
2922 "color_name = " . $ilDB->quote($a_new_name, "text") . ", " .
2923 "color_code = " . $ilDB->quote($a_code, "text") .
2924 " WHERE style_id = " . $ilDB->quote($this->getId(), "integer") .
2925 " AND color_name = " . $ilDB->quote($a_name, "text"));
2926 ilObjStyleSheet::_writeUpToDate($this->getId(), false);
2927
2928 // rename also the name in the style parameter values
2929 if ($a_name != $a_new_name) {
2930 $set = $ilDB->query("SELECT * FROM style_parameter " .
2931 " WHERE style_id = " . $ilDB->quote($this->getId(), "integer") .
2932 " AND (" .
2933 " parameter = " . $ilDB->quote("background-color", "text") . " OR " .
2934 " parameter = " . $ilDB->quote("color", "text") . " OR " .
2935 " parameter = " . $ilDB->quote("border-color", "text") . " OR " .
2936 " parameter = " . $ilDB->quote("border-top-color", "text") . " OR " .
2937 " parameter = " . $ilDB->quote("border-bottom-color", "text") . " OR " .
2938 " parameter = " . $ilDB->quote("border-left-color", "text") . " OR " .
2939 " parameter = " . $ilDB->quote("border-right-color", "text") .
2940 ")");
2941 while ($rec = $ilDB->fetchAssoc($set)) {
2942 if ($rec["value"] == "!" . $a_name ||
2943 is_int(strpos($rec["value"], "!" . $a_name . "("))) {
2944 // parameter is based on color -> rename it
2945 $this->replaceStylePar(
2946 $rec["tag"],
2947 $rec["class"],
2948 $rec["parameter"],
2949 str_replace($a_name, $a_new_name, $rec["value"]),
2950 $rec["type"],
2951 $rec["mq_id"],
2952 $rec["custom"]
2953 );
2954 }
2955 }
2956 }
2957 }
2958
2962 public function removeColor($a_name)
2963 {
2964 $ilDB = $this->db;
2965
2966 $ilDB->manipulate("DELETE FROM style_color WHERE " .
2967 " style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
2968 " color_name = " . $ilDB->quote($a_name, "text"));
2969 }
2970
2974 public function colorExists($a_color_name)
2975 {
2976 $ilDB = $this->db;
2977
2978 $set = $ilDB->query("SELECT * FROM style_color WHERE " .
2979 "style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
2980 "color_name = " . $ilDB->quote($a_color_name, "text"));
2981 if ($rec = $ilDB->fetchAssoc($set)) {
2982 return true;
2983 }
2984 return false;
2985 }
2986
2990 public function getColorCodeForName($a_name)
2991 {
2992 $ilDB = $this->db;
2993
2994 $pos = strpos($a_name, "(");
2995 if ($pos > 0) {
2996 $a_i = substr($a_name, $pos + 1);
2997 $a_i = str_replace(")", "", $a_i);
2998 $a_name = substr($a_name, 0, $pos);
2999 }
3000
3001 $set = $ilDB->query("SELECT color_code FROM style_color WHERE " .
3002 " style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
3003 " color_name = " . $ilDB->quote($a_name, "text"));
3004 if ($rec = $ilDB->fetchAssoc($set)) {
3005 if ($a_i == "") {
3006 return "#" . $rec["color_code"];
3007 } else {
3009 $rec["color_code"],
3010 (int) $a_i
3011 );
3012 }
3013 }
3014 }
3015
3019 public static function _getColorFlavor($a_rgb, $a_i)
3020 {
3021 $rgb = ilObjStyleSheet::_explodeRGB($a_rgb, true);
3022 $hls = ilObjStyleSheet::_RGBToHLS($rgb);
3023
3024 if ($a_i > 0) {
3025 $hls["l"] = $hls["l"] + ((255 - $hls["l"]) * ($a_i / 100));
3026 }
3027 if ($a_i < 0) {
3028 $hls["l"] = $hls["l"] - (($hls["l"]) * (-$a_i / 100));
3029 }
3030
3031 $rgb = ilObjStyleSheet::_HLSToRGB($hls);
3032
3033 foreach ($rgb as $k => $v) {
3034 $rgb[$k] = str_pad(dechex($v), 2, "0", STR_PAD_LEFT);
3035 }
3036
3037 return $rgb["r"] . $rgb["g"] . $rgb["b"];
3038 }
3039
3043 public static function _explodeRGB($a_rgb, $as_dec = false)
3044 {
3045 $r["r"] = substr($a_rgb, 0, 2);
3046 $r["g"] = substr($a_rgb, 2, 2);
3047 $r["b"] = substr($a_rgb, 4, 2);
3048
3049 if ($as_dec) {
3050 $r["r"] = (int) hexdec($r["r"]);
3051 $r["g"] = (int) hexdec($r["g"]);
3052 $r["b"] = (int) hexdec($r["b"]);
3053 }
3054
3055 return $r;
3056 }
3057
3061 public static function _RGBToHLS($a_rgb)
3062 {
3063 $r = $a_rgb["r"] / 255;
3064 $g = $a_rgb["g"] / 255;
3065 $b = $a_rgb["b"] / 255;
3066
3067 // max / min
3068 $max = max($r, $g, $b);
3069 $min = min($r, $g, $b);
3070
3071 //lightness
3072 $l = ($max + $min) / 2;
3073
3074 if ($max == $min) {
3075 $s = 0;
3076 $h = 0;
3077 } else {
3078 if ($l < 0.5) {
3079 $s = ($max - $min) / ($max + $min);
3080 } else {
3081 $s = ($max - $min) / (2.0 - $max - $min);
3082 }
3083
3084 if ($r == $max) {
3085 $h = ($g - $b) / ($max - $min);
3086 } elseif ($g == $max) {
3087 $h = 2.0 + ($b - $r) / ($max - $min);
3088 } elseif ($b == $max) {
3089 $h = 4.0 + ($r - $g) / ($max - $min);
3090 }
3091 }
3092
3093 $hls["h"] = round(($h / 6) * 255);
3094 $hls["l"] = round($l * 255);
3095 $hls["s"] = round($s * 255);
3096
3097 return $hls;
3098 }
3099
3103 public static function _HLSToRGB($a_hls)
3104 {
3105 $h = $a_hls["h"] / 255;
3106 $l = $a_hls["l"] / 255;
3107 $s = $a_hls["s"] / 255;
3108
3109 $rgb["r"] = $rgb["g"] = $rgb["b"] = 0;
3110
3111 // If S=0, define R, G, and B all to L
3112 if ($s == 0) {
3113 $rgb["r"] = $rgb["g"] = $rgb["b"] = $l;
3114 } else {
3115 if ($l < 0.5) {
3116 $temp2 = $l * (1.0 + $s);
3117 } else {
3118 $temp2 = $l + $s - $l * $s;
3119 }
3120
3121 $temp1 = 2.0 * $l - $temp2;
3122
3123
3124 # For each of R, G, B, compute another temporary value, temp3, as follows:
3125 foreach ($rgb as $k => $v) {
3126 switch ($k) {
3127 case "r":
3128 $temp3 = $h + 1.0 / 3.0;
3129 break;
3130
3131 case "g":
3132 $temp3 = $h;
3133 break;
3134
3135 case "b":
3136 $temp3 = $h - 1.0 / 3.0;
3137 break;
3138 }
3139 if ($temp3 < 0) {
3140 $temp3 = $temp3 + 1.0;
3141 }
3142 if ($temp3 > 1) {
3143 $temp3 = $temp3 - 1.0;
3144 }
3145
3146 if (6.0 * $temp3 < 1) {
3147 $rgb[$k] = $temp1 + ($temp2 - $temp1) * 6.0 * $temp3;
3148 } elseif (2.0 * $temp3 < 1) {
3149 $rgb[$k] = $temp2;
3150 } elseif (3.0 * $temp3 < 2) {
3151 $rgb[$k] = $temp1 + ($temp2 - $temp1) * ((2.0 / 3.0) - $temp3) * 6.0;
3152 } else {
3153 $rgb[$k] = $temp1;
3154 }
3155 }
3156 }
3157
3158 $rgb["r"] = round($rgb["r"] * 255);
3159 $rgb["g"] = round($rgb["g"] * 255);
3160 $rgb["b"] = round($rgb["b"] * 255);
3161
3162 return $rgb;
3163 }
3164
3165 //
3166 // Media queries
3167 //
3168
3172
3176 public function getMediaQueries()
3177 {
3178 $ilDB = $this->db;
3179
3180 $set = $ilDB->query("SELECT * FROM sty_media_query WHERE " .
3181 "style_id = " . $ilDB->quote($this->getId(), "integer") . " " .
3182 "ORDER BY order_nr");
3183
3184 $mq = array();
3185 while ($rec = $ilDB->fetchAssoc($set)) {
3186 $mq[] = $rec;
3187 }
3188
3189 return $mq;
3190 }
3191
3196 public function addMediaQuery($a_mquery, $order_nr = 0)
3197 {
3198 $ilDB = $this->db;
3199
3200 $id = $ilDB->nextId("sty_media_query");
3201 if ($order_nr == 0) {
3202 $order_nr = $this->getMaxMQueryOrderNr() + 10;
3203 }
3204
3205 $ilDB->manipulate("INSERT INTO sty_media_query (id, style_id, mquery, order_nr)" .
3206 " VALUES (" .
3207 $ilDB->quote($id, "integer") . "," .
3208 $ilDB->quote($this->getId(), "integer") . "," .
3209 $ilDB->quote($a_mquery, "text") . "," .
3210 $ilDB->quote($order_nr, "integer") .
3211 ")");
3212
3213 return $id;
3214 }
3215
3220 public function getMaxMQueryOrderNr()
3221 {
3222 $ilDB = $this->db;
3223
3224 $set = $ilDB->query(
3225 "SELECT max(order_nr) mnr FROM sty_media_query " .
3226 " WHERE style_id = " . $ilDB->quote($this->getId(), "integer")
3227 );
3228 $rec = $ilDB->fetchAssoc($set);
3229
3230 return (int) $rec["mnr"];
3231 }
3232
3239 public function updateMediaQuery($a_id, $a_mquery)
3240 {
3241 $ilDB = $this->db;
3242
3243 $ilDB->manipulate(
3244 "UPDATE sty_media_query SET " .
3245 " mquery = " . $ilDB->quote($a_mquery, "text") .
3246 " WHERE id = " . $ilDB->quote($a_id, "integer")
3247 );
3248 }
3249
3256 public function getMediaQueryForId($a_id)
3257 {
3258 $ilDB = $this->db;
3259
3260 $set = $ilDB->query(
3261 "SELECT * FROM sty_media_query " .
3262 " WHERE id = " . $ilDB->quote($a_id, "integer")
3263 );
3264 return $ilDB->fetchAssoc($set);
3265 }
3266
3272 public function deleteMediaQuery($a_id)
3273 {
3274 $ilDB = $this->db;
3275
3276 $ilDB->manipulate(
3277 "DELETE FROM sty_media_query WHERE " .
3278 " style_id = " . $ilDB->quote($this->getId(), "integer") .
3279 " AND id = " . $ilDB->quote($a_id, "integer")
3280 );
3281 $this->saveMediaQueryOrder();
3282 }
3283
3289 public function saveMediaQueryOrder($a_order_nr = null)
3290 {
3291 $ilDB = $this->db;
3292
3293 $mqueries = $this->getMediaQueries();
3294 if (is_array($a_order_nr)) {
3295 foreach ($mqueries as $k => $mq) {
3296 $mqueries[$k]["order_nr"] = $a_order_nr[$mq["id"]];
3297 }
3298 $mqueries = ilUtil::sortArray($mqueries, "order_nr", "", true);
3299 }
3300 $cnt = 10;
3301 foreach ($mqueries as $mq) {
3302 $ilDB->manipulate(
3303 "UPDATE sty_media_query SET " .
3304 " order_nr = " . $ilDB->quote($cnt, "integer") .
3305 " WHERE id = " . $ilDB->quote($mq["id"], "integer")
3306 );
3307 $cnt += 10;
3308 }
3309 }
3310
3311
3312 //
3313 // Table template management
3314 //
3315
3319 public function getTemplates($a_type)
3320 {
3321 $ilDB = $this->db;
3322
3323 $set = $ilDB->query("SELECT * FROM style_template WHERE " .
3324 "style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
3325 "temp_type = " . $ilDB->quote($a_type, "text") . " " .
3326 "ORDER BY name");
3327
3328 $templates = array();
3329 while ($rec = $ilDB->fetchAssoc($set)) {
3330 $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3331 $templates[] = $rec;
3332 }
3333
3334 return $templates;
3335 }
3336
3340 public function getTemplateClasses($a_tid)
3341 {
3342 $ilDB = $this->db;
3343 $set = $ilDB->query("SELECT * FROM style_template_class WHERE " .
3344 "template_id = " . $ilDB->quote($a_tid, "integer"));
3345
3346 $class = array();
3347 while ($rec = $ilDB->fetchAssoc($set)) {
3348 $key = $rec["class_type"];
3349 $class[$key] = $rec["class"];
3350 }
3351
3352 return $class;
3353 }
3354
3355
3359 public function addTemplate($a_type, $a_name, $a_classes)
3360 {
3361 $ilDB = $this->db;
3362
3363 $tid = $ilDB->nextId("style_template");
3364 $ilDB->manipulate($q = "INSERT INTO style_template " .
3365 "(id, style_id, name, temp_type)" .
3366 " VALUES (" .
3367 $ilDB->quote($tid, "integer") . "," .
3368 $ilDB->quote($this->getId(), "integer") . "," .
3369 $ilDB->quote($a_name, "text") . "," .
3370 $ilDB->quote($a_type, "text") .
3371 ")");
3372
3373 foreach ($a_classes as $t => $c) {
3374 $ilDB->manipulate($q = "INSERT INTO style_template_class " .
3375 "(template_id, class_type, class)" .
3376 " VALUES (" .
3377 $ilDB->quote($tid, "integer") . "," .
3378 $ilDB->quote($t, "text") . "," .
3379 $ilDB->quote($c, "text") .
3380 ")");
3381 }
3382
3383 include_once("./Services/Style/Content/classes/class.ilObjStyleSheetGUI.php");
3384 $this->writeTemplatePreview(
3385 $tid,
3386 ilObjStyleSheetGUI::_getTemplatePreview($this, $a_type, $tid, true)
3387 );
3388
3389 return $tid;
3390 }
3391
3395 public function updateTemplate($a_t_id, $a_name, $a_classes)
3396 {
3397 $ilDB = $this->db;
3398
3399 $ilDB->manipulate("UPDATE style_template SET " .
3400 "name = " . $ilDB->quote($a_name, "text") .
3401 " WHERE id = " . $ilDB->quote($a_t_id, "integer"));
3402
3403 $ilDB->manipulate(
3404 "DELETE FROM style_template_class WHERE " .
3405 "template_id = " . $ilDB->quote($a_t_id, "integer")
3406 );
3407 foreach ($a_classes as $t => $c) {
3408 $ilDB->manipulate($q = "INSERT INTO style_template_class " .
3409 "(template_id, class_type, class)" .
3410 " VALUES (" .
3411 $ilDB->quote($a_t_id, "integer") . "," .
3412 $ilDB->quote($t, "text") . "," .
3413 $ilDB->quote($c, "text") .
3414 ")");
3415 }
3416 }
3417
3421 public function addTemplateClass($a_t_id, $a_type, $a_class)
3422 {
3423 $ilDB = $this->db;
3424
3425 $ilDB->manipulate($q = "INSERT INTO style_template_class " .
3426 "(template_id, class_type, class)" .
3427 " VALUES (" .
3428 $ilDB->quote($a_t_id, "integer") . "," .
3429 $ilDB->quote($a_type, "text") . "," .
3430 $ilDB->quote($a_class, "text") .
3431 ")");
3432 }
3433
3434
3438 public function templateExists($a_template_name)
3439 {
3440 $ilDB = $this->db;
3441
3442 $set = $ilDB->query("SELECT * FROM style_template WHERE " .
3443 "style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
3444 "name = " . $ilDB->quote($a_template_name, "text"));
3445 if ($rec = $ilDB->fetchAssoc($set)) {
3446 return true;
3447 }
3448 return false;
3449 }
3450
3454 public function getTemplate($a_t_id)
3455 {
3456 $ilDB = $this->db;
3457
3458 $set = $ilDB->query("SELECT * FROM style_template WHERE " .
3459 "style_id = " . $ilDB->quote($this->getId(), "integer") . " " .
3460 " AND id = " . $ilDB->quote($a_t_id, "integer"));
3461
3462 if ($rec = $ilDB->fetchAssoc($set)) {
3463 $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3464
3465 $template = $rec;
3466 return $template;
3467 }
3468 return array();
3469 }
3470
3474 public function lookupTemplateName($a_t_id)
3475 {
3476 return self::_lookupTemplateName($a_t_id);
3477 }
3478
3482 public static function _lookupTemplateName($a_t_id)
3483 {
3484 global $DIC;
3485
3486 $ilDB = $DIC->database();
3487
3488 $set = $ilDB->query("SELECT name FROM style_template WHERE " .
3489 " id = " . $ilDB->quote($a_t_id, "integer"));
3490
3491 if ($rec = $ilDB->fetchAssoc($set)) {
3492 return $rec["name"];
3493 }
3494
3495 return false;
3496 }
3497
3501 public function getTemplateXML()
3502 {
3503 $ilDB = $this->db;
3504
3505 $tag = "<StyleTemplates>";
3506
3507 $ttypes = array("table", "vaccordion", "haccordion", "carousel");
3508
3509 foreach ($ttypes as $ttype) {
3510 $ts = $this->getTemplates($ttype);
3511
3512 foreach ($ts as $t) {
3514 /*$atts = array("table" => "TableClass",
3515 "caption" => "CaptionClass",
3516 "row_head" => "RowHeadClass",
3517 "row_foot" => "RowFootClass",
3518 "col_head" => "ColHeadClass",
3519 "col_foot" => "ColFootClass",
3520 "odd_row" => "OddRowClass",
3521 "even_row" => "EvenRowClass",
3522 "odd_col" => "OddColClass",
3523 "even_col" => "EvenColClass");*/
3524 $c = $t["classes"];
3525
3526 $tag .= '<StyleTemplate Name="' . $t["name"] . '">';
3527
3528 foreach ($atts as $type => $t) {
3529 if ($c[$type] != "") {
3530 $tag .= '<StyleClass Type="' . $type . '" Value="' . $c[$type] . '" />';
3531 }
3532 }
3533
3534 $tag .= "</StyleTemplate>";
3535 }
3536 }
3537
3538 $tag .= "</StyleTemplates>";
3539
3540 //echo htmlentities($tag);
3541 return $tag;
3542 }
3543
3547 public function writeTemplatePreview($a_t_id, $a_preview_html)
3548 {
3549 $ilDB = $this->db;
3550 $a_preview_html = str_replace(' width=""', "", $a_preview_html);
3551 $a_preview_html = str_replace(' valign="top"', "", $a_preview_html);
3552 $a_preview_html = str_replace('<div class="ilc_text_block_TableContent">', "<div>", $a_preview_html);
3553 //echo "1-".strlen($a_preview_html)."-";
3554 //echo htmlentities($a_preview_html);
3555 if (strlen($a_preview_html) > 4000) {
3556 //echo "2";
3557 $a_preview_html = "";
3558 }
3559 $ilDB->manipulate("UPDATE style_template SET " .
3560 "preview = " . $ilDB->quote($a_preview_html, "text") .
3561 " WHERE id = " . $ilDB->quote($a_t_id, "integer"));
3562 }
3563
3567 public function lookupTemplatePreview($a_t_id)
3568 {
3569 $ilDB = $this->db;
3570
3571 $set = $ilDB->query("SELECT preview FROM style_template " .
3572 " WHERE id = " . $ilDB->quote($a_t_id, "integer"));
3573 if ($rec = $ilDB->fetchAssoc($set)) {
3574 return $rec["preview"];
3575 }
3576
3577 return "";
3578 }
3579
3583 public static function _lookupTemplateIdByName($a_style_id, $a_name)
3584 {
3585 global $DIC;
3586
3587 $ilDB = $DIC->database();
3588
3589 $set = $ilDB->query("SELECT id FROM style_template " .
3590 " WHERE style_id = " . $ilDB->quote($a_style_id, "integer") .
3591 " AND name = " . $ilDB->quote($a_name, "text"));
3592 if ($rec = $ilDB->fetchAssoc($set)) {
3593 return $rec["id"];
3594 }
3595
3596 return false;
3597 }
3598
3602 public function removeTemplate($a_t_id)
3603 {
3604 $ilDB = $this->db;
3605
3606 $ilDB->manipulate("DELETE FROM style_template WHERE " .
3607 " style_id = " . $ilDB->quote($this->getId(), "integer") . " AND " .
3608 " id = " . $ilDB->quote($a_t_id, "integer"));
3609
3610 $ilDB->manipulate(
3611 "DELETE FROM style_template_class WHERE " .
3612 "template_id = " . $ilDB->quote($a_t_id, "integer")
3613 );
3614 }
3615
3619 public function writeStyleSetting($a_name, $a_value)
3620 {
3621 $ilDB = $this->db;
3622
3623 $ilDB->manipulate(
3624 "DELETE FROM style_setting WHERE " .
3625 " style_id = " . $ilDB->quote($this->getId(), "integer") .
3626 " AND name = " . $ilDB->quote($a_name, "text")
3627 );
3628
3629 $ilDB->manipulate("INSERT INTO style_setting " .
3630 "(style_id, name, value) VALUES (" .
3631 $ilDB->quote($this->getId(), "integer") . "," .
3632 $ilDB->quote($a_name, "text") . "," .
3633 $ilDB->quote($a_value, "text") .
3634 ")");
3635 }
3636
3640 public function lookupStyleSetting($a_name)
3641 {
3642 $ilDB = $this->db;
3643
3644 $set = $ilDB->query(
3645 "SELECT value FROM style_setting " .
3646 " WHERE style_id = " . $ilDB->quote($this->getId(), "integer") .
3647 " AND name = " . $ilDB->quote($a_name, "text")
3648 );
3649 $rec = $ilDB->fetchAssoc($set);
3650
3651 return $rec["value"];
3652 }
3653
3657 public static function writeStyleUsage($a_obj_id, $a_style_id)
3658 {
3659 global $DIC;
3660
3661 $ilDB = $DIC->database();
3662
3663 $ilDB->replace(
3664 "style_usage",
3665 array(
3666 "obj_id" => array("integer", (int) $a_obj_id)),
3667 array(
3668 "style_id" => array("integer", (int) $a_style_id))
3669 );
3670 }
3671
3675 public static function lookupObjectStyle($a_obj_id)
3676 {
3677 global $DIC;
3678
3679 $ilDB = $DIC->database();
3680
3681 $set = $ilDB->query(
3682 "SELECT style_id FROM style_usage " .
3683 " WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer")
3684 );
3685 $rec = $ilDB->fetchAssoc($set);
3686
3687 if (ilObject::_lookupType($rec["style_id"]) == "sty") {
3688 return (int) $rec["style_id"];
3689 }
3690
3691 return 0;
3692 }
3693
3697 public static function lookupObjectForStyle($a_style_id)
3698 {
3699 global $DIC;
3700
3701 $ilDB = $DIC->database();
3702
3703 $obj_ids = array();
3704 if (ilObject::_lookupType($a_style_id) == "sty") {
3705 $set = $ilDB->query(
3706 "SELECT DISTINCT obj_id FROM style_usage " .
3707 " WHERE style_id = " . $ilDB->quote($a_style_id, "integer")
3708 );
3709
3710 while ($rec = $ilDB->fetchAssoc($set)) {
3711 $obj_ids[] = $rec["obj_id"];
3712 }
3713 }
3714 return $obj_ids;
3715 }
3716}
An exception for terminatinating execution or to throw for unit testing.
static _lookupContObjIdByStyleId($a_style_id)
lookup style sheet ID
static _deleteStyleAssignments($a_style_id)
delete all style references to style
static _getTemplatePreview($a_style, $a_type, $a_t_id, $a_small_mode=false)
Get table template preview.
Class ilObjStyleSheet.
static getBasicZipPath()
Get basic zip path.
setExportSubDir($a_dir)
Set local directory, that will be included within the zip file.
static _lookupActive($a_id)
Lookup active flag.
static _lookupStandard($a_id)
Lookup standard flag.
getMediaQueries()
Get colors of style.
getMaxMQueryOrderNr()
Get maximum media query order nr.
export()
Create export file.
getRefId()
Get ref id (show error message, since styles do not use ref ids)
static _getStyleParameterInputType($par)
static getBasicImageDir()
Get basic image dir.
updateTemplate($a_t_id, $a_name, $a_classes)
Update table template.
static getContentPrintStyle()
get content print style
addMediaQuery($a_mquery, $order_nr=0)
Add media query.
getColorCodeForName($a_name)
Remove a color.
deleteMediaQuery($a_id)
Delete media query.
do_3_9_Migration($a_id)
Migrate old 3.9 styles.
getCharacteristics($a_type="", $a_no_hidden=false, $a_include_core=true)
Get characteristics.
writeTemplatePreview($a_t_id, $a_preview_html)
Write table template preview.
read()
read style properties
static _getTemplateClassTypes($a_template_type="")
Get template class types.
deleteStylePar($a_tag, $a_class, $a_par, $a_type, $a_mq_id=0, $a_custom=false)
Delete style parameter by tag/class/parameter.
static _getClonableContentStyles()
Get all clonable styles (active standard styles and individual learning module styles with write perm...
addColor($a_name, $a_code)
Add color.
createReference()
Create a reference (show error message, since styles do not use ref ids)
static _lookupUpToDate($a_id)
Looup up to date.
static _replaceStylePar($style_id, $a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id=0, $a_custom=false)
createExportDirectory()
Create export directory.
update()
update object in db
static _getStyleParameters($a_tag="")
putInTree($a_parent_ref)
Put in tree (show error message, since styles do not use ref ids)
static _HLSToRGB($a_hls)
HLS to RGB (both arrays, 0..255)
getParametersOfClass($a_type, $a_class, $a_mq_id=0)
Get parameters of class.
updateStyleParameter($a_id, $a_value)
update style parameter per id
uploadImage($a_file)
Upload image.
copyImagesToDir($a_target)
Copy images to directory.
createFromXMLFile($a_file, $a_skip_parent_create=false)
create style from xml file todo: add mq_id and custom
static lookupObjectForStyle($a_style_id)
Lookup object style.
characteristicExists($a_char, $a_style_type)
Check whether characteristic exists.
saveMediaQueryOrder($a_order_nr=null)
Save media query order.
addCharacteristic($a_type, $a_char, $a_hidden=false)
Add characteristic.
lookupTemplateName($a_t_id)
Lookup table template name for template ID.
getImagesDirectory()
Get images directory.
addTemplateClass($a_t_id, $a_type, $a_class)
Update table template.
getTemplates($a_type)
Get table templates of style.
removeColor($a_name)
Remove a color.
do_3_10_CharMigration($a_id="")
This is more or less a copy of Services/Migration/DBUpdate_1385/classes ilStyleMigration->addMissingS...
static getAvailableParameters()
Get available parameters.
updateMediaQuery($a_id, $a_mquery)
Update media query.
ilClone()
clone style sheet (note: styles have no ref ids and return an object id)
static _writeStandard($a_id, $a_std)
Write standard flag.
exportXML($a_dir)
export style xml file to directory
static _isExpandable($a_type)
setStyle($a_style)
set styles
cleanExportDirectory()
Clear export directory.
static lookupObjectStyle($a_obj_id)
Lookup object style.
handleXmlString($a_str)
Handle xml strin.
__construct($a_id=0, $a_call_by_reference=false)
Constructor @access public.
deleteCustomStylePars($a_tag, $a_class, $a_type, $a_mq_id=0)
Delete style parameter by tag/class/parameter.
& getMetaData()
get meta data object
addParameter($a_tag, $a_par, $a_type, $a_mq_id=0, $a_custom=false)
write style parameter to db
static _getColorFlavor($a_rgb, $a_i)
Get color flavor.
replaceStylePar($a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id=0, $a_custom=false)
Set style parameter per tag/class/parameter.
static _getStyleParameterNumericUnits($a_no_percentage=false)
static _createImagesDirectory($a_style_id)
Create images directory <data_dir>/sty/sty_<id>/images.
deleteParameter($a_id)
delete style parameter
getTemplateXML()
Get table template xml.
setRefId($a_ref_id)
Set ref id (show error message, since styles do not use ref ids)
setCharacteristics($a_chars)
Set characteristics.
static _getPseudoClasses($tag)
saveHideStatus($a_type, $a_char, $a_hide)
Save characteristic hide status.
writeStyleSetting($a_name, $a_value)
Write Style Setting.
static _addMissingStyleClassesToStyle($a_id)
Add missing style classes to all styles.
static _RGBToHLS($a_rgb)
RGB to HLS (both arrays, 0..255)
static _isHideable($a_type)
getStyleParameterGroups()
Get grouped parameter.
lookupStyleSetting($a_name)
Lookup style setting.
getThumbnailsDirectory()
Get thumbnails directory.
getTemplateClasses($a_tid)
Get template classes.
getHideStatus($a_type, $a_char)
Get characteristic hide status.
lookupTemplatePreview($a_t_id)
Lookup table template preview.
create($a_from_style=0, $a_import_mode=false)
Create a new style.
static _getStyleParameterSubPar($par)
writeCSSFile($a_target_file="", $a_image_dir="")
write css file to webspace directory
static getSyntaxStylePath()
get syntax style path
colorExists($a_color_name)
Check whether color exists.
static _determineTag($a_type)
getUpToDate()
Get up to date.
removeTemplate($a_t_id)
Remove table template.
getExportSubDir()
The local directory, that will be included within the zip file.
getStyle()
todo: bad style! should return array of objects, not multi-dim-arrays
static _lookupTemplateIdByName($a_style_id, $a_name)
Lookup table template preview.
static _writeActive($a_id, $a_active)
Write active flag.
static _getStandardStyles( $a_exclude_default_style=false, $a_include_deactivated=false, $a_scope=0)
Get standard styles.
addTemplate($a_type, $a_name, $a_classes)
Add table template.
setScope($a_scope)
Set scope.
static _getStyleSuperTypeForType($a_type)
updateColor($a_name, $a_new_name, $a_code)
Update color.
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
getImages()
Get images of style.
getMediaQueryForId($a_id)
Get media query for id.
static getContentStylePath($a_style_id, $add_random=true, $add_token=true)
get content style path
static _lookupTemplateName($a_t_id)
Lookup table template name for template ID.
static _writeUpToDate($a_id, $a_up_to_date)
Write up to date.
do_3_10_Migration()
Migrates 3.10 style to 3.11 style.
copyCharacteristic( $a_from_style_id, $a_from_type, $a_from_char, $a_to_char)
Copy characteristic.
static isCoreStyle($a_type, $a_class)
Is core style.
static getPlaceHolderStylePath()
get placeholder style path (for Page Layouts)
createImportDirectory()
Create import directory.
deleteCharacteristic($a_type, $a_tag, $a_class)
Delete Characteristic.
getColors()
Get colors of style.
createImagesDirectory()
Create images directory <data_dir>/sty/sty_<id>/images.
getTemplate($a_t_id)
Get template.
assignMetaData(&$a_meta_data)
assign meta data object
setUpToDate($a_up_to_date=true)
Set style up to date (false + update will trigger css generation next time)
static _explodeRGB($a_rgb, $as_dec=false)
Explode an RGB string into an array.
static _getImagesDirectory($a_style_id)
Get images directory.
static _getStyleParameterValues($par)
static _writeScope($a_id, $a_scope)
Write scope.
deleteImage($a_file)
Delete an image.
static _getCoreStyles()
Get core styles.
static _addMissingStyleClassesToAllStyles($a_styles="")
Add missing style classes to all styles todo: add mq_id and custom handling.
static writeStyleUsage($a_obj_id, $a_style_id)
Write style usage.
createExportSubDirectory()
Create export directory.
getXML()
get xml representation of style object todo: add mq_id
static _getBasicStyleDom()
Get basic style dom.
templateExists($a_template_name)
Check whether template exists.
deleteStyleParOfChar($a_type, $a_class)
Delete style parameters of characteristic.
Class ilObject Basic functions for all objects.
getType()
get object type @access public
static _lookupTitle($a_id)
lookup object title
static _getAllReferences($a_id)
get all reference ids of object
getDescription()
get object description
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
getId()
get object id @access public
static _getObjectsDataForType($a_type, $a_omit_trash=false)
get all objects of a certain type
static _lookupType($a_id, $a_reference=false)
lookup object type
getTitle()
get object title @access public
static getDataDir()
get data directory (outside webspace)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static getWebspaceDir($mode="filesystem")
get webspace directory
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static resizeImage($a_from, $a_to, $a_width, $a_height, $a_constrain_prop=false)
resize image
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static unzip(string $path_to_zip_file, bool $overwrite_existing=false, bool $unpack_flat=false)
static makeDirParents($a_dir)
Create a new directory and all parent directories.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static signFile($path_to_file)
$c
Definition: cli.php:37
global $DIC
Definition: goto.php:24
$xml
Definition: metadata.php:332
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:17
$ilErr
Definition: raiseError.php:18
foreach($_POST as $key=> $value) $res
global $ilDB