ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilStyleDefinition.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
13require_once("./Services/Xml/classes/class.ilSaxParser.php");
15{
21
22
28
30
31
39 function ilStyleDefinition($a_template_id = "")
40 {
41 global $ilias;
42
43 if ($a_template_id == "")
44 {
45 // use function to get the current skin
46 $a_template_id = self::getCurrentSkin();
47 }
48
49 // remember the template id
50 $this->template_id = $a_template_id;
51
52 if ($a_template_id == "default")
53 {
54 parent::ilSaxParser("./templates/".$a_template_id."/template.xml");
55 }
56 else
57 {
58 parent::ilSaxParser("./Customizing/global/skin/".$a_template_id."/template.xml");
59 }
60 }
61
62
63 // PUBLIC METHODS
64
71 function getStyles()
72 {
73//echo ":".count($this->styles).":";
74 if (is_array($this->styles))
75 {
76 return $this->styles;
77 }
78 else
79 {
80 return array();
81 }
82 }
83
84 function getTemplateId()
85 {
86 return $this->template_id;
87 }
88
89
90 function getTemplateName()
91 {
92 return $this->template_name;
93 }
94
95
96 function getStyle($a_id)
97 {
98 return $this->styles[$a_id];
99 }
100
101
102 function getStyleName($a_id)
103 {
104 return $this->styles[$a_id]["name"];
105 }
106
107
108 function getImageDirectory($a_master_style, $a_substyle = "")
109 {
110 if ($a_substyle != $a_master_style && $a_substyle != "")
111 {
112 return $this->styles[$a_master_style]["substyle"][$a_substyle]["image_directory"];
113 }
114 return $this->styles[$a_master_style]["image_directory"];
115 }
116
117 function getSoundDirectory($a_id)
118 {
119 return $this->styles[$a_id]["sound_directory"];
120 }
121
122 public static function _getAllTemplates()
123 {
124 $skins = array();
125
126 $skins[] = array("id" => "default");
127 if ($dp = @opendir("./Customizing/global/skin"))
128 {
129 while (($file = readdir($dp)) != false)
130 {
131 //is the file a directory?
132 if (is_dir("./Customizing/global/skin/".$file) && $file != "." && $file != ".." && $file != "CVS"
133 && $file != ".svn")
134 {
135 if (is_file("./Customizing/global/skin/".$file."/template.xml"))
136 {
137 $skins[] = array(
138 "id" => $file
139 );
140 }
141 }
142 } // while
143 }
144 else
145 {
146 return $skins;
147 }
148
149 return $skins;
150
151 }
152
154 {
155 return self::_getAllTemplates();
156 }
157
158
159 // PRIVATE METHODS
160
167 function setHandlers($a_xml_parser)
168 {
169 xml_set_object($a_xml_parser,$this);
170 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
171 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
172 }
173
182 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
183 {
184 if (!isset($a_attribs["sound_directory"]))
185 {
186 $a_attribs["sound_directory"] = "";
187 }
188
189 if (!isset($a_attribs["browsers"]))
190 {
191 $a_attribs["browsers"] = "";
192 }
193
194 switch($a_name)
195 {
196 case "template" :
197 $this->template_name = $a_attribs["name"];
198 break;
199
200 case "style" :
201 $this->last_style_id = $a_attribs["id"];
202 $this->styles[$a_attribs["id"]] =
203 array( "id" => $a_attribs["id"],
204 "name" => $a_attribs["name"],
205 "css_file" => $a_attribs["id"].".css",
206 "image_directory" => $a_attribs["image_directory"],
207 "sound_directory" => $a_attribs["sound_directory"]
208 );
209 $browsers =
210 explode(",", $a_attribs["browsers"]);
211 foreach ($browsers as $val)
212 {
213 $this->styles[$a_attribs["id"]]["browsers"][] = trim($val);
214 }
215 break;
216
217 case "substyle":
218 $this->styles[$this->last_style_id]["substyle"][$a_attribs["id"]] =
219 array( "id" => $a_attribs["id"],
220 "name" => $a_attribs["name"],
221 "css_file" => $a_attribs["id"].".css",
222 "image_directory" => $a_attribs["image_directory"],
223 "sound_directory" => $a_attribs["sound_directory"]
224 );
225 break;
226 }
227 }
228
229
238 static function styleExists($skin, $style)
239 {
240 if ($skin == "default")
241 {
242 if (is_file("./templates/".$skin."/template.xml") &&
243 is_file("./templates/".$skin."/".$style.".css")
244 )
245 {
246 return true;
247 }
248 }
249 else
250 {
251 if (is_file("./Customizing/global/skin/".$skin."/template.xml") &&
252 is_file("./Customizing/global/skin/".$skin."/".$style.".css")
253 )
254 {
255 return true;
256 }
257 }
258 return false;
259 }
260
268 static function skinExists($skin)
269 {
270 if ($skin == "default")
271 {
272 if (is_file("./templates/".$skin."/template.xml"))
273 {
274 return true;
275 }
276 }
277 else
278 {
279 if (is_file("./Customizing/global/skin/".$skin."/template.xml"))
280 {
281 return true;
282 }
283 }
284 return false;
285 }
286
294 function handlerCharacterData($a_xml_parser,$a_data)
295 {
296 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
297 $a_data = preg_replace("/\n/","",$a_data);
298 $a_data = preg_replace("/\t+/","",$a_data);
299
300 if(!empty($a_data))
301 {
302 switch($this->current_tag)
303 {
304 default:
305 break;
306 }
307 }
308 }
309
317 function handlerEndTag($a_xml_parser,$a_name)
318 {
319 }
320
321
330 public static function getCurrentSkin()
331 {
335 global $ilias;
336
337 if(isset(self::$current_skin))
338 {
339 return self::$current_skin;
340 }
341
342 if(is_object($ilias))
343 {
344 return $ilias->account->skin;
345 }
346
347 return null;
348 }
349
358 public static function getCurrentStyle()
359 {
360 global $ilias, $tree, $styleDefinition, $tree;
361
362 if (isset(self::$current_style))
363 {
365 }
366
367 if(!is_object($ilias))
368 {
369 return null;
370 }
371
372 $cs = $ilias->account->prefs['style'];
373
374 if (is_object($styleDefinition))
375 {
376 // are there any substyles?
377 $styles = $styleDefinition->getStyles();
378 if (is_array($styles[$cs]["substyle"]))
379 {
380 // read assignments, if given
381 $assignmnts = self::getSystemStyleCategoryAssignments(self::getCurrentSkin(), $cs);
382 if (count($assignmnts) > 0)
383 {
384 $ref_ass = array();
385 foreach ($assignmnts as $a)
386 {
387 $ref_ass[$a["ref_id"]] = $a["substyle"];
388 }
389
390 // check whether any ref id assigns a new style
391 if (is_object($tree) && $_GET["ref_id"] > 0 &&
392 $tree->isInTree($_GET["ref_id"]))
393 {
394 $path = $tree->getPathId((int) $_GET["ref_id"]);
395 for ($i = count($path) - 1; $i >= 0; $i--)
396 {
397 if (isset($ref_ass[$path[$i]]))
398 {
399 self::$current_style = $ref_ass[$path[$i]];
401 }
402 }
403 }
404 }
405 }
406 }
407
408 if ($_GET["ref_id"] != "")
409 {
410 self::$current_style = $cs;
411 }
412
413 return $cs;
414 }
415
424 public static function getCurrentMasterStyle()
425 {
426 global $ilias;
427
428 if (isset(self::$current_master_style))
429 {
431 }
432
433 $cs = $ilias->account->prefs['style'];
434
435 self::$current_master_style = $cs;
436
437 return $cs;
438 }
439
440
446 public static function setCurrentSkin($a_skin)
447 {
448 global $styleDefinition;
449
450 if (is_object($styleDefinition)
451 and $styleDefinition->getTemplateId() != $a_skin)
452 {
453 $styleDefinition = new ilStyleDefinition($a_skin);
454 $styleDefinition->startParsing();
455 }
456
457 self::$current_skin = $a_skin;
458 }
459
460
466 public static function setCurrentStyle($a_style)
467 {
468 self::$current_style = $a_style;
469 }
470
477 public static function getAllSkinStyles()
478 {
479 global $styleDefinition;
480
481 $all_styles = array();
482
483 $templates = $styleDefinition->getAllTemplates();
484
485 foreach ($templates as $template)
486 {
487 // get styles definition for template
488 $styleDef = new ilStyleDefinition($template["id"]);
489 $styleDef->startParsing();
490 $styles = $styleDef->getStyles();
491
492 foreach ($styles as $style)
493 {
494 $num_users = ilObjUser::_getNumberOfUsersForStyle($template["id"], $style["id"]);
495
496 // default selection list
497 $all_styles[$template["id"].":".$style["id"]] =
498 array (
499 "title" => $styleDef->getTemplateName()." / ".$style["name"],
500 "id" => $template["id"].":".$style["id"],
501 "template_id" => $template["id"],
502 "style_id" => $style["id"],
503 "template_name" => $styleDef->getTemplateName(),
504 "substyle" => $style["substyle"],
505 "style_name" => $style["name"],
506 "users" => $num_users
507 );
508 }
509 }
510
511 return $all_styles;
512 }
513
521 static function getSystemStyleCategoryAssignments($a_skin_id, $a_style_id)
522 {
523 global $ilDB;
524
525 $assignmnts = array();
526 $set = $ilDB->query("SELECT substyle, category_ref_id FROM syst_style_cat ".
527 " WHERE skin_id = ".$ilDB->quote($a_skin_id, "text").
528 " AND style_id = ".$ilDB->quote($a_style_id, "text")
529 );
530 while ($rec = $ilDB->fetchAssoc($set))
531 {
532 $assignmnts[] = array("substyle" => $rec["substyle"],
533 "ref_id" => $rec["category_ref_id"]);
534 }
535 return $assignmnts;
536 }
537
544 function writeSystemStyleCategoryAssignment($a_skin_id, $a_style_id,
545 $a_substyle, $a_ref_id)
546 {
547 global $ilDB;
548
549 $ilDB->manipulate("INSERT INTO syst_style_cat ".
550 "(skin_id, style_id, substyle, category_ref_id) VALUES (".
551 $ilDB->quote($a_skin_id, "text").",".
552 $ilDB->quote($a_style_id, "text").",".
553 $ilDB->quote($a_substyle, "text").",".
554 $ilDB->quote($a_ref_id, "integer").
555 ")");
556 }
557
564 function deleteSystemStyleCategoryAssignment($a_skin_id, $a_style_id,
565 $a_substyle, $a_ref_id)
566 {
567 global $ilDB;
568
569 $ilDB->manipulate("DELETE FROM syst_style_cat WHERE ".
570 " skin_id = ".$ilDB->quote($a_skin_id, "text").
571 " AND style_id = ".$ilDB->quote($a_style_id, "text").
572 " AND substyle = ".$ilDB->quote($a_substyle, "text").
573 " AND category_ref_id = ".$ilDB->quote($a_ref_id, "integer"));
574 }
575
576}
577?>
print $file
$_GET["client_id"]
_getNumberOfUsersForStyle($a_skin, $a_style)
skins and styles
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
parses the template.xml that defines all styles of the current template
deleteSystemStyleCategoryAssignment($a_skin_id, $a_style_id, $a_substyle, $a_ref_id)
Delete category style assignment.
getStyles()
get translation type (sys, db or 0)s
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
start tag handler
static getSystemStyleCategoryAssignments($a_skin_id, $a_style_id)
Get all system style category assignments.
static getCurrentMasterStyle()
get the current style
static setCurrentStyle($a_style)
set a new current style
handlerCharacterData($a_xml_parser, $a_data)
end tag handler
static getAllSkinStyles()
Get all skins/styles.
writeSystemStyleCategoryAssignment($a_skin_id, $a_style_id, $a_substyle, $a_ref_id)
Write category assignment.
ilStyleDefinition($a_template_id="")
Constructor.
getImageDirectory($a_master_style, $a_substyle="")
setHandlers($a_xml_parser)
set event handler
static skinExists($skin)
Check wheter a skin exists.
handlerEndTag($a_xml_parser, $a_name)
end tag handler
static getCurrentStyle()
get the current style
static setCurrentSkin($a_skin)
set a new current skin
static styleExists($skin, $style)
Check wheter a style exists.
$path
Definition: index.php:22
global $ilDB