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 media 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 ilObjMedia::setRefId() not allowed.",$this->ilias->error_obj->FATAL);
00062 }
00063
00064 function getRefId()
00065 {
00066 $this->ilias->raiseError("Operation ilObjMedia::getRefId() not allowed.",$this->ilias->error_obj->FATAL);
00067 }
00068
00069 function putInTree()
00070 {
00071 $this->ilias->raiseError("Operation ilObjMedia::putInTree() not allowed.",$this->ilias->error_obj->FATAL);
00072 }
00073
00074 function createReference()
00075 {
00076 $this->ilias->raiseError("Operation ilObjMedia::createReference() not allowed.",$this->ilias->error_obj->FATAL);
00077 }
00078
00082 function assignMetaData(&$a_meta_data)
00083 {
00084 $this->meta_data =& $a_meta_data;
00085 }
00086
00090 function &getMetaData()
00091 {
00092 return $this->meta_data;
00093 }
00094
00095 function create()
00096 {
00097 parent::create();
00098
00099 $def = array(
00100 array("tag" => "div", "class" => "PageTitle", "parameter" => "margin-top" ,"value" => "5px"),
00101 array("tag" => "div", "class" => "PageTitle", "parameter" => "margin-bottom" ,"value" => "20px"),
00102 array("tag" => "div", "class" => "PageTitle", "parameter" => "font-size" ,"value" => "23px"),
00103 array("tag" => "div", "class" => "PageTitle", "parameter" => "font-weight" ,"value" => "bold"),
00104 array("tag" => "div", "class" => "PageTitle", "parameter" => "padding-bottom" ,"value" => "3px"),
00105 array("tag" => "div", "class" => "PageTitle", "parameter" => "border-bottom-width" ,"value" => "1px"),
00106 array("tag" => "div", "class" => "PageTitle", "parameter" => "border-bottom-style" ,"value" => "solid"),
00107 array("tag" => "div", "class" => "PageTitle", "parameter" => "border-color" ,"value" => "#000000"),
00108
00109 array("tag" => "span", "class" => "Strong", "parameter" => "font-weight" ,"value" => "bold"),
00110 array("tag" => "span", "class" => "Emph", "parameter" => "font-style" ,"value" => "italic"),
00111 array("tag" => "span", "class" => "Comment", "parameter" => "color" ,"value" => "green"),
00112 array("tag" => "span", "class" => "Quotation", "parameter" => "color" ,"value" => "brown"),
00113 array("tag" => "span", "class" => "Quotation", "parameter" => "font-style" ,"value" => "italic"),
00114
00115 array("tag" => "a", "class" => "FootnoteLink", "parameter" => "color" ,"value" => "blue"),
00116 array("tag" => "a", "class" => "FootnoteLink", "parameter" => "font-weight" ,"value" => "normal"),
00117 array("tag" => "a", "class" => "FootnoteLink:hover", "parameter" => "color" ,"value" => "#000000"),
00118 array("tag" => "div", "class" => "Footnote", "parameter" => "margin-top" ,"value" => "5px"),
00119 array("tag" => "div", "class" => "Footnote", "parameter" => "margin-bottom" ,"value" => "5px"),
00120 array("tag" => "div", "class" => "Footnote", "parameter" => "font-style" ,"value" => "italic"),
00121
00122 array("tag" => "a", "class" => "IntLink", "parameter" => "color" ,"value" => "blue"),
00123 array("tag" => "a", "class" => "IntLink:visited", "parameter" => "color" ,"value" => "blue"),
00124 array("tag" => "a", "class" => "IntLink", "parameter" => "font-weight" ,"value" => "normal"),
00125 array("tag" => "a", "class" => "IntLink", "parameter" => "text-decoration" ,"value" => "underline"),
00126 array("tag" => "a", "class" => "IntLink:hover", "parameter" => "color" ,"value" => "#000000"),
00127
00128 array("tag" => "a", "class" => "ExtLink", "parameter" => "color" ,"value" => "blue"),
00129 array("tag" => "a", "class" => "ExtLink:visited", "parameter" => "color" ,"value" => "blue"),
00130 array("tag" => "a", "class" => "ExtLink", "parameter" => "font-weight" ,"value" => "normal"),
00131 array("tag" => "a", "class" => "ExtLink", "parameter" => "text-decoration" ,"value" => "underline"),
00132 array("tag" => "a", "class" => "ExtLink:hover", "parameter" => "color" ,"value" => "#000000"),
00133
00134 array("tag" => "div", "class" => "LMNavigation", "parameter" => "background-color" ,"value" => "#EEEEEE"),
00135 array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-style" ,"value" => "outset"),
00136 array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-color" ,"value" => "#EEEEEE"),
00137 array("tag" => "div", "class" => "LMNavigation", "parameter" => "border-width" ,"value" => "1px"),
00138 array("tag" => "div", "class" => "Page", "parameter" => "background-color" ,"value" => "#EEEEEE"),
00139 array("tag" => "div", "class" => "Page", "parameter" => "padding" ,"value" => "0px"),
00140 array("tag" => "div", "class" => "Page", "parameter" => "margin" ,"value" => "0px"),
00141 array("tag" => "td", "class" => "Cell1", "parameter" => "background-color" ,"value" => "#FFCCCC"),
00142 array("tag" => "td", "class" => "Cell2", "parameter" => "background-color" ,"value" => "#CCCCFF"),
00143 array("tag" => "td", "class" => "Cell3", "parameter" => "background-color" ,"value" => "#CCFFCC"),
00144 array("tag" => "td", "class" => "Cell4", "parameter" => "background-color" ,"value" => "#FFFFCC"),
00145
00146 array("tag" => "p", "class" => "Standard", "parameter" => "margin-top" ,"value" => "10px"),
00147 array("tag" => "p", "class" => "Standard", "parameter" => "margin-bottom" ,"value" => "10px"),
00148
00149 array("tag" => "p", "class" => "List", "parameter" => "margin-top" ,"value" => "3px"),
00150 array("tag" => "p", "class" => "List", "parameter" => "margin-bottom" ,"value" => "3px"),
00151
00152 array("tag" => "p", "class" => "Headline1", "parameter" => "margin-top" ,"value" => "15px"),
00153 array("tag" => "p", "class" => "Headline1", "parameter" => "margin-bottom" ,"value" => "10px"),
00154 array("tag" => "p", "class" => "Headline1", "parameter" => "font-size" ,"value" => "22px"),
00155 array("tag" => "p", "class" => "Headline1", "parameter" => "font-weight" ,"value" => "bold"),
00156
00157 array("tag" => "p", "class" => "Headline2", "parameter" => "margin-top" ,"value" => "15px"),
00158 array("tag" => "p", "class" => "Headline2", "parameter" => "margin-bottom" ,"value" => "10px"),
00159 array("tag" => "p", "class" => "Headline2", "parameter" => "font-size" ,"value" => "18px"),
00160 array("tag" => "p", "class" => "Headline2", "parameter" => "font-weight" ,"value" => "bold"),
00161
00162 array("tag" => "p", "class" => "Headline3", "parameter" => "margin-top" ,"value" => "15px"),
00163 array("tag" => "p", "class" => "Headline3", "parameter" => "margin-bottom" ,"value" => "10px"),
00164 array("tag" => "p", "class" => "Headline3", "parameter" => "font-size" ,"value" => "14px"),
00165 array("tag" => "p", "class" => "Headline3", "parameter" => "font-weight" ,"value" => "bold"),
00166
00167 array("tag" => "p", "class" => "Example", "parameter" => "padding-left" ,"value" => "20px"),
00168 array("tag" => "p", "class" => "Example", "parameter" => "border-left" ,"value" => "3px"),
00169 array("tag" => "p", "class" => "Example", "parameter" => "border-left-style" ,"value" => "solid"),
00170 array("tag" => "p", "class" => "Example", "parameter" => "border-left-color" ,"value" => "blue"),
00171
00172 array("tag" => "p", "class" => "Citation", "parameter" => "color" ,"value" => "brown"),
00173 array("tag" => "p", "class" => "Citation", "parameter" => "font-style" ,"value" => "italic"),
00174
00175 array("tag" => "p", "class" => "Mnemonic", "parameter" => "margin-left" ,"value" => "20px"),
00176 array("tag" => "p", "class" => "Mnemonic", "parameter" => "margin-right" ,"value" => "20px"),
00177 array("tag" => "p", "class" => "Mnemonic", "parameter" => "color" ,"value" => "red"),
00178 array("tag" => "p", "class" => "Mnemonic", "parameter" => "padding" ,"value" => "10px"),
00179 array("tag" => "p", "class" => "Mnemonic", "parameter" => "border" ,"value" => "1px"),
00180 array("tag" => "p", "class" => "Mnemonic", "parameter" => "border-style" ,"value" => "solid"),
00181 array("tag" => "p", "class" => "Mnemonic", "parameter" => "border-color" ,"value" => "red"),
00182
00183 array("tag" => "p", "class" => "Additional", "parameter" => "padding" ,"value" => "10px"),
00184 array("tag" => "p", "class" => "Additional", "parameter" => "border" ,"value" => "1px"),
00185 array("tag" => "p", "class" => "Additional", "parameter" => "border-style" ,"value" => "solid"),
00186 array("tag" => "p", "class" => "Additional", "parameter" => "border-color" ,"value" => "blue"),
00187
00188 array("tag" => "p", "class" => "Remark", "parameter" => "padding" ,"value" => "10px"),
00189 array("tag" => "p", "class" => "Remark", "parameter" => "border" ,"value" => "1px"),
00190 array("tag" => "p", "class" => "Remark", "parameter" => "border-style" ,"value" => "solid"),
00191 array("tag" => "p", "class" => "Remark", "parameter" => "border-color" ,"value" => "#909090"),
00192 array("tag" => "p", "class" => "Remark", "parameter" => "background-color" ,"value" => "#D0D0D0"),
00193 array("tag" => "p", "class" => "Remark", "parameter" => "text-align" ,"value" => "right"),
00194
00195 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-left" ,"value" => "0px"),
00196 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-right" ,"value" => "0px"),
00197 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-top" ,"value" => "0px"),
00198 array("tag" => "p", "class" => "TableContent", "parameter" => "margin-bottom" ,"value" => "0px"),
00199 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-left" ,"value" => "0px"),
00200 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-right" ,"value" => "0px"),
00201 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-top" ,"value" => "0px"),
00202 array("tag" => "p", "class" => "TableContent", "parameter" => "padding-bottom" ,"value" => "0px"),
00203
00204 array("tag" => "table", "class" => "Media", "parameter" => "background-color" ,"value" => "#F5F5F5"),
00205 array("tag" => "table", "class" => "Media", "parameter" => "padding" ,"value" => "0px"),
00206 array("tag" => "table", "class" => "Media", "parameter" => "margin" ,"value" => "10px"),
00207
00208 array("tag" => "td", "class" => "MediaCaption", "parameter" => "padding" ,"value" => "5px")
00209 );
00210
00211
00212
00213 foreach ($def as $sty)
00214 {
00215 $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00216 "('".$this->getId()."','".$sty["tag"]."','".$sty["class"].
00217 "','".$sty["parameter"]."','".$sty["value"]."')";
00218 $this->ilias->db->query($q);
00219 }
00220
00221 $this->read();
00222 $this->writeCSSFile();
00223 }
00224
00225 function addParameter($a_tag, $a_par)
00226 {
00227 $avail_params = $this->getAvailableParameters();
00228 $tag = explode(".", $a_tag);
00229 $value = $avail_params[$a_par][0];
00230 $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00231 "('".$this->getId()."','".$tag[0]."','".$tag[1].
00232 "','".$a_par."','".$value."')";
00233 $this->ilias->db->query($q);
00234 $this->read();
00235 $this->writeCSSFile();
00236 }
00237
00238 function deleteParameter($a_id)
00239 {
00240 $q = "DELETE FROM style_parameter WHERE id = '".$a_id."'";
00241 $this->ilias->db->query($q);
00242 }
00243
00244 function read()
00245 {
00246 parent::read();
00247
00248 $q = "SELECT * FROM style_parameter WHERE style_id = '".$this->getId()."' ORDER BY tag, class ";
00249 $style_set = $this->ilias->db->query($q);
00250 $ctag = "";
00251 $cclass = "";
00252 $this->style = array();
00253 while($style_rec = $style_set->fetchRow(DB_FETCHMODE_ASSOC))
00254 {
00255 if ($style_rec["tag"] != $ctag || $style_rec["class"] != $cclass)
00256 {
00257
00258 if(is_array($tag))
00259 {
00260 $this->style[] = $tag;
00261 }
00262 $tag = array();
00263 }
00264 $ctag = $style_rec["tag"];
00265 $cclass = $style_rec["class"];
00266 $tag[] = $style_rec;
00267 }
00268 if(is_array($tag))
00269 {
00270 $this->style[] = $tag;
00271 }
00272 }
00273
00277 function writeCSSFile($a_target_file = "")
00278 {
00279 $style = $this->getStyle();
00280
00281 if ($a_target_file == "")
00282 {
00283 $css_file_name = ilUtil::getWebspaceDir()."/css/style_".$this->getId().".css";
00284 }
00285 else
00286 {
00287 $css_file_name = $a_target_file;
00288 }
00289 $css_file = fopen($css_file_name, "w");
00290
00291 foreach ($style as $tag)
00292 {
00293 fwrite ($css_file, $tag[0]["tag"].".ilc_".$tag[0]["class"]."\n");
00294 fwrite ($css_file, "{\n");
00295
00296 foreach($tag as $par)
00297 {
00298 fwrite ($css_file, "\t".$par["parameter"].": ".$par["value"].";\n");
00299 }
00300 fwrite ($css_file, "}\n");
00301 fwrite ($css_file, "\n");
00302 }
00303 fclose($css_file);
00304 }
00305
00306
00312 function getContentStylePath($a_style_id)
00313 {
00314 if ($a_style_id > 0)
00315 {
00316 $rand = rand(1,999999);
00317 return ilUtil::getWebspaceDir("output").
00318 "/css/style_".$a_style_id.".css?dummy=$rand";
00319 }
00320 else
00321 {
00322 return "../content/content.css";
00323 }
00324 }
00325
00331 function getContentPrintStyle()
00332 {
00333 return "../content/print_content.css";
00334 }
00335
00341 function getSyntaxStylePath()
00342 {
00343 return "../content/syntaxhighlight.css";
00344 }
00345
00346 function update()
00347 {
00348 parent::update();
00349 $this->read();
00350 $this->writeCSSFile();
00351 }
00352
00353 function updateStyleParameter($a_id, $a_value)
00354 {
00355 $q = "UPDATE style_parameter SET VALUE='".$a_value."' WHERE id = '".$a_id."'";
00356 $style_set = $this->ilias->db->query($q);
00357 }
00358
00362 function getStyle()
00363 {
00364 return $this->style;
00365 }
00366
00370 function setStyle($a_style)
00371 {
00372 $this->style = $a_style;
00373 }
00374
00375
00379 function getXML()
00380 {
00381 $xml.= "<StyleSheet>";
00382 $xml.= "<Title>".$this->getTitle()."</Title>";
00383 $xml.= "<Description>".$this->getDescription()."</Description>";
00384 foreach($this->style as $style)
00385 {
00386 $xml.= "<Style Tag=\"".$style[0]["tag"]."\" Class=\"".$style[0]["class"]."\">";
00387 foreach($style as $tag)
00388 {
00389 $xml.="<StyleParameter Name=\"".$tag["parameter"]."\" Value=\"".$tag["value"]."\"/>";
00390 }
00391 $xml.= "</Style>";
00392 }
00393 $xml.= "</StyleSheet>";
00394
00395 return $xml;
00396 }
00397
00398
00402 function exportXML($a_dir)
00403 {
00404 $file = $a_dir."/style.xml";
00405
00406
00407 if (!($fp = @fopen($file,"w")))
00408 {
00409 die ("<b>Error</b>: Could not open \"".$file."\" for writing".
00410 " in <b>".__FILE__."</b> on line <b>".__LINE__."</b><br />");
00411 }
00412
00413
00414 chmod($file, 0770);
00415
00416
00417 fwrite($fp, $this->getXML());
00418
00419
00420 fclose($fp);
00421
00422 }
00423
00427 function createFromXMLFile($a_file)
00428 {
00429 parent::create();
00430 include_once("classes/class.ilStyleImportParser.php");
00431 $importParser = new ilStyleImportParser($a_file, $this);
00432 $importParser->startParsing();
00433
00434
00435 foreach ($this->style as $style)
00436 {
00437 foreach($style as $tag)
00438 {
00439 $q = "INSERT INTO style_parameter (style_id, tag, class, parameter, value) VALUES ".
00440 "('".$this->getId()."','".$tag["tag"]."','".$tag["class"].
00441 "','".$tag["parameter"]."','".$tag["value"]."')";
00442 $this->ilias->db->query($q);
00443 }
00444 }
00445 $this->update();
00446 $this->read();
00447 $this->writeCSSFile();
00448 }
00449
00453 function getAvailableTags()
00454 {
00455 $tags = array("a.FootnoteLink", "a.FootnoteLink:hover", "a.IntLink", "a.IntLink:hover",
00456 "a.IntLink:visited", "a.IntLink:active",
00457 "a.ExtLink", "a.ExtLink:hover", "a.ExtLink:visited", "a.ExtLink:active",
00458 "div.Footnote", "div.LMNavigation", "div.Page", "div.PageTitle", "span.Comment",
00459 "span.Emph", "span.Quotation", "span.Strong",
00460 "td.Cell1", "td.Cell2", "td.Cell3", "td.Cell4",
00461 "p.Standard", "p.List", "p.Headline1", "p.Headline2", "p.Headline3",
00462 "p.Example", "p.Citation", "p.Mnemonic", "p.Additional", "p.Remark",
00463 "p.TableContent",
00464 "table.Media", "td.MediaCaption");
00465
00466 return $tags;
00467 }
00468
00469 function getAvailableParameters()
00470 {
00471 $pars = array(
00472 "font-family" => array(),
00473 "font-style" => array("italic", "oblique", "normal"),
00474 "font-variant" => array("small-caps", "normal"),
00475 "font-weight" => array("bold", "normal", "bolder", "lighter"),
00476 "font-stretch" => array("wider", "narrower", "condensed", "semi-condensed",
00477 "extra-condensed", "ultra-condensed", "expanded", "semi-expanded",
00478 "extra-expanded", "ultra-expanded", "normal"),
00479 "word-spacing" => array(),
00480 "letter-spacing" => array(),
00481 "text-decoration" => array("underline", "overline", "line-through", "blink", "none"),
00482 "text-transform" => array("capitalize", "uppercase", "lowercase", "none"),
00483 "color" => array(),
00484
00485 "text-indent" => array(),
00486 "line-height" => array(),
00487 "vertical-align" => array("top", "middle", "bottom", "baseline", "sub", "super",
00488 "text-top", "text-bottom"),
00489 "text-align" => array("left", "center", "right", "justify"),
00490 "white-space" => array("normal", "pre", "nowrap"),
00491
00492 "margin" => array(),
00493 "margin-top" => array(),
00494 "margin-bottom" => array(),
00495 "margin-left" => array(),
00496 "margin-right" => array(),
00497
00498 "padding" => array(),
00499 "padding-top" => array(),
00500 "padding-bottom" => array(),
00501 "padding-left" => array(),
00502 "padding-right" => array(),
00503
00504 "border-width" => array(),
00505 "border-width-top" => array(),
00506 "border-width-bottom" => array(),
00507 "border-width-left" => array(),
00508 "border-width-right" => array(),
00509
00510 "border-color" => array(),
00511 "border-top-color" => array(),
00512 "border-bottom-color" => array(),
00513 "border-left-color" => array(),
00514 "border-right-color" => array(),
00515
00516 "border-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00517 "groove", "ridge", "inset", "outset"),
00518 "border-top-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00519 "groove", "ridge", "inset", "outset"),
00520 "border-bottom-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00521 "groove", "ridge", "inset", "outset"),
00522 "border-left-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00523 "groove", "ridge", "inset", "outset"),
00524 "border-right-style" => array("none", "hidden", "dotted", "dashed", "solid", "double",
00525 "groove", "ridge", "inset", "outset"),
00526
00527 "background-color" => array(),
00528 "background-image" => array(),
00529 "background-repeat" => array("repeat", "repeat-x", "repeat-y", "no-repeat"),
00530 "background-attachment" => array("fixed", "scroll"),
00531 "background-position" => array("top", "center", "middle", "bottom", "left", "right"),
00532
00533 "cursor" => array("auto", "default", "crosshair", "pointer", "move",
00534 "n-resize", "ne-resize", "e-resize", "se-resize", "s-resize", "sw-resize",
00535 "w-resize", "nw-resize", "text", "wait", "help"),
00536 );
00537
00538 return $pars;
00539 }
00540
00541 }
00542 ?>