[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/lib/ezdiff/classes/ -> ezdiffxmltextengine.php (source)

   1  <?php
   2  //
   3  // Definition of eZDiffXMLTextEngine class
   4  //
   5  // <creation-tag>
   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  /*! \file ezdiffxmltextengine.php
  30    eZDiffXMLTextEngine class
  31  */
  32  
  33  /*!
  34    \class eZDiffXMLTextEngine ezdiffxmltextengine.php
  35    \ingroup eZDiff
  36    \brief This class creates a diff for xml text.
  37  */
  38  
  39  include_once ( 'lib/ezdiff/classes/ezdiffengine.php' );
  40  
  41  class eZDiffXMLTextEngine extends eZDiffEngine
  42  {
  43      function eZDiffXMLTextEngine()
  44      {
  45      }
  46  
  47      /*!
  48        This function calculates changes in xml text and creates an object to hold
  49        overview of changes.
  50      */
  51      function createDifferenceObject( $fromData, $toData )
  52      {
  53          include_once ( 'lib/ezdiff/classes/ezxmltextdiff.php' );
  54          include_once ( 'lib/ezdiff/classes/ezdifftextengine.php' );
  55          include_once ( 'lib/ezutils/classes/ezini.php' );
  56          include_once ( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmleditoutput.php' );
  57          include_once ( 'lib/ezxml/classes/ezxml.php' );
  58  
  59          $changes = new eZXMLTextDiff();
  60          $contentINI = eZINI::instance( 'content.ini' );
  61          $useSimplifiedXML = $contentINI->variable( 'ContentVersionDiffSettings', 'UseSimplifiedXML' );
  62          $diffSimplifiedXML = ( $useSimplifiedXML == 'enabled' );
  63  
  64          $oldXMLTextObject = $fromData->content();
  65          $newXMLTextObject = $toData->content();
  66          
  67          $oldXML = $oldXMLTextObject->attribute( 'xml_data' );
  68          $newXML = $newXMLTextObject->attribute( 'xml_data' );
  69  
  70          $simplifiedXML = new eZSimplifiedXMLEditOutput();
  71          $xml = new eZXML();
  72          $domOld =& $xml->domTree( $oldXML, array( 'CharsetConversion' => false, 'ConvertSpecialChars' => false, 'SetParentNode' => true ) );
  73          $domNew =& $xml->domTree( $newXML, array( 'CharsetConversion' => false, 'ConvertSpecialChars' => false, 'SetParentNode' => true ) );
  74          $old = $simplifiedXML->performOutput( $domOld );
  75          $new = $simplifiedXML->performOutput( $domNew );
  76          
  77          $domOld->cleanup();
  78          $domNew->cleanup();
  79  
  80          if ( !$diffSimplifiedXML )
  81          {
  82              $old = trim( strip_tags( $old ) );
  83              $new = trim( strip_tags( $new ) );
  84  
  85              $pattern = array( '/[ ][ ]+/',
  86                                '/ \n( \n)+/',
  87                                '/^ /m',
  88                                '/(\n){3,}/' );
  89              $replace = array( ' ',
  90                                "\n",
  91                                '',
  92                                "\n\n" );
  93  
  94              $old = preg_replace( $pattern, $replace, $old );
  95              $new = preg_replace( $pattern, $replace, $new );
  96          }
  97  
  98          $oldArray = split( "\n", $old );
  99          $newArray = split( "\n", $new );
 100  
 101          $oldSums = array();
 102          foreach( $oldArray as $paragraph )
 103          {
 104              $oldSums[] = crc32( $paragraph );
 105          }
 106  
 107          $newSums = array();
 108          foreach( $newArray as $paragraph )
 109          {
 110              $newSums[] = crc32( $paragraph );
 111          }
 112  
 113          $textDiffer = new eZDiffTextEngine();
 114  
 115          $pre = $textDiffer->preProcess( $oldSums, $newSums );
 116          $out = $textDiffer->createOutput( $pre, $oldArray, $newArray );
 117          $changes->setChanges( $out );
 118          return $changes;
 119      }
 120  }
 121  
 122  ?>


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