ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
5 require_once "./Services/Object/classes/class.ilObject.php";
6 
16 {
17  var $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"));
245 
246  // style types and their super type
247  public static $style_super_types = array(
248  "text_block" => array("text_block", "heading1", "heading2", "heading3"),
249  "text_inline" => array("text_inline", "sub", "sup"),
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", "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  "text_inline" => "span",
290  "sup" => "sup",
291  "sub" => "sub",
292  "section" => "div",
293  "link" => "a",
294  "table" => "table",
295  "table_cell" => "td",
296  "table_caption" => "caption",
297  "media_cont" => "table",
298  "media_caption" => "div",
299  "iim" => "div",
300  "marker" => "a",
301  "glo_overlay" => "div",
302  "glo_ovtitle" => "h1",
303  "glo_ovclink" => "a",
304  "glo_ovuglink" => "a",
305  "glo_ovuglistlink" => "a",
306  "sco_title" => "div",
307  "sco_keyw" => "div",
308  "sco_desc" => "div",
309  "sco_obj" => "div",
310  "sco_desct" => "div",
311  "sco_objt" => "div",
312  "sco_fmess" => "div",
313  "rte_menu" => "div",
314  "rte_mlink" => "a",
315  "rte_tree" => "div",
316  "rte_tclink" => "a",
317  "rte_drag" => "div",
318  "rte_node" => "div",
319  "rte_status" => "div",
320  "rte_tlink" => "a",
321  "rte_tul" => "div",
322  "rte_tli" => "div",
323  "rte_texp" => "a",
324  "list_o" => "ol",
325  "list_u" => "ul",
326  "list_item" => "li",
327  "flist_cont" => "div",
328  "flist_head" => "div",
329  "flist" => "ul",
330  "flist_li" => "li",
331  "flist_a" => "a",
332  "question" => "div",
333  "qtitle" => "div",
334  "qanswer" => "div",
335  "qimg" => "img",
336  "qimgd" => "a",
337  "qordul" => "ul",
338  "qordli" => "li",
339  "qetitem" => "a",
340  "qetcorr" => "span",
341  "qinput" => "input",
342  "qlinput" => "textarea",
343  "qsubmit" => "input",
344  "qfeedr" => "div",
345  "qfeedw" => "div",
346  "qover" => "div",
347  "page_frame" => "div",
348  "page_cont" => "div",
349  "page_fn" => "div",
350  "page" => "div",
351  "page_tnav" => "div",
352  "page_bnav" => "div",
353  "page_lnav" => "div",
354  "page_rnav" => "div",
355  "page_lnavlink" => "a",
356  "page_rnavlink" => "a",
357  "page_lnavimage" => "img",
358  "page_rnavimage" => "img",
359  "page_title" => "h1",
360  "va_cntr" => "div",
361  "va_icntr" => "div",
362  "va_icont" => "div",
363  "va_ihead" => "div",
364  "va_iheada" => "div",
365  "va_ihcap" => "div",
366  "ha_cntr" => "div",
367  "ha_icntr" => "div",
368  "ha_icont" => "div",
369  "ha_iheada" => "div",
370  "ha_ihcap" => "div",
371  "ha_ihead" => "div",
372  "ca_cntr" => "div",
373  "ca_icntr" => "div",
374  "ca_ihead" => "div",
375  "ca_icont" => "div"
376  );
377 
378  // pseudo classes
379  public static $pseudo_classes =
380  array ("a" => array("hover"), "div" => array("hover"), "img" => array("hover"));
381 
382  // core styles these styles MUST exists -> see also basic_style/style.xml
383  public static $core_styles = array(
384  array("type" => "text_block", "class" => "Standard"),
385  array("type" => "text_block", "class" => "List"),
386  array("type" => "text_block", "class" => "TableContent"),
387  array("type" => "heading1", "class" => "Headline1"),
388  array("type" => "heading2", "class" => "Headline2"),
389  array("type" => "heading3", "class" => "Headline3"),
390  array("type" => "text_inline", "class" => "Comment"),
391  array("type" => "text_inline", "class" => "Emph"),
392  array("type" => "text_inline", "class" => "Quotation"),
393  array("type" => "text_inline", "class" => "Strong"),
394  array("type" => "text_inline", "class" => "Accent"),
395  array("type" => "text_inline", "class" => "Important"),
396  array("type" => "sup", "class" => "Sup"),
397  array("type" => "sub", "class" => "Sub"),
398  array("type" => "link", "class" => "IntLink"),
399  array("type" => "link", "class" => "ExtLink"),
400  array("type" => "link", "class" => "FootnoteLink"),
401  array("type" => "link", "class" => "FileLink"),
402  array("type" => "link", "class" => "GlossaryLink"),
403  array("type" => "media_cont", "class" => "MediaContainer"),
404  array("type" => "table", "class" => "StandardTable"),
405  array("type" => "media_caption", "class" => "MediaCaption"),
406  array("type" => "iim", "class" => "ContentPopup"),
407  array("type" => "marker", "class" => "Marker"),
408  array("type" => "page_frame", "class" => "PageFrame"),
409  array("type" => "page_cont", "class" => "PageContainer"),
410  array("type" => "page", "class" => "Page"),
411  array("type" => "page_tnav", "class" => "TopNavigation"),
412  array("type" => "page_bnav", "class" => "BottomNavigation"),
413  array("type" => "page_lnav", "class" => "LeftNavigation"),
414  array("type" => "page_rnav", "class" => "RightNavigation"),
415  array("type" => "page_lnavlink", "class" => "LeftNavigationLink"),
416  array("type" => "page_rnavlink", "class" => "RightNavigationLink"),
417  array("type" => "page_lnavimage", "class" => "LeftNavigationImage"),
418  array("type" => "page_rnavimage", "class" => "RightNavigationImage"),
419  array("type" => "page_fn", "class" => "Footnote"),
420  array("type" => "page_title", "class" => "PageTitle"),
421  array("type" => "glo_overlay", "class" => "GlossaryOverlay"),
422  array("type" => "glo_ovtitle", "class" => "GlossaryOvTitle"),
423  array("type" => "glo_ovclink", "class" => "GlossaryOvCloseLink"),
424  array("type" => "glo_ovuglink", "class" => "GlossaryOvUnitGloLink"),
425  array("type" => "glo_ovuglistlink", "class" => "GlossaryOvUGListLink"),
426  array("type" => "sco_title", "class" => "Title"),
427  array("type" => "sco_desc", "class" => "Description"),
428  array("type" => "sco_desct", "class" => "DescriptionTop"),
429  array("type" => "sco_keyw", "class" => "Keywords"),
430  array("type" => "sco_obj", "class" => "Objective"),
431  array("type" => "sco_objt", "class" => "ObjectiveTop"),
432  array("type" => "sco_fmess", "class" => "FinalMessage"),
433  array("type" => "rte_menu", "class" => "RTEMenu"),
434  array("type" => "rte_menu", "class" => "RTELogo"),
435  array("type" => "rte_menu", "class" => "RTELinkBar"),
436  array("type" => "rte_mlink", "class" => "RTELink"),
437  array("type" => "rte_mlink", "class" => "RTELinkDisabled"),
438  array("type" => "rte_tree", "class" => "RTETree"),
439  array("type" => "rte_node", "class" => "RTECourse"),
440  array("type" => "rte_node", "class" => "RTEChapter"),
441  array("type" => "rte_node", "class" => "RTESco"),
442  array("type" => "rte_node", "class" => "RTEAsset"),
443  array("type" => "rte_node", "class" => "RTECourseDisabled"),
444  array("type" => "rte_node", "class" => "RTEChapterDisabled"),
445  array("type" => "rte_node", "class" => "RTEScoDisabled"),
446  array("type" => "rte_node", "class" => "RTEAssetDisabled"),
447  array("type" => "rte_status", "class" => "RTEAsset"),
448  array("type" => "rte_status", "class" => "RTECompleted"),
449  array("type" => "rte_status", "class" => "RTENotAttempted"),
450  array("type" => "rte_status", "class" => "RTERunning"),
451  array("type" => "rte_status", "class" => "RTEIncomplete"),
452  array("type" => "rte_status", "class" => "RTEPassed"),
453  array("type" => "rte_status", "class" => "RTEFailed"),
454  array("type" => "rte_status", "class" => "RTEBrowsed"),
455  array("type" => "rte_tlink", "class" => "RTETreeLink"),
456  array("type" => "rte_tlink", "class" => "RTETreeLinkDisabled"),
457  array("type" => "rte_tlink", "class" => "RTETreeCurrent"),
458  array("type" => "rte_tul", "class" => "RTETreeList"),
459  array("type" => "rte_tli", "class" => "RTETreeItem"),
460  array("type" => "rte_texp", "class" => "RTETreeExpanded"),
461  array("type" => "rte_texp", "class" => "RTETreeCollapsed"),
462  array("type" => "rte_tree", "class" => "RTETreeControl"),
463  array("type" => "rte_tclink", "class" => "RTETreeControlLink"),
464  array("type" => "rte_drag", "class" => "RTEDragBar"),
465  array("type" => "list_o", "class" => "NumberedList"),
466  array("type" => "list_u", "class" => "BulletedList"),
467  array("type" => "list_item", "class" => "StandardListItem"),
468  array("type" => "question", "class" => "Standard"),
469  array("type" => "question", "class" => "SingleChoice"),
470  array("type" => "question", "class" => "MultipleChoice"),
471  array("type" => "question", "class" => "TextQuestion"),
472  array("type" => "question", "class" => "OrderingQuestion"),
473  array("type" => "question", "class" => "MatchingQuestion"),
474  array("type" => "question", "class" => "ImagemapQuestion"),
475  array("type" => "question", "class" => "ErrorText"),
476  array("type" => "question", "class" => "TextSubset"),
477  array("type" => "question", "class" => "ClozeTest"),
478  array("type" => "qtitle", "class" => "Title"),
479  array("type" => "qanswer", "class" => "Answer"),
480  array("type" => "qimg", "class" => "QuestionImage"),
481  array("type" => "qimgd", "class" => "ImageDetailsLink"),
482  array("type" => "qordul", "class" => "OrderList"),
483  array("type" => "qordli", "class" => "OrderListItem"),
484  array("type" => "qordul", "class" => "OrderListHorizontal"),
485  array("type" => "qordli", "class" => "OrderListItemHorizontal"),
486  array("type" => "qetitem", "class" => "ErrorTextItem"),
487  array("type" => "qetitem", "class" => "ErrorTextSelected"),
488  array("type" => "qetcorr", "class" => "ErrorTextCorrected"),
489  array("type" => "qinput", "class" => "TextInput"),
490  array("type" => "qlinput", "class" => "LongTextInput"),
491  array("type" => "qsubmit", "class" => "Submit"),
492  array("type" => "qfeedr", "class" => "FeedbackRight"),
493  array("type" => "qfeedw", "class" => "FeedbackWrong"),
494  array("type" => "qover", "class" => "Correct"),
495  array("type" => "qover", "class" => "Inorrect"),
496  array("type" => "qover", "class" => "StatusMessage"),
497  array("type" => "qover", "class" => "WrongAnswersMessage"),
498  array("type" => "flist_cont", "class" => "FileListContainer"),
499  array("type" => "flist_head", "class" => "FileListHeading"),
500  array("type" => "flist", "class" => "FileList"),
501  array("type" => "flist_li", "class" => "FileListItem"),
502  array("type" => "flist_a", "class" => "FileListItemLink")
503  );
504 
505  public static $templates = array(
506  "table" => array(
507  "table" => "table",
508  "caption" => "table_caption",
509  "row_head" => "table_cell",
510  "row_foot" => "table_cell",
511  "col_head" => "table_cell",
512  "col_foot" => "table_cell",
513  "odd_row" => "table_cell",
514  "even_row" => "table_cell",
515  "odd_col" => "table_cell",
516  "even_col" => "table_cell"),
517  "vaccordion" => array(
518  "va_cntr" => "va_cntr",
519  "va_icntr" => "va_icntr",
520  "va_ihead" => "va_ihead",
521  "va_iheada" => "va_iheada",
522  "va_ihcap" => "va_ihcap",
523  "va_icont" => "va_icont"
524  ),
525  "haccordion" => array(
526  "ha_cntr" => "ha_cntr",
527  "ha_icntr" => "ha_icntr",
528  "ha_ihead" => "ha_ihead",
529  "ha_iheada" => "ha_iheada",
530  "ha_ihcap" => "ha_ihcap",
531  "ha_icont" => "ha_icont"
532  ),
533  "carousel" => array(
534  "ca_cntr" => "ca_cntr",
535  "ca_icntr" => "ca_icntr",
536  "ca_ihead" => "ca_ihead",
537  "ca_icont" => "ca_icont"
538  )
539  );
540 
541  // basic style xml file, image directory and dom
542  protected static $basic_style_file = "./Services/Style/basic_style/style.xml";
543  protected static $basic_style_image_dir = "./Services/Style/basic_style/images";
544  protected static $basic_style_dom;
545 
552  function ilObjStyleSheet($a_id = 0, $a_call_by_reference = false)
553  {
554  $this->type = "sty";
555  $this->style = array();
556  if($a_call_by_reference)
557  {
558  $this->ilias->raiseError("Can't instantiate style object via reference id.",$this->ilias->error_obj->FATAL);
559  }
560 
561  parent::ilObject($a_id, false);
562  }
563 
567  function setRefId()
568  {
569  $this->ilias->raiseError("Operation ilObjStyleSheet::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
570  }
571 
575  function getRefId()
576  {
577  return "";
578  //$this->ilias->raiseError("Operation ilObjStyleSheet::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
579  }
580 
584  function putInTree()
585  {
586  $this->ilias->raiseError("Operation ilObjStyleSheet::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
587  }
588 
592  function createReference()
593  {
594  $this->ilias->raiseError("Operation ilObjStyleSheet::createReference() not allowed.",$this->ilias->error_obj->FATAL);
595  }
596 
600  function setUpToDate($a_up_to_date = true)
601  {
602  $this->up_to_date = $a_up_to_date;
603  }
604 
608  function getUpToDate()
609  {
610  return $this->up_to_date;
611  }
612 
616  function setScope($a_scope)
617  {
618  $this->scope = $a_scope;
619  }
620 
624  function getScope()
625  {
626  return $this->scope;
627  }
628 
632  function _writeUpToDate($a_id, $a_up_to_date)
633  {
634  global $ilDB;
635 
636  $q = "UPDATE style_data SET uptodate = ".
637  $ilDB->quote((int) $a_up_to_date, "integer").
638  " WHERE id = ".$ilDB->quote($a_id, "integer");
639  $ilDB->manipulate($q);
640  }
641 
645  function _lookupUpToDate($a_id)
646  {
647  global $ilDB;
648 
649  $q = "SELECT uptodate FROM style_data ".
650  " WHERE id = ".$ilDB->quote($a_id, "integer");
651  $res = $ilDB->query($q);
652  $sty = $ilDB->fetchAssoc($res);
653 
654  return (boolean) $sty["uptodate"];
655  }
656 
660  function _writeStandard($a_id, $a_std)
661  {
662  global $ilDB;
663 
664  $q = "UPDATE style_data SET standard = ".
665  $ilDB->quote((int) $a_std, "integer").
666  " WHERE id = ".$ilDB->quote($a_id, "integer");
667  $ilDB->manipulate($q);
668  }
669 
673  function _writeScope($a_id, $a_scope)
674  {
675  global $ilDB;
676 
677  $q = "UPDATE style_data SET category = ".
678  $ilDB->quote((int) $a_scope, "integer").
679  " WHERE id = ".$ilDB->quote($a_id, "integer");
680  $ilDB->manipulate($q);
681  }
682 
686  function _lookupStandard($a_id)
687  {
688  global $ilDB;
689 
690  $q = "SELECT * FROM style_data ".
691  " WHERE id = ".$ilDB->quote($a_id, "integer");
692  $res = $ilDB->query($q);
693  $sty = $ilDB->fetchAssoc($res);
694 
695  return (boolean) $sty["standard"];
696  }
697 
701  function _writeActive($a_id, $a_active)
702  {
703  global $ilDB;
704 
705  $q = "UPDATE style_data SET active = ".
706  $ilDB->quote((int) $a_active, "integer").
707  " WHERE id = ".$ilDB->quote($a_id, "integer");
708  $ilDB->manipulate($q);
709  }
710 
714  function _lookupActive($a_id)
715  {
716  global $ilDB;
717 
718  $q = "SELECT * FROM style_data ".
719  " WHERE id = ".$ilDB->quote($a_id, "integer");
720  $res = $ilDB->query($q);
721  $sty = $ilDB->fetchAssoc($res);
722 
723  return (boolean) $sty["active"];
724  }
725 
729  function _getStandardStyles($a_exclude_default_style = false,
730  $a_include_deactivated = false, $a_scope = 0)
731  {
732  global $ilDB, $ilias, $tree;
733 
734  $default_style = $ilias->getSetting("default_content_style_id");
735 
736  $and_str = "";
737  if (!$a_include_deactivated)
738  {
739  $and_str = " AND active = 1";
740  }
741 
742  $q = "SELECT * FROM style_data ".
743  " WHERE standard = 1".$and_str;
744  $res = $ilDB->query($q);
745  $styles = array();
746  while($sty = $ilDB->fetchAssoc($res))
747  {
748  if (!$a_exclude_default_style || $default_style != $sty["id"])
749  {
750  // check scope
751  if ($a_scope > 0 && $sty["category"] > 0)
752  {
753  if ($tree->isInTree($sty["category"]) &&
754  $tree->isInTree($a_scope))
755  {
756  $path = $tree->getPathId($a_scope);
757  if (!in_array($sty["category"], $path))
758  {
759  continue;
760  }
761  }
762  }
763  $styles[$sty["id"]] = ilObject::_lookupTitle($sty["id"]);
764  }
765  }
766 
767  return $styles;
768  }
769 
770 
776  {
777  global $ilAccess, $ilDB;
778 
779  $clonable_styles = array();
780 
781  $q = "SELECT * FROM style_data";
782  $style_set = $ilDB->query($q);
783  while($style_rec = $ilDB->fetchAssoc($style_set))
784  {
785  $clonable = false;
786  if ($style_rec["standard"] == 1)
787  {
788  if ($style_rec["active"] == 1)
789  {
790  $clonable = true;
791  }
792  }
793  else
794  {
795  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
796  $obj_ids = ilObjContentObject::_lookupContObjIdByStyleId($style_rec["id"]);
797  foreach($obj_ids as $id)
798  {
799  $ref = ilObject::_getAllReferences($id);
800  foreach($ref as $ref_id)
801  {
802  if ($ilAccess->checkAccess("write", "", $ref_id))
803  {
804  $clonable = true;
805  }
806  }
807  }
808  }
809  if ($clonable)
810  {
811  $clonable_styles[$style_rec["id"]] =
812  ilObject::_lookupTitle($style_rec["id"]);
813  }
814  }
815 
816  asort($clonable_styles);
817 
818  return $clonable_styles;
819  }
820 
824  function assignMetaData(&$a_meta_data)
825  {
826  $this->meta_data =& $a_meta_data;
827  }
828 
832  static function _getBasicStyleDom()
833  {
834  global $ilBench;
835 
836  if (!is_object(self::$basic_style_dom))
837  {
838  self::$basic_style_dom = new DOMDocument();
839  self::$basic_style_dom->load(self::$basic_style_file);
840  }
841 
842  return self::$basic_style_dom;
843  }
844 
848  function &getMetaData()
849  {
850  return $this->meta_data;
851  }
852 
856  function create($a_from_style = 0, $a_import_mode = false)
857  {
858  global $ilDB;
859 
860  parent::create();
861 
862  if ($a_from_style == 0)
863  {
864  if (!$a_import_mode)
865  {
866  // copy styles from basic style
867  $this->createFromXMLFile(self::$basic_style_file, true);
868 
869  // copy images from basic style
870  $this->createImagesDirectory();
871  ilUtil::rCopy(self::$basic_style_image_dir,
872  $this->getImagesDirectory());
873  }
874  else
875  {
876  // add style_data record
877  $q = "INSERT INTO style_data (id, uptodate, category) VALUES ".
878  "(".$ilDB->quote($this->getId(), "integer").", 0,".
879  $ilDB->quote((int) $this->getScope(), "integer").")";
880  $ilDB->manipulate($q);
882  }
883  }
884  else
885  {
886  // get style parameter records
887  $def = array();
888  $q = "SELECT * FROM style_parameter WHERE style_id = ".
889  $ilDB->quote($a_from_style, "integer");
890  $par_set = $ilDB->query($q);
891  while($par_rec = $ilDB->fetchAssoc($par_set))
892  {
893  $def[] = array("tag" => $par_rec["tag"], "class" => $par_rec["class"],
894  "parameter" => $par_rec["parameter"], "value" => $par_rec["value"],
895  "type" => $par_rec["type"], "mq_id" => $par_rec["mq_id"], "custom" => $par_rec["custom"]);
896  }
897 
898  // get style characteristics records
899  $chars = array();
900  $q = "SELECT * FROM style_char WHERE style_id = ".
901  $ilDB->quote($a_from_style, "integer");
902  $par_set = $ilDB->query($q);
903  while($par_rec = $ilDB->fetchAssoc($par_set))
904  {
905  $chars[] = array("type" => $par_rec["type"], "characteristic" => $par_rec["characteristic"]);
906  }
907 
908 
909  // copy media queries
910  $from_style = new ilObjStyleSheet($a_from_style);
911  $mqs = $from_style->getMediaQueries();
912  $mq_mapping = array();
913  foreach ($mqs as $mq)
914  {
915  $nid = $this->addMediaQuery($mq["mquery"]);
916  $mq_mapping[$mq["id"]] = $nid;
917  }
918 
919  // default style settings
920  foreach ($def as $sty)
921  {
922  $id = $ilDB->nextId("style_parameter");
923  $q = "INSERT INTO style_parameter (id, style_id, tag, class, parameter, value, type, mq_id, custom) VALUES ".
924  "(".
925  $ilDB->quote($id, "integer").",".
926  $ilDB->quote($this->getId(), "integer").",".
927  $ilDB->quote($sty["tag"], "text").",".
928  $ilDB->quote($sty["class"], "text").",".
929  $ilDB->quote($sty["parameter"], "text").",".
930  $ilDB->quote($sty["value"], "text").",".
931  $ilDB->quote($sty["type"], "text").",".
932  $ilDB->quote((int) $mq_mapping[$sty["mq_id"]], "integer").",".
933  $ilDB->quote($sty["custom"], "integer").
934  ")";
935  $ilDB->manipulate($q);
936  }
937 
938  // insert style characteristics
939  foreach ($chars as $char)
940  {
941  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
942  "(".$ilDB->quote($this->getId(), "integer").",".
943  $ilDB->quote($char["type"], "text").",".
944  $ilDB->quote($char["characteristic"], "text").")";
945  $ilDB->manipulate($q);
946  }
947 
948  // add style_data record
949  $q = "INSERT INTO style_data (id, uptodate, category) VALUES ".
950  "(".$ilDB->quote($this->getId(), "integer").", 0,".
951  $ilDB->quote((int) $this->getScope(), "integer").")";
952  $ilDB->manipulate($q);
953 
954  // copy images
955  $this->createImagesDirectory();
956  ilUtil::rCopy($from_style->getImagesDirectory(),
957  $this->getImagesDirectory());
958 
959  // copy colors
960  $colors = $from_style->getColors();
961  foreach ($colors as $c)
962  {
963  $this->addColor($c["name"], $c["code"]);
964  }
965 
966  // copy templates
968  foreach ($tcts as $tct => $v)
969  {
970  $templates = $from_style->getTemplates($tct);
971  foreach ($templates as $t)
972  {
973  $this->addTemplate($tct, $t["name"], $t["classes"]);
974  }
975  }
976 
977  }
978 
979  $this->read();
980  if (!$a_import_mode)
981  {
982  $this->writeCSSFile();
983  }
984  }
985 
989  function deleteCharacteristic($a_type, $a_tag, $a_class)
990  {
991  global $ilDB;
992 
993  // check, if characteristic is not a core style
995  if (empty($core_styles[$a_type.".".$a_tag.".".$a_class]))
996  {
997  // delete characteristic record
998  $st = $ilDB->manipulateF(
999  "DELETE FROM style_char WHERE style_id = %s AND type = %s AND characteristic = %s",
1000  array("integer", "text", "text"),
1001  array($this->getId(), $a_type, $a_class));
1002 
1003  // delete parameter records
1004  $st = $ilDB->manipulateF("DELETE FROM style_parameter WHERE style_id = %s AND tag = %s AND type = %s AND class = %s",
1005  array("integer", "text", "text", "text"),
1006  array($this->getId(), $a_tag, $a_type, $a_class));
1007  }
1008 
1009  $this->setUpToDate(false);
1010  $this->_writeUpToDate($this->getId(), false);
1011  }
1012 
1016  function characteristicExists($a_char, $a_style_type)
1017  {
1018  global $ilDB;
1019 
1020  $set = $ilDB->queryF(
1021  "SELECT style_id FROM style_char WHERE style_id = %s AND characteristic = %s AND type = %s",
1022  array("integer", "text", "text"),
1023  array($this->getId(), $a_char, $a_style_type));
1024  if ($rec = $ilDB->fetchAssoc($set))
1025  {
1026  return true;
1027  }
1028  return false;
1029  }
1030 
1034  function addCharacteristic($a_type, $a_char, $a_hidden = false)
1035  {
1036  global $ilDB;
1037 
1038  // delete characteristic record
1039  $ilDB->manipulateF("INSERT INTO style_char (style_id, type, characteristic, hide)".
1040  " VALUES (%s,%s,%s,%s) ",
1041  array("integer", "text", "text", "integer"),
1042  array($this->getId(), $a_type, $a_char, $a_hidden));
1043 
1044  $this->setUpToDate(false);
1045  $this->_writeUpToDate($this->getId(), false);
1046  }
1047 
1054  function copyCharacteristic($a_from_style_id,
1055  $a_from_type, $a_from_char, $a_to_char)
1056  {
1057  global $ilDB;
1058 
1059  if (!$this->characteristicExists($a_to_char, $a_from_type))
1060  {
1061  $this->addCharacteristic($a_from_type, $a_to_char);
1062  }
1063  $this->deleteStyleParOfChar($a_from_type, $a_to_char);
1064 
1065  $from_style = new ilObjStyleSheet($a_from_style_id);
1066 
1067  // todo fix using mq_id
1068  $pars = $from_style->getParametersOfClass($a_from_type, $a_from_char);
1069 
1070  $colors = array();
1071  foreach ($pars as $p => $v)
1072  {
1073  if (substr($v, 0, 1) == "!")
1074  {
1075  $colors[] = substr($v, 1);
1076  }
1077  $this->replaceStylePar(ilObjStyleSheet::_determineTag($a_from_type),
1078  $a_to_char, $p, $v, $a_from_type);
1079  }
1080 
1081  // copy colors
1082  foreach ($colors as $c)
1083  {
1084  if (!$this->colorExists($c))
1085  {
1086  $this->addColor($c, $from_style->getColorCodeForName($c));
1087  }
1088  }
1089  }
1090 
1094  function getCharacteristics($a_type = "", $a_no_hidden = false)
1095  {
1096  $chars = array();
1097 
1098  if ($a_type == "")
1099  {
1100  $chars = $this->chars;
1101  }
1102  if (is_array($this->chars_by_type[$a_type]))
1103  {
1104  $chars = $this->chars_by_type[$a_type];
1105  }
1106 
1107  if ($a_no_hidden)
1108  {
1109  foreach ($chars as $k => $char)
1110  {
1111  if ($a_type == "" && $this->hidden_chars[$char["type"].":".$char["class"]])
1112  {
1113  unset($chars[$k]);
1114  }
1115  else if ($this->hidden_chars[$a_type.":".$char])
1116  {
1117  unset($chars[$k]);
1118  }
1119  }
1120  }
1121 
1122  return $chars;
1123  }
1124 
1128  function setCharacteristics($a_chars)
1129  {
1130  $this->chars = $a_chars;
1131  // $this->chars_by_type[$a_type];
1132  }
1133 
1137  function saveHideStatus($a_type, $a_char, $a_hide)
1138  {
1139  global $ilDB;
1140 
1141  $ilDB->manipulate("UPDATE style_char SET ".
1142  " hide = ".$ilDB->quote((int) $a_hide, "integer").
1143  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1144  " type = ".$ilDB->quote($a_type, "text")." AND ".
1145  " characteristic = ".$ilDB->quote($a_char, "text")
1146  );
1147  }
1148 
1152  function getHideStatus($a_type, $a_char)
1153  {
1154  global $ilDB;
1155 
1156  $set = $ilDB->query("SELECT hide FROM style_char ".
1157  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1158  " type = ".$ilDB->quote($a_type, "text")." AND ".
1159  " characteristic = ".$ilDB->quote($a_char, "text")
1160  );
1161  $rec = $ilDB->fetchAssoc($set);
1162 
1163  return $rec["hide"];
1164  }
1165 
1172  function ilClone()
1173  {
1174  global $log, $lng;
1175 
1176  $lng->loadLanguageModule("style");
1177 
1178  $new_obj = new ilObjStyleSheet();
1179  $new_obj->setTitle($this->getTitle()." (".$lng->txt("sty_acopy").")");
1180  $new_obj->setType($this->getType());
1181  $new_obj->setDescription($this->getDescription());
1182  $new_obj->create($this->getId());
1183 
1184  $new_obj->writeStyleSetting("disable_auto_margins",
1185  $this->lookupStyleSetting("disable_auto_margins"));
1186 
1187  return $new_obj->getId();
1188  }
1189 
1193  function copyImagesToDir($a_target)
1194  {
1195  ilUtil::rCopy($this->getImagesDirectory(), $a_target);
1196  }
1197 
1207  function addParameter($a_tag, $a_par, $a_type, $a_mq_id = 0, $a_custom = false)
1208  {
1209  global $ilDB;
1210 
1211  $avail_params = $this->getAvailableParameters();
1212  $tag = explode(".", $a_tag);
1213  $value = $avail_params[$a_par][0];
1214  $id = $ilDB->nextId("style_parameter");
1215  $q = "INSERT INTO style_parameter (id,style_id, type, tag, class, parameter, value, mq_id, custom) VALUES ".
1216  "(".
1217  $ilDB->quote($id, "integer").",".
1218  $ilDB->quote($this->getId(), "integer").",".
1219  $ilDB->quote($a_type, "text").",".
1220  $ilDB->quote($tag[0], "text").",".
1221  $ilDB->quote($tag[1], "text").",".
1222  $ilDB->quote($a_par, "text").",".
1223  $ilDB->quote($value, "text").",".
1224  $ilDB->quote($a_mq_id, "integer").",".
1225  $ilDB->quote($a_custom, "integer").
1226  ")";
1227  $ilDB->manipulate($q);
1228  $this->read();
1229  $this->writeCSSFile();
1230  }
1231 
1237  {
1239  }
1240 
1245  static function _createImagesDirectory($a_style_id)
1246  {
1247  global $ilErr;
1248 
1249  $sty_data_dir = ilUtil::getWebspaceDir()."/sty";
1250  ilUtil::makeDir($sty_data_dir);
1251  if(!is_writable($sty_data_dir))
1252  {
1253  $ilErr->raiseError("Style data directory (".$sty_data_dir
1254  .") not writeable.", $ilErr->FATAL);
1255  }
1256 
1257  $style_dir = $sty_data_dir."/sty_".$a_style_id;
1258  ilUtil::makeDir($style_dir);
1259  if(!@is_dir($style_dir))
1260  {
1261  $ilErr->raiseError("Creation of style directory failed (".
1262  $style_dir.").",$ilErr->FATAL);
1263  }
1264 
1265  // create images subdirectory
1266  $im_dir = $style_dir."/images";
1267  ilUtil::makeDir($im_dir);
1268  if(!@is_dir($im_dir))
1269  {
1270  $ilErr->raiseError("Creation of Import Directory failed (".
1271  $im_dir.").", $ilErr->FATAL);
1272  }
1273 
1274  // create thumbnails directory
1275  $thumb_dir = $style_dir."/images/thumbnails";
1276  ilUtil::makeDir($thumb_dir);
1277  if(!@is_dir($thumb_dir))
1278  {
1279  $ilErr->raiseError("Creation of Import Directory failed (".
1280  $thumb_dir.").", $ilErr->FATAL);
1281  }
1282  }
1283 
1288  {
1290  }
1291 
1295  static function _getImagesDirectory($a_style_id)
1296  {
1297  return ilUtil::getWebspaceDir()."/sty/sty_".$a_style_id.
1298  "/images";
1299  }
1300 
1305  {
1306  return $this->getImagesDirectory().
1307  "/thumbnails";
1308  }
1309 
1313  function getImages()
1314  {
1315  $dir = $this->getImagesDirectory();
1316  $images = array();
1317  if (is_dir($dir))
1318  {
1319  $entries = ilUtil::getDir($dir);
1320  foreach($entries as $entry)
1321  {
1322  if (substr($entry["entry"],0,1) == ".")
1323  {
1324  continue;
1325  }
1326  if ($entry["type"] != "dir")
1327  {
1328  $images[] = $entry;
1329  }
1330  }
1331  }
1332 
1333  return $images;
1334  }
1335 
1339  function uploadImage($a_file)
1340  {
1341  $this->createImagesDirectory();
1342  @ilUtil::moveUploadedFile($a_file["tmp_name"], $a_file["name"],
1343  $this->getImagesDirectory()."/".$a_file["name"]);
1344  @ilUtil::resizeImage($this->getImagesDirectory()."/".$a_file["name"],
1345  $this->getThumbnailsDirectory()."/".$a_file["name"], 75, 75);
1346  }
1347 
1351  function deleteImage($a_file)
1352  {
1353  if (is_file($this->getImagesDirectory()."/".$a_file))
1354  {
1355  unlink($this->getImagesDirectory()."/".$a_file);
1356  }
1357  if (is_file($this->getThumbnailsDirectory()."/".$a_file))
1358  {
1359  unlink($this->getThumbnailsDirectory()."/".$a_file);
1360  }
1361  }
1362 
1368  function deleteParameter($a_id)
1369  {
1370  global $ilDB;
1371 
1372  $q = "DELETE FROM style_parameter WHERE id = ".
1373  $ilDB->quote($a_id, "integer");
1374  $ilDB->query($q);
1375  }
1376 
1386  function deleteStylePar($a_tag, $a_class, $a_par, $a_type, $a_mq_id = 0, $a_custom = false)
1387  {
1388  global $ilDB;
1389 
1390  $q = "DELETE FROM style_parameter WHERE ".
1391  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1392  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1393  " class = ".$ilDB->quote($a_class, "text")." AND ".
1394  " mq_id = ".$ilDB->quote($a_mq_id, "integer")." AND ".
1395  " custom = ".$ilDB->quote($a_custom, "integer")." AND ".
1396  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1397  " parameter = ".$ilDB->quote($a_par, "text");
1398 
1399  $ilDB->manipulate($q);
1400  }
1401 
1411  function deleteCustomStylePars($a_tag, $a_class, $a_type, $a_mq_id = 0)
1412  {
1413  global $ilDB;
1414 
1415  $q = "DELETE FROM style_parameter WHERE ".
1416  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1417  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1418  " class = ".$ilDB->quote($a_class, "text")." AND ".
1419  " mq_id = ".$ilDB->quote($a_mq_id, "integer")." AND ".
1420  " custom = ".$ilDB->quote(1, "integer")." AND ".
1421  " ".$ilDB->equals("type", $a_type, "text", true);
1422 
1423  $ilDB->manipulate($q);
1424  }
1425 
1434  function deleteStyleParOfChar($a_type, $a_class)
1435  {
1436  global $ilDB;
1437 
1438  $q = "DELETE FROM style_parameter WHERE ".
1439  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1440  " class = ".$ilDB->quote($a_class, "text")." AND ".
1441  " ".$ilDB->equals("type", $a_type, "text", true);
1442 
1443  $ilDB->manipulate($q);
1444  }
1445 
1446 
1450  function delete()
1451  {
1452  global $ilDB;
1453 
1454  // delete object
1455  parent::delete();
1456 
1457  // check whether this style is global default
1458  $def_style = $this->ilias->getSetting("default_content_style_id");
1459  if ($def_style == $this->getId())
1460  {
1461  $this->ilias->deleteSetting("default_content_style_id");
1462  }
1463 
1464  // check whether this style is global fixed
1465  $fixed_style = $this->ilias->getSetting("fixed_content_style_id");
1466  if ($fixed_style == $this->getId())
1467  {
1468  $this->ilias->deleteSetting("fixed_content_style_id");
1469  }
1470 
1471  // delete style parameter
1472  $q = "DELETE FROM style_parameter WHERE style_id = ".
1473  $ilDB->quote($this->getId(), "integer");
1474  $ilDB->manipulate($q);
1475 
1476  // delete style file
1477  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1478  if (is_file($css_file_name))
1479  {
1480  unlink($css_file_name);
1481  }
1482 
1483  // delete media queries
1484  $ilDB->manipulate("DELETE FROM sty_media_query WHERE ".
1485  " style_id = ".$ilDB->quote($this->getId(), "integer")
1486  );
1487 
1488  // delete entries in learning modules
1489  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
1491 
1492  // delete style data record
1493  $q = "DELETE FROM style_data WHERE id = ".
1494  $ilDB->quote($this->getId(), "integer");
1495  $ilDB->manipulate($q);
1496 
1497  }
1498 
1499 
1503  function read()
1504  {
1505  global $ilDB;
1506 
1507  parent::read();
1508 
1509  $q = "SELECT * FROM style_parameter WHERE style_id = ".
1510  $ilDB->quote($this->getId(), "integer")." ORDER BY tag, class, type, mq_id ";
1511  $style_set = $ilDB->query($q);
1512  $ctag = "";
1513  $cclass = "";
1514  $ctype = "";
1515  $cmq_id = 0;
1516  $this->style = array();
1517  // workaround for bug #17586, see also http://stackoverflow.com/questions/3066356/multiple-css-classes-properties-overlapping-based-on-the-order-defined
1518  // e.g. ha_iheada must be written after ha_ihead, since they are acting on the same dom node
1519  // styles that must be added at the end
1520  $this->end_styles = array();
1521  while($style_rec = $ilDB->fetchAssoc($style_set))
1522  {
1523  if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass
1524  || $style_rec["type"] != $ctype || $style_rec["mq_id"] != $cmq_id)
1525  {
1526  // add current tag array to style array
1527  if(is_array($tag))
1528  {
1529  if (in_array($ctype, array("ha_iheada", "va_iheada")))
1530  {
1531  $this->end_styles[] = $tag;
1532  }
1533  else
1534  {
1535  $this->style[] = $tag;
1536  }
1537  }
1538  $tag = array();
1539  }
1540  $ctag = $style_rec["tag"];
1541  $cclass = $style_rec["class"];
1542  $ctype = $style_rec["type"];
1543  $cmq_id = $style_rec["mq_id"];
1544  $tag[] = $style_rec;
1545  // added $cmq_id
1546  $this->style_class[$ctype][$cclass][$cmq_id][$style_rec["parameter"]] = $style_rec["value"];
1547  }
1548  if(is_array($tag))
1549  {
1550  $this->style[] = $tag;
1551  }
1552  foreach ($this->end_styles as $s)
1553  {
1554  $this->style[] = $s;
1555  }
1556 //var_dump($this->style_class);
1557  $q = "SELECT * FROM style_data WHERE id = ".
1558  $ilDB->quote($this->getId(), "integer");
1559  $res = $ilDB->query($q);
1560  $sty = $ilDB->fetchAssoc($res);
1561  $this->setUpToDate((boolean) $sty["uptodate"]);
1562  $this->setScope($sty["category"]);
1563 
1564  // get style characteristics records
1565  $this->chars = array();
1566  $this->chars_by_type = array();
1567  $q = "SELECT * FROM style_char WHERE style_id = ".
1568  $ilDB->quote($this->getId(), "integer").
1569  " ORDER BY type ASC, characteristic ASC";
1570  $par_set = $ilDB->query($q);
1571  while($par_rec = $ilDB->fetchAssoc($par_set))
1572  {
1573  $this->chars[] = array("type" => $par_rec["type"], "class" => $par_rec["characteristic"], "hide" => $par_rec["hide"]);
1574  $this->chars_by_type[$par_rec["type"]][] = $par_rec["characteristic"];
1575  if ($par_rec["hide"])
1576  {
1577  $this->hidden_chars[$par_rec["type"].":".$par_rec["characteristic"]] = true;
1578  }
1579  }
1580 // var_dump($this->style); exit;
1581  }
1582 
1586  function writeCSSFile($a_target_file = "", $a_image_dir = "")
1587  {
1588  $style = $this->getStyle();
1589 
1590  if ($a_target_file == "")
1591  {
1592  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1593  }
1594  else
1595  {
1596  $css_file_name = $a_target_file;
1597  }
1598  $css_file = fopen($css_file_name, "w");
1599 
1600  $page_background = "";
1601 
1602  $mqs = array(array("mquery" => "", "id" => 0));
1603  foreach ($this->getMediaQueries() as $mq)
1604  {
1605  $mqs[] = $mq;
1606  }
1607 
1608  // iterate all media queries
1609  foreach ($mqs as $mq)
1610  {
1611  if ($mq["id"] > 0)
1612  {
1613  fwrite ($css_file, "@media ".$mq["mquery"]." {\n");
1614  }
1615  reset($style);
1616  foreach ($style as $tag)
1617  {
1618  if ($tag[0]["mq_id"] != $mq["id"])
1619  {
1620  continue;
1621  }
1622  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1623  if ($tag[0]["tag"] == "td")
1624  {
1625  fwrite ($css_file, ",th".".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1626  }
1627  if (in_array($tag[0]["tag"], array("h1", "h2", "h3")))
1628  {
1629  fwrite ($css_file, ",div.ilc_text_block_".$tag[0]["class"]."\n");
1630  fwrite ($css_file, ",body.ilc_text_block_".$tag[0]["class"]."\n");
1631  }
1632  if ($tag[0]["type"] == "text_block")
1633  {
1634  fwrite ($css_file, ",body.ilc_text_block_".$tag[0]["class"]."\n");
1635  }
1636  fwrite ($css_file, "{\n");
1637 
1638  // collect table border attributes
1639  $t_border = array();
1640 
1641  foreach($tag as $par)
1642  {
1643  $cur_par = $par["parameter"];
1644  $cur_val = $par["value"];
1645 
1646  // replace named colors
1647  if (is_int(strpos($cur_par, "color")) && substr(trim($cur_val), 0, 1) == "!")
1648  {
1649  $cur_val = $this->getColorCodeForName(substr($cur_val, 1));
1650  }
1651 
1652  if ($tag[0]["type"] == "table" && is_int(strpos($par["parameter"], "border")))
1653  {
1654  $t_border[$cur_par] = $cur_val;
1655  }
1656 
1657  if (in_array($cur_par, array("background-image", "list-style-image")))
1658  {
1659  if (is_int(strpos($cur_val, "/"))) // external
1660  {
1661  $cur_val = "url(".$cur_val.")";
1662  }
1663  else // internal
1664  {
1665  if ($a_image_dir == "")
1666  {
1667  $cur_val = "url(../sty/sty_".$this->getId()."/images/".$cur_val.")";
1668  }
1669  else
1670  {
1671  $cur_val = "url(".$a_image_dir."/".$cur_val.")";
1672  }
1673  }
1674  }
1675 
1676  if ($cur_par == "opacity")
1677  {
1678  $cur_val = ((int) $cur_val) / 100;
1679  }
1680 
1681  fwrite ($css_file, "\t".$cur_par.": ".$cur_val.";\n");
1682 
1683  // IE6 fix for minimum height
1684  if ($cur_par == "min-height")
1685  {
1686  fwrite ($css_file, "\t"."height".": "."auto !important".";\n");
1687  fwrite ($css_file, "\t"."height".": ".$cur_val.";\n");
1688  }
1689 
1690  // opacity fix
1691  if ($cur_par == "opacity")
1692  {
1693  fwrite ($css_file, "\t".'-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity='.($cur_val * 100).')"'.";\n");
1694  fwrite ($css_file, "\t".'filter: alpha(opacity='.($cur_val * 100).')'.";\n");
1695  fwrite ($css_file, "\t".'-moz-opacity: '.$cur_val.";\n");
1696  }
1697 
1698  // transform fix
1699  if ($cur_par == "transform")
1700  {
1701  fwrite ($css_file, "\t".'-webkit-transform: '.$cur_val.";\n");
1702  fwrite ($css_file, "\t".'-moz-transform: '.$cur_val.";\n");
1703  fwrite ($css_file, "\t".'-ms-transform: '.$cur_val.";\n");
1704  }
1705 
1706  // transform-origin fix
1707  if ($cur_par == "transform-origin")
1708  {
1709  fwrite ($css_file, "\t".'-webkit-transform-origin: '.$cur_val.";\n");
1710  fwrite ($css_file, "\t".'-moz-transform-origin: '.$cur_val.";\n");
1711  fwrite ($css_file, "\t".'-ms-transform-origin: '.$cur_val.";\n");
1712  }
1713 
1714  // save page background
1715  if ($tag[0]["tag"] == "div" && $tag[0]["class"] == "Page"
1716  && $cur_par == "background-color")
1717  {
1718  $page_background = $cur_val;
1719  }
1720  }
1721  fwrite ($css_file, "}\n");
1722  fwrite ($css_file, "\n");
1723 
1724  // use table border attributes for th td as well
1725  /* if ($tag[0]["type"] == "table")
1726  {
1727  if (count($t_border) > 0)
1728  {
1729  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." th,".
1730  $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." td\n");
1731  fwrite ($css_file, "{\n");
1732  foreach ($t_border as $p => $v)
1733  {
1734  // fwrite ($css_file, "\t".$p.": ".$v.";\n");
1735  }
1736  fwrite ($css_file, "}\n");
1737  fwrite ($css_file, "\n");
1738  }
1739  }*/
1740  }
1741 
1742  if ($page_background != "")
1743  {
1744  fwrite ($css_file, "td.ilc_Page\n");
1745  fwrite ($css_file, "{\n");
1746  fwrite ($css_file, "\t"."background-color: ".$page_background.";\n");
1747  fwrite ($css_file, "}\n");
1748  }
1749  if ($mq["id"] > 0)
1750  {
1751  fwrite ($css_file, "}\n");
1752  }
1753  }
1754  fclose($css_file);
1755 
1756  $this->setUpToDate(true);
1757  $this->_writeUpToDate($this->getId(), true);
1758  }
1759 
1766  static function getEffectiveContentStyleId($a_style_id, $a_type = "")
1767  {
1768  global $ilSetting;
1769 
1770  // check global fixed content style
1771  $fixed_style = $ilSetting->get("fixed_content_style_id");
1772  if ($fixed_style > 0)
1773  {
1774  $a_style_id = $fixed_style;
1775  }
1776 
1777  // check global default style
1778  if ($a_style_id <= 0)
1779  {
1780  $a_style_id = $ilSetting->get("default_content_style_id");
1781  }
1782 
1783  if ($a_style_id > 0 && ilObject::_lookupType($a_style_id) == "sty")
1784  {
1785  return $a_style_id;
1786  }
1787 
1788  return 0;
1789  }
1790 
1797  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  {
1801  return $this->style_class[$a_type][$a_class][$a_mq_id];
1802  }
1803  return array();
1804  }
1805 
1811  function getContentStylePath($a_style_id)
1812  {
1813  global $ilias;
1814 
1815  $rand = rand(1,999999);
1816 
1817 
1818  // check global fixed content style
1819  $fixed_style = $ilias->getSetting("fixed_content_style_id");
1820  if ($fixed_style > 0)
1821  {
1822  $a_style_id = $fixed_style;
1823  }
1824 
1825  // check global default style
1826  if ($a_style_id <= 0)
1827  {
1828  $a_style_id = $ilias->getSetting("default_content_style_id");
1829  }
1830 
1831  if ($a_style_id > 0 && ilObject::_exists($a_style_id))
1832  {
1833  // check whether file is up to date
1834  if (!ilObjStyleSheet::_lookupUpToDate($a_style_id))
1835  {
1836  $style = new ilObjStyleSheet($a_style_id);
1837  $style->writeCSSFile();
1838  }
1839 
1840  $path = ilUtil::getWebspaceDir("output") . "/css/style_" . $a_style_id . ".css?dummy=$rand";
1841  require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
1843 
1844  return $path;
1845  }
1846  else // todo: work this out
1847  {
1848  return "./Services/COPage/css/content.css";
1849  }
1850  }
1851 
1858  {
1859  return "./Services/COPage/css/print_content.css";
1860  }
1861 
1868  {
1869  return "./Services/COPage/css/syntaxhighlight.css";
1870  }
1871 
1878  {
1879  return "./Services/COPage/css/placeholder.css";
1880  }
1881 
1882  function update()
1883  {
1884  global $ilDB;
1885 
1886  parent::update();
1887  $this->read(); // this could be done better
1888  $this->writeCSSFile();
1889 
1890  $q = "UPDATE style_data ".
1891  "SET category = ".$ilDB->quote((int) $this->getScope(), "integer").
1892  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
1893  $ilDB->manipulate($q);
1894  }
1895 
1902  function updateStyleParameter($a_id, $a_value)
1903  {
1904  global $ilDB;
1905 
1906  $q = "UPDATE style_parameter SET VALUE = ".
1907  $ilDB->quote($a_value, "text")." WHERE id = ".
1908  $ilDB->quote($a_id, "integer");
1909  $style_set = $ilDB->manipulate($q);
1910  }
1911 
1916  // todo: search for usages, add mq_id
1917  function replaceStylePar($a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id = 0, $a_custom = false)
1918  {
1919  ilObjStyleSheet::_replaceStylePar($this->getId(), $a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id, $a_custom);
1920  }
1921 
1922  function _replaceStylePar($style_id, $a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id = 0, $a_custom = false)
1923  {
1924  global $ilDB;
1925 
1926  $q = "SELECT * FROM style_parameter WHERE ".
1927  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1928  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1929  " class = ".$ilDB->quote($a_class, "text")." AND ".
1930  " mq_id = ".$ilDB->quote($a_mq_id, "integer")." AND ".
1931  " custom = ".$ilDB->quote($a_custom, "integer")." AND ".
1932  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1933  " parameter = ".$ilDB->quote($a_par, "text");
1934 
1935  $set = $ilDB->query($q);
1936 
1937  if ($rec = $set->fetchRow())
1938  {
1939  $q = "UPDATE style_parameter SET ".
1940  " value = ".$ilDB->quote($a_val, "text")." WHERE ".
1941  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1942  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1943  " class = ".$ilDB->quote($a_class, "text")." AND ".
1944  " mq_id = ".$ilDB->quote($a_mq_id, "integer")." AND ".
1945  " custom = ".$ilDB->quote($a_custom, "integer")." AND ".
1946  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1947  " parameter = ".$ilDB->quote($a_par, "text");
1948 
1949  $ilDB->manipulate($q);
1950  }
1951  else
1952  {
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($this->getId(), "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  function getStyle()
1976  {
1977  return $this->style;
1978  }
1979 
1983  function setStyle($a_style)
1984  {
1985  $this->style = $a_style;
1986  }
1987 
1988 
1995  function handleXmlString($a_str)
1996  {
1997  return str_replace("&", "&amp;", $a_str);
1998  }
1999 
2004  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  {
2015  $xml.= "<Style Tag=\"".ilObjStyleSheet::_determineTag($char["type"]).
2016  "\" Type=\"".$char["type"]."\" Class=\"".$char["class"]."\">\n";
2017  foreach($this->style as $style)
2018  {
2019  if ($style[0]["type"] == $char["type"] && $style[0]["class"] == $char["class"])
2020  {
2021  foreach($style as $tag)
2022  {
2023  $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\" Custom=\"".$tag["custom"]."\" />\n";
2024  }
2025  }
2026  }
2027  $xml.= "</Style>\n";
2028  }
2029 
2030  // colors
2031  foreach($this->getColors() as $color)
2032  {
2033  $xml.="<StyleColor Name=\"".$color["name"]."\" Code=\"".$color["code"]."\"/>\n";
2034  }
2035 
2036  // templates
2038  foreach ($tcts as $tct => $v)
2039  {
2040  $ts = $this->getTemplates($tct);
2041 
2042  foreach ($ts as $t)
2043  {
2044  $xml.="<StyleTemplate Type=\"".$tct."\" Name=\"".$t["name"]."\">\n";
2045  foreach ($t["classes"] as $ct => $c)
2046  {
2047  if ($c != "")
2048  {
2049  $xml.="<StyleTemplateClass ClassType=\"".$ct."\" Class=\"".$c."\"/>\n";
2050  }
2051  }
2052  $xml.="</StyleTemplate>\n";
2053  }
2054  }
2055 
2056 
2057  $xml.= "</StyleSheet>";
2058 //echo "<pre>".htmlentities($xml)."</pre>"; exit;
2059  return $xml;
2060  }
2061 
2062 
2067  {
2068  $sty_data_dir = ilUtil::getDataDir()."/sty";
2069  ilUtil::makeDir($sty_data_dir);
2070  if(!is_writable($sty_data_dir))
2071  {
2072  $this->ilias->raiseError("Style data directory (".$sty_data_dir
2073  .") not writeable.",$this->ilias->error_obj->FATAL);
2074  }
2075 
2076  $style_dir = $sty_data_dir."/sty_".$this->getId();
2077  ilUtil::makeDir($style_dir);
2078  if(!@is_dir($style_dir))
2079  {
2080  $this->ilias->raiseError("Creation of style directory failed (".
2081  $style_dir.").",$this->ilias->error_obj->FATAL);
2082  }
2083 
2084  // create export subdirectory
2085  $ex_dir = $style_dir."/export";
2086  ilUtil::makeDir($ex_dir);
2087  if(!@is_dir($ex_dir))
2088  {
2089  $this->ilias->raiseError("Creation of Import Directory failed (".
2090  $ex_dir.").",$this->ilias->error_obj->FATAL);
2091  }
2092 
2093  return $ex_dir;
2094  }
2095 
2100  {
2101  $sty_data_dir = ilUtil::getDataDir()."/sty";
2102  $style_dir = $sty_data_dir."/sty_".$this->getId();
2103  // create export subdirectory
2104  $ex_dir = $style_dir."/export";
2105 
2106  if (is_dir($ex_dir))
2107  {
2108  ilUtil::delDir($ex_dir, true);
2109  }
2110  }
2111 
2112 
2117  {
2118  $ex_dir = $this->createExportDirectory();
2119  $ex_sub_dir = $ex_dir."/".$this->getExportSubDir();
2120  ilUtil::makeDir($ex_sub_dir);
2121  if(!is_writable($ex_sub_dir))
2122  {
2123  $this->ilias->raiseError("Style data directory (".$ex_sub_dir
2124  .") not writeable.",$this->ilias->error_obj->FATAL);
2125  }
2126  $ex_sub_images_dir = $ex_sub_dir."/images";
2127  ilUtil::makeDir($ex_sub_images_dir);
2128  if(!is_writable($ex_sub_images_dir))
2129  {
2130  $this->ilias->raiseError("Style data directory (".$ex_sub_images_dir
2131  .") not writeable.",$this->ilias->error_obj->FATAL);
2132  }
2133  }
2134 
2138  function setExportSubDir($a_dir)
2139  {
2140  $this->export_sub_dir = $a_dir;
2141  }
2142 
2146  function getExportSubDir()
2147  {
2148  if ($this->export_sub_dir == "")
2149  {
2150  return "sty_".$this->getId();
2151  }
2152  else
2153  {
2154  return $this->export_sub_dir;
2155  }
2156  }
2157 
2163  function export()
2164  {
2165  $this->cleanExportDirectory();
2166  $ex_dir = $this->createExportDirectory();
2167  $this->createExportSubDirectory();
2168  $this->exportXML($ex_dir."/".$this->getExportSubDir());
2169 //echo "-".$this->getImagesDirectory()."-".$ex_dir."/".$this->getExportSubDir()."/images"."-";
2171  $ex_dir."/".$this->getExportSubDir()."/images");
2172  if (is_file($ex_dir."/".$this->getExportSubDir().".zip"))
2173  {
2174  unlink($ex_dir."/".$this->getExportSubDir().".zip");
2175  }
2176  ilUtil::zip($ex_dir."/".$this->getExportSubDir(),
2177  $ex_dir."/".$this->getExportSubDir().".zip");
2178 
2179  return $ex_dir."/".$this->getExportSubDir().".zip";
2180  }
2181 
2185  function exportXML($a_dir)
2186  {
2187  $file = $a_dir."/style.xml";
2188 
2189  // open file
2190  if (!($fp = @fopen($file,"w")))
2191  {
2192  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2193  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2194  }
2195 
2196  // set file permissions
2197  chmod($file, 0770);
2198 
2199  // write xml data into the file
2200  fwrite($fp, $this->getXML());
2201 
2202  // close file
2203  fclose($fp);
2204 
2205  }
2206 
2211  {
2212  $sty_data_dir = ilUtil::getDataDir()."/sty";
2213  ilUtil::makeDir($sty_data_dir);
2214  if(!is_writable($sty_data_dir))
2215  {
2216  $this->ilias->raiseError("Style data directory (".$sty_data_dir
2217  .") not writeable.",$this->ilias->error_obj->FATAL);
2218  }
2219 
2220  $style_dir = $sty_data_dir."/sty_".$this->getId();
2221  ilUtil::makeDir($style_dir);
2222  if(!@is_dir($style_dir))
2223  {
2224  $this->ilias->raiseError("Creation of style directory failed (".
2225  $style_dir.").",$this->ilias->error_obj->FATAL);
2226  }
2227 
2228  // create import subdirectory
2229  $im_dir = $style_dir."/import";
2230  ilUtil::makeDir($im_dir);
2231  if(!@is_dir($im_dir))
2232  {
2233  $this->ilias->raiseError("Creation of Import Directory failed (".
2234  $im_dir.").",$this->ilias->error_obj->FATAL);
2235  }
2236 
2237  return $im_dir;
2238  }
2239 
2243  function import($a_file)
2244  {
2245  parent::create();
2246 
2247  $im_dir = $this->createImportDirectory();
2248 
2249  // handle uploaded files
2250  if (is_array($a_file))
2251  {
2252  ilUtil::moveUploadedFile($a_file["tmp_name"],
2253  $a_file["name"], $im_dir."/".$a_file["name"]);
2254  $file_name = $a_file["name"];
2255  }
2256  else // handle not directly uploaded files
2257  {
2258  $pi = pathinfo($a_file);
2259  $file_name = $pi["basename"];
2260  copy($a_file, $im_dir."/".$file_name);
2261  }
2262  $file = pathinfo($file_name);
2263 
2264  // unzip file
2265  if (strtolower($file["extension"] == "zip"))
2266  {
2267  ilUtil::unzip($im_dir."/".$file_name);
2268  $subdir = basename($file["basename"],".".$file["extension"]);
2269  if (!is_dir($im_dir."/".$subdir))
2270  {
2271  $subdir = "style"; // check style subdir
2272  }
2273  $xml_file = $im_dir."/".$subdir."/style.xml";
2274  }
2275  else // handle xml file directly (old style)
2276  {
2277  $xml_file = $im_dir."/".$file_name;
2278  }
2279 
2280  // load information from xml file
2281 //echo "-$xml_file-";
2282  $this->createFromXMLFile($xml_file, true);
2283 
2284  // copy images
2285  $this->createImagesDirectory();
2286  if (is_dir($im_dir."/".$subdir."/images"))
2287  {
2288  ilUtil::rCopy($im_dir."/".$subdir."/images",
2289  $this->getImagesDirectory());
2290  }
2291 
2293  $this->read();
2294  $this->writeCSSFile();
2295  }
2296 
2301  function createFromXMLFile($a_file, $a_skip_parent_create = false)
2302  {
2303  global $ilDB;
2304 
2305  $this->is_3_10_skin = false;
2306 
2307  if (!$a_skip_parent_create)
2308  {
2309  parent::create();
2310  }
2311  include_once("./Services/Style/classes/class.ilStyleImportParser.php");
2312  $importParser = new ilStyleImportParser($a_file, $this);
2313  $importParser->startParsing();
2314 
2315  // store style parameter
2316  foreach ($this->style as $style)
2317  {
2318  foreach($style as $tag)
2319  {
2320  $id = $ilDB->nextId("style_parameter");
2321 
2322  // migrate old table PageFrame/PageContainer to div
2323  if (in_array($tag["class"], array("PageFrame", "PageContainer")) &&
2324  $tag["tag"] == "table")
2325  {
2326  $tag["tag"] = "div";
2327  if ($tag["parameter"] == "width" && $tag["value"] == "100%")
2328  {
2329  continue;
2330  }
2331  }
2332 
2333  $q = "INSERT INTO style_parameter (id,style_id, tag, class, parameter, type, value, custom) VALUES ".
2334  "(".
2335  $ilDB->quote($id, "integer").",".
2336  $ilDB->quote($this->getId(), "integer").",".
2337  $ilDB->quote($tag["tag"], "text").",".
2338  $ilDB->quote($tag["class"], "text").",".
2339  $ilDB->quote($tag["parameter"], "text").",".
2340  $ilDB->quote($tag["type"], "text").",".
2341  $ilDB->quote($tag["value"], "text").",".
2342  $ilDB->quote((bool) $tag["custom"], "integer").
2343  ")";
2344  $ilDB->manipulate($q);
2345  }
2346  }
2347 
2348  // store characteristics
2349  $this->is_3_10_skin = true;
2350  if (is_array($this->chars))
2351  {
2352  foreach ($this->chars as $char)
2353  {
2354  if ($char["type"] != "")
2355  {
2356  $s = substr($char["class"], strlen($char["class"]) - 6);
2357  if ($s != ":hover")
2358  {
2359  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
2360  "(".$ilDB->quote($this->getId(), "integer").",".
2361  $ilDB->quote($char["type"], "text").",".
2362  $ilDB->quote($char["class"], "text").")";
2363  $ilDB->manipulate($q);
2364  $this->is_3_10_skin = false;
2365  }
2366  }
2367  }
2368  }
2369 
2370  // add style_data record
2371  $q = "INSERT INTO style_data (id, uptodate) VALUES ".
2372  "(".$ilDB->quote($this->getId(), "integer").", 0)";
2373  $ilDB->manipulate($q);
2374 
2375  $this->update();
2376  $this->read();
2377 
2378  if ($this->is_3_10_skin)
2379  {
2380  $this->do_3_10_Migration();
2381  }
2382  //$this->writeCSSFile();
2383  }
2384 
2389  {
2390  $groups = array();
2391 
2392  foreach (self::$parameter as $parameter => $props)
2393  {
2394  $groups[$props["group"]][] = $parameter;
2395  }
2396  return $groups;
2397  }
2398 
2399  static function _getStyleParameterInputType($par)
2400  {
2401  $input = self::$parameter[$par]["input"];
2402  return $input;
2403  }
2404 
2405  static function _getStyleParameterSubPar($par)
2406  {
2407  $subpar = self::$parameter[$par]["subpar"];
2408  return $subpar;
2409  }
2410 
2411  static function _getStyleParameters($a_tag = "")
2412  {
2413  if ($a_tag == "")
2414  {
2415  return self::$parameter;
2416  }
2417  $par = array();
2418  foreach (self::$parameter as $k => $v)
2419  {
2420  if (is_array(self::$filtered_groups[$v["group"]]) &&
2421  !in_array($a_tag, self::$filtered_groups[$v["group"]]))
2422  {
2423  continue;
2424  }
2425  $par[$k] = $v;
2426  }
2427  return $par;
2428  }
2429 
2430  static function _getFilteredGroups()
2431  {
2432  return self::$filtered_groups;
2433  }
2434 
2435  static function _getStyleParameterNumericUnits($a_no_percentage = false)
2436  {
2437  if ($a_no_percentage)
2438  {
2439  return self::$num_unit_no_perc;
2440  }
2441  return self::$num_unit;
2442  }
2443 
2444  static function _getStyleParameterValues($par)
2445  {
2446  return self::$parameter[$par]["values"];
2447  }
2448 
2449  /*static function _getStyleTypes()
2450  {
2451  return self::$style_types;
2452  }*/
2453 
2454  static function _getStyleSuperTypes()
2455  {
2456  return self::$style_super_types;
2457  }
2458 
2459  static function _isExpandable($a_type)
2460  {
2461  return in_array($a_type, self::$expandable_types);
2462  }
2463 
2464  static function _isHideable($a_type)
2465  {
2466  return in_array($a_type, self::$hideable_types);
2467  }
2468 
2469  static function _getStyleSuperTypeForType($a_type)
2470  {
2471  foreach (self::$style_super_types as $s => $t)
2472  {
2473  if (in_array($a_type, $t))
2474  {
2475  return $s;
2476  }
2477  if ($a_type == $s)
2478  {
2479  return $s;
2480  }
2481  }
2482  }
2483 
2487  static function _getCoreStyles()
2488  {
2489  $c_styles = array();
2490  foreach (self::$core_styles as $cstyle)
2491  {
2492  $c_styles[$cstyle["type"].".".ilObjStyleSheet::_determineTag($cstyle["type"]).".".$cstyle["class"]]
2493  = array("type" => $cstyle["type"],
2494  "tag" => ilObjStyleSheet::_determineTag($cstyle["type"]),
2495  "class" => $cstyle["class"]);
2496  }
2497  return $c_styles;
2498  }
2499 
2503  static function _getTemplateClassTypes($a_template_type = "")
2504  {
2505  if ($a_template_type == "")
2506  {
2507  return self::$templates;
2508  }
2509 
2510  return self::$templates[$a_template_type];
2511  }
2512 
2513 
2514  function _getPseudoClasses($tag)
2515  {
2516  return self::$pseudo_classes[$tag];
2517  }
2518 
2520  {
2521  return self::$templates[$t][$k];
2522  }
2523 
2524  static function _determineTag($a_type)
2525  {
2526  return self::$assigned_tags[$a_type];
2527  }
2528 
2532  static function getAvailableParameters()
2533  {
2534  $pars = array();
2535  foreach(self::$parameter as $p => $v)
2536  {
2537  $pars[$p] = $v["values"];
2538  }
2539 
2540  return $pars;
2541  }
2542 
2543 
2547  static function _addMissingStyleClassesToStyle($a_id)
2548  {
2549  $styles = array(array("id" => $a_id));
2551  }
2552 
2557  static function _addMissingStyleClassesToAllStyles($a_styles = "")
2558  {
2559  global $ilDB;
2560 
2561  if ($a_styles == "")
2562  {
2563  $styles = ilObject::_getObjectsDataForType("sty");
2564  }
2565  else
2566  {
2567  $styles = $a_styles;
2568  }
2571 
2572  // get all core image files
2573  $core_images = array();
2574  $core_dir = self::$basic_style_image_dir;
2575  if (is_dir($core_dir))
2576  {
2577  $dir = opendir($core_dir);
2578  while($file = readdir($dir))
2579  {
2580  if (substr($file, 0, 1) != "." && is_file($core_dir."/".$file))
2581  {
2582  $core_images[] = $file;
2583  }
2584  }
2585  }
2586 
2587  foreach ($styles as $style)
2588  {
2589  $id = $style["id"];
2590 
2591  foreach($core_styles as $cs)
2592  {
2593  // check, whether core style class exists
2594  $set = $ilDB->queryF("SELECT * FROM style_char WHERE style_id = %s ".
2595  "AND type = %s AND characteristic = %s",
2596  array("integer", "text", "text"),
2597  array($id, $cs["type"], $cs["class"]));
2598 
2599  // if not, add core style class
2600  if (!($rec = $ilDB->fetchAssoc($set)))
2601  {
2602  $ilDB->manipulateF(
2603  "INSERT INTO style_char (style_id, type, characteristic) ".
2604  " VALUES (%s,%s,%s) ",
2605  array("integer", "text", "text"),
2606  array($id, $cs["type"], $cs["class"]));
2607 
2608  $xpath = new DOMXPath($bdom);
2609  $par_nodes = $xpath->query("/StyleSheet/Style[@Tag = '".$cs["tag"]."' and @Type='".
2610  $cs["type"]."' and @Class='".$cs["class"]."']/StyleParameter");
2611  foreach ($par_nodes as $par_node)
2612  {
2613  // check whether style parameter exists
2614  $set = $ilDB->queryF("SELECT * FROM style_parameter WHERE style_id = %s ".
2615  "AND type = %s AND class = %s AND tag = %s AND parameter = %s",
2616  array("integer", "text", "text", "text", "text"),
2617  array($id, $cs["type"], $cs["class"],
2618  $cs["tag"], $par_node->getAttribute("Name")));
2619 
2620  // if not, create style parameter
2621  if (!($rec = $ilDB->fetchAssoc($set)))
2622  {
2623  $spid = $ilDB->nextId("style_parameter");
2624  $st = $ilDB->manipulateF("INSERT INTO style_parameter (id, style_id, type, class, tag, parameter, value) ".
2625  " VALUES (%s,%s,%s,%s,%s,%s,%s)",
2626  array("integer", "integer", "text", "text", "text", "text", "text"),
2627  array($spid, $id, $cs["type"], $cs["class"], $cs["tag"],
2628  $par_node->getAttribute("Name"), $par_node->getAttribute("Value")));
2629  }
2630  }
2631  }
2632  }
2633 
2634  // now check, whether some core image files are missing
2637  reset($core_images);
2638  foreach($core_images as $cim)
2639  {
2640  if (!is_file($imdir."/".$cim))
2641  {
2642  copy($core_dir."/".$cim, $imdir."/".$cim);
2643  }
2644  }
2645  }
2646  }
2647 
2648  //
2649  // Color management
2650  //
2651 
2656  {
2657  global $ilDB;
2658 
2659  $this->do_3_9_Migration($this->getId());
2660 
2661  //include_once("./Services/Migration/DBUpdate_1385/classes/class.ilStyleMigration.php");
2662  //ilStyleMigration::addMissingStyleCharacteristics($this->getId());
2663 
2664  $this->do_3_10_CharMigration($this->getId());
2665 
2666  // style_char: type for characteristic
2667  $st = $ilDB->prepareManip("UPDATE style_char SET type = ? WHERE characteristic = ?".
2668  " AND style_id = ? ", array("text", "text", "integer"));
2669  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2670  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2671  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2672  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2673  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2674  $ilDB->execute($st, array("page_cont", "Page", $this->getId()));
2675 
2676  // style_parameter: type for class
2677  $st = $ilDB->prepareManip("UPDATE style_parameter SET type = ? WHERE class = ?".
2678  " AND style_id = ? ", array("text", "text", "integer"));
2679  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2680  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2681  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2682  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2683  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2684  $ilDB->execute($st, array("table", "Page", $this->getId()));
2685 
2686  $st = $ilDB->prepareManip("UPDATE style_parameter SET tag = ? WHERE class = ?".
2687  " AND style_id = ? ", array("text", "text", "integer"));
2688  $ilDB->execute($st, array("div", "MediaCaption", $this->getId()));
2689 
2690  // style_char: characteristic for characteristic
2691  $st = $ilDB->prepareManip("UPDATE style_char SET characteristic = ? WHERE characteristic = ?".
2692  " AND style_id = ? ", array("text", "text", "integer"));
2693  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2694  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2695 
2696  // style_parameter: class for class
2697  $st = $ilDB->prepareManip("UPDATE style_parameter SET class = ? WHERE class = ?".
2698  " AND style_id = ? ", array("text", "text", "integer"));
2699  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2700  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2701 
2702  // force rewriting of container style
2703  $st = $ilDB->prepareManip("DELETE FROM style_char WHERE type = ?".
2704  " AND style_id = ? ", array("text", "integer"));
2705  $ilDB->execute($st, array("page_cont", $this->getId()));
2706  $st = $ilDB->prepareManip("DELETE FROM style_parameter WHERE type = ?".
2707  " AND style_id = ? ", array("text", "integer"));
2708  $ilDB->execute($st, array("page_cont", $this->getId()));
2709 
2710  }
2711 
2718  function do_3_10_CharMigration($a_id = "")
2719  {
2720  global $ilDB;
2721 
2722  $add_str = "";
2723  if ($a_id != "")
2724  {
2725  $add_str = " AND style_id = ".$ilDB->quote($a_id, "integer");
2726  }
2727 
2728  $set = $ilDB->query($q = "SELECT DISTINCT style_id, tag, class FROM style_parameter WHERE ".
2729  $ilDB->equals("type", "", "text", true)." ".$add_str);
2730 
2731  while ($rec = $ilDB->fetchAssoc($set))
2732  {
2733  // derive types from tag
2734  $types = array();
2735  switch ($rec["tag"])
2736  {
2737  case "div":
2738  case "p":
2739  if (in_array($rec["class"], array("Headline3", "Headline1",
2740  "Headline2", "TableContent", "List", "Standard", "Remark",
2741  "Additional", "Mnemonic", "Citation", "Example")))
2742  {
2743  $types[] = "text_block";
2744  }
2745  if (in_array($rec["class"], array("Block", "Remark",
2746  "Additional", "Mnemonic", "Example", "Excursus", "Special")))
2747  {
2748  $types[] = "section";
2749  }
2750  if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation")))
2751  {
2752  $types[] = "page";
2753  }
2754  break;
2755 
2756  case "td":
2757  $types[] = "table_cell";
2758  break;
2759 
2760  case "a":
2761  if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink")))
2762  {
2763  $types[] = "link";
2764  }
2765  break;
2766 
2767  case "span":
2768  $types[] = "text_inline";
2769  break;
2770 
2771  case "table":
2772  $types[] = "table";
2773  break;
2774  }
2775 
2776  // check if style_char set exists
2777  foreach ($types as $t)
2778  {
2779  // check if second type already exists
2780  $set4 = $ilDB->queryF("SELECT * FROM style_char ".
2781  " WHERE style_id = %s AND type = %s AND characteristic = %s",
2782  array("integer", "text", "text"),
2783  array($rec["style_id"], $t, $rec["class"]));
2784  if ($rec4 = $ilDB->fetchAssoc($set4))
2785  {
2786  // ok
2787  }
2788  else
2789  {
2790 //echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
2791  $ilDB->manipulateF("INSERT INTO style_char ".
2792  " (style_id, type, characteristic) VALUES ".
2793  " (%s,%s,%s) ",
2794  array("integer", "text", "text"),
2795  array($rec["style_id"], $t, $rec["class"]));
2796  }
2797  }
2798 
2799  // update types
2800  if ($rec["type"] == "")
2801  {
2802  if (count($types) > 0)
2803  {
2804  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2805  " WHERE style_id = %s AND class = %s AND ".$ilDB->equals("type", "", "text", true),
2806  array("text", "integer", "text"),
2807  array($types[0], $rec["style_id"], $rec["class"]));
2808 //echo "<br>3-".$types[0]."-".$rec["style_id"]."-".$rec["class"]."-";
2809 
2810  // links extra handling
2811  if ($types[0] == "link")
2812  {
2813  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2814  " WHERE style_id = %s AND (class = %s OR class = %s) AND ".$ilDB->equals("type", "", "text", true),
2815  array("text", "integer", "text", "text"),
2816  array($types[0], $rec["style_id"], $rec["class"].":visited",
2817  $rec["class"].":hover"));
2818  }
2819  }
2820 
2821  if (count($types) == 2)
2822  {
2823  // select all records of first type and add second type
2824  // records if necessary.
2825  $set2 = $ilDB->queryF("SELECT * FROM style_parameter ".
2826  " WHERE style_id = %s AND class = %s AND type = %s",
2827  array("integer", "text", "text"),
2828  array($rec["style_id"], $rec["class"], $types[0]));
2829  while ($rec2 = $ilDB->fetchAssoc($set2))
2830  {
2831  // check if second type already exists
2832  $set3 = $ilDB->queryF("SELECT * FROM style_parameter ".
2833  " WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
2834  array("integer", "text", "text", "text", "text"),
2835  array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"]));
2836  if ($rec3 = $ilDB->fetchAssoc($set3))
2837  {
2838  // ok
2839  }
2840  else
2841  {
2842  $nid = $ilDB->nextId("style_parameter");
2843  $ilDB->manipulateF("INSERT INTO style_parameter ".
2844  " (id, style_id, tag, class, parameter, value, type) VALUES ".
2845  " (%s, %s,%s,%s,%s,%s,%s) ",
2846  array("integer", "integer", "text", "text", "text", "text", "text"),
2847  array($nid, $rec2["style_id"], $rec2["tag"], $rec2["class"],
2848  $rec2["parameter"], $rec2["value"], $types[1]));
2849  }
2850  }
2851  }
2852  }
2853  }
2854  }
2855 
2859  function do_3_9_Migration($a_id)
2860  {
2861  global $ilDB;
2862 
2863  $classes = array("Example", "Additional", "Citation", "Mnemonic", "Remark");
2864  $pars = array("margin-top", "margin-bottom");
2865 
2866  foreach ($classes as $curr_class)
2867  {
2868  foreach ($pars as $curr_par)
2869  {
2870  $res2 = $ilDB->queryF("SELECT id FROM style_parameter WHERE style_id = %s".
2871  " AND tag = %s AND class= %s AND parameter = %s",
2872  array("integer", "text", "text", "text"),
2873  array($a_id, "p", $curr_class, $curr_par));
2874  if ($row2 = $ilDB->fetchAssoc($res2))
2875  {
2876  $ilDB->manipulateF("UPDATE style_parameter SET value= %s WHERE id = %s",
2877  array("text", "integer"),
2878  array("10px", $row2["id"]));
2879  }
2880  else
2881  {
2882  $nid = $ilDB->nextId("style_parameter");
2883  $ilDB->manipulateF("INSERT INTO style_parameter ".
2884  "(id, style_id, tag, class, parameter,value) VALUES (%s,%s,%s,%s,%s,%s)",
2885  array("integer", "integer", "text", "text", "text", "text"),
2886  array($nid, $a_id, "div", $curr_class, $curr_par, "10px"));
2887  }
2888  }
2889  }
2890 
2891  $ilDB->manipulateF("UPDATE style_parameter SET tag = %s WHERE tag = %s and style_id = %s",
2892  array("text", "text", "integer"),
2893  array("div", "p", $a_id));
2894 
2895  }
2896 
2900 
2904  function getColors()
2905  {
2906  global $ilDB;
2907 
2908  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
2909  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
2910  "ORDER BY color_name");
2911 
2912  $colors = array();
2913  while ($rec = $ilDB->fetchAssoc($set))
2914  {
2915  $colors[] = array(
2916  "name" => $rec["color_name"],
2917  "code" => $rec["color_code"]
2918  );
2919  }
2920 
2921  return $colors;
2922  }
2923 
2927  function addColor($a_name, $a_code)
2928  {
2929  global $ilDB;
2930 
2931  $ilDB->manipulate("INSERT INTO style_color (style_id, color_name, color_code)".
2932  " VALUES (".
2933  $ilDB->quote($this->getId(), "integer").",".
2934  $ilDB->quote($a_name, "text").",".
2935  $ilDB->quote($a_code, "text").
2936  ")");
2937  }
2938 
2942  function updateColor($a_name, $a_new_name, $a_code)
2943  {
2944  global $ilDB;
2945 
2946  // todo: update names in parameters as well
2947 
2948  $ilDB->manipulate("UPDATE style_color SET ".
2949  "color_name = ".$ilDB->quote($a_new_name, "text").", ".
2950  "color_code = ".$ilDB->quote($a_code, "text").
2951  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2952  " AND color_name = ".$ilDB->quote($a_name, "text"));
2953  ilObjStyleSheet::_writeUpToDate($this->getId(), false);
2954 
2955  // rename also the name in the style parameter values
2956  if ($a_name != $a_new_name)
2957  {
2958  $set = $ilDB->query("SELECT * FROM style_parameter ".
2959  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2960  " AND (".
2961  " parameter = ".$ilDB->quote("background-color", "text"). " OR ".
2962  " parameter = ".$ilDB->quote("color", "text"). " OR ".
2963  " parameter = ".$ilDB->quote("border-color", "text"). " OR ".
2964  " parameter = ".$ilDB->quote("border-top-color", "text"). " OR ".
2965  " parameter = ".$ilDB->quote("border-bottom-color", "text"). " OR ".
2966  " parameter = ".$ilDB->quote("border-left-color", "text"). " OR ".
2967  " parameter = ".$ilDB->quote("border-right-color", "text").
2968  ")");
2969  while ($rec = $ilDB->fetchAssoc($set))
2970  {
2971  if ($rec["value"] == "!".$a_name ||
2972  is_int(strpos($rec["value"], "!".$a_name."(")))
2973  {
2974  // parameter is based on color -> rename it
2975  $this->replaceStylePar($rec["tag"], $rec["class"],
2976  $rec["parameter"], str_replace($a_name, $a_new_name, $rec["value"]), $rec["type"], $rec["mq_id"], $rec["custom"]);
2977  }
2978  }
2979  }
2980  }
2981 
2985  function removeColor($a_name)
2986  {
2987  global $ilDB;
2988 
2989  $ilDB->manipulate("DELETE FROM style_color WHERE ".
2990  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2991  " color_name = ".$ilDB->quote($a_name, "text"));
2992  }
2993 
2997  function colorExists($a_color_name)
2998  {
2999  global $ilDB;
3000 
3001  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
3002  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3003  "color_name = ".$ilDB->quote($a_color_name, "text"));
3004  if ($rec = $ilDB->fetchAssoc($set))
3005  {
3006  return true;
3007  }
3008  return false;
3009  }
3010 
3014  function getColorCodeForName($a_name)
3015  {
3016  global $ilDB;
3017 
3018  $pos = strpos($a_name, "(");
3019  if ($pos > 0)
3020  {
3021  $a_i = substr($a_name, $pos + 1);
3022  $a_i = str_replace(")", "", $a_i);
3023  $a_name = substr($a_name, 0, $pos);
3024  }
3025 
3026  $set = $ilDB->query("SELECT color_code FROM style_color WHERE ".
3027  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3028  " color_name = ".$ilDB->quote($a_name, "text"));
3029  if ($rec = $ilDB->fetchAssoc($set))
3030  {
3031  if ($a_i == "")
3032  {
3033  return "#".$rec["color_code"];
3034  }
3035  else
3036  {
3037  return "#".ilObjStyleSheet::_getColorFlavor($rec["color_code"],
3038  (int) $a_i);
3039  }
3040  }
3041  }
3042 
3046  static function _getColorFlavor($a_rgb, $a_i)
3047  {
3048  $rgb = ilObjStyleSheet::_explodeRGB($a_rgb, true);
3049  $hls = ilObjStyleSheet::_RGBToHLS($rgb);
3050 
3051  if ($a_i > 0)
3052  {
3053  $hls["l"] = $hls["l"] + ((255 - $hls["l"]) * ($a_i / 100));
3054  }
3055  if ($a_i < 0)
3056  {
3057  $hls["l"] = $hls["l"] - (($hls["l"]) * (-$a_i / 100));
3058  }
3059 
3060  $rgb = ilObjStyleSheet::_HLSToRGB($hls);
3061 
3062  foreach ($rgb as $k => $v)
3063  {
3064  $rgb[$k] = str_pad(dechex($v), 2, "0", STR_PAD_LEFT);
3065  }
3066 
3067  return $rgb["r"].$rgb["g"].$rgb["b"];
3068  }
3069 
3073  static function _explodeRGB($a_rgb, $as_dec = false)
3074  {
3075  $r["r"] = substr($a_rgb, 0, 2);
3076  $r["g"] = substr($a_rgb, 2, 2);
3077  $r["b"] = substr($a_rgb, 4, 2);
3078 
3079  if ($as_dec)
3080  {
3081  $r["r"] = (int) hexdec($r["r"]);
3082  $r["g"] = (int) hexdec($r["g"]);
3083  $r["b"] = (int) hexdec($r["b"]);
3084  }
3085 
3086  return $r;
3087  }
3088 
3092  static function _RGBToHLS($a_rgb)
3093  {
3094  $r = $a_rgb["r"] / 255;
3095  $g = $a_rgb["g"] / 255;
3096  $b = $a_rgb["b"] / 255;
3097 
3098  // max / min
3099  $max = max($r,$g,$b);
3100  $min = min($r,$g,$b);
3101 
3102  //lightness
3103  $l = ($max + $min) / 2;
3104 
3105  if ($max == $min)
3106  {
3107  $s = 0;
3108  $h = 0;
3109  }
3110  else
3111  {
3112  if ($l < 0.5)
3113  {
3114  $s = ($max - $min) / ($max + $min);
3115  }
3116  else
3117  {
3118  $s = ($max - $min) / (2.0 - $max - $min);
3119  }
3120 
3121  if ($r == $max)
3122  {
3123  $h = ($g - $b) / ($max - $min);
3124  }
3125  else if ($g == $max)
3126  {
3127  $h = 2.0 + ($b - $r) / ($max - $min);
3128  }
3129  else if ($b == $max)
3130  {
3131  $h = 4.0 + ($r - $g) / ($max - $min);
3132  }
3133  }
3134 
3135  $hls["h"] = round(($h / 6) * 255);
3136  $hls["l"] = round($l * 255);
3137  $hls["s"] = round($s * 255);
3138 
3139  return $hls;
3140  }
3141 
3145  static function _HLSToRGB($a_hls)
3146  {
3147  $h = $a_hls["h"] / 255;
3148  $l = $a_hls["l"] / 255;
3149  $s = $a_hls["s"] / 255;
3150 
3151  $rgb["r"] = $rgb["g"] = $rgb["b"] = 0;
3152 
3153  // If S=0, define R, G, and B all to L
3154  if ($s == 0)
3155  {
3156  $rgb["r"] = $rgb["g"] = $rgb["b"] = $l;
3157  }
3158  else
3159  {
3160 
3161  if ($l < 0.5)
3162  {
3163  $temp2 = $l * (1.0 + $s);
3164  }
3165  else
3166  {
3167  $temp2 = $l + $s - $l * $s;
3168  }
3169 
3170  $temp1 = 2.0 * $l - $temp2;
3171 
3172 
3173  # For each of R, G, B, compute another temporary value, temp3, as follows:
3174  foreach ($rgb as $k => $v)
3175  {
3176  switch ($k)
3177  {
3178  case "r":
3179  $temp3 = $h + 1.0 / 3.0;
3180  break;
3181 
3182  case "g":
3183  $temp3 = $h;
3184  break;
3185 
3186  case "b":
3187  $temp3 = $h - 1.0/3.0;
3188  break;
3189  }
3190  if ($temp3 < 0)
3191  {
3192  $temp3 = $temp3 + 1.0;
3193  }
3194  if ($temp3 > 1)
3195  {
3196  $temp3 = $temp3 - 1.0;
3197  }
3198 
3199  if (6.0 * $temp3 < 1)
3200  {
3201  $rgb[$k] = $temp1 + ($temp2 - $temp1) * 6.0 * $temp3;
3202  }
3203  else if (2.0 * $temp3 < 1)
3204  {
3205  $rgb[$k] = $temp2;
3206  }
3207  else if (3.0 * $temp3 < 2)
3208  {
3209  $rgb[$k] = $temp1 + ($temp2 - $temp1) * ((2.0/3.0) - $temp3) * 6.0;
3210  }
3211  else
3212  {
3213  $rgb[$k] = $temp1;
3214  }
3215  }
3216  }
3217 
3218  $rgb["r"] = round($rgb["r"] * 255);
3219  $rgb["g"] = round($rgb["g"] * 255);
3220  $rgb["b"] = round($rgb["b"] * 255);
3221 
3222  return $rgb;
3223  }
3224 
3225  //
3226  // Media queries
3227  //
3228 
3232 
3236  function getMediaQueries()
3237  {
3238  global $ilDB;
3239 
3240  $set = $ilDB->query("SELECT * FROM sty_media_query WHERE ".
3241  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
3242  "ORDER BY order_nr");
3243 
3244  $mq = array();
3245  while ($rec = $ilDB->fetchAssoc($set))
3246  {
3247  $mq[] = $rec;
3248  }
3249 
3250  return $mq;
3251  }
3252 
3257  function addMediaQuery($a_mquery, $order_nr = 0)
3258  {
3259  global $ilDB;
3260 
3261  $id = $ilDB->nextId("sty_media_query");
3262  if ($order_nr == 0)
3263  {
3264  $order_nr = $this->getMaxMQueryOrderNr() + 10;
3265  }
3266 
3267  $ilDB->manipulate("INSERT INTO sty_media_query (id, style_id, mquery, order_nr)".
3268  " VALUES (".
3269  $ilDB->quote($id, "integer").",".
3270  $ilDB->quote($this->getId(), "integer").",".
3271  $ilDB->quote($a_mquery, "text").",".
3272  $ilDB->quote($order_nr, "integer").
3273  ")");
3274 
3275  return $id;
3276  }
3277 
3283  {
3284  global $ilDB;
3285 
3286  $set = $ilDB->query("SELECT max(order_nr) mnr FROM sty_media_query ".
3287  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")
3288  );
3289  $rec = $ilDB->fetchAssoc($set);
3290 
3291  return (int) $rec["mnr"];
3292  }
3293 
3300  function updateMediaQuery($a_id, $a_mquery)
3301  {
3302  global $ilDB;
3303 
3304  $ilDB->manipulate("UPDATE sty_media_query SET ".
3305  " mquery = ".$ilDB->quote($a_mquery, "text").
3306  " WHERE id = ".$ilDB->quote($a_id, "integer")
3307  );
3308  }
3309 
3316  function getMediaQueryForId($a_id)
3317  {
3318  global $ilDB;
3319 
3320  $set = $ilDB->query("SELECT * FROM sty_media_query ".
3321  " WHERE id = ".$ilDB->quote($a_id, "integer")
3322  );
3323  return $ilDB->fetchAssoc($set);
3324  }
3325 
3331  function deleteMediaQuery($a_id)
3332  {
3333  global $ilDB;
3334 
3335  $ilDB->manipulate("DELETE FROM sty_media_query WHERE ".
3336  " style_id = ".$ilDB->quote($this->getId(), "integer").
3337  " AND id = ".$ilDB->quote($a_id, "integer")
3338  );
3339  $this->saveMediaQueryOrder();
3340  }
3341 
3347  function saveMediaQueryOrder($a_order_nr = null)
3348  {
3349  global $ilDB;
3350 
3351  $mqueries = $this->getMediaQueries();
3352  if (is_array ($a_order_nr))
3353  {
3354  foreach ($mqueries as $k => $mq)
3355  {
3356  $mqueries[$k]["order_nr"] = $a_order_nr[$mq["id"]];
3357  }
3358  $mqueries = ilUtil::sortArray($mqueries, "order_nr", "", true);
3359  }
3360  $cnt = 10;
3361  foreach ($mqueries as $mq)
3362  {
3363  $ilDB->manipulate("UPDATE sty_media_query SET ".
3364  " order_nr = ".$ilDB->quote($cnt, "integer").
3365  " WHERE id = ".$ilDB->quote($mq["id"], "integer")
3366  );
3367  $cnt+= 10;
3368  }
3369  }
3370 
3371 
3372  //
3373  // Table template management
3374  //
3375 
3379  function getTemplates($a_type)
3380  {
3381  global $ilDB;
3382 
3383  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3384  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3385  "temp_type = ".$ilDB->quote($a_type, "text")." ".
3386  "ORDER BY name");
3387 
3388  $templates = array();
3389  while ($rec = $ilDB->fetchAssoc($set))
3390  {
3391  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3392  $templates[] = $rec;
3393  }
3394 
3395  return $templates;
3396  }
3397 
3401  function getTemplateClasses($a_tid)
3402  {
3403  global $ilDB;
3404  $set = $ilDB->query("SELECT * FROM style_template_class WHERE ".
3405  "template_id = ".$ilDB->quote($a_tid, "integer"));
3406 
3407  $class = array();
3408  while ($rec = $ilDB->fetchAssoc($set))
3409  {
3410  $key = $rec["class_type"];
3411  $class[$key] = $rec["class"];
3412  }
3413 
3414  return $class;
3415  }
3416 
3417 
3421  function addTemplate($a_type, $a_name, $a_classes)
3422  {
3423  global $ilDB;
3424 
3425  $tid = $ilDB->nextId("style_template");
3426  $ilDB->manipulate($q = "INSERT INTO style_template ".
3427  "(id, style_id, name, temp_type)".
3428  " VALUES (".
3429  $ilDB->quote($tid, "integer").",".
3430  $ilDB->quote($this->getId(), "integer").",".
3431  $ilDB->quote($a_name, "text").",".
3432  $ilDB->quote($a_type, "text").
3433  ")");
3434 
3435  foreach ($a_classes as $t => $c)
3436  {
3437  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3438  "(template_id, class_type, class)".
3439  " VALUES (".
3440  $ilDB->quote($tid, "integer").",".
3441  $ilDB->quote($t, "text").",".
3442  $ilDB->quote($c, "text").
3443  ")");
3444  }
3445 
3446  include_once("./Services/Style/classes/class.ilObjStyleSheetGUI.php");
3447  $this->writeTemplatePreview($tid,
3448  ilObjStyleSheetGUI::_getTemplatePreview($this, $a_type, $tid, true));
3449 
3450  return $tid;
3451  }
3452 
3456  function updateTemplate($a_t_id, $a_name, $a_classes)
3457  {
3458  global $ilDB;
3459 
3460  $ilDB->manipulate("UPDATE style_template SET ".
3461  "name = ".$ilDB->quote($a_name, "text").
3462  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3463 
3464  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3465  "template_id = ".$ilDB->quote($a_t_id, "integer")
3466  );
3467  foreach ($a_classes as $t => $c)
3468  {
3469  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3470  "(template_id, class_type, class)".
3471  " VALUES (".
3472  $ilDB->quote($a_t_id, "integer").",".
3473  $ilDB->quote($t, "text").",".
3474  $ilDB->quote($c, "text").
3475  ")");
3476  }
3477 
3478  }
3479 
3483  function addTemplateClass($a_t_id, $a_type, $a_class)
3484  {
3485  global $ilDB;
3486 
3487  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3488  "(template_id, class_type, class)".
3489  " VALUES (".
3490  $ilDB->quote($a_t_id, "integer").",".
3491  $ilDB->quote($a_type, "text").",".
3492  $ilDB->quote($a_class, "text").
3493  ")");
3494  }
3495 
3496 
3500  function templateExists($a_template_name)
3501  {
3502  global $ilDB;
3503 
3504  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3505  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3506  "name = ".$ilDB->quote($a_template_name, "text"));
3507  if ($rec = $ilDB->fetchAssoc($set))
3508  {
3509  return true;
3510  }
3511  return false;
3512  }
3513 
3517  function getTemplate($a_t_id)
3518  {
3519  global $ilDB;
3520 
3521  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3522  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
3523  " AND id = ".$ilDB->quote($a_t_id, "integer"));
3524 
3525  if ($rec = $ilDB->fetchAssoc($set))
3526  {
3527  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3528 
3529  $template = $rec;
3530  return $template;
3531  }
3532  return array();
3533  }
3534 
3538  function lookupTemplateName($a_t_id)
3539  {
3540  global $ilDB;
3541 
3542  $set = $ilDB->query("SELECT name FROM style_template WHERE ".
3543  " id = ".$ilDB->quote($a_t_id, "integer"));
3544 
3545  if ($rec = $ilDB->fetchAssoc($set))
3546  {
3547  return $rec["name"];
3548  }
3549 
3550  return false;
3551  }
3552 
3556  function getTemplateXML()
3557  {
3558  global $ilDB;
3559 
3560  $tag = "<StyleTemplates>";
3561 
3562  $ttypes = array("table", "vaccordion", "haccordion", "carousel");
3563 
3564  foreach ($ttypes as $ttype)
3565  {
3566  $ts = $this->getTemplates($ttype);
3567 
3568  foreach($ts as $t)
3569  {
3571  /*$atts = array("table" => "TableClass",
3572  "caption" => "CaptionClass",
3573  "row_head" => "RowHeadClass",
3574  "row_foot" => "RowFootClass",
3575  "col_head" => "ColHeadClass",
3576  "col_foot" => "ColFootClass",
3577  "odd_row" => "OddRowClass",
3578  "even_row" => "EvenRowClass",
3579  "odd_col" => "OddColClass",
3580  "even_col" => "EvenColClass");*/
3581  $c = $t["classes"];
3582 
3583  $tag.= '<StyleTemplate Name="'.$t["name"].'">';
3584 
3585  foreach ($atts as $type => $t)
3586  {
3587  if ($c[$type] != "")
3588  {
3589  $tag.= '<StyleClass Type="'.$type.'" Value="'.$c[$type].'" />';
3590  }
3591  }
3592 
3593  $tag.= "</StyleTemplate>";
3594  }
3595  }
3596 
3597  $tag.= "</StyleTemplates>";
3598 
3599 //echo htmlentities($tag);
3600  return $tag;
3601  }
3602 
3606  function writeTemplatePreview($a_t_id, $a_preview_html)
3607  {
3608  global $ilDB;
3609  $a_preview_html = str_replace(' width=""', "", $a_preview_html);
3610  $a_preview_html = str_replace(' valign="top"', "", $a_preview_html);
3611  $a_preview_html = str_replace('<div class="ilc_text_block_TableContent">', "<div>", $a_preview_html);
3612 //echo "1-".strlen($a_preview_html)."-";
3613 //echo htmlentities($a_preview_html);
3614  if (strlen($a_preview_html) > 4000)
3615  {
3616 //echo "2";
3617  $a_preview_html = "";
3618  }
3619  $ilDB->manipulate("UPDATE style_template SET ".
3620  "preview = ".$ilDB->quote($a_preview_html, "text").
3621  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3622  }
3623 
3627  function lookupTemplatePreview($a_t_id)
3628  {
3629  global $ilDB;
3630 
3631  $set = $ilDB->query("SELECT preview FROM style_template ".
3632  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3633  if ($rec = $ilDB->fetchAssoc($set))
3634  {
3635  return $rec["preview"];
3636  }
3637 
3638  return "";
3639  }
3640 
3644  static function _lookupTemplateIdByName($a_style_id, $a_name)
3645  {
3646  global $ilDB;
3647 
3648  $set = $ilDB->query("SELECT id FROM style_template ".
3649  " WHERE style_id = ".$ilDB->quote($a_style_id, "integer").
3650  " AND name = ".$ilDB->quote($a_name, "text"));
3651  if ($rec = $ilDB->fetchAssoc($set))
3652  {
3653  return $rec["id"];
3654  }
3655 
3656  return false;
3657  }
3658 
3662  function removeTemplate($a_t_id)
3663  {
3664  global $ilDB;
3665 
3666  $ilDB->manipulate("DELETE FROM style_template WHERE ".
3667  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3668  " id = ".$ilDB->quote($a_t_id, "integer"));
3669 
3670  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3671  "template_id = ".$ilDB->quote($a_t_id, "integer")
3672  );
3673 
3674  }
3675 
3679  function writeStyleSetting($a_name, $a_value)
3680  {
3681  global $ilDB;
3682 
3683  $ilDB->manipulate("DELETE FROM style_setting WHERE ".
3684  " style_id = ".$ilDB->quote($this->getId(), "integer").
3685  " AND name = ".$ilDB->quote($a_name, "text")
3686  );
3687 
3688  $ilDB->manipulate("INSERT INTO style_setting ".
3689  "(style_id, name, value) VALUES (".
3690  $ilDB->quote($this->getId(), "integer").",".
3691  $ilDB->quote($a_name, "text").",".
3692  $ilDB->quote($a_value, "text").
3693  ")");
3694  }
3695 
3699  function lookupStyleSetting($a_name)
3700  {
3701  global $ilDB;
3702 
3703  $set = $ilDB->query("SELECT value FROM style_setting ".
3704  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
3705  " AND name = ".$ilDB->quote($a_name, "text")
3706  );
3707  $rec = $ilDB->fetchAssoc($set);
3708 
3709  return $rec["value"];
3710  }
3711 
3715  static function writeStyleUsage($a_obj_id, $a_style_id)
3716  {
3717  global $ilDB;
3718 
3719  $ilDB->replace("style_usage", array(
3720  "obj_id" => array("integer", (int) $a_obj_id)),
3721  array(
3722  "style_id" => array("integer", (int) $a_style_id))
3723  );
3724  }
3725 
3729  static function lookupObjectStyle($a_obj_id)
3730  {
3731  global $ilDB;
3732 
3733  $set = $ilDB->query("SELECT style_id FROM style_usage ".
3734  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")
3735  );
3736  $rec = $ilDB->fetchAssoc($set);
3737 
3738  if (ilObject::_lookupType($rec["style_id"]) == "sty")
3739  {
3740  return (int) $rec["style_id"];
3741  }
3742 
3743  return 0;
3744  }
3745 
3746 
3747 }
3748 ?>
static _lookupTemplateIdByName($a_style_id, $a_name)
Lookup table template preview.
_getTemplatePreview($a_style, $a_type, $a_t_id, $a_small_mode=false)
Get table template preview.
deleteMediaQuery($a_id)
Delete media query.
getXML()
get xml representation of style object todo: add mq_id
static _explodeRGB($a_rgb, $as_dec=false)
Explode an RGB string into an array.
print $file
static _getTemplateClassTypes($a_template_type="")
Get template class types.
getHideStatus($a_type, $a_char)
Get characteristic hide status.
removeColor($a_name)
Remove a color.
characteristicExists($a_char, $a_style_type)
Check whether characteristic exists.
exportXML($a_dir)
export style xml file to directory
static _HLSToRGB($a_hls)
HLS to RGB (both arrays, 0..255)
do_3_10_Migration()
Migrates 3.10 style to 3.11 style.
setCharacteristics($a_chars)
Set characteristics.
getColors()
Get colors of style.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
_lookupActive($a_id)
Lookup active flag.
read()
read style properties
static _determineTag($a_type)
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
_writeStandard($a_id, $a_std)
Write standard flag.
deleteParameter($a_id)
delete style parameter
addTemplate($a_type, $a_name, $a_classes)
Add table template.
_writeScope($a_id, $a_scope)
Write scope.
$h
putInTree()
Put in tree (show error message, since styles do not use ref ids)
do_3_9_Migration($a_id)
Migrate old 3.9 styles.
getRefId()
Get ref id (show error message, since styles do not use ref ids)
getPlaceHolderStylePath()
get placeholder style path (for Page Layouts)
Class ilObject Basic functions for all objects.
copyImagesToDir($a_target)
Copy images to directory.
setExportSubDir($a_dir)
Set local directory, that will be included within the zip file.
deleteImage($a_file)
Delete an image.
lookupStyleSetting($a_name)
Lookup style setting.
setScope($a_scope)
Set scope.
updateMediaQuery($a_id, $a_mquery)
Update media query.
"color:#CC0000 style
Definition: example_001.php:92
static unzip($a_file, $overwrite=false, $a_flat=false)
unzip file
_lookupContObjIdByStyleId($a_style_id)
lookup style sheet ID
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static _getStyleSuperTypeForType($a_type)
writeTemplatePreview($a_t_id, $a_preview_html)
Write table template preview.
static _lookupTitle($a_id)
lookup object title
deleteStyleParOfChar($a_type, $a_class)
Delete style parameters of characteristic.
deleteCustomStylePars($a_tag, $a_class, $a_type, $a_mq_id=0)
Delete style parameter by tag/class/parameter.
_lookupUpToDate($a_id)
Looup up to date.
writeCSSFile($a_target_file="", $a_image_dir="")
write css file to webspace directory
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static lookupObjectStyle($a_obj_id)
Lookup object style.
& getMetaData()
get meta data object
getSyntaxStylePath()
get syntax style path
createExportSubDirectory()
Create export directory.
static _getAllReferences($a_id)
get all reference ids of object
lookupTemplateName($a_t_id)
Lookup table template name for template ID.
do_3_10_CharMigration($a_id="")
This is more or less a copy of Services/Migration/DBUpdate_1385/classes ilStyleMigration->addMissingS...
getThumbnailsDirectory()
Get thumbnails directory.
handleXmlString($a_str)
Handle xml strin.
_replaceStylePar($style_id, $a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id=0, $a_custom=false)
static writeStyleUsage($a_obj_id, $a_style_id)
Write style usage.
addColor($a_name, $a_code)
Add color.
getTemplate($a_t_id)
Get template.
addTemplateClass($a_t_id, $a_type, $a_class)
Update table template.
$r
Definition: example_031.php:79
_getClonableContentStyles()
Get all clonable styles (active standard styles and individual learning module styles with write perm...
static _getBasicStyleDom()
Get basic style dom.
getImagesDirectory()
Get images directory.
templateExists($a_template_name)
Check whether template exists.
static resizeImage($a_from, $a_to, $a_width, $a_height, $a_constrain_prop=false)
resize image
getCharacteristics($a_type="", $a_no_hidden=false)
Get characteristics.
static _addMissingStyleClassesToAllStyles($a_styles="")
Add missing style classes to all styles todo: add mq_id and custom handling.
getId()
get object id public
static _isExpandable($a_type)
static moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors=true, $a_mode="move_uploaded")
move uploaded file
writeStyleSetting($a_name, $a_value)
Write Style Setting.
ilObjStyleSheet($a_id=0, $a_call_by_reference=false)
Constructor public.
getTemplateXML()
Get table template xml.
static _getCoreStyles()
Get core styles.
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
_deleteStyleAssignments($a_style_id)
delete all style references to style
getTitle()
get object title public
uploadImage($a_file)
Upload image.
getDescription()
get object description
_getStandardStyles($a_exclude_default_style=false, $a_include_deactivated=false, $a_scope=0)
Get standard styles.
addParameter($a_tag, $a_par, $a_type, $a_mq_id=0, $a_custom=false)
write style parameter to db
redirection script todo: (a better solution should control the processing via a xml file) ...
setUpToDate($a_up_to_date=true)
Set style up to date (false + update will trigger css generation next time)
copyCharacteristic($a_from_style_id, $a_from_type, $a_from_char, $a_to_char)
Copy characteristic.
saveHideStatus($a_type, $a_char, $a_hide)
Save characteristic hide status.
setStyle($a_style)
set styles
static signFile($path_to_file)
getParametersOfClass($a_type, $a_class, $a_mq_id=0)
Get parameters of class.
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
getType()
get object type public
getStyleParameterGroups()
Get grouped parameter.
static _lookupType($a_id, $a_reference=false)
lookup object type
getContentPrintStyle()
get content print style
export()
Create export file.
getTemplates($a_type)
Get table templates of style.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
deleteStylePar($a_tag, $a_class, $a_par, $a_type, $a_mq_id=0, $a_custom=false)
Delete style parameter by tag/class/parameter.
_writeActive($a_id, $a_active)
Write active flag.
static _getColorFlavor($a_rgb, $a_i)
Get color flavor.
updateColor($a_name, $a_new_name, $a_code)
Update color.
static _createImagesDirectory($a_style_id)
Create images directory <data_dir>/sty/sty_<id>/images.
createExportDirectory()
Create export directory.
getStyle()
todo: bad style! should return array of objects, not multi-dim-arrays
updateStyleParameter($a_id, $a_value)
update style parameter per id
_writeUpToDate($a_id, $a_up_to_date)
Write up to date.
static _addMissingStyleClassesToStyle($a_id)
Add missing style classes to all styles.
createReference()
Create a reference (show error message, since styles do not use ref ids)
static _getImagesDirectory($a_style_id)
Get images directory.
addCharacteristic($a_type, $a_char, $a_hidden=false)
Add characteristic.
static _RGBToHLS($a_rgb)
RGB to HLS (both arrays, 0..255)
_lookupStandard($a_id)
Lookup standard flag.
getTemplateClasses($a_tid)
Get template classes.
static _getStyleParameterValues($par)
getMaxMQueryOrderNr()
Get maximum media query order nr.
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 getDataDir()
get data directory (outside webspace)
colorExists($a_color_name)
Check whether color exists.
deleteCharacteristic($a_type, $a_tag, $a_class)
Delete Characteristic.
global $l
Definition: afr.php:30
static _getStyleParameterNumericUnits($a_no_percentage=false)
getContentStylePath($a_style_id)
get content style path
create($a_from_style=0, $a_import_mode=false)
Create a new style.
getExportSubDir()
The local directory, that will be included within the zip file.
global $ilSetting
Definition: privfeed.php:40
createImportDirectory()
Create import directory.
getColorCodeForName($a_name)
Remove a color.
$path
Definition: index.php:22
updateTemplate($a_t_id, $a_name, $a_classes)
Update table template.
global $ilBench
Definition: ilias.php:18
global $ilDB
Class ilObjStyleSheet.
static _getStyleParameters($a_tag="")
removeTemplate($a_t_id)
Remove table template.
saveMediaQueryOrder($a_order_nr=null)
Save media query order.
setRefId()
Set ref id (show error message, since styles do not use ref ids)
static _isHideable($a_type)
assignMetaData(&$a_meta_data)
assign meta data object
cleanExportDirectory()
Clear export directory.
getImages()
Get images of style.
createFromXMLFile($a_file, $a_skip_parent_create=false)
create style from xml file todo: add mq_id and custom
static _getStyleParameterInputType($par)
addMediaQuery($a_mquery, $order_nr=0)
Add media query.
_getObjectsDataForType($a_type, $a_omit_trash=false)
get all objects of a certain type
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getWebspaceDir($mode="filesystem")
get webspace directory
static _getStyleParameterSubPar($par)
createImagesDirectory()
Create images directory <data_dir>/sty/sty_<id>/images.
getMediaQueries()
Get colors of style.
ilClone()
clone style sheet (note: styles have no ref ids and return an object id)
getMediaQueryForId($a_id)
Get media query for id.
static getAvailableParameters()
Get available parameters.
lookupTemplatePreview($a_t_id)
Lookup table template preview.
getUpToDate()
Get up to date.