[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZDHTMLXMLInput class 4 // 5 // Created on: <27-Mar-2006 15:28:40 ks> 6 // 7 // Copyright (C) 1999-2006 eZ systems as. All rights reserved. 8 // 9 10 /*! \file ezdhtmlxmlinput.php 11 */ 12 13 /*! 14 \class eZDHTMLXMLInput 15 \brief The class eZDHTMLXMLInput does 16 17 */ 18 19 include_once ( 'extension/ezdhtml/ezxmltext/common/ezxmlschema.php' ); 20 include_once ( 'extension/ezdhtml/ezxmltext/common/ezxmlinputparser.php' ); 21 22 class eZDHTMLInputParser extends eZXMLInputParser 23 { 24 var $InputTags = array( 25 'section' => array( 'name' => 'section' ), 26 'b' => array( 'name' => 'strong' ), 27 'bold' => array( 'name' => 'strong' ), 28 'strong' => array( 'name' => 'strong' ), 29 'i' => array( 'name' => 'emphasize' ), 30 'em' => array( 'name' => 'emphasize' ), 31 'img' => array( 'nameHandler' => 'tagNameImg', 32 'noChildren' => true ), 33 'h1' => array( 'nameHandler' => 'tagNameHeader' ), 34 'h2' => array( 'nameHandler' => 'tagNameHeader' ), 35 'h3' => array( 'nameHandler' => 'tagNameHeader' ), 36 'h4' => array( 'nameHandler' => 'tagNameHeader' ), 37 'h5' => array( 'nameHandler' => 'tagNameHeader' ), 38 'h6' => array( 'nameHandler' => 'tagNameHeader' ), 39 'p' => array( 'name' => 'paragraph' ), 40 'br' => array( 'name' => 'br', 41 'noChildren' => true ), 42 'span' => array( 'nameHandler' => 'tagNameSpan' ), 43 'table' => array( 'nameHandler' => 'tagNameTable' ), 44 'td' => array( 'name' => 'td' ), 45 'tr' => array( 'name' => 'tr' ), 46 'th' => array( 'name' => 'th' ), 47 'ol' => array( 'name' => 'ol' ), 48 'ul' => array( 'name' => 'ul' ), 49 'li' => array( 'name' => 'li' ), 50 'a' => array( 'name' => 'link' ), 51 'link' => array( 'name' => 'link' ), 52 // Stubs for not supported tags. 53 'tbody' => array( 'name' => '' ) 54 ); 55 56 var $OutputTags = array( 57 'section' => array(), 58 59 'embed' => array( 'structHandler' => 'appendLineParagraph', 60 'publishHandler' => 'publishHandlerEmbed', 61 'attributes' => array( 'alt' => 'size', 62 'html_id' => 'xhtml:id' ) ), 63 64 'embed-inline' => array( 'structHandler' => 'appendLineParagraph', 65 'publishHandler' => 'publishHandlerEmbed', 66 'attributes' => array( 'alt' => 'size', 67 'html_id' => 'xhtml:id' ) ), 68 69 'object' => array( 'structHandler' => 'structHandlerObject', 70 'publishHandler' => 'publishHandlerObject', 71 'attributes' => array( 'alt' => 'size' ) ), 72 73 'table' => array( 'structHandler' => 'appendParagraph', 74 'publishHandler' => 'publishHandlerTable', 75 'attributes' => array( 'border' => false, 76 'ezborder' => 'border' ) ), 77 78 'tr' => array(), 79 80 'td' => array( 'attributes' => array( 'width' => 'xhtml:width', 81 'colspan' => 'xhtml:colspan', 82 'rowspan' => 'xhtml:rowspan' ) ), 83 84 'th' => array( 'attributes' => array( 'width' => 'xhtml:width', 85 'colspan' => 'xhtml:colspan', 86 'rowspan' => 'xhtml:rowspan' ) ), 87 88 'ol' => array( 'structHandler' => 'structHandlerLists' ), 89 90 'ul' => array( 'structHandler' => 'structHandlerLists' ), 91 92 'li' => array( 'autoCloseOn' => array( 'li' ) ), 93 94 'header' => array( 'initHandler' => 'initHandlerHeader', 95 'autoCloseOn' => array( 'paragraph' ), 96 'structHandler' => 'structHandlerHeader' ), 97 98 'paragraph' => array( 'autoCloseOn' => array( 'paragraph' ), 99 'structHandler' => 'structHandlerParagraph' ), 100 101 'line' => array(), 102 103 'br' => array( 'parsingHandler' => 'breakInlineFlow', 104 'structHandler' => 'structHandlerBr', 105 'attributes' => false ), 106 107 'literal' => array( 'parsingHandler' => 'parsingHandlerLiteral', 108 'structHandler' => 'appendParagraph', 109 'attributes' => array( 'class' => false, 110 'title' => 'class' ) ), 111 112 'strong' => array( 'structHandler' => 'appendLineParagraph' ), 113 114 'emphasize' => array( 'structHandler' => 'appendLineParagraph' ), 115 116 'link' => array( 'structHandler' => 'appendLineParagraph', 117 'publishHandler' => 'publishHandlerLink', 118 'attributes' => array( 'title' => 'xhtml:title', 119 'id' => 'xhtml:id' ) ), 120 121 'anchor' => array( 'structHandler' => 'appendLineParagraph' ), 122 123 'custom' => array( //'parsingHandler' => 'parsingHandlerCustom', 124 'initHandler' => 'initHandlerCustom', 125 'structHandler' => 'structHandlerCustom', 126 'attributes' => array( 'title' => 'name' ) ), 127 128 '#text' => array( 'structHandler' => 'structHandlerText' ) 129 ); 130 131 function eZDHTMLInputParser( $validate = false, $errorLevel = EZ_XMLINPUTPARSER_SHOW_NO_ERRORS, 132 $parseLineBreaks = false, $removeDefaultAttrs = true ) 133 { 134 $this->eZXMLInputParser( $validate, $errorLevel, $parseLineBreaks, $removeDefaultAttrs ); 135 136 if ( $this->eZPublishVersion >= 3.8 ) 137 { 138 $ini =& eZINI::instance( 'content.ini' ); 139 $this->anchorAsAttribute = $ini->variable( 'header', 'AnchorAsAttribute' ) == 'disabled' ? false : true; 140 } 141 142 if ( $this->eZPublishVersion < 3.9 ) 143 { 144 // Literal was inline before 3.9 145 $this->OutputTags['literal']['structHandler'] = 'appendLineParagraph'; 146 } 147 } 148 149 /* 150 Name handlers (called at pass 1) 151 */ 152 function &tagNameSpan( $tagName, &$attributes ) 153 { 154 $name = ''; 155 if ( isset( $attributes['type'] ) && $attributes['type'] == 'custom' ) 156 { 157 $name = 'custom'; 158 $attributes['children_required'] = 'true'; 159 } 160 else if ( isset( $attributes['style'] ) ) 161 { 162 if ( strstr( $attributes['style'], 'font-weight: bold;' ) ) 163 $name = 'strong'; 164 elseif ( strstr( $attributes['style'], 'font-style: italic;' ) ) 165 $name = 'emphasize'; 166 } 167 return $name; 168 } 169 170 function &tagNameHeader( $tagName, &$attributes ) 171 { 172 $attributes['level'] = $tagName[1]; 173 $name = 'header'; 174 return $name; 175 } 176 177 function &tagNameTable( $tagName, &$attributes ) 178 { 179 $name = 'table'; 180 181 if ( isset( $attributes['id'] ) ) 182 { 183 if ( $attributes['id'] == 'literal' ) 184 { 185 $name = 'literal'; 186 return $name; 187 } 188 elseif ( $attributes['id'] == 'custom' ) 189 { 190 $name = 'custom'; 191 return $name; 192 } 193 } 194 if ( isset( $attributes['border'] ) && !isset( $attributes['ezborder'] ) ) 195 { 196 $attributes['ezborder'] = $attributes['border']; 197 } 198 return $name; 199 } 200 201 function &tagNameImg( $tagName, &$attributes ) 202 { 203 $name = ''; 204 if ( isset( $attributes['id'] ) ) 205 { 206 if ( strstr( $attributes['id'], 'eZObject_' ) || strstr( $attributes['id'], 'eZNode_' ) ) 207 if ( $this->eZPublishVersion >= 3.6 ) 208 { 209 if ( $this->eZPublishVersion >= 3.8 && 210 isset( $attributes['inline'] ) && 211 $attributes['inline'] == 'true' ) 212 { 213 $name = 'embed-inline'; 214 } 215 else 216 { 217 $name = 'embed'; 218 } 219 } 220 else 221 { 222 $name = 'object'; 223 } 224 } 225 if ( isset( $attributes['type'] ) ) 226 { 227 if ( $attributes['type'] == 'anchor' ) 228 $name = 'anchor'; 229 elseif ( $attributes['type'] == 'custom' ) 230 $name = 'custom'; 231 } 232 233 return $name; 234 } 235 236 /* 237 Parsing Handlers (called at pass 1) 238 */ 239 function &parsingHandlerLiteral( &$element, &$param ) 240 { 241 $ret = null; 242 $data =& $param[0]; 243 $pos =& $param[1]; 244 245 $tablePos = strpos( $data, '</table>', $pos ); 246 if ( $tablePos === false ) 247 $tablePos = strpos( $data, '</TABLE>', $pos ); 248 249 if ( $tablePos === false ) 250 return $ret; 251 252 $text = substr( $data, $pos, $tablePos - $pos ); 253 254 $text = preg_replace( "/\s*<\s?\/?t[drh|(body)].*?>/i", "", $text ); 255 256 $text = preg_replace( "/^<p.*?>/i", "", $text ); 257 258 $text = preg_replace( "/<\/\s?p>/i", "", $text ); 259 260 $text = preg_replace( "/<p.*?>/i", "\n\n", $text ); 261 $text = preg_replace( "/<\/?\s?br.*?>/i", "\n", $text ); 262 263 $text = $this->entitiesDecode( $text ); 264 $text = $this->convertNumericEntities( $text ); 265 266 $textNode = $this->Document->createTextNode( $text ); 267 $element->appendChild( $textNode ); 268 269 $pos = $tablePos + strlen( '</table>' ); 270 $ret = false; 271 272 return $ret; 273 } 274 275 function &breakInlineFlow( &$element, &$param ) 276 { 277 // Breaks the flow of inline tags. Used for non-inline tags caught within inline. 278 // Works for tags with no children only. 279 $ret = null; 280 $data =& $param[0]; 281 $pos =& $param[1]; 282 $tagBeginPos =& $param[2]; 283 $parent =& $element->parentNode; 284 285 $wholeTagString = substr( $data, $tagBeginPos, $pos - $tagBeginPos ); 286 287 if ( $parent && 288 //!$this->XMLSchema->isInline( $element ) && 289 $this->XMLSchema->isInline( $parent ) //&& 290 //!$this->XMLSchema->check( $parent, $element ) 291 ) 292 { 293 $insertData = ''; 294 $currentParent =& $parent; 295 end( $this->ParentStack ); 296 do 297 { 298 $stackData = current( $this->ParentStack ); 299 $currentParentName = $stackData[0]; 300 $insertData .= "</$currentParentName>"; 301 $currentParent =& $currentParent->parentNode; 302 prev( $this->ParentStack ); 303 } 304 while( $this->XMLSchema->isInline( $currentParent ) ); 305 306 $insertData .= $wholeTagString; 307 308 $currentParent =& $parent; 309 end( $this->ParentStack ); 310 $appendData = ''; 311 do 312 { 313 $stackData = current( $this->ParentStack ); 314 $currentParentName = $stackData[0]; 315 $currentParentAttrString = ''; 316 if ( $stackData[2] ) 317 $currentParentAttrString = ' ' . $stackData[2]; 318 $appendData = "<$currentParentName$currentParentAttrString>" . $appendData; 319 $currentParent =& $currentParent->parentNode; 320 prev( $this->ParentStack ); 321 } 322 while( $this->XMLSchema->isInline( $currentParent ) ); 323 324 $insertData .= $appendData; 325 326 $data = $insertData . substr( $data, $pos ); 327 $pos = 0; 328 $parent->removeChild( $element ); 329 $ret = false; 330 } 331 332 return $ret; 333 } 334 335 /* 336 Init handlers. (called at pass 2) 337 */ 338 // Init handler for 'Custom' element. 339 function &initHandlerCustom( &$element, &$params ) 340 { 341 $ret = null; 342 if ( $this->XMLSchema->isInline( $element ) ) 343 return $ret; 344 345 $tr =& $element->firstChild(); 346 if ( !$tr || $tr->nodeName != 'tr' ) 347 return $ret; 348 349 $td =& $tr->firstChild(); 350 if ( $td->nodeName != 'td' ) 351 return $ret; 352 353 // php5 TODO: children 354 foreach( array_keys( $td->Children ) as $key ) 355 { 356 $child =& $td->Children[$key]; 357 $td->removeChild( $child ); 358 $element->appendChild( $child ); 359 } 360 $element->removeChild( $tr ); 361 362 return $ret; 363 } 364 365 function &initHandlerHeader( &$element, &$params ) 366 { 367 $ret = null; 368 369 if ( $this->anchorAsAttribute ) 370 { 371 $anchorElement =& $element->firstChild(); 372 if ( $anchorElement->nodeName == 'anchor' ) 373 { 374 $element->setAttribute( 'anchor_name', $anchorElement->getAttribute( 'name' ) ); 375 $element->removeChild( $anchorElement ); 376 } 377 } 378 379 return $ret; 380 } 381 382 /* 383 Structure handlers. (called at pass 2) 384 */ 385 // Structure handler for inline nodes. 386 function &appendLineParagraph( &$element, &$newParent ) 387 { 388 $ret = array(); 389 $parent =& $element->parentNode; 390 if ( !$parent ) 391 return $ret; 392 393 $parentName = $parent->nodeName; 394 $next =& $element->nextSibling(); 395 $newParentName = $newParent != null ? $newParent->nodeName : ''; 396 397 // Correct schema by adding <line> and <paragraph> tags. 398 if ( $parentName == 'line' || $this->XMLSchema->isInline( $parent ) ) 399 { 400 return $ret; 401 } 402 403 if ( $newParentName == 'line' ) 404 { 405 $parent->removeChild( $element ); 406 $newParent->appendChild( $element ); 407 $ret['result'] =& $newParent; 408 } 409 elseif ( $parentName == 'paragraph' ) 410 { 411 $newLine =& $this->createAndPublishElement( 'line', $ret ); 412 $parent->replaceChild( $newLine, $element ); 413 $newLine->appendChild( $element ); 414 $ret['result'] =& $newLine; 415 } 416 elseif ( $newParentName == 'paragraph' ) 417 { 418 $newLine =& $this->createAndPublishElement( 'line', $ret ); 419 $parent->removeChild( $element ); 420 $newParent->appendChild( $newLine ); 421 $newLine->appendChild( $element ); 422 $ret['result'] =& $newLine; 423 } 424 elseif ( $this->XMLSchema->check( $parent, 'paragraph' ) ) 425 { 426 $newLine =& $this->createAndPublishElement( 'line', $ret ); 427 $newPara =& $this->createAndPublishElement( 'paragraph', $ret ); 428 $parent->replaceChild( $newPara, $element ); 429 $newPara->appendChild( $newLine ); 430 $newLine->appendChild( $element ); 431 $ret['result'] =& $newLine; 432 } 433 return $ret; 434 } 435 436 // Structure handler for temporary <br> elements 437 function &structHandlerBr( &$element, &$newParent ) 438 { 439 $ret = array(); 440 if ( $newParent && $newParent->nodeName == 'line' ) 441 { 442 $ret['result'] =& $newParent->parentNode; 443 } 444 return $ret; 445 446 } 447 448 // Structure handler for in-paragraph nodes. 449 function &appendParagraph( &$element, &$newParent ) 450 { 451 $ret = array(); 452 $parent =& $element->parentNode; 453 if ( !$parent ) 454 return $ret; 455 456 $parentName = $parent->nodeName; 457 458 if ( $parentName != 'paragraph' ) 459 { 460 if ( $newParent && $newParent->nodeName == 'paragraph' ) 461 { 462 $parent->removeChild( $element ); 463 $newParent->appendChild( $element ); 464 return $newParent; 465 } 466 if ( $newParent && $newParent->parentNode && $newParent->parentNode->nodeName == 'paragraph' ) 467 { 468 $para =& $newParent->parentNode; 469 $parent->removeChild( $element ); 470 $para->appendChild( $element ); 471 return $newParent->parentNode; 472 } 473 474 if ( $this->XMLSchema->check( $parentName, 'paragraph' ) ) 475 { 476 $newPara =& $this->createAndPublishElement( 'paragraph', $ret ); 477 $parent->replaceChild( $newPara, $element ); 478 $newPara->appendChild( $element ); 479 $ret['result'] =& $newPara; 480 } 481 } 482 return $ret; 483 } 484 485 // Strucutre handler for #text 486 function &structHandlerText( &$element, &$newParent ) 487 { 488 $ret = null; 489 $parent =& $element->parentNode; 490 491 // Remove empty text elements 492 if ( $element->content() == '' ) 493 { 494 $parent->removeChild( $element ); 495 return $ret; 496 } 497 498 /*if ( !$newParent && $parent->nodeName == 'section' ) 499 { 500 $parent->removeChild( $element ); 501 }*/ 502 503 $ret =& $this->appendLineParagraph( $element, $newParent ); 504 505 // Fix for italic/bold styles in Mozilla. 506 $addStrong = $addEmph = null; 507 $myParent =& $element->parentNode; 508 while( $myParent ) 509 { 510 $style = $myParent->getAttribute( 'style' ); 511 if ( $style && $addStrong !== false && strstr( $style, 'font-weight: bold;' ) ) 512 { 513 $addStrong = true; 514 } 515 if ( $style && $addEmph !== false && strstr( $style, 'font-style: italic;' ) ) 516 { 517 $addEmph = true; 518 } 519 520 if ( $myParent->nodeName == 'strong' ) 521 { 522 $addStrong = false; 523 } 524 elseif ( $myParent->nodeName == 'emphasize' ) 525 { 526 $addEmph = false; 527 } 528 elseif ( $myParent->nodeName == 'td' || $myParent->nodeName == 'th' || $myParent->nodeName == 'section' ) 529 { 530 break; 531 } 532 $tmp =& $myParent; 533 $myParent =& $tmp->parentNode; 534 } 535 536 $parent =& $element->parentNode; 537 if ( $addEmph ) 538 { 539 $emph =& $this->Document->createElement( 'emphasize' ); 540 $parent->insertBefore( $emph, $element ); 541 $parent->removeChild( $element ); 542 $emph->appendChild( $element ); 543 } 544 if ( $addStrong ) 545 { 546 $strong =& $this->Document->createElement( 'strong' ); 547 $parent->insertBefore( $strong, $element ); 548 $parent->removeChild( $element ); 549 $strong->appendChild( $element ); 550 } 551 552 // Left trim spaces: 553 if ( $this->TrimSpaces ) 554 { 555 $trim = false; 556 $currentElement =& $element; 557 558 // Check if it is the first element in line 559 do 560 { 561 $prev =& $currentElement->previousSibling(); 562 if ( $prev ) 563 break; 564 565 $currentElement =& $currentElement->parentNode; 566 if ( $currentElement->nodeName == 'line' || 567 $currentElement->nodeName == 'paragraph' ) 568 { 569 $trim = true; 570 break; 571 } 572 573 }while( $currentElement ); 574 575 if ( $trim ) 576 { 577 // Trim and remove if empty 578 $element->content = ltrim( $element->content ); 579 if ( $element->content == '' ) 580 { 581 $parent =& $element->parentNode; 582 $parent->removeChild( $element ); 583 } 584 } 585 } 586 587 return $ret; 588 } 589 590 // Structure handler for 'header' tag. 591 function &structHandlerHeader( &$element, &$param ) 592 { 593 $ret = null; 594 $parent =& $element->parentNode; 595 $level = $element->getAttribute( 'level' ); 596 if ( !$level ) 597 $level = 1; 598 599 $element->removeAttribute( 'level' ); 600 if ( $level ) 601 { 602 $sectionLevel = -1; 603 $current =& $element; 604 while( $current->parentNode ) 605 { 606 $tmp =& $current; 607 $current =& $tmp->parentNode; 608 if ( $current->nodeName == 'section' ) 609 $sectionLevel++; 610 else 611 if ( $current->nodeName == 'td' ) 612 { 613 $sectionLevel++; 614 break; 615 } 616 } 617 if ( $level > $sectionLevel ) 618 { 619 $newParent =& $parent; 620 for ( $i = $sectionLevel; $i < $level; $i++ ) 621 { 622 $newSection =& $this->Document->createElement( 'section' ); 623 if ( $i == $sectionLevel ) 624 $newParent->insertBefore( $newSection, $element ); 625 else 626 $newParent->appendChild( $newSection ); 627 // Schema check 628 if ( !$this->processElementBySchema( $newSection, false ) ) 629 { 630 return $ret; 631 } 632 $newParent =& $newSection; 633 unset( $newSection ); 634 } 635 $elementToMove =& $element; 636 while( $elementToMove && 637 $elementToMove->nodeName != 'section' ) 638 { 639 $next =& $elementToMove->nextSibling(); 640 $parent->removeChild( $elementToMove ); 641 $newParent->appendChild( $elementToMove ); 642 $elementToMove =& $next; 643 644 if ( $elementToMove->nodeName == 'header' && 645 $elementToMove->getAttribute( 'level' ) <= $level ) 646 break; 647 } 648 } 649 elseif ( $level < $sectionLevel ) 650 { 651 $newLevel = $sectionLevel + 1; 652 $current =& $element; 653 while( $level < $newLevel ) 654 { 655 $tmp =& $current; 656 $current =& $tmp->parentNode; 657 if ( $current->nodeName == 'section' ) 658 $newLevel--; 659 } 660 $elementToMove =& $element; 661 while( $elementToMove && 662 $elementToMove->nodeName != 'section' ) 663 { 664 $next =& $elementToMove->nextSibling(); 665 $parent->removeChild( $elementToMove ); 666 $current->appendChild( $elementToMove ); 667 $elementToMove =& $next; 668 669 if ( $elementToMove->nodeName == 'header' && 670 $elementToMove->getAttribute( 'level' ) <= $level ) 671 break; 672 } 673 } 674 } 675 return $ret; 676 } 677 678 // Structure handler for 'custom' tag. 679 function &structHandlerCustom( &$element, &$params ) 680 { 681 $ret = null; 682 $isInline = $this->XMLSchema->isInline( $element ); 683 if ( $isInline ) 684 { 685 $ret =& $this->appendLineParagraph( $element, $params ); 686 687 $value = $element->getAttribute( 'value' ); 688 if ( $value ) 689 { 690 $value = $this->washText( $value ); 691 $textNode = $this->Document->createTextNode( $value ); 692 $element->appendChild( $textNode ); 693 } 694 } 695 else 696 { 697 $ret =& $this->appendParagraph( $element, $params ); 698 } 699 return $ret; 700 } 701 702 // Structure handler for 'ul' and 'ol' tags. 703 function &structHandlerLists( &$element, &$params ) 704 { 705 $ret = null; 706 $parent =& $element->parentNode; 707 $parentName = $parent->nodeName; 708 709 if ( $parentName == 'paragraph' ) 710 return $ret; 711 712 // If we are inside a list 713 if ( $parentName == 'ol' || $parentName == 'ul' ) 714 { 715 // If previous 'li' doesn't exist, create it, 716 // else append to the previous 'li' element. 717 $prev =& $element->previousSibling(); 718 if ( !$prev ) 719 { 720 $li =& $this->Document->createElement( 'li' ); 721 $parent->insertBefore( $li, $element ); 722 $parent->removeChild( $element ); 723 $li->appendChild( $element ); 724 } 725 else 726 { 727 $lastChild =& $prev->lastChild(); 728 if ( $lastChild->nodeName != 'paragraph' ) 729 { 730 $para =& $this->Document->createElement( 'paragraph' ); 731 $parent->removeChild( $element ); 732 $prev->appendChild( $element ); 733 } 734 else 735 { 736 $parent->removeChild( $element ); 737 $lastChild->appendChild( $element ); 738 } 739 } 740 } 741 if ( $parentName == 'li' ) 742 { 743 $prev =& $element->previousSibling(); 744 if ( $prev ) 745 { 746 $parent->removeChild( $element ); 747 $prev->appendChild( $element ); 748 } 749 } 750 $ret =& $this->appendParagraph( $element, $params ); 751 return $ret; 752 } 753 754 /*/ Structure handler for 'object' tag. 755 function &structHandlerObject( &$element, &$params ) 756 { 757 $ret = null; 758 $parent =& $element->parentNode; 759 if ( $parent->nodeName == 'link' ) 760 { 761 $attr = $parent->getAttribute( 'id' ); 762 if ( $attr ) 763 $element->setAttributeNS( 'http://ez.no/namespaces/ezpublish3/image/', 'image:ezurl_id', $attr ); 764 765 $attr = $parent->getAttribute( 'target' ); 766 if ( $attr ) 767 $element->setAttributeNS( 'http://ez.no/namespaces/ezpublish3/image/', 'image:ezurl_target', $attr ); 768 769 $attr = $parent->getAttribute( 'href' ); 770 if ( $attr ) 771 $element->setAttributeNS( 'http://ez.no/namespaces/ezpublish3/image/', 'image:ezurl_href', $attr ); 772 773 $parent->removeChild( $element ); 774 $grandParent =& $parent->parentNode; 775 $grandParent->insertBefore( $element, $parent ); 776 $grandParent->removeChild( $parent ); 777 } 778 $ret =& $this->appendLineParagraph( $element, $params ); 779 return $ret; 780 }*/ 781 782 // Structure handler for 'paragraph' element. 783 function &structHandlerParagraph( &$element, &$params ) 784 { 785 $ret = null; 786 787 if ( $element->getAttribute( 'ezparser-new-element' ) == 'true' && 788 !$element->hasChildren() ) 789 { 790 $element->parentNode->removeChild( $element ); 791 return $ret; 792 } 793 794 // Removes single line tag 795 // php5 TODO: childNodes->length 796 $line =& $element->lastChild(); 797 if ( count( $element->Children ) == 1 && $line->nodeName == 'line' ) 798 { 799 $element->removeChild( $line ); 800 foreach( array_keys( $line->Children ) as $key ) 801 { 802 $newChild =& $line->Children[$key]; 803 $line->removeChild( $newChild ); 804 $element->appendChild( $newChild ); 805 } 806 } 807 808 return $ret; 809 } 810 811 /* 812 Publish handlers. (called at pass 2) 813 */ 814 // Publish handler for 'link' element. 815 function &publishHandlerLink( &$element, &$params ) 816 { 817 $ret = null; 818 819 $href = $element->getAttribute( 'href' ); 820 if ( $href ) 821 { 822 $objectID = false; 823 if ( $this->eZPublishVersion > 3.5 && 824 preg_match( "@^ezobject://([0-9]+)/?(#[^/]*)?/?@i", $href, $matches ) ) 825 { 826 $objectID = $matches[1]; 827 if ( isset( $matches[2] ) ) 828 $anchorName = substr( $matches[2], 1 ); 829 $element->setAttribute( 'object_id', $objectID ); 830 } 831 elseif ( $this->eZPublishVersion > 3.5 && 832 preg_match( "@^eznode://([^/#]+)/?(#[^/]*)?/?@i", $href, $matches ) ) 833 { 834 $nodePath = $matches[1]; 835 if ( isset( $matches[2] ) ) 836 $anchorName = substr( $matches[2], 1 ); 837 838 if ( ereg( "^[0-9]+$", $nodePath ) ) 839 { 840 $nodeID = $nodePath; 841 $node = eZContentObjectTreeNode::fetch( $nodeID ); 842 if ( !$node ) 843 { 844 $this->Messages[] = ezx18n( 'extension/ezdhtml', 'handlers/input', 'Node %1 does not exist.', false, array( $nodeID ) ); 845 } 846 } 847 else 848 { 849 $node = eZContentObjectTreeNode::fetchByURLPath( $nodePath ); 850 if ( !$node ) 851 { 852 $this->Messages[] = ezx18n( 'extension/ezdhtml', 'handlers/input', 'Node \'%1\' does not exist.', false, array( $nodePath ) ); 853 } 854 else 855 { 856 $nodeID = $node->attribute( 'node_id' ); 857 } 858 $element->setAttribute( 'show_path', 'true' ); 859 } 860 861 if ( isset( $nodeID ) && $nodeID ) 862 { 863 $element->setAttribute( 'node_id', $nodeID ); 864 865 $node = eZContentObjectTreeNode::fetch( $nodeID ); 866 $objectID = $node->attribute( 'contentobject_id' ); 867 } 868 } 869 elseif ( $this->eZPublishVersion > 3.5 && 870 ereg( "^#.*$" , $href ) ) 871 { 872 $anchorName = substr( $href, 1 ); 873 } 874 else 875 { 876 if ( $this->eZPublishVersion > 3.5 ) 877 { 878 $temp = explode( '#', $href ); 879 $url = $temp[0]; 880 if ( isset( $temp[1] ) ) 881 $anchorName = $temp[1]; 882 } 883 else 884 $url = $href; 885 886 if ( $url ) 887 { 888 // Protection from XSS attack 889 if ( preg_match( "/^(java|vb)script:.*/i" , $url ) ) 890 { 891 $this->isInputValid = false; 892 $this->Messages[] = "Using scripts in links is not allowed, link '$url' has been removed"; 893 $element->removeAttribute( 'href' ); 894 return $ret; 895 } 896 897 // Check mail address validity 898 if ( preg_match( "/^mailto:(.*)/i" , $url, $mailAddr ) ) 899 { 900 include_once ( 'lib/ezutils/classes/ezmail.php' ); 901 if ( !eZMail::validate( $mailAddr[1] ) ) 902 { 903 $this->isInputValid = false; 904 if ( $this->errorLevel >= 0 ) 905 $this->Messages[] = ezi18n( 'kernel/classes/datatypes', "Invalid e-mail address: '%1'", 906 false, array( $mailAddr[1] ) ); 907 $element->removeAttribute( 'href' ); 908 return $ret; 909 } 910 911 } 912 // Store urlID instead of href 913 $urlID = $this->convertHrefToID( $url ); 914 if ( $urlID ) 915 { 916 if ( $this->eZPublishVersion >= 3.6 ) 917 $urlIDAttributeName = 'url_id'; 918 else 919 $urlIDAttributeName = 'id'; 920 $element->setAttribute( $urlIDAttributeName, $urlID ); 921 } 922 } 923 } 924 925 if ( $objectID && !in_array( $objectID, $this->linkedObjectIDArray ) ) 926 $this->linkedObjectIDArray[] = $objectID; 927 928 if ( isset( $anchorName ) && $anchorName ) 929 $element->setAttribute( 'anchor_name', $anchorName ); 930 } 931 return $ret; 932 } 933 934 function convertHrefToID( $href ) 935 { 936 $href = str_replace("&", "&", $href ); 937 938 $urlID = eZURL::registerURL( $href ); 939 940 if ( !in_array( $urlID, $this->urlIDArray ) ) 941 $this->urlIDArray[] = $urlID; 942 943 return $urlID; 944 } 945 946 // Publish handler for 'table' element. 947 function &publishHandlerTable( &$element, &$params ) 948 { 949 $ret = null; 950 951 // Trying to convert CSS rules to XML attributes 952 // (for the case of pasting from external source) 953 954 $style = $element->getAttribute( 'style' ); 955 if ( $style ) 956 { 957 $styleArray = explode( ';', $style ); 958 foreach( $styleArray as $styleString ) 959 { 960 if ( !$styleString ) 961 continue; 962 963 list( $styleName, $styleValue ) = explode( ':', $styleString ); 964 $styleName = trim( $styleName ); 965 $styleValue = trim( $styleValue ); 966 if ( $styleName ) 967 { 968 $element->setAttribute( $styleName, $styleValue ); 969 } 970 } 971 } 972 return $ret; 973 } 974 975 // Publish handler for 'embed' element. 976 function &publishHandlerEmbed( &$element, &$params ) 977 { 978 $ret = null; 979 $ID = $element->getAttribute( 'id' ); 980 if ( $ID ) 981 { 982 $objectID = false; 983 $element->removeAttribute( 'id' ); 984 if ( strstr( $ID, 'eZObject_' ) ) 985 { 986 $objectID = substr( $ID, strpos( $ID, '_' ) + 1 ); 987 $element->setAttribute( 'object_id', $objectID ); 988 } 989 if ( strstr( $ID, 'eZNode_' ) ) 990 { 991 $nodeID = substr( $ID, strpos( $ID, '_' ) + 1 ); 992 $element->setAttribute( 'node_id', $nodeID ); 993 994 $node = eZContentObjectTreeNode::fetch( $nodeID ); 995 if ( $node ) 996 $objectID = $node->attribute( 'contentobject_id' ); 997 } 998 999 if ( $objectID && !in_array( $objectID, $this->embeddedObjectIDArray ) ) 1000 $this->embeddedObjectIDArray[] = $objectID; 1001 } 1002 $align = $element->getAttribute( 'align' ); 1003 if ( $align && $align == 'middle' ) 1004 { 1005 $element->setAttribute( 'align', 'center' ); 1006 } 1007 //$this->convertCustomAttributes( $element ); 1008 return $ret; 1009 } 1010 1011 /*/ Publish handler for 'object' element. 1012 function &publishHandlerObject( &$element, &$params ) 1013 { 1014 $ret = null; 1015 $objectID = $element->getAttribute( 'id' ); 1016 if ( $objectID ) 1017 { 1018 $objectID = substr( $objectID, strpos( $objectID, '_' ) + 1 ); 1019 $element->setAttribute( 'id', $objectID ); 1020 } 1021 $align = $element->getAttribute( 'align' ); 1022 if ( $align && $align == 'middle' ) 1023 { 1024 $element->setAttribute( 'align', 'center' ); 1025 } 1026 1027 $href = $element->getAttributeNS( 'http://ez.no/namespaces/ezpublish3/image/', 'ezurl_href' ); 1028 if ( $href ) 1029 { 1030 $urlID = $this->convertHrefToID( $href ); 1031 $element->setAttributeNS( 'http://ez.no/namespaces/ezpublish3/image/', 'image:ezurl_id', $urlID ); 1032 $element->removeAttributeNS( 'http://ez.no/namespaces/ezpublish3/image/', 'ezurl_href' ); 1033 } 1034 1035 //$this->convertCustomAttributes( $element ); 1036 return $ret; 1037 }*/ 1038 1039 function processAttributesBySchema( &$element, $verbose = true ) 1040 { 1041 // custom attributes conversion 1042 $attr = $element->getAttribute( 'customattributes' ); 1043 if ( $attr ) 1044 { 1045 $attrArray = explode( 'attribute_separation', $attr ); 1046 foreach( $attrArray as $attr ) 1047 { 1048 list( $attrName, $attrValue ) = explode( '|', $attr ); 1049 $element->setAttributeNS( 'http://ez.no/namespaces/ezpublish3/custom/', 'custom:' . $attrName, $attrValue ); 1050 } 1051 } 1052 1053 parent::processAttributesBySchema( $element, $verbose ); 1054 } 1055 1056 function getUrlIDArray() 1057 { 1058 return $this->urlIDArray; 1059 } 1060 1061 function getEmbeddedObjectIDArray() 1062 { 1063 return $this->embeddedObjectIDArray; 1064 } 1065 1066 function getLinkedObjectIDArray() 1067 { 1068 return $this->linkedObjectIDArray; 1069 } 1070 1071 var $urlIDArray = array(); 1072 var $embeddedObjectIDArray = array(); 1073 var $linkedObjectIDArray = array(); 1074 1075 var $anchorAsAttribute = true; 1076 } 1077 ?>
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 |