ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
96 {
97 return $this->template_version;
98 }
99
100 function getStyle($a_id)
101 {
102 return $this->styles[$a_id];
103 }
104
105
106 function getStyleName($a_id)
107 {
108 return $this->styles[$a_id]["name"];
109 }
110
111 function getImageDirectory($a_master_style, $a_substyle = "")
112 {
113 if ($a_substyle != $a_master_style && $a_substyle != "")
114 {
115 return $this->styles[$a_master_style]["substyle"][$a_substyle]["image_directory"];
116 }
117 return $this->styles[$a_master_style]["image_directory"];
118 }
119
120 function getSoundDirectory($a_id)
121 {
122 return $this->styles[$a_id]["sound_directory"];
123 }
124
125 public static function _getAllTemplates()
126 {
127 $skins = array();
128
129 $skins[] = array("id" => "default");
130 if ($dp = @opendir("./Customizing/global/skin"))
131 {
132 while (($file = readdir($dp)) != false)
133 {
134 //is the file a directory?
135 if (is_dir("./Customizing/global/skin/".$file) && $file != "." && $file != ".." && $file != "CVS"
136 && $file != ".svn")
137 {
138 if (is_file("./Customizing/global/skin/".$file."/template.xml"))
139 {
140 $skins[] = array(
141 "id" => $file
142 );
143 }
144 }
145 } // while
146 }
147 else
148 {
149 return $skins;
150 }
151
152 return $skins;
153
154 }
155
157 {
158 return self::_getAllTemplates();
159 }
160
161
162 // PRIVATE METHODS
163
170 function setHandlers($a_xml_parser)
171 {
172 xml_set_object($a_xml_parser,$this);
173 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
174 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
175 }
176
185 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
186 {
187 if (!isset($a_attribs["sound_directory"]))
188 {
189 $a_attribs["sound_directory"] = "";
190 }
191
192 if (!isset($a_attribs["browsers"]))
193 {
194 $a_attribs["browsers"] = "";
195 }
196
197 switch($a_name)
198 {
199 case "template" :
200 $this->template_name = $a_attribs["name"];
201 $this->template_version = $a_attribs["version"];
202 break;
203
204 case "style" :
205 $this->last_style_id = $a_attribs["id"];
206 $this->styles[$a_attribs["id"]] =
207 array( "id" => $a_attribs["id"],
208 "name" => $a_attribs["name"],
209 "css_file" => $a_attribs["id"].".css",
210 "image_directory" => $a_attribs["image_directory"],
211 "sound_directory" => $a_attribs["sound_directory"]
212 );
213 $browsers =
214 explode(",", $a_attribs["browsers"]);
215 foreach ($browsers as $val)
216 {
217 $this->styles[$a_attribs["id"]]["browsers"][] = trim($val);
218 }
219 break;
220
221 case "substyle":
222 $this->styles[$this->last_style_id]["substyle"][$a_attribs["id"]] =
223 array( "id" => $a_attribs["id"],
224 "name" => $a_attribs["name"],
225 "css_file" => $a_attribs["id"].".css",
226 "image_directory" => $a_attribs["image_directory"],
227 "sound_directory" => $a_attribs["sound_directory"]
228 );
229 break;
230 }
231 }
232
233
242 static function styleExists($skin, $style)
243 {
244 if ($skin == "default")
245 {
246 if (is_file("./templates/".$skin."/template.xml") &&
247 is_file("./templates/".$skin."/".$style.".css")
248 )
249 {
250 return true;
251 }
252 }
253 else
254 {
255 if (is_file("./Customizing/global/skin/".$skin."/template.xml") &&
256 is_file("./Customizing/global/skin/".$skin."/".$style.".css")
257 )
258 {
259 return true;
260 }
261 }
262 return false;
263 }
264
272 static function skinExists($skin)
273 {
274 if ($skin == "default")
275 {
276 if (is_file("./templates/".$skin."/template.xml"))
277 {
278 return true;
279 }
280 }
281 else
282 {
283 if (is_file("./Customizing/global/skin/".$skin."/template.xml"))
284 {
285 return true;
286 }
287 }
288 return false;
289 }
290
298 function handlerCharacterData($a_xml_parser,$a_data)
299 {
300 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
301 $a_data = preg_replace("/\n/","",$a_data);
302 $a_data = preg_replace("/\t+/","",$a_data);
303
304 if(!empty($a_data))
305 {
306 switch($this->current_tag)
307 {
308 default:
309 break;
310 }
311 }
312 }
313
321 function handlerEndTag($a_xml_parser,$a_name)
322 {
323 }
324
325
334 public static function getCurrentSkin()
335 {
339 global $ilias;
340
341 if(isset(self::$current_skin))
342 {
343 return self::$current_skin;
344 }
345
346 if(is_object($ilias))
347 {
348 return $ilias->account->skin;
349 }
350
351 return null;
352 }
353
362 public static function getCurrentStyle()
363 {
364 global $ilias, $tree, $styleDefinition, $tree;
365
366 if (isset(self::$current_style))
367 {
369 }
370
371 if(!is_object($ilias))
372 {
373 return null;
374 }
375
376 $cs = $ilias->account->prefs['style'];
377
378 if (is_object($styleDefinition))
379 {
380 // are there any substyles?
381 $styles = $styleDefinition->getStyles();
382 if (is_array($styles[$cs]["substyle"]))
383 {
384 // read assignments, if given
385 $assignmnts = self::getSystemStyleCategoryAssignments(self::getCurrentSkin(), $cs);
386 if (count($assignmnts) > 0)
387 {
388 $ref_ass = array();
389 foreach ($assignmnts as $a)
390 {
391 $ref_ass[$a["ref_id"]] = $a["substyle"];
392 }
393
394 // check whether any ref id assigns a new style
395 if (is_object($tree) && $_GET["ref_id"] > 0 &&
396 $tree->isInTree($_GET["ref_id"]))
397 {
398 $path = $tree->getPathId((int) $_GET["ref_id"]);
399 for ($i = count($path) - 1; $i >= 0; $i--)
400 {
401 if (isset($ref_ass[$path[$i]]))
402 {
403 self::$current_style = $ref_ass[$path[$i]];
405 }
406 }
407 }
408 }
409 }
410 }
411
412 if ($_GET["ref_id"] != "")
413 {
414 self::$current_style = $cs;
415 }
416
417 return $cs;
418 }
419
428 public static function getCurrentMasterStyle()
429 {
430 global $ilias;
431
432 if (isset(self::$current_master_style))
433 {
435 }
436
437 $cs = $ilias->account->prefs['style'];
438
439 self::$current_master_style = $cs;
440
441 return $cs;
442 }
443
449 public static function getCurrentSkinVersion()
450 {
452 global $styleDefinition;
453
454 self::getCurrentSkin();
455
456 $skin_version = '';
457 if (is_object($styleDefinition))
458 {
459 $version = $styleDefinition->getTemplateVersion();
460 if($version != '$Id$') {
461 $skin_version = $version;
462 }
463 }
464
465 return $skin_version;
466 }
467
468
474 public static function setCurrentSkin($a_skin)
475 {
476 global $styleDefinition;
477
478 if (is_object($styleDefinition)
479 and $styleDefinition->getTemplateId() != $a_skin)
480 {
481 $styleDefinition = new ilStyleDefinition($a_skin);
482 $styleDefinition->startParsing();
483 }
484
485 self::$current_skin = $a_skin;
486 }
487
488
494 public static function setCurrentStyle($a_style)
495 {
496 self::$current_style = $a_style;
497 }
498
505 public static function getAllSkinStyles()
506 {
507 global $styleDefinition;
508
509 $all_styles = array();
510
511 $templates = $styleDefinition->getAllTemplates();
512
513 foreach ($templates as $template)
514 {
515 // get styles definition for template
516 $styleDef = new ilStyleDefinition($template["id"]);
517 $styleDef->startParsing();
518 $styles = $styleDef->getStyles();
519
520 foreach ($styles as $style)
521 {
522 $num_users = ilObjUser::_getNumberOfUsersForStyle($template["id"], $style["id"]);
523
524 // default selection list
525 $all_styles[$template["id"].":".$style["id"]] =
526 array (
527 "title" => $styleDef->getTemplateName()." / ".$style["name"],
528 "id" => $template["id"].":".$style["id"],
529 "template_id" => $template["id"],
530 "style_id" => $style["id"],
531 "template_name" => $styleDef->getTemplateName(),
532 "substyle" => $style["substyle"],
533 "style_name" => $style["name"],
534 "users" => $num_users
535 );
536 }
537 }
538
539 return $all_styles;
540 }
541
549 static function getSystemStyleCategoryAssignments($a_skin_id, $a_style_id)
550 {
551 global $ilDB;
552
553 $assignmnts = array();
554 $set = $ilDB->query("SELECT substyle, category_ref_id FROM syst_style_cat ".
555 " WHERE skin_id = ".$ilDB->quote($a_skin_id, "text").
556 " AND style_id = ".$ilDB->quote($a_style_id, "text")
557 );
558 while ($rec = $ilDB->fetchAssoc($set))
559 {
560 $assignmnts[] = array("substyle" => $rec["substyle"],
561 "ref_id" => $rec["category_ref_id"]);
562 }
563 return $assignmnts;
564 }
565
572 function writeSystemStyleCategoryAssignment($a_skin_id, $a_style_id,
573 $a_substyle, $a_ref_id)
574 {
575 global $ilDB;
576
577 $ilDB->manipulate("INSERT INTO syst_style_cat ".
578 "(skin_id, style_id, substyle, category_ref_id) VALUES (".
579 $ilDB->quote($a_skin_id, "text").",".
580 $ilDB->quote($a_style_id, "text").",".
581 $ilDB->quote($a_substyle, "text").",".
582 $ilDB->quote($a_ref_id, "integer").
583 ")");
584 }
585
592 function deleteSystemStyleCategoryAssignment($a_skin_id, $a_style_id,
593 $a_substyle, $a_ref_id)
594 {
595 global $ilDB;
596
597 $ilDB->manipulate("DELETE FROM syst_style_cat WHERE ".
598 " skin_id = ".$ilDB->quote($a_skin_id, "text").
599 " AND style_id = ".$ilDB->quote($a_style_id, "text").
600 " AND substyle = ".$ilDB->quote($a_substyle, "text").
601 " AND category_ref_id = ".$ilDB->quote($a_ref_id, "integer"));
602 }
603
604}
605?>
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.
$style
Definition: example_012.php:70
$template_id
Definition: example_062.php:89
$path
Definition: index.php:22
global $ilDB