ILIAS  release_7 Revision v7.30-3-g800a261c036
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{
21 protected $tree;
22
23
32 public function __construct($a_xml_file, &$a_style_obj)
33 {
34 global $DIC;
35
36 $this->lng = $DIC->language();
37 $this->tree = $DIC->repositoryTree();
38 $lng = $DIC->language();
39 $tree = $DIC->repositoryTree();
40
41 $this->style_obj = $a_style_obj;
42
43 parent::__construct($a_xml_file);
44 }
45
46
52 public function setHandlers($a_xml_parser)
53 {
54 xml_set_object($a_xml_parser, $this);
55 xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
56 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
57 }
58
62 public function startParsing()
63 {
64 $this->styles = array();
65 parent::startParsing();
66 $this->style_obj->setStyle($this->styles);
67 $this->style_obj->setCharacteristics($this->chars);
68 }
69
70
74 public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
75 {
76 $a_attribs = $this->trimAndStripAttribs($a_attribs);
77 switch ($a_name) {
78 case "Style":
79 $this->current_tag = $a_attribs["Tag"];
80 $this->current_class = $a_attribs["Class"];
81 $this->current_type = $a_attribs["Type"];
82 if ($this->current_class == "PageTitle" && $this->current_type == "page_title" && $this->current_tag == "div") {
83 $this->current_tag = "h1";
84 }
85 if ($this->current_class == "Headline1" && $this->current_tag == "div") {
86 $this->current_tag = "h1";
87 $this->current_type = "heading1";
88 }
89 if ($this->current_class == "Headline2" && $this->current_tag == "div") {
90 $this->current_tag = "h2";
91 $this->current_type = "heading2";
92 }
93 if ($this->current_class == "Headline3" && $this->current_tag == "div") {
94 $this->current_tag = "h3";
95 $this->current_type = "heading3";
96 }
97 $this->current_tags = array();
98 $this->chars[] = array("type" => $this->current_type,
99 "class" => $this->current_class);
100 break;
101
102 case "StyleParameter":
103 $this->current_tags[] = array(
104 "tag" => $this->current_tag,
105 "class" => $this->current_class,
106 "parameter" => $a_attribs["Name"],
107 "type" => $this->current_type,
108 "value" => $a_attribs["Value"],
109 "custom" => $a_attribs["Custom"]);
110 break;
111
112 case "StyleColor":
113 $this->style_obj->addColor($a_attribs["Name"], $a_attribs["Code"]);
114 break;
115
116 case "StyleTemplate":
117 $this->cur_template = array("type" => $a_attribs["Type"],
118 "name" => $a_attribs["Name"]);
119 $this->cur_template_classes = array();
120 break;
121
122 case "StyleTemplateClass":
123 $this->cur_template_classes[$a_attribs["ClassType"]] =
124 $a_attribs["Class"];
125 break;
126
127 }
128 $this->cdata = "";
129 }
130
131
135 public function handlerEndTag($a_xml_parser, $a_name)
136 {
137 $this->cdata = $this->trimAndStrip($this->cdata);
138 switch ($a_name) {
139 case "Title":
140 $this->style_obj->setTitle($this->cdata);
141 break;
142
143 case "Description":
144 $this->style_obj->setDescription($this->cdata);
145 break;
146
147 case "Style":
148 $this->styles[] = $this->current_tags;
149 break;
150
151 case "StyleTemplate":
152 $this->style_obj->addTemplate(
153 $this->cur_template["type"],
154 $this->cur_template["name"],
155 $this->cur_template_classes
156 );
157 break;
158
159 }
160 }
161
165 public function handlerCharacterData($a_xml_parser, $a_data)
166 {
167 // i don't know why this is necessary, but
168 // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
169 // in character data, but we don't want that, because it's the
170 // way we mask user html in our content, so we convert back...
171 $a_data = str_replace("<", "&lt;", $a_data);
172 $a_data = str_replace(">", "&gt;", $a_data);
173
174 // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
175 $a_data = preg_replace("/\n/", "", $a_data);
176 $a_data = preg_replace("/\t+/", "", $a_data);
177 if (!empty($a_data)) {
178 $this->cdata .= $a_data;
179 }
180 }
181
182 protected function trimAndStripAttribs(array $attribs) : array
183 {
184 $ret = [];
185 foreach ($attribs as $k => $v) {
186 $ret[$k] = $this->trimAndStrip((string) $v);
187 }
188 return $ret;
189 }
190
191 protected function trimAndStrip(string $input) : string
192 {
193 return ilUtil::stripSlashes(trim($input));
194 }
195}
An exception for terminatinating execution or to throw for unit testing.
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
__construct($a_xml_file, &$a_style_obj)
Constructor.
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
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6