TYPO3 CMS  TYPO3_7-6
ExtdirectTreeCommands.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
26 {
33  public function visiblyNode($nodeData)
34  {
36  $node = GeneralUtility::makeInstance(PagetreeNode::class, (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 = [
44  'success' => false,
45  'message' => $exception->getMessage()
46  ];
47  }
48  return $returnValue;
49  }
50 
57  public function disableNode($nodeData)
58  {
60  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
61  try {
62  Commands::disableNode($node);
63  $newNode = Commands::getNode($node->getId());
64  $newNode->setLeaf($node->isLeafNode());
65  $returnValue = $newNode->toArray();
66  } catch (\Exception $exception) {
67  $returnValue = [
68  'success' => false,
69  'message' => $exception->getMessage()
70  ];
71  }
72  return $returnValue;
73  }
74 
81  public function deleteNode($nodeData)
82  {
84  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
85  try {
86  Commands::deleteNode($node);
87  $returnValue = [];
88  if (static::getBackendUser()->workspace) {
89  $record = Commands::getNodeRecord($node->getId());
90  if ($record['_ORIG_uid']) {
91  $newNode = Commands::getNewNode($record);
92  $returnValue = $newNode->toArray();
93  }
94  }
95  } catch (\Exception $exception) {
96  $returnValue = [
97  'success' => false,
98  'message' => $exception->getMessage()
99  ];
100  }
101  return $returnValue;
102  }
103 
111  public function restoreNode($nodeData, $destination)
112  {
114  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
115  try {
116  Commands::restoreNode($node, $destination);
117  $newNode = Commands::getNode($node->getId());
118  $returnValue = $newNode->toArray();
119  } catch (\Exception $exception) {
120  $returnValue = [
121  'success' => false,
122  'message' => $exception->getMessage()
123  ];
124  }
125  return $returnValue;
126  }
127 
136  public function updateLabel($nodeData, $updatedLabel)
137  {
138  if ($updatedLabel === '') {
139  return [];
140  }
142  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
143  try {
144  Commands::updateNodeLabel($node, $updatedLabel);
145  $shortendedText = GeneralUtility::fixed_lgd_cs($updatedLabel, (int)static::getBackendUser()->uc['titleLen']);
146  $returnValue = [
147  'editableText' => $updatedLabel,
148  'updatedText' => htmlspecialchars($shortendedText)
149  ];
150  } catch (\Exception $exception) {
151  $returnValue = [
152  'success' => false,
153  'message' => $exception->getMessage()
154  ];
155  }
156  return $returnValue;
157  }
158 
165  public static function setTemporaryMountPoint($nodeData)
166  {
168  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
169  static::getBackendUser()->uc['pageTree_temporaryMountPoint'] = $node->getId();
170  static::getBackendUser()->writeUC(static::getBackendUser()->uc);
172  }
173 
181  public function moveNodeToFirstChildOfDestination($nodeData, $destination)
182  {
184  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
185  try {
186  Commands::moveNode($node, $destination);
187  $newNode = Commands::getNode($node->getId(), false);
188  $newNode->setLeaf($node->isLeafNode());
189  $returnValue = $newNode->toArray();
190  } catch (\Exception $exception) {
191  $returnValue = [
192  'success' => false,
193  'message' => $exception->getMessage()
194  ];
195  }
196  return $returnValue;
197  }
198 
206  public function moveNodeAfterDestination($nodeData, $destination)
207  {
209  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
210  try {
211  Commands::moveNode($node, -$destination);
212  $newNode = Commands::getNode($node->getId(), false);
213  $newNode->setLeaf($node->isLeafNode());
214  $returnValue = $newNode->toArray();
215  } catch (\Exception $exception) {
216  $returnValue = [
217  'success' => false,
218  'message' => $exception->getMessage()
219  ];
220  }
221  return $returnValue;
222  }
223 
232  public function copyNodeToFirstChildOfDestination($nodeData, $destination)
233  {
235  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
236  try {
237  $newPageId = Commands::copyNode($node, $destination);
238  $newNode = Commands::getNode($newPageId);
239  $newNode->setLeaf($node->isLeafNode());
240  $returnValue = $newNode->toArray();
241  } catch (\Exception $exception) {
242  $returnValue = [
243  'success' => false,
244  'message' => $exception->getMessage()
245  ];
246  }
247  return $returnValue;
248  }
249 
258  public function copyNodeAfterDestination($nodeData, $destination)
259  {
261  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
262  try {
263  $newPageId = Commands::copyNode($node, -$destination);
264  $newNode = Commands::getNode($newPageId);
265  $newNode->setLeaf($node->isLeafNode());
266  $returnValue = $newNode->toArray();
267  } catch (\Exception $exception) {
268  $returnValue = [
269  'success' => false,
270  'message' => $exception->getMessage()
271  ];
272  }
273  return $returnValue;
274  }
275 
283  public function insertNodeToFirstChildOfDestination($parentNodeData, $pageType)
284  {
286  $parentNode = GeneralUtility::makeInstance(PagetreeNode::class, (array)$parentNodeData);
287  try {
288  $newPageId = Commands::createNode($parentNode, $parentNode->getId(), $pageType);
289  $returnValue = Commands::getNode($newPageId)->toArray();
290  } catch (\Exception $exception) {
291  $returnValue = [
292  'success' => false,
293  'message' => $exception->getMessage()
294  ];
295  }
296  return $returnValue;
297  }
298 
307  public function insertNodeAfterDestination($parentNodeData, $destination, $pageType)
308  {
310  $parentNode = GeneralUtility::makeInstance(PagetreeNode::class, (array)$parentNodeData);
311  try {
312  $newPageId = Commands::createNode($parentNode, -$destination, $pageType);
313  $returnValue = Commands::getNode($newPageId)->toArray();
314  } catch (\Exception $exception) {
315  $returnValue = [
316  'success' => false,
317  'message' => $exception->getMessage()
318  ];
319  }
320  return $returnValue;
321  }
322 
329  public static function getViewLink($nodeData)
330  {
332  $node = GeneralUtility::makeInstance(PagetreeNode::class, (array)$nodeData);
333  $javascriptLink = BackendUtility::viewOnClick($node->getId());
334  $extractedLink = '';
335  if (preg_match('/window\\.open\\(\'([^\']+)\'/i', $javascriptLink, $match)) {
336  // Clean JSON-serialized ampersands ('&')
337  // @see GeneralUtility::quoteJSvalue()
338  $extractedLink = json_decode('"' . trim($match[1], '"') . '"', JSON_HEX_AMP);
339  }
340  return $extractedLink;
341  }
342 
353  public static function addRootlineOfNodeToStateHash($stateId, $nodeId)
354  {
355  $mountPoints = array_map('intval', static::getBackendUser()->returnWebmounts());
356  if (empty($mountPoints)) {
357  $mountPoints = [0];
358  }
359  if (!empty(static::getBackendUser()->uc['pageTree_temporaryMountPoint'])) {
360  $mountPoints[] = (int)static::getBackendUser()->uc['pageTree_temporaryMountPoint'];
361  }
362  $mountPoints = array_unique($mountPoints);
364  $userSettingsController = GeneralUtility::makeInstance(UserSettingsController::class);
365  $state = $userSettingsController->process('get', 'BackendComponents.States.' . $stateId);
366  if (empty($state)) {
367  $state = new \stdClass();
368  $state->stateHash = new \stdClass();
369  }
370  $state->stateHash = (object)$state->stateHash;
371  $rootline = BackendUtility::BEgetRootLine($nodeId, '', (int)static::getBackendUser()->workspace !== 0);
372  $rootlineIds = [];
373  foreach ($rootline as $pageData) {
374  $rootlineIds[] = (int)$pageData['uid'];
375  }
376  foreach ($mountPoints as $mountPoint) {
377  if (!in_array($mountPoint, $rootlineIds, true)) {
378  continue;
379  }
380  $isFirstNode = true;
381  foreach ($rootline as $pageData) {
382  $node = Commands::getNewNode($pageData, $mountPoint);
383  if ($isFirstNode) {
384  $isFirstNode = false;
385  $state->stateHash->lastSelectedNode = $node->calculateNodeId();
386  } else {
387  $state->stateHash->{$node->calculateNodeId('')} = 1;
388  }
389  }
390  }
391  $userSettingsController->process('set', 'BackendComponents.States.' . $stateId, $state);
392  return (array)$state->stateHash;
393  }
394 
408  public static function getNodePaths($pageId)
409  {
410  $pagePaths = [];
411  $mountPoints = array_map('intval', static::getBackendUser()->returnWebmounts());
412  if (empty($mountPoints)) {
413  $mountPoints = [0];
414  }
415  $mountPoints[] = (int)static::getBackendUser()->uc['pageTree_temporaryMountPoint'];
416  $mountPoints = array_unique($mountPoints);
417  $rootLine = BackendUtility::BEgetRootLine($pageId, '', (int)static::getBackendUser()->workspace !== 0);
418  $rootLineIds = [];
419  foreach ($rootLine as $rootLineLevel) {
420  $rootLineIds[] = (int)$rootLineLevel['uid'];
421  }
422  foreach ($mountPoints as $mountPoint) {
423  $pagePath = [];
424  if (!in_array($mountPoint, $rootLineIds, true)) {
425  continue;
426  }
427  foreach ($rootLine as $rootLineLevel) {
428  $node = Commands::getNewNode($rootLineLevel, $mountPoint);
429  array_unshift($pagePath, $node->calculateNodeId());
430  // Break if mount-point has been reached
431  if ($mountPoint === (int)$rootLineLevel['uid']) {
432  break;
433  }
434  }
435  // Attach valid partial root-lines
436  if (!empty($pagePath)) {
437  if ($mountPoint !== 0) {
438  array_unshift($pagePath, Commands::getNewNode(['uid' => 0])->calculateNodeId());
439  }
440  $pagePaths[] = $pagePath;
441  }
442  }
443  return $pagePaths;
444  }
445 
449  protected static function getBackendUser()
450  {
451  return $GLOBALS['BE_USER'];
452  }
453 }
static getNodeRecord($nodeId, $unsetMovePointers=true)
Definition: Commands.php:278
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:113
static deleteNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
Definition: Commands.php:84
static BEgetRootLine($uid, $clause='', $workspaceOL=false)
static visiblyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
Definition: Commands.php:60
static copyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId)
Definition: Commands.php:132
static createNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $parentNode, $targetId, $pageType)
Definition: Commands.php:162
static moveNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId)
Definition: Commands.php:148
static viewOnClick($pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
static fixed_lgd_cs($string, $chars, $appendString='...')
static restoreNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $targetId)
Definition: Commands.php:97
static getNode($nodeId, $unsetMovePointers=true)
Definition: Commands.php:234
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']