[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/datatypes/ezxmltext/handlers/input/ -> ezsimplifiedxmlinputparser.php (source)

   1  <?php
   2  //
   3  // Definition of eZSimplifiedXMLInputParser class
   4  //
   5  // Created on: <27-Mar-2006 15:28:39 ks>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  
  28  //
  29  
  30  if ( !class_exists( 'eZXMLInputParser' ) )
  31      include_once ( 'kernel/classes/datatypes/ezxmltext/ezxmlinputparser.php' );
  32  
  33  class eZSimplifiedXMLInputParser extends eZXMLInputParser
  34  {
  35      var $InputTags = array(
  36          'b'       => array( 'name' => 'strong' ),
  37          'bold'    => array( 'name' => 'strong' ),
  38          'i'       => array( 'name' => 'emphasize' ),
  39          'em'      => array( 'name' => 'emphasize' ),
  40          'h'       => array( 'name' => 'header' ),
  41          'p'       => array( 'name' => 'paragraph' ),
  42          'para'    => array( 'name' => 'paragraph' ),
  43          'br'      => array( 'name' => 'br',
  44                              'noChildren' => true ),
  45          'a'       => array( 'name' => 'link' ),
  46          );
  47  
  48      var $OutputTags = array(
  49          'section'   => array(),
  50  
  51          'embed'     => array( //'parsingHandler' => 'breakInlineFlow',
  52                                'structHandler' => 'appendLineParagraph',
  53                                'publishHandler' => 'publishHandlerEmbed',
  54                                'attributes' => array( 'id' => 'xhtml:id' ),
  55                                'requiredInputAttributes' => array( 'href' ) ),
  56  
  57          'embed-inline'     => array( //'parsingHandler' => 'breakInlineFlow',
  58                                'structHandler' => 'appendLineParagraph',
  59                                'publishHandler' => 'publishHandlerEmbed',
  60                                'attributes' => array( 'id' => 'xhtml:id' ),
  61                                'requiredInputAttributes' => array( 'href' ) ),
  62  
  63          'object'    => array( //'parsingHandler' => 'breakInlineFlow',
  64                                'structHandler' => 'appendLineParagraph',
  65                                'publishHandler' => 'publishHandlerObject',
  66                                'attributes' => array( 'href' => 'image:ezurl_href',
  67                                                       'target' => 'image:ezurl_target',
  68                                                       'ezurl_href' => 'image:ezurl_href',
  69                                                       'ezurl_id' => 'image:ezurl_id',
  70                                                       'ezurl_target' => 'image:ezurl_target' ),
  71                                'requiredInputAttributes' => array( 'id' ) ),
  72  
  73          'table'     => array( 'structHandler' => 'appendParagraph' ),
  74  
  75          'tr'        => array(),
  76  
  77          'td'        => array( 'attributes' => array( 'width' => 'xhtml:width',
  78                                                       'colspan' => 'xhtml:colspan',
  79                                                       'rowspan' => 'xhtml:rowspan' ) ),
  80  
  81          'th'        => array( 'attributes' => array( 'width' => 'xhtml:width',
  82                                                       'colspan' => 'xhtml:colspan',
  83                                                       'rowspan' => 'xhtml:rowspan' ) ),
  84  
  85          'ol'        => array( 'structHandler' => 'structHandlerLists' ),
  86  
  87          'ul'        => array( 'structHandler' => 'structHandlerLists' ),
  88  
  89          'li'        => array( 'autoCloseOn' => array( 'li' ) ),
  90  
  91          'header'    => array( 'autoCloseOn' => array( 'paragraph' ),
  92                                'structHandler' => 'structHandlerHeader' ),
  93  
  94          'paragraph' => array( 'autoCloseOn' => array( 'paragraph' ),
  95                                'publishHandler' => 'publishHandlerParagraph' ),
  96  
  97          'line'      => array(),
  98  
  99          'br'        => array( 'parsingHandler' => 'breakInlineFlow',
 100                                'structHandler' => 'structHandlerBr',
 101                                'attributes' => false ),
 102  
 103          'literal'   => array( 'parsingHandler' => 'parsingHandlerLiteral',
 104                                'structHandler' => 'appendParagraph' ),
 105  
 106          'strong'    => array( 'structHandler' => 'appendLineParagraph' ),
 107  
 108          'emphasize' => array( 'structHandler' => 'appendLineParagraph' ),
 109  
 110          'link'      => array( 'structHandler' => 'appendLineParagraph',
 111                                'publishHandler' => 'publishHandlerLink',
 112                                'attributes' => array( 'title' => 'xhtml:title',
 113                                                       'id' => 'xhtml:id' ),
 114                                'requiredInputAttributes' => array( 'href' ) ),
 115  
 116          'anchor'    => array( 'structHandler' => 'appendLineParagraph' ),
 117  
 118          'custom'    => array( //'parsingHandler' => 'parsingHandlerCustom',
 119                                'structHandler' => 'structHandlerCustom',
 120                                'publishHandler' => 'publishHandlerCustom',
 121                                'requiredInputAttributes' => array( 'name' ) ),
 122  
 123          '#text'     => array( 'structHandler' => 'structHandlerText' )
 124          );
 125  
 126      function eZSimplifiedXMLInputParser( $contentObjectID, $validate = true, $errorLevel = EZ_XMLINPUTPARSER_SHOW_ALL_ERRORS,
 127                                           $parseLineBreaks = false, $removeDefaultAttrs = false )
 128      {
 129          $this->contentObjectID = $contentObjectID;
 130          $this->eZXMLInputParser( $validate, $errorLevel, $parseLineBreaks, $removeDefaultAttrs );
 131      }
 132  
 133      /*
 134          Parsing Handlers (called at pass 1)
 135      */
 136      function &parsingHandlerLiteral( &$element, &$param )
 137      {
 138          $ret = null;
 139          $data =& $param[0];
 140          $pos =& $param[1];
 141  
 142          $tablePos = strpos( $data, '</literal>', $pos );
 143          if ( $tablePos === false )
 144              $tablePos = strpos( $data, '</LITERAL>', $pos );
 145  
 146          if ( $tablePos === false )
 147              return $ret;
 148  
 149          $text = substr( $data, $pos, $tablePos - $pos );
 150  
 151          $textNode = $this->Document->createTextNode( $text );
 152          $element->appendChild( $textNode );
 153  
 154          $pos = $tablePos + strlen( '</literal>' );
 155          $ret = false;
 156  
 157          return $ret;
 158      }
 159  
 160      /*function &parsingHandlerCustom( &$element, &$param )
 161      {
 162          $ret = null;
 163          $name = $element->getAttribute( 'name' );
 164  
 165          $isInline = false;
 166          $ini =& eZINI::instance( 'content.ini' );
 167  
 168          $isInlineTagList = $ini->variable( 'CustomTagSettings', 'IsInline' );
 169          if ( isset( $isInlineTagList[$name] ) )
 170          {
 171              if ( $isInlineTagList[$name] == 'true' )
 172                  $isInline = true;
 173          }
 174  
 175          $element->setAttribute( 'inline', $isInline ? 'true' : 'false' );
 176          return $ret;
 177      }*/
 178  
 179      function &breakInlineFlow( &$element, &$param )
 180      {
 181          // Breaks the flow of inline tags. Used for non-inline tags caught within inline.
 182          // Works for tags with no children only.
 183          $ret = null;
 184          $data =& $param[0];
 185          $pos =& $param[1];
 186          $tagBeginPos =& $param[2];
 187          $parent =& $element->parentNode;
 188  
 189          $wholeTagString = substr( $data, $tagBeginPos, $pos - $tagBeginPos );
 190  
 191          if ( $parent &&
 192               //!$this->XMLSchema->isInline( $element ) &&
 193               $this->XMLSchema->isInline( $parent ) //&&
 194               //!$this->XMLSchema->check( $parent, $element )
 195               )
 196          {
 197              $insertData = '';
 198              $currentParent =& $parent;
 199              end( $this->ParentStack );
 200              do
 201              {
 202                  $stackData = current( $this->ParentStack );
 203                  $currentParentName = $stackData[0];
 204                  $insertData .= "</$currentParentName>";
 205                  $currentParent =& $currentParent->parentNode;
 206                  prev( $this->ParentStack );
 207              }
 208              while( $this->XMLSchema->isInline( $currentParent ) );
 209  
 210              $insertData .= $wholeTagString;
 211  
 212              $currentParent =& $parent;
 213              end( $this->ParentStack );
 214              $appendData = '';
 215              do
 216              {
 217                  $stackData = current( $this->ParentStack );
 218                  $currentParentName = $stackData[0];
 219                  $currentParentAttrString = '';
 220                  if ( $stackData[2] )
 221                      $currentParentAttrString = ' ' . $stackData[2];
 222                  $appendData = "<$currentParentName$currentParentAttrString>" . $appendData;
 223                  $currentParent =& $currentParent->parentNode;
 224                  prev( $this->ParentStack );
 225              }
 226              while( $this->XMLSchema->isInline( $currentParent ) );
 227  
 228              $insertData .= $appendData;
 229  
 230              $data = $insertData . substr( $data, $pos );
 231              $pos = 0;
 232              $parent->removeChild( $element );
 233              $ret = false;
 234          }
 235  
 236          return $ret;
 237      }
 238  
 239      
 240      /*
 241          Structure handlers. (called at pass 2)
 242      */
 243      // Structure handler for inline nodes.
 244      function &appendLineParagraph( &$element, &$newParent )
 245      {
 246          $ret = array();
 247          $parent =& $element->parentNode;
 248          if ( !$parent )
 249          {
 250              return $ret;
 251          }
 252  
 253          $parentName = $parent->nodeName;
 254          $newParentName = $newParent != null ? $newParent->nodeName : '';
 255  
 256          // Correct structure by adding <line> and <paragraph> tags.
 257          if ( $parentName == 'line' || $this->XMLSchema->isInline( $parent ) )
 258          {
 259              return $ret;
 260          }
 261  
 262          if ( $newParentName == 'line' )
 263          {
 264              $parent->removeChild( $element );
 265              $newParent->appendChild( $element );
 266              $newLine =& $newParent;
 267              $ret['result'] =& $newParent;
 268          }
 269          elseif ( $parentName == 'paragraph' )
 270          {
 271              $newLine =& $this->createAndPublishElement( 'line', $ret );
 272              $parent->replaceChild( $newLine, $element );
 273              $newLine->appendChild( $element );
 274              $ret['result'] =& $newLine;
 275          }
 276          elseif ( $newParentName == 'paragraph' )
 277          {
 278              $newLine =& $this->createAndPublishElement( 'line', $ret );
 279              $parent->removeChild( $element );
 280              $newParent->appendChild( $newLine );
 281              $newLine->appendChild( $element );
 282              $ret['result'] =& $newLine;
 283          }
 284          elseif ( $this->XMLSchema->check( $parent, 'paragraph' ) )
 285          {
 286              $newLine =& $this->createAndPublishElement( 'line', $ret );
 287              $newPara =& $this->createAndPublishElement( 'paragraph', $ret );
 288              $parent->replaceChild( $newPara, $element );
 289              $newPara->appendChild( $newLine );
 290              $newLine->appendChild( $element );
 291              $ret['result'] =& $newLine;
 292          }
 293  
 294          return $ret;
 295      }
 296  
 297      // Structure handler for temporary <br> elements
 298      function &structHandlerBr( &$element, &$newParent )
 299      {
 300          $ret = array();
 301          $ret['result'] =& $newParent;
 302          $parent =& $element->parentNode;
 303  
 304          $next =& $element->nextSibling();
 305  
 306          if ( $element->getAttribute( 'ignore' ) != 'true' &&
 307               $next &&
 308               $next->nodeName == 'br' )
 309          {
 310              if ( $this->XMLSchema->check( $parent, 'paragraph' ) )
 311              {
 312                  if ( !$newParent )
 313                  {
 314                      // create paragraph in case of the first empty paragraph
 315                      $newPara =& $this->createAndPublishElement( 'paragraph', $ret );
 316                      $parent->replaceChild( $newPara, $element );
 317                  }
 318                  elseif ( $newParent->nodeName == 'paragraph' ||
 319                           $newParent->nodeName == 'line' )
 320                  {
 321                      // break paragraph or line flow
 322                      unset( $ret );
 323                      $ret = array();
 324  
 325                      // Do not process next <br> tag
 326                      $next->setAttribute( 'ignore', 'true' );
 327  
 328                      // create paragraph in case of the last empty paragraph (not inside section)
 329                      $nextToNext =& $next->nextSibling();
 330                      $tmp =& $parent;
 331                      while( !$nextToNext && $tmp && $tmp->nodeName == 'section' )
 332                      {
 333                          $nextToNext =& $tmp->nextSibling();
 334                          $tmp =& $tmp->parentNode;
 335                      }
 336                      if ( !$nextToNext )
 337                      {
 338                          $newPara =& $this->createAndPublishElement( 'paragraph', $ret );
 339                          $parent->replaceChild( $newPara, $element );
 340                      }
 341                  }
 342              }
 343          }
 344          else
 345          {
 346              if ( $newParent && $newParent->nodeName == 'line' )
 347              {
 348                  $ret['result'] =& $newParent->parentNode;
 349              }
 350          }
 351  
 352          // Trim spaces used for tag indenting
 353          if ( $next && $next->Type == EZ_XML_NODE_TEXT && !trim( $next->content() ) )
 354          {
 355              $nextToNext =& $next->nextSibling();
 356              if ( !$nextToNext || $nextToNext->nodeName != 'br' )
 357              {
 358                  $parent->removeChild( $next );
 359              }
 360          }
 361  
 362          return $ret;
 363      }
 364  
 365      // Structure handler for in-paragraph nodes.
 366      function &appendParagraph( &$element, &$newParent )
 367      {
 368          $ret = array();
 369          $parent =& $element->parentNode;
 370          if ( !$parent )
 371              return $ret;
 372  
 373          $parentName = $parent->nodeName;
 374  
 375          if ( $parentName != 'paragraph' )
 376          {
 377              if ( $newParent && $newParent->nodeName == 'paragraph' )
 378              {
 379                  $parent->removeChild( $element );
 380                  $newParent->appendChild( $element );
 381                  $ret['result'] =& $newParent;
 382              }
 383              if ( $newParent && $newParent->parentNode && $newParent->parentNode->nodeName == 'paragraph' )
 384              {
 385                  $para =& $newParent->parentNode;
 386                  $parent->removeChild( $element );
 387                  $para->appendChild( $element );
 388                  $ret['result'] =& $newParent->parentNode;
 389              }
 390  
 391              if ( $this->XMLSchema->check( $parentName, 'paragraph' ) )
 392              {
 393                  $newPara =& $this->createAndPublishElement( 'paragraph', $ret );
 394                  $parent->replaceChild( $newPara, $element );
 395                  $newPara->appendChild( $element );
 396                  $ret['result'] =& $newPara;
 397              }
 398          }
 399          return $ret;
 400      }
 401  
 402      // Structure handler for 'header' tag.
 403      function &structHandlerHeader( &$element, &$param )
 404      {
 405          $ret = null;
 406          $parent =& $element->parentNode;
 407          $level = $element->getAttribute( 'level' );
 408          if ( !$level )
 409              $level = 1;
 410  
 411          $element->removeAttribute( 'level' );
 412          if ( $level )
 413          {
 414              $sectionLevel = -1;
 415              $current =& $element;
 416              while( $current->parentNode )
 417              {
 418                  $tmp =& $current;
 419                  $current =& $tmp->parentNode;
 420                  if ( $current->nodeName == 'section' )
 421                      $sectionLevel++;
 422                  else
 423                      if ( $current->nodeName == 'td' )
 424                      {
 425                          $sectionLevel++;
 426                          break;
 427                      }
 428              }
 429              if ( $level > $sectionLevel )
 430              {
 431                  $newParent =& $parent;
 432                  for ( $i = $sectionLevel; $i < $level; $i++ )
 433                  {
 434                     $newSection =& $this->Document->createElement( 'section' );
 435                     if ( $i == $sectionLevel )
 436                         $newParent->insertBefore( $newSection, $element );
 437                     else
 438                         $newParent->appendChild( $newSection );
 439                     // Schema check
 440                     if ( !$this->processElementBySchema( $newSection, false ) )
 441                     {
 442                         return $ret;
 443                     }
 444                     $newParent =& $newSection;
 445                     unset( $newSection );
 446                  }
 447                  $elementToMove =& $element;
 448                  while( $elementToMove &&
 449                         $elementToMove->nodeName != 'section' )
 450                  {
 451                      $next =& $elementToMove->nextSibling();
 452                      $parent->removeChild( $elementToMove );
 453                      $newParent->appendChild( $elementToMove );
 454                      $elementToMove =& $next;
 455  
 456                      if ( $elementToMove->nodeName == 'header' &&
 457                           $elementToMove->getAttribute( 'level' ) <= $level ) 
 458                          break;
 459                  }
 460              }
 461              elseif ( $level < $sectionLevel )
 462              {
 463                  $newLevel = $sectionLevel + 1;
 464                  $current =& $element;
 465                  while( $level < $newLevel )
 466                  {
 467                      $tmp =& $current;
 468                      $current =& $tmp->parentNode;
 469                      if ( $current->nodeName == 'section' )
 470                          $newLevel--;
 471                  }
 472                  $elementToMove =& $element;
 473                  while( $elementToMove &&
 474                         $elementToMove->nodeName != 'section' )
 475                  {
 476                      $next =& $elementToMove->nextSibling();
 477                      $parent->removeChild( $elementToMove );
 478                      $current->appendChild( $elementToMove );
 479                      $elementToMove =& $next;
 480  
 481                      if ( $elementToMove->nodeName == 'header' &&
 482                           $elementToMove->getAttribute( 'level' ) <= $level ) 
 483                          break;
 484                  }
 485              }
 486          }
 487          return $ret;
 488      }
 489  
 490      // Structure handler for 'custom' tag.
 491      function &structHandlerCustom( &$element, &$params )
 492      {
 493          $ret = null;
 494          if ( $this->XMLSchema->isInline( $element ) )
 495          {
 496              $ret =& $this->appendLineParagraph( $element, $params );
 497          }
 498          else
 499          {
 500              $ret =& $this->appendParagraph( $element, $params );
 501          }
 502          return $ret;
 503      }
 504  
 505      // Structure handler for 'ul' and 'ol' tags.
 506      function &structHandlerLists( &$element, &$params )
 507      {
 508          $ret = array();
 509          $parent =& $element->parentNode;
 510          $parentName = $parent->nodeName;
 511  
 512          if ( $parentName == 'paragraph' )
 513              return $ret;
 514  
 515          // If we are inside a list
 516          if ( $parentName == 'ol' || $parentName == 'ul' )
 517          {
 518              // If previous 'li' doesn't exist, create it,
 519              // else append to the previous 'li' element.
 520              $prev =& $element->previousSibling();
 521              if ( !$prev )
 522              {
 523                  $li =& $this->Document->createElement( 'li' );
 524                  $parent->insertBefore( $li, $element );
 525                  $parent->removeChild( $element );
 526                  $li->appendChild( $element );
 527              }
 528              else
 529              {
 530                  $lastChild =& $prev->lastChild();
 531                  if ( $lastChild->nodeName != 'paragraph' )
 532                  {
 533                      $para =& $this->Document->createElement( 'paragraph' );
 534                      $parent->removeChild( $element );
 535                      $prev->appendChild( $element );
 536                      $ret['result'] =& $para;
 537                  }
 538                  else
 539                  {
 540                      $parent->removeChild( $element );
 541                      $lastChild->appendChild( $element );
 542                      $ret['result'] =& $lastChild;
 543                  }
 544                  return $ret;
 545              }
 546          }
 547          if ( $parentName == 'li' )
 548          {
 549              $prev =& $element->previousSibling();
 550              if ( $prev )
 551              {
 552                  $parent->removeChild( $element );
 553                  $prev->appendChild( $element );
 554                  $ret['result'] =& $prev;
 555          return $ret;
 556              }
 557          }
 558          $ret =& $this->appendParagraph( $element, $params );
 559  
 560          return $ret;
 561      }
 562  
 563      // Strucutre handler for #text
 564      function &structHandlerText( &$element, &$newParent )
 565      {
 566          $ret = null;
 567          $parent =& $element->parentNode;
 568          if ( !$parent )
 569              return $ret;
 570  
 571          // Remove empty text elements
 572          if ( $element->content() == '' )
 573          {
 574              $parent->removeChild( $element );
 575              return $ret;
 576          }
 577  
 578          $ret =& $this->appendLineParagraph( $element, $newParent );
 579  
 580          // Left trim spaces:
 581          if ( $this->TrimSpaces )
 582          {
 583              $trim = false;
 584              $currentElement =& $element;
 585  
 586              // Check if it is the first element in line
 587              do
 588              {
 589                  $prev =& $currentElement->previousSibling();
 590                  if ( $prev )
 591                      break;
 592  
 593                  $currentElement =& $currentElement->parentNode;
 594                  if ( $currentElement->nodeName == 'line' ||
 595                       $currentElement->nodeName == 'paragraph' )
 596                  {
 597                      $trim = true;
 598                      break;
 599                  }
 600  
 601              }while( $currentElement );
 602  
 603              if ( $trim )
 604              {
 605                  // Trim and remove if empty
 606                  $element->content = ltrim( $element->content );
 607                  if ( $element->content == '' )
 608                  {
 609                      $parent =& $element->parentNode;
 610                      $parent->removeChild( $element );
 611                  }
 612              }
 613          }
 614  
 615          return $ret;
 616      }
 617  
 618      /*
 619          Publish handlers. (called at pass 2)
 620      */
 621      // Publish handler for 'paragraph' element.
 622      function &publishHandlerParagraph( &$element, &$params )
 623      {
 624          $ret = null;
 625          // Removes single line tag
 626          // php5 TODO: childNodes->length
 627          $line =& $element->lastChild();
 628          if ( count( $element->Children ) == 1 && $line->nodeName == 'line' )
 629          {
 630              $element->removeChild( $line );
 631              foreach( array_keys( $line->Children ) as $key )
 632              {
 633                  $newChild =& $line->Children[$key];
 634                  $line->removeChild( $newChild );
 635                  $element->appendChild( $newChild );
 636              }   
 637          }
 638  
 639          return $ret;
 640      }
 641  
 642      // Publish handler for 'link' element.
 643      function &publishHandlerLink( &$element, &$params )
 644      {
 645          $ret = null;
 646  
 647          $href = $element->getAttribute( 'href' );
 648  
 649          if ( $href )
 650          {
 651              if ( ereg( "^ezobject://[0-9]+(#.*)?$", $href ) )
 652              {
 653                  $url = strtok( $href, '#' );
 654                  $anchorName = strtok( '#' );
 655                  $objectID = substr( strrchr( $url, "/" ), 1 );
 656                  $element->setAttribute( 'object_id', $objectID );
 657  
 658                   if ( !in_array( $objectID, $this->linkedObjectIDArray ) )
 659                      $this->linkedObjectIDArray[] = $objectID;
 660              }
 661              elseif ( ereg( "^eznode://.+(#.*)?$" , $href ) )
 662              {
 663                  $objectID = null;
 664                  $url = strtok( $href, '#' );
 665                  $anchorName = strtok( '#' );
 666                  $nodePath = substr( strchr( $url, "/" ), 2 );
 667                  if ( ereg( "^[0-9]+$", $nodePath ) )
 668                  {
 669                      $nodeID = $nodePath;
 670                      $node = eZContentObjectTreeNode::fetch( $nodeID );
 671                      if ( !$node && $this->errorLevel >= 1 )
 672                      {
 673                          $this->isInputValid = false;
 674                          $this->Messages[] = ezi18n( 'kernel/classes/datatypes', 'Node %1 does not exist.',
 675                                                      false, array( $nodeID ) );
 676                      }
 677                      else
 678                      {
 679                          $objectID = $node->attribute( 'contentobject_id' );
 680                      }
 681                  }
 682                  else
 683                  {
 684                      $node = eZContentObjectTreeNode::fetchByURLPath( $nodePath );
 685                      if ( !$node && $this->errorLevel >= 1 )
 686                      {
 687                          $this->isInputValid = false;
 688                          $this->Messages[] = ezi18n( 'kernel/classes/datatypes', 'Node \'%1\' does not exist.',
 689                                                      false, array( $nodePath ) );
 690                      }
 691                      else
 692                      {
 693                          $nodeID = $node->attribute( 'node_id' );
 694                          $objectID = $node->attribute( 'contentobject_id' );
 695                      }
 696                      $element->setAttribute( 'show_path', 'true' );
 697                  }
 698                  $element->setAttribute( 'node_id', $nodeID );
 699  
 700                  if ( $objectID && !in_array( $objectID, $this->linkedObjectIDArray ) )
 701                      $this->linkedObjectIDArray[] = $objectID;
 702              }
 703              elseif ( ereg( "^#.*$" , $href ) )
 704              {
 705                  $anchorName = substr( $href, 1 );
 706              }
 707              else
 708              {
 709                  //washing href. single and double quotes replaced with their urlencoded form
 710                  $href = str_replace( array('\'','"'), array('%27','%22'), $href );
 711  
 712                  $temp = explode( '#', $href );
 713                  $url = $temp[0];
 714                  if ( isset( $temp[1] ) )
 715                      $anchorName = $temp[1];
 716  
 717                  if ( $url )
 718                  {
 719                      // Protection from XSS attack
 720                      if ( preg_match( "/^(java|vb)script:.*/i" , $url ) )
 721                      {
 722                          $this->isInputValid = false;
 723                          if ( $this->errorLevel >= 1 )
 724                              $this->Messages[] = ezi18n( 'kernel/classes/datatypes', "Using scripts in links is not allowed, link '%1' has been removed",
 725                                                          false, array( $url ) );
 726                          $element->removeAttribute( 'href' );
 727                          return $ret;
 728  
 729                      }
 730                      // Check mail address validity
 731                      if ( preg_match( "/^mailto:(.*)/i" , $url, $mailAddr ) )
 732                      {
 733                          include_once ( 'lib/ezutils/classes/ezmail.php' );
 734                          if ( !eZMail::validate( $mailAddr[1] ) )
 735                          {
 736                              $this->isInputValid = false;
 737                              if ( $this->errorLevel >= 1 )
 738                                  $this->Messages[] = ezi18n( 'kernel/classes/datatypes', "Invalid e-mail address: '%1'",
 739                                                              false, array( $mailAddr[1] ) );
 740                              $element->removeAttribute( 'href' );
 741                              return $ret;
 742                          }
 743                          
 744                      }
 745                      // Store urlID instead of href
 746                      $urlID = $this->convertHrefToID( $url );
 747                      if ( $urlID )
 748                      {
 749                          if ( $this->eZPublishVersion >= 3.6 )
 750                              $urlIDAttributeName = 'url_id';
 751                          else
 752                              $urlIDAttributeName = 'id';
 753                          $element->setAttribute( $urlIDAttributeName, $urlID );
 754                      }
 755                  }
 756              }
 757  
 758              if ( isset( $anchorName ) && $anchorName )
 759                      $element->setAttribute( 'anchor_name', $anchorName );
 760  
 761              $element->removeAttribute( 'href' );
 762          }
 763  
 764          return $ret;
 765      }
 766  
 767      function convertHrefToID( $href )
 768      {
 769          $href = str_replace("&amp;", "&", $href );
 770  
 771          $urlID = eZURL::registerURL( $href );
 772  
 773          if ( !in_array( $urlID, $this->urlIDArray ) )
 774               $this->urlIDArray[] = $urlID;
 775  
 776          return $urlID;
 777      }
 778  
 779      // Publish handler for 'embed' element.
 780      function &publishHandlerEmbed( &$element, &$params )
 781      {
 782          $ret = null;
 783          
 784          $href = $element->getAttribute( 'href' );
 785          //washing href. single and double quotes replaced with their urlencoded form
 786          $href = str_replace( array('\'','"'), array('%27','%22'), $href );
 787  
 788          if ( $href != null )
 789          {
 790              if ( ereg( "^ezobject://[0-9]+$" , $href ) )
 791              {
 792                  $objectID = substr( strrchr( $href, "/" ), 1 );
 793  
 794                  // protection from self-embedding
 795                  if ( $objectID == $this->contentObjectID )
 796                  {
 797                      $this->isInputValid = false;
 798                      if ( $this->errorLevel >= 1 )
 799                          $this->Messages[] = ezi18n( 'kernel/classes/datatypes',
 800                                                      'Object %1 can not be embeded to itself.', false, array( $objectID ) );
 801                      $element->removeAttribute( 'href' );
 802                      return $ret;
 803                  }
 804  
 805                  $element->setAttribute( 'object_id', $objectID );
 806  
 807                  if ( !in_array( $objectID, $this->relatedObjectIDArray ) )
 808                      $this->relatedObjectIDArray[] = $objectID;
 809              }
 810              elseif ( ereg( "^eznode://.+$" , $href ) )
 811              {
 812                  $nodePath = substr( strchr( $href, "/" ), 2 );
 813  
 814                  if ( ereg( "^[0-9]+$", $nodePath ) )
 815                  {
 816                      $nodeID = $nodePath;
 817                      $node = eZContentObjectTreeNode::fetch( $nodeID );
 818                      if ( !$node )
 819                      {
 820                          $this->isInputValid = false;
 821  
 822                          if ( $this->errorLevel >= 1 )
 823                              $this->Messages[] = ezi18n( 'kernel/classes/datatypes', 'Node %1 does not exist.',
 824                                                          false, array( $nodeID ) );
 825                          $element->removeAttribute( 'href' );
 826                          return $ret;
 827                      }
 828                  }
 829                  else
 830                  {
 831                      $node = eZContentObjectTreeNode::fetchByURLPath( $nodePath );
 832                      if ( !$node )
 833                      {
 834                          $this->isInputValid = false;
 835  
 836                          if ( $this->errorLevel >= 1 )
 837                              $this->Messages[] = ezi18n( 'kernel/classes/datatypes', 'Node \'%1\' does not exist.',
 838                                                          false, array( $nodePath ) );
 839                          $element->removeAttribute( 'href' );
 840                          return $ret;
 841                      }
 842                      $nodeID = $node->attribute('node_id');
 843                      $element->setAttribute( 'show_path', 'true' );
 844                  }
 845  
 846                  $element->setAttribute( 'node_id', $nodeID );
 847                  $objectID = $node->attribute( 'contentobject_id' );
 848  
 849                  // protection from self-embedding
 850                  if ( $objectID == $this->contentObjectID )
 851                  {
 852                      $this->isInputValid = false;
 853  
 854                      if ( $this->errorLevel >= 1 )
 855                          $this->Messages[] = ezi18n( 'kernel/classes/datatypes', 'Object %1 can not be embeded to itself.',
 856                                                      false, array( $objectID ) );
 857                      $element->removeAttribute( 'href' );
 858                      return $ret;
 859                  }
 860  
 861                  if ( !in_array( $objectID, $this->relatedObjectIDArray ) )
 862                       $this->relatedObjectIDArray[] = $objectID;
 863              }
 864              else
 865              {
 866                  $this->isInputValid = false;
 867                  $this->Messages[] = ezi18n( 'kernel/classes/datatypes', 'Invalid reference in &lt;embed&gt; tag. Note that <embed> tag supports only \'eznode\' and \'ezobject\' protocols.' );
 868                  $element->removeAttribute( 'href' );
 869                  return $ret;
 870              }
 871          }
 872  
 873          $element->removeAttribute( 'href' );
 874          $this->convertCustomAttributes( $element );
 875          return $ret;
 876      }
 877  
 878      // Publish handler for 'object' element.
 879      function &publishHandlerObject( &$element, &$params )
 880      {
 881          $ret = null;
 882  
 883          $objectID = $element->getAttribute( 'id' );
 884          // protection from self-embedding
 885          if ( $objectID == $this->contentObjectID )
 886          {
 887              $this->isInputValid = false;
 888              $this->Messages[] = ezi18n( 'kernel/classes/datatypes',
 889                                          'Object %1 can not be embeded to itself.', false, array( $objectID ) );
 890              return $ret;
 891          }
 892  
 893          if ( !in_array( $objectID, $this->relatedObjectIDArray ) )
 894               $this->relatedObjectIDArray[] = $objectID;
 895  
 896          // If there are any image object with links.
 897          $href = $element->getAttributeNS( $this->Namespaces['image'], 'ezurl_href' );
 898          //washing href. single and double quotes inside url replaced with their urlencoded form
 899          $href = str_replace( array('\'','"'), array('%27','%22'), $href );
 900  
 901          $urlID = $element->getAttributeNS( $this->Namespaces['image'], 'ezurl_id' );
 902  
 903          if ( $href != null )
 904          {
 905              $urlID = eZURL::registerURL( $href );
 906              $element->setAttributeNS( $this->Namespaces['image'], 'image:ezurl_id', $urlID );
 907              $element->removeAttributeNS( $this->Namespaces['image'], 'ezurl_href' );
 908          }
 909  
 910          if ( $urlID != null )
 911          {
 912              $this->urlIDArray[] = $urlID;
 913          }
 914          
 915          $this->convertCustomAttributes( $element );
 916          
 917          return $ret;
 918      }
 919  
 920      // Publish handler for 'custom' element.
 921      function &publishHandlerCustom( &$element, &$params )
 922      {
 923          $ret = null;
 924          
 925          $element->removeAttribute( 'inline' );
 926          $this->convertCustomAttributes( $element );
 927  
 928          return $ret;
 929      }
 930  
 931      function convertCustomAttributes( &$element )
 932      {
 933          $schemaAttrs = $this->XMLSchema->attributes( $element );
 934          $attributes = $element->attributes();
 935      
 936          foreach( $attributes as $attr )
 937          {
 938              if ( !$attr->Prefix && !in_array( $attr->LocalName, $schemaAttrs ) )
 939              {
 940                  $element->setAttributeNS( $this->Namespaces['custom'], 'custom:' . $attr->LocalName, $element->getAttribute( $attr->LocalName ) );
 941                  $element->removeAttribute( $attr->LocalName );
 942              }
 943          }
 944      }
 945  
 946      function getRelatedObjectIDArray()
 947      {
 948          return $this->relatedObjectIDArray;
 949      }
 950  
 951      function getLinkedObjectIDArray()
 952      {
 953          return $this->linkedObjectIDArray;
 954      }
 955  
 956      function getUrlIDArray()
 957      {
 958          return $this->urlIDArray;
 959      }
 960  
 961      var $urlIDArray = array();
 962      var $relatedObjectIDArray = array();
 963      var $linkedObjectIDArray = array();
 964  
 965      // needed for self-embedding protection
 966      var $contentObjectID = 0;
 967  }
 968  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7