ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
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"),
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"),
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  );
276 
277  // these types can be hidden in the content editor
278  public static $hideable_types = array (
279  "table", "table_cell"
280  );
281 
282  // tag that are used by style types
283  public static $assigned_tags = array (
284  "text_block" => "div",
285  "heading1" => "h1",
286  "heading2" => "h2",
287  "heading3" => "h3",
288  "text_inline" => "span",
289  "section" => "div",
290  "link" => "a",
291  "table" => "table",
292  "table_cell" => "td",
293  "table_caption" => "caption",
294  "media_cont" => "table",
295  "media_caption" => "div",
296  "iim" => "div",
297  "marker" => "a",
298  "glo_overlay" => "div",
299  "glo_ovtitle" => "h1",
300  "glo_ovclink" => "a",
301  "glo_ovuglink" => "a",
302  "glo_ovuglistlink" => "a",
303  "sco_title" => "div",
304  "sco_keyw" => "div",
305  "sco_desc" => "div",
306  "sco_obj" => "div",
307  "sco_desct" => "div",
308  "sco_objt" => "div",
309  "sco_fmess" => "div",
310  "rte_menu" => "div",
311  "rte_mlink" => "a",
312  "rte_tree" => "div",
313  "rte_tclink" => "a",
314  "rte_drag" => "div",
315  "rte_node" => "div",
316  "rte_status" => "div",
317  "rte_tlink" => "a",
318  "rte_tul" => "div",
319  "rte_tli" => "div",
320  "rte_texp" => "a",
321  "list_o" => "ol",
322  "list_u" => "ul",
323  "list_item" => "li",
324  "flist_cont" => "div",
325  "flist_head" => "div",
326  "flist" => "ul",
327  "flist_li" => "li",
328  "flist_a" => "a",
329  "question" => "div",
330  "qtitle" => "div",
331  "qanswer" => "div",
332  "qimg" => "img",
333  "qimgd" => "a",
334  "qordul" => "ul",
335  "qordli" => "li",
336  "qetitem" => "a",
337  "qetcorr" => "span",
338  "qinput" => "input",
339  "qlinput" => "textarea",
340  "qsubmit" => "input",
341  "qfeedr" => "div",
342  "qfeedw" => "div",
343  "qover" => "div",
344  "page_frame" => "div",
345  "page_cont" => "div",
346  "page_fn" => "div",
347  "page" => "div",
348  "page_tnav" => "div",
349  "page_bnav" => "div",
350  "page_lnav" => "div",
351  "page_rnav" => "div",
352  "page_lnavlink" => "a",
353  "page_rnavlink" => "a",
354  "page_lnavimage" => "img",
355  "page_rnavimage" => "img",
356  "page_title" => "h1",
357  "va_cntr" => "div",
358  "va_icntr" => "div",
359  "va_icont" => "div",
360  "va_ihead" => "div",
361  "va_iheada" => "div",
362  "va_ihcap" => "div",
363  "ha_cntr" => "div",
364  "ha_icntr" => "div",
365  "ha_icont" => "div",
366  "ha_iheada" => "div",
367  "ha_ihcap" => "div",
368  "ha_ihead" => "div"
369  );
370 
371  // pseudo classes
372  public static $pseudo_classes =
373  array ("a" => array("hover"), "div" => array("hover"), "img" => array("hover"));
374 
375  // core styles these styles MUST exists -> see also basic_style/style.xml
376  public static $core_styles = array(
377  array("type" => "text_block", "class" => "Standard"),
378  array("type" => "text_block", "class" => "List"),
379  array("type" => "text_block", "class" => "TableContent"),
380  array("type" => "heading1", "class" => "Headline1"),
381  array("type" => "heading2", "class" => "Headline2"),
382  array("type" => "heading3", "class" => "Headline3"),
383  array("type" => "text_inline", "class" => "Comment"),
384  array("type" => "text_inline", "class" => "Emph"),
385  array("type" => "text_inline", "class" => "Quotation"),
386  array("type" => "text_inline", "class" => "Strong"),
387  array("type" => "text_inline", "class" => "Accent"),
388  array("type" => "text_inline", "class" => "Important"),
389  array("type" => "link", "class" => "IntLink"),
390  array("type" => "link", "class" => "ExtLink"),
391  array("type" => "link", "class" => "FootnoteLink"),
392  array("type" => "link", "class" => "FileLink"),
393  array("type" => "link", "class" => "GlossaryLink"),
394  array("type" => "media_cont", "class" => "MediaContainer"),
395  array("type" => "table", "class" => "StandardTable"),
396  array("type" => "media_caption", "class" => "MediaCaption"),
397  array("type" => "iim", "class" => "ContentPopup"),
398  array("type" => "marker", "class" => "Marker"),
399  array("type" => "page_frame", "class" => "PageFrame"),
400  array("type" => "page_cont", "class" => "PageContainer"),
401  array("type" => "page", "class" => "Page"),
402  array("type" => "page_tnav", "class" => "TopNavigation"),
403  array("type" => "page_bnav", "class" => "BottomNavigation"),
404  array("type" => "page_lnav", "class" => "LeftNavigation"),
405  array("type" => "page_rnav", "class" => "RightNavigation"),
406  array("type" => "page_lnavlink", "class" => "LeftNavigationLink"),
407  array("type" => "page_rnavlink", "class" => "RightNavigationLink"),
408  array("type" => "page_lnavimage", "class" => "LeftNavigationImage"),
409  array("type" => "page_rnavimage", "class" => "RightNavigationImage"),
410  array("type" => "page_fn", "class" => "Footnote"),
411  array("type" => "page_title", "class" => "PageTitle"),
412  array("type" => "glo_overlay", "class" => "GlossaryOverlay"),
413  array("type" => "glo_ovtitle", "class" => "GlossaryOvTitle"),
414  array("type" => "glo_ovclink", "class" => "GlossaryOvCloseLink"),
415  array("type" => "glo_ovuglink", "class" => "GlossaryOvUnitGloLink"),
416  array("type" => "glo_ovuglistlink", "class" => "GlossaryOvUGListLink"),
417  array("type" => "sco_title", "class" => "Title"),
418  array("type" => "sco_desc", "class" => "Description"),
419  array("type" => "sco_desct", "class" => "DescriptionTop"),
420  array("type" => "sco_keyw", "class" => "Keywords"),
421  array("type" => "sco_obj", "class" => "Objective"),
422  array("type" => "sco_objt", "class" => "ObjectiveTop"),
423  array("type" => "sco_fmess", "class" => "FinalMessage"),
424  array("type" => "rte_menu", "class" => "RTEMenu"),
425  array("type" => "rte_menu", "class" => "RTELogo"),
426  array("type" => "rte_menu", "class" => "RTELinkBar"),
427  array("type" => "rte_mlink", "class" => "RTELink"),
428  array("type" => "rte_mlink", "class" => "RTELinkDisabled"),
429  array("type" => "rte_tree", "class" => "RTETree"),
430  array("type" => "rte_node", "class" => "RTECourse"),
431  array("type" => "rte_node", "class" => "RTEChapter"),
432  array("type" => "rte_node", "class" => "RTESco"),
433  array("type" => "rte_node", "class" => "RTEAsset"),
434  array("type" => "rte_node", "class" => "RTECourseDisabled"),
435  array("type" => "rte_node", "class" => "RTEChapterDisabled"),
436  array("type" => "rte_node", "class" => "RTEScoDisabled"),
437  array("type" => "rte_node", "class" => "RTEAssetDisabled"),
438  array("type" => "rte_status", "class" => "RTEAsset"),
439  array("type" => "rte_status", "class" => "RTECompleted"),
440  array("type" => "rte_status", "class" => "RTENotAttempted"),
441  array("type" => "rte_status", "class" => "RTERunning"),
442  array("type" => "rte_status", "class" => "RTEIncomplete"),
443  array("type" => "rte_status", "class" => "RTEPassed"),
444  array("type" => "rte_status", "class" => "RTEFailed"),
445  array("type" => "rte_status", "class" => "RTEBrowsed"),
446  array("type" => "rte_tlink", "class" => "RTETreeLink"),
447  array("type" => "rte_tlink", "class" => "RTETreeLinkDisabled"),
448  array("type" => "rte_tlink", "class" => "RTETreeCurrent"),
449  array("type" => "rte_tul", "class" => "RTETreeList"),
450  array("type" => "rte_tli", "class" => "RTETreeItem"),
451  array("type" => "rte_texp", "class" => "RTETreeExpanded"),
452  array("type" => "rte_texp", "class" => "RTETreeCollapsed"),
453  array("type" => "rte_tree", "class" => "RTETreeControl"),
454  array("type" => "rte_tclink", "class" => "RTETreeControlLink"),
455  array("type" => "rte_drag", "class" => "RTEDragBar"),
456  array("type" => "list_o", "class" => "NumberedList"),
457  array("type" => "list_u", "class" => "BulletedList"),
458  array("type" => "list_item", "class" => "StandardListItem"),
459  array("type" => "question", "class" => "Standard"),
460  array("type" => "question", "class" => "SingleChoice"),
461  array("type" => "question", "class" => "MultipleChoice"),
462  array("type" => "question", "class" => "TextQuestion"),
463  array("type" => "question", "class" => "OrderingQuestion"),
464  array("type" => "question", "class" => "MatchingQuestion"),
465  array("type" => "question", "class" => "ImagemapQuestion"),
466  array("type" => "question", "class" => "ErrorText"),
467  array("type" => "question", "class" => "TextSubset"),
468  array("type" => "question", "class" => "ClozeTest"),
469  array("type" => "qtitle", "class" => "Title"),
470  array("type" => "qanswer", "class" => "Answer"),
471  array("type" => "qimg", "class" => "QuestionImage"),
472  array("type" => "qimgd", "class" => "ImageDetailsLink"),
473  array("type" => "qordul", "class" => "OrderList"),
474  array("type" => "qordli", "class" => "OrderListItem"),
475  array("type" => "qordul", "class" => "OrderListHorizontal"),
476  array("type" => "qordli", "class" => "OrderListItemHorizontal"),
477  array("type" => "qetitem", "class" => "ErrorTextItem"),
478  array("type" => "qetitem", "class" => "ErrorTextSelected"),
479  array("type" => "qetcorr", "class" => "ErrorTextCorrected"),
480  array("type" => "qinput", "class" => "TextInput"),
481  array("type" => "qlinput", "class" => "LongTextInput"),
482  array("type" => "qsubmit", "class" => "Submit"),
483  array("type" => "qfeedr", "class" => "FeedbackRight"),
484  array("type" => "qfeedw", "class" => "FeedbackWrong"),
485  array("type" => "qover", "class" => "Correct"),
486  array("type" => "qover", "class" => "Inorrect"),
487  array("type" => "qover", "class" => "StatusMessage"),
488  array("type" => "qover", "class" => "WrongAnswersMessage"),
489  array("type" => "flist_cont", "class" => "FileListContainer"),
490  array("type" => "flist_head", "class" => "FileListHeading"),
491  array("type" => "flist", "class" => "FileList"),
492  array("type" => "flist_li", "class" => "FileListItem"),
493  array("type" => "flist_a", "class" => "FileListItemLink")
494  );
495 
496  public static $templates = array(
497  "table" => array(
498  "table" => "table",
499  "caption" => "table_caption",
500  "row_head" => "table_cell",
501  "row_foot" => "table_cell",
502  "col_head" => "table_cell",
503  "col_foot" => "table_cell",
504  "odd_row" => "table_cell",
505  "even_row" => "table_cell",
506  "odd_col" => "table_cell",
507  "even_col" => "table_cell"),
508  "vaccordion" => array(
509  "va_cntr" => "va_cntr",
510  "va_icntr" => "va_icntr",
511  "va_ihead" => "va_ihead",
512  "va_iheada" => "va_iheada",
513  "va_ihcap" => "va_ihcap",
514  "va_icont" => "va_icont"
515  ),
516  "haccordion" => array(
517  "ha_cntr" => "ha_cntr",
518  "ha_icntr" => "ha_icntr",
519  "ha_ihead" => "ha_ihead",
520  "ha_iheada" => "ha_iheada",
521  "ha_ihcap" => "ha_ihcap",
522  "ha_icont" => "ha_icont"
523  )
524  );
525 
526  // basic style xml file, image directory and dom
527  protected static $basic_style_file = "./Services/Style/basic_style/style.xml";
528  protected static $basic_style_image_dir = "./Services/Style/basic_style/images";
529  protected static $basic_style_dom;
530 
537  function ilObjStyleSheet($a_id = 0, $a_call_by_reference = false)
538  {
539  $this->type = "sty";
540  $this->style = array();
541  if($a_call_by_reference)
542  {
543  $this->ilias->raiseError("Can't instantiate style object via reference id.",$this->ilias->error_obj->FATAL);
544  }
545 
546  parent::ilObject($a_id, false);
547  }
548 
552  function setRefId()
553  {
554  $this->ilias->raiseError("Operation ilObjStyleSheet::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
555  }
556 
560  function getRefId()
561  {
562  return "";
563  //$this->ilias->raiseError("Operation ilObjStyleSheet::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
564  }
565 
569  function putInTree()
570  {
571  $this->ilias->raiseError("Operation ilObjStyleSheet::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
572  }
573 
577  function createReference()
578  {
579  $this->ilias->raiseError("Operation ilObjStyleSheet::createReference() not allowed.",$this->ilias->error_obj->FATAL);
580  }
581 
585  function setUpToDate($a_up_to_date = true)
586  {
587  $this->up_to_date = $a_up_to_date;
588  }
589 
593  function getUpToDate()
594  {
595  return $this->up_to_date;
596  }
597 
601  function setScope($a_scope)
602  {
603  $this->scope = $a_scope;
604  }
605 
609  function getScope()
610  {
611  return $this->scope;
612  }
613 
617  function _writeUpToDate($a_id, $a_up_to_date)
618  {
619  global $ilDB;
620 
621  $q = "UPDATE style_data SET uptodate = ".
622  $ilDB->quote((int) $a_up_to_date, "integer").
623  " WHERE id = ".$ilDB->quote($a_id, "integer");
624  $ilDB->manipulate($q);
625  }
626 
630  function _lookupUpToDate($a_id)
631  {
632  global $ilDB;
633 
634  $q = "SELECT uptodate FROM style_data ".
635  " WHERE id = ".$ilDB->quote($a_id, "integer");
636  $res = $ilDB->query($q);
637  $sty = $ilDB->fetchAssoc($res);
638 
639  return (boolean) $sty["uptodate"];
640  }
641 
645  function _writeStandard($a_id, $a_std)
646  {
647  global $ilDB;
648 
649  $q = "UPDATE style_data SET standard = ".
650  $ilDB->quote((int) $a_std, "integer").
651  " WHERE id = ".$ilDB->quote($a_id, "integer");
652  $ilDB->manipulate($q);
653  }
654 
658  function _writeScope($a_id, $a_scope)
659  {
660  global $ilDB;
661 
662  $q = "UPDATE style_data SET category = ".
663  $ilDB->quote((int) $a_scope, "integer").
664  " WHERE id = ".$ilDB->quote($a_id, "integer");
665  $ilDB->manipulate($q);
666  }
667 
671  function _lookupStandard($a_id)
672  {
673  global $ilDB;
674 
675  $q = "SELECT * FROM style_data ".
676  " WHERE id = ".$ilDB->quote($a_id, "integer");
677  $res = $ilDB->query($q);
678  $sty = $ilDB->fetchAssoc($res);
679 
680  return (boolean) $sty["standard"];
681  }
682 
686  function _writeActive($a_id, $a_active)
687  {
688  global $ilDB;
689 
690  $q = "UPDATE style_data SET active = ".
691  $ilDB->quote((int) $a_active, "integer").
692  " WHERE id = ".$ilDB->quote($a_id, "integer");
693  $ilDB->manipulate($q);
694  }
695 
699  function _lookupActive($a_id)
700  {
701  global $ilDB;
702 
703  $q = "SELECT * FROM style_data ".
704  " WHERE id = ".$ilDB->quote($a_id, "integer");
705  $res = $ilDB->query($q);
706  $sty = $ilDB->fetchAssoc($res);
707 
708  return (boolean) $sty["active"];
709  }
710 
714  function _getStandardStyles($a_exclude_default_style = false,
715  $a_include_deactivated = false, $a_scope = 0)
716  {
717  global $ilDB, $ilias, $tree;
718 
719  $default_style = $ilias->getSetting("default_content_style_id");
720 
721  $and_str = "";
722  if (!$a_include_deactivated)
723  {
724  $and_str = " AND active = 1";
725  }
726 
727  $q = "SELECT * FROM style_data ".
728  " WHERE standard = 1".$and_str;
729  $res = $ilDB->query($q);
730  $styles = array();
731  while($sty = $ilDB->fetchAssoc($res))
732  {
733  if (!$a_exclude_default_style || $default_style != $sty["id"])
734  {
735  // check scope
736  if ($a_scope > 0 && $sty["category"] > 0)
737  {
738  if ($tree->isInTree($sty["category"]) &&
739  $tree->isInTree($a_scope))
740  {
741  $path = $tree->getPathId($a_scope);
742  if (!in_array($sty["category"], $path))
743  {
744  continue;
745  }
746  }
747  }
748  $styles[$sty["id"]] = ilObject::_lookupTitle($sty["id"]);
749  }
750  }
751 
752  return $styles;
753  }
754 
755 
761  {
762  global $ilAccess, $ilDB;
763 
764  $clonable_styles = array();
765 
766  $q = "SELECT * FROM style_data";
767  $style_set = $ilDB->query($q);
768  while($style_rec = $ilDB->fetchAssoc($style_set))
769  {
770  $clonable = false;
771  if ($style_rec["standard"] == 1)
772  {
773  if ($style_rec["active"] == 1)
774  {
775  $clonable = true;
776  }
777  }
778  else
779  {
780  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
781  $obj_ids = ilObjContentObject::_lookupContObjIdByStyleId($style_rec["id"]);
782  foreach($obj_ids as $id)
783  {
784  $ref = ilObject::_getAllReferences($id);
785  foreach($ref as $ref_id)
786  {
787  if ($ilAccess->checkAccess("write", "", $ref_id))
788  {
789  $clonable = true;
790  }
791  }
792  }
793  }
794  if ($clonable)
795  {
796  $clonable_styles[$style_rec["id"]] =
797  ilObject::_lookupTitle($style_rec["id"]);
798  }
799  }
800  return $clonable_styles;
801  }
802 
806  function assignMetaData(&$a_meta_data)
807  {
808  $this->meta_data =& $a_meta_data;
809  }
810 
814  static function _getBasicStyleDom()
815  {
816  global $ilBench;
817 
818  if (!is_object(self::$basic_style_dom))
819  {
820  self::$basic_style_dom = new DOMDocument();
821  self::$basic_style_dom->load(self::$basic_style_file);
822  }
823 
824  return self::$basic_style_dom;
825  }
826 
830  function &getMetaData()
831  {
832  return $this->meta_data;
833  }
834 
838  function create($a_from_style = 0, $a_import_mode = false)
839  {
840  global $ilDB;
841 
842  parent::create();
843 
844  if ($a_from_style == 0)
845  {
846  if (!$a_import_mode)
847  {
848  // copy styles from basic style
849  $this->createFromXMLFile(self::$basic_style_file, true);
850 
851  // copy images from basic style
852  $this->createImagesDirectory();
853  ilUtil::rCopy(self::$basic_style_image_dir,
854  $this->getImagesDirectory());
855  }
856  }
857  else
858  {
859  // get style parameter records
860  $def = array();
861  $q = "SELECT * FROM style_parameter WHERE style_id = ".
862  $ilDB->quote($a_from_style, "integer");
863  $par_set = $ilDB->query($q);
864  while($par_rec = $ilDB->fetchAssoc($par_set))
865  {
866  $def[] = array("tag" => $par_rec["tag"], "class" => $par_rec["class"],
867  "parameter" => $par_rec["parameter"], "value" => $par_rec["value"],
868  "type" => $par_rec["type"], "mq_id" => $par_rec["mq_id"], "custom" => $par_rec["custom"]);
869  }
870 
871  // get style characteristics records
872  $chars = array();
873  $q = "SELECT * FROM style_char WHERE style_id = ".
874  $ilDB->quote($a_from_style, "integer");
875  $par_set = $ilDB->query($q);
876  while($par_rec = $ilDB->fetchAssoc($par_set))
877  {
878  $chars[] = array("type" => $par_rec["type"], "characteristic" => $par_rec["characteristic"]);
879  }
880 
881 
882  // copy media queries
883  $from_style = new ilObjStyleSheet($a_from_style);
884  $mqs = $from_style->getMediaQueries();
885  $mq_mapping = array();
886  foreach ($mqs as $mq)
887  {
888  $nid = $this->addMediaQuery($mq["mquery"]);
889  $mq_mapping[$mq["id"]] = $nid;
890  }
891 
892  // default style settings
893  foreach ($def as $sty)
894  {
895  $id = $ilDB->nextId("style_parameter");
896  $q = "INSERT INTO style_parameter (id, style_id, tag, class, parameter, value, type, mq_id, custom) VALUES ".
897  "(".
898  $ilDB->quote($id, "integer").",".
899  $ilDB->quote($this->getId(), "integer").",".
900  $ilDB->quote($sty["tag"], "text").",".
901  $ilDB->quote($sty["class"], "text").",".
902  $ilDB->quote($sty["parameter"], "text").",".
903  $ilDB->quote($sty["value"], "text").",".
904  $ilDB->quote($sty["type"], "text").",".
905  $ilDB->quote((int) $mq_mapping[$sty["mq_id"]], "integer").",".
906  $ilDB->quote($sty["custom"], "integer").
907  ")";
908  $ilDB->manipulate($q);
909  }
910 
911  // insert style characteristics
912  foreach ($chars as $char)
913  {
914  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
915  "(".$ilDB->quote($this->getId(), "integer").",".
916  $ilDB->quote($char["type"], "text").",".
917  $ilDB->quote($char["characteristic"], "text").")";
918  $ilDB->manipulate($q);
919  }
920 
921  // add style_data record
922  $q = "INSERT INTO style_data (id, uptodate, category) VALUES ".
923  "(".$ilDB->quote($this->getId(), "integer").", 0,".
924  $ilDB->quote((int) $this->getScope(), "integer").")";
925  $ilDB->manipulate($q);
926 
927  // copy images
928  $this->createImagesDirectory();
929  ilUtil::rCopy($from_style->getImagesDirectory(),
930  $this->getImagesDirectory());
931 
932  // copy colors
933  $colors = $from_style->getColors();
934  foreach ($colors as $c)
935  {
936  $this->addColor($c["name"], $c["code"]);
937  }
938 
939  // copy templates
941  foreach ($tcts as $tct => $v)
942  {
943  $templates = $from_style->getTemplates($tct);
944  foreach ($templates as $t)
945  {
946  $this->addTemplate($tct, $t["name"], $t["classes"]);
947  }
948  }
949 
950  }
951 
952  $this->read();
953  if (!$a_import_mode)
954  {
955  $this->writeCSSFile();
956  }
957  }
958 
962  function deleteCharacteristic($a_type, $a_tag, $a_class)
963  {
964  global $ilDB;
965 
966  // check, if characteristic is not a core style
968  if (empty($core_styles[$a_type.".".$a_tag.".".$a_class]))
969  {
970  // delete characteristic record
971  $st = $ilDB->manipulateF(
972  "DELETE FROM style_char WHERE style_id = %s AND type = %s AND characteristic = %s",
973  array("integer", "text", "text"),
974  array($this->getId(), $a_type, $a_class));
975 
976  // delete parameter records
977  $st = $ilDB->manipulateF("DELETE FROM style_parameter WHERE style_id = %s AND tag = %s AND type = %s AND class = %s",
978  array("integer", "text", "text", "text"),
979  array($this->getId(), $a_tag, $a_type, $a_class));
980  }
981 
982  $this->setUpToDate(false);
983  $this->_writeUpToDate($this->getId(), false);
984  }
985 
989  function characteristicExists($a_char, $a_style_type)
990  {
991  global $ilDB;
992 
993  $set = $ilDB->queryF(
994  "SELECT style_id FROM style_char WHERE style_id = %s AND characteristic = %s AND type = %s",
995  array("integer", "text", "text"),
996  array($this->getId(), $a_char, $a_style_type));
997  if ($rec = $ilDB->fetchAssoc($set))
998  {
999  return true;
1000  }
1001  return false;
1002  }
1003 
1007  function addCharacteristic($a_type, $a_char, $a_hidden = false)
1008  {
1009  global $ilDB;
1010 
1011  // delete characteristic record
1012  $ilDB->manipulateF("INSERT INTO style_char (style_id, type, characteristic, hide)".
1013  " VALUES (%s,%s,%s,%s) ",
1014  array("integer", "text", "text", "integer"),
1015  array($this->getId(), $a_type, $a_char, $a_hidden));
1016 
1017  $this->setUpToDate(false);
1018  $this->_writeUpToDate($this->getId(), false);
1019  }
1020 
1027  function copyCharacteristic($a_from_style_id,
1028  $a_from_type, $a_from_char, $a_to_char)
1029  {
1030  global $ilDB;
1031 
1032  if (!$this->characteristicExists($a_to_char, $a_from_type))
1033  {
1034  $this->addCharacteristic($a_from_type, $a_to_char);
1035  }
1036  $this->deleteStyleParOfChar($a_from_type, $a_to_char);
1037 
1038  $from_style = new ilObjStyleSheet($a_from_style_id);
1039 
1040  // todo fix using mq_id
1041  $pars = $from_style->getParametersOfClass($a_from_type, $a_from_char);
1042 
1043  $colors = array();
1044  foreach ($pars as $p => $v)
1045  {
1046  if (substr($v, 0, 1) == "!")
1047  {
1048  $colors[] = substr($v, 1);
1049  }
1050  $this->replaceStylePar(ilObjStyleSheet::_determineTag($a_from_type),
1051  $a_to_char, $p, $v, $a_from_type);
1052  }
1053 
1054  // copy colors
1055  foreach ($colors as $c)
1056  {
1057  if (!$this->colorExists($c))
1058  {
1059  $this->addColor($c, $from_style->getColorCodeForName($c));
1060  }
1061  }
1062  }
1063 
1067  function getCharacteristics($a_type = "", $a_no_hidden = false)
1068  {
1069  $chars = array();
1070 
1071  if ($a_type == "")
1072  {
1073  $chars = $this->chars;
1074  }
1075  if (is_array($this->chars_by_type[$a_type]))
1076  {
1077  $chars = $this->chars_by_type[$a_type];
1078  }
1079 
1080  if ($a_no_hidden)
1081  {
1082  foreach ($chars as $k => $char)
1083  {
1084  if ($a_type == "" && $this->hidden_chars[$char["type"].":".$char["class"]])
1085  {
1086  unset($chars[$k]);
1087  }
1088  else if ($this->hidden_chars[$a_type.":".$char])
1089  {
1090  unset($chars[$k]);
1091  }
1092  }
1093  }
1094 
1095  return $chars;
1096  }
1097 
1101  function setCharacteristics($a_chars)
1102  {
1103  $this->chars = $a_chars;
1104  // $this->chars_by_type[$a_type];
1105  }
1106 
1110  function saveHideStatus($a_type, $a_char, $a_hide)
1111  {
1112  global $ilDB;
1113 
1114  $ilDB->manipulate("UPDATE style_char SET ".
1115  " hide = ".$ilDB->quote((int) $a_hide, "integer").
1116  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1117  " type = ".$ilDB->quote($a_type, "text")." AND ".
1118  " characteristic = ".$ilDB->quote($a_char, "text")
1119  );
1120  }
1121 
1125  function getHideStatus($a_type, $a_char)
1126  {
1127  global $ilDB;
1128 
1129  $set = $ilDB->query("SELECT hide FROM style_char ".
1130  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1131  " type = ".$ilDB->quote($a_type, "text")." AND ".
1132  " characteristic = ".$ilDB->quote($a_char, "text")
1133  );
1134  $rec = $ilDB->fetchAssoc($set);
1135 
1136  return $rec["hide"];
1137  }
1138 
1145  function ilClone()
1146  {
1147  global $log, $lng;
1148 
1149  $lng->loadLanguageModule("style");
1150 
1151  $new_obj = new ilObjStyleSheet();
1152  $new_obj->setTitle($this->getTitle()." (".$lng->txt("sty_acopy").")");
1153  $new_obj->setType($this->getType());
1154  $new_obj->setDescription($this->getDescription());
1155  $new_obj->create($this->getId());
1156 
1157  $new_obj->writeStyleSetting("disable_auto_margins",
1158  $this->lookupStyleSetting("disable_auto_margins"));
1159 
1160  return $new_obj->getId();
1161  }
1162 
1166  function copyImagesToDir($a_target)
1167  {
1168  ilUtil::rCopy($this->getImagesDirectory(), $a_target);
1169  }
1170 
1180  function addParameter($a_tag, $a_par, $a_type, $a_mq_id = 0, $a_custom = false)
1181  {
1182  global $ilDB;
1183 
1184  $avail_params = $this->getAvailableParameters();
1185  $tag = explode(".", $a_tag);
1186  $value = $avail_params[$a_par][0];
1187  $id = $ilDB->nextId("style_parameter");
1188  $q = "INSERT INTO style_parameter (id,style_id, type, tag, class, parameter, value, mq_id, custom) VALUES ".
1189  "(".
1190  $ilDB->quote($id, "integer").",".
1191  $ilDB->quote($this->getId(), "integer").",".
1192  $ilDB->quote($a_type, "text").",".
1193  $ilDB->quote($tag[0], "text").",".
1194  $ilDB->quote($tag[1], "text").",".
1195  $ilDB->quote($a_par, "text").",".
1196  $ilDB->quote($value, "text").",".
1197  $ilDB->quote($a_mq_id, "integer").",".
1198  $ilDB->quote($a_custom, "integer").
1199  ")";
1200  $ilDB->manipulate($q);
1201  $this->read();
1202  $this->writeCSSFile();
1203  }
1204 
1210  {
1212  }
1213 
1218  static function _createImagesDirectory($a_style_id)
1219  {
1220  global $ilErr;
1221 
1222  $sty_data_dir = ilUtil::getWebspaceDir()."/sty";
1223  ilUtil::makeDir($sty_data_dir);
1224  if(!is_writable($sty_data_dir))
1225  {
1226  $ilErr->raiseError("Style data directory (".$sty_data_dir
1227  .") not writeable.", $ilErr->FATAL);
1228  }
1229 
1230  $style_dir = $sty_data_dir."/sty_".$a_style_id;
1231  ilUtil::makeDir($style_dir);
1232  if(!@is_dir($style_dir))
1233  {
1234  $ilErr->raiseError("Creation of style directory failed (".
1235  $style_dir.").",$ilErr->FATAL);
1236  }
1237 
1238  // create images subdirectory
1239  $im_dir = $style_dir."/images";
1240  ilUtil::makeDir($im_dir);
1241  if(!@is_dir($im_dir))
1242  {
1243  $ilErr->raiseError("Creation of Import Directory failed (".
1244  $im_dir.").", $ilErr->FATAL);
1245  }
1246 
1247  // create thumbnails directory
1248  $thumb_dir = $style_dir."/images/thumbnails";
1249  ilUtil::makeDir($thumb_dir);
1250  if(!@is_dir($thumb_dir))
1251  {
1252  $ilErr->raiseError("Creation of Import Directory failed (".
1253  $thumb_dir.").", $ilErr->FATAL);
1254  }
1255  }
1256 
1261  {
1263  }
1264 
1268  static function _getImagesDirectory($a_style_id)
1269  {
1270  return ilUtil::getWebspaceDir()."/sty/sty_".$a_style_id.
1271  "/images";
1272  }
1273 
1278  {
1279  return $this->getImagesDirectory().
1280  "/thumbnails";
1281  }
1282 
1286  function getImages()
1287  {
1288  $dir = $this->getImagesDirectory();
1289  $images = array();
1290  if (is_dir($dir))
1291  {
1292  $entries = ilUtil::getDir($dir);
1293  foreach($entries as $entry)
1294  {
1295  if (substr($entry["entry"],0,1) == ".")
1296  {
1297  continue;
1298  }
1299  if ($entry["type"] != "dir")
1300  {
1301  $images[] = $entry;
1302  }
1303  }
1304  }
1305 
1306  return $images;
1307  }
1308 
1312  function uploadImage($a_file)
1313  {
1314  $this->createImagesDirectory();
1315  @ilUtil::moveUploadedFile($a_file["tmp_name"], $a_file["name"],
1316  $this->getImagesDirectory()."/".$a_file["name"]);
1317  @ilUtil::resizeImage($this->getImagesDirectory()."/".$a_file["name"],
1318  $this->getThumbnailsDirectory()."/".$a_file["name"], 75, 75);
1319  }
1320 
1324  function deleteImage($a_file)
1325  {
1326  if (is_file($this->getImagesDirectory()."/".$a_file))
1327  {
1328  unlink($this->getImagesDirectory()."/".$a_file);
1329  }
1330  if (is_file($this->getThumbnailsDirectory()."/".$a_file))
1331  {
1332  unlink($this->getThumbnailsDirectory()."/".$a_file);
1333  }
1334  }
1335 
1341  function deleteParameter($a_id)
1342  {
1343  global $ilDB;
1344 
1345  $q = "DELETE FROM style_parameter WHERE id = ".
1346  $ilDB->quote($a_id, "integer");
1347  $ilDB->query($q);
1348  }
1349 
1359  function deleteStylePar($a_tag, $a_class, $a_par, $a_type, $a_mq_id = 0, $a_custom = false)
1360  {
1361  global $ilDB;
1362 
1363  $q = "DELETE FROM style_parameter WHERE ".
1364  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1365  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1366  " class = ".$ilDB->quote($a_class, "text")." AND ".
1367  " mq_id = ".$ilDB->quote($a_mq_id, "integer")." AND ".
1368  " custom = ".$ilDB->quote($a_custom, "integer")." AND ".
1369  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1370  " parameter = ".$ilDB->quote($a_par, "text");
1371 
1372  $ilDB->manipulate($q);
1373  }
1374 
1384  function deleteCustomStylePars($a_tag, $a_class, $a_type, $a_mq_id = 0)
1385  {
1386  global $ilDB;
1387 
1388  $q = "DELETE FROM style_parameter WHERE ".
1389  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1390  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1391  " class = ".$ilDB->quote($a_class, "text")." AND ".
1392  " mq_id = ".$ilDB->quote($a_mq_id, "integer")." AND ".
1393  " custom = ".$ilDB->quote(1, "integer")." AND ".
1394  " ".$ilDB->equals("type", $a_type, "text", true);
1395 
1396  $ilDB->manipulate($q);
1397  }
1398 
1407  function deleteStyleParOfChar($a_type, $a_class)
1408  {
1409  global $ilDB;
1410 
1411  $q = "DELETE FROM style_parameter WHERE ".
1412  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1413  " class = ".$ilDB->quote($a_class, "text")." AND ".
1414  " ".$ilDB->equals("type", $a_type, "text", true);
1415 
1416  $ilDB->manipulate($q);
1417  }
1418 
1419 
1423  function delete()
1424  {
1425  global $ilDB;
1426 
1427  // delete object
1428  parent::delete();
1429 
1430  // check whether this style is global default
1431  $def_style = $this->ilias->getSetting("default_content_style_id");
1432  if ($def_style == $this->getId())
1433  {
1434  $this->ilias->deleteSetting("default_content_style_id");
1435  }
1436 
1437  // check whether this style is global fixed
1438  $fixed_style = $this->ilias->getSetting("fixed_content_style_id");
1439  if ($fixed_style == $this->getId())
1440  {
1441  $this->ilias->deleteSetting("fixed_content_style_id");
1442  }
1443 
1444  // delete style parameter
1445  $q = "DELETE FROM style_parameter WHERE style_id = ".
1446  $ilDB->quote($this->getId(), "integer");
1447  $ilDB->manipulate($q);
1448 
1449  // delete style file
1450  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1451  if (is_file($css_file_name))
1452  {
1453  unlink($css_file_name);
1454  }
1455 
1456  // delete media queries
1457  $ilDB->manipulate("DELETE FROM sty_media_query WHERE ".
1458  " style_id = ".$ilDB->quote($this->getId(), "integer")
1459  );
1460 
1461  // delete entries in learning modules
1462  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
1464 
1465  // delete style data record
1466  $q = "DELETE FROM style_data WHERE id = ".
1467  $ilDB->quote($this->getId(), "integer");
1468  $ilDB->manipulate($q);
1469 
1470  }
1471 
1472 
1476  function read()
1477  {
1478  global $ilDB;
1479 
1480  parent::read();
1481 
1482  $q = "SELECT * FROM style_parameter WHERE style_id = ".
1483  $ilDB->quote($this->getId(), "integer")." ORDER BY tag, class, type, mq_id ";
1484  $style_set = $ilDB->query($q);
1485  $ctag = "";
1486  $cclass = "";
1487  $ctype = "";
1488  $cmq_id = 0;
1489  $this->style = array();
1490  // workaround for bug #17586, see also http://stackoverflow.com/questions/3066356/multiple-css-classes-properties-overlapping-based-on-the-order-defined
1491  // e.g. ha_iheada must be written after ha_ihead, since they are acting on the same dom node
1492  // styles that must be added at the end
1493  $this->end_styles = array();
1494  while($style_rec = $ilDB->fetchAssoc($style_set))
1495  {
1496  if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass
1497  || $style_rec["type"] != $ctype || $style_rec["mq_id"] != $cmq_id)
1498  {
1499  // add current tag array to style array
1500  if(is_array($tag))
1501  {
1502  if (in_array($ctype, array("ha_iheada", "va_iheada")))
1503  {
1504  $this->end_styles[] = $tag;
1505  }
1506  else
1507  {
1508  $this->style[] = $tag;
1509  }
1510  }
1511  $tag = array();
1512  }
1513  $ctag = $style_rec["tag"];
1514  $cclass = $style_rec["class"];
1515  $ctype = $style_rec["type"];
1516  $cmq_id = $style_rec["mq_id"];
1517  $tag[] = $style_rec;
1518  // added $cmq_id
1519  $this->style_class[$ctype][$cclass][$cmq_id][$style_rec["parameter"]] = $style_rec["value"];
1520  }
1521  if(is_array($tag))
1522  {
1523  $this->style[] = $tag;
1524  }
1525  foreach ($this->end_styles as $s)
1526  {
1527  $this->style[] = $s;
1528  }
1529 //var_dump($this->style_class);
1530  $q = "SELECT * FROM style_data WHERE id = ".
1531  $ilDB->quote($this->getId(), "integer");
1532  $res = $ilDB->query($q);
1533  $sty = $ilDB->fetchAssoc($res);
1534  $this->setUpToDate((boolean) $sty["uptodate"]);
1535  $this->setScope($sty["category"]);
1536 
1537  // get style characteristics records
1538  $this->chars = array();
1539  $this->chars_by_type = array();
1540  $q = "SELECT * FROM style_char WHERE style_id = ".
1541  $ilDB->quote($this->getId(), "integer").
1542  " ORDER BY type ASC, characteristic ASC";
1543  $par_set = $ilDB->query($q);
1544  while($par_rec = $ilDB->fetchAssoc($par_set))
1545  {
1546  $this->chars[] = array("type" => $par_rec["type"], "class" => $par_rec["characteristic"], "hide" => $par_rec["hide"]);
1547  $this->chars_by_type[$par_rec["type"]][] = $par_rec["characteristic"];
1548  if ($par_rec["hide"])
1549  {
1550  $this->hidden_chars[$par_rec["type"].":".$par_rec["characteristic"]] = true;
1551  }
1552  }
1553 // var_dump($this->style); exit;
1554  }
1555 
1559  function writeCSSFile($a_target_file = "", $a_image_dir = "")
1560  {
1561  $style = $this->getStyle();
1562 
1563  if ($a_target_file == "")
1564  {
1565  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1566  }
1567  else
1568  {
1569  $css_file_name = $a_target_file;
1570  }
1571  $css_file = fopen($css_file_name, "w");
1572 
1573  $page_background = "";
1574 
1575  $mqs = array(array("mquery" => "", "id" => 0));
1576  foreach ($this->getMediaQueries() as $mq)
1577  {
1578  $mqs[] = $mq;
1579  }
1580 
1581  // iterate all media queries
1582  foreach ($mqs as $mq)
1583  {
1584  if ($mq["id"] > 0)
1585  {
1586  fwrite ($css_file, "@media ".$mq["mquery"]." {\n");
1587  }
1588  reset($style);
1589  foreach ($style as $tag)
1590  {
1591  if ($tag[0]["mq_id"] != $mq["id"])
1592  {
1593  continue;
1594  }
1595  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1596  if ($tag[0]["tag"] == "td")
1597  {
1598  fwrite ($css_file, ",th".".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1599  }
1600  if (in_array($tag[0]["tag"], array("h1", "h2", "h3")))
1601  {
1602  fwrite ($css_file, ",div.ilc_text_block_".$tag[0]["class"]."\n");
1603  fwrite ($css_file, ",body.ilc_text_block_".$tag[0]["class"]."\n");
1604  }
1605  if ($tag[0]["type"] == "text_block")
1606  {
1607  fwrite ($css_file, ",body.ilc_text_block_".$tag[0]["class"]."\n");
1608  }
1609  fwrite ($css_file, "{\n");
1610 
1611  // collect table border attributes
1612  $t_border = array();
1613 
1614  foreach($tag as $par)
1615  {
1616  $cur_par = $par["parameter"];
1617  $cur_val = $par["value"];
1618 
1619  // replace named colors
1620  if (is_int(strpos($cur_par, "color")) && substr(trim($cur_val), 0, 1) == "!")
1621  {
1622  $cur_val = $this->getColorCodeForName(substr($cur_val, 1));
1623  }
1624 
1625  if ($tag[0]["type"] == "table" && is_int(strpos($par["parameter"], "border")))
1626  {
1627  $t_border[$cur_par] = $cur_val;
1628  }
1629 
1630  if (in_array($cur_par, array("background-image", "list-style-image")))
1631  {
1632  if (is_int(strpos($cur_val, "/"))) // external
1633  {
1634  $cur_val = "url(".$cur_val.")";
1635  }
1636  else // internal
1637  {
1638  if ($a_image_dir == "")
1639  {
1640  $cur_val = "url(../sty/sty_".$this->getId()."/images/".$cur_val.")";
1641  }
1642  else
1643  {
1644  $cur_val = "url(".$a_image_dir."/".$cur_val.")";
1645  }
1646  }
1647  }
1648 
1649  if ($cur_par == "opacity")
1650  {
1651  $cur_val = ((int) $cur_val) / 100;
1652  }
1653 
1654  fwrite ($css_file, "\t".$cur_par.": ".$cur_val.";\n");
1655 
1656  // IE6 fix for minimum height
1657  if ($cur_par == "min-height")
1658  {
1659  fwrite ($css_file, "\t"."height".": "."auto !important".";\n");
1660  fwrite ($css_file, "\t"."height".": ".$cur_val.";\n");
1661  }
1662 
1663  // opacity fix
1664  if ($cur_par == "opacity")
1665  {
1666  fwrite ($css_file, "\t".'-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity='.($cur_val * 100).')"'.";\n");
1667  fwrite ($css_file, "\t".'filter: alpha(opacity='.($cur_val * 100).')'.";\n");
1668  fwrite ($css_file, "\t".'-moz-opacity: '.$cur_val.";\n");
1669  }
1670 
1671  // transform fix
1672  if ($cur_par == "transform")
1673  {
1674  fwrite ($css_file, "\t".'-webkit-transform: '.$cur_val.";\n");
1675  fwrite ($css_file, "\t".'-moz-transform: '.$cur_val.";\n");
1676  fwrite ($css_file, "\t".'-ms-transform: '.$cur_val.";\n");
1677  }
1678 
1679  // transform-origin fix
1680  if ($cur_par == "transform-origin")
1681  {
1682  fwrite ($css_file, "\t".'-webkit-transform-origin: '.$cur_val.";\n");
1683  fwrite ($css_file, "\t".'-moz-transform-origin: '.$cur_val.";\n");
1684  fwrite ($css_file, "\t".'-ms-transform-origin: '.$cur_val.";\n");
1685  }
1686 
1687  // save page background
1688  if ($tag[0]["tag"] == "div" && $tag[0]["class"] == "Page"
1689  && $cur_par == "background-color")
1690  {
1691  $page_background = $cur_val;
1692  }
1693  }
1694  fwrite ($css_file, "}\n");
1695  fwrite ($css_file, "\n");
1696 
1697  // use table border attributes for th td as well
1698  /* if ($tag[0]["type"] == "table")
1699  {
1700  if (count($t_border) > 0)
1701  {
1702  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." th,".
1703  $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." td\n");
1704  fwrite ($css_file, "{\n");
1705  foreach ($t_border as $p => $v)
1706  {
1707  // fwrite ($css_file, "\t".$p.": ".$v.";\n");
1708  }
1709  fwrite ($css_file, "}\n");
1710  fwrite ($css_file, "\n");
1711  }
1712  }*/
1713  }
1714 
1715  if ($page_background != "")
1716  {
1717  fwrite ($css_file, "td.ilc_Page\n");
1718  fwrite ($css_file, "{\n");
1719  fwrite ($css_file, "\t"."background-color: ".$page_background.";\n");
1720  fwrite ($css_file, "}\n");
1721  }
1722  if ($mq["id"] > 0)
1723  {
1724  fwrite ($css_file, "}\n");
1725  }
1726  }
1727  fclose($css_file);
1728 
1729  $this->setUpToDate(true);
1730  $this->_writeUpToDate($this->getId(), true);
1731  }
1732 
1739  static function getEffectiveContentStyleId($a_style_id, $a_type = "")
1740  {
1741  global $ilSetting;
1742 
1743  // check global fixed content style
1744  $fixed_style = $ilSetting->get("fixed_content_style_id");
1745  if ($fixed_style > 0)
1746  {
1747  $a_style_id = $fixed_style;
1748  }
1749 
1750  // check global default style
1751  if ($a_style_id <= 0)
1752  {
1753  $a_style_id = $ilSetting->get("default_content_style_id");
1754  }
1755 
1756  if ($a_style_id > 0 && ilObject::_lookupType($a_style_id) == "sty")
1757  {
1758  return $a_style_id;
1759  }
1760 
1761  return 0;
1762  }
1763 
1770  function getParametersOfClass($a_type, $a_class, $a_mq_id = 0)
1771  {
1772  if (is_array($this->style_class[$a_type][$a_class][$a_mq_id]))
1773  {
1774  return $this->style_class[$a_type][$a_class][$a_mq_id];
1775  }
1776  return array();
1777  }
1778 
1784  function getContentStylePath($a_style_id)
1785  {
1786  global $ilias;
1787 
1788  $rand = rand(1,999999);
1789 
1790 
1791  // check global fixed content style
1792  $fixed_style = $ilias->getSetting("fixed_content_style_id");
1793  if ($fixed_style > 0)
1794  {
1795  $a_style_id = $fixed_style;
1796  }
1797 
1798  // check global default style
1799  if ($a_style_id <= 0)
1800  {
1801  $a_style_id = $ilias->getSetting("default_content_style_id");
1802  }
1803 
1804  if ($a_style_id > 0 && ilObject::_exists($a_style_id))
1805  {
1806  // check whether file is up to date
1807  if (!ilObjStyleSheet::_lookupUpToDate($a_style_id))
1808  {
1809  $style = new ilObjStyleSheet($a_style_id);
1810  $style->writeCSSFile();
1811  }
1812 
1813  return ilUtil::getWebspaceDir("output").
1814  "/css/style_".$a_style_id.".css?dummy=$rand";
1815  }
1816  else // todo: work this out
1817  {
1818  return "./Services/COPage/css/content.css";
1819  }
1820  }
1821 
1828  {
1829  return "./Services/COPage/css/print_content.css";
1830  }
1831 
1838  {
1839  return "./Services/COPage/css/syntaxhighlight.css";
1840  }
1841 
1848  {
1849  return "./Services/COPage/css/placeholder.css";
1850  }
1851 
1852  function update()
1853  {
1854  global $ilDB;
1855 
1856  parent::update();
1857  $this->read(); // this could be done better
1858  $this->writeCSSFile();
1859 
1860  $q = "UPDATE style_data ".
1861  "SET category = ".$ilDB->quote((int) $this->getScope(), "integer").
1862  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
1863  $ilDB->manipulate($q);
1864  }
1865 
1872  function updateStyleParameter($a_id, $a_value)
1873  {
1874  global $ilDB;
1875 
1876  $q = "UPDATE style_parameter SET VALUE = ".
1877  $ilDB->quote($a_value, "text")." WHERE id = ".
1878  $ilDB->quote($a_id, "integer");
1879  $style_set = $ilDB->manipulate($q);
1880  }
1881 
1886  // todo: search for usages, add mq_id
1887  function replaceStylePar($a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id = 0, $a_custom = false)
1888  {
1889  ilObjStyleSheet::_replaceStylePar($this->getId(), $a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id, $a_custom);
1890  }
1891 
1892  function _replaceStylePar($style_id, $a_tag, $a_class, $a_par, $a_val, $a_type, $a_mq_id = 0, $a_custom = false)
1893  {
1894  global $ilDB;
1895 
1896  $q = "SELECT * FROM style_parameter WHERE ".
1897  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1898  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1899  " class = ".$ilDB->quote($a_class, "text")." AND ".
1900  " mq_id = ".$ilDB->quote($a_mq_id, "integer")." AND ".
1901  " custom = ".$ilDB->quote($a_custom, "integer")." AND ".
1902  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1903  " parameter = ".$ilDB->quote($a_par, "text");
1904 
1905  $set = $ilDB->query($q);
1906 
1907  if ($rec = $set->fetchRow())
1908  {
1909  $q = "UPDATE style_parameter SET ".
1910  " value = ".$ilDB->quote($a_val, "text")." WHERE ".
1911  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1912  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1913  " class = ".$ilDB->quote($a_class, "text")." AND ".
1914  " mq_id = ".$ilDB->quote($a_mq_id, "integer")." AND ".
1915  " custom = ".$ilDB->quote($a_custom, "integer")." AND ".
1916  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1917  " parameter = ".$ilDB->quote($a_par, "text");
1918 
1919  $ilDB->manipulate($q);
1920  }
1921  else
1922  {
1923  $id = $ilDB->nextId("style_parameter");
1924  $q = "INSERT INTO style_parameter (id, value, style_id, tag, class, type, parameter, mq_id, custom) VALUES ".
1925  " (".
1926  $ilDB->quote($id, "integer").",".
1927  $ilDB->quote($a_val, "text").",".
1928  " ".$ilDB->quote($this->getId(), "integer").",".
1929  " ".$ilDB->quote($a_tag, "text").",".
1930  " ".$ilDB->quote($a_class, "text").",".
1931  " ".$ilDB->quote($a_type, "text").",".
1932  " ".$ilDB->quote($a_par, "text").",".
1933  " ".$ilDB->quote($a_mq_id, "integer").",".
1934  " ".$ilDB->quote($a_custom, "integer").
1935  ")";
1936 
1937  $ilDB->manipulate($q);
1938  }
1939  }
1940 
1941 
1945  function getStyle()
1946  {
1947  return $this->style;
1948  }
1949 
1953  function setStyle($a_style)
1954  {
1955  $this->style = $a_style;
1956  }
1957 
1958 
1965  function handleXmlString($a_str)
1966  {
1967  return str_replace("&", "&amp;", $a_str);
1968  }
1969 
1974  function getXML()
1975  {
1976  $xml.= "<StyleSheet>\n";
1977 
1978  // title and description
1979  $xml.= "<Title>".$this->handleXmlString($this->getTitle())."</Title>";
1980  $xml.= "<Description>".$this->handleXmlString($this->getDescription())."</Description>\n";
1981 
1982  // style classes
1983  foreach($this->chars as $char)
1984  {
1985  $xml.= "<Style Tag=\"".ilObjStyleSheet::_determineTag($char["type"]).
1986  "\" Type=\"".$char["type"]."\" Class=\"".$char["class"]."\">\n";
1987  foreach($this->style as $style)
1988  {
1989  if ($style[0]["type"] == $char["type"] && $style[0]["class"] == $char["class"])
1990  {
1991  foreach($style as $tag)
1992  {
1993  $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\" Custom=\"".$tag["custom"]."\" />\n";
1994  }
1995  }
1996  }
1997  $xml.= "</Style>\n";
1998  }
1999 
2000  // colors
2001  foreach($this->getColors() as $color)
2002  {
2003  $xml.="<StyleColor Name=\"".$color["name"]."\" Code=\"".$color["code"]."\"/>\n";
2004  }
2005 
2006  // templates
2008  foreach ($tcts as $tct => $v)
2009  {
2010  $ts = $this->getTemplates($tct);
2011 
2012  foreach ($ts as $t)
2013  {
2014  $xml.="<StyleTemplate Type=\"".$tct."\" Name=\"".$t["name"]."\">\n";
2015  foreach ($t["classes"] as $ct => $c)
2016  {
2017  if ($c != "")
2018  {
2019  $xml.="<StyleTemplateClass ClassType=\"".$ct."\" Class=\"".$c."\"/>\n";
2020  }
2021  }
2022  $xml.="</StyleTemplate>\n";
2023  }
2024  }
2025 
2026 
2027  $xml.= "</StyleSheet>";
2028 //echo "<pre>".htmlentities($xml)."</pre>"; exit;
2029  return $xml;
2030  }
2031 
2032 
2037  {
2038  $sty_data_dir = ilUtil::getDataDir()."/sty";
2039  ilUtil::makeDir($sty_data_dir);
2040  if(!is_writable($sty_data_dir))
2041  {
2042  $this->ilias->raiseError("Style data directory (".$sty_data_dir
2043  .") not writeable.",$this->ilias->error_obj->FATAL);
2044  }
2045 
2046  $style_dir = $sty_data_dir."/sty_".$this->getId();
2047  ilUtil::makeDir($style_dir);
2048  if(!@is_dir($style_dir))
2049  {
2050  $this->ilias->raiseError("Creation of style directory failed (".
2051  $style_dir.").",$this->ilias->error_obj->FATAL);
2052  }
2053 
2054  // create export subdirectory
2055  $ex_dir = $style_dir."/export";
2056  ilUtil::makeDir($ex_dir);
2057  if(!@is_dir($ex_dir))
2058  {
2059  $this->ilias->raiseError("Creation of Import Directory failed (".
2060  $ex_dir.").",$this->ilias->error_obj->FATAL);
2061  }
2062 
2063  return $ex_dir;
2064  }
2065 
2070  {
2071  $sty_data_dir = ilUtil::getDataDir()."/sty";
2072  $style_dir = $sty_data_dir."/sty_".$this->getId();
2073  // create export subdirectory
2074  $ex_dir = $style_dir."/export";
2075 
2076  if (is_dir($ex_dir))
2077  {
2078  ilUtil::delDir($ex_dir, true);
2079  }
2080  }
2081 
2082 
2087  {
2088  $ex_dir = $this->createExportDirectory();
2089  $ex_sub_dir = $ex_dir."/".$this->getExportSubDir();
2090  ilUtil::makeDir($ex_sub_dir);
2091  if(!is_writable($ex_sub_dir))
2092  {
2093  $this->ilias->raiseError("Style data directory (".$ex_sub_dir
2094  .") not writeable.",$this->ilias->error_obj->FATAL);
2095  }
2096  $ex_sub_images_dir = $ex_sub_dir."/images";
2097  ilUtil::makeDir($ex_sub_images_dir);
2098  if(!is_writable($ex_sub_images_dir))
2099  {
2100  $this->ilias->raiseError("Style data directory (".$ex_sub_images_dir
2101  .") not writeable.",$this->ilias->error_obj->FATAL);
2102  }
2103  }
2104 
2108  function setExportSubDir($a_dir)
2109  {
2110  $this->export_sub_dir = $a_dir;
2111  }
2112 
2116  function getExportSubDir()
2117  {
2118  if ($this->export_sub_dir == "")
2119  {
2120  return "sty_".$this->getId();
2121  }
2122  else
2123  {
2124  return $this->export_sub_dir;
2125  }
2126  }
2127 
2133  function export()
2134  {
2135  $this->cleanExportDirectory();
2136  $ex_dir = $this->createExportDirectory();
2137  $this->createExportSubDirectory();
2138  $this->exportXML($ex_dir."/".$this->getExportSubDir());
2139 //echo "-".$this->getImagesDirectory()."-".$ex_dir."/".$this->getExportSubDir()."/images"."-";
2141  $ex_dir."/".$this->getExportSubDir()."/images");
2142  if (is_file($ex_dir."/".$this->getExportSubDir().".zip"))
2143  {
2144  unlink($ex_dir."/".$this->getExportSubDir().".zip");
2145  }
2146  ilUtil::zip($ex_dir."/".$this->getExportSubDir(),
2147  $ex_dir."/".$this->getExportSubDir().".zip");
2148 
2149  return $ex_dir."/".$this->getExportSubDir().".zip";
2150  }
2151 
2155  function exportXML($a_dir)
2156  {
2157  $file = $a_dir."/style.xml";
2158 
2159  // open file
2160  if (!($fp = @fopen($file,"w")))
2161  {
2162  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2163  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2164  }
2165 
2166  // set file permissions
2167  chmod($file, 0770);
2168 
2169  // write xml data into the file
2170  fwrite($fp, $this->getXML());
2171 
2172  // close file
2173  fclose($fp);
2174 
2175  }
2176 
2181  {
2182  $sty_data_dir = ilUtil::getDataDir()."/sty";
2183  ilUtil::makeDir($sty_data_dir);
2184  if(!is_writable($sty_data_dir))
2185  {
2186  $this->ilias->raiseError("Style data directory (".$sty_data_dir
2187  .") not writeable.",$this->ilias->error_obj->FATAL);
2188  }
2189 
2190  $style_dir = $sty_data_dir."/sty_".$this->getId();
2191  ilUtil::makeDir($style_dir);
2192  if(!@is_dir($style_dir))
2193  {
2194  $this->ilias->raiseError("Creation of style directory failed (".
2195  $style_dir.").",$this->ilias->error_obj->FATAL);
2196  }
2197 
2198  // create import subdirectory
2199  $im_dir = $style_dir."/import";
2200  ilUtil::makeDir($im_dir);
2201  if(!@is_dir($im_dir))
2202  {
2203  $this->ilias->raiseError("Creation of Import Directory failed (".
2204  $im_dir.").",$this->ilias->error_obj->FATAL);
2205  }
2206 
2207  return $im_dir;
2208  }
2209 
2213  function import($a_file)
2214  {
2215  parent::create();
2216 
2217  $im_dir = $this->createImportDirectory();
2218 
2219  // handle uploaded files
2220  if (is_array($a_file))
2221  {
2222  ilUtil::moveUploadedFile($a_file["tmp_name"],
2223  $a_file["name"], $im_dir."/".$a_file["name"]);
2224  $file_name = $a_file["name"];
2225  }
2226  else // handle not directly uploaded files
2227  {
2228  $pi = pathinfo($a_file);
2229  $file_name = $pi["basename"];
2230  copy($a_file, $im_dir."/".$file_name);
2231  }
2232  $file = pathinfo($file_name);
2233 
2234  // unzip file
2235  if (strtolower($file["extension"] == "zip"))
2236  {
2237  ilUtil::unzip($im_dir."/".$file_name);
2238  $subdir = basename($file["basename"],".".$file["extension"]);
2239  if (!is_dir($im_dir."/".$subdir))
2240  {
2241  $subdir = "style"; // check style subdir
2242  }
2243  $xml_file = $im_dir."/".$subdir."/style.xml";
2244  }
2245  else // handle xml file directly (old style)
2246  {
2247  $xml_file = $im_dir."/".$file_name;
2248  }
2249 
2250  // load information from xml file
2251 //echo "-$xml_file-";
2252  $this->createFromXMLFile($xml_file, true);
2253 
2254  // copy images
2255  $this->createImagesDirectory();
2256  if (is_dir($im_dir."/".$subdir."/images"))
2257  {
2258  ilUtil::rCopy($im_dir."/".$subdir."/images",
2259  $this->getImagesDirectory());
2260  }
2261 
2263  $this->read();
2264  $this->writeCSSFile();
2265  }
2266 
2271  function createFromXMLFile($a_file, $a_skip_parent_create = false)
2272  {
2273  global $ilDB;
2274 
2275  $this->is_3_10_skin = false;
2276 
2277  if (!$a_skip_parent_create)
2278  {
2279  parent::create();
2280  }
2281  include_once("./Services/Style/classes/class.ilStyleImportParser.php");
2282  $importParser = new ilStyleImportParser($a_file, $this);
2283  $importParser->startParsing();
2284 
2285  // store style parameter
2286  foreach ($this->style as $style)
2287  {
2288  foreach($style as $tag)
2289  {
2290  $id = $ilDB->nextId("style_parameter");
2291 
2292  // migrate old table PageFrame/PageContainer to div
2293  if (in_array($tag["class"], array("PageFrame", "PageContainer")) &&
2294  $tag["tag"] == "table")
2295  {
2296  $tag["tag"] = "div";
2297  if ($tag["parameter"] == "width" && $tag["value"] == "100%")
2298  {
2299  continue;
2300  }
2301  }
2302 
2303  $q = "INSERT INTO style_parameter (id,style_id, tag, class, parameter, type, value, custom) VALUES ".
2304  "(".
2305  $ilDB->quote($id, "integer").",".
2306  $ilDB->quote($this->getId(), "integer").",".
2307  $ilDB->quote($tag["tag"], "text").",".
2308  $ilDB->quote($tag["class"], "text").",".
2309  $ilDB->quote($tag["parameter"], "text").",".
2310  $ilDB->quote($tag["type"], "text").",".
2311  $ilDB->quote($tag["value"], "text").",".
2312  $ilDB->quote((bool) $tag["custom"], "integer").
2313  ")";
2314  $ilDB->manipulate($q);
2315  }
2316  }
2317 
2318  // store characteristics
2319  $this->is_3_10_skin = true;
2320  if (is_array($this->chars))
2321  {
2322  foreach ($this->chars as $char)
2323  {
2324  if ($char["type"] != "")
2325  {
2326  $s = substr($char["class"], strlen($char["class"]) - 6);
2327  if ($s != ":hover")
2328  {
2329  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
2330  "(".$ilDB->quote($this->getId(), "integer").",".
2331  $ilDB->quote($char["type"], "text").",".
2332  $ilDB->quote($char["class"], "text").")";
2333  $ilDB->manipulate($q);
2334  $this->is_3_10_skin = false;
2335  }
2336  }
2337  }
2338  }
2339 
2340  // add style_data record
2341  $q = "INSERT INTO style_data (id, uptodate) VALUES ".
2342  "(".$ilDB->quote($this->getId(), "integer").", 0)";
2343  $ilDB->manipulate($q);
2344 
2345  $this->update();
2346  $this->read();
2347 
2348  if ($this->is_3_10_skin)
2349  {
2350  $this->do_3_10_Migration();
2351  }
2352  //$this->writeCSSFile();
2353  }
2354 
2359  {
2360  $groups = array();
2361 
2362  foreach (self::$parameter as $parameter => $props)
2363  {
2364  $groups[$props["group"]][] = $parameter;
2365  }
2366  return $groups;
2367  }
2368 
2369  static function _getStyleParameterInputType($par)
2370  {
2371  $input = self::$parameter[$par]["input"];
2372  return $input;
2373  }
2374 
2375  static function _getStyleParameterSubPar($par)
2376  {
2377  $subpar = self::$parameter[$par]["subpar"];
2378  return $subpar;
2379  }
2380 
2381  static function _getStyleParameters($a_tag = "")
2382  {
2383  if ($a_tag == "")
2384  {
2385  return self::$parameter;
2386  }
2387  $par = array();
2388  foreach (self::$parameter as $k => $v)
2389  {
2390  if (is_array(self::$filtered_groups[$v["group"]]) &&
2391  !in_array($a_tag, self::$filtered_groups[$v["group"]]))
2392  {
2393  continue;
2394  }
2395  $par[$k] = $v;
2396  }
2397  return $par;
2398  }
2399 
2400  static function _getFilteredGroups()
2401  {
2402  return self::$filtered_groups;
2403  }
2404 
2405  static function _getStyleParameterNumericUnits($a_no_percentage = false)
2406  {
2407  if ($a_no_percentage)
2408  {
2409  return self::$num_unit_no_perc;
2410  }
2411  return self::$num_unit;
2412  }
2413 
2414  static function _getStyleParameterValues($par)
2415  {
2416  return self::$parameter[$par]["values"];
2417  }
2418 
2419  /*static function _getStyleTypes()
2420  {
2421  return self::$style_types;
2422  }*/
2423 
2424  static function _getStyleSuperTypes()
2425  {
2426  return self::$style_super_types;
2427  }
2428 
2429  static function _isExpandable($a_type)
2430  {
2431  return in_array($a_type, self::$expandable_types);
2432  }
2433 
2434  static function _isHideable($a_type)
2435  {
2436  return in_array($a_type, self::$hideable_types);
2437  }
2438 
2439  static function _getStyleSuperTypeForType($a_type)
2440  {
2441  foreach (self::$style_super_types as $s => $t)
2442  {
2443  if (in_array($a_type, $t))
2444  {
2445  return $s;
2446  }
2447  if ($a_type == $s)
2448  {
2449  return $s;
2450  }
2451  }
2452  }
2453 
2457  static function _getCoreStyles()
2458  {
2459  $c_styles = array();
2460  foreach (self::$core_styles as $cstyle)
2461  {
2462  $c_styles[$cstyle["type"].".".ilObjStyleSheet::_determineTag($cstyle["type"]).".".$cstyle["class"]]
2463  = array("type" => $cstyle["type"],
2464  "tag" => ilObjStyleSheet::_determineTag($cstyle["type"]),
2465  "class" => $cstyle["class"]);
2466  }
2467  return $c_styles;
2468  }
2469 
2473  static function _getTemplateClassTypes($a_template_type = "")
2474  {
2475  if ($a_template_type == "")
2476  {
2477  return self::$templates;
2478  }
2479 
2480  return self::$templates[$a_template_type];
2481  }
2482 
2483 
2484  function _getPseudoClasses($tag)
2485  {
2486  return self::$pseudo_classes[$tag];
2487  }
2488 
2490  {
2491  return self::$templates[$t][$k];
2492  }
2493 
2494  static function _determineTag($a_type)
2495  {
2496  return self::$assigned_tags[$a_type];
2497  }
2498 
2502  static function getAvailableParameters()
2503  {
2504  $pars = array();
2505  foreach(self::$parameter as $p => $v)
2506  {
2507  $pars[$p] = $v["values"];
2508  }
2509 
2510  return $pars;
2511  }
2512 
2513 
2517  static function _addMissingStyleClassesToStyle($a_id)
2518  {
2519  $styles = array(array("id" => $a_id));
2521  }
2522 
2527  static function _addMissingStyleClassesToAllStyles($a_styles = "")
2528  {
2529  global $ilDB;
2530 
2531  if ($a_styles == "")
2532  {
2533  $styles = ilObject::_getObjectsDataForType("sty");
2534  }
2535  else
2536  {
2537  $styles = $a_styles;
2538  }
2541 
2542  // get all core image files
2543  $core_images = array();
2544  $core_dir = self::$basic_style_image_dir;
2545  if (is_dir($core_dir))
2546  {
2547  $dir = opendir($core_dir);
2548  while($file = readdir($dir))
2549  {
2550  if (substr($file, 0, 1) != "." && is_file($core_dir."/".$file))
2551  {
2552  $core_images[] = $file;
2553  }
2554  }
2555  }
2556 
2557  foreach ($styles as $style)
2558  {
2559  $id = $style["id"];
2560 
2561  foreach($core_styles as $cs)
2562  {
2563  // check, whether core style class exists
2564  $set = $ilDB->queryF("SELECT * FROM style_char WHERE style_id = %s ".
2565  "AND type = %s AND characteristic = %s",
2566  array("integer", "text", "text"),
2567  array($id, $cs["type"], $cs["class"]));
2568 
2569  // if not, add core style class
2570  if (!($rec = $ilDB->fetchAssoc($set)))
2571  {
2572  $ilDB->manipulateF(
2573  "INSERT INTO style_char (style_id, type, characteristic) ".
2574  " VALUES (%s,%s,%s) ",
2575  array("integer", "text", "text"),
2576  array($id, $cs["type"], $cs["class"]));
2577 
2578  $xpath = new DOMXPath($bdom);
2579  $par_nodes = $xpath->query("/StyleSheet/Style[@Tag = '".$cs["tag"]."' and @Type='".
2580  $cs["type"]."' and @Class='".$cs["class"]."']/StyleParameter");
2581  foreach ($par_nodes as $par_node)
2582  {
2583  // check whether style parameter exists
2584  $set = $ilDB->queryF("SELECT * FROM style_parameter WHERE style_id = %s ".
2585  "AND type = %s AND class = %s AND tag = %s AND parameter = %s",
2586  array("integer", "text", "text", "text", "text"),
2587  array($id, $cs["type"], $cs["class"],
2588  $cs["tag"], $par_node->getAttribute("Name")));
2589 
2590  // if not, create style parameter
2591  if (!($rec = $ilDB->fetchAssoc($set)))
2592  {
2593  $spid = $ilDB->nextId("style_parameter");
2594  $st = $ilDB->manipulateF("INSERT INTO style_parameter (id, style_id, type, class, tag, parameter, value) ".
2595  " VALUES (%s,%s,%s,%s,%s,%s,%s)",
2596  array("integer", "integer", "text", "text", "text", "text", "text"),
2597  array($spid, $id, $cs["type"], $cs["class"], $cs["tag"],
2598  $par_node->getAttribute("Name"), $par_node->getAttribute("Value")));
2599  }
2600  }
2601  }
2602  }
2603 
2604  // now check, whether some core image files are missing
2607  reset($core_images);
2608  foreach($core_images as $cim)
2609  {
2610  if (!is_file($imdir."/".$cim))
2611  {
2612  copy($core_dir."/".$cim, $imdir."/".$cim);
2613  }
2614  }
2615  }
2616  }
2617 
2618  //
2619  // Color management
2620  //
2621 
2626  {
2627  global $ilDB;
2628 
2629  $this->do_3_9_Migration($this->getId());
2630 
2631  //include_once("./Services/Migration/DBUpdate_1385/classes/class.ilStyleMigration.php");
2632  //ilStyleMigration::addMissingStyleCharacteristics($this->getId());
2633 
2634  $this->do_3_10_CharMigration($this->getId());
2635 
2636  // style_char: type for characteristic
2637  $st = $ilDB->prepareManip("UPDATE style_char SET type = ? WHERE characteristic = ?".
2638  " AND style_id = ? ", array("text", "text", "integer"));
2639  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2640  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2641  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2642  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2643  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2644  $ilDB->execute($st, array("page_cont", "Page", $this->getId()));
2645 
2646  // style_parameter: type for class
2647  $st = $ilDB->prepareManip("UPDATE style_parameter SET type = ? WHERE class = ?".
2648  " AND style_id = ? ", array("text", "text", "integer"));
2649  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2650  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2651  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2652  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2653  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2654  $ilDB->execute($st, array("table", "Page", $this->getId()));
2655 
2656  $st = $ilDB->prepareManip("UPDATE style_parameter SET tag = ? WHERE class = ?".
2657  " AND style_id = ? ", array("text", "text", "integer"));
2658  $ilDB->execute($st, array("div", "MediaCaption", $this->getId()));
2659 
2660  // style_char: characteristic for characteristic
2661  $st = $ilDB->prepareManip("UPDATE style_char SET characteristic = ? WHERE characteristic = ?".
2662  " AND style_id = ? ", array("text", "text", "integer"));
2663  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2664  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2665 
2666  // style_parameter: class for class
2667  $st = $ilDB->prepareManip("UPDATE style_parameter SET class = ? WHERE class = ?".
2668  " AND style_id = ? ", array("text", "text", "integer"));
2669  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2670  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2671 
2672  // force rewriting of container style
2673  $st = $ilDB->prepareManip("DELETE FROM style_char WHERE type = ?".
2674  " AND style_id = ? ", array("text", "integer"));
2675  $ilDB->execute($st, array("page_cont", $this->getId()));
2676  $st = $ilDB->prepareManip("DELETE FROM style_parameter WHERE type = ?".
2677  " AND style_id = ? ", array("text", "integer"));
2678  $ilDB->execute($st, array("page_cont", $this->getId()));
2679 
2680  }
2681 
2688  function do_3_10_CharMigration($a_id = "")
2689  {
2690  global $ilDB;
2691 
2692  $add_str = "";
2693  if ($a_id != "")
2694  {
2695  $add_str = " AND style_id = ".$ilDB->quote($a_id, "integer");
2696  }
2697 
2698  $set = $ilDB->query($q = "SELECT DISTINCT style_id, tag, class FROM style_parameter WHERE ".
2699  $ilDB->equals("type", "", "text", true)." ".$add_str);
2700 
2701  while ($rec = $ilDB->fetchAssoc($set))
2702  {
2703  // derive types from tag
2704  $types = array();
2705  switch ($rec["tag"])
2706  {
2707  case "div":
2708  case "p":
2709  if (in_array($rec["class"], array("Headline3", "Headline1",
2710  "Headline2", "TableContent", "List", "Standard", "Remark",
2711  "Additional", "Mnemonic", "Citation", "Example")))
2712  {
2713  $types[] = "text_block";
2714  }
2715  if (in_array($rec["class"], array("Block", "Remark",
2716  "Additional", "Mnemonic", "Example", "Excursus", "Special")))
2717  {
2718  $types[] = "section";
2719  }
2720  if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation")))
2721  {
2722  $types[] = "page";
2723  }
2724  break;
2725 
2726  case "td":
2727  $types[] = "table_cell";
2728  break;
2729 
2730  case "a":
2731  if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink")))
2732  {
2733  $types[] = "link";
2734  }
2735  break;
2736 
2737  case "span":
2738  $types[] = "text_inline";
2739  break;
2740 
2741  case "table":
2742  $types[] = "table";
2743  break;
2744  }
2745 
2746  // check if style_char set exists
2747  foreach ($types as $t)
2748  {
2749  // check if second type already exists
2750  $set4 = $ilDB->queryF("SELECT * FROM style_char ".
2751  " WHERE style_id = %s AND type = %s AND characteristic = %s",
2752  array("integer", "text", "text"),
2753  array($rec["style_id"], $t, $rec["class"]));
2754  if ($rec4 = $ilDB->fetchAssoc($set4))
2755  {
2756  // ok
2757  }
2758  else
2759  {
2760 //echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
2761  $ilDB->manipulateF("INSERT INTO style_char ".
2762  " (style_id, type, characteristic) VALUES ".
2763  " (%s,%s,%s) ",
2764  array("integer", "text", "text"),
2765  array($rec["style_id"], $t, $rec["class"]));
2766  }
2767  }
2768 
2769  // update types
2770  if ($rec["type"] == "")
2771  {
2772  if (count($types) > 0)
2773  {
2774  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2775  " WHERE style_id = %s AND class = %s AND ".$ilDB->equals("type", "", "text", true),
2776  array("text", "integer", "text"),
2777  array($types[0], $rec["style_id"], $rec["class"]));
2778 //echo "<br>3-".$types[0]."-".$rec["style_id"]."-".$rec["class"]."-";
2779 
2780  // links extra handling
2781  if ($types[0] == "link")
2782  {
2783  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2784  " WHERE style_id = %s AND (class = %s OR class = %s) AND ".$ilDB->equals("type", "", "text", true),
2785  array("text", "integer", "text", "text"),
2786  array($types[0], $rec["style_id"], $rec["class"].":visited",
2787  $rec["class"].":hover"));
2788  }
2789  }
2790 
2791  if (count($types) == 2)
2792  {
2793  // select all records of first type and add second type
2794  // records if necessary.
2795  $set2 = $ilDB->queryF("SELECT * FROM style_parameter ".
2796  " WHERE style_id = %s AND class = %s AND type = %s",
2797  array("integer", "text", "text"),
2798  array($rec["style_id"], $rec["class"], $types[0]));
2799  while ($rec2 = $ilDB->fetchAssoc($set2))
2800  {
2801  // check if second type already exists
2802  $set3 = $ilDB->queryF("SELECT * FROM style_parameter ".
2803  " WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
2804  array("integer", "text", "text", "text", "text"),
2805  array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"]));
2806  if ($rec3 = $ilDB->fetchAssoc($set3))
2807  {
2808  // ok
2809  }
2810  else
2811  {
2812  $nid = $ilDB->nextId("style_parameter");
2813  $ilDB->manipulateF("INSERT INTO style_parameter ".
2814  " (id, style_id, tag, class, parameter, value, type) VALUES ".
2815  " (%s, %s,%s,%s,%s,%s,%s) ",
2816  array("integer", "integer", "text", "text", "text", "text", "text"),
2817  array($nid, $rec2["style_id"], $rec2["tag"], $rec2["class"],
2818  $rec2["parameter"], $rec2["value"], $types[1]));
2819  }
2820  }
2821  }
2822  }
2823  }
2824  }
2825 
2829  function do_3_9_Migration($a_id)
2830  {
2831  global $ilDB;
2832 
2833  $classes = array("Example", "Additional", "Citation", "Mnemonic", "Remark");
2834  $pars = array("margin-top", "margin-bottom");
2835 
2836  foreach ($classes as $curr_class)
2837  {
2838  foreach ($pars as $curr_par)
2839  {
2840  $res2 = $ilDB->queryF("SELECT id FROM style_parameter WHERE style_id = %s".
2841  " AND tag = %s AND class= %s AND parameter = %s",
2842  array("integer", "text", "text", "text"),
2843  array($a_id, "p", $curr_class, $curr_par));
2844  if ($row2 = $ilDB->fetchAssoc($res2))
2845  {
2846  $ilDB->manipulateF("UPDATE style_parameter SET value= %s WHERE id = %s",
2847  array("text", "integer"),
2848  array("10px", $row2["id"]));
2849  }
2850  else
2851  {
2852  $nid = $ilDB->nextId("style_parameter");
2853  $ilDB->manipulateF("INSERT INTO style_parameter ".
2854  "(id, style_id, tag, class, parameter,value) VALUES (%s,%s,%s,%s,%s,%s)",
2855  array("integer", "integer", "text", "text", "text", "text"),
2856  array($nid, $a_id, "div", $curr_class, $curr_par, "10px"));
2857  }
2858  }
2859  }
2860 
2861  $ilDB->manipulateF("UPDATE style_parameter SET tag = %s WHERE tag = %s and style_id = %s",
2862  array("text", "text", "integer"),
2863  array("div", "p", $a_id));
2864 
2865  }
2866 
2870 
2874  function getColors()
2875  {
2876  global $ilDB;
2877 
2878  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
2879  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
2880  "ORDER BY color_name");
2881 
2882  $colors = array();
2883  while ($rec = $ilDB->fetchAssoc($set))
2884  {
2885  $colors[] = array(
2886  "name" => $rec["color_name"],
2887  "code" => $rec["color_code"]
2888  );
2889  }
2890 
2891  return $colors;
2892  }
2893 
2897  function addColor($a_name, $a_code)
2898  {
2899  global $ilDB;
2900 
2901  $ilDB->manipulate("INSERT INTO style_color (style_id, color_name, color_code)".
2902  " VALUES (".
2903  $ilDB->quote($this->getId(), "integer").",".
2904  $ilDB->quote($a_name, "text").",".
2905  $ilDB->quote($a_code, "text").
2906  ")");
2907  }
2908 
2912  function updateColor($a_name, $a_new_name, $a_code)
2913  {
2914  global $ilDB;
2915 
2916  // todo: update names in parameters as well
2917 
2918  $ilDB->manipulate("UPDATE style_color SET ".
2919  "color_name = ".$ilDB->quote($a_new_name, "text").", ".
2920  "color_code = ".$ilDB->quote($a_code, "text").
2921  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2922  " AND color_name = ".$ilDB->quote($a_name, "text"));
2923  ilObjStyleSheet::_writeUpToDate($this->getId(), false);
2924 
2925  // rename also the name in the style parameter values
2926  if ($a_name != $a_new_name)
2927  {
2928  $set = $ilDB->query("SELECT * FROM style_parameter ".
2929  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2930  " AND (".
2931  " parameter = ".$ilDB->quote("background-color", "text"). " OR ".
2932  " parameter = ".$ilDB->quote("color", "text"). " OR ".
2933  " parameter = ".$ilDB->quote("border-color", "text"). " OR ".
2934  " parameter = ".$ilDB->quote("border-top-color", "text"). " OR ".
2935  " parameter = ".$ilDB->quote("border-bottom-color", "text"). " OR ".
2936  " parameter = ".$ilDB->quote("border-left-color", "text"). " OR ".
2937  " parameter = ".$ilDB->quote("border-right-color", "text").
2938  ")");
2939  while ($rec = $ilDB->fetchAssoc($set))
2940  {
2941  if ($rec["value"] == "!".$a_name ||
2942  is_int(strpos($rec["value"], "!".$a_name."(")))
2943  {
2944  // parameter is based on color -> rename it
2945  $this->replaceStylePar($rec["tag"], $rec["class"],
2946  $rec["parameter"], str_replace($a_name, $a_new_name, $rec["value"]), $rec["type"], $rec["mq_id"], $rec["custom"]);
2947  }
2948  }
2949  }
2950  }
2951 
2955  function removeColor($a_name)
2956  {
2957  global $ilDB;
2958 
2959  $ilDB->manipulate("DELETE FROM style_color WHERE ".
2960  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2961  " color_name = ".$ilDB->quote($a_name, "text"));
2962  }
2963 
2967  function colorExists($a_color_name)
2968  {
2969  global $ilDB;
2970 
2971  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
2972  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2973  "color_name = ".$ilDB->quote($a_color_name, "text"));
2974  if ($rec = $ilDB->fetchAssoc($set))
2975  {
2976  return true;
2977  }
2978  return false;
2979  }
2980 
2984  function getColorCodeForName($a_name)
2985  {
2986  global $ilDB;
2987 
2988  $pos = strpos($a_name, "(");
2989  if ($pos > 0)
2990  {
2991  $a_i = substr($a_name, $pos + 1);
2992  $a_i = str_replace(")", "", $a_i);
2993  $a_name = substr($a_name, 0, $pos);
2994  }
2995 
2996  $set = $ilDB->query("SELECT color_code FROM style_color WHERE ".
2997  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2998  " color_name = ".$ilDB->quote($a_name, "text"));
2999  if ($rec = $ilDB->fetchAssoc($set))
3000  {
3001  if ($a_i == "")
3002  {
3003  return "#".$rec["color_code"];
3004  }
3005  else
3006  {
3007  return "#".ilObjStyleSheet::_getColorFlavor($rec["color_code"],
3008  (int) $a_i);
3009  }
3010  }
3011  }
3012 
3016  static function _getColorFlavor($a_rgb, $a_i)
3017  {
3018  $rgb = ilObjStyleSheet::_explodeRGB($a_rgb, true);
3019  $hls = ilObjStyleSheet::_RGBToHLS($rgb);
3020 
3021  if ($a_i > 0)
3022  {
3023  $hls["l"] = $hls["l"] + ((255 - $hls["l"]) * ($a_i / 100));
3024  }
3025  if ($a_i < 0)
3026  {
3027  $hls["l"] = $hls["l"] - (($hls["l"]) * (-$a_i / 100));
3028  }
3029 
3030  $rgb = ilObjStyleSheet::_HLSToRGB($hls);
3031 
3032  foreach ($rgb as $k => $v)
3033  {
3034  $rgb[$k] = str_pad(dechex($v), 2, "0", STR_PAD_LEFT);
3035  }
3036 
3037  return $rgb["r"].$rgb["g"].$rgb["b"];
3038  }
3039 
3043  static function _explodeRGB($a_rgb, $as_dec = false)
3044  {
3045  $r["r"] = substr($a_rgb, 0, 2);
3046  $r["g"] = substr($a_rgb, 2, 2);
3047  $r["b"] = substr($a_rgb, 4, 2);
3048 
3049  if ($as_dec)
3050  {
3051  $r["r"] = (int) hexdec($r["r"]);
3052  $r["g"] = (int) hexdec($r["g"]);
3053  $r["b"] = (int) hexdec($r["b"]);
3054  }
3055 
3056  return $r;
3057  }
3058 
3062  static function _RGBToHLS($a_rgb)
3063  {
3064  $r = $a_rgb["r"] / 255;
3065  $g = $a_rgb["g"] / 255;
3066  $b = $a_rgb["b"] / 255;
3067 
3068  // max / min
3069  $max = max($r,$g,$b);
3070  $min = min($r,$g,$b);
3071 
3072  //lightness
3073  $l = ($max + $min) / 2;
3074 
3075  if ($max == $min)
3076  {
3077  $s = 0;
3078  $h = 0;
3079  }
3080  else
3081  {
3082  if ($l < 0.5)
3083  {
3084  $s = ($max - $min) / ($max + $min);
3085  }
3086  else
3087  {
3088  $s = ($max - $min) / (2.0 - $max - $min);
3089  }
3090 
3091  if ($r == $max)
3092  {
3093  $h = ($g - $b) / ($max - $min);
3094  }
3095  else if ($g == $max)
3096  {
3097  $h = 2.0 + ($b - $r) / ($max - $min);
3098  }
3099  else if ($b == $max)
3100  {
3101  $h = 4.0 + ($r - $g) / ($max - $min);
3102  }
3103  }
3104 
3105  $hls["h"] = round(($h / 6) * 255);
3106  $hls["l"] = round($l * 255);
3107  $hls["s"] = round($s * 255);
3108 
3109  return $hls;
3110  }
3111 
3115  static function _HLSToRGB($a_hls)
3116  {
3117  $h = $a_hls["h"] / 255;
3118  $l = $a_hls["l"] / 255;
3119  $s = $a_hls["s"] / 255;
3120 
3121  $rgb["r"] = $rgb["g"] = $rgb["b"] = 0;
3122 
3123  // If S=0, define R, G, and B all to L
3124  if ($s == 0)
3125  {
3126  $rgb["r"] = $rgb["g"] = $rgb["b"] = $l;
3127  }
3128  else
3129  {
3130 
3131  if ($l < 0.5)
3132  {
3133  $temp2 = $l * (1.0 + $s);
3134  }
3135  else
3136  {
3137  $temp2 = $l + $s - $l * $s;
3138  }
3139 
3140  $temp1 = 2.0 * $l - $temp2;
3141 
3142 
3143  # For each of R, G, B, compute another temporary value, temp3, as follows:
3144  foreach ($rgb as $k => $v)
3145  {
3146  switch ($k)
3147  {
3148  case "r":
3149  $temp3 = $h + 1.0 / 3.0;
3150  break;
3151 
3152  case "g":
3153  $temp3 = $h;
3154  break;
3155 
3156  case "b":
3157  $temp3 = $h - 1.0/3.0;
3158  break;
3159  }
3160  if ($temp3 < 0)
3161  {
3162  $temp3 = $temp3 + 1.0;
3163  }
3164  if ($temp3 > 1)
3165  {
3166  $temp3 = $temp3 - 1.0;
3167  }
3168 
3169  if (6.0 * $temp3 < 1)
3170  {
3171  $rgb[$k] = $temp1 + ($temp2 - $temp1) * 6.0 * $temp3;
3172  }
3173  else if (2.0 * $temp3 < 1)
3174  {
3175  $rgb[$k] = $temp2;
3176  }
3177  else if (3.0 * $temp3 < 2)
3178  {
3179  $rgb[$k] = $temp1 + ($temp2 - $temp1) * ((2.0/3.0) - $temp3) * 6.0;
3180  }
3181  else
3182  {
3183  $rgb[$k] = $temp1;
3184  }
3185  }
3186  }
3187 
3188  $rgb["r"] = round($rgb["r"] * 255);
3189  $rgb["g"] = round($rgb["g"] * 255);
3190  $rgb["b"] = round($rgb["b"] * 255);
3191 
3192  return $rgb;
3193  }
3194 
3195  //
3196  // Media queries
3197  //
3198 
3202 
3206  function getMediaQueries()
3207  {
3208  global $ilDB;
3209 
3210  $set = $ilDB->query("SELECT * FROM sty_media_query WHERE ".
3211  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
3212  "ORDER BY order_nr");
3213 
3214  $mq = array();
3215  while ($rec = $ilDB->fetchAssoc($set))
3216  {
3217  $mq[] = $rec;
3218  }
3219 
3220  return $mq;
3221  }
3222 
3227  function addMediaQuery($a_mquery)
3228  {
3229  global $ilDB;
3230 
3231  $id = $ilDB->nextId("sty_media_query");
3232  $order_nr = $this->getMaxMQueryOrderNr() + 10;
3233 
3234  $ilDB->manipulate("INSERT INTO sty_media_query (id, style_id, mquery, order_nr)".
3235  " VALUES (".
3236  $ilDB->quote($id, "integer").",".
3237  $ilDB->quote($this->getId(), "integer").",".
3238  $ilDB->quote($a_mquery, "text").",".
3239  $ilDB->quote($order_nr, "integer").
3240  ")");
3241 
3242  return $id;
3243  }
3244 
3250  {
3251  global $ilDB;
3252 
3253  $set = $ilDB->query("SELECT max(order_nr) mnr FROM sty_media_query ".
3254  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")
3255  );
3256  $rec = $ilDB->fetchAssoc($set);
3257 
3258  return (int) $rec["mnr"];
3259  }
3260 
3267  function updateMediaQuery($a_id, $a_mquery)
3268  {
3269  global $ilDB;
3270 
3271  $ilDB->manipulate("UPDATE sty_media_query SET ".
3272  " mquery = ".$ilDB->quote($a_mquery, "text").
3273  " WHERE id = ".$ilDB->quote($a_id, "integer")
3274  );
3275  }
3276 
3283  function getMediaQueryForId($a_id)
3284  {
3285  global $ilDB;
3286 
3287  $set = $ilDB->query("SELECT * FROM sty_media_query ".
3288  " WHERE id = ".$ilDB->quote($a_id, "integer")
3289  );
3290  return $ilDB->fetchAssoc($set);
3291  }
3292 
3298  function deleteMediaQuery($a_id)
3299  {
3300  global $ilDB;
3301 
3302  $ilDB->manipulate("DELETE FROM sty_media_query WHERE ".
3303  " style_id = ".$ilDB->quote($this->getId(), "integer").
3304  " AND id = ".$ilDB->quote($a_id, "integer")
3305  );
3306  $this->saveMediaQueryOrder();
3307  }
3308 
3314  function saveMediaQueryOrder($a_order_nr = null)
3315  {
3316  global $ilDB;
3317 
3318  $mqueries = $this->getMediaQueries();
3319  if (is_array ($a_order_nr))
3320  {
3321  foreach ($mqueries as $k => $mq)
3322  {
3323  $mqueries[$k]["order_nr"] = $a_order_nr[$mq["id"]];
3324  }
3325  $mqueries = ilUtil::sortArray($mqueries, "order_nr", "", true);
3326  }
3327  $cnt = 10;
3328  foreach ($mqueries as $mq)
3329  {
3330  $ilDB->manipulate("UPDATE sty_media_query SET ".
3331  " order_nr = ".$ilDB->quote($cnt, "integer").
3332  " WHERE id = ".$ilDB->quote($mq["id"], "integer")
3333  );
3334  $cnt+= 10;
3335  }
3336  }
3337 
3338 
3339  //
3340  // Table template management
3341  //
3342 
3346  function getTemplates($a_type)
3347  {
3348  global $ilDB;
3349 
3350  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3351  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3352  "temp_type = ".$ilDB->quote($a_type, "text")." ".
3353  "ORDER BY name");
3354 
3355  $templates = array();
3356  while ($rec = $ilDB->fetchAssoc($set))
3357  {
3358  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3359  $templates[] = $rec;
3360  }
3361 
3362  return $templates;
3363  }
3364 
3368  function getTemplateClasses($a_tid)
3369  {
3370  global $ilDB;
3371  $set = $ilDB->query("SELECT * FROM style_template_class WHERE ".
3372  "template_id = ".$ilDB->quote($a_tid, "integer"));
3373 
3374  $class = array();
3375  while ($rec = $ilDB->fetchAssoc($set))
3376  {
3377  $key = $rec["class_type"];
3378  $class[$key] = $rec["class"];
3379  }
3380 
3381  return $class;
3382  }
3383 
3384 
3388  function addTemplate($a_type, $a_name, $a_classes)
3389  {
3390  global $ilDB;
3391 
3392  $tid = $ilDB->nextId("style_template");
3393  $ilDB->manipulate($q = "INSERT INTO style_template ".
3394  "(id, style_id, name, temp_type)".
3395  " VALUES (".
3396  $ilDB->quote($tid, "integer").",".
3397  $ilDB->quote($this->getId(), "integer").",".
3398  $ilDB->quote($a_name, "text").",".
3399  $ilDB->quote($a_type, "text").
3400  ")");
3401 
3402  foreach ($a_classes as $t => $c)
3403  {
3404  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3405  "(template_id, class_type, class)".
3406  " VALUES (".
3407  $ilDB->quote($tid, "integer").",".
3408  $ilDB->quote($t, "text").",".
3409  $ilDB->quote($c, "text").
3410  ")");
3411  }
3412 
3413  include_once("./Services/Style/classes/class.ilObjStyleSheetGUI.php");
3414  $this->writeTemplatePreview($tid,
3415  ilObjStyleSheetGUI::_getTemplatePreview($this, $a_type, $tid, true));
3416 
3417  return $tid;
3418  }
3419 
3423  function updateTemplate($a_t_id, $a_name, $a_classes)
3424  {
3425  global $ilDB;
3426 
3427  $ilDB->manipulate("UPDATE style_template SET ".
3428  "name = ".$ilDB->quote($a_name, "text").
3429  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3430 
3431  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3432  "template_id = ".$ilDB->quote($a_t_id, "integer")
3433  );
3434  foreach ($a_classes as $t => $c)
3435  {
3436  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3437  "(template_id, class_type, class)".
3438  " VALUES (".
3439  $ilDB->quote($a_t_id, "integer").",".
3440  $ilDB->quote($t, "text").",".
3441  $ilDB->quote($c, "text").
3442  ")");
3443  }
3444 
3445  }
3446 
3450  function templateExists($a_template_name)
3451  {
3452  global $ilDB;
3453 
3454  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3455  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3456  "name = ".$ilDB->quote($a_template_name, "text"));
3457  if ($rec = $ilDB->fetchAssoc($set))
3458  {
3459  return true;
3460  }
3461  return false;
3462  }
3463 
3467  function getTemplate($a_t_id)
3468  {
3469  global $ilDB;
3470 
3471  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3472  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
3473  " AND id = ".$ilDB->quote($a_t_id, "integer"));
3474 
3475  if ($rec = $ilDB->fetchAssoc($set))
3476  {
3477  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3478 
3479  $template = $rec;
3480  return $template;
3481  }
3482  return array();
3483  }
3484 
3488  function lookupTemplateName($a_t_id)
3489  {
3490  global $ilDB;
3491 
3492  $set = $ilDB->query("SELECT name FROM style_template WHERE ".
3493  " id = ".$ilDB->quote($a_t_id, "integer"));
3494 
3495  if ($rec = $ilDB->fetchAssoc($set))
3496  {
3497  return $rec["name"];
3498  }
3499 
3500  return false;
3501  }
3502 
3506  function getTemplateXML()
3507  {
3508  global $ilDB;
3509 
3510  $tag = "<StyleTemplates>";
3511 
3512  $ttypes = array("table", "vaccordion", "haccordion");
3513 
3514  foreach ($ttypes as $ttype)
3515  {
3516  $ts = $this->getTemplates($ttype);
3517 
3518  foreach($ts as $t)
3519  {
3521  /*$atts = array("table" => "TableClass",
3522  "caption" => "CaptionClass",
3523  "row_head" => "RowHeadClass",
3524  "row_foot" => "RowFootClass",
3525  "col_head" => "ColHeadClass",
3526  "col_foot" => "ColFootClass",
3527  "odd_row" => "OddRowClass",
3528  "even_row" => "EvenRowClass",
3529  "odd_col" => "OddColClass",
3530  "even_col" => "EvenColClass");*/
3531  $c = $t["classes"];
3532 
3533  $tag.= '<StyleTemplate Name="'.$t["name"].'">';
3534 
3535  foreach ($atts as $type => $t)
3536  {
3537  if ($c[$type] != "")
3538  {
3539  $tag.= '<StyleClass Type="'.$type.'" Value="'.$c[$type].'" />';
3540  }
3541  }
3542 
3543  $tag.= "</StyleTemplate>";
3544  }
3545  }
3546 
3547  $tag.= "</StyleTemplates>";
3548 
3549 //echo htmlentities($tag);
3550  return $tag;
3551  }
3552 
3556  function writeTemplatePreview($a_t_id, $a_preview_html)
3557  {
3558  global $ilDB;
3559  $a_preview_html = str_replace(' width=""', "", $a_preview_html);
3560  $a_preview_html = str_replace(' valign="top"', "", $a_preview_html);
3561  $a_preview_html = str_replace('<div class="ilc_text_block_TableContent">', "<div>", $a_preview_html);
3562 //echo "1-".strlen($a_preview_html)."-";
3563 //echo htmlentities($a_preview_html);
3564  if (strlen($a_preview_html) > 4000)
3565  {
3566 //echo "2";
3567  $a_preview_html = "";
3568  }
3569  $ilDB->manipulate("UPDATE style_template SET ".
3570  "preview = ".$ilDB->quote($a_preview_html, "text").
3571  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3572  }
3573 
3577  function lookupTemplatePreview($a_t_id)
3578  {
3579  global $ilDB;
3580 
3581  $set = $ilDB->query("SELECT preview FROM style_template ".
3582  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3583  if ($rec = $ilDB->fetchAssoc($set))
3584  {
3585  return $rec["preview"];
3586  }
3587 
3588  return "";
3589  }
3590 
3594  static function _lookupTemplateIdByName($a_style_id, $a_name)
3595  {
3596  global $ilDB;
3597 
3598  $set = $ilDB->query("SELECT id FROM style_template ".
3599  " WHERE style_id = ".$ilDB->quote($a_style_id, "integer").
3600  " AND name = ".$ilDB->quote($a_name, "text"));
3601  if ($rec = $ilDB->fetchAssoc($set))
3602  {
3603  return $rec["id"];
3604  }
3605 
3606  return false;
3607  }
3608 
3612  function removeTemplate($a_t_id)
3613  {
3614  global $ilDB;
3615 
3616  $ilDB->manipulate("DELETE FROM style_template WHERE ".
3617  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3618  " id = ".$ilDB->quote($a_t_id, "integer"));
3619 
3620  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3621  "template_id = ".$ilDB->quote($a_t_id, "integer")
3622  );
3623 
3624  }
3625 
3629  function writeStyleSetting($a_name, $a_value)
3630  {
3631  global $ilDB;
3632 
3633  $ilDB->manipulate("DELETE FROM style_setting WHERE ".
3634  " style_id = ".$ilDB->quote($this->getId(), "integer").
3635  " AND name = ".$ilDB->quote($a_name, "text")
3636  );
3637 
3638  $ilDB->manipulate("INSERT INTO style_setting ".
3639  "(style_id, name, value) VALUES (".
3640  $ilDB->quote($this->getId(), "integer").",".
3641  $ilDB->quote($a_name, "text").",".
3642  $ilDB->quote($a_value, "text").
3643  ")");
3644  }
3645 
3649  function lookupStyleSetting($a_name)
3650  {
3651  global $ilDB;
3652 
3653  $set = $ilDB->query("SELECT value FROM style_setting ".
3654  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
3655  " AND name = ".$ilDB->quote($a_name, "text")
3656  );
3657  $rec = $ilDB->fetchAssoc($set);
3658 
3659  return $rec["value"];
3660  }
3661 
3665  static function writeStyleUsage($a_obj_id, $a_style_id)
3666  {
3667  global $ilDB;
3668 
3669  $ilDB->replace("style_usage", array(
3670  "obj_id" => array("integer", (int) $a_obj_id)),
3671  array(
3672  "style_id" => array("integer", (int) $a_style_id))
3673  );
3674  }
3675 
3679  static function lookupObjectStyle($a_obj_id)
3680  {
3681  global $ilDB;
3682 
3683  $set = $ilDB->query("SELECT style_id FROM style_usage ".
3684  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")
3685  );
3686  $rec = $ilDB->fetchAssoc($set);
3687 
3688  if (ilObject::_lookupType($rec["style_id"]) == "sty")
3689  {
3690  return (int) $rec["style_id"];
3691  }
3692 
3693  return 0;
3694  }
3695 
3696 
3697 }
3698 ?>
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.
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.
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.
_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
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.
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)
_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.
$r
getUpToDate()
Get up to date.
addMediaQuery($a_mquery)
Add media query.