[ Index ]
 

Code source de eZ Publish 3.9.0

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

title

Body

[fermer]

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

   1  <?php
   2  //
   3  // Created on: <04-Jul-2002 13:06: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/ezcontentobject.php' );
  28  include_once ( 'kernel/classes/ezcontentobjecttreenode.php' );
  29  include_once ( 'kernel/classes/ezcontentbrowse.php' );
  30  include_once ( 'kernel/classes/ezcontentbrowsebookmark.php' );
  31  include_once ( 'kernel/classes/ezcontentclass.php' );
  32  include_once ( "lib/ezdb/classes/ezdb.php" );
  33  include_once ( "lib/ezutils/classes/ezhttptool.php" );
  34  include_once ( "lib/ezutils/classes/ezini.php" );
  35  include_once ( 'kernel/classes/datatypes/ezuser/ezuser.php' );
  36  
  37  $http =& eZHTTPTool::instance();
  38  $module =& $Params["Module"];
  39  
  40  /* We retrieve the class ID for users as this is used in many places in this
  41   * code in order to be able to cleanup the user-policy cache. */
  42  $ini =& eZINI::instance();
  43  $userClassID = $ini->variable( "UserSettings", "UserClassID" );
  44  
  45  if ( $module->hasActionParameter( 'LanguageCode' ) )
  46      $languageCode = $module->actionParameter( 'LanguageCode' );
  47  else
  48  {
  49      $languageCode = false;
  50  }
  51  
  52  $viewMode = 'full';
  53  if ( $module->hasActionParameter( 'ViewMode' ) )
  54      $viewMode = $module->actionParameter( 'ViewMode' );
  55  
  56  if ( $http->hasPostVariable( 'BrowseCancelButton' ) || $http->hasPostVariable( 'CancelButton' ) )
  57  {
  58      if ( $http->hasPostVariable( 'BrowseCancelURI' ) )
  59      {
  60          return $module->redirectTo( $http->postVariable( 'BrowseCancelURI' ) );
  61      }
  62      else if ( $http->hasPostVariable( 'CancelURI' ) )
  63      {
  64          return $module->redirectTo( $http->postVariable( 'CancelURI' ) );
  65      }
  66  }
  67  // Merge post variables and variables that were used before login
  68  if ( $http->hasSessionVariable( 'LastPostVars' ) )
  69  {
  70      $post =& $http->attribute( 'post' );
  71      $post = array_merge( $post, $http->sessionVariable( 'LastPostVars' ) );
  72      unset( $post );
  73      $http->removeSessionVariable( 'LastPostVars' );
  74  }
  75  
  76  if ( $http->hasPostVariable( 'NewButton' ) || $module->isCurrentAction( 'NewObjectAddNodeAssignment' )  )
  77  {
  78      $hasClassInformation = false;
  79      $contentClassID = false;
  80      $contentClassIdentifier = false;
  81      $languageCode = false;
  82      $class = false;
  83  
  84      if ( $http->hasPostVariable( 'ClassID' ) )
  85      {
  86          $contentClassID = $http->postVariable( 'ClassID' );
  87          if ( $contentClassID )
  88              $hasClassInformation = true;
  89      }
  90      else if ( $http->hasPostVariable( 'ClassIdentifier' ) )
  91      {
  92          $contentClassIdentifier = $http->postVariable( 'ClassIdentifier' );
  93          $class = eZContentClass::fetchByIdentifier( $contentClassIdentifier );
  94          if ( is_object( $class ) )
  95          {
  96              $contentClassID = $class->attribute( 'id' );
  97              if ( $contentClassID )
  98                  $hasClassInformation = true;
  99          }
 100      }
 101  
 102      if ( $http->hasPostVariable( 'ContentLanguageCode' ) )
 103      {
 104          include_once ( 'kernel/classes/ezcontentlanguage.php' );
 105          $languageCode = $http->postVariable( 'ContentLanguageCode' );
 106          $languageID = eZContentLanguage::idByLocale( $languageCode );
 107          if ( $languageID === false )
 108          {
 109              eZDebug::writeError( "The language code [$languageCode] specified in ContentLanguageCode does not exist in the system." );
 110              return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
 111          }
 112      }
 113      else
 114      {
 115          include_once ( 'kernel/classes/ezcontentlanguage.php' );
 116          $allLanguages = eZContentLanguage::prioritizedLanguages();
 117          // Only show language selection if there are more than 1 languages.
 118          if ( count( $allLanguages ) > 1 &&
 119               $hasClassInformation )
 120          {
 121              include_once ( 'kernel/common/template.php' );
 122              $tpl =& templateInit();
 123  
 124              $tpl->setVariable( 'node_id', $http->postVariable( 'NodeID' ) );
 125              $tpl->setVariable( 'class_id', $contentClassID );
 126              $tpl->setVariable( 'assignment_remote_id', ( $http->hasPostVariable( 'AssignmentRemoteID' ) )? $http->postVariable( 'AssignmentRemoteID' ): false );
 127              $tpl->setVariable( 'redirect_uri_after_publish', ( $http->hasPostVariable( 'RedirectURIAfterPublish' ) )? $http->postVariable( 'RedirectURIAfterPublish' ): false );
 128  
 129              $Result = array();
 130              $Result['content'] =& $tpl->fetch( 'design:content/create_languages.tpl' );
 131              return $Result;
 132          }
 133      }
 134  
 135      if ( ( $hasClassInformation && $http->hasPostVariable( 'NodeID' ) ) || $module->isCurrentAction( 'NewObjectAddNodeAssignment' ) )
 136      {
 137          if (  $module->isCurrentAction( 'NewObjectAddNodeAssignment' ) )
 138          {
 139              $selectedNodeIDArray = eZContentBrowse::result( 'NewObjectAddNodeAssignment' );
 140              if ( count( $selectedNodeIDArray ) == 0 )
 141                  return $module->redirectToView( 'view', array( 'full', 2 ) );
 142              $node = eZContentObjectTreeNode::fetch( $selectedNodeIDArray[0] );
 143          }
 144          else
 145          {
 146              $node = eZContentObjectTreeNode::fetch( $http->postVariable( 'NodeID' ) );
 147          }
 148  
 149          if ( is_object( $node ) )
 150          {
 151              $parentContentObject =& $node->attribute( 'object' );
 152              if ( $parentContentObject->checkAccess( 'create', $contentClassID,  $parentContentObject->attribute( 'contentclass_id' ), false, $languageCode ) == '1' )
 153              {
 154                  $user =& eZUser::currentUser();
 155                  $userID =& $user->attribute( 'contentobject_id' );
 156                  // We should set sectionID to 0 because when publishing eZContentOperationCollection::updateSectionID() will be called
 157                  // and sectionID will be updated
 158                  $sectionID = 0;
 159  
 160                  if ( !is_object( $class ) )
 161                      $class = eZContentClass::fetch( $contentClassID );
 162                  if ( is_object( $class ) )
 163                  {
 164                      $db =& eZDB::instance();
 165                      $db->begin();
 166                      $contentObject = $class->instantiateIn( $languageCode, $userID, $sectionID, false, EZ_VERSION_STATUS_INTERNAL_DRAFT );
 167                      $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $contentObject->attribute( 'id' ),
 168                                                                         'contentobject_version' => $contentObject->attribute( 'current_version' ),
 169                                                                         'parent_node' => $node->attribute( 'node_id' ),
 170                                                                         'is_main' => 1,
 171                                                                         'sort_field' => $class->attribute( 'sort_field' ),
 172                                                                         'sort_order' => $class->attribute( 'sort_order' ) ) );
 173                      if ( $http->hasPostVariable( 'AssignmentRemoteID' ) )
 174                      {
 175                          $nodeAssignment->setAttribute( 'remote_id', $http->postVariable( 'AssignmentRemoteID' ) );
 176                      }
 177                      $nodeAssignment->store();
 178                      $db->commit();
 179  
 180                      if ( $http->hasPostVariable( 'RedirectURIAfterPublish' ) )
 181                      {
 182                          $http->setSessionVariable( 'RedirectURIAfterPublish', $http->postVariable( 'RedirectURIAfterPublish' ) );
 183                      }
 184                      $module->redirectTo( $module->functionURI( 'edit' ) . '/' . $contentObject->attribute( 'id' ) . '/' . $contentObject->attribute( 'current_version' ) );
 185                      return;
 186                  }
 187                  else
 188                  {
 189                      return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 190                  }
 191              }
 192              else
 193              {
 194                  // If ACCESS DENIED save current post variables for using after login
 195                  $http->setSessionVariable( '$_POST_BeforeLogin', $http->attribute( 'post' ) );
 196                  return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 197              }
 198          }
 199          else
 200          {
 201              return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
 202          }
 203      }
 204      else if ( $hasClassInformation )
 205      {
 206          if ( !is_object( $class ) )
 207              $class = eZContentClass::fetch( $contentClassID );
 208          eZContentBrowse::browse( array( 'action_name' => 'NewObjectAddNodeAssignment',
 209                                          'description_template' => 'design:content/browse_first_placement.tpl',
 210                                          'keys' => array( 'class' => $class->attribute( 'id' ),
 211                                                           'classgroup' => $class->attribute( 'ingroup_id_list' ) ),
 212                                          'persistent_data' => array( 'ClassID' => $class->attribute( 'id' ), 'ContentLanguageCode' => $languageCode ),
 213                                          'content' => array( 'class_id' => $class->attribute( 'id' ) ),
 214                                          'cancel_page' => $module->redirectionURIForModule( $module, 'view', array( 'full', 2 ) ),
 215                                          'from_page' => "/content/action" ),
 216                                   $module );
 217      }
 218  }
 219  else if ( $http->hasPostVariable( 'SetSorting' ) &&
 220            $http->hasPostVariable( 'ContentObjectID' ) && $http->hasPostVariable( 'ContentNodeID' ) &&
 221            $http->hasPostVariable( 'SortingField' )    && $http->hasPostVariable( 'SortingOrder' ) )
 222  {
 223      $nodeID          = $http->postVariable( 'ContentNodeID' );
 224      $contentObjectID = $http->postVariable( 'ContentObjectID' );
 225      $sortingField    = $http->postVariable( 'SortingField' );
 226      $sortingOrder    = $http->postVariable( 'SortingOrder' );
 227      $node = eZContentObjectTreeNode::fetch( $nodeID );
 228      $contentObject =& eZContentObject::fetch( $contentObjectID );
 229  
 230      $db =& eZDB::instance();
 231      $db->begin();
 232      $node->setAttribute( 'sort_field', $sortingField );
 233      $node->setAttribute( 'sort_order', $sortingOrder );
 234      $node->store();
 235      $db->commit();
 236  
 237      // invalidate node view cache
 238      include_once ( 'kernel/classes/ezcontentcachemanager.php' );
 239      eZContentCacheManager::clearContentCache( $contentObjectID );
 240  
 241      return $module->redirectToView( 'view', array( 'full', $nodeID, $languageCode ) );
 242  }
 243  else if ( $module->isCurrentAction( 'MoveNode' ) )
 244  {
 245      /* This action is used through the admin interface with the "Move" button,
 246       * or in the pop-up menu and will move a node to a different location. */
 247  
 248      if ( !$module->hasActionParameter( 'NodeID' ) )
 249      {
 250          eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
 251                               'content/action' );
 252          return $module->redirectToView( 'view', array( 'full', 2 ) );
 253      }
 254  
 255      $nodeID = $module->actionParameter( 'NodeID' );
 256      $node = eZContentObjectTreeNode::fetch( $nodeID );
 257      if ( !$node )
 258          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel', array() );
 259  
 260      if ( !$node->canMoveFrom() )
 261          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel', array() );
 262  
 263      $object =& $node->object();
 264      if ( !$object )
 265          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel', array() );
 266      $objectID = $object->attribute( 'id' );
 267      $class =& $object->contentClass();
 268      $classID = $class->attribute( 'id' );
 269  
 270      if ( $module->hasActionParameter( 'NewParentNode' ) )
 271      {
 272          $selectedNodeID = $module->actionParameter( 'NewParentNode' );
 273      }
 274      else
 275      {
 276          $selectedNodeIDArray = eZContentBrowse::result( 'MoveNode' );
 277          $selectedNodeID = $selectedNodeIDArray[0];
 278      }
 279      $selectedNode = eZContentObjectTreeNode::fetch( $selectedNodeID );
 280      if ( !$selectedNode )
 281      {
 282          eZDebug::writeWarning( "Content node with ID $selectedNodeID does not exist, cannot use that as parent node for node $nodeID",
 283                                 'content/action' );
 284          return $module->redirectToView( 'view', array( 'full', 2 ) );
 285      }
 286      // check if the object can be moved to (under) the selected node
 287      if ( !$selectedNode->canMoveTo( $classID ) )
 288      {
 289          eZDebug::writeError( "Cannot move node $nodeID as child of parent node $selectedNodeID, the current user does not have create permission for class ID $classID",
 290                               'content/action' );
 291          return $module->redirectToView( 'view', array( 'full', 2 ) );
 292      }
 293  
 294      // Check if we try to move the node as child of itself or one of its children
 295      if ( in_array( $node->attribute( 'node_id' ), $selectedNode->pathArray()  ) )
 296      {
 297          eZDebug::writeError( "Cannot move node $nodeID as child of itself or one of its own children (node $selectedNodeID).",
 298                               'content/action' );
 299          return $module->redirectToView( 'view', array( 'full', $node->attribute( 'node_id' ) ) );
 300      }
 301  
 302      include_once ( 'kernel/classes/ezcontentobjecttreenodeoperations.php' );
 303      if( !eZContentObjectTreeNodeOperations::move( $nodeID, $selectedNodeID ) )
 304      {
 305          eZDebug::writeError( "Failed to move node $nodeID as child of parent node $selectedNodeID",
 306                               'content/action' );
 307      }
 308  
 309      return $module->redirectToView( 'view', array( $viewMode, $nodeID, $languageCode ) );
 310  }
 311  else if ( $module->isCurrentAction( 'MoveNodeRequest' ) )
 312  {
 313      /* This action is started through the pop-up menu when a "Move" is
 314       * requested and through the use of the "Move" button. It will start the
 315       * browser to select where the node should be moved to. */
 316  
 317      if ( !$module->hasActionParameter( 'NodeID' ) )
 318      {
 319          eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
 320                               'content/action' );
 321          return $module->redirectToView( 'view', array( 'full', 2 ) );
 322      }
 323  
 324      $nodeID = $module->actionParameter( 'NodeID' );
 325      $node = eZContentObjectTreeNode::fetch( $nodeID );
 326      if ( !$node )
 327          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel', array() );
 328  
 329      if ( !$node->canMoveFrom() )
 330          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel', array() );
 331  
 332      $object =& $node->object();
 333      if ( !$object )
 334          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel', array() );
 335      $objectID = $object->attribute( 'id' );
 336      $class =& $object->contentClass();
 337  
 338      $ignoreNodesSelect = array();
 339      $ignoreNodesSelectSubtree = array();
 340      $ignoreNodesClick = array();
 341  
 342      $publishedAssigned =& $object->assignedNodes( false );
 343      foreach ( $publishedAssigned as $element )
 344      {
 345          $ignoreNodesSelect[] = $element['node_id'];
 346          $ignoreNodesSelectSubtree[] = $element['node_id'];
 347          $ignoreNodesClick[]  = $element['node_id'];
 348          $ignoreNodesSelect[] = $element['parent_node_id'];
 349      }
 350  
 351      $ignoreNodesSelect = array_unique( $ignoreNodesSelect );
 352      $ignoreNodesSelectSubtree = array_unique( $ignoreNodesSelectSubtree );
 353      $ignoreNodesClick = array_unique( $ignoreNodesClick );
 354      eZContentBrowse::browse( array( 'action_name' => 'MoveNode',
 355                                      'description_template' => 'design:content/browse_move_node.tpl',
 356                                      'keys' => array( 'class' => $class->attribute( 'id' ),
 357                                                       'class_id' => $class->attribute( 'identifier' ),
 358                                                       'classgroup' => $class->attribute( 'ingroup_id_list' ),
 359                                                       'section' => $object->attribute( 'section_id' ) ),
 360                                      'ignore_nodes_select' => $ignoreNodesSelect,
 361                                      'ignore_nodes_select_subtree' => $ignoreNodesSelectSubtree,
 362                                      'ignore_nodes_click'  => $ignoreNodesClick,
 363                                      'persistent_data' => array( 'ContentNodeID' => $nodeID,
 364                                                                  'ViewMode' => $viewMode,
 365                                                                  'ContentObjectLanguageCode' => $languageCode,
 366                                                                  'MoveNodeAction' => '1' ),
 367                                      'permission' => array( 'access' => 'create',
 368                                                             'contentclass_id' => $class->attribute( 'id' ) ),
 369                                      'content' => array( 'object_id' => $objectID,
 370                                                          'object_version' => $object->attribute( 'current_version' ),
 371                                                          'object_language' => $languageCode ),
 372                                      'start_node' => $node->attribute( 'parent_node_id' ),
 373                                      'cancel_page' => $module->redirectionURIForModule( $module, 'view', array( $viewMode, $nodeID, $languageCode ) ),
 374                                      'from_page' => "/content/action" ),
 375                               $module );
 376  
 377      return;
 378  }
 379  else if ( $module->isCurrentAction( 'SwapNode' ) )
 380  {
 381      if ( !$module->hasActionParameter( 'NodeID' ) )
 382      {
 383          eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
 384                               'content/action' );
 385          return $module->redirectToView( 'view', array( 'full', 2 ) );
 386      }
 387  
 388      $nodeID = $module->actionParameter( 'NodeID' );
 389      $node = eZContentObjectTreeNode::fetch( $nodeID );
 390  
 391      if ( !$node )
 392          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel', array() );
 393  
 394      if ( !$node->canSwap() )
 395      {
 396          eZDebug::writeError( "Cannot swap node $nodeID (no edit permission)" );
 397          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel', array() );
 398      }
 399  
 400      $nodeParentNodeID = & $node->attribute( 'parent_node_id' );
 401  
 402      $object =& $node->object();
 403      if ( !$object )
 404          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel', array() );
 405      $objectID = $object->attribute( 'id' );
 406      $objectVersion = $object->attribute( 'current_version' );
 407      $class =& $object->contentClass();
 408      $classID = $class->attribute( 'id' );
 409  
 410      if ( $module->hasActionParameter( 'NewNode' ) )
 411      {
 412          $selectedNodeID = $module->actionParameter( 'NewNode' );
 413      }
 414      else
 415      {
 416           $selectedNodeIDArray = eZContentBrowse::result( 'SwapNode' );
 417           $selectedNodeID = $selectedNodeIDArray[0];
 418      }
 419  
 420      $selectedNode = eZContentObjectTreeNode::fetch( $selectedNodeID );
 421      if ( !$selectedNode )
 422      {
 423          eZDebug::writeWarning( "Content node with ID $selectedNodeID does not exist, cannot use that as exchanging node for node $nodeID",
 424                                 'content/action' );
 425          return $module->redirectToView( 'view', array( 'full', 2 ) );
 426      }
 427      if ( !$selectedNode->canSwap() )
 428      {
 429          eZDebug::writeError( "Cannot use node $selectedNodeID as the exchanging node for $nodeID, the current user does not have edit permission for it",
 430                               'content/action' );
 431          return $module->redirectToView( 'view', array( 'full', 2 ) );
 432      }
 433  
 434      // clear cache.
 435      include_once ( 'kernel/classes/ezcontentcachemanager.php' );
 436      eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
 437  
 438      $selectedObject =& $selectedNode->object();
 439      $selectedObjectID =& $selectedObject->attribute( 'id' );
 440      $selectedObjectVersion =& $selectedObject->attribute( 'current_version' );
 441      $selectedNodeParentNodeID=& $selectedNode->attribute( 'parent_node_id' );
 442  
 443  
 444      /* In order to swap node1 and node2 a user should have the following permissions:
 445       * 1. move_from: move node1
 446       * 2. move_from: move node2
 447       * 3. move_to: move an object of the same class as node2 under parent of node1
 448       * 4. move_to: move an object of the same class as node1 under parent of node2
 449       *
 450       * The First two has already been checked. Let's check the rest.
 451       */
 452      $nodeParent            =& $node->attribute( 'parent' );
 453      $selectedNodeParent    =& $selectedNode->attribute( 'parent' );
 454      $objectClassID         =& $object->attribute( 'contentclass_id' );
 455      $selectedObjectClassID =& $selectedObject->attribute( 'contentclass_id' );
 456  
 457      if ( !$nodeParent || !$selectedNodeParent )
 458          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel', array() );
 459  
 460      if ( !$nodeParent->canMoveTo( $selectedObjectClassID ) )
 461      {
 462          eZDebug::writeError( "Cannot move an object of class $selectedObjectClassID to node $nodeParentNodeID (no create permission)" );
 463          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel', array() );
 464      }
 465      if ( !$selectedNodeParent->canMoveTo( $objectClassID ) )
 466      {
 467          eZDebug::writeError( "Cannot move an object of class $objectClassID to node $selectedNodeParentNodeID (no create permission)" );
 468          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel', array() );
 469      }
 470  
 471      // exchange contentobject ids and versions.
 472      $node->setAttribute( 'contentobject_id', $selectedObjectID );
 473      $node->setAttribute( 'contentobject_version', $selectedObjectVersion );
 474  
 475      $db =& eZDB::instance();
 476      $db->begin();
 477      $node->store();
 478      $selectedNode->setAttribute( 'contentobject_id', $objectID );
 479      $selectedNode->setAttribute( 'contentobject_version', $objectVersion );
 480      $selectedNode->store();
 481  
 482      // clear user policy cache if this was a user object
 483      if ( $object->attribute( 'contentclass_id' ) == $userClassID )
 484      {
 485          eZUser::cleanupCache();
 486      }
 487  
 488      // modify path string
 489      $changedOriginalNode = eZContentObjectTreeNode::fetch( $nodeID );
 490      $changedOriginalNode->updateSubTreePath();
 491      $changedTargetNode = eZContentObjectTreeNode::fetch( $selectedNodeID );
 492      $changedTargetNode->updateSubTreePath();
 493  
 494      // modify section
 495      if ( $changedOriginalNode->attribute( 'main_node_id' ) == $changedOriginalNode->attribute( 'node_id' ) )
 496      {
 497          $changedOriginalObject =& $changedOriginalNode->object();
 498          $parentObject =& $nodeParent->object();
 499          if ( $changedOriginalObject->attribute( 'section_id' ) != $parentObject->attribute( 'section_id' ) )
 500          {
 501  
 502              eZContentObjectTreeNode::assignSectionToSubTree( $changedOriginalNode->attribute( 'main_node_id' ),
 503                                                               $parentObject->attribute( 'section_id' ),
 504                                                               $changedOriginalObject->attribute( 'section_id' ) );
 505          }
 506      }
 507      if ( $changedTargetNode->attribute( 'main_node_id' ) == $changedTargetNode->attribute( 'node_id' ) )
 508      {
 509          $changedTargetObject =& $changedTargetNode->object();
 510          $selectedParentObject =& $selectedNodeParent->object();
 511          if ( $changedTargetObject->attribute( 'section_id' ) != $selectedParentObject->attribute( 'section_id' ) )
 512          {
 513  
 514              eZContentObjectTreeNode::assignSectionToSubTree( $changedTargetNode->attribute( 'main_node_id' ),
 515                                                               $selectedParentObject->attribute( 'section_id' ),
 516                                                               $changedTargetObject->attribute( 'section_id' ) );
 517          }
 518      }
 519  
 520      $db->commit();
 521  
 522      // clear cache for new placement.
 523      eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
 524  
 525      return $module->redirectToView( 'view', array( $viewMode, $nodeID, $languageCode ) );
 526  }
 527  else if ( $module->isCurrentAction( 'SwapNodeRequest' ) )
 528  {
 529      /* This action brings a browse screen up to select with which the selected
 530       * node should be swapped. It will not actually move the nodes. */
 531  
 532      if ( !$module->hasActionParameter( 'NodeID' ) )
 533      {
 534          eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
 535                               'content/action' );
 536          return $module->redirectToView( 'view', array( 'full', 2 ) );
 537      }
 538  
 539      $nodeID = $module->actionParameter( 'NodeID' );
 540      $node = eZContentObjectTreeNode::fetch( $nodeID );
 541      if ( !$node )
 542          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel', array() );
 543  
 544      if ( !$node->canSwap() )
 545      {
 546          eZDebug::writeError( "Cannot swap node $nodeID (no edit permission)" );
 547          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel', array() );
 548      }
 549  
 550      $object =& $node->object();
 551      if ( !$object )
 552          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel', array() );
 553      $objectID = $object->attribute( 'id' );
 554      $class =& $object->contentClass();
 555  
 556      $ignoreNodesSelect = array( $nodeID );
 557      $ignoreNodesClick = array();
 558  
 559      eZContentBrowse::browse( array( 'action_name' => 'SwapNode',
 560                                      'description_template' => 'design:content/browse_swap_node.tpl',
 561                                      'keys' => array( 'class' => $class->attribute( 'id' ),
 562                                                       'class_id' => $class->attribute( 'identifier' ),
 563                                                       'classgroup' => $class->attribute( 'ingroup_id_list' ),
 564                                                       'section' => $object->attribute( 'section_id' ) ),
 565                                      'ignore_nodes_select' => $ignoreNodesSelect,
 566                                      'ignore_nodes_click'  => $ignoreNodesClick,
 567                                      'persistent_data' => array( 'ContentNodeID' => $nodeID,
 568                                                                  'ViewMode' => $viewMode,
 569                                                                  'ContentObjectLanguageCode' => $languageCode,
 570                                                                  'SwapNodeAction' => '1' ),
 571                                      'permission' => array( 'access' => 'edit',
 572                                                             'contentclass_id' => $class->attribute( 'id' ) ),
 573                                      'content' => array( 'object_id' => $objectID,
 574                                                          'object_version' => $object->attribute( 'current_version' ),
 575                                                          'object_language' => $languageCode ),
 576                                      'start_node' => $node->attribute( 'parent_node_id' ),
 577                                      'cancel_page' => $module->redirectionURIForModule( $module, 'view', array( $viewMode, $nodeID, $languageCode ) ),
 578                                      'from_page' => "/content/action" ),
 579                               $module );
 580  
 581      return;
 582  }
 583  else if ( $module->isCurrentAction( 'UpdateMainAssignment' ) )
 584  {
 585      /* This action selects a different main assignment node for the object. */
 586  
 587      if ( !$module->hasActionParameter( 'ObjectID' ) )
 588      {
 589          eZDebug::writeError( "Missing ObjectID parameter for action " . $module->currentAction(),
 590                               'content/action' );
 591          return $module->redirectToView( 'view', array( 'full', 2 ) );
 592      }
 593      if ( !$module->hasActionParameter( 'NodeID' ) )
 594      {
 595          eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
 596                               'content/action' );
 597          return $module->redirectToView( 'view', array( 'full', 2 ) );
 598      }
 599  
 600      $objectID = $module->actionParameter( 'ObjectID' );
 601      $nodeID = $module->actionParameter( 'NodeID' );
 602  
 603      if ( $module->hasActionParameter( 'MainAssignmentID' ) )
 604      {
 605          $mainAssignmentID = $module->actionParameter( 'MainAssignmentID' );
 606  
 607          $object =& eZContentObject::fetch( $objectID );
 608          if ( !$object )
 609          {
 610              return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
 611          }
 612  
 613          $existingMainNodeID = false;
 614          $existingMainNode =& $object->attribute( 'main_node' );
 615          if ( $existingMainNode )
 616              $existingMainNodeID = $existingMainNode->attribute( 'node_id' );
 617          if ( $existingMainNodeID === false or
 618               $existingMainNodeID != $mainAssignmentID )
 619          {
 620              if ( $existingMainNode and
 621                   !$existingMainNode->checkAccess( 'edit' ) )
 622              {
 623                  return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel', array() );
 624              }
 625  
 626              $newMainNode = eZContentObjectTreeNode::fetch( $mainAssignmentID );
 627              if ( !$newMainNode )
 628              {
 629                  return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
 630              }
 631  
 632              if ( !$newMainNode->checkAccess( 'edit' ) )
 633              {
 634                  return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 635              }
 636  
 637              eZContentObjectTreeNode::updateMainNodeID( $mainAssignmentID, $objectID, false,
 638                                                         $newMainNode->attribute( 'parent_node_id' ) );
 639  
 640              include_once ( 'kernel/classes/ezcontentcachemanager.php' );
 641              eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
 642          }
 643      }
 644      else
 645      {
 646          eZDebug::writeError( "No MainAssignmentID found for action " . $module->currentAction(),
 647                               'content/action' );
 648      }
 649  
 650      return $module->redirectToView( 'view', array( $viewMode, $nodeID, $languageCode ) );
 651  }
 652  else if ( $module->isCurrentAction( 'AddAssignment' ) or
 653            $module->isCurrentAction( 'SelectAssignmentLocation' ) )
 654  {
 655      if ( !$module->hasActionParameter( 'ObjectID' ) )
 656      {
 657          eZDebug::writeError( "Missing ObjectID parameter for action " . $module->currentAction(),
 658                               'content/action' );
 659          return $module->redirectToView( 'view', array( 'full', 2 ) );
 660      }
 661      if ( !$module->hasActionParameter( 'NodeID' ) )
 662      {
 663          eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
 664                               'content/action' );
 665          return $module->redirectToView( 'view', array( 'full', 2 ) );
 666      }
 667  
 668      $objectID = $module->actionParameter( 'ObjectID' );
 669      $nodeID = $module->actionParameter( 'NodeID' );
 670  
 671      $object =& eZContentObject::fetch( $objectID );
 672      if ( !$object )
 673      {
 674          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
 675      }
 676  
 677      $user =& eZUser::currentUser();
 678      if ( !$object->checkAccess( 'edit' ) &&
 679           !$user->attribute( 'has_manage_locations' ) )
 680      {
 681          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 682      }
 683  
 684      $existingNode = eZContentObjectTreeNode::fetch( $nodeID );
 685      if ( !$existingNode )
 686      {
 687          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
 688      }
 689  
 690      $class =& $object->contentClass();
 691      if ( $module->isCurrentAction( 'AddAssignment' ) )
 692      {
 693          $selectedNodeIDArray = eZContentBrowse::result( 'AddNodeAssignment' );
 694          if ( !is_array( $selectedNodeIDArray ) )
 695              $selectedNodeIDArray = array();
 696  
 697          $nodeAssignmentList =& eZNodeAssignment::fetchForObject( $objectID, $object->attribute( 'current_version' ), 0, false );
 698          $assignedNodes =& $object->assignedNodes();
 699  
 700          $parentNodeIDArray = array();
 701          $setMainNode = false;
 702          $hasMainNode = false;
 703          foreach ( $assignedNodes as $assignedNode )
 704          {
 705              if ( $assignedNode->attribute( 'is_main' ) )
 706                  $hasMainNode = true;
 707  
 708              $append = false;
 709              foreach ( $nodeAssignmentList as $nodeAssignment )
 710              {
 711                  if ( $nodeAssignment['parent_node'] == $assignedNode->attribute( 'parent_node_id' ) )
 712                  {
 713                      $append = true;
 714                      break;
 715                  }
 716              }
 717              if ( $append )
 718              {
 719                  $parentNodeIDArray[] = $assignedNode->attribute( 'parent_node_id' );
 720              }
 721          }
 722          if ( !$hasMainNode )
 723              $setMainNode = true;
 724  
 725          $mainNodeID = $existingNode->attribute( 'main_node_id' );
 726          $objectName = $object->attribute( 'name' );
 727  
 728          $db =& eZDB::instance();
 729          $db->begin();
 730          $locationAdded = false;
 731          $node = eZContentObjectTreeNode::fetch( $nodeID );
 732          foreach ( $selectedNodeIDArray as $selectedNodeID )
 733          {
 734              if ( !in_array( $selectedNodeID, $parentNodeIDArray ) )
 735              {
 736                  $parentNode = eZContentObjectTreeNode::fetch( $selectedNodeID );
 737                  $parentNodeObject =& $parentNode->attribute( 'object' );
 738  
 739                  $canCreate = ( ( $parentNode->checkAccess( 'create', $class->attribute( 'id' ), $parentNodeObject->attribute( 'contentclass_id' ) ) == 1 ) ||
 740                                 ( $parentNode->canAddLocation() && $node->canRead() ) );
 741  
 742                  if ( $canCreate )
 743                  {
 744                      $insertedNode =& $object->addLocation( $selectedNodeID, true );
 745  
 746                      // Now set is as published and fix main_node_id
 747                      $insertedNode->setAttribute( 'contentobject_is_published', 1 );
 748                      $insertedNode->setAttribute( 'main_node_id', $node->attribute( 'main_node_id' ) );
 749                      $insertedNode->setAttribute( 'contentobject_version', $node->attribute( 'contentobject_version' ) );
 750                      // Make sure the path_identification_string is set correctly.
 751                      $insertedNode->updateSubTreePath();
 752                      $insertedNode->sync();
 753  
 754                      $locationAdded = true;
 755                  }
 756              }
 757          }
 758          if ( $locationAdded )
 759          {
 760              if ( $object->attribute( 'contentclass_id' ) == $userClassID )
 761              {
 762                  eZUser::cleanupCache();
 763              }
 764          }
 765          $db->commit();
 766  
 767          include_once ( 'kernel/classes/ezcontentcachemanager.php' );
 768          eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
 769      }
 770      else if ( $module->isCurrentAction( 'SelectAssignmentLocation' ) )
 771      {
 772          $ignoreNodesSelect = array();
 773          $ignoreNodesClick  = array();
 774  
 775          $assigned =& eZNodeAssignment::fetchForObject( $objectID, $object->attribute( 'current_version' ), 0, false );
 776          $publishedAssigned =& $object->assignedNodes( false );
 777          $isTopLevel = false;
 778          foreach ( $publishedAssigned as $element )
 779          {
 780              $append = false;
 781              if ( $element['parent_node_id'] == 1 )
 782                  $isTopLevel = true;
 783              foreach ( $assigned as $ass )
 784              {
 785                  if ( $ass['parent_node'] == $element['parent_node_id'] )
 786                  {
 787                      $append = true;
 788                      break;
 789                  }
 790              }
 791              if ( $append )
 792              {
 793                  $ignoreNodesSelect[] = $element['node_id'];
 794                  $ignoreNodesClick[]  = $element['node_id'];
 795                  $ignoreNodesSelect[] = $element['parent_node_id'];
 796              }
 797          }
 798  
 799          if ( !$isTopLevel )
 800          {
 801              $ignoreNodesSelect = array_unique( $ignoreNodesSelect );
 802              $objectID = $object->attribute( 'id' );
 803              eZContentBrowse::browse( array( 'action_name' => 'AddNodeAssignment',
 804                                              'description_template' => 'design:content/browse_placement.tpl',
 805                                              'keys' => array( 'class' => $class->attribute( 'id' ),
 806                                                               'class_id' => $class->attribute( 'identifier' ),
 807                                                               'classgroup' => $class->attribute( 'ingroup_id_list' ),
 808                                                               'section' => $object->attribute( 'section_id' ) ),
 809                                              'ignore_nodes_select' => $ignoreNodesSelect,
 810                                              'ignore_nodes_click'  => $ignoreNodesClick,
 811                                              'persistent_data' => array( 'ContentNodeID' => $nodeID,
 812                                                                          'ContentObjectID' => $objectID,
 813                                                                          'ViewMode' => $viewMode,
 814                                                                          'ContentObjectLanguageCode' => $languageCode,
 815                                                                          'AddAssignmentAction' => '1' ),
 816                                              'content' => array( 'object_id' => $objectID,
 817                                                                  'object_version' => $object->attribute( 'current_version' ),
 818                                                                  'object_language' => $languageCode ),
 819                                              'cancel_page' => $module->redirectionURIForModule( $module, 'view', array( $viewMode, $nodeID, $languageCode ) ),
 820                                              'from_page' => "/content/action" ),
 821                                       $module );
 822  
 823              return;
 824          }
 825          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 826      }
 827  
 828      return $module->redirectToView( 'view', array( $viewMode, $nodeID, $languageCode ) );
 829  }
 830  else if ( $module->isCurrentAction( 'RemoveAssignment' )  )
 831  {
 832      if ( !$module->hasActionParameter( 'ObjectID' ) )
 833      {
 834          eZDebug::writeError( "Missing ObjectID parameter for action RemoveAssignment",
 835                               'content/action' );
 836          return $module->redirectToView( 'view', array( 'full', 2 ) );
 837      }
 838      if ( !$module->hasActionParameter( 'NodeID' ) )
 839      {
 840          eZDebug::writeError( "Missing NodeID parameter for action RemoveAssignment",
 841                               'content/action' );
 842          return $module->redirectToView( 'view', array( 'full', 2 ) );
 843      }
 844  
 845      $objectID = $module->actionParameter( 'ObjectID' );
 846      $nodeID = $module->actionParameter( 'NodeID' );
 847      $redirectNodeID = $nodeID;
 848  
 849      $object =& eZContentObject::fetch( $objectID );
 850      if ( !$object )
 851      {
 852          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
 853      }
 854  
 855      $user =& eZUser::currentUser();
 856      if ( !$object->checkAccess( 'edit' ) &&
 857           !$user->hasManageLocations() )
 858      {
 859          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
 860      }
 861  
 862      if ( $module->hasActionParameter( 'AssignmentIDSelection' ) )
 863      {
 864          eZDebug::writeError( "Use of POST variable 'AssignmentIDSelection' is deprecated, use the node ID and put it in 'LocationIDSelection' instead" );
 865          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
 866      }
 867  
 868      if ( !$module->hasActionParameter( 'LocationIDSelection' ) )
 869          return $module->redirectToView( 'view', array( $viewMode, $redirectNodeID, $languageCode ) );
 870  
 871      $locationIDSelection = $module->actionParameter( 'LocationIDSelection' );
 872  
 873      $hasChildren = false;
 874  
 875      $nodes = array();
 876      foreach ( $locationIDSelection as $locationID )
 877      {
 878          $nodes[] = eZContentObjectTreeNode::fetch( $locationID );
 879      }
 880      $removeList = array();
 881      $nodeRemoveList = array();
 882      foreach ( array_keys( $nodes ) as $key )
 883      {
 884          $node =& $nodes[$key];
 885          if ( $node )
 886          {
 887              // Security checks, removal of current node is not allowed
 888              // and we require removal rights
 889              if ( !$node->canRemove() &&
 890                   !$node->canRemoveLocation() )
 891                  continue;
 892              if ( $node->attribute( 'node_id' ) == $nodeID )
 893              {
 894                  $redirectNodeID = $node->attribute( 'parent_node_id' );
 895              }
 896  
 897              $removeList[] = $node->attribute( 'node_id' );
 898              $nodeRemoveList[] =& $node;
 899              $count = $node->childrenCount( false );
 900              unset( $node );
 901  
 902              if ( $count > 0 )
 903              {
 904                  $hasChildren = true;
 905              }
 906          }
 907      }
 908  
 909      if ( $hasChildren )
 910      {
 911          $http->setSessionVariable( 'CurrentViewMode', $viewMode );
 912          $http->setSessionVariable( 'DeleteIDArray', $removeList );
 913          $http->setSessionVariable( 'ContentObjectID', $objectID );
 914          $http->setSessionVariable( 'ContentNodeID', $nodeID );
 915          $http->setSessionVariable( 'ContentLanguage', $languageCode );
 916          return $module->redirectToView( 'removeobject' );
 917      }
 918      else
 919      {
 920          $mainNodeChanged = false;
 921          $nodeAssignmentList =& eZNodeAssignment::fetchForObject( $objectID, $object->attribute( 'current_version' ), 0, false );
 922          $nodeAssignmentIDList =array();
 923  
 924          $db =& eZDB::instance();
 925          $db->begin();
 926          foreach ( $nodeRemoveList as $key => $node )
 927          {
 928              foreach ( array_keys( $nodeAssignmentList ) as $nodeAssignmentKey )
 929              {
 930                  $nodeAssignment =& $nodeAssignmentList[$nodeAssignmentKey];
 931                  if ( $nodeAssignment['parent_node'] == $node->attribute( 'parent_node_id' ) )
 932                  {
 933                      $nodeAssignmentIDList[] = $nodeAssignment['id'];
 934                      unset( $nodeAssignmentList[$nodeAssignmentKey] );
 935                  }
 936              }
 937  
 938              if ( $node->attribute( 'node_id' ) == $node->attribute( 'main_node_id' ) )
 939                  $mainNodeChanged = true;
 940              $node->remove();
 941          }
 942          eZNodeAssignment::purgeByID( array_unique( $nodeAssignmentIDList ) );
 943  
 944          if ( $mainNodeChanged )
 945          {
 946              $allNodes =& $object->assignedNodes();
 947              $mainNode =& $allNodes[0];
 948              eZContentObjectTreeNode::updateMainNodeID( $mainNode->attribute( 'node_id' ), $objectID, false, $mainNode->attribute( 'parent_node_id' ) );
 949          }
 950          $db->commit();
 951      }
 952  
 953      include_once ( 'kernel/classes/ezcontentcachemanager.php' );
 954      eZContentCacheManager::clearObjectViewCacheIfNeeded( $objectID );
 955      // clear user policy cache if this was a user object
 956      if ( $object->attribute( 'contentclass_id' ) == $userClassID )
 957      {
 958          eZUser::cleanupCache();
 959      }
 960  
 961      // we don't clear template block cache here since it's cleared in eZContentObjectTreeNode::remove()
 962  
 963      return $module->redirectToView( 'view', array( $viewMode, $redirectNodeID, $languageCode ) );
 964  }
 965  else if ( $http->hasPostVariable( 'EditButton' )  )
 966  {
 967      if ( $http->hasPostVariable( 'ContentObjectID' ) )
 968      {
 969          $parameters = array( $http->postVariable( 'ContentObjectID' ) );
 970          if ( $http->hasPostVariable( 'ContentObjectVersion' ) )
 971          {
 972              $parameters[] = $http->postVariable( 'ContentObjectVersion' );
 973              if ( $http->hasPostVariable( 'ContentObjectLanguageCode' ) )
 974              {
 975                  $parameters[] = $http->postVariable( 'ContentObjectLanguageCode' );
 976              }
 977          }
 978          else
 979          {
 980              if ( $http->hasPostVariable( 'ContentObjectLanguageCode' ) )
 981              {
 982                  $languageCode = $http->postVariable( 'ContentObjectLanguageCode' );
 983                  if ( $languageCode == '' )
 984                  {
 985                      $parameters[] = 'a'; // this will be treatead as not entering the version number and offering
 986                                           // list with new languages
 987                  }
 988                  else
 989                  {
 990                      $parameters[] = 'f'; // this will be treatead as not entering the version number
 991                      $parameters[]= $languageCode;
 992                  }
 993              }
 994          }
 995  
 996          if ( $http->hasPostVariable( 'RedirectURIAfterPublish' ) )
 997          {
 998              $http->setSessionVariable( 'RedirectURIAfterPublish', $http->postVariable( 'RedirectURIAfterPublish' ) );
 999          }
1000  
1001          $module->redirectToView( 'edit', $parameters );
1002          return;
1003      }
1004  }
1005  else if ( $http->hasPostVariable( 'PreviewPublishButton' )  )
1006  {
1007      if ( $http->hasPostVariable( 'ContentObjectID' ) )
1008      {
1009          $parameters = array( $http->postVariable( 'ContentObjectID' ) );
1010          if ( $http->hasPostVariable( 'ContentObjectVersion' ) )
1011          {
1012              $parameters[] = $http->postVariable( 'ContentObjectVersion' );
1013              if ( $http->hasPostVariable( 'ContentObjectLanguageCode' ) )
1014              {
1015                  $parameters[] = $http->postVariable( 'ContentObjectLanguageCode' );
1016              }
1017          }
1018          $module->setCurrentAction( 'Publish', 'edit' );
1019          return $module->run( 'edit', $parameters );
1020      }
1021  }
1022  else if ( $http->hasPostVariable( 'RemoveButton' ) )
1023  {
1024      if ( $http->hasPostVariable( 'ViewMode' ) )
1025      {
1026          $viewMode = $http->postVariable( 'ViewMode' );
1027      }
1028      else
1029      {
1030          $viewMode = 'full';
1031      }
1032  //     if ( $http->hasPostVariable( 'TopLevelNode' ) )
1033  //     {
1034  //         $topLevelNode = $http->postVariable( 'TopLevelNode' );
1035  //     }
1036  //     else
1037  //     {
1038  //         $topLevelNode = '2';
1039  //     }
1040      $contentNodeID = 2;
1041      if ( $http->hasPostVariable( 'ContentNodeID' ) )
1042          $contentNodeID = $http->postVariable( 'ContentNodeID' );
1043      $contentObjectID = 1;
1044      if ( $http->hasPostVariable( 'ContentObjectID' ) )
1045          $contentObjectID = $http->postVariable( 'ContentObjectID' );
1046  
1047      if ( $http->hasPostVariable( 'DeleteIDArray' ) )
1048      {
1049          $deleteIDArray = $http->postVariable( 'DeleteIDArray' );
1050          if ( is_array( $deleteIDArray ) && count( $deleteIDArray ) > 0 )
1051          {
1052              $http->setSessionVariable( 'CurrentViewMode', $viewMode );
1053              $http->setSessionVariable( 'ContentNodeID', $contentNodeID );
1054              $http->setSessionVariable( 'ContentObjectID', $contentObjectID );
1055              $http->setSessionVariable( 'DeleteIDArray', $deleteIDArray );
1056              include_once ( 'kernel/classes/ezsection.php' );
1057              $object =& eZContentObject::fetch( $contentObjectID );
1058              eZSection::setGlobalID( $object->attribute( 'section_id' ) );
1059              $section = eZSection::fetch( $object->attribute( 'section_id' ) );
1060              if ( $section )
1061                  $navigationPartIdentifier = $section->attribute( 'navigation_part_identifier' );
1062              else
1063                  $navigationPartIdentifier = null;
1064              if ( $navigationPartIdentifier and $navigationPartIdentifier == 'ezusernavigationpart' )
1065              {
1066                  $module->redirectTo( $module->functionURI( 'removeuserobject' ) . '/' );
1067              }
1068              elseif ( $navigationPartIdentifier and $navigationPartIdentifier == 'ezmedianavigationpart' )
1069              {
1070                  $module->redirectTo( $module->functionURI( 'removemediaobject' ) . '/' );
1071              }
1072              else
1073              {
1074                  $module->redirectTo( $module->functionURI( 'removeobject' ) . '/' );
1075              }
1076          }
1077          else
1078          {
1079              $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $contentNodeID . '/' );
1080          }
1081      }
1082      else
1083      {
1084          $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $contentNodeID . '/' );
1085      }
1086  }
1087  else if ( $http->hasPostVariable( 'UpdatePriorityButton' ) )
1088  {
1089      include_once ( 'kernel/classes/ezcontentcache.php' );
1090      if ( $http->hasPostVariable( 'ViewMode' ) )
1091      {
1092          $viewMode = $http->postVariable( 'ViewMode' );
1093      }
1094      else
1095      {
1096          $viewMode = 'full';
1097      }
1098  
1099      if ( $http->hasPostVariable( 'ContentNodeID' ) )
1100      {
1101          $contentNodeID = $http->postVariable( 'ContentNodeID' );
1102      }
1103      else
1104      {
1105          eZDebug::writeError( "Variable 'ContentNodeID' can not be found in template." );
1106          $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $contentNodeID . '/' );
1107          return;
1108      }
1109      if ( $http->hasPostVariable( 'Priority' ) and $http->hasPostVariable( 'PriorityID' ) )
1110      {
1111          $contentNode = eZContentObjectTreeNode::fetch( $contentNodeID );
1112          if ( !$contentNode->attribute( 'can_edit' ) )
1113          {
1114              eZDebug::writeError( 'Current user can not update the priorities because he has no permissions to edit the node' );
1115              $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $contentNodeID . '/' );
1116              return;
1117          }
1118          $priorityArray = $http->postVariable( 'Priority' );
1119          $priorityIDArray = $http->postVariable( 'PriorityID' );
1120  
1121          $db =& eZDB::instance();
1122          $db->begin();
1123          for ( $i=0; $i<count( $priorityArray );$i++ )
1124          {
1125              $priority = (int) $priorityArray[$i];
1126              $nodeID = (int) $priorityIDArray[$i];
1127              $db->query( "UPDATE ezcontentobject_tree SET priority=$priority WHERE node_id=$nodeID" );
1128          }
1129          $db->commit();
1130      }
1131  
1132      if ( $http->hasPostVariable( 'ContentObjectID' ) )
1133      {
1134          $objectID = $http->postVariable( 'ContentObjectID' );
1135          include_once ( 'kernel/classes/ezcontentcachemanager.php' );
1136          eZContentCacheManager::clearContentCache( $objectID );
1137      }
1138  
1139      $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $contentNodeID . '/' );
1140      return;
1141  }
1142  else if ( $http->hasPostVariable( "ActionAddToBookmarks" ) )
1143  {
1144      $user =& eZUser::currentUser();
1145      $nodeID = false;
1146      if ( $http->hasPostVariable( 'ContentNodeID' ) )
1147      {
1148          $nodeID = $http->postVariable( 'ContentNodeID' );
1149          $node = eZContentObjectTreeNode::fetch( $nodeID );
1150          $bookmark = eZContentBrowseBookmark::createNew( $user->id(), $nodeID, $node->attribute( 'name' ) );
1151      }
1152      if ( !$nodeID )
1153      {
1154          $contentINI =& eZINI::instance( 'content.ini' );
1155          $nodeID = $contentINI->variable( 'NodeSettings', 'RootNode' );
1156      }
1157      if ( $http->hasPostVariable( 'ViewMode' ) )
1158      {
1159          $viewMode = $http->postVariable( 'ViewMode' );
1160      }
1161      else
1162      {
1163          $viewMode = 'full';
1164      }
1165      $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $nodeID . '/' );
1166      return;
1167  }
1168  else if ( $http->hasPostVariable( "ActionAddToNotification" ) )
1169  {
1170      $nodeID = $http->postVariable( 'ContentNodeID' );
1171      $module->redirectTo( 'notification/addtonotification/' . $nodeID . '/' );
1172      return;
1173  }
1174  else if ( $http->hasPostVariable( "ContentObjectID" )  )
1175  {
1176      $objectID = $http->postVariable( "ContentObjectID" );
1177      $action = $http->postVariable( "ContentObjectID" );
1178  
1179  
1180      // Check which action to perform
1181      if ( $http->hasPostVariable( "ActionAddToBasket" ) )
1182      {
1183          $shopModule =& eZModule::exists( "shop" );
1184          $result =& $shopModule->run( "basket", array() );
1185          if ( isset( $result['content'] ) && $result['content'] )
1186          {
1187              return $result;
1188          }
1189          else
1190          {
1191              $module->setExitStatus( $shopModule->exitStatus() );
1192              $module->setRedirectURI( $shopModule->redirectURI() );
1193          }
1194  
1195      }
1196      else if ( $http->hasPostVariable( "ActionAddToWishList" ) )
1197      {
1198          $user =& eZUser::currentUser();
1199          if ( !$user->isLoggedIn() )
1200              return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
1201  
1202          $shopModule =& eZModule::exists( "shop" );
1203          $result =& $shopModule->run( "wishlist", array() );
1204          $module->setExitStatus( $shopModule->exitStatus() );
1205          $module->setRedirectURI( $shopModule->redirectURI() );
1206      }
1207      else if ( $http->hasPostVariable( "ActionPreview" ) )
1208      {
1209          $user =& eZUser::currentUser();
1210          $object =& eZContentObject::fetch(  $objectID );
1211          $module->redirectTo( $module->functionURI( 'versionview' ) . '/' . $objectID . '/' . $object->attribute( 'current_version' ) . '/' );
1212          return;
1213  
1214      }
1215      else if ( $http->hasPostVariable( "ActionRemove" ) )
1216      {
1217          if ( $http->hasPostVariable( 'ViewMode' ) )
1218          {
1219              $viewMode = $http->postVariable( 'ViewMode' );
1220          }
1221          else
1222          {
1223              $viewMode = 'full';
1224          }
1225          $parentNodeID = 2;
1226          $contentNodeID = null;
1227          if ( $http->hasPostVariable( 'ContentNodeID' ) and is_numeric( $http->postVariable( 'ContentNodeID' ) ) )
1228          {
1229              $contentNodeID = $http->postVariable( 'ContentNodeID' );
1230              $node = eZContentObjectTreeNode::fetch( $contentNodeID );
1231              $parentNodeID =& $node->attribute( 'parent_node_id' );
1232          }
1233          $contentObjectID = 1;
1234          if ( $http->hasPostVariable( 'ContentObjectID' ) )
1235              $contentObjectID = $http->postVariable( 'ContentObjectID' );
1236  
1237          if ( $contentNodeID != null )
1238          {
1239              $http->setSessionVariable( 'CurrentViewMode', $viewMode );
1240              $http->setSessionVariable( 'ContentNodeID', $parentNodeID );
1241              $http->setSessionVariable( 'ContentObjectID', $contentObjectID );
1242              $http->setSessionVariable( 'DeleteIDArray', array( $contentNodeID ) );
1243              $object =& eZContentObject::fetchByNodeID( $contentNodeID);
1244              include_once ( 'kernel/classes/ezsection.php' );
1245              eZSection::setGlobalID( $object->attribute( 'section_id' ) );
1246              $section = eZSection::fetch( $object->attribute( 'section_id' ) );
1247              if ( $section )
1248                  $navigationPartIdentifier = $section->attribute( 'navigation_part_identifier' );
1249              else
1250                  $navigationPartIdentifier = null;
1251              if ( $navigationPartIdentifier and $navigationPartIdentifier == 'ezusernavigationpart' )
1252              {
1253                  $module->redirectTo( $module->functionURI( 'removeuserobject' ) . '/' );
1254              }
1255              elseif ( $navigationPartIdentifier and $navigationPartIdentifier == 'ezmedianavigationpart' )
1256              {
1257                  $module->redirectTo( $module->functionURI( 'removemediaobject' ) . '/' );
1258              }
1259              else
1260              {
1261                  $module->redirectTo( $module->functionURI( 'removeobject' ) . '/' );
1262              }
1263          }
1264          else
1265              $module->redirectToView( 'view', array( $viewMode, $parentNodeID ) );
1266      }
1267      else if ( $http->hasPostVariable( "ActionCollectInformation" ) )
1268      {
1269          $Result =& $module->run( "collectinformation", array() );
1270          return $Result;
1271      }
1272      else
1273      {
1274          include_once ( 'lib/ezutils/classes/ezextension.php' );
1275          $baseDirectory = eZExtension::baseDirectory();
1276          $contentINI =& eZINI::instance( 'content.ini' );
1277          $extensionDirectories = $contentINI->variable( 'ActionSettings', 'ExtensionDirectories' );
1278          foreach ( $extensionDirectories as $extensionDirectory )
1279          {
1280              $extensionPath = $baseDirectory . '/' . $extensionDirectory . '/actions/content_actionhandler.php';
1281              if ( file_exists( $extensionPath ) )
1282              {
1283                  include_once( $extensionPath );
1284                  $actionFunction = $extensionDirectory . '_ContentActionHandler';
1285                  if ( function_exists( $actionFunction ) )
1286                  {
1287                      $actionResult = $actionFunction( $Module, $http, $objectID );
1288                      if ( $actionResult )
1289                          return $actionResult;
1290                  }
1291              }
1292          }
1293          eZDebug::writeError( "Unknown content object action", "kernel/content/action.php" );
1294      }
1295  }
1296  else if ( $http->hasPostVariable( 'RedirectButton' ) )
1297  {
1298      if ( $http->hasPostVariable( 'RedirectURI' ) )
1299      {
1300          $module->redirectTo( $http->postVariable( 'RedirectURI' ) );
1301          return;
1302      }
1303  }
1304  else if ( $http->hasPostVariable( 'DestinationURL' ) )
1305  {
1306      $postVariables = $http->attribute( 'post' );
1307      $destinationURL = $http->postVariable( 'DestinationURL' );
1308      $additionalParams = '';
1309  
1310      foreach( $postVariables as $key => $value )
1311      {
1312          if ( is_array( $value ) )
1313          {
1314              $value = implode( ',', $value );
1315          }
1316          if ( strpos( $key, 'Param' ) === 0 )
1317          {
1318              $destinationURL .= '/' . $value;
1319          }
1320          else if ( $key != 'DestinationURL' &&
1321                    $key != 'Submit' )
1322          {
1323              $additionalParams .= "/$key/$value";
1324          }
1325      }
1326  
1327      $module->redirectTo( '/' . $destinationURL . $additionalParams );
1328      return;
1329  }
1330  else if ( $module->isCurrentAction( 'ClearViewCache' ) or
1331            $module->isCurrentAction( 'ClearViewCacheSubtree' ) )
1332  {
1333      if ( !$module->hasActionParameter( 'ObjectID' ) )
1334      {
1335          eZDebug::writeError( "Missing ObjectID parameter for action " . $module->currentAction(),
1336                               'content/action' );
1337          return $module->redirectToView( 'view', array( 'full', 2 ) );
1338      }
1339      if ( !$module->hasActionParameter( 'NodeID' ) )
1340      {
1341          eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
1342                               'content/action' );
1343          return $module->redirectToView( 'view', array( 'full', 2 ) );
1344      }
1345  
1346      $objectID = $module->actionParameter( 'ObjectID' );
1347      $nodeID = $module->actionParameter( 'NodeID' );
1348  
1349      $object =& eZContentObject::fetch( $objectID );
1350      if ( !$object )
1351      {
1352          return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
1353      }
1354  
1355      $user =& eZUser::currentUser();
1356      $result = $user->hasAccessTo( 'setup', 'managecache' );
1357      if ( $result['accessWord'] != 'yes' )
1358      {
1359          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
1360      }
1361  
1362      include_once ( 'kernel/classes/ezcontentcachemanager.php' );
1363      if ( $module->isCurrentAction( 'ClearViewCache' ) )
1364      {
1365          eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
1366      }
1367      else
1368      {
1369          $node = eZContentObjectTreeNode::fetch( $nodeID );
1370          if ( !$node )
1371          {
1372              return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
1373          }
1374          $limit = 50;
1375          $offset = 0;
1376          $params = array( 'AsObject' => false,
1377                           'Depth' => false,
1378                           'Limitation' => array() ); // Empty array means no permission checking
1379          $subtreeCount = $node->subTreeCount( $params );
1380          while ( $offset < $subtreeCount )
1381          {
1382              $params['Offset'] = $offset;
1383              $params['Limit'] = $limit;
1384              $subtree =& $node->subTree( $params );
1385              $offset += count( $subtree );
1386              if ( count( $subtree ) == 0 )
1387              {
1388                  break;
1389              }
1390              $objectIDList = array();
1391              foreach ( $subtree as $subtreeNode )
1392              {
1393                  $objectIDList[] = $subtreeNode['contentobject_id'];
1394              }
1395              $objectIDList = array_unique( $objectIDList );
1396              unset( $subtree );
1397  
1398              foreach ( $objectIDList as $objectID )
1399                  eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
1400          }
1401      }
1402  
1403      if ( $module->hasActionParameter( 'CurrentURL' ) )
1404      {
1405          $currentURL = $module->actionParameter( 'CurrentURL' );
1406          return $module->redirectTo( $currentURL );
1407      }
1408  
1409      return $module->redirectToView( 'view', array( $viewMode, $nodeID, $languageCode ) );
1410  }
1411  else if ( $module->isCurrentAction( 'UploadFile' ) )
1412  {
1413      if ( !$module->hasActionParameter( 'UploadActionName' ) )
1414      {
1415          eZDebug::writeError( "Missing UploadActionName parameter for action " . $module->currentAction(),
1416                               'content/action' );
1417          include_once ( 'kernel/classes/ezredirectmanager.php' );
1418          eZRedirectManager::redirectTo( $module, 'content/view/full/2', true );
1419          return;
1420      }
1421  
1422      $user =& eZUser::currentUser();
1423      $result = $user->hasAccessTo( 'content', 'create' );
1424      if ( $result['accessWord'] != 'yes' )
1425      {
1426          return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
1427      }
1428  
1429      $uploadActionName = $module->actionParameter( 'UploadActionName' );
1430      $parameters = array( 'action_name' => $uploadActionName );
1431  
1432      // Check for locations for the new object
1433      if ( $module->hasActionParameter( 'UploadParentNodes' ) )
1434      {
1435          $parentNodes = $module->actionParameter( 'UploadParentNodes' );
1436          if ( !is_array( $parentNodes ) )
1437              $parentNodes = array( $parentNodes );
1438  
1439          foreach ( $parentNodes as $parentNodeID )
1440          {
1441              $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID );
1442              if ( !is_object( $parentNode ) )
1443              {
1444                  eZDebug::writeError( "Cannot upload file as child of parent node $parentNodeID, the parent does not exist",
1445                                       'content/action:' . $module->currentAction() );
1446                  return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
1447              }
1448              if ( !$parentNode->canCreate() )
1449              {
1450                  eZDebug::writeError( "Cannot upload file as child of parent node $parentNodeID, no permissions" . $module->currentAction(),
1451                                       'content/action:' . $module->currentAction() );
1452                  return $module->handleError( EZ_ERROR_KERNEL_ACCESS_DENIED, 'kernel' );
1453              }
1454          }
1455          $parameters['parent_nodes'] = $parentNodes;
1456      }
1457  
1458      // Check for redirection to current page
1459      if ( $module->hasActionParameter( 'UploadRedirectBack' ) )
1460      {
1461          if ( $module->actionParameter( 'UploadRedirectBack' ) == 1 )
1462          {
1463              include_once ( 'kernel/classes/ezredirectmanager.php' );
1464              $parameters['result_uri'] = eZRedirectManager::redirectURI( $module, 'content/view/full/2', true );
1465          }
1466          else if ( $module->actionParameter( 'UploadRedirectBack' ) == 2 )
1467          {
1468              include_once ( 'kernel/classes/ezredirectmanager.php' );
1469              $parameters['result_uri'] = eZRedirectManager::redirectURI( $module, 'content/view/full/2', false );
1470          }
1471      }
1472  
1473      // Check for redirection to specific page
1474      if ( $module->hasActionParameter( 'UploadRedirectURI' ) )
1475      {
1476          $parameters['result_uri'] = $module->actionParameter( 'UploadRedirectURI' );
1477      }
1478  
1479      include_once ( 'kernel/classes/ezcontentupload.php' );
1480      eZContentUpload::upload( $parameters, $module );
1481      return;
1482  }
1483  /*else if ( $http->hasPostVariable( 'RemoveObject' ) )
1484  {
1485      $removeObjectID = $http->postVariable( 'RemoveObject' );
1486      if ( is_numeric( $removeObjectID ) )
1487      {
1488          $contentObject = eZContentObject::fetch( $removeObjectID );
1489          if ( $contentObject->attribute( 'can_remove' ) )
1490          {
1491              $contentObject->remove();
1492          }
1493      }
1494      $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $topLevelNode . '/' );
1495      return;
1496  }*/
1497  else if ( !isset( $result ) )
1498  {
1499      return $module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' );
1500  }
1501  
1502  
1503  // return module contents
1504  $Result = array();
1505  $Result['content'] =& $result;
1506  
1507  ?>


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