ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilStyleDefinition.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
33 require_once("./classes/class.ilSaxParser.php");
34 
36 {
41  static $current_skin;
42 
43 
49 
50 
58  function ilStyleDefinition($a_template_id = "")
59  {
60  global $ilias;
61 
62  if ($a_template_id == "")
63  {
64  // use function to get the current skin
65  $a_template_id = self::getCurrentSkin();
66  }
67 
68  // remember the template id
69  $this->template_id = $a_template_id;
70 
71  if ($a_template_id == "default")
72  {
73  parent::ilSaxParser("./templates/".$a_template_id."/template.xml");
74  }
75  else
76  {
77  parent::ilSaxParser("./Customizing/global/skin/".$a_template_id."/template.xml");
78  }
79  }
80 
81 
82  // PUBLIC METHODS
83 
90  function getStyles()
91  {
92 //echo ":".count($this->styles).":";
93  if (is_array($this->styles))
94  {
95  return $this->styles;
96  }
97  else
98  {
99  return array();
100  }
101  }
102 
103  function getTemplateId()
104  {
105  return $this->template_id;
106  }
107 
108 
109  function getTemplateName()
110  {
111  return $this->template_name;
112  }
113 
114 
115  function getStyle($a_id)
116  {
117  return $this->styles[$a_id];
118  }
119 
120 
121  function getStyleName($a_id)
122  {
123  return $this->styles[$a_id]["name"];
124  }
125 
126 
127  function getImageDirectory($a_id)
128  {
129  return $this->styles[$a_id]["image_directory"];
130  }
131 
132  function getSoundDirectory($a_id)
133  {
134  return $this->styles[$a_id]["sound_directory"];
135  }
136 
137  public static function _getAllTemplates()
138  {
139  $skins = array();
140 
141  $skins[] = array("id" => "default");
142  if ($dp = @opendir("./Customizing/global/skin"))
143  {
144  while (($file = readdir($dp)) != false)
145  {
146  //is the file a directory?
147  if (is_dir("./Customizing/global/skin/".$file) && $file != "." && $file != ".." && $file != "CVS"
148  && $file != ".svn")
149  {
150  if (is_file("./Customizing/global/skin/".$file."/template.xml"))
151  {
152  $skins[] = array(
153  "id" => $file
154  );
155  }
156  }
157  } // while
158  }
159  else
160  {
161  return $skins;
162  }
163 
164  return $skins;
165 
166  }
167 
168  function getAllTemplates()
169  {
170  return self::_getAllTemplates();
171  }
172 
173 
174  // PRIVATE METHODS
175 
182  function setHandlers($a_xml_parser)
183  {
184  xml_set_object($a_xml_parser,$this);
185  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
186  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
187  }
188 
197  function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
198  {
199  if (!isset($a_attribs["sound_directory"]))
200  {
201  $a_attribs["sound_directory"] = "";
202  }
203 
204  if (!isset($a_attribs["browsers"]))
205  {
206  $a_attribs["browsers"] = "";
207  }
208 
209  switch($a_name)
210  {
211  case "template" :
212  $this->template_name = $a_attribs["name"];
213  break;
214 
215  case "style" :
216  $this->styles[$a_attribs["id"]] =
217  array( "id" => $a_attribs["id"],
218  "name" => $a_attribs["name"],
219  "css_file" => $a_attribs["id"].".css",
220  "image_directory" => $a_attribs["image_directory"],
221  "sound_directory" => $a_attribs["sound_directory"]
222  );
223  $browsers =
224  explode(",", $a_attribs["browsers"]);
225  foreach ($browsers as $val)
226  {
227  $this->styles[$a_attribs["id"]]["browsers"][] = trim($val);
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  {
336  global $ilias;
337 
338  return isset(self::$current_skin) ? self::$current_skin :
339  $ilias->account->skin;
340  }
341 
350  public static function getCurrentStyle()
351  {
352  global $ilias;
353 
354  return isset(self::$current_style) ? self::$current_style :
355  $ilias->account->prefs['style'];
356  }
357 
363  public static function setCurrentSkin($a_skin)
364  {
365  global $styleDefinition;
366 
367  if (is_object($styleDefinition)
368  and $styleDefinition->getTemplateId() != $a_skin)
369  {
370  $styleDefinition = new ilStyleDefinition($a_skin);
371  $styleDefinition->startParsing();
372  }
373 
374  self::$current_skin = $a_skin;
375  }
376 
377 
383  public static function setCurrentStyle($a_style)
384  {
385  self::$current_style = $a_style;
386  }
387 }
388 ?>