/kernel/content/action.php
PHP | 1525 lines | 1317 code | 149 blank | 59 comment | 285 complexity | 88b8e043f88c7ee41843674106ec8392 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * @copyright Copyright (C) eZ Systems AS. All rights reserved.
- * @license For full copyright and license information view LICENSE file distributed with this source code.
- * @version //autogentag//
- * @package kernel
- */
- $http = eZHTTPTool::instance();
- $module = $Params['Module'];
- if ( $module->hasActionParameter( 'LanguageCode' ) )
- $languageCode = $module->actionParameter( 'LanguageCode' );
- else
- {
- $languageCode = false;
- }
- $viewMode = 'full';
- if ( $module->hasActionParameter( 'ViewMode' ) )
- $viewMode = $module->actionParameter( 'ViewMode' );
- if ( $http->hasPostVariable( 'BrowseCancelButton' ) || $http->hasPostVariable( 'CancelButton' ) )
- {
- if ( $http->hasPostVariable( 'BrowseCancelURI' ) )
- {
- return $module->redirectTo( $http->postVariable( 'BrowseCancelURI' ) );
- }
- else if ( $http->hasPostVariable( 'CancelURI' ) )
- {
- return $module->redirectTo( $http->postVariable( 'CancelURI' ) );
- }
- }
- // Merge post variables and variables that were used before login
- if ( $http->hasSessionVariable( 'LastPostVars' ) )
- {
- $post = $http->attribute( 'post' );
- $currentPostVarNames = array_keys( $post );
- foreach ( $http->sessionVariable( 'LastPostVars' ) as $var => $value )
- {
- if ( !in_array( $var, $currentPostVarNames ) )
- {
- $http->setPostVariable( $var, $value );
- }
- }
- $http->removeSessionVariable( 'LastPostVars' );
- }
- if ( $http->hasPostVariable( 'NewButton' ) || $module->isCurrentAction( 'NewObjectAddNodeAssignment' ) )
- {
- $hasClassInformation = false;
- $contentClassID = false;
- $contentClassIdentifier = false;
- $languageCode = false;
- $class = false;
- if ( $http->hasPostVariable( 'ClassID' ) )
- {
- $contentClassID = $http->postVariable( 'ClassID' );
- if ( $contentClassID )
- $hasClassInformation = true;
- }
- else if ( $http->hasPostVariable( 'ClassIdentifier' ) )
- {
- $contentClassIdentifier = $http->postVariable( 'ClassIdentifier' );
- $class = eZContentClass::fetchByIdentifier( $contentClassIdentifier );
- if ( is_object( $class ) )
- {
- $contentClassID = $class->attribute( 'id' );
- if ( $contentClassID )
- $hasClassInformation = true;
- }
- }
- if ( $http->hasPostVariable( 'ContentLanguageCode' ) )
- {
- $languageCode = $http->postVariable( 'ContentLanguageCode' );
- $languageID = eZContentLanguage::idByLocale( $languageCode );
- if ( $languageID === false )
- {
- eZDebug::writeError( "The language code [$languageCode] specified in ContentLanguageCode does not exist in the system." );
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
- }
- }
- else
- {
- $allLanguages = eZContentLanguage::prioritizedLanguages();
- // Only show language selection if there are more than 1 languages.
- if ( count( $allLanguages ) > 1 &&
- $hasClassInformation )
- {
- $tpl = eZTemplate::factory();
- $tpl->setVariable( 'node_id', $http->postVariable( 'NodeID' ) );
- $tpl->setVariable( 'class_id', $contentClassID );
- $tpl->setVariable( 'assignment_remote_id', $http->postVariable( 'AssignmentRemoteID', false ) );
- $tpl->setVariable( 'redirect_uri_after_publish', $http->postVariable( 'RedirectURIAfterPublish', false ) );
- $tpl->setVariable( 'redirect_uri_after_discard', $http->postVariable( 'RedirectIfDiscarded', false ) );
- $Result = array();
- $Result['content'] = $tpl->fetch( 'design:content/create_languages.tpl' );
- return $Result;
- }
- }
- if ( ( $hasClassInformation && $http->hasPostVariable( 'NodeID' ) ) || $module->isCurrentAction( 'NewObjectAddNodeAssignment' ) )
- {
- if ( $module->isCurrentAction( 'NewObjectAddNodeAssignment' ) )
- {
- $selectedNodeIDArray = eZContentBrowse::result( 'NewObjectAddNodeAssignment' );
- if ( count( $selectedNodeIDArray ) == 0 )
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- $node = eZContentObjectTreeNode::fetch( $selectedNodeIDArray[0] );
- }
- else
- {
- $node = eZContentObjectTreeNode::fetch( $http->postVariable( 'NodeID' ) );
- }
- if ( is_object( $node ) )
- {
- $contentObject = eZContentObject::createWithNodeAssignment( $node,
- $contentClassID,
- $languageCode,
- $http->postVariable( 'AssignmentRemoteID', false ) );
- if ( $contentObject )
- {
- if ( $http->hasPostVariable( 'RedirectURIAfterPublish' ) )
- {
- $http->setSessionVariable( 'RedirectURIAfterPublish', $http->postVariable( 'RedirectURIAfterPublish' ) );
- }
- if ( $http->hasPostVariable( 'RedirectIfDiscarded' ) )
- {
- $http->setSessionVariable( 'RedirectIfDiscarded', $http->postVariable( 'RedirectIfDiscarded' ) );
- }
- $module->redirectTo( $module->functionURI( 'edit' ) . '/' . $contentObject->attribute( 'id' ) . '/' . $contentObject->attribute( 'current_version' ) );
- return;
- }
- else
- {
- // If ACCESS DENIED save current post variables for using after login
- $http->setSessionVariable( '$_POST_BeforeLogin', $http->attribute( 'post' ) );
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
- }
- }
- else
- {
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
- }
- }
- else if ( $hasClassInformation )
- {
- if ( !is_object( $class ) )
- $class = eZContentClass::fetch( $contentClassID );
- eZContentBrowse::browse( array( 'action_name' => 'NewObjectAddNodeAssignment',
- 'description_template' => 'design:content/browse_first_placement.tpl',
- 'keys' => array( 'class' => $class->attribute( 'id' ),
- 'classgroup' => $class->attribute( 'ingroup_id_list' ) ),
- 'persistent_data' => array( 'ClassID' => $class->attribute( 'id' ), 'ContentLanguageCode' => $languageCode ),
- 'content' => array( 'class_id' => $class->attribute( 'id' ) ),
- 'cancel_page' => $module->redirectionURIForModule( $module, 'view', array( 'full', 2 ) ),
- 'from_page' => "/content/action" ),
- $module );
- }
- }
- else if ( $http->hasPostVariable( 'SetSorting' ) &&
- $http->hasPostVariable( 'ContentObjectID' ) && $http->hasPostVariable( 'ContentNodeID' ) &&
- $http->hasPostVariable( 'SortingField' ) && $http->hasPostVariable( 'SortingOrder' ) )
- {
- $nodeID = $http->postVariable( 'ContentNodeID' );
- $contentObjectID = $http->postVariable( 'ContentObjectID' );
- $sortingField = $http->postVariable( 'SortingField' );
- $sortingOrder = $http->postVariable( 'SortingOrder' );
- $node = eZContentObjectTreeNode::fetch( $nodeID );
- $contentObject = eZContentObject::fetch( $contentObjectID );
- if ( eZOperationHandler::operationIsAvailable( 'content_sort' ) )
- {
- $operationResult = eZOperationHandler::execute( 'content', 'sort',
- array( 'node_id' => $nodeID,
- 'sorting_field' => $sortingField,
- 'sorting_order' => $sortingOrder ), null, true );
- }
- else
- {
- eZContentOperationCollection::changeSortOrder( $nodeID, $sortingField, $sortingOrder );
- }
- if ( $http->hasPostVariable( 'RedirectURIAfterSorting' ) )
- {
- return $module->redirectTo( $http->postVariable( 'RedirectURIAfterSorting' ) );
- }
- return $module->redirectToView( 'view', array( 'full', $nodeID, $languageCode ) );
- }
- else if ( $module->isCurrentAction( 'MoveNode' ) )
- {
- /* This action is used through the admin interface with the "Move" button,
- * or in the pop-up menu and will move a node to a different location. */
- if ( !$module->hasActionParameter( 'NodeID' ) )
- {
- eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- if ( $module->hasActionParameter( 'NewParentNode' ) )
- {
- $selectedNodeID = $module->actionParameter( 'NewParentNode' );
- }
- else
- {
- $selectedNodeIDArray = eZContentBrowse::result( 'MoveNode' );
- $selectedNodeID = $selectedNodeIDArray[0];
- }
- $selectedNode = eZContentObjectTreeNode::fetch( $selectedNodeID );
- if ( !$selectedNode )
- {
- eZDebug::writeWarning( "Content node with ID $selectedNodeID does not exist, cannot use that as parent node for node $nodeID",
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- $nodeIDlist = $module->actionParameter( 'NodeID' );
- if ( strpos( $nodeIDlist, ',' ) !== false )
- {
- $nodeIDlist = explode( ',', $nodeIDlist );
- }
- else
- {
- $nodeIDlist = array( $nodeIDlist );
- }
- // Check that all user has access to move all selected nodes
- $nodeToMoveList = array();
- foreach( $nodeIDlist as $key => $nodeID )
- {
- $node = eZContentObjectTreeNode::fetch( $nodeID );
- if ( !$node )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- if ( !$node->canMoveFrom() )
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array() );
- $object = $node->object();
- if ( !$object )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- $nodeToMoveList[] = array( 'node_id' => $nodeID,
- 'object_id' => $object->attribute( 'id' ) );
- $class = $object->contentClass();
- $classID = $class->attribute( 'id' );
- // check if the object can be moved to (under) the selected node
- if ( !$selectedNode->canMoveTo( $classID ) )
- {
- eZDebug::writeError( "Cannot move node $nodeID as child of parent node $selectedNodeID, the current user does not have create permission for class ID $classID",
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- // Check if we try to move the node as child of itself or one of its children
- if ( in_array( $node->attribute( 'node_id' ), $selectedNode->pathArray() ) )
- {
- eZDebug::writeError( "Cannot move node $nodeID as child of itself or one of its own children (node $selectedNodeID).",
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', $node->attribute( 'node_id' ) ) );
- }
- }
- // move selected nodes, this should probably be inside a transaction
- foreach( $nodeToMoveList as $nodeToMove )
- {
- if ( eZOperationHandler::operationIsAvailable( 'content_move' ) )
- {
- $operationResult = eZOperationHandler::execute( 'content',
- 'move', array( 'node_id' => $nodeToMove['node_id'],
- 'object_id' => $nodeToMove['object_id'],
- 'new_parent_node_id' => $selectedNodeID ),
- null,
- true );
- }
- else
- {
- eZContentOperationCollection::moveNode( $nodeToMove['node_id'], $nodeToMove['object_id'], $selectedNodeID );
- }
- }
- return $module->redirectToView( 'view', array( $viewMode, $selectedNodeID, $languageCode ) );
- }
- else if ( $module->isCurrentAction( 'MoveNodeRequest' ) )
- {
- /* This action is started through the pop-up menu when a "Move" is
- * requested and through the use of the "Move" button. It will start the
- * browser to select where the node should be moved to. */
- if ( !$module->hasActionParameter( 'NodeID' ) )
- {
- eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- $nodeID = $module->actionParameter( 'NodeID' );
- $node = eZContentObjectTreeNode::fetch( $nodeID );
- if ( !$node )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- if ( !$node->canMoveFrom() )
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array() );
- $object = $node->object();
- if ( !$object )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- $objectID = $object->attribute( 'id' );
- $class = $object->contentClass();
- $ignoreNodesSelect = array();
- $ignoreNodesSelectSubtree = array();
- $ignoreNodesClick = array();
- $publishedAssigned = $object->assignedNodes( false );
- foreach ( $publishedAssigned as $element )
- {
- $ignoreNodesSelect[] = $element['node_id'];
- $ignoreNodesSelectSubtree[] = $element['node_id'];
- $ignoreNodesClick[] = $element['node_id'];
- $ignoreNodesSelect[] = $element['parent_node_id'];
- }
- $ignoreNodesSelect = array_unique( $ignoreNodesSelect );
- $ignoreNodesSelectSubtree = array_unique( $ignoreNodesSelectSubtree );
- $ignoreNodesClick = array_unique( $ignoreNodesClick );
- eZContentBrowse::browse( array( 'action_name' => 'MoveNode',
- 'description_template' => 'design:content/browse_move_node.tpl',
- 'keys' => array( 'class' => $class->attribute( 'id' ),
- 'class_id' => $class->attribute( 'identifier' ),
- 'classgroup' => $class->attribute( 'ingroup_id_list' ),
- 'section' => $object->attribute( 'section_id' ) ),
- 'ignore_nodes_select' => $ignoreNodesSelect,
- 'ignore_nodes_select_subtree' => $ignoreNodesSelectSubtree,
- 'ignore_nodes_click' => $ignoreNodesClick,
- 'persistent_data' => array( 'ContentNodeID' => $nodeID,
- 'ViewMode' => $viewMode,
- 'ContentObjectLanguageCode' => $languageCode,
- 'MoveNodeAction' => '1' ),
- 'permission' => array( 'access' => 'create',
- 'contentclass_id' => $class->attribute( 'id' ) ),
- 'content' => array( 'object_id' => $objectID,
- 'object_version' => $object->attribute( 'current_version' ),
- 'object_language' => $languageCode ),
- 'start_node' => $node->attribute( 'parent_node_id' ),
- 'cancel_page' => $module->redirectionURIForModule( $module, 'view', array( $viewMode, $nodeID, $languageCode ) ),
- 'from_page' => "/content/action" ),
- $module );
- return;
- }
- else if ( $module->isCurrentAction( 'SwapNode' ) )
- {
- if ( !$module->hasActionParameter( 'NodeID' ) )
- {
- eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- $nodeID = $module->actionParameter( 'NodeID' );
- $node = eZContentObjectTreeNode::fetch( $nodeID );
- if ( !$node )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- if ( !$node->canSwap() )
- {
- eZDebug::writeError( "Cannot swap node $nodeID (no edit permission)" );
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array() );
- }
- $nodeParentNodeID = $node->attribute( 'parent_node_id' );
- $object = $node->object();
- if ( !$object )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- $objectID = $object->attribute( 'id' );
- if ( $module->hasActionParameter( 'NewNode' ) )
- {
- $selectedNodeID = $module->actionParameter( 'NewNode' );
- }
- else
- {
- $selectedNodeIDArray = eZContentBrowse::result( 'SwapNode' );
- $selectedNodeID = $selectedNodeIDArray[0];
- }
- $selectedNode = eZContentObjectTreeNode::fetch( $selectedNodeID );
- if ( !$selectedNode )
- {
- eZDebug::writeWarning( "Content node with ID $selectedNodeID does not exist, cannot use that as exchanging node for node $nodeID",
- 'content/action' );
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- }
- if ( !$selectedNode->canSwap() )
- {
- eZDebug::writeError( "Cannot use node $selectedNodeID as the exchanging node for $nodeID, the current user does not have edit permission for it",
- 'content/action' );
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array() );
- }
- // verify one of the nodes contains children and the other is not a container.
- if ( !$node->classIsContainer() && $selectedNode->childrenCount() > 0 )
- {
- eZDebug::writeError( "Cannot use node $selectedNodeID as the exchanging node for $nodeID, as it contains sub items (node is not container)",
- 'content/action' );
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- }
- if ( !$selectedNode->classIsContainer() && $node->childrenCount() > 0 )
- {
- eZDebug::writeError( "Cannot use node $selectedNodeID as the exchanging node for $nodeID, as it is not container (node contains sub items)",
- 'content/action' );
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- }
- // clear cache.
- eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
- $selectedObject = $selectedNode->object();
- $selectedNodeParentNodeID = $selectedNode->attribute( 'parent_node_id' );
- /* In order to swap node1 and node2 a user should have the following permissions:
- * 1. move_from: move node1
- * 2. move_from: move node2
- * 3. move_to: move an object of the same class as node2 under parent of node1
- * 4. move_to: move an object of the same class as node1 under parent of node2
- *
- * The First two has already been checked. Let's check the rest.
- */
- $nodeParent = $node->attribute( 'parent' );
- $selectedNodeParent = $selectedNode->attribute( 'parent' );
- $objectClassID = $object->attribute( 'contentclass_id' );
- $selectedObjectClassID = $selectedObject->attribute( 'contentclass_id' );
- if ( !$nodeParent || !$selectedNodeParent )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- if ( !$nodeParent->canMoveTo( $selectedObjectClassID ) )
- {
- eZDebug::writeError( "Cannot move an object of class $selectedObjectClassID to node $nodeParentNodeID (no create permission)" );
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array() );
- }
- if ( !$selectedNodeParent->canMoveTo( $objectClassID ) )
- {
- eZDebug::writeError( "Cannot move an object of class $objectClassID to node $selectedNodeParentNodeID (no create permission)" );
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array() );
- }
- // exchange contentobject ids and versions.
- if ( eZOperationHandler::operationIsAvailable( 'content_swap' ) )
- {
- $operationResult = eZOperationHandler::execute( 'content',
- 'swap',
- array( 'node_id' => $nodeID,
- 'selected_node_id' => $selectedNodeID,
- 'node_id_list' => array( $nodeID, $selectedNodeID ) ),
- null,
- true );
- }
- else
- {
- eZContentOperationCollection::swapNode( $nodeID, $selectedNodeID, array( $nodeID, $selectedNodeID ) );
- }
- return $module->redirectToView( 'view', array( $viewMode, $nodeID, $languageCode ) );
- }
- else if ( $module->isCurrentAction( 'SwapNodeRequest' ) )
- {
- /* This action brings a browse screen up to select with which the selected
- * node should be swapped. It will not actually move the nodes. */
- if ( !$module->hasActionParameter( 'NodeID' ) )
- {
- eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- $nodeID = $module->actionParameter( 'NodeID' );
- $node = eZContentObjectTreeNode::fetch( $nodeID );
- if ( !$node )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- if ( !$node->canSwap() )
- {
- eZDebug::writeError( "Cannot swap node $nodeID (no edit permission)" );
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array() );
- }
- $object = $node->object();
- if ( !$object )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- $objectID = $object->attribute( 'id' );
- $class = $object->contentClass();
- $ignoreNodesSelect = array( $nodeID );
- $ignoreNodesClick = array();
- eZContentBrowse::browse( array( 'action_name' => 'SwapNode',
- 'description_template' => 'design:content/browse_swap_node.tpl',
- 'keys' => array( 'class' => $class->attribute( 'id' ),
- 'class_id' => $class->attribute( 'identifier' ),
- 'classgroup' => $class->attribute( 'ingroup_id_list' ),
- 'section' => $object->attribute( 'section_id' ) ),
- 'ignore_nodes_select' => $ignoreNodesSelect,
- 'ignore_nodes_click' => $ignoreNodesClick,
- 'persistent_data' => array( 'ContentNodeID' => $nodeID,
- 'ViewMode' => $viewMode,
- 'ContentObjectLanguageCode' => $languageCode,
- 'SwapNodeAction' => '1' ),
- 'permission' => array( 'access' => 'edit',
- 'contentclass_id' => $class->attribute( 'id' ) ),
- 'content' => array( 'object_id' => $objectID,
- 'object_version' => $object->attribute( 'current_version' ),
- 'object_language' => $languageCode ),
- 'start_node' => $node->attribute( 'parent_node_id' ),
- 'cancel_page' => $module->redirectionURIForModule( $module, 'view', array( $viewMode, $nodeID, $languageCode ) ),
- 'from_page' => "/content/action" ),
- $module );
- return;
- }
- else if ( $module->isCurrentAction( 'UpdateMainAssignment' ) )
- {
- /* This action selects a different main assignment node for the object. */
- if ( !$module->hasActionParameter( 'ObjectID' ) )
- {
- eZDebug::writeError( "Missing ObjectID parameter for action " . $module->currentAction(),
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- if ( !$module->hasActionParameter( 'NodeID' ) )
- {
- eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- $objectID = $module->actionParameter( 'ObjectID' );
- $nodeID = $module->actionParameter( 'NodeID' );
- if ( $module->hasActionParameter( 'MainAssignmentID' ) )
- {
- $mainAssignmentID = $module->actionParameter( 'MainAssignmentID' );
- $object = eZContentObject::fetch( $objectID );
- if ( !$object )
- {
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
- }
- $existingMainNodeID = false;
- $existingMainNode = $object->attribute( 'main_node' );
- if ( $existingMainNode )
- $existingMainNodeID = $existingMainNode->attribute( 'node_id' );
- if ( $existingMainNodeID === false or
- $existingMainNodeID != $mainAssignmentID )
- {
- if ( $existingMainNode and
- !$existingMainNode->checkAccess( 'edit' ) )
- {
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array() );
- }
- $newMainNode = eZContentObjectTreeNode::fetch( $mainAssignmentID );
- if ( !$newMainNode )
- {
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
- }
- if ( !$newMainNode->checkAccess( 'edit' ) )
- {
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
- }
- $mainAssignmentParentID = $newMainNode->attribute( 'parent_node_id' );
- if ( eZOperationHandler::operationIsAvailable( 'content_updatemainassignment' ) )
- {
- $operationResult = eZOperationHandler::execute( 'content',
- 'updatemainassignment', array( 'main_assignment_id' => $mainAssignmentID,
- 'object_id' => $objectID,
- 'main_assignment_parent_id' => $mainAssignmentParentID ),null, true );
- }
- else
- {
- eZContentOperationCollection::UpdateMainAssignment( $mainAssignmentID, $objectID, $newMainNode->attribute( 'parent_node_id' ) );
- }
- }
- }
- else
- {
- eZDebug::writeError( "No MainAssignmentID found for action " . $module->currentAction(),
- 'content/action' );
- }
- return $module->redirectToView( 'view', array( $viewMode, $nodeID, $languageCode ) );
- }
- else if ( $module->isCurrentAction( 'AddAssignment' ) or
- $module->isCurrentAction( 'SelectAssignmentLocation' ) )
- {
- if ( !$module->hasActionParameter( 'ObjectID' ) )
- {
- eZDebug::writeError( "Missing ObjectID parameter for action " . $module->currentAction(),
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- if ( !$module->hasActionParameter( 'NodeID' ) )
- {
- eZDebug::writeError( "Missing NodeID parameter for action " . $module->currentAction(),
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- $objectID = $module->actionParameter( 'ObjectID' );
- $nodeID = $module->actionParameter( 'NodeID' );
- $object = eZContentObject::fetch( $objectID );
- if ( !$object )
- {
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
- }
- $user = eZUser::currentUser();
- if ( !$object->checkAccess( 'edit' ) &&
- !$user->attribute( 'has_manage_locations' ) )
- {
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
- }
- $existingNode = eZContentObjectTreeNode::fetch( $nodeID );
- if ( !$existingNode )
- {
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
- }
- $class = $object->contentClass();
- if ( $module->isCurrentAction( 'AddAssignment' ) )
- {
- $selectedNodeIDArray = eZContentBrowse::result( 'AddNodeAssignment' );
- if ( !is_array( $selectedNodeIDArray ) )
- $selectedNodeIDArray = array();
- if ( eZOperationHandler::operationIsAvailable( 'content_addlocation' ) )
- {
- $operationResult = eZOperationHandler::execute( 'content',
- 'addlocation', array( 'node_id' => $nodeID,
- 'object_id' => $objectID,
- 'select_node_id_array' => $selectedNodeIDArray ),
- null,
- true );
- }
- else
- {
- eZContentOperationCollection::addAssignment( $nodeID, $objectID, $selectedNodeIDArray );
- }
- }
- else if ( $module->isCurrentAction( 'SelectAssignmentLocation' ) )
- {
- $ignoreNodesSelect = array();
- $ignoreNodesClick = array();
- $assigned = eZNodeAssignment::fetchForObject( $objectID, $object->attribute( 'current_version' ), 0, false );
- $publishedAssigned = $object->assignedNodes( false );
- $isTopLevel = false;
- foreach ( $publishedAssigned as $element )
- {
- $append = false;
- if ( $element['parent_node_id'] == 1 )
- $isTopLevel = true;
- foreach ( $assigned as $ass )
- {
- if ( $ass['parent_node'] == $element['parent_node_id'] )
- {
- $append = true;
- break;
- }
- }
- if ( $append )
- {
- $ignoreNodesSelect[] = $element['node_id'];
- $ignoreNodesClick[] = $element['node_id'];
- $ignoreNodesSelect[] = $element['parent_node_id'];
- }
- }
- if ( !$isTopLevel )
- {
- $ignoreNodesSelect = array_unique( $ignoreNodesSelect );
- $objectID = $object->attribute( 'id' );
- eZContentBrowse::browse( array( 'action_name' => 'AddNodeAssignment',
- 'description_template' => 'design:content/browse_placement.tpl',
- 'keys' => array( 'class' => $class->attribute( 'id' ),
- 'class_id' => $class->attribute( 'identifier' ),
- 'classgroup' => $class->attribute( 'ingroup_id_list' ),
- 'section' => $object->attribute( 'section_id' ) ),
- 'ignore_nodes_select' => $ignoreNodesSelect,
- 'ignore_nodes_click' => $ignoreNodesClick,
- 'persistent_data' => array( 'ContentNodeID' => $nodeID,
- 'ContentObjectID' => $objectID,
- 'ViewMode' => $viewMode,
- 'ContentObjectLanguageCode' => $languageCode,
- 'AddAssignmentAction' => '1' ),
- 'content' => array( 'object_id' => $objectID,
- 'object_version' => $object->attribute( 'current_version' ),
- 'object_language' => $languageCode ),
- 'cancel_page' => $module->redirectionURIForModule( $module, 'view', array( $viewMode, $nodeID, $languageCode ) ),
- 'from_page' => "/content/action" ),
- $module );
- return;
- }
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
- }
- return $module->redirectToView( 'view', array( $viewMode, $nodeID, $languageCode ) );
- }
- else if ( $module->isCurrentAction( 'RemoveAssignment' ) )
- {
- if ( !$module->hasActionParameter( 'ObjectID' ) )
- {
- eZDebug::writeError( "Missing ObjectID parameter for action RemoveAssignment",
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- if ( !$module->hasActionParameter( 'NodeID' ) )
- {
- eZDebug::writeError( "Missing NodeID parameter for action RemoveAssignment",
- 'content/action' );
- return $module->redirectToView( 'view', array( 'full', 2 ) );
- }
- $objectID = $module->actionParameter( 'ObjectID' );
- $nodeID = $module->actionParameter( 'NodeID' );
- $redirectNodeID = $nodeID;
- $object = eZContentObject::fetch( $objectID );
- if ( !$object )
- {
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
- }
- $user = eZUser::currentUser();
- if ( !$object->checkAccess( 'edit' ) &&
- !$user->hasManageLocations() )
- {
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
- }
- if ( $module->hasActionParameter( 'AssignmentIDSelection' ) )
- {
- eZDebug::writeError( "Use of POST variable 'AssignmentIDSelection' is deprecated, use the node ID and put it in 'LocationIDSelection' instead" );
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' );
- }
- if ( !$module->hasActionParameter( 'LocationIDSelection' ) )
- return $module->redirectToView( 'view', array( $viewMode, $redirectNodeID, $languageCode ) );
- $locationIDSelection = $module->actionParameter( 'LocationIDSelection' );
- $hasChildren = false;
- $nodes = array();
- foreach ( $locationIDSelection as $locationID )
- {
- $nodes[] = eZContentObjectTreeNode::fetch( $locationID );
- }
- $removeList = array();
- foreach ( $nodes as $node )
- {
- if ( $node )
- {
- // Security checks, removal of current node is not allowed
- // and we require removal rights
- if ( !$node->canRemove() &&
- !$node->canRemoveLocation() )
- continue;
- if ( $node->attribute( 'node_id' ) == $nodeID )
- {
- $redirectNodeID = $node->attribute( 'parent_node_id' );
- }
- $removeList[$node->attribute( 'node_id' )] = 1;
- $count = $node->childrenCount( false );
- if ( $count > 0 )
- {
- $hasChildren = true;
- }
- }
- }
- if ( $hasChildren )
- {
- $http->setSessionVariable( 'CurrentViewMode', $viewMode );
- $http->setSessionVariable( 'DeleteIDArray', array_keys( $removeList ) );
- $http->setSessionVariable( 'ContentNodeID', $nodeID );
- $http->setSessionVariable( 'ContentLanguage', $languageCode );
- return $module->redirectToView( 'removeobject' );
- }
- else
- {
- if ( eZOperationHandler::operationIsAvailable( 'content_removelocation' ) )
- {
- $operationResult = eZOperationHandler::execute( 'content',
- 'removelocation', array( 'node_list' => array_keys( $removeList ) ),
- null,
- true );
- }
- else
- {
- eZContentOperationCollection::removeNodes( array_keys( $removeList ) );
- }
- }
- return $module->redirectToView( 'view', array( $viewMode, $redirectNodeID, $languageCode ) );
- }
- else if ( $http->hasPostVariable( 'EditButton' ) )
- {
- if ( $http->hasPostVariable( 'ContentObjectID' ) )
- {
- $parameters = array( $http->postVariable( 'ContentObjectID' ) );
- if ( $http->hasPostVariable( 'ContentObjectVersion' ) )
- {
- $parameters[] = $http->postVariable( 'ContentObjectVersion' );
- if ( $http->hasPostVariable( 'ContentObjectLanguageCode' ) )
- {
- $parameters[] = $http->postVariable( 'ContentObjectLanguageCode' );
- }
- }
- else
- {
- if ( $http->hasPostVariable( 'ContentObjectLanguageCode' ) )
- {
- $languageCode = $http->postVariable( 'ContentObjectLanguageCode' );
- if ( $languageCode == '' )
- {
- $parameters[] = 'a'; // this will be treatead as not entering the version number and offering
- // list with new languages
- }
- else
- {
- $parameters[] = 'f'; // this will be treatead as not entering the version number
- $parameters[]= $languageCode;
- }
- }
- }
- if ( $http->hasPostVariable( 'RedirectURIAfterPublish' ) )
- {
- $http->setSessionVariable( 'RedirectURIAfterPublish', $http->postVariable( 'RedirectURIAfterPublish' ) );
- }
- if ( $http->hasPostVariable( 'RedirectIfDiscarded' ) )
- {
- $http->setSessionVariable( 'RedirectIfDiscarded', $http->postVariable( 'RedirectIfDiscarded' ) );
- }
- $module->redirectToView( 'edit', $parameters );
- return;
- }
- }
- else if ( $http->hasPostVariable( 'PreviewPublishButton' ) )
- {
- if ( $http->hasPostVariable( 'ContentObjectID' ) )
- {
- $parameters = array( $http->postVariable( 'ContentObjectID' ) );
- if ( $http->hasPostVariable( 'ContentObjectVersion' ) )
- {
- $parameters[] = $http->postVariable( 'ContentObjectVersion' );
- if ( $http->hasPostVariable( 'ContentObjectLanguageCode' ) )
- {
- $parameters[] = $http->postVariable( 'ContentObjectLanguageCode' );
- }
- }
- $module->setCurrentAction( 'Publish', 'edit' );
- return $module->run( 'edit', $parameters );
- }
- }
- else if ( $http->hasPostVariable( 'RemoveButton' ) )
- {
- $viewMode = $http->postVariable( 'ViewMode', 'full' );
- $contentNodeID = $http->postVariable( 'ContentNodeID', 2 );
- $contentObjectID = $http->postVariable( 'ContentObjectID', 1 );
- $hideRemoveConfirm = false;
- if ( $http->hasPostVariable( 'HideRemoveConfirmation' ) )
- $hideRemoveConfirm = $http->postVariable( 'HideRemoveConfirmation' ) ? true : false;
- if ( $http->hasPostVariable( 'DeleteIDArray' ) or $http->hasPostVariable( 'SelectedIDArray' ) )
- {
- if ( $http->hasPostVariable( 'SelectedIDArray' ) )
- $deleteIDArray = $http->postVariable( 'SelectedIDArray' );
- else
- $deleteIDArray = $http->postVariable( 'DeleteIDArray' );
- if ( is_array( $deleteIDArray ) && count( $deleteIDArray ) > 0 )
- {
- $http->setSessionVariable( 'CurrentViewMode', $viewMode );
- $http->setSessionVariable( 'ContentNodeID', $contentNodeID );
- $http->setSessionVariable( 'HideRemoveConfirmation', $hideRemoveConfirm );
- $http->setSessionVariable( 'DeleteIDArray', $deleteIDArray );
- $object = eZContentObject::fetch( $contentObjectID );
- if ( $object instanceof eZContentObject )
- {
- $section = eZSection::fetch( $object->attribute( 'section_id' ) );
- }
- if ( isset($section) && $section )
- $navigationPartIdentifier = $section->attribute( 'navigation_part_identifier' );
- else
- $navigationPartIdentifier = null;
- if ( $navigationPartIdentifier and $navigationPartIdentifier == 'ezusernavigationpart' )
- {
- $module->redirectTo( $module->functionURI( 'removeuserobject' ) . '/' );
- }
- elseif ( $navigationPartIdentifier and $navigationPartIdentifier == 'ezmedianavigationpart' )
- {
- $module->redirectTo( $module->functionURI( 'removemediaobject' ) . '/' );
- }
- else
- {
- $module->redirectTo( $module->functionURI( 'removeobject' ) . '/' );
- }
- }
- else
- {
- $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $contentNodeID . '/' );
- }
- }
- else
- {
- $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $contentNodeID . '/' );
- }
- }
- else if ( $http->hasPostVariable( 'MoveButton' ) )
- {
- /* action for multi select move, uses same interface as RemoveButton */
- $viewMode = $http->postVariable( 'ViewMode', 'full' );
- $parentNodeID = $http->postVariable( 'ContentNodeID', 2 );
- $parentObjectID = $http->postVariable( 'ContentObjectID', 1 );
- if ( $http->hasPostVariable( 'DeleteIDArray' ) or $http->hasPostVariable( 'SelectedIDArray' ) )
- {
- if ( $http->hasPostVariable( 'SelectedIDArray' ) )
- $moveIDArray = $http->postVariable( 'SelectedIDArray' );
- else
- $moveIDArray = $http->postVariable( 'DeleteIDArray' );
- if ( is_array( $moveIDArray ) && count( $moveIDArray ) > 0 )
- {
- $ignoreNodesSelect = array();
- $ignoreNodesSelectSubtree = array();
- $ignoreNodesClick = array();
- $classIDArray = array();
- $classIdentifierArray = array();
- $classGroupArray = array();
- $sectionIDArray = array();
- $objectNameArray = array();
- foreach( $moveIDArray as $nodeID )
- {
- $node = eZContentObjectTreeNode::fetch( $nodeID );
- if ( !$node )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- if ( !$node->canMoveFrom() )
- return $module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel', array() );
- $object = $node->object();
- if ( !$object )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- $class = $object->contentClass();
- $classIDArray[] = $class->attribute( 'id' );
- $classIdentifierArray[] = $class->attribute( 'identifier' );
- $classGroupArray = array_merge( $classGroupArray, $class->attribute( 'ingroup_id_list' ) );
- $sectionIDArray[] = $object->attribute( 'section_id' );
- $objectNameArray[] = $object->attribute( 'name' );
- $publishedAssigned = $object->assignedNodes( false );
- foreach ( $publishedAssigned as $element )
- {
- $ignoreNodesSelect[] = $element['node_id'];
- $ignoreNodesSelectSubtree[] = $element['node_id'];
- $ignoreNodesClick[] = $element['node_id'];
- $ignoreNodesSelect[] = $element['parent_node_id'];
- }
- }
- $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID );
- if ( !$parentNode )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- $parentObject = $parentNode->object();
- if ( !$parentObject )
- return $module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel', array() );
- $parentObjectID = $parentObject->attribute( 'id' );
- $ignoreNodesSelect = array_unique( $ignoreNodesSelect );
- $ignoreNodesSelectSubtree = array_unique( $ignoreNodesSelectSubtree );
- $ignoreNodesClick = array_unique( $ignoreNodesClick );
- $classIDArray = array_unique( $classIDArray );
- $classIdentifierArray = array_unique( $classIdentifierArray );
- $classGroupArray = array_unique( $classGroupArray );
- $sectionIDArray = array_unique( $sectionIDArray );
- eZContentBrowse::browse( array( 'action_name' => 'MoveNode',
- 'description_template' => 'design:content/browse_move_node.tpl',
- 'keys' => array( 'class' => $classIDArray,
- 'class_id' => $classIdentifierArray,
- 'classgroup' => $classGroupArray,
- 'section' => $sectionIDArray ),
- 'ignore_nodes_select' => $ignoreNodesSelect,
- 'ignore_nodes_select_subtree' => $ignoreNodesSelectSubtree,
- 'ignore_nodes_click' => $ignoreNodesClick,
- 'persistent_data' => array( 'ContentNodeID' => implode( ',', $moveIDArray ),
- 'ViewMode' => $viewMode,
- 'ContentObjectLanguageCode' => $languageCode,
- 'MoveNodeAction' => '1' ),
- 'permission' => array( 'access' => 'create',
- 'contentclass_id' => $classIDArray ),
- 'content' => array( 'name_list' => $objectNameArray, 'node_id_list' => $moveIDArray ),
- 'start_node' => $parentNodeID,
- 'cancel_page' => $module->redirectionURIForModule( $module, 'view', array( $viewMode, $parentNodeID, $languageCode ) ),
- 'from_page' => "/content/action" ),
- $module );
- }
- else
- {
- eZDebug::writeError( "Empty SelectedIDArray parameter for action " . $module->currentAction(),
- 'content/action' );
- $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $parentNodeID . '/' );
- }
- }
- else
- {
- eZDebug::writeError( "Missing SelectedIDArray parameter for action " . $module->currentAction(),
- 'content/action' );
- $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $parentNodeID . '/' );
- }
- }
- else if ( $http->hasPostVariable( 'UpdatePriorityButton' ) )
- {
- $viewMode = $http->postVariable( 'ViewMode', 'full' );
- if ( $http->hasPostVariable( 'ContentNodeID' ) )
- {
- $contentNodeID = $http->postVariable( 'ContentNodeID' );
- }
- else
- {
- eZDebug::writeError( "Variable 'ContentNodeID' can not be found in template." );
- $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $contentNodeID . '/' );
- return;
- }
- if ( $http->hasPostVariable( 'Priority' ) and $http->hasPostVariable( 'PriorityID' ) )
- {
- $contentNode = eZContentObjectTreeNode::fetch( $contentNodeID );
- if ( !$contentNode->attribute( 'can_edit' ) )
- {
- eZDebug::writeError( 'Current user can not update the priorities because he has no permissions to edit the node' );
- $module->redirectTo( $module->functionURI( 'view' ) . '/' . $viewMode . '/' . $contentNodeID . '/' );
- return;
- }
- $priorityArray = $http->postVariable( 'Priority' );
- $priorityIDArray = $http->postVariable( 'PriorityID' );
- if ( eZOperationHandler::operationIsAvailable( 'content_updatepriority' ) )
- {
- $operationResult = eZOperationHandler::execute( 'content', 'updatepriority',
- array( 'node_id' => $contentNodeID,
- …
Large files files are truncated, but you can click here to view the full file