[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

/kernel/content/ -> history.php (source)

   1  <?php
   2  //
   3  // Created on: <22-Apr-2002 15:41:30 bf>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  include_once ( 'kernel/classes/ezcontentclass.php' );
  28  include_once ( 'kernel/classes/ezcontentclassattribute.php' );
  29  
  30  include_once ( 'kernel/classes/ezcontentobject.php' );
  31  include_once ( 'kernel/classes/ezcontentobjectversion.php' );
  32  include_once ( 'kernel/classes/ezcontentobjectattribute.php' );
  33  
  34  include_once ( 'kernel/common/template.php' );
  35  include_once ( "lib/ezutils/classes/ezini.php" );
  36  include_once ( "lib/ezdb/classes/ezdb.php" );
  37  
  38  include_once ( 'lib/ezdiff/classes/ezdiff.php' );
  39  
  40  $tpl =& templateInit();
  41  $http =& eZHTTPTool::instance();
  42  
  43  $ObjectID = $Params['ObjectID'];
  44  $EditVersion = $Params['EditVersion'];
  45  
  46  $Offset = $Params['Offset'];
  47  $viewParameters = array( 'offset' => $Offset );
  48  
  49  if ( $http->hasPostVariable( 'BackButton' )  )
  50  {
  51      $userRedirectURI = '';
  52      if ( $http->hasPostVariable( 'RedirectURI' ) )
  53      {
  54          $redurectURI = $http->postVariable( 'RedirectURI' );
  55          $http->removeSessionVariable( 'LastAccessesVersionURI' );
  56          return $Module->redirectTo( $redurectURI );
  57      }
  58      if ( $http->hasSessionVariable( "LastAccessesURI" ) )
  59          $userRedirectURI = $http->sessionVariable( "LastAccessesURI" );
  60      return $Module->redirectTo( $userRedirectURI );
  61  }
  62  
  63  $object =& eZContentObject::fetch( $ObjectID );
  64  
  65  $editWarning = false;
  66  
  67  $canEdit = false;
  68  $canRemove = false;
  69  
  70  if ( $object === null )
  71      return $Module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
  72  
  73  if ( !$object->attribute( 'can_read' ) )
  74      return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
  75  
  76  if ( $object->attribute( 'can_edit' ) )
  77      $canEdit = true;
  78  
  79  $canRemove = true;
  80  
  81  $http =& eZHTTPTool::instance();
  82  
  83  
  84  //content/diff functionality
  85  //Set default values
  86  $previousVersion = 1;
  87  $newestVersion = 1;
  88  
  89  //By default, set preselect the previous and most recent version for diffing
  90  if ( count( $object->versions() ) > 1 )
  91  {
  92      $versionArray = $object->versions( false );
  93      $selectableVersions = array();
  94      foreach( $versionArray as $versionItem )
  95      {
  96          //Only return version numbers of archived or published items
  97          if ( in_array( $versionItem['status'], array( 0, 1, 3 ) ) )
  98          {
  99              $selectableVersions[] = $versionItem['version'];
 100          }
 101      }
 102      $newestVersion = array_pop( $selectableVersions );
 103      $previousVersion = array_pop( $selectableVersions );
 104  }
 105  
 106  $tpl->setVariable( 'selectOldVersion', $previousVersion );
 107  $tpl->setVariable( 'selectNewVersion', $newestVersion );
 108  $tpl->setVariable( 'module', $Module );
 109  
 110  $diff = array();
 111  
 112  if ( $http->hasPostVariable('DiffButton') && $http->hasPostVariable( 'FromVersion' ) && $http->hasPostVariable( 'ToVersion' ) )
 113  {
 114      if ( !$object->attribute( 'can_diff' ) )
 115          return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 116  
 117      $lang = false;
 118      if ( $http->hasPostVariable( 'Language' ) )
 119      {
 120          $lang = $http->postVariable( 'Language' );
 121      }
 122      $oldVersion = $http->postVariable( 'FromVersion' );
 123      $newVersion = $http->postVariable( 'ToVersion' );
 124  
 125      if ( is_numeric( $oldVersion ) && is_numeric( $newVersion ) )
 126      {
 127          $oldObject = $object->version( $oldVersion );
 128          $newObject = $object->version( $newVersion );
 129          
 130          if ( $lang )
 131          {
 132              $oldAttributes = $object->fetchDataMap( $oldVersion, $lang );
 133              //Fallback, if desired language not available in version
 134              if ( !$oldAttributes )
 135              {
 136                  $oldObjectLang = $oldObject->attribute( 'initial_language' );
 137                  $oldAttributes = $object->fetchDataMap( $oldVersion, $oldObjectLang->attribute( 'locale' ) );
 138              }
 139              $newAttributes = $object->fetchDataMap( $newVersion, $lang );
 140              //Fallback, if desired language not available in version
 141              if ( !$newAttributes )
 142              {
 143                  $newObjectLang = $newObject->attribute( 'initial_language' );
 144                  $newAttributes = $object->fetchDataMap( $newVersion, $newObjectLang->attribute( 'locale' ) );
 145              }
 146  
 147          }
 148          else
 149          {
 150              $oldAttributes = $oldObject->dataMap();
 151              $newAttributes = $newObject->dataMap();
 152          }
 153  
 154          //Extra options to open up for future extensions of the system.
 155          $extraOptions = false;
 156          if ( $http->hasPostVariable( 'ExtraOptions' ) )
 157          {
 158              $extraOptions = $http->postVariable( 'ExtraOptions' );
 159          }
 160  
 161          //Invoke diff method in the datatype
 162          foreach ( $oldAttributes as $attribute )
 163          {
 164              $newAttr = $newAttributes[$attribute->attribute( 'contentclass_attribute_identifier' )];
 165              $contentClassAttr = $newAttr->attribute( 'contentclass_attribute' );
 166              $diff[$contentClassAttr->attribute( 'id' )] = $contentClassAttr->diff( $attribute, $newAttr, $extraOptions );
 167          }
 168  
 169          $tpl->setVariable( 'oldVersion', $oldVersion );
 170          $tpl->setVariable( 'oldVersionObject', $object->version( $oldVersion ) );
 171  
 172          $tpl->setVariable( 'newVersion', $newVersion );
 173          $tpl->setVariable( 'newVersionObject', $object->version( $newVersion ) );
 174          $tpl->setVariable( 'diff', $diff );
 175      }
 176  }
 177  //content/diff end
 178  
 179  //content/versions
 180  if ( $http->hasSessionVariable( 'ExcessVersionHistoryLimit' ) )
 181  {
 182      $excessLimit = $http->sessionVariable( 'ExcessVersionHistoryLimit' );
 183      if ( $excessLimit )
 184          $editWarning = 3;
 185      $http->removeSessionVariable( 'ExcessVersionHistoryLimit' );
 186  }
 187  
 188  if ( $http->hasPostVariable( 'RemoveButton' )  )
 189  {
 190      if ( !$canEdit )
 191          return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 192      if ( $http->hasPostVariable( 'DeleteIDArray' ) )
 193      {
 194          $db =& eZDB::instance();
 195          $db->begin();
 196  
 197          $deleteIDArray = $http->postVariable( 'DeleteIDArray' );
 198          $versionArray = array();
 199          foreach ( $deleteIDArray as $deleteID )
 200          {
 201              $version = eZContentObjectVersion::fetch( $deleteID );
 202              $versionArray[] = $version->attribute( 'version' );
 203              if ( $version != null )
 204              {
 205                  if ( $version->attribute( 'can_remove' ) )
 206                  {
 207                      $version->remove();
 208                  }
 209              }
 210          }
 211          $db->commit();
 212      }
 213  }
 214  
 215  $user =& eZUser::currentUser();
 216  
 217  if ( $Module->isCurrentAction( 'Edit' )  )
 218  {
 219      if ( !$canEdit )
 220          return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 221  
 222      $versionID = false;
 223  
 224      if ( is_array( $Module->actionParameter( 'VersionKeyArray' ) ) )
 225      {
 226          $versionID = array_keys( $Module->actionParameter( 'VersionKeyArray' ) );
 227          $versionID = $versionID[0];
 228      }
 229      else if ( $Module->hasActionParameter( 'VersionID' ) )
 230          $versionID = $Module->actionParameter( 'VersionID' );
 231  
 232      $version =& $object->version( $versionID );
 233      if ( !$version )
 234          $versionID = false;
 235  
 236      if ( $versionID !== false and
 237           !in_array( $version->attribute( 'status' ), array( EZ_VERSION_STATUS_DRAFT, EZ_VERSION_STATUS_INTERNAL_DRAFT ) ) )
 238      {
 239          $editWarning = 1;
 240          $EditVersion = $versionID;
 241      }
 242      else if ( $versionID !== false and
 243                $version->attribute( 'creator_id' ) != $user->attribute( 'contentobject_id' ) )
 244      {
 245          $editWarning = 2;
 246          $EditVersion = $versionID;
 247      }
 248      else
 249      {
 250          return $Module->redirectToView( 'edit', array( $ObjectID, $versionID, $version->initialLanguageCode() ) );
 251      }
 252  }
 253  
 254  $versions =& $object->versions();
 255  
 256  if ( $Module->isCurrentAction( 'CopyVersion' )  )
 257  {
 258      if ( !$canEdit )
 259      {
 260      return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 261      }
 262      
 263      if ( is_array( $Module->actionParameter( 'VersionKeyArray' ) ) )
 264      {
 265      $versionID = array_keys( $Module->actionParameter( 'VersionKeyArray' ) );
 266      $versionID = $versionID[0];
 267      }
 268      else
 269      {
 270      $versionID = $Module->actionParameter( 'VersionID' );
 271      }
 272      
 273      $languages = $Module->actionParameter( 'LanguageArray' );
 274      if ( $languages && array_key_exists( $versionID, $languages ) )
 275      {
 276      $language = $languages[$versionID];
 277      }
 278      else
 279      {
 280      $language = false;
 281      }
 282      
 283      if ( !$object->checkAccess( 'edit', false, false, false, $language ) )
 284      {
 285      return $Module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 286      }
 287      
 288      $contentINI =& eZINI::instance( 'content.ini' );
 289      $versionlimit = $contentINI->variable( 'VersionManagement', 'DefaultVersionHistoryLimit' );
 290  
 291      $limitList = $contentINI->variable( 'VersionManagement', 'VersionHistoryClass' );
 292  
 293      $classID = $object->attribute( 'contentclass_id' );
 294      foreach ( array_keys ( $limitList ) as $key )
 295      {
 296          if ( $classID == $key )
 297              $versionlimit =& $limitList[$key];
 298      }
 299      if ( $versionlimit < 2 )
 300          $versionlimit = 2;
 301  
 302      $versionCount = $object->getVersionCount();
 303      if ( $versionCount < $versionlimit )
 304      {
 305          $db =& eZDB::instance();
 306          $db->begin();
 307          foreach ( array_keys( $versions ) as $versionKey )
 308          {
 309              $version =& $versions[$versionKey];
 310              if ( $version->attribute( 'version' ) == $versionID )
 311              {
 312                  $newVersionID = $object->copyRevertTo( $versionID, $language );
 313  
 314                  if ( !$http->hasPostVariable( 'DoNotEditAfterCopy' ) )
 315                  {
 316                      break;
 317                  }
 318              }
 319          }
 320          $db->commit();
 321  
 322          if ( !$http->hasPostVariable( 'DoNotEditAfterCopy' ) )
 323          {
 324              return $Module->redirectToView( 'edit', array( $ObjectID, $newVersionID, $language ) );
 325          }
 326      }
 327      else
 328      {
 329          $params = array( 'conditions'=> array( 'status' => 3 ) );
 330          $versions =& $object->versions( true, $params );
 331          if ( count( $versions ) > 0 )
 332          {
 333              $modified = $versions[0]->attribute( 'modified' );
 334              $removeVersion =& $versions[0];
 335              foreach ( array_keys( $versions ) as $versionKey )
 336              {
 337                  $version =& $versions[$versionKey];
 338                  $currentModified = $version->attribute( 'modified' );
 339                  if ( $currentModified < $modified )
 340                  {
 341                      $modified = $currentModified;
 342                      $removeVersion = $version;
 343                  }
 344              }
 345  
 346              $db =& eZDB::instance();
 347              $db->begin();
 348              $removeVersion->remove();
 349  
 350              $versions =& $object->versions();
 351              foreach ( array_keys( $versions ) as $versionKey )
 352              {
 353                  $version =& $versions[$versionKey];
 354                  if ( $version->attribute( 'version' ) == $versionID )
 355                  {
 356                      $newVersionID = $object->copyRevertTo( $versionID );
 357  
 358                      if ( !$http->hasPostVariable( 'DoNotEditAfterCopy' ) )
 359                      {
 360                          break;
 361                      }
 362                  }
 363              }
 364              $db->commit();
 365  
 366              if ( !$http->hasPostVariable( 'DoNotEditAfterCopy' ) )
 367              {
 368                  return $Module->redirectToView( 'edit', array( $ObjectID, $newVersionID, $version->initialLanguageCode() ) );
 369              }
 370          }
 371          else
 372          {
 373              $http->setSessionVariable( 'ExcessVersionHistoryLimit', true );
 374              $currentVersion = $object->attribute( 'current_version' );
 375              $Module->redirectToView( 'history', array( $ObjectID, $currentVersion ) );
 376              return EZ_MODULE_HOOK_STATUS_CANCEL_RUN;
 377          }
 378      }
 379  }
 380  
 381  $res =& eZTemplateDesignResource::instance();
 382  $res->setKeys( array( array( 'object', $object->attribute( 'id' ) ), // Object ID
 383                        array( 'class', $object->attribute( 'contentclass_id' ) ), // Class ID
 384                        array( 'class_identifier', $object->attribute( 'class_identifier' ) ), // Class identifier
 385                        array( 'section_id', $object->attribute( 'section_id' ) ) // Section ID
 386                        ) ); // Section ID, 0 so far
 387                        
 388  include_once ( 'kernel/classes/ezsection.php' );
 389  eZSection::setGlobalID( $object->attribute( 'section_id' ) );
 390  $versionArray =( isset( $versionArray ) and is_array( $versionArray ) ) ? array_unique( $versionArray ) : array();
 391  $LastAccessesVersionURI = $http->hasSessionVariable( 'LastAccessesVersionURI' ) ? $http->sessionVariable( 'LastAccessesVersionURI' ) : null;
 392  $explodedURI = $LastAccessesVersionURI ? explode ( '/', $LastAccessesVersionURI ) : null;
 393  if ( $LastAccessesVersionURI and is_array( $versionArray ) and !in_array( $explodedURI[3], $versionArray ) )
 394    $tpl->setVariable( 'redirect_uri', $http->sessionVariable( 'LastAccessesVersionURI' ) );
 395  
 396  //Fetch newer drafts and count of newer drafts.
 397  $newerDraftVersionList =  eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),
 398                                                             null, array(  'contentobject_id' => $object->attribute( 'id' ),
 399                                                                           'status' => EZ_VERSION_STATUS_DRAFT,
 400                                                                           'version' => array( '>', $object->attribute( 'current_version' ) ) ),
 401                                                             array( 'modified' => false,
 402                                                                    'initial_language_id' => true ),
 403                                                             null,
 404                                                             true );
 405  
 406  $newerDraftVersionListCount =  eZPersistentObject::fetchObjectList( eZContentObjectVersion::definition(),
 407                                                            array(), array( 'contentobject_id' => $object->attribute( 'id' ),
 408                                                                         'status' => EZ_VERSION_STATUS_DRAFT,
 409                                                                         'version' => array( '>', $object->attribute( 'current_version' ) ) ),
 410                                                            null, null,
 411                                                            false,false,
 412                                                            array( array( 'operation' => 'count( * )',
 413                                                                          'name' => 'count' ) ) );
 414  
 415  $tpl->setVariable( 'newerDraftVersionList', $newerDraftVersionList );
 416  $tpl->setVariable( 'newerDraftVersionListCount', $newerDraftVersionListCount[0]['count'] );
 417  $tpl->setVariable( 'view_parameters', $viewParameters );
 418  $tpl->setVariable( 'object', $object );
 419  $tpl->setVariable( 'edit_version', $EditVersion );
 420  $tpl->setVariable( 'versions', $versions );
 421  $tpl->setVariable( 'edit_warning', $editWarning );
 422  $tpl->setVariable( 'can_edit', $canEdit );
 423  //$tpl->setVariable( 'can_remove', $canRemove );
 424  $tpl->setVariable( 'user_id', $user->attribute( 'contentobject_id' ) );
 425  
 426  $Result = array();
 427  $Result['content'] =& $tpl->fetch( 'design:content/history.tpl' );
 428  $Result['path'] = array( array( 'text' => ezi18n( 'kernel/content', 'History' ),
 429                                  'url' => false ) );
 430  
 431  ?>


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