ILIAS  release_4-4 Revision
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 
180  "opacity" => array(
181  "values" => array(),
182  "input" => "percentage",
183  "group" => "special"),
184  "cursor" => array(
185  "values" => array("auto", "default", "crosshair", "pointer", "move",
186  "n-resize", "ne-resize", "e-resize", "se-resize", "s-resize", "sw-resize",
187  "w-resize", "nw-resize", "text", "wait", "help"),
188  "input" => "select",
189  "group" => "special"),
190  "clear" => array(
191  "values" => array ("both","left","right","none"),
192  "input" => "select",
193  "group" => "special"),
194 
195  "list-style-type.ol" => array(
196  "values" => array ("decimal","lower-roman","upper-roman",
197  "lower-alpha", "upper-alpha", "lower-greek", "hebrew",
198  "decimal-leading-zero", "cjk-ideographic", "hiragana",
199  "katakana", "hiragana-iroha", "katakana-iroha", "none"),
200  "input" => "select",
201  "group" => "ol"),
202  "list-style-type.ul" => array(
203  "values" => array ("disc","circle","square",
204  "none"),
205  "input" => "select",
206  "group" => "ul"),
207  "list-style-image.ul" => array(
208  "values" => array(),
209  "input" => "background_image",
210  "group" => "ul"),
211  "list-style-position.ol" => array(
212  "values" => array ("inside","outside"),
213  "input" => "select",
214  "group" => "ol"),
215  "list-style-position.ul" => array(
216  "values" => array ("inside","outside"),
217  "input" => "select",
218  "group" => "ul"
219  ),
220  "border-collapse" => array(
221  "values" => array ("collapse","separate"),
222  "input" => "select",
223  "group" => "table"
224  ),
225  "caption-side" => array(
226  "values" => array ("top","bottom","left","right"),
227  "input" => "select",
228  "group" => "table"
229  )
230  );
231 
232  // filter groups of properties that should only be
233  // displayed with matching tag (group -> tags)
234  public static $filtered_groups =
235  array("ol" => array("ol"), "ul" => array("ul"),
236  "table" => array("table"), "positioning" => array("h1", "h2", "h3", "div", "img", "table", "a"));
237 
238  // style types and their super type
239  public static $style_super_types = array(
240  "text_block" => array("text_block", "heading1", "heading2", "heading3"),
241  "text_inline" => array("text_inline"),
242  "section" => array("section"),
243  "link" => array("link"),
244  "table" => array("table", "table_cell", "table_caption"),
245  "list" => array("list_o", "list_u", "list_item"),
246  "flist" => array("flist_cont", "flist_head", "flist", "flist_li", "flist_a"),
247  "media" => array("media_cont", "media_caption", "iim", "marker"),
248  "tabs" => array("va_cntr", "va_icntr", "va_ihead", "va_icont",
249  "ha_cntr", "ha_icntr", "ha_ihead", "ha_icont"),
250  "question" => array("question", "qtitle", "qanswer", "qinput", "qlinput", "qsubmit", "qfeedr", "qfeedw",
251  "qimg", "qordul", "qordli", "qimgd", "qetitem", "qetcorr", "qover"),
252  "page" => array("page_frame", "page_cont", "page_title", "page_fn",
253  "page_tnav", "page_bnav", "page_lnav", "page_rnav", "page_lnavlink", "page_rnavlink",
254  "page_lnavimage", "page_rnavimage"),
255  "glo" => array("glo_overlay", "glo_ovtitle", "glo_ovclink", "glo_ovuglink", "glo_ovuglistlink"),
256  "sco" => array("sco_title", "sco_keyw", "sco_desc", "sco_desct", "sco_obj", "sco_objt", "sco_fmess"),
257  "rte" => array("rte_menu", "rte_mlink", "rte_tree", "rte_node", "rte_tlink","rte_status",
258  "rte_tul", "rte_tli", "rte_texp", "rte_tclink", "rte_drag")
259  );
260 
261  // these types are expandable, i.e. the user can define new style classes
262  public static $expandable_types = array (
263  "text_block", "section", "media_cont", "table", "table_cell", "flist_li", "table_caption",
264  "list_o", "list_u",
265  "va_cntr", "va_icntr", "va_ihead", "va_icont",
266  "ha_cntr", "ha_icntr", "ha_ihead", "ha_icont"
267  );
268 
269  // these types can be hidden in the content editor
270  public static $hideable_types = array (
271  "table", "table_cell"
272  );
273 
274  // tag that are used by style types
275  public static $assigned_tags = array (
276  "text_block" => "div",
277  "heading1" => "h1",
278  "heading2" => "h2",
279  "heading3" => "h3",
280  "text_inline" => "span",
281  "section" => "div",
282  "link" => "a",
283  "table" => "table",
284  "table_cell" => "td",
285  "table_caption" => "caption",
286  "media_cont" => "table",
287  "media_caption" => "div",
288  "iim" => "div",
289  "marker" => "a",
290  "glo_overlay" => "div",
291  "glo_ovtitle" => "h1",
292  "glo_ovclink" => "a",
293  "glo_ovuglink" => "a",
294  "glo_ovuglistlink" => "a",
295  "sco_title" => "div",
296  "sco_keyw" => "div",
297  "sco_desc" => "div",
298  "sco_obj" => "div",
299  "sco_desct" => "div",
300  "sco_objt" => "div",
301  "sco_fmess" => "div",
302  "rte_menu" => "div",
303  "rte_mlink" => "a",
304  "rte_tree" => "div",
305  "rte_tclink" => "a",
306  "rte_drag" => "div",
307  "rte_node" => "div",
308  "rte_status" => "div",
309  "rte_tlink" => "a",
310  "rte_tul" => "div",
311  "rte_tli" => "div",
312  "rte_texp" => "a",
313  "list_o" => "ol",
314  "list_u" => "ul",
315  "list_item" => "li",
316  "flist_cont" => "div",
317  "flist_head" => "div",
318  "flist" => "ul",
319  "flist_li" => "li",
320  "flist_a" => "a",
321  "question" => "div",
322  "qtitle" => "div",
323  "qanswer" => "div",
324  "qimg" => "img",
325  "qimgd" => "a",
326  "qordul" => "ul",
327  "qordli" => "li",
328  "qetitem" => "a",
329  "qetcorr" => "span",
330  "qinput" => "input",
331  "qlinput" => "textarea",
332  "qsubmit" => "input",
333  "qfeedr" => "div",
334  "qfeedw" => "div",
335  "qover" => "div",
336  "page_frame" => "div",
337  "page_cont" => "div",
338  "page_fn" => "div",
339  "page" => "div",
340  "page_tnav" => "div",
341  "page_bnav" => "div",
342  "page_lnav" => "div",
343  "page_rnav" => "div",
344  "page_lnavlink" => "a",
345  "page_rnavlink" => "a",
346  "page_lnavimage" => "img",
347  "page_rnavimage" => "img",
348  "page_title" => "h1",
349  "va_cntr" => "div",
350  "va_icntr" => "div",
351  "va_icont" => "div",
352  "va_ihead" => "div",
353  "ha_cntr" => "div",
354  "ha_icntr" => "div",
355  "ha_icont" => "div",
356  "ha_ihead" => "div"
357  );
358 
359  // pseudo classes
360  public static $pseudo_classes =
361  array ("a" => array("hover"), "div" => array("hover"), "img" => array("hover"));
362 
363  // core styles these styles MUST exists -> see also basic_style/style.xml
364  public static $core_styles = array(
365  array("type" => "text_block", "class" => "Standard"),
366  array("type" => "text_block", "class" => "List"),
367  array("type" => "text_block", "class" => "TableContent"),
368  array("type" => "heading1", "class" => "Headline1"),
369  array("type" => "heading2", "class" => "Headline2"),
370  array("type" => "heading3", "class" => "Headline3"),
371  array("type" => "text_inline", "class" => "Comment"),
372  array("type" => "text_inline", "class" => "Emph"),
373  array("type" => "text_inline", "class" => "Quotation"),
374  array("type" => "text_inline", "class" => "Strong"),
375  array("type" => "text_inline", "class" => "Accent"),
376  array("type" => "text_inline", "class" => "Important"),
377  array("type" => "link", "class" => "IntLink"),
378  array("type" => "link", "class" => "ExtLink"),
379  array("type" => "link", "class" => "FootnoteLink"),
380  array("type" => "link", "class" => "FileLink"),
381  array("type" => "link", "class" => "GlossaryLink"),
382  array("type" => "media_cont", "class" => "MediaContainer"),
383  array("type" => "table", "class" => "StandardTable"),
384  array("type" => "media_caption", "class" => "MediaCaption"),
385  array("type" => "iim", "class" => "ContentPopup"),
386  array("type" => "marker", "class" => "Marker"),
387  array("type" => "page_frame", "class" => "PageFrame"),
388  array("type" => "page_cont", "class" => "PageContainer"),
389  array("type" => "page", "class" => "Page"),
390  array("type" => "page_tnav", "class" => "TopNavigation"),
391  array("type" => "page_bnav", "class" => "BottomNavigation"),
392  array("type" => "page_lnav", "class" => "LeftNavigation"),
393  array("type" => "page_rnav", "class" => "RightNavigation"),
394  array("type" => "page_lnavlink", "class" => "LeftNavigationLink"),
395  array("type" => "page_rnavlink", "class" => "RightNavigationLink"),
396  array("type" => "page_lnavimage", "class" => "LeftNavigationImage"),
397  array("type" => "page_rnavimage", "class" => "RightNavigationImage"),
398  array("type" => "page_fn", "class" => "Footnote"),
399  array("type" => "page_title", "class" => "PageTitle"),
400  array("type" => "glo_overlay", "class" => "GlossaryOverlay"),
401  array("type" => "glo_ovtitle", "class" => "GlossaryOvTitle"),
402  array("type" => "glo_ovclink", "class" => "GlossaryOvCloseLink"),
403  array("type" => "glo_ovuglink", "class" => "GlossaryOvUnitGloLink"),
404  array("type" => "glo_ovuglistlink", "class" => "GlossaryOvUGListLink"),
405  array("type" => "sco_title", "class" => "Title"),
406  array("type" => "sco_desc", "class" => "Description"),
407  array("type" => "sco_desct", "class" => "DescriptionTop"),
408  array("type" => "sco_keyw", "class" => "Keywords"),
409  array("type" => "sco_obj", "class" => "Objective"),
410  array("type" => "sco_objt", "class" => "ObjectiveTop"),
411  array("type" => "sco_fmess", "class" => "FinalMessage"),
412  array("type" => "rte_menu", "class" => "RTEMenu"),
413  array("type" => "rte_menu", "class" => "RTELogo"),
414  array("type" => "rte_menu", "class" => "RTELinkBar"),
415  array("type" => "rte_mlink", "class" => "RTELink"),
416  array("type" => "rte_mlink", "class" => "RTELinkDisabled"),
417  array("type" => "rte_tree", "class" => "RTETree"),
418  array("type" => "rte_node", "class" => "RTECourse"),
419  array("type" => "rte_node", "class" => "RTEChapter"),
420  array("type" => "rte_node", "class" => "RTESco"),
421  array("type" => "rte_node", "class" => "RTEAsset"),
422  array("type" => "rte_node", "class" => "RTECourseDisabled"),
423  array("type" => "rte_node", "class" => "RTEChapterDisabled"),
424  array("type" => "rte_node", "class" => "RTEScoDisabled"),
425  array("type" => "rte_node", "class" => "RTEAssetDisabled"),
426  array("type" => "rte_status", "class" => "RTEAsset"),
427  array("type" => "rte_status", "class" => "RTECompleted"),
428  array("type" => "rte_status", "class" => "RTENotAttempted"),
429  array("type" => "rte_status", "class" => "RTERunning"),
430  array("type" => "rte_status", "class" => "RTEIncomplete"),
431  array("type" => "rte_status", "class" => "RTEPassed"),
432  array("type" => "rte_status", "class" => "RTEFailed"),
433  array("type" => "rte_status", "class" => "RTEBrowsed"),
434  array("type" => "rte_tlink", "class" => "RTETreeLink"),
435  array("type" => "rte_tlink", "class" => "RTETreeLinkDisabled"),
436  array("type" => "rte_tlink", "class" => "RTETreeCurrent"),
437  array("type" => "rte_tul", "class" => "RTETreeList"),
438  array("type" => "rte_tli", "class" => "RTETreeItem"),
439  array("type" => "rte_texp", "class" => "RTETreeExpanded"),
440  array("type" => "rte_texp", "class" => "RTETreeCollapsed"),
441  array("type" => "rte_tree", "class" => "RTETreeControl"),
442  array("type" => "rte_tclink", "class" => "RTETreeControlLink"),
443  array("type" => "rte_drag", "class" => "RTEDragBar"),
444  array("type" => "list_o", "class" => "NumberedList"),
445  array("type" => "list_u", "class" => "BulletedList"),
446  array("type" => "list_item", "class" => "StandardListItem"),
447  array("type" => "question", "class" => "Standard"),
448  array("type" => "question", "class" => "SingleChoice"),
449  array("type" => "question", "class" => "MultipleChoice"),
450  array("type" => "question", "class" => "TextQuestion"),
451  array("type" => "question", "class" => "OrderingQuestion"),
452  array("type" => "question", "class" => "MatchingQuestion"),
453  array("type" => "question", "class" => "ImagemapQuestion"),
454  array("type" => "question", "class" => "ErrorText"),
455  array("type" => "question", "class" => "TextSubset"),
456  array("type" => "question", "class" => "ClozeTest"),
457  array("type" => "qtitle", "class" => "Title"),
458  array("type" => "qanswer", "class" => "Answer"),
459  array("type" => "qimg", "class" => "QuestionImage"),
460  array("type" => "qimgd", "class" => "ImageDetailsLink"),
461  array("type" => "qordul", "class" => "OrderList"),
462  array("type" => "qordli", "class" => "OrderListItem"),
463  array("type" => "qordul", "class" => "OrderListHorizontal"),
464  array("type" => "qordli", "class" => "OrderListItemHorizontal"),
465  array("type" => "qetitem", "class" => "ErrorTextItem"),
466  array("type" => "qetitem", "class" => "ErrorTextSelected"),
467  array("type" => "qetcorr", "class" => "ErrorTextCorrected"),
468  array("type" => "qinput", "class" => "TextInput"),
469  array("type" => "qlinput", "class" => "LongTextInput"),
470  array("type" => "qsubmit", "class" => "Submit"),
471  array("type" => "qfeedr", "class" => "FeedbackRight"),
472  array("type" => "qfeedw", "class" => "FeedbackWrong"),
473  array("type" => "qover", "class" => "Correct"),
474  array("type" => "qover", "class" => "Inorrect"),
475  array("type" => "qover", "class" => "StatusMessage"),
476  array("type" => "qover", "class" => "WrongAnswersMessage"),
477  array("type" => "flist_cont", "class" => "FileListContainer"),
478  array("type" => "flist_head", "class" => "FileListHeading"),
479  array("type" => "flist", "class" => "FileList"),
480  array("type" => "flist_li", "class" => "FileListItem"),
481  array("type" => "flist_a", "class" => "FileListItemLink")
482  );
483 
484  public static $templates = array(
485  "table" => array(
486  "table" => "table",
487  "caption" => "table_caption",
488  "row_head" => "table_cell",
489  "row_foot" => "table_cell",
490  "col_head" => "table_cell",
491  "col_foot" => "table_cell",
492  "odd_row" => "table_cell",
493  "even_row" => "table_cell",
494  "odd_col" => "table_cell",
495  "even_col" => "table_cell"),
496  "vaccordion" => array(
497  "va_cntr" => "va_cntr",
498  "va_icntr" => "va_icntr",
499  "va_ihead" => "va_ihead",
500  "va_icont" => "va_icont"
501  ),
502  "haccordion" => array(
503  "ha_cntr" => "ha_cntr",
504  "ha_icntr" => "ha_icntr",
505  "ha_ihead" => "ha_ihead",
506  "ha_icont" => "ha_icont"
507  )
508  );
509 
510  // basic style xml file, image directory and dom
511  protected static $basic_style_file = "./Services/Style/basic_style/style.xml";
512  protected static $basic_style_image_dir = "./Services/Style/basic_style/images";
513  protected static $basic_style_dom;
514 
521  function ilObjStyleSheet($a_id = 0, $a_call_by_reference = false)
522  {
523  $this->type = "sty";
524  $this->style = array();
525  if($a_call_by_reference)
526  {
527  $this->ilias->raiseError("Can't instantiate style object via reference id.",$this->ilias->error_obj->FATAL);
528  }
529 
530  parent::ilObject($a_id, false);
531  }
532 
536  function setRefId()
537  {
538  $this->ilias->raiseError("Operation ilObjStyleSheet::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
539  }
540 
544  function getRefId()
545  {
546  return "";
547  //$this->ilias->raiseError("Operation ilObjStyleSheet::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
548  }
549 
553  function putInTree()
554  {
555  $this->ilias->raiseError("Operation ilObjStyleSheet::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
556  }
557 
561  function createReference()
562  {
563  $this->ilias->raiseError("Operation ilObjStyleSheet::createReference() not allowed.",$this->ilias->error_obj->FATAL);
564  }
565 
569  function setUpToDate($a_up_to_date = true)
570  {
571  $this->up_to_date = $a_up_to_date;
572  }
573 
577  function getUpToDate()
578  {
579  return $this->up_to_date;
580  }
581 
585  function setScope($a_scope)
586  {
587  $this->scope = $a_scope;
588  }
589 
593  function getScope()
594  {
595  return $this->scope;
596  }
597 
601  function _writeUpToDate($a_id, $a_up_to_date)
602  {
603  global $ilDB;
604 
605  $q = "UPDATE style_data SET uptodate = ".
606  $ilDB->quote((int) $a_up_to_date, "integer").
607  " WHERE id = ".$ilDB->quote($a_id, "integer");
608  $ilDB->manipulate($q);
609  }
610 
614  function _lookupUpToDate($a_id)
615  {
616  global $ilDB;
617 
618  $q = "SELECT uptodate FROM style_data ".
619  " WHERE id = ".$ilDB->quote($a_id, "integer");
620  $res = $ilDB->query($q);
621  $sty = $ilDB->fetchAssoc($res);
622 
623  return (boolean) $sty["uptodate"];
624  }
625 
629  function _writeStandard($a_id, $a_std)
630  {
631  global $ilDB;
632 
633  $q = "UPDATE style_data SET standard = ".
634  $ilDB->quote((int) $a_std, "integer").
635  " WHERE id = ".$ilDB->quote($a_id, "integer");
636  $ilDB->manipulate($q);
637  }
638 
642  function _writeScope($a_id, $a_scope)
643  {
644  global $ilDB;
645 
646  $q = "UPDATE style_data SET category = ".
647  $ilDB->quote((int) $a_scope, "integer").
648  " WHERE id = ".$ilDB->quote($a_id, "integer");
649  $ilDB->manipulate($q);
650  }
651 
655  function _lookupStandard($a_id)
656  {
657  global $ilDB;
658 
659  $q = "SELECT * FROM style_data ".
660  " WHERE id = ".$ilDB->quote($a_id, "integer");
661  $res = $ilDB->query($q);
662  $sty = $ilDB->fetchAssoc($res);
663 
664  return (boolean) $sty["standard"];
665  }
666 
670  function _writeActive($a_id, $a_active)
671  {
672  global $ilDB;
673 
674  $q = "UPDATE style_data SET active = ".
675  $ilDB->quote((int) $a_active, "integer").
676  " WHERE id = ".$ilDB->quote($a_id, "integer");
677  $ilDB->manipulate($q);
678  }
679 
683  function _lookupActive($a_id)
684  {
685  global $ilDB;
686 
687  $q = "SELECT * FROM style_data ".
688  " WHERE id = ".$ilDB->quote($a_id, "integer");
689  $res = $ilDB->query($q);
690  $sty = $ilDB->fetchAssoc($res);
691 
692  return (boolean) $sty["active"];
693  }
694 
698  function _getStandardStyles($a_exclude_default_style = false,
699  $a_include_deactivated = false, $a_scope = 0)
700  {
701  global $ilDB, $ilias, $tree;
702 
703  $default_style = $ilias->getSetting("default_content_style_id");
704 
705  $and_str = "";
706  if (!$a_include_deactivated)
707  {
708  $and_str = " AND active = 1";
709  }
710 
711  $q = "SELECT * FROM style_data ".
712  " WHERE standard = 1".$and_str;
713  $res = $ilDB->query($q);
714  $styles = array();
715  while($sty = $ilDB->fetchAssoc($res))
716  {
717  if (!$a_exclude_default_style || $default_style != $sty["id"])
718  {
719  // check scope
720  if ($a_scope > 0 && $sty["category"] > 0)
721  {
722  if ($tree->isInTree($sty["category"]) &&
723  $tree->isInTree($a_scope))
724  {
725  $path = $tree->getPathId($a_scope);
726  if (!in_array($sty["category"], $path))
727  {
728  continue;
729  }
730  }
731  }
732  $styles[$sty["id"]] = ilObject::_lookupTitle($sty["id"]);
733  }
734  }
735 
736  return $styles;
737  }
738 
739 
745  {
746  global $ilAccess, $ilDB;
747 
748  $clonable_styles = array();
749 
750  $q = "SELECT * FROM style_data";
751  $style_set = $ilDB->query($q);
752  while($style_rec = $ilDB->fetchAssoc($style_set))
753  {
754  $clonable = false;
755  if ($style_rec["standard"] == 1)
756  {
757  if ($style_rec["active"] == 1)
758  {
759  $clonable = true;
760  }
761  }
762  else
763  {
764  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
765  $obj_ids = ilObjContentObject::_lookupContObjIdByStyleId($style_rec["id"]);
766  foreach($obj_ids as $id)
767  {
768  $ref = ilObject::_getAllReferences($id);
769  foreach($ref as $ref_id)
770  {
771  if ($ilAccess->checkAccess("write", "", $ref_id))
772  {
773  $clonable = true;
774  }
775  }
776  }
777  }
778  if ($clonable)
779  {
780  $clonable_styles[$style_rec["id"]] =
781  ilObject::_lookupTitle($style_rec["id"]);
782  }
783  }
784  return $clonable_styles;
785  }
786 
790  function assignMetaData(&$a_meta_data)
791  {
792  $this->meta_data =& $a_meta_data;
793  }
794 
798  static function _getBasicStyleDom()
799  {
800  global $ilBench;
801 
802  if (!is_object(self::$basic_style_dom))
803  {
804  self::$basic_style_dom = new DOMDocument();
805  self::$basic_style_dom->load(self::$basic_style_file);
806  }
807 
808  return self::$basic_style_dom;
809  }
810 
814  function &getMetaData()
815  {
816  return $this->meta_data;
817  }
818 
822  function create($a_from_style = 0, $a_import_mode = false)
823  {
824  global $ilDB;
825 
826  parent::create();
827 
828  if ($a_from_style == 0)
829  {
830  if (!$a_import_mode)
831  {
832  // copy styles from basic style
833  $this->createFromXMLFile(self::$basic_style_file, true);
834 
835  // copy images from basic style
836  $this->createImagesDirectory();
837  ilUtil::rCopy(self::$basic_style_image_dir,
838  $this->getImagesDirectory());
839  }
840  }
841  else
842  {
843  // get style parameter records
844  $def = array();
845  $q = "SELECT * FROM style_parameter WHERE style_id = ".
846  $ilDB->quote($a_from_style, "integer");
847  $par_set = $ilDB->query($q);
848  while($par_rec = $ilDB->fetchAssoc($par_set))
849  {
850  $def[] = array("tag" => $par_rec["tag"], "class" => $par_rec["class"],
851  "parameter" => $par_rec["parameter"], "value" => $par_rec["value"],
852  "type" => $par_rec["type"]);
853  }
854 
855  // get style characteristics records
856  $chars = array();
857  $q = "SELECT * FROM style_char WHERE style_id = ".
858  $ilDB->quote($a_from_style, "integer");
859  $par_set = $ilDB->query($q);
860  while($par_rec = $ilDB->fetchAssoc($par_set))
861  {
862  $chars[] = array("type" => $par_rec["type"], "characteristic" => $par_rec["characteristic"]);
863  }
864 
865  // default style settings
866  foreach ($def as $sty)
867  {
868  $id = $ilDB->nextId("style_parameter");
869  $q = "INSERT INTO style_parameter (id, style_id, tag, class, parameter, value, type) VALUES ".
870  "(".
871  $ilDB->quote($id, "integer").",".
872  $ilDB->quote($this->getId(), "integer").",".
873  $ilDB->quote($sty["tag"], "text").",".
874  $ilDB->quote($sty["class"], "text").",".
875  $ilDB->quote($sty["parameter"], "text").",".
876  $ilDB->quote($sty["value"], "text").",".
877  $ilDB->quote($sty["type"], "text").")";
878  $ilDB->manipulate($q);
879  }
880 
881  // insert style characteristics
882  foreach ($chars as $char)
883  {
884  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
885  "(".$ilDB->quote($this->getId(), "integer").",".
886  $ilDB->quote($char["type"], "text").",".
887  $ilDB->quote($char["characteristic"], "text").")";
888  $ilDB->manipulate($q);
889  }
890 
891  // add style_data record
892  $q = "INSERT INTO style_data (id, uptodate, category) VALUES ".
893  "(".$ilDB->quote($this->getId(), "integer").", 0,".
894  $ilDB->quote((int) $this->getScope(), "integer").")";
895  $ilDB->manipulate($q);
896 
897  // copy images
898  $from_style = new ilObjStyleSheet($a_from_style);
899  $this->createImagesDirectory();
900  ilUtil::rCopy($from_style->getImagesDirectory(),
901  $this->getImagesDirectory());
902 
903  // copy colors
904  $colors = $from_style->getColors();
905  foreach ($colors as $c)
906  {
907  $this->addColor($c["name"], $c["code"]);
908  }
909 
910  // copy templates
912  foreach ($tcts as $tct => $v)
913  {
914  $templates = $from_style->getTemplates($tct);
915  foreach ($templates as $t)
916  {
917  $this->addTemplate($tct, $t["name"], $t["classes"]);
918  }
919  }
920 
921  }
922 
923  $this->read();
924  if (!$a_import_mode)
925  {
926  $this->writeCSSFile();
927  }
928  }
929 
933  function deleteCharacteristic($a_type, $a_tag, $a_class)
934  {
935  global $ilDB;
936 
937  // check, if characteristic is not a core style
939  if (empty($core_styles[$a_type.".".$a_tag.".".$a_class]))
940  {
941  // delete characteristic record
942  $st = $ilDB->manipulateF(
943  "DELETE FROM style_char WHERE style_id = %s AND type = %s AND characteristic = %s",
944  array("integer", "text", "text"),
945  array($this->getId(), $a_type, $a_class));
946 
947  // delete parameter records
948  $st = $ilDB->manipulateF("DELETE FROM style_parameter WHERE style_id = %s AND tag = %s AND type = %s AND class = %s",
949  array("integer", "text", "text", "text"),
950  array($this->getId(), $a_tag, $a_type, $a_class));
951  }
952 
953  $this->setUpToDate(false);
954  $this->_writeUpToDate($this->getId(), false);
955  }
956 
960  function characteristicExists($a_char, $a_style_type)
961  {
962  global $ilDB;
963 
964  $set = $ilDB->queryF(
965  "SELECT style_id FROM style_char WHERE style_id = %s AND characteristic = %s AND type = %s",
966  array("integer", "text", "text"),
967  array($this->getId(), $a_char, $a_style_type));
968  if ($rec = $ilDB->fetchAssoc($set))
969  {
970  return true;
971  }
972  return false;
973  }
974 
978  function addCharacteristic($a_type, $a_char, $a_hidden = false)
979  {
980  global $ilDB;
981 
982  // delete characteristic record
983  $ilDB->manipulateF("INSERT INTO style_char (style_id, type, characteristic, hide)".
984  " VALUES (%s,%s,%s,%s) ",
985  array("integer", "text", "text", "integer"),
986  array($this->getId(), $a_type, $a_char, $a_hidden));
987 
988  $this->setUpToDate(false);
989  $this->_writeUpToDate($this->getId(), false);
990  }
991 
998  function copyCharacteristic($a_from_style_id,
999  $a_from_type, $a_from_char, $a_to_char)
1000  {
1001  global $ilDB;
1002 
1003  if (!$this->characteristicExists($a_to_char, $a_from_type))
1004  {
1005  $this->addCharacteristic($a_from_type, $a_to_char);
1006  }
1007  $this->deleteStyleParOfChar($a_from_type, $a_to_char);
1008 
1009  $from_style = new ilObjStyleSheet($a_from_style_id);
1010 
1011  $pars = $from_style->getParametersOfClass($a_from_type, $a_from_char);
1012 
1013  $colors = array();
1014  foreach ($pars as $p => $v)
1015  {
1016  if (substr($v, 0, 1) == "!")
1017  {
1018  $colors[] = substr($v, 1);
1019  }
1020  $this->replaceStylePar(ilObjStyleSheet::_determineTag($a_from_type),
1021  $a_to_char, $p, $v, $a_from_type);
1022  }
1023 
1024  // copy colors
1025  foreach ($colors as $c)
1026  {
1027  if (!$this->colorExists($c))
1028  {
1029  $this->addColor($c, $from_style->getColorCodeForName($c));
1030  }
1031  }
1032  }
1033 
1037  function getCharacteristics($a_type = "", $a_no_hidden = false)
1038  {
1039  $chars = array();
1040 
1041  if ($a_type == "")
1042  {
1043  $chars = $this->chars;
1044  }
1045  if (is_array($this->chars_by_type[$a_type]))
1046  {
1047  $chars = $this->chars_by_type[$a_type];
1048  }
1049 
1050  if ($a_no_hidden)
1051  {
1052  foreach ($chars as $k => $char)
1053  {
1054  if ($a_type == "" && $this->hidden_chars[$char["type"].":".$char["class"]])
1055  {
1056  unset($chars[$k]);
1057  }
1058  else if ($this->hidden_chars[$a_type.":".$char])
1059  {
1060  unset($chars[$k]);
1061  }
1062  }
1063  }
1064 
1065  return $chars;
1066  }
1067 
1071  function setCharacteristics($a_chars)
1072  {
1073  $this->chars = $a_chars;
1074  // $this->chars_by_type[$a_type];
1075  }
1076 
1080  function saveHideStatus($a_type, $a_char, $a_hide)
1081  {
1082  global $ilDB;
1083 
1084  $ilDB->manipulate("UPDATE style_char SET ".
1085  " hide = ".$ilDB->quote((int) $a_hide, "integer").
1086  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1087  " type = ".$ilDB->quote($a_type, "text")." AND ".
1088  " characteristic = ".$ilDB->quote($a_char, "text")
1089  );
1090  }
1091 
1095  function getHideStatus($a_type, $a_char)
1096  {
1097  global $ilDB;
1098 
1099  $set = $ilDB->query("SELECT hide FROM style_char ".
1100  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1101  " type = ".$ilDB->quote($a_type, "text")." AND ".
1102  " characteristic = ".$ilDB->quote($a_char, "text")
1103  );
1104  $rec = $ilDB->fetchAssoc($set);
1105 
1106  return $rec["hide"];
1107  }
1108 
1115  function ilClone()
1116  {
1117  global $log, $lng;
1118 
1119  $lng->loadLanguageModule("style");
1120 
1121  $new_obj = new ilObjStyleSheet();
1122  $new_obj->setTitle($this->getTitle()." (".$lng->txt("sty_acopy").")");
1123  $new_obj->setType($this->getType());
1124  $new_obj->setDescription($this->getDescription());
1125  $new_obj->create($this->getId());
1126 
1127  $new_obj->writeStyleSetting("disable_auto_margins",
1128  $this->lookupStyleSetting("disable_auto_margins"));
1129 
1130  return $new_obj->getId();
1131  }
1132 
1136  function copyImagesToDir($a_target)
1137  {
1138  ilUtil::rCopy($this->getImagesDirectory(), $a_target);
1139  }
1140 
1148  function addParameter($a_tag, $a_par, $a_type)
1149  {
1150  global $ilDB;
1151 
1152  $avail_params = $this->getAvailableParameters();
1153  $tag = explode(".", $a_tag);
1154  $value = $avail_params[$a_par][0];
1155  $id = $ilDB->nextId("style_parameter");
1156  $q = "INSERT INTO style_parameter (id,style_id, type, tag, class, parameter, value) VALUES ".
1157  "(".
1158  $ilDB->quote($id, "integer").",".
1159  $ilDB->quote($this->getId(), "integer").",".
1160  $ilDB->quote($a_type, "text").",".
1161  $ilDB->quote($tag[0], "text").",".
1162  $ilDB->quote($tag[1], "text").",".
1163  $ilDB->quote($a_par, "text").",".
1164  $ilDB->quote($value, "text").")";
1165  $ilDB->manipulate($q);
1166  $this->read();
1167  $this->writeCSSFile();
1168  }
1169 
1175  {
1177  }
1178 
1183  static function _createImagesDirectory($a_style_id)
1184  {
1185  global $ilErr;
1186 
1187  $sty_data_dir = ilUtil::getWebspaceDir()."/sty";
1188  ilUtil::makeDir($sty_data_dir);
1189  if(!is_writable($sty_data_dir))
1190  {
1191  $ilErr->raiseError("Style data directory (".$sty_data_dir
1192  .") not writeable.", $ilErr->FATAL);
1193  }
1194 
1195  $style_dir = $sty_data_dir."/sty_".$a_style_id;
1196  ilUtil::makeDir($style_dir);
1197  if(!@is_dir($style_dir))
1198  {
1199  $ilErr->raiseError("Creation of style directory failed (".
1200  $style_dir.").",$ilErr->FATAL);
1201  }
1202 
1203  // create images subdirectory
1204  $im_dir = $style_dir."/images";
1205  ilUtil::makeDir($im_dir);
1206  if(!@is_dir($im_dir))
1207  {
1208  $ilErr->raiseError("Creation of Import Directory failed (".
1209  $im_dir.").", $ilErr->FATAL);
1210  }
1211 
1212  // create thumbnails directory
1213  $thumb_dir = $style_dir."/images/thumbnails";
1214  ilUtil::makeDir($thumb_dir);
1215  if(!@is_dir($thumb_dir))
1216  {
1217  $ilErr->raiseError("Creation of Import Directory failed (".
1218  $thumb_dir.").", $ilErr->FATAL);
1219  }
1220  }
1221 
1226  {
1228  }
1229 
1233  static function _getImagesDirectory($a_style_id)
1234  {
1235  return ilUtil::getWebspaceDir()."/sty/sty_".$a_style_id.
1236  "/images";
1237  }
1238 
1243  {
1244  return $this->getImagesDirectory().
1245  "/thumbnails";
1246  }
1247 
1251  function getImages()
1252  {
1253  $dir = $this->getImagesDirectory();
1254  $images = array();
1255  if (is_dir($dir))
1256  {
1257  $entries = ilUtil::getDir($dir);
1258  foreach($entries as $entry)
1259  {
1260  if (substr($entry["entry"],0,1) == ".")
1261  {
1262  continue;
1263  }
1264  if ($entry["type"] != "dir")
1265  {
1266  $images[] = $entry;
1267  }
1268  }
1269  }
1270 
1271  return $images;
1272  }
1273 
1277  function uploadImage($a_file)
1278  {
1279  $this->createImagesDirectory();
1280  @ilUtil::moveUploadedFile($a_file["tmp_name"], $a_file["name"],
1281  $this->getImagesDirectory()."/".$a_file["name"]);
1282  @ilUtil::resizeImage($this->getImagesDirectory()."/".$a_file["name"],
1283  $this->getThumbnailsDirectory()."/".$a_file["name"], 75, 75);
1284  }
1285 
1289  function deleteImage($a_file)
1290  {
1291  if (is_file($this->getImagesDirectory()."/".$a_file))
1292  {
1293  unlink($this->getImagesDirectory()."/".$a_file);
1294  }
1295  if (is_file($this->getThumbnailsDirectory()."/".$a_file))
1296  {
1297  unlink($this->getThumbnailsDirectory()."/".$a_file);
1298  }
1299  }
1300 
1306  function deleteParameter($a_id)
1307  {
1308  global $ilDB;
1309 
1310  $q = "DELETE FROM style_parameter WHERE id = ".
1311  $ilDB->quote($a_id, "integer");
1312  $ilDB->query($q);
1313  }
1314 
1323  function deleteStylePar($a_tag, $a_class, $a_par, $a_type)
1324  {
1325  global $ilDB;
1326 
1327  $q = "DELETE FROM style_parameter WHERE ".
1328  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1329  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1330  " class = ".$ilDB->quote($a_class, "text")." AND ".
1331  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1332  " parameter = ".$ilDB->quote($a_par, "text");
1333 
1334  $ilDB->manipulate($q);
1335  }
1336 
1345  function deleteStyleParOfChar($a_type, $a_class)
1346  {
1347  global $ilDB;
1348 
1349  $q = "DELETE FROM style_parameter WHERE ".
1350  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
1351  " class = ".$ilDB->quote($a_class, "text")." AND ".
1352  " ".$ilDB->equals("type", $a_type, "text", true);
1353 
1354  $ilDB->manipulate($q);
1355  }
1356 
1357 
1361  function delete()
1362  {
1363  global $ilDB;
1364 
1365  // delete object
1366  parent::delete();
1367 
1368  // check whether this style is global default
1369  $def_style = $this->ilias->getSetting("default_content_style_id");
1370  if ($def_style == $this->getId())
1371  {
1372  $this->ilias->deleteSetting("default_content_style_id");
1373  }
1374 
1375  // check whether this style is global fixed
1376  $fixed_style = $this->ilias->getSetting("fixed_content_style_id");
1377  if ($fixed_style == $this->getId())
1378  {
1379  $this->ilias->deleteSetting("fixed_content_style_id");
1380  }
1381 
1382  // delete style parameter
1383  $q = "DELETE FROM style_parameter WHERE style_id = ".
1384  $ilDB->quote($this->getId(), "integer");
1385  $ilDB->manipulate($q);
1386 
1387  // delete style file
1388  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1389  if (is_file($css_file_name))
1390  {
1391  unlink($css_file_name);
1392  }
1393 
1394  // delete entries in learning modules
1395  include_once("./Modules/LearningModule/classes/class.ilObjContentObject.php");
1397 
1398  // delete style data record
1399  $q = "DELETE FROM style_data WHERE id = ".
1400  $ilDB->quote($this->getId(), "integer");
1401  $ilDB->manipulate($q);
1402 
1403  }
1404 
1405 
1409  function read()
1410  {
1411  global $ilDB;
1412 
1413  parent::read();
1414 
1415  $q = "SELECT * FROM style_parameter WHERE style_id = ".
1416  $ilDB->quote($this->getId(), "integer")." ORDER BY tag, class, type ";
1417  $style_set = $ilDB->query($q);
1418  $ctag = "";
1419  $cclass = "";
1420  $ctype = "";
1421  $this->style = array();
1422  while($style_rec = $ilDB->fetchAssoc($style_set))
1423  {
1424  if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass
1425  || $style_rec["type"] != $ctype)
1426  {
1427  // add current tag array to style array
1428  if(is_array($tag))
1429  {
1430  $this->style[] = $tag;
1431  }
1432  $tag = array();
1433  }
1434  $ctag = $style_rec["tag"];
1435  $cclass = $style_rec["class"];
1436  $ctype = $style_rec["type"];
1437  $tag[] = $style_rec;
1438  $this->style_class[$ctype][$cclass][$style_rec["parameter"]] = $style_rec["value"];
1439  }
1440  if(is_array($tag))
1441  {
1442  $this->style[] = $tag;
1443  }
1444 //var_dump($this->style_class);
1445  $q = "SELECT * FROM style_data WHERE id = ".
1446  $ilDB->quote($this->getId(), "integer");
1447  $res = $ilDB->query($q);
1448  $sty = $ilDB->fetchAssoc($res);
1449  $this->setUpToDate((boolean) $sty["uptodate"]);
1450  $this->setScope($sty["category"]);
1451 
1452  // get style characteristics records
1453  $this->chars = array();
1454  $this->chars_by_type = array();
1455  $q = "SELECT * FROM style_char WHERE style_id = ".
1456  $ilDB->quote($this->getId(), "integer").
1457  " ORDER BY type ASC, characteristic ASC";
1458  $par_set = $ilDB->query($q);
1459  while($par_rec = $ilDB->fetchAssoc($par_set))
1460  {
1461  $this->chars[] = array("type" => $par_rec["type"], "class" => $par_rec["characteristic"], "hide" => $par_rec["hide"]);
1462  $this->chars_by_type[$par_rec["type"]][] = $par_rec["characteristic"];
1463  if ($par_rec["hide"])
1464  {
1465  $this->hidden_chars[$par_rec["type"].":".$par_rec["characteristic"]] = true;
1466  }
1467  }
1468  }
1469 
1473  function writeCSSFile($a_target_file = "", $a_image_dir = "")
1474  {
1475  $style = $this->getStyle();
1476 
1477  if ($a_target_file == "")
1478  {
1479  $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
1480  }
1481  else
1482  {
1483  $css_file_name = $a_target_file;
1484  }
1485  $css_file = fopen($css_file_name, "w");
1486 
1487  $page_background = "";
1488 
1489  foreach ($style as $tag)
1490  {
1491  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1492  if ($tag[0]["tag"] == "td")
1493  {
1494  fwrite ($css_file, ",th".".ilc_".$tag[0]["type"]."_".$tag[0]["class"]."\n");
1495  }
1496  if (in_array($tag[0]["tag"], array("h1", "h2", "h3")))
1497  {
1498  fwrite ($css_file, ",div.ilc_text_block_".$tag[0]["class"]."\n");
1499  fwrite ($css_file, ",body.ilc_text_block_".$tag[0]["class"]."\n");
1500  }
1501  if ($tag[0]["type"] == "text_block")
1502  {
1503  fwrite ($css_file, ",body.ilc_text_block_".$tag[0]["class"]."\n");
1504  }
1505  fwrite ($css_file, "{\n");
1506 
1507  // collect table border attributes
1508  $t_border = array();
1509 
1510  foreach($tag as $par)
1511  {
1512  $cur_par = $par["parameter"];
1513  $cur_val = $par["value"];
1514 
1515  // replace named colors
1516  if (is_int(strpos($cur_par, "color")) && substr(trim($cur_val), 0, 1) == "!")
1517  {
1518  $cur_val = $this->getColorCodeForName(substr($cur_val, 1));
1519  }
1520 
1521  if ($tag[0]["type"] == "table" && is_int(strpos($par["parameter"], "border")))
1522  {
1523  $t_border[$cur_par] = $cur_val;
1524  }
1525 
1526  if (in_array($cur_par, array("background-image", "list-style-image")))
1527  {
1528  if (is_int(strpos($cur_val, "/"))) // external
1529  {
1530  $cur_val = "url(".$cur_val.")";
1531  }
1532  else // internal
1533  {
1534  if ($a_image_dir == "")
1535  {
1536  $cur_val = "url(../sty/sty_".$this->getId()."/images/".$cur_val.")";
1537  }
1538  else
1539  {
1540  $cur_val = "url(".$a_image_dir."/".$cur_val.")";
1541  }
1542  }
1543  }
1544 
1545  if ($cur_par == "opacity")
1546  {
1547  $cur_val = ((int) $cur_val) / 100;
1548  }
1549 
1550  fwrite ($css_file, "\t".$cur_par.": ".$cur_val.";\n");
1551 
1552  // IE6 fix for minimum height
1553  if ($cur_par == "min-height")
1554  {
1555  fwrite ($css_file, "\t"."height".": "."auto !important".";\n");
1556  fwrite ($css_file, "\t"."height".": ".$cur_val.";\n");
1557  }
1558 
1559  // opacity fix
1560  if ($cur_par == "opacity")
1561  {
1562  fwrite ($css_file, "\t".'-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity='.($cur_val * 100).')"'.";\n");
1563  fwrite ($css_file, "\t".'filter: alpha(opacity='.($cur_val * 100).')'.";\n");
1564  fwrite ($css_file, "\t".'-moz-opacity: '.$cur_val.";\n");
1565  }
1566 
1567  // save page background
1568  if ($tag[0]["tag"] == "div" && $tag[0]["class"] == "Page"
1569  && $cur_par == "background-color")
1570  {
1571  $page_background = $cur_val;
1572  }
1573  }
1574  fwrite ($css_file, "}\n");
1575  fwrite ($css_file, "\n");
1576 
1577  // use table border attributes for th td as well
1578 /* if ($tag[0]["type"] == "table")
1579  {
1580  if (count($t_border) > 0)
1581  {
1582  fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." th,".
1583  $tag[0]["tag"].".ilc_".$tag[0]["type"]."_".$tag[0]["class"]." td\n");
1584  fwrite ($css_file, "{\n");
1585  foreach ($t_border as $p => $v)
1586  {
1587 // fwrite ($css_file, "\t".$p.": ".$v.";\n");
1588  }
1589  fwrite ($css_file, "}\n");
1590  fwrite ($css_file, "\n");
1591  }
1592  }*/
1593  }
1594 
1595  if ($page_background != "")
1596  {
1597  fwrite ($css_file, "td.ilc_Page\n");
1598  fwrite ($css_file, "{\n");
1599  fwrite ($css_file, "\t"."background-color: ".$page_background.";\n");
1600  fwrite ($css_file, "}\n");
1601  }
1602  fclose($css_file);
1603 
1604  $this->setUpToDate(true);
1605  $this->_writeUpToDate($this->getId(), true);
1606  }
1607 
1614  static function getEffectiveContentStyleId($a_style_id, $a_type = "")
1615  {
1616  global $ilSetting;
1617 
1618  // check global fixed content style
1619  $fixed_style = $ilSetting->get("fixed_content_style_id");
1620  if ($fixed_style > 0)
1621  {
1622  $a_style_id = $fixed_style;
1623  }
1624 
1625  // check global default style
1626  if ($a_style_id <= 0)
1627  {
1628  $a_style_id = $ilSetting->get("default_content_style_id");
1629  }
1630 
1631  if ($a_style_id > 0 && ilObject::_lookupType($a_style_id) == "sty")
1632  {
1633  return $a_style_id;
1634  }
1635 
1636  return 0;
1637  }
1638 
1645  function getParametersOfClass($a_type, $a_class)
1646  {
1647  if (is_array($this->style_class[$a_type][$a_class]))
1648  {
1649  return $this->style_class[$a_type][$a_class];
1650  }
1651  return array();
1652  }
1653 
1659  function getContentStylePath($a_style_id)
1660  {
1661  global $ilias;
1662 
1663  $rand = rand(1,999999);
1664 
1665 
1666  // check global fixed content style
1667  $fixed_style = $ilias->getSetting("fixed_content_style_id");
1668  if ($fixed_style > 0)
1669  {
1670  $a_style_id = $fixed_style;
1671  }
1672 
1673  // check global default style
1674  if ($a_style_id <= 0)
1675  {
1676  $a_style_id = $ilias->getSetting("default_content_style_id");
1677  }
1678 
1679  if ($a_style_id > 0 && ilObject::_exists($a_style_id))
1680  {
1681  // check whether file is up to date
1682  if (!ilObjStyleSheet::_lookupUpToDate($a_style_id))
1683  {
1684  $style = new ilObjStyleSheet($a_style_id);
1685  $style->writeCSSFile();
1686  }
1687 
1688  return ilUtil::getWebspaceDir("output").
1689  "/css/style_".$a_style_id.".css?dummy=$rand";
1690  }
1691  else // todo: work this out
1692  {
1693  return "./Services/COPage/css/content.css";
1694  }
1695  }
1696 
1703  {
1704  return "./Services/COPage/css/print_content.css";
1705  }
1706 
1713  {
1714  return "./Services/COPage/css/syntaxhighlight.css";
1715  }
1716 
1723  {
1724  return "./Services/COPage/css/placeholder.css";
1725  }
1726 
1727  function update()
1728  {
1729  global $ilDB;
1730 
1731  parent::update();
1732  $this->read(); // this could be done better
1733  $this->writeCSSFile();
1734 
1735  $q = "UPDATE style_data ".
1736  "SET category = ".$ilDB->quote((int) $this->getScope(), "integer").
1737  " WHERE id = ".$ilDB->quote($this->getId(), "integer");
1738  $ilDB->manipulate($q);
1739  }
1740 
1747  function updateStyleParameter($a_id, $a_value)
1748  {
1749  global $ilDB;
1750 
1751  $q = "UPDATE style_parameter SET VALUE = ".
1752  $ilDB->quote($a_value, "text")." WHERE id = ".
1753  $ilDB->quote($a_id, "integer");
1754  $style_set = $ilDB->manipulate($q);
1755  }
1756 
1761  function replaceStylePar($a_tag, $a_class, $a_par, $a_val, $a_type)
1762  {
1763  ilObjStyleSheet::_replaceStylePar($this->getId(), $a_tag, $a_class, $a_par, $a_val, $a_type);
1764  }
1765 
1766  function _replaceStylePar($style_id, $a_tag, $a_class, $a_par, $a_val, $a_type)
1767  {
1768  global $ilDB;
1769 
1770  $q = "SELECT * FROM style_parameter WHERE ".
1771  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1772  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1773  " class = ".$ilDB->quote($a_class, "text")." AND ".
1774  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1775  " parameter = ".$ilDB->quote($a_par, "text");
1776 
1777  $set = $ilDB->query($q);
1778 
1779  if ($rec = $set->fetchRow())
1780  {
1781  $q = "UPDATE style_parameter SET ".
1782  " value = ".$ilDB->quote($a_val, "text")." WHERE ".
1783  " style_id = ".$ilDB->quote($style_id, "integer")." AND ".
1784  " tag = ".$ilDB->quote($a_tag, "text")." AND ".
1785  " class = ".$ilDB->quote($a_class, "text")." AND ".
1786  " ".$ilDB->equals("type", $a_type, "text", true)." AND ".
1787  " parameter = ".$ilDB->quote($a_par, "text");
1788 
1789  $ilDB->manipulate($q);
1790  }
1791  else
1792  {
1793  $id = $ilDB->nextId("style_parameter");
1794  $q = "INSERT INTO style_parameter (id, value, style_id, tag, class, type, parameter) VALUES ".
1795  " (".
1796  $ilDB->quote($id, "integer").",".
1797  $ilDB->quote($a_val, "text").",".
1798  " ".$ilDB->quote($this->getId(), "integer").",".
1799  " ".$ilDB->quote($a_tag, "text").",".
1800  " ".$ilDB->quote($a_class, "text").",".
1801  " ".$ilDB->quote($a_type, "text").",".
1802  " ".$ilDB->quote($a_par, "text").")";
1803 
1804  $ilDB->manipulate($q);
1805  }
1806  }
1807 
1808 
1812  function getStyle()
1813  {
1814  return $this->style;
1815  }
1816 
1820  function setStyle($a_style)
1821  {
1822  $this->style = $a_style;
1823  }
1824 
1825 
1832  function handleXmlString($a_str)
1833  {
1834  return str_replace("&", "&amp;", $a_str);
1835  }
1836 
1840  function getXML()
1841  {
1842  $xml.= "<StyleSheet>\n";
1843 
1844  // title and description
1845  $xml.= "<Title>".$this->handleXmlString($this->getTitle())."</Title>";
1846  $xml.= "<Description>".$this->handleXmlString($this->getDescription())."</Description>\n";
1847 
1848  // style classes
1849  foreach($this->chars as $char)
1850  {
1851  $xml.= "<Style Tag=\"".ilObjStyleSheet::_determineTag($char["type"]).
1852  "\" Type=\"".$char["type"]."\" Class=\"".$char["class"]."\">\n";
1853  foreach($this->style as $style)
1854  {
1855  if ($style[0]["type"] == $char["type"] && $style[0]["class"] == $char["class"])
1856  {
1857  foreach($style as $tag)
1858  {
1859  $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\"/>\n";
1860  }
1861  }
1862  }
1863  $xml.= "</Style>\n";
1864  }
1865 
1866  // colors
1867  foreach($this->getColors() as $color)
1868  {
1869  $xml.="<StyleColor Name=\"".$color["name"]."\" Code=\"".$color["code"]."\"/>\n";
1870  }
1871 
1872  // templates
1874  foreach ($tcts as $tct => $v)
1875  {
1876  $ts = $this->getTemplates($tct);
1877 
1878  foreach ($ts as $t)
1879  {
1880  $xml.="<StyleTemplate Type=\"".$tct."\" Name=\"".$t["name"]."\">\n";
1881  foreach ($t["classes"] as $ct => $c)
1882  {
1883  if ($c != "")
1884  {
1885  $xml.="<StyleTemplateClass ClassType=\"".$ct."\" Class=\"".$c."\"/>\n";
1886  }
1887  }
1888  $xml.="</StyleTemplate>\n";
1889  }
1890  }
1891 
1892 
1893  $xml.= "</StyleSheet>";
1894 //echo "<pre>".htmlentities($xml)."</pre>"; exit;
1895  return $xml;
1896  }
1897 
1898 
1903  {
1904  $sty_data_dir = ilUtil::getDataDir()."/sty";
1905  ilUtil::makeDir($sty_data_dir);
1906  if(!is_writable($sty_data_dir))
1907  {
1908  $this->ilias->raiseError("Style data directory (".$sty_data_dir
1909  .") not writeable.",$this->ilias->error_obj->FATAL);
1910  }
1911 
1912  $style_dir = $sty_data_dir."/sty_".$this->getId();
1913  ilUtil::makeDir($style_dir);
1914  if(!@is_dir($style_dir))
1915  {
1916  $this->ilias->raiseError("Creation of style directory failed (".
1917  $style_dir.").",$this->ilias->error_obj->FATAL);
1918  }
1919 
1920  // create export subdirectory
1921  $ex_dir = $style_dir."/export";
1922  ilUtil::makeDir($ex_dir);
1923  if(!@is_dir($ex_dir))
1924  {
1925  $this->ilias->raiseError("Creation of Import Directory failed (".
1926  $ex_dir.").",$this->ilias->error_obj->FATAL);
1927  }
1928 
1929  return $ex_dir;
1930  }
1931 
1936  {
1937  $sty_data_dir = ilUtil::getDataDir()."/sty";
1938  $style_dir = $sty_data_dir."/sty_".$this->getId();
1939  // create export subdirectory
1940  $ex_dir = $style_dir."/export";
1941 
1942  if (is_dir($ex_dir))
1943  {
1944  ilUtil::delDir($ex_dir, true);
1945  }
1946  }
1947 
1948 
1953  {
1954  $ex_dir = $this->createExportDirectory();
1955  $ex_sub_dir = $ex_dir."/".$this->getExportSubDir();
1956  ilUtil::makeDir($ex_sub_dir);
1957  if(!is_writable($ex_sub_dir))
1958  {
1959  $this->ilias->raiseError("Style data directory (".$ex_sub_dir
1960  .") not writeable.",$this->ilias->error_obj->FATAL);
1961  }
1962  $ex_sub_images_dir = $ex_sub_dir."/images";
1963  ilUtil::makeDir($ex_sub_images_dir);
1964  if(!is_writable($ex_sub_images_dir))
1965  {
1966  $this->ilias->raiseError("Style data directory (".$ex_sub_images_dir
1967  .") not writeable.",$this->ilias->error_obj->FATAL);
1968  }
1969  }
1970 
1974  function setExportSubDir($a_dir)
1975  {
1976  $this->export_sub_dir = $a_dir;
1977  }
1978 
1982  function getExportSubDir()
1983  {
1984  if ($this->export_sub_dir == "")
1985  {
1986  return "sty_".$this->getId();
1987  }
1988  else
1989  {
1990  return $this->export_sub_dir;
1991  }
1992  }
1993 
1999  function export()
2000  {
2001  $this->cleanExportDirectory();
2002  $ex_dir = $this->createExportDirectory();
2003  $this->createExportSubDirectory();
2004  $this->exportXML($ex_dir."/".$this->getExportSubDir());
2005 //echo "-".$this->getImagesDirectory()."-".$ex_dir."/".$this->getExportSubDir()."/images"."-";
2007  $ex_dir."/".$this->getExportSubDir()."/images");
2008  if (is_file($ex_dir."/".$this->getExportSubDir().".zip"))
2009  {
2010  unlink($ex_dir."/".$this->getExportSubDir().".zip");
2011  }
2012  ilUtil::zip($ex_dir."/".$this->getExportSubDir(),
2013  $ex_dir."/".$this->getExportSubDir().".zip");
2014 
2015  return $ex_dir."/".$this->getExportSubDir().".zip";
2016  }
2017 
2021  function exportXML($a_dir)
2022  {
2023  $file = $a_dir."/style.xml";
2024 
2025  // open file
2026  if (!($fp = @fopen($file,"w")))
2027  {
2028  die ("<b>Error</b>: Could not open \"".$file."\" for writing".
2029  " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
2030  }
2031 
2032  // set file permissions
2033  chmod($file, 0770);
2034 
2035  // write xml data into the file
2036  fwrite($fp, $this->getXML());
2037 
2038  // close file
2039  fclose($fp);
2040 
2041  }
2042 
2047  {
2048  $sty_data_dir = ilUtil::getDataDir()."/sty";
2049  ilUtil::makeDir($sty_data_dir);
2050  if(!is_writable($sty_data_dir))
2051  {
2052  $this->ilias->raiseError("Style data directory (".$sty_data_dir
2053  .") not writeable.",$this->ilias->error_obj->FATAL);
2054  }
2055 
2056  $style_dir = $sty_data_dir."/sty_".$this->getId();
2057  ilUtil::makeDir($style_dir);
2058  if(!@is_dir($style_dir))
2059  {
2060  $this->ilias->raiseError("Creation of style directory failed (".
2061  $style_dir.").",$this->ilias->error_obj->FATAL);
2062  }
2063 
2064  // create import subdirectory
2065  $im_dir = $style_dir."/import";
2066  ilUtil::makeDir($im_dir);
2067  if(!@is_dir($im_dir))
2068  {
2069  $this->ilias->raiseError("Creation of Import Directory failed (".
2070  $im_dir.").",$this->ilias->error_obj->FATAL);
2071  }
2072 
2073  return $im_dir;
2074  }
2075 
2079  function import($a_file)
2080  {
2081  parent::create();
2082 
2083  $im_dir = $this->createImportDirectory();
2084 
2085  // handle uploaded files
2086  if (is_array($a_file))
2087  {
2088  ilUtil::moveUploadedFile($a_file["tmp_name"],
2089  $a_file["name"], $im_dir."/".$a_file["name"]);
2090  $file_name = $a_file["name"];
2091  }
2092  else // handle not directly uploaded files
2093  {
2094  $pi = pathinfo($a_file);
2095  $file_name = $pi["basename"];
2096  copy($a_file, $im_dir."/".$file_name);
2097  }
2098  $file = pathinfo($file_name);
2099 
2100  // unzip file
2101  if (strtolower($file["extension"] == "zip"))
2102  {
2103  ilUtil::unzip($im_dir."/".$file_name);
2104  $subdir = basename($file["basename"],".".$file["extension"]);
2105  if (!is_dir($im_dir."/".$subdir))
2106  {
2107  $subdir = "style"; // check style subdir
2108  }
2109  $xml_file = $im_dir."/".$subdir."/style.xml";
2110  }
2111  else // handle xml file directly (old style)
2112  {
2113  $xml_file = $im_dir."/".$file_name;
2114  }
2115 
2116  // load information from xml file
2117 //echo "-$xml_file-";
2118  $this->createFromXMLFile($xml_file, true);
2119 
2120  // copy images
2121  $this->createImagesDirectory();
2122  if (is_dir($im_dir."/".$subdir."/images"))
2123  {
2124  ilUtil::rCopy($im_dir."/".$subdir."/images",
2125  $this->getImagesDirectory());
2126  }
2127 
2129  $this->read();
2130  $this->writeCSSFile();
2131  }
2132 
2136  function createFromXMLFile($a_file, $a_skip_parent_create = false)
2137  {
2138  global $ilDB;
2139 
2140  $this->is_3_10_skin = false;
2141 
2142  if (!$a_skip_parent_create)
2143  {
2144  parent::create();
2145  }
2146  include_once("./Services/Style/classes/class.ilStyleImportParser.php");
2147  $importParser = new ilStyleImportParser($a_file, $this);
2148  $importParser->startParsing();
2149 
2150  // store style parameter
2151  foreach ($this->style as $style)
2152  {
2153  foreach($style as $tag)
2154  {
2155  $id = $ilDB->nextId("style_parameter");
2156 
2157  // migrate old table PageFrame/PageContainer to div
2158  if (in_array($tag["class"], array("PageFrame", "PageContainer")) &&
2159  $tag["tag"] == "table")
2160  {
2161  $tag["tag"] = "div";
2162  if ($tag["parameter"] == "width" && $tag["value"] == "100%")
2163  {
2164  continue;
2165  }
2166  }
2167 
2168  $q = "INSERT INTO style_parameter (id,style_id, tag, class, parameter, type, value) VALUES ".
2169  "(".
2170  $ilDB->quote($id, "integer").",".
2171  $ilDB->quote($this->getId(), "integer").",".
2172  $ilDB->quote($tag["tag"], "text").",".
2173  $ilDB->quote($tag["class"], "text").",".
2174  $ilDB->quote($tag["parameter"], "text").",".
2175  $ilDB->quote($tag["type"], "text").",".
2176  $ilDB->quote($tag["value"], "text").")";
2177 //echo "<br>-$q";
2178  $ilDB->manipulate($q);
2179  }
2180  }
2181 
2182  // store characteristics
2183  $this->is_3_10_skin = true;
2184  if (is_array($this->chars))
2185  {
2186  foreach ($this->chars as $char)
2187  {
2188  if ($char["type"] != "")
2189  {
2190  $s = substr($char["class"], strlen($char["class"]) - 6);
2191  if ($s != ":hover")
2192  {
2193  $q = "INSERT INTO style_char (style_id, type, characteristic) VALUES ".
2194  "(".$ilDB->quote($this->getId(), "integer").",".
2195  $ilDB->quote($char["type"], "text").",".
2196  $ilDB->quote($char["class"], "text").")";
2197  $ilDB->manipulate($q);
2198  $this->is_3_10_skin = false;
2199  }
2200  }
2201  }
2202  }
2203 
2204  // add style_data record
2205  $q = "INSERT INTO style_data (id, uptodate) VALUES ".
2206  "(".$ilDB->quote($this->getId(), "integer").", 0)";
2207  $ilDB->manipulate($q);
2208 
2209  $this->update();
2210  $this->read();
2211 
2212  if ($this->is_3_10_skin)
2213  {
2214  $this->do_3_10_Migration();
2215  }
2216  //$this->writeCSSFile();
2217  }
2218 
2223  {
2224  $groups = array();
2225 
2226  foreach (self::$parameter as $parameter => $props)
2227  {
2228  $groups[$props["group"]][] = $parameter;
2229  }
2230  return $groups;
2231  }
2232 
2233  static function _getStyleParameterInputType($par)
2234  {
2235  $input = self::$parameter[$par]["input"];
2236  return $input;
2237  }
2238 
2239  static function _getStyleParameterSubPar($par)
2240  {
2241  $subpar = self::$parameter[$par]["subpar"];
2242  return $subpar;
2243  }
2244 
2245  static function _getStyleParameters($a_tag = "")
2246  {
2247  if ($a_tag == "")
2248  {
2249  return self::$parameter;
2250  }
2251  $par = array();
2252  foreach (self::$parameter as $k => $v)
2253  {
2254  if (is_array(self::$filtered_groups[$v["group"]]) &&
2255  !in_array($a_tag, self::$filtered_groups[$v["group"]]))
2256  {
2257  continue;
2258  }
2259  $par[$k] = $v;
2260  }
2261  return $par;
2262  }
2263 
2264  static function _getFilteredGroups()
2265  {
2266  return self::$filtered_groups;
2267  }
2268 
2269  static function _getStyleParameterNumericUnits($a_no_percentage = false)
2270  {
2271  if ($a_no_percentage)
2272  {
2273  return self::$num_unit_no_perc;
2274  }
2275  return self::$num_unit;
2276  }
2277 
2278  static function _getStyleParameterValues($par)
2279  {
2280  return self::$parameter[$par]["values"];
2281  }
2282 
2283  /*static function _getStyleTypes()
2284  {
2285  return self::$style_types;
2286  }*/
2287 
2288  static function _getStyleSuperTypes()
2289  {
2290  return self::$style_super_types;
2291  }
2292 
2293  static function _isExpandable($a_type)
2294  {
2295  return in_array($a_type, self::$expandable_types);
2296  }
2297 
2298  static function _isHideable($a_type)
2299  {
2300  return in_array($a_type, self::$hideable_types);
2301  }
2302 
2303  static function _getStyleSuperTypeForType($a_type)
2304  {
2305  foreach (self::$style_super_types as $s => $t)
2306  {
2307  if (in_array($a_type, $t))
2308  {
2309  return $s;
2310  }
2311  if ($a_type == $s)
2312  {
2313  return $s;
2314  }
2315  }
2316  }
2317 
2321  static function _getCoreStyles()
2322  {
2323  $c_styles = array();
2324  foreach (self::$core_styles as $cstyle)
2325  {
2326  $c_styles[$cstyle["type"].".".ilObjStyleSheet::_determineTag($cstyle["type"]).".".$cstyle["class"]]
2327  = array("type" => $cstyle["type"],
2328  "tag" => ilObjStyleSheet::_determineTag($cstyle["type"]),
2329  "class" => $cstyle["class"]);
2330  }
2331  return $c_styles;
2332  }
2333 
2337  static function _getTemplateClassTypes($a_template_type = "")
2338  {
2339  if ($a_template_type == "")
2340  {
2341  return self::$templates;
2342  }
2343 
2344  return self::$templates[$a_template_type];
2345  }
2346 
2347 
2348  function _getPseudoClasses($tag)
2349  {
2350  return self::$pseudo_classes[$tag];
2351  }
2352 
2354  {
2355  return self::$templates[$t][$k];
2356  }
2357 
2358  static function _determineTag($a_type)
2359  {
2360  return self::$assigned_tags[$a_type];
2361  }
2362 
2366  static function getAvailableParameters()
2367  {
2368  $pars = array();
2369  foreach(self::$parameter as $p => $v)
2370  {
2371  $pars[$p] = $v["values"];
2372  }
2373 
2374  return $pars;
2375  }
2376 
2377 
2381  static function _addMissingStyleClassesToStyle($a_id)
2382  {
2383  $styles = array(array("id" => $a_id));
2385  }
2386 
2390  static function _addMissingStyleClassesToAllStyles($a_styles = "")
2391  {
2392  global $ilDB;
2393 
2394  if ($a_styles == "")
2395  {
2396  $styles = ilObject::_getObjectsDataForType("sty");
2397  }
2398  else
2399  {
2400  $styles = $a_styles;
2401  }
2404 
2405  // get all core image files
2406  $core_images = array();
2407  $core_dir = self::$basic_style_image_dir;
2408  if (is_dir($core_dir))
2409  {
2410  $dir = opendir($core_dir);
2411  while($file = readdir($dir))
2412  {
2413  if (substr($file, 0, 1) != "." && is_file($core_dir."/".$file))
2414  {
2415  $core_images[] = $file;
2416  }
2417  }
2418  }
2419 
2420  foreach ($styles as $style)
2421  {
2422  $id = $style["id"];
2423 
2424  foreach($core_styles as $cs)
2425  {
2426  // check, whether core style class exists
2427  $set = $ilDB->queryF("SELECT * FROM style_char WHERE style_id = %s ".
2428  "AND type = %s AND characteristic = %s",
2429  array("integer", "text", "text"),
2430  array($id, $cs["type"], $cs["class"]));
2431 
2432  // if not, add core style class
2433  if (!($rec = $ilDB->fetchAssoc($set)))
2434  {
2435  $ilDB->manipulateF(
2436  "INSERT INTO style_char (style_id, type, characteristic) ".
2437  " VALUES (%s,%s,%s) ",
2438  array("integer", "text", "text"),
2439  array($id, $cs["type"], $cs["class"]));
2440 
2441  $xpath = new DOMXPath($bdom);
2442  $par_nodes = $xpath->query("/StyleSheet/Style[@Tag = '".$cs["tag"]."' and @Type='".
2443  $cs["type"]."' and @Class='".$cs["class"]."']/StyleParameter");
2444  foreach ($par_nodes as $par_node)
2445  {
2446  // check whether style parameter exists
2447  $set = $ilDB->queryF("SELECT * FROM style_parameter WHERE style_id = %s ".
2448  "AND type = %s AND class = %s AND tag = %s AND parameter = %s",
2449  array("integer", "text", "text", "text", "text"),
2450  array($id, $cs["type"], $cs["class"],
2451  $cs["tag"], $par_node->getAttribute("Name")));
2452 
2453  // if not, create style parameter
2454  if (!($rec = $ilDB->fetchAssoc($set)))
2455  {
2456  $spid = $ilDB->nextId("style_parameter");
2457  $st = $ilDB->manipulateF("INSERT INTO style_parameter (id, style_id, type, class, tag, parameter, value) ".
2458  " VALUES (%s,%s,%s,%s,%s,%s,%s)",
2459  array("integer", "integer", "text", "text", "text", "text", "text"),
2460  array($spid, $id, $cs["type"], $cs["class"], $cs["tag"],
2461  $par_node->getAttribute("Name"), $par_node->getAttribute("Value")));
2462  }
2463  }
2464  }
2465  }
2466 
2467  // now check, whether some core image files are missing
2470  reset($core_images);
2471  foreach($core_images as $cim)
2472  {
2473  if (!is_file($imdir."/".$cim))
2474  {
2475  copy($core_dir."/".$cim, $imdir."/".$cim);
2476  }
2477  }
2478  }
2479  }
2480 
2481  //
2482  // Color management
2483  //
2484 
2489  {
2490  global $ilDB;
2491 
2492  $this->do_3_9_Migration($this->getId());
2493 
2494  //include_once("./Services/Migration/DBUpdate_1385/classes/class.ilStyleMigration.php");
2495  //ilStyleMigration::addMissingStyleCharacteristics($this->getId());
2496 
2497  $this->do_3_10_CharMigration($this->getId());
2498 
2499  // style_char: type for characteristic
2500  $st = $ilDB->prepareManip("UPDATE style_char SET type = ? WHERE characteristic = ?".
2501  " AND style_id = ? ", array("text", "text", "integer"));
2502  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2503  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2504  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2505  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2506  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2507  $ilDB->execute($st, array("page_cont", "Page", $this->getId()));
2508 
2509  // style_parameter: type for class
2510  $st = $ilDB->prepareManip("UPDATE style_parameter SET type = ? WHERE class = ?".
2511  " AND style_id = ? ", array("text", "text", "integer"));
2512  $ilDB->execute($st, array("media_cont", "Media", $this->getId()));
2513  $ilDB->execute($st, array("media_caption", "MediaCaption", $this->getId()));
2514  $ilDB->execute($st, array("page_fn", "Footnote", $this->getId()));
2515  $ilDB->execute($st, array("page_nav", "LMNavigation", $this->getId()));
2516  $ilDB->execute($st, array("page_title", "PageTitle", $this->getId()));
2517  $ilDB->execute($st, array("table", "Page", $this->getId()));
2518 
2519  $st = $ilDB->prepareManip("UPDATE style_parameter SET tag = ? WHERE class = ?".
2520  " AND style_id = ? ", array("text", "text", "integer"));
2521  $ilDB->execute($st, array("div", "MediaCaption", $this->getId()));
2522 
2523  // style_char: characteristic for characteristic
2524  $st = $ilDB->prepareManip("UPDATE style_char SET characteristic = ? WHERE characteristic = ?".
2525  " AND style_id = ? ", array("text", "text", "integer"));
2526  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2527  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2528 
2529  // style_parameter: class for class
2530  $st = $ilDB->prepareManip("UPDATE style_parameter SET class = ? WHERE class = ?".
2531  " AND style_id = ? ", array("text", "text", "integer"));
2532  $ilDB->execute($st, array("MediaContainer", "Media", $this->getId()));
2533  $ilDB->execute($st, array("PageContainer", "Page", $this->getId()));
2534 
2535  // force rewriting of container style
2536  $st = $ilDB->prepareManip("DELETE FROM style_char WHERE type = ?".
2537  " AND style_id = ? ", array("text", "integer"));
2538  $ilDB->execute($st, array("page_cont", $this->getId()));
2539  $st = $ilDB->prepareManip("DELETE FROM style_parameter WHERE type = ?".
2540  " AND style_id = ? ", array("text", "integer"));
2541  $ilDB->execute($st, array("page_cont", $this->getId()));
2542 
2543  }
2544 
2551  function do_3_10_CharMigration($a_id = "")
2552  {
2553  global $ilDB;
2554 
2555  $add_str = "";
2556  if ($a_id != "")
2557  {
2558  $add_str = " AND style_id = ".$ilDB->quote($a_id, "integer");
2559  }
2560 
2561  $set = $ilDB->query($q = "SELECT DISTINCT style_id, tag, class FROM style_parameter WHERE ".
2562  $ilDB->equals("type", "", "text", true)." ".$add_str);
2563 
2564  while ($rec = $ilDB->fetchAssoc($set))
2565  {
2566  // derive types from tag
2567  $types = array();
2568  switch ($rec["tag"])
2569  {
2570  case "div":
2571  case "p":
2572  if (in_array($rec["class"], array("Headline3", "Headline1",
2573  "Headline2", "TableContent", "List", "Standard", "Remark",
2574  "Additional", "Mnemonic", "Citation", "Example")))
2575  {
2576  $types[] = "text_block";
2577  }
2578  if (in_array($rec["class"], array("Block", "Remark",
2579  "Additional", "Mnemonic", "Example", "Excursus", "Special")))
2580  {
2581  $types[] = "section";
2582  }
2583  if (in_array($rec["class"], array("Page", "Footnote", "PageTitle", "LMNavigation")))
2584  {
2585  $types[] = "page";
2586  }
2587  break;
2588 
2589  case "td":
2590  $types[] = "table_cell";
2591  break;
2592 
2593  case "a":
2594  if (in_array($rec["class"], array("ExtLink", "IntLink", "FootnoteLink")))
2595  {
2596  $types[] = "link";
2597  }
2598  break;
2599 
2600  case "span":
2601  $types[] = "text_inline";
2602  break;
2603 
2604  case "table":
2605  $types[] = "table";
2606  break;
2607  }
2608 
2609  // check if style_char set exists
2610  foreach ($types as $t)
2611  {
2612  // check if second type already exists
2613  $set4 = $ilDB->queryF("SELECT * FROM style_char ".
2614  " WHERE style_id = %s AND type = %s AND characteristic = %s",
2615  array("integer", "text", "text"),
2616  array($rec["style_id"], $t, $rec["class"]));
2617  if ($rec4 = $ilDB->fetchAssoc($set4))
2618  {
2619  // ok
2620  }
2621  else
2622  {
2623 //echo "<br>1-".$rec["style_id"]."-".$t."-".$rec["class"]."-";
2624  $ilDB->manipulateF("INSERT INTO style_char ".
2625  " (style_id, type, characteristic) VALUES ".
2626  " (%s,%s,%s) ",
2627  array("integer", "text", "text"),
2628  array($rec["style_id"], $t, $rec["class"]));
2629  }
2630  }
2631 
2632  // update types
2633  if ($rec["type"] == "")
2634  {
2635  if (count($types) > 0)
2636  {
2637  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2638  " WHERE style_id = %s AND class = %s AND ".$ilDB->equals("type", "", "text", true),
2639  array("text", "integer", "text"),
2640  array($types[0], $rec["style_id"], $rec["class"]));
2641 //echo "<br>3-".$types[0]."-".$rec["style_id"]."-".$rec["class"]."-";
2642 
2643  // links extra handling
2644  if ($types[0] == "link")
2645  {
2646  $ilDB->manipulateF("UPDATE style_parameter SET type = %s ".
2647  " WHERE style_id = %s AND (class = %s OR class = %s) AND ".$ilDB->equals("type", "", "text", true),
2648  array("text", "integer", "text", "text"),
2649  array($types[0], $rec["style_id"], $rec["class"].":visited",
2650  $rec["class"].":hover"));
2651  }
2652  }
2653 
2654  if (count($types) == 2)
2655  {
2656  // select all records of first type and add second type
2657  // records if necessary.
2658  $set2 = $ilDB->queryF("SELECT * FROM style_parameter ".
2659  " WHERE style_id = %s AND class = %s AND type = %s",
2660  array("integer", "text", "text"),
2661  array($rec["style_id"], $rec["class"], $types[0]));
2662  while ($rec2 = $ilDB->fetchAssoc($set2))
2663  {
2664  // check if second type already exists
2665  $set3 = $ilDB->queryF("SELECT * FROM style_parameter ".
2666  " WHERE style_id = %s AND tag = %s AND class = %s AND type = %s AND parameter = %s",
2667  array("integer", "text", "text", "text", "text"),
2668  array($rec["style_id"], $rec["tag"], $rec["class"], $types[1], $rec["parameter"]));
2669  if ($rec3 = $ilDB->fetchAssoc($set3))
2670  {
2671  // ok
2672  }
2673  else
2674  {
2675  $nid = $ilDB->nextId("style_parameter");
2676  $ilDB->manipulateF("INSERT INTO style_parameter ".
2677  " (id, style_id, tag, class, parameter, value, type) VALUES ".
2678  " (%s, %s,%s,%s,%s,%s,%s) ",
2679  array("integer", "integer", "text", "text", "text", "text", "text"),
2680  array($nid, $rec2["style_id"], $rec2["tag"], $rec2["class"],
2681  $rec2["parameter"], $rec2["value"], $types[1]));
2682  }
2683  }
2684  }
2685  }
2686  }
2687  }
2688 
2692  function do_3_9_Migration($a_id)
2693  {
2694  global $ilDB;
2695 
2696  $classes = array("Example", "Additional", "Citation", "Mnemonic", "Remark");
2697  $pars = array("margin-top", "margin-bottom");
2698 
2699  foreach ($classes as $curr_class)
2700  {
2701  foreach ($pars as $curr_par)
2702  {
2703  $res2 = $ilDB->queryF("SELECT id FROM style_parameter WHERE style_id = %s".
2704  " AND tag = %s AND class= %s AND parameter = %s",
2705  array("integer", "text", "text", "text"),
2706  array($a_id, "p", $curr_class, $curr_par));
2707  if ($row2 = $ilDB->fetchAssoc($res2))
2708  {
2709  $ilDB->manipulateF("UPDATE style_parameter SET value= %s WHERE id = %s",
2710  array("text", "integer"),
2711  array("10px", $row2["id"]));
2712  }
2713  else
2714  {
2715  $nid = $ilDB->nextId("style_parameter");
2716  $ilDB->manipulateF("INSERT INTO style_parameter ".
2717  "(id, style_id, tag, class, parameter,value) VALUES (%s,%s,%s,%s,%s,%s)",
2718  array("integer", "integer", "text", "text", "text", "text"),
2719  array($nid, $a_id, "div", $curr_class, $curr_par, "10px"));
2720  }
2721  }
2722  }
2723 
2724  $ilDB->manipulateF("UPDATE style_parameter SET tag = %s WHERE tag = %s and style_id = %s",
2725  array("text", "text", "integer"),
2726  array("div", "p", $a_id));
2727 
2728  }
2729 
2730 
2734  function getColors()
2735  {
2736  global $ilDB;
2737 
2738  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
2739  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
2740  "ORDER BY color_name");
2741 
2742  $colors = array();
2743  while ($rec = $ilDB->fetchAssoc($set))
2744  {
2745  $colors[] = array(
2746  "name" => $rec["color_name"],
2747  "code" => $rec["color_code"]
2748  );
2749  }
2750 
2751  return $colors;
2752  }
2753 
2757  function addColor($a_name, $a_code)
2758  {
2759  global $ilDB;
2760 
2761  $ilDB->manipulate("INSERT INTO style_color (style_id, color_name, color_code)".
2762  " VALUES (".
2763  $ilDB->quote($this->getId(), "integer").",".
2764  $ilDB->quote($a_name, "text").",".
2765  $ilDB->quote($a_code, "text").
2766  ")");
2767  }
2768 
2772  function updateColor($a_name, $a_new_name, $a_code)
2773  {
2774  global $ilDB;
2775 
2776  // todo: update names in parameters as well
2777 
2778  $ilDB->manipulate("UPDATE style_color SET ".
2779  "color_name = ".$ilDB->quote($a_new_name, "text").", ".
2780  "color_code = ".$ilDB->quote($a_code, "text").
2781  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2782  " AND color_name = ".$ilDB->quote($a_name, "text"));
2783  ilObjStyleSheet::_writeUpToDate($this->getId(), false);
2784 
2785  // rename also the name in the style parameter values
2786  if ($a_name != $a_new_name)
2787  {
2788  $set = $ilDB->query("SELECT * FROM style_parameter ".
2789  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
2790  " AND (".
2791  " parameter = ".$ilDB->quote("background-color", "text"). " OR ".
2792  " parameter = ".$ilDB->quote("color", "text"). " OR ".
2793  " parameter = ".$ilDB->quote("border-color", "text"). " OR ".
2794  " parameter = ".$ilDB->quote("border-top-color", "text"). " OR ".
2795  " parameter = ".$ilDB->quote("border-bottom-color", "text"). " OR ".
2796  " parameter = ".$ilDB->quote("border-left-color", "text"). " OR ".
2797  " parameter = ".$ilDB->quote("border-right-color", "text").
2798  ")");
2799  while ($rec = $ilDB->fetchAssoc($set))
2800  {
2801  if ($rec["value"] == "!".$a_name ||
2802  is_int(strpos($rec["value"], "!".$a_name."(")))
2803  {
2804  // parameter is based on color -> rename it
2805  $this->replaceStylePar($rec["tag"], $rec["class"],
2806  $rec["parameter"], str_replace($a_name, $a_new_name, $rec["value"]), $rec["type"]);
2807  }
2808  }
2809  }
2810  }
2811 
2815  function removeColor($a_name)
2816  {
2817  global $ilDB;
2818 
2819  $ilDB->manipulate("DELETE FROM style_color WHERE ".
2820  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2821  " color_name = ".$ilDB->quote($a_name, "text"));
2822  }
2823 
2827  function colorExists($a_color_name)
2828  {
2829  global $ilDB;
2830 
2831  $set = $ilDB->query("SELECT * FROM style_color WHERE ".
2832  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2833  "color_name = ".$ilDB->quote($a_color_name, "text"));
2834  if ($rec = $ilDB->fetchAssoc($set))
2835  {
2836  return true;
2837  }
2838  return false;
2839  }
2840 
2844  function getColorCodeForName($a_name)
2845  {
2846  global $ilDB;
2847 
2848  $pos = strpos($a_name, "(");
2849  if ($pos > 0)
2850  {
2851  $a_i = substr($a_name, $pos + 1);
2852  $a_i = str_replace(")", "", $a_i);
2853  $a_name = substr($a_name, 0, $pos);
2854  }
2855 
2856  $set = $ilDB->query("SELECT color_code FROM style_color WHERE ".
2857  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
2858  " color_name = ".$ilDB->quote($a_name, "text"));
2859  if ($rec = $ilDB->fetchAssoc($set))
2860  {
2861  if ($a_i == "")
2862  {
2863  return "#".$rec["color_code"];
2864  }
2865  else
2866  {
2867  return "#".ilObjStyleSheet::_getColorFlavor($rec["color_code"],
2868  (int) $a_i);
2869  }
2870  }
2871  }
2872 
2876  static function _getColorFlavor($a_rgb, $a_i)
2877  {
2878  $rgb = ilObjStyleSheet::_explodeRGB($a_rgb, true);
2879  $hls = ilObjStyleSheet::_RGBToHLS($rgb);
2880 
2881  if ($a_i > 0)
2882  {
2883  $hls["l"] = $hls["l"] + ((255 - $hls["l"]) * ($a_i / 100));
2884  }
2885  if ($a_i < 0)
2886  {
2887  $hls["l"] = $hls["l"] - (($hls["l"]) * (-$a_i / 100));
2888  }
2889 
2890  $rgb = ilObjStyleSheet::_HLSToRGB($hls);
2891 
2892  foreach ($rgb as $k => $v)
2893  {
2894  $rgb[$k] = str_pad(dechex($v), 2, "0", STR_PAD_LEFT);
2895  }
2896 
2897  return $rgb["r"].$rgb["g"].$rgb["b"];
2898  }
2899 
2903  static function _explodeRGB($a_rgb, $as_dec = false)
2904  {
2905  $r["r"] = substr($a_rgb, 0, 2);
2906  $r["g"] = substr($a_rgb, 2, 2);
2907  $r["b"] = substr($a_rgb, 4, 2);
2908 
2909  if ($as_dec)
2910  {
2911  $r["r"] = (int) hexdec($r["r"]);
2912  $r["g"] = (int) hexdec($r["g"]);
2913  $r["b"] = (int) hexdec($r["b"]);
2914  }
2915 
2916  return $r;
2917  }
2918 
2922  static function _RGBToHLS($a_rgb)
2923  {
2924  $r = $a_rgb["r"] / 255;
2925  $g = $a_rgb["g"] / 255;
2926  $b = $a_rgb["b"] / 255;
2927 
2928  // max / min
2929  $max = max($r,$g,$b);
2930  $min = min($r,$g,$b);
2931 
2932  //lightness
2933  $l = ($max + $min) / 2;
2934 
2935  if ($max == $min)
2936  {
2937  $s = 0;
2938  $h = 0;
2939  }
2940  else
2941  {
2942  if ($l < 0.5)
2943  {
2944  $s = ($max - $min) / ($max + $min);
2945  }
2946  else
2947  {
2948  $s = ($max - $min) / (2.0 - $max - $min);
2949  }
2950 
2951  if ($r == $max)
2952  {
2953  $h = ($g - $b) / ($max - $min);
2954  }
2955  else if ($g == $max)
2956  {
2957  $h = 2.0 + ($b - $r) / ($max - $min);
2958  }
2959  else if ($b == $max)
2960  {
2961  $h = 4.0 + ($r - $g) / ($max - $min);
2962  }
2963  }
2964 
2965  $hls["h"] = round(($h / 6) * 255);
2966  $hls["l"] = round($l * 255);
2967  $hls["s"] = round($s * 255);
2968 
2969  return $hls;
2970  }
2971 
2975  static function _HLSToRGB($a_hls)
2976  {
2977  $h = $a_hls["h"] / 255;
2978  $l = $a_hls["l"] / 255;
2979  $s = $a_hls["s"] / 255;
2980 
2981  $rgb["r"] = $rgb["g"] = $rgb["b"] = 0;
2982 
2983  // If S=0, define R, G, and B all to L
2984  if ($s == 0)
2985  {
2986  $rgb["r"] = $rgb["g"] = $rgb["b"] = $l;
2987  }
2988  else
2989  {
2990 
2991  if ($l < 0.5)
2992  {
2993  $temp2 = $l * (1.0 + $s);
2994  }
2995  else
2996  {
2997  $temp2 = $l + $s - $l * $s;
2998  }
2999 
3000  $temp1 = 2.0 * $l - $temp2;
3001 
3002 
3003  # For each of R, G, B, compute another temporary value, temp3, as follows:
3004  foreach ($rgb as $k => $v)
3005  {
3006  switch ($k)
3007  {
3008  case "r":
3009  $temp3 = $h + 1.0 / 3.0;
3010  break;
3011 
3012  case "g":
3013  $temp3 = $h;
3014  break;
3015 
3016  case "b":
3017  $temp3 = $h - 1.0/3.0;
3018  break;
3019  }
3020  if ($temp3 < 0)
3021  {
3022  $temp3 = $temp3 + 1.0;
3023  }
3024  if ($temp3 > 1)
3025  {
3026  $temp3 = $temp3 - 1.0;
3027  }
3028 
3029  if (6.0 * $temp3 < 1)
3030  {
3031  $rgb[$k] = $temp1 + ($temp2 - $temp1) * 6.0 * $temp3;
3032  }
3033  else if (2.0 * $temp3 < 1)
3034  {
3035  $rgb[$k] = $temp2;
3036  }
3037  else if (3.0 * $temp3 < 2)
3038  {
3039  $rgb[$k] = $temp1 + ($temp2 - $temp1) * ((2.0/3.0) - $temp3) * 6.0;
3040  }
3041  else
3042  {
3043  $rgb[$k] = $temp1;
3044  }
3045  }
3046  }
3047 
3048  $rgb["r"] = round($rgb["r"] * 255);
3049  $rgb["g"] = round($rgb["g"] * 255);
3050  $rgb["b"] = round($rgb["b"] * 255);
3051 
3052  return $rgb;
3053  }
3054 
3055  //
3056  // Table template management
3057  //
3058 
3062  function getTemplates($a_type)
3063  {
3064  global $ilDB;
3065 
3066  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3067  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3068  "temp_type = ".$ilDB->quote($a_type, "text")." ".
3069  "ORDER BY name");
3070 
3071  $templates = array();
3072  while ($rec = $ilDB->fetchAssoc($set))
3073  {
3074  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3075  $templates[] = $rec;
3076  }
3077 
3078  return $templates;
3079  }
3080 
3084  function getTemplateClasses($a_tid)
3085  {
3086  global $ilDB;
3087  $set = $ilDB->query("SELECT * FROM style_template_class WHERE ".
3088  "template_id = ".$ilDB->quote($a_tid, "integer"));
3089 
3090  $class = array();
3091  while ($rec = $ilDB->fetchAssoc($set))
3092  {
3093  $key = $rec["class_type"];
3094  $class[$key] = $rec["class"];
3095  }
3096 
3097  return $class;
3098  }
3099 
3100 
3104  function addTemplate($a_type, $a_name, $a_classes)
3105  {
3106  global $ilDB;
3107 
3108  $tid = $ilDB->nextId("style_template");
3109  $ilDB->manipulate($q = "INSERT INTO style_template ".
3110  "(id, style_id, name, temp_type)".
3111  " VALUES (".
3112  $ilDB->quote($tid, "integer").",".
3113  $ilDB->quote($this->getId(), "integer").",".
3114  $ilDB->quote($a_name, "text").",".
3115  $ilDB->quote($a_type, "text").
3116  ")");
3117 
3118  foreach ($a_classes as $t => $c)
3119  {
3120  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3121  "(template_id, class_type, class)".
3122  " VALUES (".
3123  $ilDB->quote($tid, "integer").",".
3124  $ilDB->quote($t, "text").",".
3125  $ilDB->quote($c, "text").
3126  ")");
3127  }
3128 
3129  include_once("./Services/Style/classes/class.ilObjStyleSheetGUI.php");
3130  $this->writeTemplatePreview($tid,
3131  ilObjStyleSheetGUI::_getTemplatePreview($this, $a_type, $tid, true));
3132 
3133  return $tid;
3134  }
3135 
3139  function updateTemplate($a_t_id, $a_name, $a_classes)
3140  {
3141  global $ilDB;
3142 
3143  $ilDB->manipulate("UPDATE style_template SET ".
3144  "name = ".$ilDB->quote($a_name, "text").
3145  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3146 
3147  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3148  "template_id = ".$ilDB->quote($a_t_id, "integer")
3149  );
3150  foreach ($a_classes as $t => $c)
3151  {
3152  $ilDB->manipulate($q = "INSERT INTO style_template_class ".
3153  "(template_id, class_type, class)".
3154  " VALUES (".
3155  $ilDB->quote($a_t_id, "integer").",".
3156  $ilDB->quote($t, "text").",".
3157  $ilDB->quote($c, "text").
3158  ")");
3159  }
3160 
3161  }
3162 
3166  function templateExists($a_template_name)
3167  {
3168  global $ilDB;
3169 
3170  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3171  "style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3172  "name = ".$ilDB->quote($a_template_name, "text"));
3173  if ($rec = $ilDB->fetchAssoc($set))
3174  {
3175  return true;
3176  }
3177  return false;
3178  }
3179 
3183  function getTemplate($a_t_id)
3184  {
3185  global $ilDB;
3186 
3187  $set = $ilDB->query("SELECT * FROM style_template WHERE ".
3188  "style_id = ".$ilDB->quote($this->getId(), "integer")." ".
3189  " AND id = ".$ilDB->quote($a_t_id, "integer"));
3190 
3191  if ($rec = $ilDB->fetchAssoc($set))
3192  {
3193  $rec["classes"] = $this->getTemplateClasses($rec["id"]);
3194 
3195  $template = $rec;
3196  return $template;
3197  }
3198  return array();
3199  }
3200 
3204  function lookupTemplateName($a_t_id)
3205  {
3206  global $ilDB;
3207 
3208  $set = $ilDB->query("SELECT name FROM style_template WHERE ".
3209  " id = ".$ilDB->quote($a_t_id, "integer"));
3210 
3211  if ($rec = $ilDB->fetchAssoc($set))
3212  {
3213  return $rec["name"];
3214  }
3215 
3216  return false;
3217  }
3218 
3222  function getTemplateXML()
3223  {
3224  global $ilDB;
3225 
3226  $tag = "<StyleTemplates>";
3227 
3228  $ttypes = array("table", "vaccordion", "haccordion");
3229 
3230  foreach ($ttypes as $ttype)
3231  {
3232  $ts = $this->getTemplates($ttype);
3233 
3234  foreach($ts as $t)
3235  {
3237  /*$atts = array("table" => "TableClass",
3238  "caption" => "CaptionClass",
3239  "row_head" => "RowHeadClass",
3240  "row_foot" => "RowFootClass",
3241  "col_head" => "ColHeadClass",
3242  "col_foot" => "ColFootClass",
3243  "odd_row" => "OddRowClass",
3244  "even_row" => "EvenRowClass",
3245  "odd_col" => "OddColClass",
3246  "even_col" => "EvenColClass");*/
3247  $c = $t["classes"];
3248 
3249  $tag.= '<StyleTemplate Name="'.$t["name"].'">';
3250 
3251  foreach ($atts as $type => $t)
3252  {
3253  if ($c[$type] != "")
3254  {
3255  $tag.= '<StyleClass Type="'.$type.'" Value="'.$c[$type].'" />';
3256  }
3257  }
3258 
3259  $tag.= "</StyleTemplate>";
3260  }
3261  }
3262 
3263  $tag.= "</StyleTemplates>";
3264 
3265 //echo htmlentities($tag);
3266  return $tag;
3267  }
3268 
3272  function writeTemplatePreview($a_t_id, $a_preview_html)
3273  {
3274  global $ilDB;
3275  $a_preview_html = str_replace(' width=""', "", $a_preview_html);
3276  $a_preview_html = str_replace(' valign="top"', "", $a_preview_html);
3277  $a_preview_html = str_replace('<div class="ilc_text_block_TableContent">', "<div>", $a_preview_html);
3278 //echo "1-".strlen($a_preview_html)."-";
3279 //echo htmlentities($a_preview_html);
3280  if (strlen($a_preview_html) > 4000)
3281  {
3282 //echo "2";
3283  $a_preview_html = "";
3284  }
3285  $ilDB->manipulate("UPDATE style_template SET ".
3286  "preview = ".$ilDB->quote($a_preview_html, "text").
3287  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3288  }
3289 
3293  function lookupTemplatePreview($a_t_id)
3294  {
3295  global $ilDB;
3296 
3297  $set = $ilDB->query("SELECT preview FROM style_template ".
3298  " WHERE id = ".$ilDB->quote($a_t_id, "integer"));
3299  if ($rec = $ilDB->fetchAssoc($set))
3300  {
3301  return $rec["preview"];
3302  }
3303 
3304  return "";
3305  }
3306 
3310  static function _lookupTemplateIdByName($a_style_id, $a_name)
3311  {
3312  global $ilDB;
3313 
3314  $set = $ilDB->query("SELECT id FROM style_template ".
3315  " WHERE style_id = ".$ilDB->quote($a_style_id, "integer").
3316  " AND name = ".$ilDB->quote($a_name, "text"));
3317  if ($rec = $ilDB->fetchAssoc($set))
3318  {
3319  return $rec["id"];
3320  }
3321 
3322  return false;
3323  }
3324 
3328  function removeTemplate($a_t_id)
3329  {
3330  global $ilDB;
3331 
3332  $ilDB->manipulate("DELETE FROM style_template WHERE ".
3333  " style_id = ".$ilDB->quote($this->getId(), "integer")." AND ".
3334  " id = ".$ilDB->quote($a_t_id, "integer"));
3335 
3336  $ilDB->manipulate("DELETE FROM style_template_class WHERE ".
3337  "template_id = ".$ilDB->quote($a_t_id, "integer")
3338  );
3339 
3340  }
3341 
3345  function writeStyleSetting($a_name, $a_value)
3346  {
3347  global $ilDB;
3348 
3349  $ilDB->manipulate("DELETE FROM style_setting WHERE ".
3350  " style_id = ".$ilDB->quote($this->getId(), "integer").
3351  " AND name = ".$ilDB->quote($a_name, "text")
3352  );
3353 
3354  $ilDB->manipulate("INSERT INTO style_setting ".
3355  "(style_id, name, value) VALUES (".
3356  $ilDB->quote($this->getId(), "integer").",".
3357  $ilDB->quote($a_name, "text").",".
3358  $ilDB->quote($a_value, "text").
3359  ")");
3360  }
3361 
3365  function lookupStyleSetting($a_name)
3366  {
3367  global $ilDB;
3368 
3369  $set = $ilDB->query("SELECT value FROM style_setting ".
3370  " WHERE style_id = ".$ilDB->quote($this->getId(), "integer").
3371  " AND name = ".$ilDB->quote($a_name, "text")
3372  );
3373  $rec = $ilDB->fetchAssoc($set);
3374 
3375  return $rec["value"];
3376  }
3377 
3381  static function writeStyleUsage($a_obj_id, $a_style_id)
3382  {
3383  global $ilDB;
3384 
3385  $ilDB->replace("style_usage", array(
3386  "obj_id" => array("integer", (int) $a_obj_id)),
3387  array(
3388  "style_id" => array("integer", (int) $a_style_id))
3389  );
3390  }
3391 
3395  static function lookupObjectStyle($a_obj_id)
3396  {
3397  global $ilDB;
3398 
3399  $set = $ilDB->query("SELECT style_id FROM style_usage ".
3400  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer")
3401  );
3402  $rec = $ilDB->fetchAssoc($set);
3403 
3404  if (ilObject::_lookupType($rec["style_id"]) == "sty")
3405  {
3406  return (int) $rec["style_id"];
3407  }
3408 
3409  return 0;
3410  }
3411 
3412 
3413 }
3414 ?>
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.
getXML()
get xml representation of style object
static _explodeRGB($a_rgb, $as_dec=false)
Explode an RGB string into an array.
print $file
replaceStylePar($a_tag, $a_class, $a_par, $a_val, $a_type)
Set style parameter per tag/class/parameter.
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.
addParameter($a_tag, $a_par, $a_type)
write style parameter to db
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.
_lookupUpToDate($a_id)
Looup up to date.
writeCSSFile($a_target_file="", $a_image_dir="")
write css file to webspace directory
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.
static writeStyleUsage($a_obj_id, $a_style_id)
Write style usage.
addColor($a_name, $a_code)
Add color.
getTemplate($a_t_id)
Get template.
_replaceStylePar($style_id, $a_tag, $a_class, $a_par, $a_val, $a_type)
_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.
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.
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.
deleteStylePar($a_tag, $a_class, $a_par, $a_type)
Delete style parameter by tag/class/parameter.
saveHideStatus($a_type, $a_char, $a_hide)
Save characteristic hide status.
setStyle($a_style)
set styles
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 ...
_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)
static getDataDir()
get data directory (outside webspace)
getParametersOfClass($a_type, $a_class)
Get parameters of class.
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
Class ilObjStyleSheet.
static _getStyleParameters($a_tag="")
removeTemplate($a_t_id)
Remove table template.
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
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.
ilClone()
clone style sheet (note: styles have no ref ids and return an object id)
static getAvailableParameters()
Get available parameters.
lookupTemplatePreview($a_t_id)
Lookup table template preview.
$r
getUpToDate()
Get up to date.