[SPIP] ~2.1.12 -->2.1.25
[velocampus/web/www.git] / www / extensions / safehtml / lib / safehtml / classes / HTMLSax3 / States.php
1 <?php
2 define('XML_HTMLSAX3_STATE_STOP', 0);
3 define('XML_HTMLSAX3_STATE_START', 1);
4 define('XML_HTMLSAX3_STATE_TAG', 2);
5 define('XML_HTMLSAX3_STATE_OPENING_TAG', 3);
6 define('XML_HTMLSAX3_STATE_CLOSING_TAG', 4);
7 define('XML_HTMLSAX3_STATE_ESCAPE', 6);
8 define('XML_HTMLSAX3_STATE_JASP', 7);
9 define('XML_HTMLSAX3_STATE_PI', 8);
10 class XML_HTMLSax3_StartingState {
11 function parse(&$context) {
12 $data = $context->scanUntilString('<');
13 if ($data != '') {
14 $context->handler_object_data->
15 {$context->handler_method_data}($context->htmlsax, $data);
16 }
17 $context->IgnoreCharacter();
18 return XML_HTMLSAX3_STATE_TAG;
19 }
20 }
21 class XML_HTMLSax3_TagState {
22 function parse(&$context) {
23 switch($context->ScanCharacter()) {
24 case '/':
25 return XML_HTMLSAX3_STATE_CLOSING_TAG;
26 break;
27 case '?':
28 return XML_HTMLSAX3_STATE_PI;
29 break;
30 case '%':
31 return XML_HTMLSAX3_STATE_JASP;
32 break;
33 case '!':
34 return XML_HTMLSAX3_STATE_ESCAPE;
35 break;
36 default:
37 $context->unscanCharacter();
38 return XML_HTMLSAX3_STATE_OPENING_TAG;
39 }
40 }
41 }
42 class XML_HTMLSax3_ClosingTagState {
43 function parse(&$context) {
44 $tag = $context->scanUntilCharacters('/>');
45 if ($tag != '') {
46 $char = $context->scanCharacter();
47 if ($char == '/') {
48 $char = $context->scanCharacter();
49 if ($char != '>') {
50 $context->unscanCharacter();
51 }
52 }
53 $context->handler_object_element->
54 {$context->handler_method_closing}($context->htmlsax, $tag, FALSE);
55 }
56 return XML_HTMLSAX3_STATE_START;
57 }
58 }
59 class XML_HTMLSax3_OpeningTagState {
60 function parseAttributes(&$context) {
61 $Attributes = array();
62
63 $context->ignoreWhitespace();
64 $attributename = $context->scanUntilCharacters("=/> \n\r\t");
65 while ($attributename != '') {
66 $attributevalue = NULL;
67 $context->ignoreWhitespace();
68 $char = $context->scanCharacter();
69 if ($char == '=') {
70 $context->ignoreWhitespace();
71 $char = $context->ScanCharacter();
72 if ($char == '"') {
73 $attributevalue= $context->scanUntilString('"');
74 $context->IgnoreCharacter();
75 } else if ($char == "'") {
76 $attributevalue = $context->scanUntilString("'");
77 $context->IgnoreCharacter();
78 } else {
79 $context->unscanCharacter();
80 $attributevalue =
81 $context->scanUntilCharacters("> \n\r\t");
82 }
83 } else if ($char !== NULL) {
84 $attributevalue = NULL;
85 $context->unscanCharacter();
86 }
87 $Attributes[$attributename] = $attributevalue;
88
89 $context->ignoreWhitespace();
90 $attributename = $context->scanUntilCharacters("=/> \n\r\t");
91 }
92 return $Attributes;
93 }
94
95 function parse(&$context) {
96 $tag = $context->scanUntilCharacters("/> \n\r\t");
97 if ($tag != '') {
98 $this->attrs = array();
99 $Attributes = $this->parseAttributes($context);
100 $char = $context->scanCharacter();
101 if ($char == '/') {
102 $char = $context->scanCharacter();
103 if ($char != '>') {
104 $context->unscanCharacter();
105 }
106 $context->handler_object_element->
107 {$context->handler_method_opening}($context->htmlsax, $tag,
108 $Attributes, TRUE);
109 $context->handler_object_element->
110 {$context->handler_method_closing}($context->htmlsax, $tag,
111 TRUE);
112 } else {
113 $context->handler_object_element->
114 {$context->handler_method_opening}($context->htmlsax, $tag,
115 $Attributes, FALSE);
116 }
117 }
118 return XML_HTMLSAX3_STATE_START;
119 }
120 }
121
122 class XML_HTMLSax3_EscapeState {
123 function parse(&$context) {
124 $char = $context->ScanCharacter();
125 if ($char == '-') {
126 $char = $context->ScanCharacter();
127 if ($char == '-') {
128 $context->unscanCharacter();
129 $context->unscanCharacter();
130 $text = $context->scanUntilString('-->');
131 $text .= $context->scanCharacter();
132 $text .= $context->scanCharacter();
133 } else {
134 $context->unscanCharacter();
135 $text = $context->scanUntilString('>');
136 }
137 } else if ( $char == '[') {
138 $context->unscanCharacter();
139 $text = $context->scanUntilString(']>');
140 $text.= $context->scanCharacter();
141 } else {
142 $context->unscanCharacter();
143 $text = $context->scanUntilString('>');
144 }
145
146 $context->IgnoreCharacter();
147 if ($text != '') {
148 $context->handler_object_escape->
149 {$context->handler_method_escape}($context->htmlsax, $text);
150 }
151 return XML_HTMLSAX3_STATE_START;
152 }
153 }
154 class XML_HTMLSax3_JaspState {
155 function parse(&$context) {
156 $text = $context->scanUntilString('%>');
157 if ($text != '') {
158 $context->handler_object_jasp->
159 {$context->handler_method_jasp}($context->htmlsax, $text);
160 }
161 $context->IgnoreCharacter();
162 $context->IgnoreCharacter();
163 return XML_HTMLSAX3_STATE_START;
164 }
165 }
166 class XML_HTMLSax3_PiState {
167 function parse(&$context) {
168 $target = $context->scanUntilCharacters(" \n\r\t");
169 $data = $context->scanUntilString('?>');
170 if ($data != '') {
171 $context->handler_object_pi->
172 {$context->handler_method_pi}($context->htmlsax, $target, $data);
173 }
174 $context->IgnoreCharacter();
175 $context->IgnoreCharacter();
176 return XML_HTMLSAX3_STATE_START;
177 }
178 }
179 ?>