TYPO3 CMS  TYPO3_6-2
ExtdirectTreeCommands.php
Go to the documentation of this file.
1 <?php
3 
20 
27 
34  public function visiblyNode($nodeData) {
36  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
37  try {
38  Commands::visiblyNode($node);
39  $newNode = Commands::getNode($node->getId());
40  $newNode->setLeaf($node->isLeafNode());
41  $returnValue = $newNode->toArray();
42  } catch (\Exception $exception) {
43  $returnValue = array(
44  'success' => FALSE,
45  'error' => $exception->getMessage()
46  );
47  }
48  return $returnValue;
49  }
50 
57  public function disableNode($nodeData) {
59  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
60  try {
61  Commands::disableNode($node);
62  $newNode = Commands::getNode($node->getId());
63  $newNode->setLeaf($node->isLeafNode());
64  $returnValue = $newNode->toArray();
65  } catch (\Exception $exception) {
66  $returnValue = array(
67  'success' => FALSE,
68  'message' => $exception->getMessage()
69  );
70  }
71  return $returnValue;
72  }
73 
80  public function deleteNode($nodeData) {
82  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
83  try {
84  Commands::deleteNode($node);
85  $returnValue = array();
86  if ($GLOBALS['BE_USER']->workspace) {
87  $record = Commands::getNodeRecord($node->getId());
88  if ($record['_ORIG_uid']) {
89  $newNode = Commands::getNewNode($record);
90  $returnValue = $newNode->toArray();
91  }
92  }
93  } catch (\Exception $exception) {
94  $returnValue = array(
95  'success' => FALSE,
96  'message' => $exception->getMessage()
97  );
98  }
99  return $returnValue;
100  }
101 
109  public function restoreNode($nodeData, $destination) {
111  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
112  try {
113  Commands::restoreNode($node, $destination);
114  $newNode = Commands::getNode($node->getId());
115  $returnValue = $newNode->toArray();
116  } catch (\Exception $exception) {
117  $returnValue = array(
118  'success' => FALSE,
119  'message' => $exception->getMessage()
120  );
121  }
122  return $returnValue;
123  }
124 
133  public function updateLabel($nodeData, $updatedLabel) {
134  if ($updatedLabel === '') {
135  return array();
136  }
138  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
139  try {
140  Commands::updateNodeLabel($node, $updatedLabel);
141  $shortendedText = GeneralUtility::fixed_lgd_cs($updatedLabel, (int)$GLOBALS['BE_USER']->uc['titleLen']);
142  $returnValue = array(
143  'editableText' => $updatedLabel,
144  'updatedText' => htmlspecialchars($shortendedText)
145  );
146  } catch (\Exception $exception) {
147  $returnValue = array(
148  'success' => FALSE,
149  'message' => $exception->getMessage()
150  );
151  }
152  return $returnValue;
153  }
154 
161  static public function setTemporaryMountPoint($nodeData) {
163  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
164  $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'] = $node->getId();
165  $GLOBALS['BE_USER']->writeUC($GLOBALS['BE_USER']->uc);
167  }
168 
176  public function moveNodeToFirstChildOfDestination($nodeData, $destination) {
178  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
179  try {
180  Commands::moveNode($node, $destination);
181  $newNode = Commands::getNode($node->getId(), FALSE);
182  $newNode->setLeaf($node->isLeafNode());
183  $returnValue = $newNode->toArray();
184  } catch (\Exception $exception) {
185  $returnValue = array(
186  'success' => FALSE,
187  'message' => $exception->getMessage()
188  );
189  }
190  return $returnValue;
191  }
192 
200  public function moveNodeAfterDestination($nodeData, $destination) {
202  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
203  try {
204  Commands::moveNode($node, -$destination);
205  $newNode = Commands::getNode($node->getId(), FALSE);
206  $newNode->setLeaf($node->isLeafNode());
207  $returnValue = $newNode->toArray();
208  } catch (\Exception $exception) {
209  $returnValue = array(
210  'success' => FALSE,
211  'message' => $exception->getMessage()
212  );
213  }
214  return $returnValue;
215  }
216 
225  public function copyNodeToFirstChildOfDestination($nodeData, $destination) {
227  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
229  $dataProvider = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\DataProvider');
230  try {
231  $newPageId = Commands::copyNode($node, $destination);
232  $newNode = Commands::getNode($newPageId);
233  $newNode->setLeaf($node->isLeafNode());
234  $returnValue = $newNode->toArray();
235  } catch (\Exception $exception) {
236  $returnValue = array(
237  'success' => FALSE,
238  'message' => $exception->getMessage()
239  );
240  }
241  return $returnValue;
242  }
243 
252  public function copyNodeAfterDestination($nodeData, $destination) {
254  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
256  $dataProvider = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\DataProvider');
257  try {
258  $newPageId = Commands::copyNode($node, -$destination);
259  $newNode = Commands::getNode($newPageId);
260  $newNode->setLeaf($node->isLeafNode());
261  $returnValue = $newNode->toArray();
262  } catch (\Exception $exception) {
263  $returnValue = array(
264  'success' => FALSE,
265  'message' => $exception->getMessage()
266  );
267  }
268  return $returnValue;
269  }
270 
278  public function insertNodeToFirstChildOfDestination($parentNodeData, $pageType) {
280  $parentNode = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $parentNodeData);
281  try {
282  $newPageId = Commands::createNode($parentNode, $parentNode->getId(), $pageType);
283  $returnValue = Commands::getNode($newPageId)->toArray();
284  } catch (\Exception $exception) {
285  $returnValue = array(
286  'success' => FALSE,
287  'message' => $exception->getMessage()
288  );
289  }
290  return $returnValue;
291  }
292 
301  public function insertNodeAfterDestination($parentNodeData, $destination, $pageType) {
303  $parentNode = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $parentNodeData);
304  try {
305  $newPageId = Commands::createNode($parentNode, -$destination, $pageType);
306  $returnValue = Commands::getNode($newPageId)->toArray();
307  } catch (\Exception $exception) {
308  $returnValue = array(
309  'success' => FALSE,
310  'message' => $exception->getMessage()
311  );
312  }
313  return $returnValue;
314  }
315 
322  static public function getViewLink($nodeData) {
324  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode', (array) $nodeData);
325  $javascriptLink = BackendUtility::viewOnClick($node->getId());
326  preg_match('/window\\.open\\(\'([^\']+)\'/i', $javascriptLink, $match);
327  return $match[1];
328  }
329 
340  static public function addRootlineOfNodeToStateHash($stateId, $nodeId) {
341  $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts());
342  if (count($mountPoints) == 0) {
343  $mountPoints = array(0);
344  }
345  if (!empty($GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'])){
346  $mountPoints[] = (int)$GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'];
347  }
348  $mountPoints = array_unique($mountPoints);
350  $userSettings = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\User\\ExtDirect\\BackendUserSettingsDataProvider');
351  $state = $userSettings->get('BackendComponents.States.' . $stateId);
352  $state->stateHash = (object) $state->stateHash;
353  $rootline = BackendUtility::BEgetRootLine($nodeId, '', $GLOBALS['BE_USER']->workspace != 0);
354  $rootlineIds = array();
355  foreach ($rootline as $pageData) {
356  $rootlineIds[] = (int)$pageData['uid'];
357  }
358  foreach ($mountPoints as $mountPoint) {
359  if (!in_array($mountPoint, $rootlineIds, TRUE)) {
360  continue;
361  }
362  $isFirstNode = TRUE;
363  foreach ($rootline as $pageData) {
364  $node = Commands::getNewNode($pageData, $mountPoint);
365  if ($isFirstNode) {
366  $isFirstNode = FALSE;
367  $state->stateHash->lastSelectedNode = $node->calculateNodeId();
368  } else {
369  $state->stateHash->{$node->calculateNodeId('')} = 1;
370  }
371  }
372  }
373  $userSettings->set('BackendComponents.States.' . $stateId, $state);
374  return (array) $state->stateHash;
375  }
376 
377 }
static BEgetRootLine($uid, $clause='', $workspaceOL=FALSE)
static disableNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
Definition: Commands.php:72
static updateNodeLabel(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $updatedLabel)
Definition: Commands.php:110
static deleteNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
Definition: Commands.php:83
static getNode($nodeId, $unsetMovePointers=TRUE)
Definition: Commands.php:226
static visiblyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
Definition: Commands.php:61
static copyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId)
Definition: Commands.php:128
static createNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $parentNode, $targetId, $pageType)
Definition: Commands.php:156
static viewOnClick($pageUid, $backPath='', $rootLine='', $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=TRUE)
static moveNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId)
Definition: Commands.php:143
static getNodeRecord($nodeId, $unsetMovePointers=TRUE)
Definition: Commands.php:268
static fixed_lgd_cs($string, $chars, $appendString='...')
static restoreNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $targetId)
Definition: Commands.php:95
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]