PageRenderTime 70ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/kernel/content/action.php

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