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 $q = "DELETE FROM style_parameter WHERE style_id = ".$ilDB->quote($this->getId());
00269 $ilDB->query($q);
00270
00271
00272 $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
00273 if (is_file($css_file_name))
00274 {
00275 unlink($css_file_name);
00276 }
00277
00278
00279 include_once("content/classes/class.ilObjContentObject.php");
00280 ilObjContentObject::_deleteStyleAssignments($this->getId());
00281 }
00282
00283
00287 function read()
00288 {
00289 parent::read();
00290
00291 $q = "SELECT * FROM style_parameter WHERE style_id = '".$this->getId()."' ORDER BY tag, class ";
00292 $style_set = $this->ilias->db->query($q);
00293 $ctag = "";
00294 $cclass = "";
00295 $this->style = array();
00296 while($style_rec = $style_set->fetchRow(DB_FETCHMODE_ASSOC))
00297 {
00298 if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass)
00299 {
00300
00301 if(is_array($tag))
00302 {
00303 $this->style[] = $tag;
00304 }
00305 $tag = array();
00306 }
00307 $ctag = $style_rec["tag"];
00308 $cclass = $style_rec["class"];
00309 $tag[] = $style_rec;
00310 }
00311 if(is_array($tag))
00312 {
00313 $this->style[] = $tag;
00314 }
00315 }
00316
00320 function writeCSSFile($a_target_file = "")
00321 {
00322 $style = $this->getStyle();
00323
00324 if ($a_target_file == "")
00325 {
00326 $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
00327 }
00328 else
00329 {
00330 $css_file_name = $a_target_file;
00331 }
00332 $css_file = fopen($css_file_name, "w");
00333
00334 foreach ($style as $tag)
00335 {
00336 fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["class"]."\n");
00337 fwrite ($css_file, "{\n");
00338
00339 foreach($tag as $par)
00340 {
00341 fwrite ($css_file, "\t".$par["parameter"].": ".$par["value"].";\n");
00342 }
00343 fwrite ($css_file, "}\n");
00344 fwrite ($css_file, "\n");
00345 }
00346 fclose($css_file);
00347 }
00348
00349
00355 function getContentStylePath($a_style_id)
00356 {
00357 global $ilias;
00358
00359 $rand = rand(1,999999);
00360
00361
00362 $fixed_style = $ilias->getSetting("fixed_content_style_id");
00363 if ($fixed_style > 0)
00364 {
00365 $a_style_id = $fixed_style;
00366 }
00367
00368
00369 if ($a_style_id <= 0)
00370 {
00371 $a_style_id = $ilias->getSetting("default_content_style_id");
00372 }
00373
00374 if ($a_style_id > 0)
00375 {
00376 return ilUtil::getWebspaceDir("output").
00377 "/css/style_".$a_style_id.".css?dummy=$rand";
00378 }
00379 else
00380 {
00381 return "../content/content.css";
00382 }
00383 }
00384
00390 function getContentPrintStyle()
00391 {
00392 return "../content/print_content.css";
00393 }
00394
00400 function getSyntaxStylePath()
00401 {
00402 return "../content/syntaxhighlight.css";
00403 }
00404
00405 function update()
00406 {
00407 parent::update();
00408 $this->read();
00409 $this->writeCSSFile();
00410 }
00411
00412 function updateStyleParameter($a_id, $a_value)
00413 {
00414 $q = "UPDATE style_parameter SET VALUE='".$a_value."' WHERE id = '".$a_id."'";
00415 $style_set = $this->ilias->db->query($q);
00416 }
00417
00421 function getStyle()
00422 {
00423 return $this->style;
00424 }
00425
00429 function setStyle($a_style)
00430 {
00431 $this->style = $a_style;
00432 }
00433
00434
00438 function getXML()
00439 {
00440 $xml.= "<StyleSheet>";
00441 $xml.= "<Title>".$this->getTitle()."</Title>";
00442 $xml.= "<Description>".$this->getDescription()."</Description>";
00443 foreach($this->style as $style)
00444 {
00445 $xml.= "<Style Tag=\"".$style[0]["tag"]."\" Class=\"".$style[0]["class"]."\">";
00446 foreach($style as $tag)
00447 {
00448 $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\"/>";
00449 }
00450 $xml.= "</Style>";
00451 }
00452 $xml.= "</StyleSheet>";
00453
00454 return $xml;
00455 }
00456
00457
00461 function exportXML($a_dir)
00462 {
00463 $file = $a_dir."/style.xml";
00464
00465
00466 if (!($fp = @fopen($file,"w")))
00467 {
00468 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
00469 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
00470 }
00471
00472
00473 chmod($file, 0770);
00474
00475
00476 fwrite($fp, $this->getXML());
00477
00478
00479 fclose($fp);
00480
00481 }
00482
00486 function createFromXMLFile($a_file)
00487 {
00488 parent::create();
00489 include_once("classes/class.ilStyleImportParser.php");
00490 $importParser = new ilStyleImportParser($a_file, $this);
00491 $importParser->startParsing();
00492
00493
00494 foreach ($this->style as $style)
00495 {
00496 foreach($style as $tag)
00497 {
00498 $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00499 "('".$this->getId()."','".$tag["tag"]."','".$tag["class"].
00500 "','".$tag["parameter"]."','".$tag["value"]."')";
00501 $this->ilias->db->query($q);
00502 }
00503 }
00504 $this->update();
00505 $this->read();
00506 $this->writeCSSFile();
00507 }
00508
00512 function getAvailableTags()
00513 {
00514 $tags = array("a.FootnoteLink", "a.FootnoteLink:hover", "a.IntLink", "a.IntLink:hover",
00515 "a.IntLink:visited", "a.IntLink:active",
00516 "a.ExtLink", "a.ExtLink:hover", "a.ExtLink:visited", "a.ExtLink:active",
00517 "div.Footnote", "div.LMNavigation", "div.Page", "div.PageTitle", "span.Comment",
00518 "span.Emph", "span.Quotation", "span.Strong",
00519 "td.Cell1", "td.Cell2", "td.Cell3", "td.Cell4",
00520 "p.Standard", "p.List", "p.Headline1", "p.Headline2", "p.Headline3",
00521 "p.Example", "p.Citation", "p.Mnemonic", "p.Additional", "p.Remark",
00522 "p.TableContent",
00523 "table.Media", "td.MediaCaption");
00524
00525 return $tags;
00526 }
00527
00528 function getAvailableParameters()
00529 {
00530 $pars = array(
00531 "font-family" => array(),
00532 "font-style" => array("italic", "oblique", "normal"),
00533 "font-variant" => array("small-caps", "normal"),
00534 "font-weight" => array("bold", "normal", "bolder", "lighter"),
00535 "font-stretch" => array("wider", "narrower", "condensed", "semi-condensed",
00536 "extra-condensed", "ultra-condensed", "expanded", "semi-expanded",
00537 "extra-expanded", "ultra-expanded", "normal"),
00538 "word-spacing" => array(),
00539 "letter-spacing" => array(),
00540 "text-decoration" => array("underline", "overline", "line-through", "blink", "none"),
00541 "text-transform" => array("capitalize", "uppercase", "lowercase", "none"),
00542 "color" => array(),
00543
00544 "text-indent" => array(),
00545 "line-height" => array(),
00546 "vertical-align" => array("top", "middle", "bottom", "baseline", "sub", "super",
00547 "text-top", "text-bottom"),
00548 "text-align" => array("left", "center", "right", "justify"),
00549 "white-space" => array("normal", "pre", "nowrap"),
00550
00551 "margin" => array(),
00552 "margin-top" => array(),
00553 "margin-bottom" => array(),
00554 "margin-left" => array(),
00555 "margin-right" => array(),
00556
00557 "padding" => array(),
00558 "padding-top" => array(),
00559 "padding-bottom" => array(),
00560 "padding-left" => array(),
00561 "padding-right" => array(),
00562
00563 "border-width" => array(),
00564 "border-width-top" => array(),
00565 "border-width-bottom" => array(),
00566 "border-width-left" => array(),
00567 "border-width-right" => array(),
00568
00569 "border-color" => array(),
00570 "border-top-color" => array(),
00571 "border-bottom-color" => array(),
00572 "border-left-color" => array(),
00573 "border-right-color" => array(),
00574
00575 "border-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00576 "groove", "ridge", "inset", "outset"),
00577 "border-top-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00578 "groove", "ridge", "inset", "outset"),
00579 "border-bottom-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00580 "groove", "ridge", "inset", "outset"),
00581 "border-left-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00582 "groove", "ridge", "inset", "outset"),
00583 "border-right-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00584 "groove", "ridge", "inset", "outset"),
00585
00586 "background-color" => array(),
00587 "background-image" => array(),
00588 "background-repeat" => array("repeat", "repeat-x", "repeat-y", "no-repeat"),
00589 "background-attachment" => array("fixed", "scroll"),
00590 "background-position" => array("top", "center", "middle", "bottom", "left", "right"),
00591
00592 "cursor" => array("auto", "default", "crosshair", "pointer", "move",
00593 "n-resize", "ne-resize", "e-resize", "se-resize", "s-resize", "sw-resize",
00594 "w-resize", "nw-resize", "text", "wait", "help"),
00595 "clear" => array ("non","left","right","both")
00596 );
00597
00598 return $pars;
00599 }
00600
00601 }
00602 ?>