ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
6require_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();
55 parent::startParsing();
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 "custom" => $a_attribs["Custom"]);
105 break;
106
107 case "StyleColor":
108 $this->style_obj->addColor($a_attribs["Name"], $a_attribs["Code"]);
109 break;
110
111 case "StyleTemplate":
112 $this->cur_template = array("type" => $a_attribs["Type"],
113 "name" => $a_attribs["Name"]);
114 $this->cur_template_classes = array();
115 break;
116
117 case "StyleTemplateClass":
118 $this->cur_template_classes[$a_attribs["ClassType"]] =
119 $a_attribs["Class"];
120 break;
121
122 }
123 $this->cdata = "";
124 }
125
126
130 function handlerEndTag($a_xml_parser, $a_name)
131 {
132 switch($a_name)
133 {
134 case "Title":
135 $this->style_obj->setTitle($this->cdata);
136 break;
137
138 case "Description":
139 $this->style_obj->setDescription($this->cdata);
140 break;
141
142 case "Style":
143 $this->styles[] = $this->current_tags;
144 break;
145
146 case "StyleTemplate":
147 $this->style_obj->addTemplate($this->cur_template["type"],
148 $this->cur_template["name"], $this->cur_template_classes);
149 break;
150
151 }
152 }
153
157 function handlerCharacterData($a_xml_parser, $a_data)
158 {
159 // i don't know why this is necessary, but
160 // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
161 // in character data, but we don't want that, because it's the
162 // way we mask user html in our content, so we convert back...
163 $a_data = str_replace("<","&lt;",$a_data);
164 $a_data = str_replace(">","&gt;",$a_data);
165
166 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
167 $a_data = preg_replace("/\n/","",$a_data);
168 $a_data = preg_replace("/\t+/","",$a_data);
169 if(!empty($a_data))
170 {
171 $this->cdata .= $a_data;
172 }
173 }
174
175}
176?>
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
setHandlers($a_xml_parser)
set event handler should be overwritten by inherited class @access private
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
ilStyleImportParser($a_xml_file, &$a_style_obj)
Constructor.