00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 include_once( "lib/ezxml/classes/ezxml.php" );
00031
00032 class eZXMLSchema
00033 {
00034 var $Schema = array(
00035 'section' => array( 'blockChildrenAllowed' => array( 'header', 'paragraph', 'section' ),
00036 'inlineChildrenAllowed' => false,
00037 'childrenRequired' => false,
00038 'isInline' => false,
00039 'attributes' => array( 'xmlns:image', 'xmlns:xhtml', 'xmlns:custom', 'xmlns:tmp' ) ),
00040
00041 'embed' => array( 'blockChildrenAllowed' => false,
00042 'inlineChildrenAllowed' => false,
00043 'childrenRequired' => null,
00044 'isInline' => true,
00045 'attributes' => array( 'object_id', 'node_id', 'show_path', 'size',
00046 'align', 'view', 'xhtml:id', 'class', 'target' ),
00047 'attributesDefaults' => array( 'align' => 'right', 'view' => 'embed', 'class' => '' ) ),
00048
00049 'embed-inline' => array( 'blockChildrenAllowed' => false,
00050 'inlineChildrenAllowed' => false,
00051 'childrenRequired' => null,
00052 'isInline' => true,
00053 'attributes' => array( 'object_id', 'node_id', 'show_path', 'size',
00054 'align', 'view', 'xhtml:id', 'class', 'target' ),
00055 'attributesDefaults' => array( 'align' => 'right', 'view' => 'embed-inline', 'class' => '' ) ),
00056
00057 'table' => array( 'blockChildrenAllowed' => array( 'tr' ),
00058 'inlineChildrenAllowed' => false,
00059 'childrenRequired' => true,
00060 'isInline' => false,
00061 'attributes' => array( 'class', 'width', 'border' ) ),
00062
00063 'tr' => array( 'blockChildrenAllowed' => array( 'td', 'th' ),
00064 'inlineChildrenAllowed' => false,
00065 'childrenRequired' => false,
00066 'isInline' => false,
00067 'attributes' => array( 'class' ) ),
00068
00069 'td' => array( 'blockChildrenAllowed' => array( 'header', 'paragraph', 'section', 'table' ),
00070 'inlineChildrenAllowed' => false,
00071 'childrenRequired' => false,
00072 'isInline' => false,
00073 'attributes' => array( 'class', 'xhtml:width', 'xhtml:colspan', 'xhtml:rowspan' ) ),
00074
00075 'th' => array( 'blockChildrenAllowed' => array( 'header', 'paragraph', 'section', 'table' ),
00076 'inlineChildrenAllowed' => false,
00077 'childrenRequired' => false,
00078 'isInline' => false,
00079 'attributes' => array( 'class', 'xhtml:width', 'xhtml:colspan', 'xhtml:rowspan' ) ),
00080
00081 'ol' => array( 'blockChildrenAllowed' => array( 'li' ),
00082 'inlineChildrenAllowed' => false,
00083 'childrenRequired' => true,
00084 'isInline' => false,
00085 'attributes' => array( 'class' ) ),
00086
00087 'ul' => array( 'blockChildrenAllowed' => array( 'li' ),
00088 'inlineChildrenAllowed' => false,
00089 'childrenRequired' => true,
00090 'isInline' => false,
00091 'attributes' => array( 'class' ) ),
00092
00093 'li' => array( 'blockChildrenAllowed' => array( 'paragraph' ),
00094 'inlineChildrenAllowed' => false,
00095 'childrenRequired' => true,
00096 'isInline' => false,
00097 'attributes' => array( 'class' ) ),
00098
00099 'header' => array( 'blockChildrenAllowed' => false,
00100 'inlineChildrenAllowed' => true,
00101 'childrenRequired' => true,
00102 'isInline' => false,
00103 'attributes' => array( 'class', 'anchor_name' ) ),
00104
00105 'paragraph' => array( 'blockChildrenAllowed' => array( 'line', 'link', 'embed', 'table', 'ol', 'ul', 'custom', 'literal' ),
00106 'inlineChildrenAllowed' => true,
00107 'childrenRequired' => true,
00108 'isInline' => false,
00109 'attributes' => array( 'class' ) ),
00110
00111 'line' => array( 'blockChildrenAllowed' => false,
00112 'inlineChildrenAllowed' => true,
00113 'childrenRequired' => true,
00114 'isInline' => false,
00115 'attributes' => false ),
00116
00117 'literal' => array( 'blockChildrenAllowed' => false,
00118 'inlineChildrenAllowed' => array( '#text' ),
00119 'childrenRequired' => true,
00120 'isInline' => false,
00121 'attributes' => array( 'class' ) ),
00122
00123 'strong' => array( 'blockChildrenAllowed' => false,
00124 'inlineChildrenAllowed' => true,
00125 'childrenRequired' => true,
00126 'isInline' => true,
00127 'attributes' => array( 'class' ) ),
00128
00129 'emphasize' => array( 'blockChildrenAllowed' => false,
00130 'inlineChildrenAllowed' => true,
00131 'childrenRequired' => true,
00132 'isInline' => true,
00133 'attributes' => array( 'class' ) ),
00134
00135 'link' => array( 'blockChildrenAllowed' => false,
00136 'inlineChildrenAllowed' => true,
00137 'childrenRequired' => true,
00138 'isInline' => true,
00139 'attributes' => array( 'class', 'xhtml:id', 'target', 'xhtml:title',
00140 'object_id', 'node_id', 'show_path', 'anchor_name',
00141 'url_id', 'id', 'view' ),
00142 'attributesDefaults' => array( 'target' => '_self' ) ),
00143
00144 'anchor' => array( 'blockChildrenAllowed' => false,
00145 'inlineChildrenAllowed' => false,
00146 'childrenRequired' => false,
00147 'isInline' => true,
00148 'attributes' => array( 'name' ) ),
00149
00150 'custom' => array( 'blockChildrenAllowed' => true,
00151 'inlineChildrenAllowed' => true,
00152 'childrenRequired' => false,
00153 'isInline' => null,
00154 'attributes' => array( 'name' ) ),
00155
00156 '#text' => array( 'blockChildrenAllowed' => false,
00157 'inlineChildrenAllowed' => false,
00158 'childrenRequired' => false,
00159 'isInline' => true,
00160 'attributes' => false )
00161 );
00162
00163 function eZXMLSchema()
00164 {
00165 include_once( 'lib/ezutils/classes/ezini.php' );
00166 $ini =& eZINI::instance( 'content.ini' );
00167
00168
00169 $this->Schema['custom']['isInline'] = $ini->variable( 'CustomTagSettings', 'IsInline' );
00170 if ( !is_array( $this->Schema['custom']['isInline'] ) )
00171 $this->Schema['custom']['isInline'] = array();
00172
00173 $this->Schema['custom']['tagList'] = $ini->variable( 'CustomTagSettings', 'AvailableCustomTags' );
00174 if ( !is_array( $this->Schema['custom']['tagList'] ) )
00175 $this->Schema['custom']['tagList'] = array();
00176
00177 include_once( 'lib/version.php' );
00178 $eZPublishVersion = eZPublishSDK::majorVersion() + eZPublishSDK::minorVersion() * 0.1;
00179
00180
00181 foreach( array_keys( $this->Schema ) as $tagName )
00182 {
00183 if ( $ini->hasVariable( $tagName, 'AvailableClasses' ) )
00184 {
00185 $avail = $ini->variable( $tagName, 'AvailableClasses' );
00186 if ( is_array( $avail ) && count( $avail ) )
00187 $this->Schema[$tagName]['classesList'] = $avail;
00188 else
00189 $this->Schema[$tagName]['classesList'] = array();
00190 }
00191 else
00192 $this->Schema[$tagName]['classesList'] = array();
00193 }
00194
00195
00196
00197 $allowEmptyParagraph = $ini->variable( 'paragraph', 'AllowEmpty' );
00198 $this->Schema['paragraph']['childrenRequired'] = $allowEmptyParagraph == 'true' ? false : true;
00199
00200
00201 $ini =& eZINI::instance( 'content.ini' );
00202 foreach( array_keys( $this->Schema ) as $tagName )
00203 {
00204 if ( $tagName == 'custom' )
00205 {
00206
00207 foreach( $this->Schema['custom']['tagList'] as $customTagName )
00208 {
00209 if ( $ini->hasVariable( $customTagName, 'CustomAttributes' ) )
00210 {
00211 $avail = $ini->variable( $customTagName, 'CustomAttributes' );
00212 if ( is_array( $avail ) && count( $avail ) )
00213 $this->Schema['custom']['customAttributes'][$customTagName] = $avail;
00214 else
00215 $this->Schema['custom']['customAttributes'][$customTagName] = array();
00216 }
00217 else
00218 $this->Schema['custom']['customAttributes'][$customTagName] = array();
00219 }
00220 }
00221 else
00222 {
00223
00224 if ( $ini->hasVariable( $tagName, 'CustomAttributes' ) )
00225 {
00226 $avail = $ini->variable( $tagName, 'CustomAttributes' );
00227 if ( is_array( $avail ) && count( $avail ) )
00228 $this->Schema[$tagName]['customAttributes'] = $avail;
00229 else
00230 $this->Schema[$tagName]['customAttributes'] = array();
00231 }
00232 else
00233 $this->Schema[$tagName]['customAttributes'] = array();
00234 }
00235 }
00236 }
00237
00238 function &instance()
00239 {
00240 $impl =& $GLOBALS["eZXMLSchemaGlobalInstance"];
00241
00242 $class = get_class( $impl );
00243 if ( $class != "ezxmlschema" )
00244 {
00245 unset( $impl );
00246 $impl = new eZXMLSchema();
00247
00248
00249 $GLOBALS["eZXMLSchemaGlobalInstance"] =& $impl;
00250 }
00251
00252 return $impl;
00253 }
00254
00255
00256 function isInline( $element )
00257 {
00258 if ( is_string( $element ) )
00259 $elementName = $element;
00260 else
00261 $elementName = $element->nodeName;
00262
00263 $isInline = $this->Schema[$elementName]['isInline'];
00264
00265
00266 if ( is_array( $isInline ) && !is_string( $element ) )
00267 {
00268 $isInline = false;
00269 $name = $element->getAttribute( 'name' );
00270
00271 if ( isset( $this->Schema['custom']['isInline'][$name] ) )
00272 {
00273 if ( $this->Schema['custom']['isInline'][$name] == 'true' )
00274 $isInline = true;
00275 }
00276 }
00277 return $isInline;
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 function check( $parent, $child )
00292 {
00293 if ( is_string( $parent ) )
00294 $parentName = $parent;
00295 else
00296 $parentName = $parent->nodeName;
00297
00298 if ( is_string( $child ) )
00299 $childName = $child;
00300 else
00301 $childName = $child->nodeName;
00302
00303 if ( isset( $this->Schema[$childName] ) )
00304 {
00305 $isInline = $this->isInline( $child );
00306
00307 if ( $isInline === true )
00308 {
00309 $allowed = $this->Schema[$parentName]['inlineChildrenAllowed'];
00310 }
00311 elseif ( $isInline === false )
00312 {
00313
00314 if ( $parentName == 'custom' && !is_string( $parent ) &&
00315 $parent->getAttribute( 'inline' ) != 'true' )
00316 {
00317 $allowed = true;
00318 }
00319 else
00320 $allowed = $this->Schema[$parentName]['blockChildrenAllowed'];
00321 }
00322 else
00323 return true;
00324
00325 if ( is_array( $allowed ) )
00326 $allowed = in_array( $childName, $allowed );
00327
00328 if ( !$allowed )
00329 return false;
00330 }
00331 else
00332 {
00333
00334 return null;
00335 }
00336 return true;
00337 }
00338
00339 function childrenRequired( $element )
00340 {
00341
00342
00343
00344 return $this->Schema[$element->nodeName]['childrenRequired'];
00345 }
00346
00347 function hasAttributes( $element )
00348 {
00349
00350
00351
00352 return ( $this->Schema[$element->nodeName]['attributes'] != false );
00353 }
00354
00355 function attributes( $element )
00356 {
00357 return $this->Schema[$element->nodeName]['attributes'];
00358 }
00359
00360 function customAttributes( $element )
00361 {
00362 if ( is_string( $element ) )
00363 {
00364 return $this->Schema[$element]['customAttributes'];
00365 }
00366 else
00367 {
00368 if ( $element->nodeName == 'custom' )
00369 {
00370 $name = $element->getAttribute( 'name' );
00371 if ( $name )
00372 return $this->Schema['custom']['customAttributes'][$name];
00373 }
00374 else
00375 {
00376 return $this->Schema[$element->nodeName]['customAttributes'];
00377 }
00378 }
00379 return array();
00380 }
00381
00382 function attrDefaultValue( $tagName, $attrName )
00383 {
00384 if ( isset( $this->Schema[$tagName]['attributesDefaults'][$attrName] ) )
00385 return $this->Schema[$tagName]['attributesDefaults'][$attrName];
00386 else
00387 return array();
00388 }
00389
00390 function attrDefaultValues( $tagName )
00391 {
00392 if ( isset( $this->Schema[$tagName]['attributesDefaults'] ) )
00393 return $this->Schema[$tagName]['attributesDefaults'];
00394 else
00395 return array();
00396 }
00397
00398 function exists( $element )
00399 {
00400 if ( is_string( $element ) )
00401 {
00402 return isset( $this->Schema[$element] );
00403 }
00404 else
00405 {
00406 if ( $element->nodeName == 'custom' )
00407 {
00408 $name = $element->getAttribute( 'name' );
00409 if ( $name )
00410 return in_array( $name, $this->Schema['custom']['tagList'] );
00411 }
00412 else
00413 {
00414 return isset( $this->Schema[$element->nodeName] );
00415 }
00416 }
00417 return false;
00418 }
00419
00420 function availableElements()
00421 {
00422 return array_keys( $this->Schema );
00423 }
00424
00425 function getClassesList( $tagName )
00426 {
00427 if ( isset( $this->Schema[$tagName]['classesList'] ) )
00428 return $this->Schema[$tagName]['classesList'];
00429 else
00430 return array();
00431 }
00432
00433 function addAvailableClass( $tagName, $class )
00434 {
00435 if ( !isset( $this->Schema[$tagName]['classesList'] ) )
00436 $this->Schema[$tagName]['classesList'] = array();
00437
00438 $this->Schema[$tagName]['classesList'][] = $class;
00439 }
00440
00441 function addCustomAttribute( $element, $attrName )
00442 {
00443 if ( is_string( $element ) )
00444 {
00445 $this->Schema[$element]['customAttributes'][] = $attrName;
00446 }
00447 else
00448 {
00449 if ( $element->nodeName == 'custom' )
00450 {
00451 $name = $element->getAttribute( 'name' );
00452 if ( $name )
00453 $this->Schema['custom']['customAttributes'][$name][] = $attrName;
00454 }
00455 else
00456 {
00457 $this->Schema[$element->nodeName]['customAttributes'][] = $attrName;
00458 }
00459 }
00460 }
00461 }
00462 ?>