Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezxmlschema.php
Go to the documentation of this file.
1 <?php
11 class eZXMLSchema
12 {
13 public $Schema = array(
14 'section' => array( 'blockChildrenAllowed' => array( 'header', 'paragraph', 'section' ),
15 'inlineChildrenAllowed' => false,
16 'childrenRequired' => false,
17 'isInline' => false,
18 'attributes' => array( 'xmlns:image', 'xmlns:xhtml', 'xmlns:custom', 'xmlns:tmp' ) ),
19
20 'embed' => array( 'blockChildrenAllowed' => false,
21 'inlineChildrenAllowed' => false,
22 'childrenRequired' => null,
23 'isInline' => true,
24 'attributes' => array( 'object_id', 'node_id', 'show_path', 'size',
25 'align', 'view', 'xhtml:id', 'class', 'target' ),
26 'attributesDefaults' => array( 'align' => '', 'view' => 'embed', 'class' => '' ) ),
27
28 'embed-inline' => array( 'blockChildrenAllowed' => false,
29 'inlineChildrenAllowed' => false,
30 'childrenRequired' => null,
31 'isInline' => true,
32 'attributes' => array( 'object_id', 'node_id', 'show_path', 'size',
33 'align', 'view', 'xhtml:id', 'class', 'target' ),
34 'attributesDefaults' => array( 'align' => '', 'view' => 'embed-inline', 'class' => '' ) ),
35
36 'table' => array( 'blockChildrenAllowed' => array( 'tr' ),
37 'inlineChildrenAllowed' => false,
38 'childrenRequired' => true,
39 'isInline' => false,
40 'attributes' => array( 'class', 'width', 'border', 'align' ) ),
41
42 'tr' => array( 'blockChildrenAllowed' => array( 'td', 'th' ),
43 'inlineChildrenAllowed' => false,
44 'childrenRequired' => false,
45 'isInline' => false,
46 'attributes' => array( 'class' ) ),
47
48 'td' => array( 'blockChildrenAllowed' => array( 'header', 'paragraph', 'section', 'table' ),
49 'inlineChildrenAllowed' => false,
50 'childrenRequired' => false,
51 'isInline' => false,
52 'attributes' => array( 'class', 'align', 'xhtml:width', 'xhtml:colspan', 'xhtml:rowspan' ) ),
53
54 'th' => array( 'blockChildrenAllowed' => array( 'header', 'paragraph', 'section', 'table' ),
55 'inlineChildrenAllowed' => false,
56 'childrenRequired' => false,
57 'isInline' => false,
58 'attributes' => array( 'class', 'align', 'xhtml:width', 'xhtml:colspan', 'xhtml:rowspan' ) ),
59
60 'ol' => array( 'blockChildrenAllowed' => array( 'li' ),
61 'inlineChildrenAllowed' => false,
62 'childrenRequired' => true,
63 'isInline' => false,
64 'attributes' => array( 'class' ) ),
65
66 'ul' => array( 'blockChildrenAllowed' => array( 'li' ),
67 'inlineChildrenAllowed' => false,
68 'childrenRequired' => true,
69 'isInline' => false,
70 'attributes' => array( 'class' ) ),
71
72 'li' => array( 'blockChildrenAllowed' => array( 'paragraph' ),
73 'inlineChildrenAllowed' => false,
74 'childrenRequired' => true,
75 'isInline' => false,
76 'attributes' => array( 'class' ) ),
77
78 'header' => array( 'blockChildrenAllowed' => array( 'line' ),
79 'inlineChildrenAllowed' => true,
80 'childrenRequired' => true,
81 'isInline' => false,
82 'attributes' => array( 'class', 'anchor_name', 'align' ) ),
83
84 'paragraph' => array( 'blockChildrenAllowed' => array( 'line', 'link', 'embed', 'table', 'ol', 'ul', 'custom', 'literal' ),
85 'inlineChildrenAllowed' => true,
86 'childrenRequired' => true,
87 'isInline' => false,
88 'attributes' => array( 'class', 'align' ) ),
89
90 'line' => array( 'blockChildrenAllowed' => false,
91 'inlineChildrenAllowed' => true,
92 'childrenRequired' => true,
93 'isInline' => false,
94 'attributes' => false ),
95
96 'literal' => array( 'blockChildrenAllowed' => false,
97 'inlineChildrenAllowed' => array( '#text' ),
98 'childrenRequired' => true,
99 'isInline' => false,
100 'attributes' => array( 'class' ) ),
101
102 'strong' => array( 'blockChildrenAllowed' => false,
103 'inlineChildrenAllowed' => true,
104 'childrenRequired' => true,
105 'isInline' => true,
106 'attributes' => array( 'class' ) ),
107
108 'emphasize' => array( 'blockChildrenAllowed' => false,
109 'inlineChildrenAllowed' => true,
110 'childrenRequired' => true,
111 'isInline' => true,
112 'attributes' => array( 'class' ) ),
113
114 'link' => array( 'blockChildrenAllowed' => false,
115 'inlineChildrenAllowed' => true,
116 'childrenRequired' => true,
117 'isInline' => true,
118 'attributes' => array( 'class', 'xhtml:id', 'target', 'xhtml:title',
119 'object_id', 'node_id', 'show_path', 'anchor_name',
120 'url_id', 'id', 'view' ),
121 'attributesDefaults' => array( 'target' => '_self' ) ),
122
123 'anchor' => array( 'blockChildrenAllowed' => false,
124 'inlineChildrenAllowed' => false,
125 'childrenRequired' => false,
126 'isInline' => true,
127 'attributes' => array( 'name' ) ),
128
129 'custom' => array( 'blockChildrenAllowed' => true,
130 'inlineChildrenAllowed' => true,
131 'childrenRequired' => false,
132 'isInline' => null,
133 'attributes' => array( 'name', 'align' ) ),
134
135 '#text' => array( 'blockChildrenAllowed' => false,
136 'inlineChildrenAllowed' => false,
137 'childrenRequired' => false,
138 'isInline' => true,
139 'attributes' => false )
140 );
141
145 public function __construct()
146 {
147 $ini = eZINI::instance( 'content.ini' );
148
149 // Get inline custom tags list
150 $this->Schema['custom']['isInline'] = $ini->variable( 'CustomTagSettings', 'IsInline' );
151 if ( !is_array( $this->Schema['custom']['isInline'] ) )
152 $this->Schema['custom']['isInline'] = array();
153
154 $this->Schema['custom']['tagList'] = $ini->variable( 'CustomTagSettings', 'AvailableCustomTags' );
155 if ( !is_array( $this->Schema['custom']['tagList'] ) )
156 $this->Schema['custom']['tagList'] = array();
157
158 $eZPublishVersion = eZPublishSDK::majorVersion() + eZPublishSDK::minorVersion() * 0.1;
159
160 // Get all tags available classes list
161 foreach( array_keys( $this->Schema ) as $tagName )
162 {
163 if ( $ini->hasVariable( $tagName, 'AvailableClasses' ) )
164 {
165 $avail = $ini->variable( $tagName, 'AvailableClasses' );
166 if ( is_array( $avail ) && count( $avail ) )
167 $this->Schema[$tagName]['classesList'] = $avail;
168 else
169 $this->Schema[$tagName]['classesList'] = array();
170 }
171 else
172 $this->Schema[$tagName]['classesList'] = array();
173 }
174
175
176 // Fix for empty paragraphs setting
177 $allowEmptyParagraph = $ini->variable( 'paragraph', 'AllowEmpty' );
178 $this->Schema['paragraph']['childrenRequired'] = $allowEmptyParagraph == 'true' ? false : true;
179
180 // Get all tags custom attributes list
181 $ini = eZINI::instance( 'content.ini' );
182 foreach( array_keys( $this->Schema ) as $tagName )
183 {
184 if ( $tagName == 'custom' )
185 {
186 // Custom attributes of custom tags
187 foreach( $this->Schema['custom']['tagList'] as $customTagName )
188 {
189 if ( $ini->hasVariable( $customTagName, 'CustomAttributes' ) )
190 {
191 $avail = $ini->variable( $customTagName, 'CustomAttributes' );
192 if ( is_array( $avail ) && count( $avail ) )
193 $this->Schema['custom']['customAttributes'][$customTagName] = $avail;
194 else
195 $this->Schema['custom']['customAttributes'][$customTagName] = array();
196 }
197 else
198 $this->Schema['custom']['customAttributes'][$customTagName] = array();
199 }
200 }
201 else
202 {
203 // Custom attributes of regular tags
204 if ( $ini->hasVariable( $tagName, 'CustomAttributes' ) )
205 {
206 $avail = $ini->variable( $tagName, 'CustomAttributes' );
207 if ( is_array( $avail ) && count( $avail ) )
208 $this->Schema[$tagName]['customAttributes'] = $avail;
209 else
210 $this->Schema[$tagName]['customAttributes'] = array();
211 }
212 else
213 $this->Schema[$tagName]['customAttributes'] = array();
214 }
215 }
216 }
217
223 static function instance()
224 {
225 if ( empty( $GLOBALS["eZXMLSchemaGlobalInstance"] ) )
226 {
227 $GLOBALS["eZXMLSchemaGlobalInstance"] = new eZXMLSchema();
228 }
229
230 return $GLOBALS["eZXMLSchemaGlobalInstance"];
231 }
232
233 // Determines if the tag is inline
234 function isInline( $element )
235 {
236 if ( is_string( $element ) )
237 $elementName = $element;
238 else
239 $elementName = $element->nodeName;
240
241 $isInline = $this->Schema[$elementName]['isInline'];
242
243 // Special workaround for custom tags.
244 if ( is_array( $isInline ) && !is_string( $element ) )
245 {
246 $isInline = false;
247 $name = $element->getAttribute( 'name' );
248
249 if ( isset( $this->Schema['custom']['isInline'][$name] ) )
250 {
251 if ( $this->Schema['custom']['isInline'][$name] != 'false' )
252 $isInline = true;
253 }
254 }
255 return $isInline;
256 }
257
269 function check( $parent, $child )
270 {
271 if ( is_string( $parent ) )
272 $parentName = $parent;
273 else
274 $parentName = $parent->nodeName;
275
276 if ( is_string( $child ) )
277 $childName = $child;
278 else
279 $childName = $child->nodeName;
280
281 if ( isset( $this->Schema[$childName] ) )
282 {
283 $isInline = $this->isInline( $child );
284
285 if ( $isInline === true )
286 {
287 $allowed = $this->Schema[$parentName]['inlineChildrenAllowed'];
288 }
289 elseif ( $isInline === false )
290 {
291 // Special workaround for custom tags.
292 if ( $parentName == 'custom' && !is_string( $parent ) &&
293 $parent->getAttribute( 'inline' ) != 'true' )
294 {
295 $allowed = true;
296 }
297 else
298 $allowed = $this->Schema[$parentName]['blockChildrenAllowed'];
299 }
300 else
301 return true;
302
303 if ( is_array( $allowed ) )
304 $allowed = in_array( $childName, $allowed );
305
306 if ( !$allowed )
307 return false;
308 }
309 else
310 {
311 return null;
312 }
313 return true;
314 }
315
316 function childrenRequired( $element )
317 {
318 //if ( !isset( $this->Schema[$element->nodeName] ) )
319 // return false;
320
321 return $this->Schema[$element->nodeName]['childrenRequired'];
322 }
323
324 function hasAttributes( $element )
325 {
326 //if ( !isset( $this->Schema[$element->nodeName] ) )
327 // return false;
328
329 return ( $this->Schema[$element->nodeName]['attributes'] != false );
330 }
331
332 function attributes( $element )
333 {
334 return $this->Schema[$element->nodeName]['attributes'];
335 }
336
337 function customAttributes( $element )
338 {
339 if ( is_string( $element ) )
340 {
341 return $this->Schema[$element]['customAttributes'];
342 }
343 else
344 {
345 if ( $element->nodeName == 'custom' )
346 {
347 $name = $element->getAttribute( 'name' );
348 if ( $name )
349 return $this->Schema['custom']['customAttributes'][$name];
350 }
351 else
352 {
353 return $this->Schema[$element->nodeName]['customAttributes'];
354 }
355 }
356 return array();
357 }
358
359 function attrDefaultValue( $tagName, $attrName )
360 {
361 if ( isset( $this->Schema[$tagName]['attributesDefaults'][$attrName] ) )
362 return $this->Schema[$tagName]['attributesDefaults'][$attrName];
363 else
364 return array();
365 }
366
367 function attrDefaultValues( $tagName )
368 {
369 if ( isset( $this->Schema[$tagName]['attributesDefaults'] ) )
370 return $this->Schema[$tagName]['attributesDefaults'];
371 else
372 return array();
373 }
374
375 function exists( $element )
376 {
377 if ( is_string( $element ) )
378 {
379 return isset( $this->Schema[$element] );
380 }
381 else
382 {
383 if ( $element->nodeName == 'custom' )
384 {
385 $name = $element->getAttribute( 'name' );
386 if ( $name )
387 return in_array( $name, $this->Schema['custom']['tagList'] );
388 }
389 else
390 {
391 return isset( $this->Schema[$element->nodeName] );
392 }
393 }
394 return false;
395 }
396
397 function availableElements()
398 {
399 return array_keys( $this->Schema );
400 }
401
402 function getClassesList( $tagName )
403 {
404 if ( isset( $this->Schema[$tagName]['classesList'] ) )
405 return $this->Schema[$tagName]['classesList'];
406 else
407 return array();
408 }
409
410 function addAvailableClass( $tagName, $class )
411 {
412 if ( !isset( $this->Schema[$tagName]['classesList'] ) )
413 $this->Schema[$tagName]['classesList'] = array();
414
415 $this->Schema[$tagName]['classesList'][] = $class;
416 }
417
418 function addCustomAttribute( $element, $attrName )
419 {
420 if ( is_string( $element ) )
421 {
422 $this->Schema[$element]['customAttributes'][] = $attrName;
423 }
424 else
425 {
426 if ( $element->nodeName == 'custom' )
427 {
428 $name = $element->getAttribute( 'name' );
429 if ( $name )
430 $this->Schema['custom']['customAttributes'][$name][] = $attrName;
431 }
432 else
433 {
434 $this->Schema[$element->nodeName]['customAttributes'][] = $attrName;
435 }
436 }
437 }
438 }
439 ?>
eZXMLSchema
Definition: ezxmlschema.php:12
eZXMLSchema\$Schema
$Schema
Definition: ezxmlschema.php:13
eZXMLSchema\childrenRequired
childrenRequired( $element)
Definition: ezxmlschema.php:316
eZXMLSchema\check
check( $parent, $child)
Definition: ezxmlschema.php:269
eZXMLSchema\getClassesList
getClassesList( $tagName)
Definition: ezxmlschema.php:402
eZXMLSchema\customAttributes
customAttributes( $element)
Definition: ezxmlschema.php:337
eZXMLSchema\attributes
attributes( $element)
Definition: ezxmlschema.php:332
eZXMLSchema\hasAttributes
hasAttributes( $element)
Definition: ezxmlschema.php:324
eZXMLSchema\instance
static instance()
Definition: ezxmlschema.php:223
eZXMLSchema\exists
exists( $element)
Definition: ezxmlschema.php:375
eZXMLSchema\__construct
__construct()
Definition: ezxmlschema.php:145
eZXMLSchema\addCustomAttribute
addCustomAttribute( $element, $attrName)
Definition: ezxmlschema.php:418
eZXMLSchema\addAvailableClass
addAvailableClass( $tagName, $class)
Definition: ezxmlschema.php:410
eZXMLSchema\attrDefaultValue
attrDefaultValue( $tagName, $attrName)
Definition: ezxmlschema.php:359
eZXMLSchema\isInline
isInline( $element)
Definition: ezxmlschema.php:234
eZXMLSchema\availableElements
availableElements()
Definition: ezxmlschema.php:397
eZXMLSchema\attrDefaultValues
attrDefaultValues( $tagName)
Definition: ezxmlschema.php:367
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.