ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilStyleImportParser.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
6 require_once("./Services/Xml/classes/class.ilSaxParser.php");
7 
17 {
18 
27  function ilStyleImportParser($a_xml_file, &$a_style_obj)
28  {
29  global $lng, $tree;
30 
31  $this->style_obj =& $a_style_obj;
32 
33  parent::ilSaxParser($a_xml_file);
34  }
35 
36 
42  function setHandlers($a_xml_parser)
43  {
44  xml_set_object($a_xml_parser,$this);
45  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
46  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
47  }
48 
52  function startParsing()
53  {
54  $this->styles = array();
56  $this->style_obj->setStyle($this->styles);
57  $this->style_obj->setCharacteristics($this->chars);
58  }
59 
60 
64  function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
65  {
66 
67  switch($a_name)
68  {
69  case "Style":
70  $this->current_tag = $a_attribs["Tag"];
71  $this->current_class = $a_attribs["Class"];
72  $this->current_type = $a_attribs["Type"];
73  if ($this->current_class == "PageTitle" && $this->current_type == "page_title" && $this->current_tag == "div")
74  {
75  $this->current_tag = "h1";
76  }
77  if ($this->current_class == "Headline1" && $this->current_tag == "div")
78  {
79  $this->current_tag = "h1";
80  $this->current_type = "heading1";
81  }
82  if ($this->current_class == "Headline2" && $this->current_tag == "div")
83  {
84  $this->current_tag = "h2";
85  $this->current_type = "heading2";
86  }
87  if ($this->current_class == "Headline3" && $this->current_tag == "div")
88  {
89  $this->current_tag = "h3";
90  $this->current_type = "heading3";
91  }
92  $this->current_tags = array();
93  $this->chars[] = array("type" => $this->current_type,
94  "class" => $this->current_class);
95  break;
96 
97  case "StyleParameter":
98  $this->current_tags[] = array(
99  "tag" => $this->current_tag,
100  "class" => $this->current_class,
101  "parameter" => $a_attribs["Name"],
102  "type" => $this->current_type,
103  "value" => $a_attribs["Value"]);
104  break;
105 
106  case "StyleColor":
107  $this->style_obj->addColor($a_attribs["Name"], $a_attribs["Code"]);
108  break;
109 
110  case "StyleTemplate":
111  $this->cur_template = array("type" => $a_attribs["Type"],
112  "name" => $a_attribs["Name"]);
113  $this->cur_template_classes = array();
114  break;
115 
116  case "StyleTemplateClass":
117  $this->cur_template_classes[$a_attribs["ClassType"]] =
118  $a_attribs["Class"];
119  break;
120 
121  }
122  $this->cdata = "";
123  }
124 
125 
129  function handlerEndTag($a_xml_parser, $a_name)
130  {
131  switch($a_name)
132  {
133  case "Title":
134  $this->style_obj->setTitle($this->cdata);
135  break;
136 
137  case "Description":
138  $this->style_obj->setDescription($this->cdata);
139  break;
140 
141  case "Style":
142  $this->styles[] = $this->current_tags;
143  break;
144 
145  case "StyleTemplate":
146  $this->style_obj->addTemplate($this->cur_template["type"],
147  $this->cur_template["name"], $this->cur_template_classes);
148  break;
149 
150  }
151  }
152 
156  function handlerCharacterData($a_xml_parser, $a_data)
157  {
158  // i don't know why this is necessary, but
159  // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
160  // in character data, but we don't want that, because it's the
161  // way we mask user html in our content, so we convert back...
162  $a_data = str_replace("<","&lt;",$a_data);
163  $a_data = str_replace(">","&gt;",$a_data);
164 
165  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
166  $a_data = preg_replace("/\n/","",$a_data);
167  $a_data = preg_replace("/\t+/","",$a_data);
168  if(!empty($a_data))
169  {
170  $this->cdata .= $a_data;
171  }
172  }
173 
174 }
175 ?>