[ 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/ -> ezxmltexttype.php (source)

   1  <?php
   2  //
   3  // Definition of eZXMLTextType class
   4  //
   5  // Created on: <06-May-2002 20:02:55 bf>
   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    \class eZXMLTextType ezxmltexttype
  31    \ingroup eZDatatype
  32    \brief The class eZXMLTextType haneles XML formatted datatypes
  33  
  34  The formatted datatypes store the data in XML. A typical example of this is shown below:
  35  \code
  36  <?xml version="1.0" encoding="utf-8" ?>
  37  <section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
  38           xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/">
  39  <header>This is a level one header</header>
  40  <paragraph>
  41  This is a <emphasize>block</emphasize> of text.
  42  </paragraph>
  43    <section>
  44    <header class="foo">This is a level two header has classification "foo"</header>
  45    <paragraph>
  46    This is the second paragraph with <bold class="foo">bold text which has classification "foo"</bold>
  47    </paragraph>
  48    <header>This is a level two header</header>
  49    <paragraph>
  50      <line>Paragraph can have table</line>
  51      <table class="foo" border='1' width='100%'>
  52        <tr>
  53          <th class="foo"><paragraph>table header of class "foo"</paragraph></th>
  54          <td xhtml:width="66" xhtml:colspan="2" xhtml:rowspan="2">
  55            <paragraph>table cell text</paragraph>
  56          </td>
  57        </tr>
  58      </table>
  59    </paragraph>
  60    <paragraph>
  61      <line>This is the first line with <anchor name="first">anchor</anchor></line>
  62      <line>This is the second line with <link target="_self" id="1">link</link></line>
  63      <line>This is the third line.</line>
  64    </paragraph>
  65    <paragraph>
  66      <ul class="foo">
  67         <li>List item 1</li>
  68         <li>List item 2</li>
  69      </ul>
  70    </paragraph>
  71    <paragraph>
  72      <ol>
  73         <li>Ordered list item 1</li>
  74         <li>ordered list item 2</li>
  75      </ol>
  76    </paragraph>
  77    <paragraph>
  78      <line>Paragraph can have both inline custom tag <custom name="myInlineTag">text</custom> and block custom tag</line>
  79      <custom name="myBlockTag">
  80        <paragraph>
  81          block text
  82        </paragraph>
  83      </custom>
  84    </paragraph>
  85    <paragraph>
  86      Paragraph can have image object with link <object id="55" size="large" align="center" image:ezurl_id="4" />
  87    </paragraph>
  88    <paragraph>
  89      You can use literal tag to write html code if you have done some changes in override system.
  90      <literal class="html">&lt;font color=&quot;red&quot;&gt;red text&lt;/font&gt;</literal>
  91    </paragraph>
  92    <header>This is a level two header</header>
  93    </section>
  94  </section>
  95  
  96  \endcode
  97  
  98  */
  99  
 100  include_once ( "kernel/classes/ezdatatype.php" );
 101  include_once ( "lib/ezxml/classes/ezxml.php" );
 102  include_once ( "kernel/common/template.php" );
 103  include_once ( 'lib/eztemplate/classes/eztemplateincludefunction.php' );
 104  include_once ( 'kernel/classes/datatypes/ezurl/ezurl.php' );
 105  include_once ( 'kernel/classes/datatypes/ezurl/ezurlobjectlink.php' );
 106  include_once ( "lib/ezutils/classes/ezini.php" );
 107  
 108  
 109  define( "EZ_DATATYPESTRING_XML_TEXT", "ezxmltext" );
 110  define( 'EZ_DATATYPESTRING_XML_TEXT_COLS_FIELD', 'data_int1' );
 111  define( 'EZ_DATATYPESTRING_XML_TEXT_COLS_VARIABLE', '_ezxmltext_cols_' );
 112  
 113  // The timestamp of the format for eZ publish 3.0.
 114  define( 'EZ_XMLTEXT_VERSION_30_TIMESTAMP', 1045487555 );
 115  // Contains the timestamp of the current xml format, if the stored
 116  // timestamp is less than this it needs to be upgraded until it is correct.
 117  define( 'EZ_XMLTEXT_VERSION_TIMESTAMP', EZ_XMLTEXT_VERSION_30_TIMESTAMP );
 118  
 119  class eZXMLTextType extends eZDataType
 120  {
 121      function eZXMLTextType()
 122      {
 123          $this->eZDataType( EZ_DATATYPESTRING_XML_TEXT, ezi18n( 'kernel/classes/datatypes', "XML block", 'Datatype name' ),
 124                             array( 'serialize_supported' => true ) );
 125      }
 126  
 127      /*!
 128       Set class attribute value for template version
 129      */
 130      function initializeClassAttribute( &$classAttribute )
 131      {
 132          if ( $classAttribute->attribute( EZ_DATATYPESTRING_XML_TEXT_COLS_FIELD ) == null )
 133              $classAttribute->setAttribute( EZ_DATATYPESTRING_XML_TEXT_COLS_FIELD, 10 );
 134          $classAttribute->store();
 135      }
 136  
 137      /*!
 138       Sets the default value.
 139      */
 140      function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
 141      {
 142          if ( $currentVersion != false )
 143          {
 144              $xmlText = eZXMLTextType::rawXMLText( $originalContentObjectAttribute );
 145              $contentObjectAttribute->setAttribute( "data_text", $xmlText );
 146          }
 147          else
 148          {
 149          }
 150      }
 151  
 152      /*!
 153       Validates the input and returns true if the input was
 154       valid for this datatype.
 155      */
 156      function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
 157      {
 158          /// Get object for input validation
 159          // To do: only validate, not save data
 160          $xmlText =& $this->objectAttributeContent( $contentObjectAttribute );
 161          $input =& $xmlText->attribute( 'input' );
 162          $isValid = $input->validateInput( $http, $base, $contentObjectAttribute );
 163  
 164          return $isValid;
 165      }
 166  
 167      function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
 168      {
 169          $column = $base . EZ_DATATYPESTRING_XML_TEXT_COLS_VARIABLE . $classAttribute->attribute( 'id' );
 170          if ( $http->hasPostVariable( $column ) )
 171          {
 172              $columnValue = $http->postVariable( $column );
 173              $classAttribute->setAttribute( EZ_DATATYPESTRING_XML_TEXT_COLS_FIELD,  $columnValue );
 174              return true;
 175          }
 176          return false;
 177      }
 178  
 179      /*!
 180       Fetches the http post var string input and stores it in the data instance.
 181      */
 182      function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
 183      {
 184          // To do: Data should be saved here.
 185          /*$xmlText =& $this->objectAttributeContent( $contentObjectAttribute );
 186          $input =& $xmlText->attribute( 'input' );
 187          $isValid = $input->validateInput( $http, $base, $contentObjectAttribute );*/
 188          return true;
 189      }
 190  
 191      /*!
 192       Initializes the object attribute with some data after object attribute is already stored.
 193       It means that for initial version you allready have an attribute_id and you can store data somewhere using this id.
 194       \note Default implementation does nothing.
 195      */
 196      function postInitializeObjectAttribute( &$objectAttribute, $currentVersion, &$originalContentObjectAttribute )
 197      {
 198      }
 199  
 200      /*!
 201       Store the content.
 202      */
 203      function storeObjectAttribute( &$attribute )
 204      {
 205          $attribute->setAttribute( 'data_int', EZ_XMLTEXT_VERSION_TIMESTAMP );
 206      }
 207  
 208      /*!
 209       \reimp
 210      */
 211      function &viewTemplate( &$contentobjectAttribute )
 212      {
 213          $template = $this->DataTypeString;
 214          $suffix = $this->viewTemplateSuffix( $contentobjectAttribute );
 215          if ( $suffix )
 216              $template .= '_' . $suffix;
 217          return $template;
 218      }
 219  
 220      /*!
 221       \reimp
 222      */
 223      function &editTemplate( &$contentobjectAttribute )
 224      {
 225          $template = $this->DataTypeString;
 226          $suffix = $this->editTemplateSuffix( $contentobjectAttribute );
 227          if ( $suffix )
 228              $template .= '_' . $suffix;
 229          return $template;
 230      }
 231  
 232      /*!
 233       \reimp
 234      */
 235      function &informationTemplate( &$contentobjectAttribute )
 236      {
 237          $template = $this->DataTypeString;
 238          $suffix = $this->informationTemplateSuffix( $contentobjectAttribute );
 239          if ( $suffix )
 240              $template .= '_' . $suffix;
 241          return $template;
 242      }
 243  
 244      /*!
 245       \reimp
 246      */
 247      function &viewTemplateSuffix( &$contentobjectAttribute )
 248      {
 249          $content =& $this->objectAttributeContent( $contentobjectAttribute );
 250          $outputHandler =& $content->attribute( 'output' );
 251          $suffix = $outputHandler->viewTemplateSuffix( $contentobjectAttribute );
 252          return $suffix;
 253      }
 254  
 255      /*!
 256       \reimp
 257      */
 258      function &editTemplateSuffix( &$contentobjectAttribute )
 259      {
 260          $content =& $this->objectAttributeContent( $contentobjectAttribute );
 261          $inputHandler =& $content->attribute( 'input' );
 262          $suffix =& $inputHandler->editTemplateSuffix( $contentobjectAttribute );
 263          return $suffix;
 264      }
 265  
 266      /*!
 267       \reimp
 268      */
 269      function &informationTemplateSuffix( &$contentobjectAttribute )
 270      {
 271          $content =& $this->objectAttributeContent( $contentobjectAttribute );
 272          $inputHandler =& $content->attribute( 'input' );
 273          $suffix =& $inputHandler->informationTemplateSuffix( $contentobjectAttribute );
 274          return $suffix;
 275      }
 276  
 277      /*!
 278       \return the RAW XML text from the attribute \a $contentobjectAttribute.
 279               If the XML format is older than the current one it will
 280               be upgraded to the current before being returned.
 281      */
 282      function rawXMLText( &$contentObjectAttribute )
 283      {
 284          $text = $contentObjectAttribute->attribute( 'data_text' );
 285          $timestamp = $contentObjectAttribute->attribute( 'data_int' );
 286          if ( $timestamp < EZ_XMLTEXT_VERSION_30_TIMESTAMP )
 287          {
 288              include_once ( 'lib/ezi18n/classes/eztextcodec.php' );
 289              $charset = 'UTF-8';
 290              $codec =& eZTextCodec::instance( false, $charset );
 291              $text = $codec->convertString( $text );
 292              $timestamp = EZ_XMLTEXT_VERSION_30_TIMESTAMP;
 293          }
 294          return $text;
 295      }
 296  
 297      /*!
 298       \static
 299       \return the XML structure in \a $domDocument as text.
 300               It will take of care of the necessary charset conversions
 301               for content storage.
 302      */
 303      function domString( &$domDocument )
 304      {
 305          $ini =& eZINI::instance();
 306          $xmlCharset = $ini->variable( 'RegionalSettings', 'ContentXMLCharset' );
 307          if ( $xmlCharset == 'enabled' )
 308          {
 309              include_once ( 'lib/ezi18n/classes/eztextcodec.php' );
 310              $charset = eZTextCodec::internalCharset();
 311          }
 312          else if ( $xmlCharset == 'disabled' )
 313              $charset = true;
 314          else
 315              $charset = $xmlCharset;
 316          if ( $charset !== true )
 317          {
 318              include_once ( 'lib/ezi18n/classes/ezcharsetinfo.php' );
 319              $charset = eZCharsetInfo::realCharsetCode( $charset );
 320          }
 321          $domString = $domDocument->toString( $charset );
 322  
 323          $eZXMLini =& eZINI::instance( 'ezxml.ini' );
 324          if ( $eZXMLini->hasVariable( 'InputSettings', 'AllowNumericEntities' ) )
 325          {
 326              if ( $eZXMLini->variable( 'InputSettings', 'AllowNumericEntities' ) == 'true' )
 327              {
 328                  $domString = preg_replace( '/&amp;#([0-9]+);/', '&#\1;', $domString );
 329              }
 330          }
 331  
 332          return $domString;
 333      }
 334  
 335      /*!
 336       Returns the content.
 337      */
 338      function &objectAttributeContent( &$contentObjectAttribute )
 339      {
 340          include_once ( 'kernel/classes/datatypes/ezxmltext/ezxmltext.php' );
 341          $xmlText = new eZXMLText( eZXMLTextType::rawXMLText( $contentObjectAttribute ), $contentObjectAttribute );
 342          return $xmlText;
 343      }
 344  
 345      /*!
 346       Returns the meta data used for storing search indeces.
 347      */
 348      function metaData( $contentObjectAttribute )
 349      {
 350          $metaData = "";
 351  
 352          $xml = new eZXML();
 353          $dom =& $xml->domTree( eZXMLTextType::rawXMLText( $contentObjectAttribute ) );
 354  
 355          if ( $dom )
 356          {
 357              $textNodes = $dom->elementsByName( "#text" );
 358              if ( is_array( $textNodes ) )
 359              {
 360                  foreach ( $textNodes as $node )
 361                  {
 362                      $metaData .= " " . $node->content();
 363                  }
 364              }
 365          }
 366          return $metaData;
 367      }
 368      /*!
 369       \return string representation of an contentobjectattribute data for simplified export
 370  
 371      */
 372      function toString( $contentObjectAttribute )
 373      {
 374          return $contentObjectAttribute->attribute( 'data_text' );
 375      }
 376  
 377      function fromString( &$contentObjectAttribute, $string )
 378      {
 379          return $contentObjectAttribute->setAttribute( 'data_text', $string );
 380      }
 381  
 382  
 383      /*!
 384       Returns the text.
 385      */
 386      function title( &$contentObjectAttribute )
 387      {
 388          $text = eZXMLTextType::rawXMLText( $contentObjectAttribute );
 389          // parse xml
 390          include_once ( 'lib/ezxml/classes/ezxml.php' );
 391          $xml = new eZXML();
 392          $document =& $xml->domTree( $text );
 393  
 394          // Get first text element of xml
 395          if ( !$document )
 396              return $text;
 397  
 398          $root =& $document->root();
 399          $section =& $root->firstChild();
 400          $textDom = false;
 401          if ( $section )
 402              $textDom =& $section->firstChild();
 403  
 404          if ( $textDom and $textDom->hasChildren() )
 405          {
 406              $textDomContent =& $textDom->firstChild();
 407              $text = $textDomContent->content();
 408          }
 409          elseif ( $textDom )
 410          {
 411              $text = $textDom->content();
 412          }
 413  
 414          return $text;
 415      }
 416  
 417      function hasObjectAttributeContent( &$contentObjectAttribute )
 418      {
 419          $content = $this->objectAttributeContent( $contentObjectAttribute );
 420          if ( is_object( $content ) and
 421               !$content->attribute( 'is_empty' ) )
 422              return true;
 423          return false;
 424      }
 425  
 426      /*!
 427       \reimp
 428      */
 429      function isIndexable()
 430      {
 431          return true;
 432      }
 433  
 434      /*!
 435       \reimp
 436      */
 437      function isInformationCollector()
 438      {
 439          return false;
 440      }
 441  
 442      /*!
 443       \reimp
 444       Makes sure content/datatype/.../ezxmltags/... are included.
 445      */
 446      function templateList()
 447      {
 448          return array( array( 'regexp',
 449                               '#^content/datatype/[a-zA-Z]+/ezxmltags/#' ) );
 450      }
 451  
 452      /*!
 453       \reimp
 454      */
 455      function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
 456      {
 457          $textColumns = $classAttribute->attribute( EZ_DATATYPESTRING_XML_TEXT_COLS_FIELD );
 458          $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'text-column-count', $textColumns ) );
 459      }
 460  
 461      /*!
 462       \reimp
 463      */
 464      function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
 465      {
 466          $textColumns = $attributeParametersNode->elementTextContentByName( 'text-column-count' );
 467          $classAttribute->setAttribute( EZ_DATATYPESTRING_XML_TEXT_COLS_FIELD, $textColumns );
 468      }
 469  
 470      /*!
 471      */
 472      function customObjectAttributeHTTPAction( $http, $action, &$contentObjectAttribute )
 473      {
 474          $content =& $this->objectAttributeContent( $contentObjectAttribute );
 475          $inputHandler =& $content->attribute( 'input' );
 476          $inputHandler->customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute );
 477      }
 478  
 479      /*!
 480       \reimp
 481       \return a DOM representation of the content object attribute
 482      */
 483      function serializeContentObjectAttribute( &$package, &$objectAttribute )
 484      {
 485          include_once ( 'lib/ezxml/classes/ezxml.php' );
 486  
 487          $DOMNode = $this->createContentObjectAttributeDOMNode( $objectAttribute );
 488  
 489          $xml = new eZXML();
 490          $doc =& $xml->domTree( $objectAttribute->attribute( 'data_text' ) );
 491  
 492          if ( $doc )
 493          {
 494              /* For all links found in the XML, do the following:
 495               * - add "href" attribute fetching it from ezurl table.
 496               * - remove "id" attribute.
 497               */
 498              {
 499                  include_once ( 'kernel/classes/datatypes/ezurl/ezurlobjectlink.php' );
 500                  include_once ( 'kernel/classes/datatypes/ezurl/ezurl.php' );
 501  
 502                  $links =& $doc->elementsByName( 'link' );
 503                  $embeds =& $doc->elementsByName( 'embed' );
 504                  $objects =& $doc->elementsByName( 'object' );
 505                  $embedsInline =& $doc->elementsByName( 'embed-inline' );
 506  
 507                  $allTags = array_merge( $links, $embeds, $embedsInline, $objects );
 508  
 509                  if ( is_array( $allTags ) )
 510                  {
 511                      foreach ( array_keys( $allTags ) as $index )
 512                      {
 513                          $tag =& $allTags[$index];
 514                          $linkID = $tag->getAttribute( 'url_id' );
 515                          if ( $tag->nodeName == 'object' )
 516                              $objectID = $tag->getAttribute( 'id' );
 517                          else
 518                              $objectID = $tag->getAttribute( 'object_id' );
 519                          $nodeID = $tag->getAttribute( 'node_id' );
 520                          if ( $linkID )
 521                          {
 522                              $urlObj = eZURL::fetch( $linkID );
 523                              if ( !$urlObj ) // an error occured
 524                                  continue;
 525                              $url =& $urlObj->attribute( 'url' );
 526                              $tag->setAttribute( 'href', $url );
 527                              $tag->removeAttribute( 'url_id' );
 528                              unset( $urlObj );
 529                          }
 530                          elseif ( $objectID )
 531                          {
 532                              $object = eZContentObject::fetch( $objectID, false );
 533                              if ( is_array( $object ) )
 534                                  $tag->setAttribute( 'object_remote_id', $object['remote_id'] );
 535  
 536                              if ( $tag->nodeName == 'object' )
 537                                  $tag->removeAttribute( 'id' );
 538                              else
 539                                  $tag->removeAttribute( 'object_id' );
 540                          }
 541                          elseif ( $nodeID )
 542                          {
 543                              $node = eZContentObjectTreeNode::fetch( $nodeID, false, false );
 544                              if ( is_array( $node ) )
 545                                  $tag->setAttribute( 'node_remote_id', $node['remote_id'] );
 546                              $tag->removeAttribute( 'node_id' );
 547                          }
 548                      }
 549                  }
 550              }
 551  
 552              $DOMNode->appendChild( $doc->root() );
 553          }
 554  
 555          return $DOMNode;
 556      }
 557  
 558      /*!
 559       \reimp
 560       \param contentobject attribute object
 561       \param ezdomnode object
 562      */
 563      function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode )
 564      {
 565          $rootNode = $attributeNode->firstChild();
 566          if ( $rootNode )
 567          {
 568  
 569              /* For all links found in the XML, do the following:
 570               * Search for url specified in 'href' link attribute (in ezurl table).
 571               * If the url not found then create a new one.
 572               * Then associate the found (or created) URL with the object attribute by creating new url-object link.
 573               * After that, remove "href" attribute, add new "id" attribute.
 574               * This new 'id' will always refer to the existing url object.
 575               */
 576              include_once ( 'kernel/classes/datatypes/ezurl/ezurlobjectlink.php' );
 577              include_once ( 'kernel/classes/datatypes/ezurl/ezurl.php' );
 578  
 579              $xml = new eZXML();
 580              $domDocument =& $xml->domTree( $rootNode->toString( 0 ), array ( 'CharsetConversion' => false ) );
 581  
 582              if ( $domDocument )
 583              {
 584                  $links =& $domDocument->elementsByName( 'link' );
 585                  if ( !is_array( $links ) )
 586                      $links = array();
 587  
 588                  foreach ( array_keys( $links ) as $index )
 589                  {
 590                      $linkRef =& $links[$index];
 591                      $href = $linkRef->attributeValue( 'href' );
 592                      if ( !$href )
 593                          continue;
 594                      $urlObj = eZURL::urlByURL( $href );
 595  
 596                      if ( !$urlObj )
 597                      {
 598                          $urlObj = eZURL::create( $href );
 599                          $urlObj->store();
 600                      }
 601  
 602                      $linkRef->remove_attribute( 'href' );
 603                      $linkRef->set_attribute( 'url_id', $urlObj->attribute( 'id' ) );
 604                      $urlObjectLink = eZURLObjectLink::create( $urlObj->attribute( 'id' ),
 605                                                                $objectAttribute->attribute( 'id' ),
 606                                                                $objectAttribute->attribute( 'version' ) );
 607                      $urlObjectLink->store();
 608  
 609                  }
 610                  $objectAttribute->setAttribute( 'data_text', eZXMLTextType::domString( $domDocument ) );
 611                  $domDocument->cleanup();
 612              }
 613          }
 614      }
 615  
 616      function postUnserializeContentObjectAttribute( &$package, &$objectAttribute )
 617      {
 618          $xmlString = $objectAttribute->attribute( 'data_text' );
 619          $xml = new eZXML();
 620          $doc =& $xml->domTree( $xmlString );
 621  
 622          if ( !is_object( $doc ) )
 623              return false;
 624  
 625          $links =& $doc->elementsByName( 'link' );
 626          $objects =& $doc->elementsByName( 'object' );
 627          $embeds =& $doc->elementsByName( 'embed' );
 628          $embedsInline =& $doc->elementsByName( 'embed-inline' );
 629  
 630          $allTags = array_merge( $links, $embeds, $embedsInline, $objects );
 631          $modified = false;
 632  
 633          $contentObject =& $objectAttribute->attribute( 'object' );
 634          foreach( array_keys( $allTags ) as $key )
 635          {
 636              $tag =& $allTags[$key];
 637  
 638              $objectRemoteID = $tag->getAttribute( 'object_remote_id' );
 639              $nodeRemoteID = $tag->getAttribute( 'node_remote_id' );
 640              if ( $objectRemoteID )
 641              {
 642                  $objectArray = eZContentObject::fetchByRemoteID( $objectRemoteID, false );
 643                  if ( !is_array( $objectArray ) )
 644                  {
 645                      eZDebug::writeWarning( "Can't fetch object with remoteID = $objectRemoteID", 'eZXMLTextType::unserialize' );
 646                      continue;
 647                  }
 648  
 649                  $objectID = $objectArray['id'];
 650                  if ( $tag->nodeName == 'object' )
 651                      $tag->setAttribute( 'id', $objectID );
 652                  else
 653                      $tag->setAttribute( 'object_id', $objectID );
 654                  $tag->removeAttribute( 'object_remote_id' );
 655                  $modified = true;
 656  
 657                  // add as related object
 658                  if ( $contentObject )
 659                  {
 660                      $relationType = $tag->nodeName == 'link' ? EZ_CONTENT_OBJECT_RELATION_LINK : EZ_CONTENT_OBJECT_RELATION_EMBED;
 661                      $contentObject->addContentObjectRelation( $objectID, $objectAttribute->attribute( 'version' ), false, 0, $relationType );
 662                  }
 663              }
 664              elseif ( $nodeRemoteID )
 665              {
 666                  $nodeArray = eZContentObjectTreeNode::fetchByRemoteID( $nodeRemoteID, false );
 667                  if ( !is_array( $nodeArray ) )
 668                  {
 669                      eZDebug::writeWarning( "Can't fetch node with remoteID = $nodeRemoteID", 'eZXMLTextType::unserialize' );
 670                      continue;
 671                  }
 672  
 673                  $nodeID = $nodeArray['node_id'];
 674                  $tag->setAttribute( 'node_id', $nodeID );
 675                  $tag->removeAttribute( 'node_remote_id' );
 676                  $modified = true;
 677  
 678                  // add as related object
 679                  if ( $contentObject )
 680                  {
 681                      $node = eZContentObjectTreeNode::fetch( $nodeID );
 682                      if ( $node )
 683                      {
 684                          $relationType = $tag->nodeName == 'link' ? EZ_CONTENT_OBJECT_RELATION_LINK : EZ_CONTENT_OBJECT_RELATION_EMBED;
 685                          $contentObject->addContentObjectRelation( $node->attribute( 'contentobject_id' ), $objectAttribute->attribute( 'version' ), false, 0, $relationType );
 686                      }
 687                  }
 688              }
 689          }
 690  
 691          if ( $modified )
 692          {
 693              $objectAttribute->setAttribute( 'data_text', eZXMLTextType::domString( $doc ) );
 694              return true;
 695          }
 696          else
 697          {
 698              return false;
 699          }
 700      }
 701      /*!
 702       Delete stored object attribute, this will clean up the ezurls and ezobjectlinks
 703      */
 704      function deleteStoredObjectAttribute( &$contentObjectAttribute, $version = null )
 705      {
 706          $contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
 707  
 708          $db =& eZDB::instance();
 709  
 710          /* First we remove the link between the keyword and the object
 711           * attribute to be removed */
 712          include_once ( 'kernel/classes/datatypes/ezurl/ezurlobjectlink.php' );
 713          if ( $version == null )
 714          {
 715              eZPersistentObject::removeObject( eZURLObjectLink::definition(),
 716                                                array( 'contentobject_attribute_id' => $contentObjectAttributeID ) );
 717  
 718          }
 719          else
 720          {
 721              eZPersistentObject::removeObject( eZURLObjectLink::definition(),
 722                                                array( 'contentobject_attribute_id' => $contentObjectAttributeID,
 723                                                       'contentobject_attribute_version' => $version ) );
 724          }
 725  
 726          /* Here we figure out which which URLs are not in use at all */
 727          if ( $db->databaseName() == 'oracle' )
 728          {
 729              $res = $db->arrayQuery( "SELECT DISTINCT id
 730                                       FROM ezurl, ezurl_object_link
 731                                       WHERE ezurl.id = ezurl_object_link.url_id(+)
 732                                           AND url_id IS NULL" );
 733          }
 734          else
 735          {
 736              $res = $db->arrayQuery(" SELECT DISTINCT id
 737                                       FROM ezurl LEFT JOIN ezurl_object_link ON (ezurl.id  = ezurl_object_link.url_id)
 738                                       WHERE url_id IS NULL" );
 739          }
 740  
 741          /* And if there are some, we delete them */
 742          if ( count( $res ) )
 743          {
 744              $unusedUrlIDs = array();
 745              foreach ( $res as $record )
 746                  $unusedUrlIDs[] = $record['id'];
 747              $unusedUrlIDString = implode( ', ', $unusedUrlIDs );
 748  
 749              $db->query( "DELETE FROM ezurl WHERE id IN ($unusedUrlIDString)" );
 750          }
 751      }
 752  
 753      /*!
 754        \reimp
 755      */
 756      function diff( $old, $new, $options = false )
 757      {
 758          include_once ( 'lib/ezdiff/classes/ezdiff.php' );
 759          $diff = new eZDiff();
 760          $diff->setDiffEngineType( $diff->engineType( 'xml' ) );
 761          $diff->initDiffEngine();
 762          $diffObject = $diff->diff( $old, $new );
 763          return $diffObject;
 764      }
 765  
 766  }
 767  
 768  eZDataType::register( EZ_DATATYPESTRING_XML_TEXT, "ezXMLTextType" );
 769  
 770  ?>


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