ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilStyleImportParser.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 
25 require_once("./classes/class.ilSaxParser.php");
26 
36 {
37 
46  function ilStyleImportParser($a_xml_file, &$a_style_obj)
47  {
48  global $lng, $tree;
49 
50  $this->style_obj =& $a_style_obj;
51 
52  parent::ilSaxParser($a_xml_file);
53  }
54 
55 
61  function setHandlers($a_xml_parser)
62  {
63  xml_set_object($a_xml_parser,$this);
64  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
65  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
66  }
67 
71  function startParsing()
72  {
73  $this->styles = array();
75  $this->style_obj->setStyle($this->styles);
76  $this->style_obj->setCharacteristics($this->chars);
77  }
78 
79 
83  function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
84  {
85 
86  switch($a_name)
87  {
88  case "Style":
89  $this->current_tag = $a_attribs["Tag"];
90  $this->current_class = $a_attribs["Class"];
91  $this->current_type = $a_attribs["Type"];
92  if ($this->current_class == "PageTitle" && $this->current_type == "page_title" && $this->current_tag == "div")
93  {
94  $this->current_tag = "h1";
95  }
96  if ($this->current_class == "Headline1" && $this->current_tag == "div")
97  {
98  $this->current_tag = "h1";
99  $this->current_type = "heading1";
100  }
101  if ($this->current_class == "Headline2" && $this->current_tag == "div")
102  {
103  $this->current_tag = "h2";
104  $this->current_type = "heading2";
105  }
106  if ($this->current_class == "Headline3" && $this->current_tag == "div")
107  {
108  $this->current_tag = "h3";
109  $this->current_type = "heading3";
110  }
111  $this->current_tags = array();
112  $this->chars[] = array("type" => $this->current_type,
113  "class" => $this->current_class);
114  break;
115 
116  case "StyleParameter":
117  $this->current_tags[] = array(
118  "tag" => $this->current_tag,
119  "class" => $this->current_class,
120  "parameter" => $a_attribs["Name"],
121  "type" => $this->current_type,
122  "value" => $a_attribs["Value"]);
123  break;
124 
125  case "StyleColor":
126  $this->style_obj->addColor($a_attribs["Name"], $a_attribs["Code"]);
127  break;
128 
129  case "StyleTemplate":
130  $this->cur_template = array("type" => $a_attribs["Type"],
131  "name" => $a_attribs["Name"]);
132  $this->cur_template_classes = array();
133  break;
134 
135  case "StyleTemplateClass":
136  $this->cur_template_classes[$a_attribs["ClassType"]] =
137  $a_attribs["Class"];
138  break;
139 
140  }
141  $this->cdata = "";
142  }
143 
144 
148  function handlerEndTag($a_xml_parser, $a_name)
149  {
150  switch($a_name)
151  {
152  case "Title":
153  $this->style_obj->setTitle($this->cdata);
154  break;
155 
156  case "Description":
157  $this->style_obj->setDescription($this->cdata);
158  break;
159 
160  case "Style":
161  $this->styles[] = $this->current_tags;
162  break;
163 
164  case "StyleTemplate":
165  $this->style_obj->addTemplate($this->cur_template["type"],
166  $this->cur_template["name"], $this->cur_template_classes);
167  break;
168 
169  }
170  }
171 
175  function handlerCharacterData($a_xml_parser, $a_data)
176  {
177  // i don't know why this is necessary, but
178  // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
179  // in character data, but we don't want that, because it's the
180  // way we mask user html in our content, so we convert back...
181  $a_data = str_replace("<","&lt;",$a_data);
182  $a_data = str_replace(">","&gt;",$a_data);
183 
184  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
185  $a_data = preg_replace("/\n/","",$a_data);
186  $a_data = preg_replace("/\t+/","",$a_data);
187  if(!empty($a_data))
188  {
189  $this->cdata .= $a_data;
190  }
191  }
192 
193 }
194 ?>