[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZXMLSchema class 4 // 5 // Created on: <27-Mar-2006 15:28:39 ks> 6 // 7 // SOFTWARE NAME: eZ publish 8 // BUILD VERSION: 17785 9 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 10 // SOFTWARE LICENSE: GNU General Public License v2.0 11 // NOTICE: > 12 // This program is free software; you can redistribute it and/or 13 // modify it under the terms of version 2.0 of the GNU General 14 // Public License as published by the Free Software Foundation. 15 // 16 // This program is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of version 2.0 of the GNU General 22 // Public License along with this program; if not, write to the Free 23 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 24 // MA 02110-1301, USA. 25 // 26 27 28 include_once ( "lib/ezxml/classes/ezxml.php" ); 29 30 class eZXMLSchema 31 { 32 var $Schema = array( 33 'section' => array( 'blockChildrenAllowed' => array( 'header', 'paragraph', 'section' ), 34 'inlineChildrenAllowed' => false, 35 'childrenRequired' => false, 36 'isInline' => false, 37 'attributes' => array( 'xmlns:image', 'xmlns:xhtml', 'xmlns:custom' ) ), 38 39 'embed' => array( 'blockChildrenAllowed' => false, 40 'inlineChildrenAllowed' => false, 41 'childrenRequired' => null, 42 'isInline' => true, 43 'attributes' => array( 'object_id', 'node_id', 'show_path', 'size', 44 'align', 'view', 'xhtml:id', 'class', 'target' ), 45 'attributesDefaults' => array( 'align' => 'right', 'view' => 'embed', 'class' => '' ) ), 46 47 'embed-inline' => array( 'blockChildrenAllowed' => false, 48 'inlineChildrenAllowed' => false, 49 'childrenRequired' => null, 50 'isInline' => true, 51 'attributes' => array( 'object_id', 'node_id', 'show_path', 'size', 52 'align', 'view', 'xhtml:id', 'class', 'target' ), 53 'attributesDefaults' => array( 'align' => 'right', 'view' => 'embed-inline', 'class' => '' ) ), 54 55 'object' => array( 'blockChildrenAllowed' => false, 56 'inlineChildrenAllowed' => false, 57 'childrenRequired' => null, 58 'isInline' => true, 59 'attributes' => array( 'class', 'id', 'size', 'align', 60 'view', 'image:ezurl_id', 'image:ezurl_target' ), 61 'attributesDefaults' => array( 'align' => 'right', 'view' => 'embed' ) ), 62 63 'table' => array( 'blockChildrenAllowed' => array( 'tr' ), 64 'inlineChildrenAllowed' => false, 65 'childrenRequired' => true, 66 'isInline' => false, 67 'attributes' => array( 'class', 'width', 'border' ) ), 68 69 'tr' => array( 'blockChildrenAllowed' => array( 'td', 'th' ), 70 'inlineChildrenAllowed' => false, 71 'childrenRequired' => false, 72 'isInline' => false, 73 'attributes' => array( 'class' ) ), 74 75 'td' => array( 'blockChildrenAllowed' => array( 'header', 'paragraph', 'section', 'table' ), 76 'inlineChildrenAllowed' => false, 77 'childrenRequired' => false, 78 'isInline' => false, 79 'attributes' => array( 'class', 'xhtml:width', 'xhtml:colspan', 'xhtml:rowspan' ) ), 80 81 'th' => array( 'blockChildrenAllowed' => array( 'header', 'paragraph', 'section', 'table' ), 82 'inlineChildrenAllowed' => false, 83 'childrenRequired' => false, 84 'isInline' => false, 85 'attributes' => array( 'class', 'xhtml:width', 'xhtml:colspan', 'xhtml:rowspan' ) ), 86 87 'ol' => array( 'blockChildrenAllowed' => array( 'li' ), 88 'inlineChildrenAllowed' => false, 89 'childrenRequired' => true, 90 'isInline' => false, 91 'attributes' => array( 'class' ) ), 92 93 'ul' => array( 'blockChildrenAllowed' => array( 'li' ), 94 'inlineChildrenAllowed' => false, 95 'childrenRequired' => true, 96 'isInline' => false, 97 'attributes' => array( 'class' ) ), 98 99 'li' => array( 'blockChildrenAllowed' => array( 'paragraph' ), 100 'inlineChildrenAllowed' => false, 101 'childrenRequired' => true, 102 'isInline' => false, 103 'attributes' => array( 'class' ) ), 104 105 'header' => array( 'blockChildrenAllowed' => false, 106 'inlineChildrenAllowed' => true, 107 'childrenRequired' => true, 108 'isInline' => false, 109 'attributes' => array( 'class', 'anchor_name' ) ), 110 111 'paragraph' => array( 'blockChildrenAllowed' => array( 'line', 'link', 'embed', 'object', 'table', 'ol', 'ul', 'custom', 'literal' ), 112 'inlineChildrenAllowed' => true, 113 'childrenRequired' => true, 114 'isInline' => false, 115 'attributes' => array( 'class' ) ), 116 117 'line' => array( 'blockChildrenAllowed' => false, 118 'inlineChildrenAllowed' => true, 119 'childrenRequired' => true, 120 'isInline' => false, 121 'attributes' => false ), 122 123 'literal' => array( 'blockChildrenAllowed' => false, 124 'inlineChildrenAllowed' => array( '#text' ), 125 'childrenRequired' => true, 126 'isInline' => false, 127 'attributes' => array( 'class' ) ), 128 129 'strong' => array( 'blockChildrenAllowed' => false, 130 'inlineChildrenAllowed' => true, 131 'childrenRequired' => true, 132 'isInline' => true, 133 'attributes' => array( 'class' ) ), 134 135 'emphasize' => array( 'blockChildrenAllowed' => false, 136 'inlineChildrenAllowed' => true, 137 'childrenRequired' => true, 138 'isInline' => true, 139 'attributes' => array( 'class' ) ), 140 141 'link' => array( 'blockChildrenAllowed' => false, 142 'inlineChildrenAllowed' => true, 143 'childrenRequired' => true, 144 'isInline' => true, 145 'attributes' => array( 'class', 'xhtml:id', 'target', 'xhtml:title', 146 'object_id', 'node_id', 'show_path', 'anchor_name', 147 'url_id', 'id', 'view' ), 148 'attributesDefaults' => array( 'target' => '_self' ) ), 149 150 'anchor' => array( 'blockChildrenAllowed' => false, 151 'inlineChildrenAllowed' => false, 152 'childrenRequired' => false, 153 'isInline' => true, 154 'attributes' => array( 'name' ) ), 155 156 'custom' => array( 'blockChildrenAllowed' => true, 157 'inlineChildrenAllowed' => true, 158 'childrenRequired' => false, 159 'isInline' => null, 160 'attributes' => array( 'name' ) ), 161 162 '#text' => array( 'blockChildrenAllowed' => false, 163 'inlineChildrenAllowed' => false, 164 'childrenRequired' => false, 165 'isInline' => true, 166 'attributes' => false ) 167 ); 168 169 function eZXMLSchema() 170 { 171 include_once ( 'lib/ezutils/classes/ezini.php' ); 172 $ini =& eZINI::instance( 'content.ini' ); 173 174 // Get inline custom tags list 175 $this->Schema['custom']['isInline'] = $ini->variable( 'CustomTagSettings', 'IsInline' ); 176 if ( !is_array( $this->Schema['custom']['isInline'] ) ) 177 $this->Schema['custom']['isInline'] = array(); 178 179 $this->Schema['custom']['tagList'] = $ini->variable( 'CustomTagSettings', 'AvailableCustomTags' ); 180 if ( !is_array( $this->Schema['custom']['tagList'] ) ) 181 $this->Schema['custom']['tagList'] = array(); 182 183 include_once ( 'lib/version.php' ); 184 $eZPublishVersion = eZPublishSDK::majorVersion() + eZPublishSDK::minorVersion() * 0.1; 185 186 // Get all tags available classes list 187 foreach( array_keys( $this->Schema ) as $tagName ) 188 { 189 if ( $ini->hasVariable( $tagName, 'AvailableClasses' ) ) 190 { 191 $avail = $ini->variable( $tagName, 'AvailableClasses' ); 192 if ( is_array( $avail ) && count( $avail ) ) 193 $this->Schema[$tagName]['classesList'] = $avail; 194 else 195 $this->Schema[$tagName]['classesList'] = array(); 196 } 197 else 198 $this->Schema[$tagName]['classesList'] = array(); 199 } 200 201 if ( $eZPublishVersion >= 3.8 ) 202 { 203 // Fix for empty paragraphs setting 204 $allowEmptyParagraph = $ini->variable( 'paragraph', 'AllowEmpty' ); 205 $this->Schema['paragraph']['childrenRequired'] = $allowEmptyParagraph == 'true' ? false : true; 206 } 207 else 208 { 209 // Fix for headers content 210 $this->Schema['header']['inlineChildrenAllowed'] = array( '#text' ); 211 } 212 213 if ( $eZPublishVersion >= 3.9 ) 214 { 215 // <object> is not supported in 3.9 216 unset( $this->Schema['object'] ); 217 218 // Get all tags custom attributes list 219 $ini =& eZINI::instance( 'content.ini' ); 220 foreach( array_keys( $this->Schema ) as $tagName ) 221 { 222 if ( $tagName == 'custom' ) 223 { 224 // Custom attributes of custom tags 225 foreach( $this->Schema['custom']['tagList'] as $customTagName ) 226 { 227 if ( $ini->hasVariable( $customTagName, 'CustomAttributes' ) ) 228 { 229 $avail = $ini->variable( $customTagName, 'CustomAttributes' ); 230 if ( is_array( $avail ) && count( $avail ) ) 231 $this->Schema['custom']['customAttributes'][$customTagName] = $avail; 232 else 233 $this->Schema['custom']['customAttributes'][$customTagName] = array(); 234 } 235 else 236 $this->Schema['custom']['customAttributes'][$customTagName] = array(); 237 238 } 239 } 240 else 241 { 242 // Custom attributes of regular tags 243 if ( $ini->hasVariable( $tagName, 'CustomAttributes' ) ) 244 { 245 $avail = $ini->variable( $tagName, 'CustomAttributes' ); 246 if ( is_array( $avail ) && count( $avail ) ) 247 $this->Schema[$tagName]['customAttributes'] = $avail; 248 else 249 $this->Schema[$tagName]['customAttributes'] = array(); 250 } 251 else 252 $this->Schema[$tagName]['customAttributes'] = array(); 253 } 254 } 255 } 256 else 257 { 258 // Literal was inline before 3.9 259 $this->Schema['literal']['isInline'] = true; 260 $this->Schema['link']['attributes'] = array( 'class', 'xhtml:id', 'target', 'xhtml:title', 261 'object_id', 'node_id', 'show_path', 'anchor_name', 262 'url_id', 'id' ); 263 } 264 } 265 266 function &instance() 267 { 268 $impl =& $GLOBALS["eZXMLSchemaGlobalInstance"]; 269 270 $class = get_class( $impl ); 271 if ( $class != "ezxmlschema" ) 272 { 273 unset( $impl ); 274 $impl = new eZXMLSchema(); 275 276 // Set global instance 277 $GLOBALS["eZXMLSchemaGlobalInstance"] =& $impl; 278 } 279 280 return $impl; 281 } 282 283 // Determines if the tag is inline 284 function isInline( $element ) 285 { 286 if ( is_string( $element ) ) 287 $elementName = $element; 288 else 289 $elementName = $element->nodeName; 290 291 $isInline = $this->Schema[$elementName]['isInline']; 292 293 // Special workaround for custom tags. 294 if ( is_array( $isInline ) && !is_string( $element ) ) 295 { 296 $isInline = false; 297 $name = $element->getAttribute( 'name' ); 298 299 if ( isset( $this->Schema['custom']['isInline'][$name] ) ) 300 { 301 if ( $this->Schema['custom']['isInline'][$name] == 'true' ) 302 $isInline = true; 303 } 304 } 305 return $isInline; 306 } 307 308 /*! 309 Checks if one element is allowed to be a child of another 310 311 \param $parent parent element: eZDOMNode or string 312 \param $child child element: eZDOMNode or string 313 314 \return true if elements match schema 315 \return false if elements don't match schema 316 \return null in case of errors 317 */ 318 319 function check( $parent, $child ) 320 { 321 if ( is_string( $parent ) ) 322 $parentName = $parent; 323 else 324 $parentName = $parent->nodeName; 325 326 if ( is_string( $child ) ) 327 $childName = $child; 328 else 329 $childName = $child->nodeName; 330 331 if ( isset( $this->Schema[$childName] ) ) 332 { 333 $isInline = $this->isInline( $child ); 334 335 if ( $isInline === true ) 336 { 337 $allowed = $this->Schema[$parentName]['inlineChildrenAllowed']; 338 } 339 elseif ( $isInline === false ) 340 { 341 // Special workaround for custom tags. 342 if ( $parentName == 'custom' && !is_string( $parent ) && 343 $parent->getAttribute( 'inline' ) != 'true' ) 344 { 345 $allowed = true; 346 } 347 else 348 $allowed = $this->Schema[$parentName]['blockChildrenAllowed']; 349 } 350 else 351 return true; 352 353 if ( is_array( $allowed ) ) 354 $allowed = in_array( $childName, $allowed ); 355 356 if ( !$allowed ) 357 return false; 358 } 359 else 360 { 361 //eZDebug::writeError( "No schema set for <" . $childName . "> tag.", 'eZXMLSchema' ); 362 return null; 363 } 364 return true; 365 } 366 367 function childrenRequired( $element ) 368 { 369 //if ( !isset( $this->Schema[$element->nodeName] ) ) 370 // return false; 371 372 return $this->Schema[$element->nodeName]['childrenRequired']; 373 } 374 375 function hasAttributes( $element ) 376 { 377 //if ( !isset( $this->Schema[$element->nodeName] ) ) 378 // return false; 379 380 return ( $this->Schema[$element->nodeName]['attributes'] != false ); 381 } 382 383 function attributes( $element ) 384 { 385 return $this->Schema[$element->nodeName]['attributes']; 386 } 387 388 function customAttributes( $element ) 389 { 390 if ( is_string( $element ) ) 391 { 392 return $this->Schema[$element]['customAttributes']; 393 } 394 else 395 { 396 if ( $element->nodeName == 'custom' ) 397 { 398 $name = $element->getAttribute( 'name' ); 399 if ( $name ) 400 return $this->Schema['custom']['customAttributes'][$name]; 401 } 402 else 403 { 404 return $this->Schema[$element->nodeName]['customAttributes']; 405 } 406 } 407 return array(); 408 } 409 410 function attrDefaultValue( $tagName, $attrName ) 411 { 412 if ( isset( $this->Schema[$tagName]['attributesDefaults'][$attrName] ) ) 413 return $this->Schema[$tagName]['attributesDefaults'][$attrName]; 414 else 415 return array(); 416 } 417 418 function attrDefaultValues( $tagName ) 419 { 420 if ( isset( $this->Schema[$tagName]['attributesDefaults'] ) ) 421 return $this->Schema[$tagName]['attributesDefaults']; 422 else 423 return array(); 424 } 425 426 function exists( $element ) 427 { 428 if ( is_string( $element ) ) 429 { 430 return isset( $this->Schema[$element] ); 431 } 432 else 433 { 434 if ( $element->nodeName == 'custom' ) 435 { 436 $name = $element->getAttribute( 'name' ); 437 if ( $name ) 438 return in_array( $name, $this->Schema['custom']['tagList'] ); 439 } 440 else 441 { 442 return isset( $this->Schema[$element->nodeName] ); 443 } 444 } 445 return false; 446 } 447 448 function availableElements() 449 { 450 return array_keys( $this->Schema ); 451 } 452 453 function getClassesList( $tagName ) 454 { 455 if ( isset( $this->Schema[$tagName]['classesList'] ) ) 456 return $this->Schema[$tagName]['classesList']; 457 else 458 return array(); 459 } 460 461 function addAvailableClass( $tagName, $class ) 462 { 463 if ( !isset( $this->Schema[$tagName]['classesList'] ) ) 464 $this->Schema[$tagName]['classesList'] = array(); 465 466 $this->Schema[$tagName]['classesList'][] = $class; 467 } 468 469 function addCustomAttribute( $element, $attrName ) 470 { 471 if ( is_string( $element ) ) 472 { 473 $this->Schema[$element]['customAttributes'][] = $attrName; 474 } 475 else 476 { 477 if ( $element->nodeName == 'custom' ) 478 { 479 $name = $element->getAttribute( 'name' ); 480 if ( $name ) 481 $this->Schema['custom']['customAttributes'][$name][] = $attrName; 482 } 483 else 484 { 485 $this->Schema[$element->nodeName]['customAttributes'][] = $attrName; 486 } 487 } 488 } 489 } 490 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |