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
00031
00032 if ( !class_exists( 'eZXMLInputParser' ) )
00033 include_once( 'kernel/classes/datatypes/ezxmltext/ezxmlinputparser.php' );
00034
00035 class eZSimplifiedXMLInputParser extends eZXMLInputParser
00036 {
00037 var $InputTags = array(
00038 'b' => array( 'name' => 'strong' ),
00039 'bold' => array( 'name' => 'strong' ),
00040 'i' => array( 'name' => 'emphasize' ),
00041 'em' => array( 'name' => 'emphasize' ),
00042 'h' => array( 'name' => 'header' ),
00043 'p' => array( 'name' => 'paragraph' ),
00044 'para' => array( 'name' => 'paragraph' ),
00045 'br' => array( 'name' => 'br',
00046 'noChildren' => true ),
00047 'a' => array( 'name' => 'link' ),
00048 );
00049
00050 var $OutputTags = array(
00051 'section' => array(),
00052
00053 'embed' => array(
00054 'structHandler' => 'appendLineParagraph',
00055 'publishHandler' => 'publishHandlerEmbed',
00056 'attributes' => array( 'id' => 'xhtml:id' ),
00057 'requiredInputAttributes' => array( 'href' ) ),
00058
00059 'embed-inline' => array(
00060 'structHandler' => 'appendLineParagraph',
00061 'publishHandler' => 'publishHandlerEmbed',
00062 'attributes' => array( 'id' => 'xhtml:id' ),
00063 'requiredInputAttributes' => array( 'href' ) ),
00064
00065 'object' => array(
00066 'structHandler' => 'appendLineParagraph',
00067 'publishHandler' => 'publishHandlerObject',
00068 'attributes' => array( 'href' => 'image:ezurl_href',
00069 'target' => 'image:ezurl_target',
00070 'ezurl_href' => 'image:ezurl_href',
00071 'ezurl_id' => 'image:ezurl_id',
00072 'ezurl_target' => 'image:ezurl_target' ),
00073 'requiredInputAttributes' => array( 'id' ) ),
00074
00075 'table' => array( 'structHandler' => 'appendParagraph' ),
00076
00077 'tr' => array(),
00078
00079 'td' => array( 'attributes' => array( 'width' => 'xhtml:width',
00080 'colspan' => 'xhtml:colspan',
00081 'rowspan' => 'xhtml:rowspan' ) ),
00082
00083 'th' => array( 'attributes' => array( 'width' => 'xhtml:width',
00084 'colspan' => 'xhtml:colspan',
00085 'rowspan' => 'xhtml:rowspan' ) ),
00086
00087 'ol' => array( 'structHandler' => 'structHandlerLists' ),
00088
00089 'ul' => array( 'structHandler' => 'structHandlerLists' ),
00090
00091 'li' => array( 'autoCloseOn' => array( 'li' ) ),
00092
00093 'header' => array( 'autoCloseOn' => array( 'paragraph' ),
00094 'structHandler' => 'structHandlerHeader' ),
00095
00096 'paragraph' => array( 'autoCloseOn' => array( 'paragraph' ),
00097 'publishHandler' => 'publishHandlerParagraph' ),
00098
00099 'line' => array(),
00100
00101 'br' => array( 'parsingHandler' => 'breakInlineFlow',
00102 'structHandler' => 'structHandlerBr',
00103 'attributes' => false ),
00104
00105 'literal' => array( 'parsingHandler' => 'parsingHandlerLiteral',
00106 'structHandler' => 'appendParagraph' ),
00107
00108 'strong' => array( 'structHandler' => 'appendLineParagraph' ),
00109
00110 'emphasize' => array( 'structHandler' => 'appendLineParagraph' ),
00111
00112 'link' => array( 'structHandler' => 'appendLineParagraph',
00113 'publishHandler' => 'publishHandlerLink',
00114 'attributes' => array( 'title' => 'xhtml:title',
00115 'id' => 'xhtml:id' ),
00116 'requiredInputAttributes' => array( 'href' ) ),
00117
00118 'anchor' => array( 'structHandler' => 'appendLineParagraph' ),
00119
00120 'custom' => array( 'structHandler' => 'structHandlerCustom',
00121 'publishHandler' => 'publishHandlerCustom',
00122 'requiredInputAttributes' => array( 'name' ) ),
00123
00124 '#text' => array( 'structHandler' => 'structHandlerText' )
00125 );
00126
00127 function eZSimplifiedXMLInputParser( $contentObjectID, $validateErrorLevel = EZ_XMLINPUTPARSER_ERROR_ALL, $detectErrorLevel = EZ_XMLINPUTPARSER_ERROR_ALL,
00128 $parseLineBreaks = false, $removeDefaultAttrs = false )
00129 {
00130 $this->contentObjectID = $contentObjectID;
00131 $this->eZXMLInputParser( $validateErrorLevel, $detectErrorLevel, $parseLineBreaks, $removeDefaultAttrs );
00132 }
00133
00134
00135
00136
00137 function &parsingHandlerLiteral( &$element, &$param )
00138 {
00139 $ret = null;
00140 $data =& $param[0];
00141 $pos =& $param[1];
00142
00143 $tablePos = strpos( $data, '</literal>', $pos );
00144 if ( $tablePos === false )
00145 $tablePos = strpos( $data, '</LITERAL>', $pos );
00146
00147 if ( $tablePos === false )
00148 return $ret;
00149
00150 $text = substr( $data, $pos, $tablePos - $pos );
00151
00152 $textNode = $this->Document->createTextNode( $text );
00153 $element->appendChild( $textNode );
00154
00155 $pos = $tablePos + strlen( '</literal>' );
00156 $ret = false;
00157
00158 return $ret;
00159 }
00160
00161 function &breakInlineFlow( &$element, &$param )
00162 {
00163
00164
00165 $ret = null;
00166 $data =& $param[0];
00167 $pos =& $param[1];
00168 $tagBeginPos =& $param[2];
00169 $parent =& $element->parentNode;
00170
00171 $wholeTagString = substr( $data, $tagBeginPos, $pos - $tagBeginPos );
00172
00173 if ( $parent &&
00174 $this->XMLSchema->isInline( $parent ) )
00175 {
00176 $insertData = '';
00177 $currentParent =& $parent;
00178
00179 end( $this->ParentStack );
00180 do
00181 {
00182 $stackData = current( $this->ParentStack );
00183 $currentParentName = $stackData[0];
00184 $insertData .= "</$currentParentName>";
00185 $currentParent->setAttributeNS( 'http://ez.no/namespaces/ezpublish3/temporary/', 'tmp:new-element', 'true' );
00186 $currentParent =& $currentParent->parentNode;
00187 prev( $this->ParentStack );
00188 }
00189 while( $this->XMLSchema->isInline( $currentParent ) );
00190
00191 $insertData .= $wholeTagString;
00192
00193 $currentParent =& $parent;
00194 end( $this->ParentStack );
00195 $appendData = '';
00196 do
00197 {
00198 $stackData = current( $this->ParentStack );
00199 $currentParentName = $stackData[0];
00200 $currentParentAttrString = '';
00201 if ( $stackData[2] )
00202 $currentParentAttrString = ' ' . $stackData[2];
00203 $currentParentAttrString .= " tmp:new-element='true'";
00204 $appendData = "<$currentParentName$currentParentAttrString>" . $appendData;
00205 $currentParent =& $currentParent->parentNode;
00206 prev( $this->ParentStack );
00207 }
00208 while( $this->XMLSchema->isInline( $currentParent ) );
00209
00210 $insertData .= $appendData;
00211
00212 $data = $insertData . substr( $data, $pos );
00213 $pos = 0;
00214 $parent->removeChild( $element );
00215 $ret = false;
00216 }
00217
00218 return $ret;
00219 }
00220
00221
00222
00223
00224
00225
00226 function &appendLineParagraph( &$element, &$newParent )
00227 {
00228 $ret = array();
00229 $parent =& $element->parentNode;
00230 if ( !$parent )
00231 {
00232 return $ret;
00233 }
00234
00235 $parentName = $parent->nodeName;
00236 $newParentName = $newParent != null ? $newParent->nodeName : '';
00237
00238
00239 if ( $parentName == 'line' || $this->XMLSchema->isInline( $parent ) )
00240 {
00241 return $ret;
00242 }
00243
00244 if ( $newParentName == 'line' )
00245 {
00246 $parent->removeChild( $element );
00247 $newParent->appendChild( $element );
00248 $newLine =& $newParent;
00249 $ret['result'] =& $newParent;
00250 }
00251 elseif ( $parentName == 'paragraph' )
00252 {
00253 $newLine =& $this->createAndPublishElement( 'line', $ret );
00254 $parent->replaceChild( $newLine, $element );
00255 $newLine->appendChild( $element );
00256 $ret['result'] =& $newLine;
00257 }
00258 elseif ( $newParentName == 'paragraph' )
00259 {
00260 $newLine =& $this->createAndPublishElement( 'line', $ret );
00261 $parent->removeChild( $element );
00262 $newParent->appendChild( $newLine );
00263 $newLine->appendChild( $element );
00264 $ret['result'] =& $newLine;
00265 }
00266 elseif ( $this->XMLSchema->check( $parent, 'paragraph' ) )
00267 {
00268 $newLine =& $this->createAndPublishElement( 'line', $ret );
00269 $newPara =& $this->createAndPublishElement( 'paragraph', $ret );
00270 $parent->replaceChild( $newPara, $element );
00271 $newPara->appendChild( $newLine );
00272 $newLine->appendChild( $element );
00273 $ret['result'] =& $newLine;
00274 }
00275
00276 return $ret;
00277 }
00278
00279
00280 function &structHandlerBr( &$element, &$newParent )
00281 {
00282 $ret = array();
00283 $ret['result'] =& $newParent;
00284 $parent =& $element->parentNode;
00285
00286 $next =& $element->nextSibling();
00287
00288 if ( $element->getAttribute( 'ignore' ) != 'true' &&
00289 $next &&
00290 $next->nodeName == 'br' )
00291 {
00292 if ( $this->XMLSchema->check( $parent, 'paragraph' ) )
00293 {
00294 if ( !$newParent )
00295 {
00296
00297 $newPara =& $this->createAndPublishElement( 'paragraph', $ret );
00298 $parent->replaceChild( $newPara, $element );
00299 }
00300 elseif ( $newParent->nodeName == 'paragraph' ||
00301 $newParent->nodeName == 'line' )
00302 {
00303
00304 unset( $ret );
00305 $ret = array();
00306
00307
00308 $next->setAttribute( 'ignore', 'true' );
00309
00310
00311 $nextToNext =& $next->nextSibling();
00312 $tmp =& $parent;
00313 while( !$nextToNext && $tmp && $tmp->nodeName == 'section' )
00314 {
00315 $nextToNext =& $tmp->nextSibling();
00316 $tmp =& $tmp->parentNode;
00317 }
00318 if ( !$nextToNext )
00319 {
00320 $newPara =& $this->createAndPublishElement( 'paragraph', $ret );
00321 $parent->replaceChild( $newPara, $element );
00322 }
00323 }
00324 }
00325 }
00326 else
00327 {
00328 if ( $newParent && $newParent->nodeName == 'line' )
00329 {
00330 $ret['result'] =& $newParent->parentNode;
00331 }
00332 }
00333
00334
00335 if ( $next && $next->Type == EZ_XML_NODE_TEXT && !trim( $next->content() ) )
00336 {
00337 $nextToNext =& $next->nextSibling();
00338 if ( !$nextToNext || $nextToNext->nodeName != 'br' )
00339 {
00340 $parent->removeChild( $next );
00341 }
00342 }
00343 return $ret;
00344 }
00345
00346
00347 function &appendParagraph( &$element, &$newParent )
00348 {
00349 $ret = array();
00350 $parent =& $element->parentNode;
00351 if ( !$parent )
00352 return $ret;
00353
00354 $parentName = $parent->nodeName;
00355
00356 if ( $parentName != 'paragraph' )
00357 {
00358 if ( $newParent && $newParent->nodeName == 'paragraph' )
00359 {
00360 $parent->removeChild( $element );
00361 $newParent->appendChild( $element );
00362 $ret['result'] =& $newParent;
00363 }
00364 elseif ( $newParent && $newParent->parentNode && $newParent->parentNode->nodeName == 'paragraph' )
00365 {
00366 $para =& $newParent->parentNode;
00367 $parent->removeChild( $element );
00368 $para->appendChild( $element );
00369 $ret['result'] =& $newParent->parentNode;
00370 }
00371 elseif ( $this->XMLSchema->check( $parentName, 'paragraph' ) )
00372 {
00373 $newPara =& $this->createAndPublishElement( 'paragraph', $ret );
00374 $parent->replaceChild( $newPara, $element );
00375 $newPara->appendChild( $element );
00376 $ret['result'] =& $newPara;
00377 }
00378 }
00379 return $ret;
00380 }
00381
00382
00383 function &structHandlerHeader( &$element, &$param )
00384 {
00385 $ret = null;
00386 $parent =& $element->parentNode;
00387 $level = $element->getAttribute( 'level' );
00388 if ( !$level )
00389 $level = 1;
00390
00391 $element->removeAttribute( 'level' );
00392 if ( $level )
00393 {
00394 $sectionLevel = -1;
00395 $current =& $element;
00396 while( $current->parentNode )
00397 {
00398 $tmp =& $current;
00399 $current =& $tmp->parentNode;
00400 if ( $current->nodeName == 'section' )
00401 $sectionLevel++;
00402 else
00403 if ( $current->nodeName == 'td' )
00404 {
00405 $sectionLevel++;
00406 break;
00407 }
00408 }
00409 if ( $level > $sectionLevel )
00410 {
00411 if ( $this->StrictHeaders &&
00412 $level - $sectionLevel > 1 )
00413 {
00414 $this->handleError( EZ_XMLINPUTPARSER_ERROR_SCHEMA, "Incorrect headers nesting" );
00415 }
00416
00417 $newParent =& $parent;
00418 for ( $i = $sectionLevel; $i < $level; $i++ )
00419 {
00420 $newSection =& $this->Document->createElement( 'section' );
00421 if ( $i == $sectionLevel )
00422 $newParent->insertBefore( $newSection, $element );
00423 else
00424 $newParent->appendChild( $newSection );
00425
00426 $newParent =& $newSection;
00427 unset( $newSection );
00428 }
00429 $elementToMove =& $element;
00430 while( $elementToMove &&
00431 $elementToMove->nodeName != 'section' )
00432 {
00433 $next =& $elementToMove->nextSibling();
00434 $parent->removeChild( $elementToMove );
00435 $newParent->appendChild( $elementToMove );
00436 $elementToMove =& $next;
00437
00438 if ( $elementToMove->nodeName == 'header' )
00439 {
00440
00441 $headerLevel = $elementToMove->getAttribute( 'level' );
00442 if ( $level - $sectionLevel > 1 )
00443 {
00444 if ( $headerLevel == $level )
00445 {
00446 $newParent2 =& $this->Document->createElement( 'section' );
00447 $newParent->parentNode->appendChild( $newParent2 );
00448 unset( $newParent );
00449 $newParent =& $newParent2;
00450 }
00451 elseif ( $headerLevel < $level )
00452 break;
00453 }
00454 else
00455 if ( $headerLevel <= $level )
00456 break;
00457 }
00458 }
00459 }
00460 elseif ( $level < $sectionLevel )
00461 {
00462 $newLevel = $sectionLevel + 1;
00463 $current =& $element;
00464 while( $level < $newLevel )
00465 {
00466 $tmp =& $current;
00467 $current =& $tmp->parentNode;
00468 if ( $current->nodeName == 'section' )
00469 $newLevel--;
00470 }
00471 $elementToMove =& $element;
00472 while( $elementToMove &&
00473 $elementToMove->nodeName != 'section' )
00474 {
00475 $next =& $elementToMove->nextSibling();
00476 $parent->removeChild( $elementToMove );
00477 $current->appendChild( $elementToMove );
00478 $elementToMove =& $next;
00479
00480 if ( $elementToMove->nodeName == 'header' &&
00481 $elementToMove->getAttribute( 'level' ) <= $level )
00482 break;
00483 }
00484 }
00485 }
00486 return $ret;
00487 }
00488
00489
00490 function &structHandlerCustom( &$element, &$params )
00491 {
00492 $ret = null;
00493 if ( $this->XMLSchema->isInline( $element ) )
00494 {
00495 $ret =& $this->appendLineParagraph( $element, $params );
00496 }
00497 else
00498 {
00499 $ret =& $this->appendParagraph( $element, $params );
00500 }
00501 return $ret;
00502 }
00503
00504
00505 function &structHandlerLists( &$element, &$params )
00506 {
00507 $ret = array();
00508 $parent =& $element->parentNode;
00509 $parentName = $parent->nodeName;
00510
00511 if ( $parentName == 'paragraph' )
00512 return $ret;
00513
00514
00515 if ( $parentName == 'ol' || $parentName == 'ul' )
00516 {
00517
00518
00519 $prev =& $element->previousSibling();
00520 if ( !$prev )
00521 {
00522 $li =& $this->Document->createElement( 'li' );
00523 $parent->insertBefore( $li, $element );
00524 $parent->removeChild( $element );
00525 $li->appendChild( $element );
00526 }
00527 else
00528 {
00529 $lastChild =& $prev->lastChild();
00530 if ( $lastChild->nodeName != 'paragraph' )
00531 {
00532 $para =& $this->Document->createElement( 'paragraph' );
00533 $parent->removeChild( $element );
00534 $prev->appendChild( $element );
00535 $ret['result'] =& $para;
00536 }
00537 else
00538 {
00539 $parent->removeChild( $element );
00540 $lastChild->appendChild( $element );
00541 $ret['result'] =& $lastChild;
00542 }
00543 return $ret;
00544 }
00545 }
00546 if ( $parentName == 'li' )
00547 {
00548 $prev =& $element->previousSibling();
00549 if ( $prev )
00550 {
00551 $parent->removeChild( $element );
00552 $prev->appendChild( $element );
00553 $ret['result'] =& $prev;
00554 return $ret;
00555 }
00556 }
00557 $ret =& $this->appendParagraph( $element, $params );
00558
00559 return $ret;
00560 }
00561
00562
00563 function &structHandlerText( &$element, &$newParent )
00564 {
00565 $ret = null;
00566 $parent =& $element->parentNode;
00567 if ( !$parent )
00568 return $ret;
00569
00570
00571 if ( $element->content() == '' )
00572 {
00573 $parent->removeChild( $element );
00574 return $ret;
00575 }
00576
00577 $ret =& $this->appendLineParagraph( $element, $newParent );
00578
00579
00580 if ( $this->TrimSpaces )
00581 {
00582 $trim = false;
00583 $currentElement =& $element;
00584
00585
00586 do
00587 {
00588 $prev =& $currentElement->previousSibling();
00589 if ( $prev )
00590 break;
00591
00592 $currentElement =& $currentElement->parentNode;
00593 if ( $currentElement->nodeName == 'line' ||
00594 $currentElement->nodeName == 'paragraph' )
00595 {
00596 $trim = true;
00597 break;
00598 }
00599
00600 }while( $currentElement );
00601
00602 if ( $trim )
00603 {
00604
00605 $element->content = ltrim( $element->content );
00606 if ( $element->content == '' )
00607 {
00608 $parent =& $element->parentNode;
00609 $parent->removeChild( $element );
00610 }
00611 }
00612 }
00613
00614 return $ret;
00615 }
00616
00617
00618
00619
00620
00621 function &publishHandlerParagraph( &$element, &$params )
00622 {
00623 $ret = null;
00624
00625
00626 $line =& $element->lastChild();
00627 if ( count( $element->Children ) == 1 && $line->nodeName == 'line' )
00628 {
00629 $element->removeChild( $line );
00630 foreach( array_keys( $line->Children ) as $key )
00631 {
00632 $newChild =& $line->Children[$key];
00633 $line->removeChild( $newChild );
00634 $element->appendChild( $newChild );
00635 }
00636 }
00637
00638 return $ret;
00639 }
00640
00641
00642 function &publishHandlerLink( &$element, &$params )
00643 {
00644 $ret = null;
00645
00646 $href = $element->getAttribute( 'href' );
00647
00648 if ( $href )
00649 {
00650 if ( ereg( "^ezobject://[0-9]+(#.*)?$", $href ) )
00651 {
00652 $url = strtok( $href, '#' );
00653 $anchorName = strtok( '#' );
00654 $objectID = substr( strrchr( $url, "/" ), 1 );
00655 $element->setAttribute( 'object_id', $objectID );
00656
00657 if ( !in_array( $objectID, $this->linkedObjectIDArray ) )
00658 $this->linkedObjectIDArray[] = $objectID;
00659 }
00660 elseif ( ereg( "^eznode://.+(#.*)?$" , $href ) )
00661 {
00662 $objectID = null;
00663 $url = strtok( $href, '#' );
00664 $anchorName = strtok( '#' );
00665 $nodePath = substr( strchr( $url, "/" ), 2 );
00666 if ( ereg( "^[0-9]+$", $nodePath ) )
00667 {
00668 $nodeID = $nodePath;
00669 $node = eZContentObjectTreeNode::fetch( $nodeID, false, false );
00670 if ( !$node )
00671 {
00672 $this->handleError( EZ_XMLINPUTPARSER_ERROR_DATA, "Node '%1' does not exist.",
00673 array( $nodeID ) );
00674 }
00675 else
00676 {
00677 $objectID = $node['contentobject_id'];
00678 }
00679 }
00680 else
00681 {
00682 $node = eZContentObjectTreeNode::fetchByURLPath( $nodePath, false );
00683 if ( !$node )
00684 {
00685 $this->handleError( EZ_XMLINPUTPARSER_ERROR_DATA, "Node '%1' does not exist.",
00686 array( $nodePath ) );
00687 }
00688 else
00689 {
00690 $nodeID = $node['node_id'];
00691 $objectID = $node['contentobject_id'];
00692 }
00693 $element->setAttribute( 'show_path', 'true' );
00694 }
00695 $element->setAttribute( 'node_id', $nodeID );
00696
00697 if ( $objectID && !in_array( $objectID, $this->linkedObjectIDArray ) )
00698 $this->linkedObjectIDArray[] = $objectID;
00699 }
00700 elseif ( ereg( "^#.*$" , $href ) )
00701 {
00702 $anchorName = substr( $href, 1 );
00703 }
00704 else
00705 {
00706
00707 $href = str_replace( array('\'','"'), array('%27','%22'), $href );
00708
00709 $temp = explode( '#', $href );
00710 $url = $temp[0];
00711 if ( isset( $temp[1] ) )
00712 $anchorName = $temp[1];
00713
00714 if ( $url )
00715 {
00716
00717 if ( preg_match( "/^(java|vb)script:.*/i" , $url ) )
00718 {
00719 $this->handleError( EZ_XMLINPUTPARSER_ERROR_DATA, "Using scripts in links is not allowed, link '%1' has been removed",
00720 array( $url ) );
00721
00722 $element->removeAttribute( 'href' );
00723 return $ret;
00724
00725 }
00726
00727 if ( preg_match( "/^mailto:(.*)/i" , $url, $mailAddr ) )
00728 {
00729 include_once( 'lib/ezutils/classes/ezmail.php' );
00730 if ( !eZMail::validate( $mailAddr[1] ) )
00731 {
00732 $this->handleError( EZ_XMLINPUTPARSER_ERROR_DATA, "Invalid e-mail address: '%1'",
00733 array( $mailAddr[1] ) );
00734
00735 $element->removeAttribute( 'href' );
00736 return $ret;
00737 }
00738
00739 }
00740
00741 $urlID = $this->convertHrefToID( $url );
00742 if ( $urlID )
00743 {
00744 if ( $this->eZPublishVersion >= 3.6 )
00745 $urlIDAttributeName = 'url_id';
00746 else
00747 $urlIDAttributeName = 'id';
00748 $element->setAttribute( $urlIDAttributeName, $urlID );
00749 }
00750 }
00751 }
00752
00753 if ( isset( $anchorName ) && $anchorName )
00754 $element->setAttribute( 'anchor_name', $anchorName );
00755
00756 $element->removeAttribute( 'href' );
00757 }
00758
00759 return $ret;
00760 }
00761
00762 function convertHrefToID( $href )
00763 {
00764 $href = str_replace("&", "&", $href );
00765
00766 $urlID = eZURL::registerURL( $href );
00767
00768 if ( !in_array( $urlID, $this->urlIDArray ) )
00769 $this->urlIDArray[] = $urlID;
00770
00771 return $urlID;
00772 }
00773
00774
00775 function &publishHandlerEmbed( &$element, &$params )
00776 {
00777 $ret = null;
00778
00779 $href = $element->getAttribute( 'href' );
00780
00781 $href = str_replace( array('\'','"'), array('%27','%22'), $href );
00782
00783 if ( $href != null )
00784 {
00785 if ( ereg( "^ezobject://[0-9]+$" , $href ) )
00786 {
00787 $objectID = substr( strrchr( $href, "/" ), 1 );
00788
00789
00790 if ( $objectID == $this->contentObjectID )
00791 {
00792 $this->handleError( EZ_XMLINPUTPARSER_ERROR_DATA, 'Object %1 can not be embeded to itself.',
00793 array( $objectID ) );
00794
00795 $element->removeAttribute( 'href' );
00796 return $ret;
00797 }
00798
00799 $element->setAttribute( 'object_id', $objectID );
00800
00801 if ( !in_array( $objectID, $this->relatedObjectIDArray ) )
00802 $this->relatedObjectIDArray[] = $objectID;
00803 }
00804 elseif ( ereg( "^eznode://.+$" , $href ) )
00805 {
00806 $nodePath = substr( strchr( $href, "/" ), 2 );
00807
00808 if ( ereg( "^[0-9]+$", $nodePath ) )
00809 {
00810 $nodeID = $nodePath;
00811 $node = eZContentObjectTreeNode::fetch( $nodeID, false, false );
00812 if ( !$node )
00813 {
00814 $this->handleError( EZ_XMLINPUTPARSER_ERROR_DATA, "Node '%1' does not exist.",
00815 array( $nodeID ) );
00816
00817 $element->removeAttribute( 'href' );
00818 return $ret;
00819 }
00820 }
00821 else
00822 {
00823 $node = eZContentObjectTreeNode::fetchByURLPath( $nodePath, false );
00824 if ( !$node )
00825 {
00826 $this->handleError( EZ_XMLINPUTPARSER_ERROR_DATA, 'Node \'%1\' does not exist.',
00827 array( $nodePath ) );
00828
00829 $element->removeAttribute( 'href' );
00830 return $ret;
00831 }
00832 $nodeID = $node['node_id'];
00833 $element->setAttribute( 'show_path', 'true' );
00834 }
00835
00836 $element->setAttribute( 'node_id', $nodeID );
00837 $objectID = $node['contentobject_id'];
00838
00839
00840 if ( $objectID == $this->contentObjectID )
00841 {
00842 $this->handleError( EZ_XMLINPUTPARSER_ERROR_DATA, 'Object %1 can not be embeded to itself.',
00843 array( $objectID ) );
00844
00845 $element->removeAttribute( 'href' );
00846 return $ret;
00847 }
00848
00849 if ( !in_array( $objectID, $this->relatedObjectIDArray ) )
00850 $this->relatedObjectIDArray[] = $objectID;
00851 }
00852 else
00853 {
00854 $this->isInputValid = false;
00855 $this->Messages[] = ezi18n( 'kernel/classes/datatypes', 'Invalid reference in <embed> tag. Note that <embed> tag supports only \'eznode\' and \'ezobject\' protocols.' );
00856 $element->removeAttribute( 'href' );
00857 return $ret;
00858 }
00859 }
00860
00861 $element->removeAttribute( 'href' );
00862 $this->convertCustomAttributes( $element );
00863 return $ret;
00864 }
00865
00866
00867 function &publishHandlerObject( &$element, &$params )
00868 {
00869 $ret = null;
00870
00871 $objectID = $element->getAttribute( 'id' );
00872
00873 if ( $objectID == $this->contentObjectID )
00874 {
00875 $this->isInputValid = false;
00876 $this->Messages[] = ezi18n( 'kernel/classes/datatypes',
00877 'Object %1 can not be embeded to itself.', false, array( $objectID ) );
00878 return $ret;
00879 }
00880
00881 if ( !in_array( $objectID, $this->relatedObjectIDArray ) )
00882 $this->relatedObjectIDArray[] = $objectID;
00883
00884
00885 $href = $element->getAttributeNS( $this->Namespaces['image'], 'ezurl_href' );
00886
00887 $href = str_replace( array('\'','"'), array('%27','%22'), $href );
00888
00889 $urlID = $element->getAttributeNS( $this->Namespaces['image'], 'ezurl_id' );
00890
00891 if ( $href != null )
00892 {
00893 $urlID = eZURL::registerURL( $href );
00894 $element->setAttributeNS( $this->Namespaces['image'], 'image:ezurl_id', $urlID );
00895 $element->removeAttributeNS( $this->Namespaces['image'], 'ezurl_href' );
00896 }
00897
00898 if ( $urlID != null )
00899 {
00900 $this->urlIDArray[] = $urlID;
00901 }
00902
00903 $this->convertCustomAttributes( $element );
00904
00905 return $ret;
00906 }
00907
00908
00909 function &publishHandlerCustom( &$element, &$params )
00910 {
00911 $ret = null;
00912
00913 $element->removeAttribute( 'inline' );
00914 $this->convertCustomAttributes( $element );
00915
00916 return $ret;
00917 }
00918
00919 function convertCustomAttributes( &$element )
00920 {
00921 $schemaAttrs = $this->XMLSchema->attributes( $element );
00922 $attributes = $element->attributes();
00923
00924 foreach( $attributes as $attr )
00925 {
00926 if ( !$attr->Prefix && !in_array( $attr->LocalName, $schemaAttrs ) )
00927 {
00928 $element->setAttributeNS( $this->Namespaces['custom'], 'custom:' . $attr->LocalName, $element->getAttribute( $attr->LocalName ) );
00929 $element->removeAttribute( $attr->LocalName );
00930 }
00931 }
00932 }
00933
00934 function getRelatedObjectIDArray()
00935 {
00936 return $this->relatedObjectIDArray;
00937 }
00938
00939 function getLinkedObjectIDArray()
00940 {
00941 return $this->linkedObjectIDArray;
00942 }
00943
00944 function getUrlIDArray()
00945 {
00946 return $this->urlIDArray;
00947 }
00948
00949 var $urlIDArray = array();
00950 var $relatedObjectIDArray = array();
00951 var $linkedObjectIDArray = array();
00952
00953
00954 var $contentObjectID = 0;
00955 }
00956 ?>