00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once "classes/class.ilObject.php";
00026
00036 class ilObjStyleSheet extends ilObject
00037 {
00038 var $style;
00039
00040
00047 function ilObjStyleSheet($a_id = 0, $a_call_by_reference = false)
00048 {
00049 $this->type = "sty";
00050 $this->style = array();
00051 if($a_call_by_reference)
00052 {
00053 $this->ilias->raiseError("Can't instantiate style object via reference id.",$this->ilias->error_obj->FATAL);
00054 }
00055
00056 parent::ilObject($a_id, false);
00057 }
00058
00059 function setRefId()
00060 {
00061 $this->ilias->raiseError("Operation ilObjStyleSheet::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
00062 }
00063
00064 function getRefId()
00065 {
00066 return "";
00067
00068 }
00069
00070 function putInTree()
00071 {
00072 $this->ilias->raiseError("Operation ilObjStyleSheet::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
00073 }
00074
00075 function createReference()
00076 {
00077 $this->ilias->raiseError("Operation ilObjStyleSheet::createReference() not allowed.",$this->ilias->error_obj->FATAL);
00078 }
00079
00083 function assignMetaData(&$a_meta_data)
00084 {
00085 $this->meta_data =& $a_meta_data;
00086 }
00087
00091 function &getMetaData()
00092 {
00093 return $this->meta_data;
00094 }
00095
00096 function create()
00097 {
00098 parent::create();
00099
00100 $def = array(
00101 array("tag" => "div", "class" => "PageTitle", "parameter" => "margin-top" ,"value" => "5px"),
00102 array("tag" => "div", "class" => "PageTitle", "parameter" => "margin-bottom" ,"value" => "20px"),
00103 array("tag" => "div", "class" => "PageTitle", "parameter" => "font-size" ,"value" => "23px"),
00104 array("tag" => "div", "class" => "PageTitle", "parameter" => "font-weight" ,"value" => "bold"),
00105 array("tag" => "div", "class" => "PageTitle", "parameter" => "padding-bottom" ,"value" => "3px"),
00106 array("tag" => "div", "class" => "PageTitle", "parameter" => "border-bottom-width" ,"value" => "1px"),
00107 array("tag" => "div", "class" => "PageTitle", "parameter" => "border-bottom-style" ,"value" => "solid"),
00108 array("tag" => "div", "class" => "PageTitle", "parameter" => "border-color" ,"value" => "#000000"),
00109
00110 array("tag" => "span", "class" => "Strong", "parameter" => "font-weight" ,"value" => "bold"),
00111 array("tag" => "span", "class" => "Emph", "parameter" => "font-style" ,"value" => "italic"),
00112 array("tag" => "span", "class" => "Comment", "parameter" => "color" ,"value" => "green"),
00113 array("tag" => "span", "class" => "Quotation", "parameter" => "color" ,"value" => "brown"),
00114 array("tag" => "span", "class" => "Quotation", "parameter" => "font-style" ,"value" => "italic"),
00115
00116 array("tag" => "a", "class" => "FootnoteLink", "parameter" => "color" ,"value" => "blue"),
00117 array("tag" => "a", "class" => "FootnoteLink", "parameter" => "font-weight" ,"value" => "normal"),
00118 array("tag" => "a", "class" => "FootnoteLink:hover", "parameter" => "color" ,"value" => "#000000"),
00119 array("tag" => "div", "class" => "Footnote", "parameter" => "margin-top" ,"value" => "5px"),
00120 array("tag" => "div", "class" => "Footnote", "parameter" => "margin-bottom" ,"value" => "5px"),
00121 array("tag" => "div", "class" => "Footnote", "parameter" => "font-style" ,"value" => "italic"),
00122
00123 array("tag" => "a", "class" => "IntLink", "parameter" => "color" ,"value" => "blue"),
00124 array("tag" => "a", "class" => "IntLink:visited", "parameter" => "color" ,"value" => "blue"),
00125 array("tag" => "a", "class" => "IntLink", "parameter" => "font-weight" ,"value" => "normal"),
00126 array("tag" => "a", "class" => "IntLink", "parameter" => "text-decoration" ,"value" => "underline"),
00127 array("tag" => "a", "class" => "IntLink:hover", "parameter" => "color" ,"value" => "#000000"),
00128
00129 array("tag" => "a", "class" => "ExtLink", "parameter" => "color" ,"value" => "blue"),
00130 array("tag" => "a", "class" => "ExtLink:visited", "parameter" => "color" ,"value" => "blue"),
00131 array("tag" => "a", "class" => "ExtLink", "parameter" => "font-weight" ,"value" => "normal"),
00132 array("tag" => "a", "class" => "ExtLink", "parameter" => "text-decoration" ,"value" => "underline"),
00133 array("tag" => "a", "class" => "ExtLink:hover", "parameter" => "color" ,"value" => "#000000"),
00134
00135 array("tag" => "div", "class" => "LMNavigation", "parameter" => "background-color" ,"value" => "#EEEEEE"),
00136 array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-style" ,"value" => "outset"),
00137 array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-color" ,"value" => "#EEEEEE"),
00138 array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-width" ,"value" => "1px"),
00139 array("tag" => "div", "class" => "Page", "parameter" => "background-color" ,"value" => "#EEEEEE"),
00140 array("tag" => "div", "class" => "Page", "parameter" => "padding" ,"value" => "0px"),
00141 array("tag" => "div", "class" => "Page", "parameter" => "margin" ,"value" => "0px"),
00142 array("tag" => "td", "class" => "Cell1", "parameter" => "background-color" ,"value" => "#FFCCCC"),
00143 array("tag" => "td", "class" => "Cell2", "parameter" => "background-color" ,"value" => "#CCCCFF"),
00144 array("tag" => "td", "class" => "Cell3", "parameter" => "background-color" ,"value" => "#CCFFCC"),
00145 array("tag" => "td", "class" => "Cell4", "parameter" => "background-color" ,"value" => "#FFFFCC"),
00146
00147 array("tag" => "p", "class" => "Standard", "parameter" => "margin-top" ,"value" => "10px"),
00148 array("tag" => "p", "class" => "Standard", "parameter" => "margin-bottom" ,"value" => "10px"),
00149
00150 array("tag" => "p", "class" => "List", "parameter" => "margin-top" ,"value" => "3px"),
00151 array("tag" => "p", "class" => "List", "parameter" => "margin-bottom" ,"value" => "3px"),
00152
00153 array("tag" => "p", "class" => "Headline1", "parameter" => "margin-top" ,"value" => "15px"),
00154 array("tag" => "p", "class" => "Headline1", "parameter" => "margin-bottom" ,"value" => "10px"),
00155 array("tag" => "p", "class" => "Headline1", "parameter" => "font-size" ,"value" => "22px"),
00156 array("tag" => "p", "class" => "Headline1", "parameter" => "font-weight" ,"value" => "bold"),
00157
00158 array("tag" => "p", "class" => "Headline2", "parameter" => "margin-top" ,"value" => "15px"),
00159 array("tag" => "p", "class" => "Headline2", "parameter" => "margin-bottom" ,"value" => "10px"),
00160 array("tag" => "p", "class" => "Headline2", "parameter" => "font-size" ,"value" => "18px"),
00161 array("tag" => "p", "class" => "Headline2", "parameter" => "font-weight" ,"value" => "bold"),
00162
00163 array("tag" => "p", "class" => "Headline3", "parameter" => "margin-top" ,"value" => "15px"),
00164 array("tag" => "p", "class" => "Headline3", "parameter" => "margin-bottom" ,"value" => "10px"),
00165 array("tag" => "p", "class" => "Headline3", "parameter" => "font-size" ,"value" => "14px"),
00166 array("tag" => "p", "class" => "Headline3", "parameter" => "font-weight" ,"value" => "bold"),
00167
00168 array("tag" => "p", "class" => "Example", "parameter" => "padding-left" ,"value" => "20px"),
00169 array("tag" => "p", "class" => "Example", "parameter" => "border-left" ,"value" => "3px"),
00170 array("tag" => "p", "class" => "Example", "parameter" => "border-left-style" ,"value" => "solid"),
00171 array("tag" => "p", "class" => "Example", "parameter" => "border-left-color" ,"value" => "blue"),
00172
00173 array("tag" => "p", "class" => "Citation", "parameter" => "color" ,"value" => "brown"),
00174 array("tag" => "p", "class" => "Citation", "parameter" => "font-style" ,"value" => "italic"),
00175
00176 array("tag" => "p", "class" => "Mnemonic", "parameter" => "margin-left" ,"value" => "20px"),
00177 array("tag" => "p", "class" => "Mnemonic", "parameter" => "margin-right" ,"value" => "20px"),
00178 array("tag" => "p", "class" => "Mnemonic", "parameter" => "color" ,"value" => "red"),
00179 array("tag" => "p", "class" => "Mnemonic", "parameter" => "padding" ,"value" => "10px"),
00180 array("tag" => "p", "class" => "Mnemonic", "parameter" => "border" ,"value" => "1px"),
00181 array("tag" => "p", "class" => "Mnemonic", "parameter" => "border-style" ,"value" => "solid"),
00182 array("tag" => "p", "class" => "Mnemonic", "parameter" => "border-color" ,"value" => "red"),
00183
00184 array("tag" => "p", "class" => "Additional", "parameter" => "padding" ,"value" => "10px"),
00185 array("tag" => "p", "class" => "Additional", "parameter" => "border" ,"value" => "1px"),
00186 array("tag" => "p", "class" => "Additional", "parameter" => "border-style" ,"value" => "solid"),
00187 array("tag" => "p", "class" => "Additional", "parameter" => "border-color" ,"value" => "blue"),
00188
00189 array("tag" => "p", "class" => "Remark", "parameter" => "padding" ,"value" => "10px"),
00190 array("tag" => "p", "class" => "Remark", "parameter" => "border" ,"value" => "1px"),
00191 array("tag" => "p", "class" => "Remark", "parameter" => "border-style" ,"value" => "solid"),
00192 array("tag" => "p", "class" => "Remark", "parameter" => "border-color" ,"value" => "#909090"),
00193 array("tag" => "p", "class" => "Remark", "parameter" => "background-color" ,"value" => "#D0D0D0"),
00194 array("tag" => "p", "class" => "Remark", "parameter" => "text-align" ,"value" => "right"),
00195
00196 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-left" ,"value" => "0px"),
00197 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-right" ,"value" => "0px"),
00198 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-top" ,"value" => "0px"),
00199 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-bottom" ,"value" => "0px"),
00200 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-left" ,"value" => "0px"),
00201 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-right" ,"value" => "0px"),
00202 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-top" ,"value" => "0px"),
00203 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-bottom" ,"value" => "0px"),
00204
00205 array("tag" => "table", "class" => "Media", "parameter" => "background-color" ,"value" => "#F5F5F5"),
00206 array("tag" => "table", "class" => "Media", "parameter" => "padding" ,"value" => "0px"),
00207 array("tag" => "table", "class" => "Media", "parameter" => "margin" ,"value" => "10px"),
00208
00209 array("tag" => "td", "class" => "MediaCaption", "parameter" => "padding" ,"value" => "5px")
00210 );
00211
00212
00213
00214 foreach ($def as $sty)
00215 {
00216 $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00217 "('".$this->getId()."','".$sty["tag"]."','".$sty["class"].
00218 "','".$sty["parameter"]."','".$sty["value"]."')";
00219 $this->ilias->db->query($q);
00220 }
00221
00222 $this->read();
00223 $this->writeCSSFile();
00224 }
00225
00232 function addParameter($a_tag, $a_par)
00233 {
00234 $avail_params = $this->getAvailableParameters();
00235 $tag = explode(".", $a_tag);
00236 $value = $avail_params[$a_par][0];
00237 $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00238 "('".$this->getId()."','".$tag[0]."','".$tag[1].
00239 "','".$a_par."','".$value."')";
00240 $this->ilias->db->query($q);
00241 $this->read();
00242 $this->writeCSSFile();
00243 }
00244
00250 function deleteParameter($a_id)
00251 {
00252 $q = "DELETE FROM style_parameter WHERE id = '".$a_id."'";
00253 $this->ilias->db->query($q);
00254 }
00255
00256
00260 function delete()
00261 {
00262 global $ilDB;
00263
00264
00265 parent::delete();
00266
00267
00268 $def_style = $this->ilias->getSetting("default_content_style_id");
00269 if ($def_style == $this->getId())
00270 {
00271 $this->ilias->deleteSetting("default_content_style_id");
00272 }
00273
00274
00275 $fixed_style = $this->ilias->getSetting("fixed_content_style_id");
00276 if ($fixed_style == $this->getId())
00277 {
00278 $this->ilias->deleteSetting("fixed_content_style_id");
00279 }
00280
00281
00282 $q = "DELETE FROM style_parameter WHERE style_id = ".$ilDB->quote($this->getId());
00283 $ilDB->query($q);
00284
00285
00286 $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
00287 if (is_file($css_file_name))
00288 {
00289 unlink($css_file_name);
00290 }
00291
00292
00293 include_once("content/classes/class.ilObjContentObject.php");
00294 ilObjContentObject::_deleteStyleAssignments($this->getId());
00295
00296 }
00297
00298
00302 function read()
00303 {
00304 parent::read();
00305
00306 $q = "SELECT * FROM style_parameter WHERE style_id = '".$this->getId()."' ORDER BY tag, class ";
00307 $style_set = $this->ilias->db->query($q);
00308 $ctag = "";
00309 $cclass = "";
00310 $this->style = array();
00311 while($style_rec = $style_set->fetchRow(DB_FETCHMODE_ASSOC))
00312 {
00313 if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass)
00314 {
00315
00316 if(is_array($tag))
00317 {
00318 $this->style[] = $tag;
00319 }
00320 $tag = array();
00321 }
00322 $ctag = $style_rec["tag"];
00323 $cclass = $style_rec["class"];
00324 $tag[] = $style_rec;
00325 }
00326 if(is_array($tag))
00327 {
00328 $this->style[] = $tag;
00329 }
00330 }
00331
00335 function writeCSSFile($a_target_file = "")
00336 {
00337 $style = $this->getStyle();
00338
00339 if ($a_target_file == "")
00340 {
00341 $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
00342 }
00343 else
00344 {
00345 $css_file_name = $a_target_file;
00346 }
00347 $css_file = fopen($css_file_name, "w");
00348
00349 foreach ($style as $tag)
00350 {
00351 fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["class"]."\n");
00352 fwrite ($css_file, "{\n");
00353
00354 foreach($tag as $par)
00355 {
00356 fwrite ($css_file, "\t".$par["parameter"].": ".$par["value"].";\n");
00357 }
00358 fwrite ($css_file, "}\n");
00359 fwrite ($css_file, "\n");
00360 }
00361 fclose($css_file);
00362 }
00363
00364
00370 function getContentStylePath($a_style_id)
00371 {
00372 global $ilias;
00373
00374 $rand = rand(1,999999);
00375
00376
00377 $fixed_style = $ilias->getSetting("fixed_content_style_id");
00378 if ($fixed_style > 0)
00379 {
00380 $a_style_id = $fixed_style;
00381 }
00382
00383
00384 if ($a_style_id <= 0)
00385 {
00386 $a_style_id = $ilias->getSetting("default_content_style_id");
00387 }
00388
00389 if ($a_style_id > 0)
00390 {
00391 return ilUtil::getWebspaceDir("output").
00392 "/css/style_".$a_style_id.".css?dummy=$rand";
00393 }
00394 else
00395 {
00396 if (defined("ILIAS_MODULE"))
00397 {
00398 return "../content/content.css";
00399 }
00400 else
00401 {
00402 return "./content/content.css";
00403 }
00404 }
00405 }
00406
00412 function getContentPrintStyle()
00413 {
00414 if (defined("ILIAS_MODULE"))
00415 {
00416 return "../content/print_content.css";
00417 }
00418 else
00419 {
00420 return "./content/print_content.css";
00421 }
00422 }
00423
00429 function getSyntaxStylePath()
00430 {
00431 if (defined("ILIAS_MODULE"))
00432 {
00433 return "../content/syntaxhighlight.css";
00434 }
00435 else
00436 {
00437 return "./content/syntaxhighlight.css";
00438 }
00439 }
00440
00441 function update()
00442 {
00443 parent::update();
00444 $this->read();
00445 $this->writeCSSFile();
00446 }
00447
00448 function updateStyleParameter($a_id, $a_value)
00449 {
00450 $q = "UPDATE style_parameter SET VALUE='".$a_value."' WHERE id = '".$a_id."'";
00451 $style_set = $this->ilias->db->query($q);
00452 }
00453
00457 function getStyle()
00458 {
00459 return $this->style;
00460 }
00461
00465 function setStyle($a_style)
00466 {
00467 $this->style = $a_style;
00468 }
00469
00470
00474 function getXML()
00475 {
00476 $xml.= "<StyleSheet>";
00477 $xml.= "<Title>".$this->getTitle()."</Title>";
00478 $xml.= "<Description>".$this->getDescription()."</Description>";
00479 foreach($this->style as $style)
00480 {
00481 $xml.= "<Style Tag=\"".$style[0]["tag"]."\" Class=\"".$style[0]["class"]."\">";
00482 foreach($style as $tag)
00483 {
00484 $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\"/>";
00485 }
00486 $xml.= "</Style>";
00487 }
00488 $xml.= "</StyleSheet>";
00489
00490 return $xml;
00491 }
00492
00493
00497 function exportXML($a_dir)
00498 {
00499 $file = $a_dir."/style.xml";
00500
00501
00502 if (!($fp = @fopen($file,"w")))
00503 {
00504 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
00505 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
00506 }
00507
00508
00509 chmod($file, 0770);
00510
00511
00512 fwrite($fp, $this->getXML());
00513
00514
00515 fclose($fp);
00516
00517 }
00518
00522 function createFromXMLFile($a_file)
00523 {
00524 parent::create();
00525 include_once("classes/class.ilStyleImportParser.php");
00526 $importParser = new ilStyleImportParser($a_file, $this);
00527 $importParser->startParsing();
00528
00529
00530 foreach ($this->style as $style)
00531 {
00532 foreach($style as $tag)
00533 {
00534 $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00535 "('".$this->getId()."','".$tag["tag"]."','".$tag["class"].
00536 "','".$tag["parameter"]."','".$tag["value"]."')";
00537 $this->ilias->db->query($q);
00538 }
00539 }
00540 $this->update();
00541 $this->read();
00542 $this->writeCSSFile();
00543 }
00544
00548 function getAvailableTags()
00549 {
00550 $tags = array("a.FootnoteLink", "a.FootnoteLink:hover", "a.IntLink", "a.IntLink:hover",
00551 "a.IntLink:visited", "a.IntLink:active",
00552 "a.ExtLink", "a.ExtLink:hover", "a.ExtLink:visited", "a.ExtLink:active",
00553 "div.Footnote", "div.LMNavigation", "div.Page", "div.PageTitle", "span.Comment",
00554 "span.Emph", "span.Quotation", "span.Strong",
00555 "td.Cell1", "td.Cell2", "td.Cell3", "td.Cell4",
00556 "p.Standard", "p.List", "p.Headline1", "p.Headline2", "p.Headline3",
00557 "p.Example", "p.Citation", "p.Mnemonic", "p.Additional", "p.Remark",
00558 "p.TableContent",
00559 "table.Media", "td.MediaCaption");
00560
00561 return $tags;
00562 }
00563
00564 function getAvailableParameters()
00565 {
00566 $pars = array(
00567 "font-family" => array(),
00568 "font-style" => array("italic", "oblique", "normal"),
00569 "font-variant" => array("small-caps", "normal"),
00570 "font-weight" => array("bold", "normal", "bolder", "lighter"),
00571 "font-stretch" => array("wider", "narrower", "condensed", "semi-condensed",
00572 "extra-condensed", "ultra-condensed", "expanded", "semi-expanded",
00573 "extra-expanded", "ultra-expanded", "normal"),
00574 "word-spacing" => array(),
00575 "letter-spacing" => array(),
00576 "text-decoration" => array("underline", "overline", "line-through", "blink", "none"),
00577 "text-transform" => array("capitalize", "uppercase", "lowercase", "none"),
00578 "color" => array(),
00579
00580 "text-indent" => array(),
00581 "line-height" => array(),
00582 "vertical-align" => array("top", "middle", "bottom", "baseline", "sub", "super",
00583 "text-top", "text-bottom"),
00584 "text-align" => array("left", "center", "right", "justify"),
00585 "white-space" => array("normal", "pre", "nowrap"),
00586
00587 "margin" => array(),
00588 "margin-top" => array(),
00589 "margin-bottom" => array(),
00590 "margin-left" => array(),
00591 "margin-right" => array(),
00592
00593 "padding" => array(),
00594 "padding-top" => array(),
00595 "padding-bottom" => array(),
00596 "padding-left" => array(),
00597 "padding-right" => array(),
00598
00599 "border-width" => array(),
00600 "border-width-top" => array(),
00601 "border-width-bottom" => array(),
00602 "border-width-left" => array(),
00603 "border-width-right" => array(),
00604
00605 "border-color" => array(),
00606 "border-top-color" => array(),
00607 "border-bottom-color" => array(),
00608 "border-left-color" => array(),
00609 "border-right-color" => array(),
00610
00611 "border-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00612 "groove", "ridge", "inset", "outset"),
00613 "border-top-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00614 "groove", "ridge", "inset", "outset"),
00615 "border-bottom-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00616 "groove", "ridge", "inset", "outset"),
00617 "border-left-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00618 "groove", "ridge", "inset", "outset"),
00619 "border-right-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00620 "groove", "ridge", "inset", "outset"),
00621
00622 "background-color" => array(),
00623 "background-image" => array(),
00624 "background-repeat" => array("repeat", "repeat-x", "repeat-y", "no-repeat"),
00625 "background-attachment" => array("fixed", "scroll"),
00626 "background-position" => array("top", "center", "middle", "bottom", "left", "right"),
00627
00628 "cursor" => array("auto", "default", "crosshair", "pointer", "move",
00629 "n-resize", "ne-resize", "e-resize", "se-resize", "s-resize", "sw-resize",
00630 "w-resize", "nw-resize", "text", "wait", "help"),
00631 "clear" => array ("non","left","right","both")
00632 );
00633
00634 return $pars;
00635 }
00636
00637 }
00638 ?>