TYPO3  7.6
Commands.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\Pagetree;
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 
23 
27 class Commands
28 {
32  protected static $useNavTitle = null;
33 
37  protected static $addIdAsPrefix = null;
38 
42  protected static $addDomainName = null;
43 
47  protected static $backgroundColors = null;
48 
52  protected static $titleLength = null;
53 
60  public static function visiblyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
61  {
62  $data['pages'][$node->getWorkspaceId()]['hidden'] = 0;
63  self::processTceCmdAndDataMap(array(), $data);
64  }
65 
72  public static function disableNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
73  {
74  $data['pages'][$node->getWorkspaceId()]['hidden'] = 1;
75  self::processTceCmdAndDataMap(array(), $data);
76  }
77 
84  public static function deleteNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
85  {
86  $cmd['pages'][$node->getId()]['delete'] = 1;
87  self::processTceCmdAndDataMap($cmd);
88  }
89 
97  public static function restoreNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $targetId)
98  {
99  $cmd['pages'][$node->getId()]['undelete'] = 1;
100  self::processTceCmdAndDataMap($cmd);
101  if ($node->getId() !== $targetId) {
102  self::moveNode($node, $targetId);
103  }
104  }
105 
113  public static function updateNodeLabel(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $updatedLabel)
114  {
115  if ($GLOBALS['BE_USER']->checkLanguageAccess(0)) {
116  $data['pages'][$node->getWorkspaceId()][$node->getTextSourceField()] = $updatedLabel;
117  self::processTceCmdAndDataMap(array(), $data);
118  } else {
119  throw new \RuntimeException(implode(LF, array('Editing title of page id \'' . $node->getWorkspaceId() . '\' failed. Editing default language is not allowed.')), 1365513336);
120  }
121  }
122 
132  public static function copyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId)
133  {
134  $cmd['pages'][$sourceNode->getId()]['copy'] = $targetId;
135  $returnValue = self::processTceCmdAndDataMap($cmd);
136  return $returnValue['pages'][$sourceNode->getId()];
137  }
138 
148  public static function moveNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId)
149  {
150  $cmd['pages'][$sourceNode->getId()]['move'] = $targetId;
151  self::processTceCmdAndDataMap($cmd);
152  }
153 
162  public static function createNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $parentNode, $targetId, $pageType)
163  {
164  $placeholder = 'NEW12345';
165  $pid = (int)$parentNode->getWorkspaceId();
166  $targetId = (int)$targetId;
167 
168  // Use page TsConfig as default page initialization
169  $pageTs = BackendUtility::getPagesTSconfig($pid);
170  if (array_key_exists('TCAdefaults.', $pageTs) && array_key_exists('pages.', $pageTs['TCAdefaults.'])) {
171  $data['pages'][$placeholder] = $pageTs['TCAdefaults.']['pages.'];
172  } else {
173  $data['pages'][$placeholder] = array();
174  }
175 
176  $data['pages'][$placeholder]['pid'] = $pid;
177  $data['pages'][$placeholder]['doktype'] = $pageType;
178  $data['pages'][$placeholder]['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tree.defaultPageTitle', true);
179  $newPageId = self::processTceCmdAndDataMap(array(), $data);
180  $node = self::getNode($newPageId[$placeholder]);
181  if ($pid !== $targetId) {
182  self::moveNode($node, $targetId);
183  }
184 
185  return $newPageId[$placeholder];
186  }
187 
204  protected static function processTceCmdAndDataMap(array $cmd, array $data = array())
205  {
207  $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
208  $tce->stripslashes_values = 0;
209  $tce->start($data, $cmd);
210  $tce->copyTree = MathUtility::forceIntegerInRange($GLOBALS['BE_USER']->uc['copyLevels'], 0, 100);
211  if (!empty($cmd)) {
212  $tce->process_cmdmap();
213  $returnValues = $tce->copyMappingArray_merged;
214  } elseif (!empty($data)) {
215  $tce->process_datamap();
216  $returnValues = $tce->substNEWwithIDs;
217  } else {
218  $returnValues = array();
219  }
220  // check errors
221  if (!empty($tce->errorLog)) {
222  throw new \RuntimeException(implode(LF, $tce->errorLog), 1333754629);
223  }
224  return $returnValues;
225  }
226 
234  public static function getNode($nodeId, $unsetMovePointers = true)
235  {
236  $record = self::getNodeRecord($nodeId, $unsetMovePointers);
237  return self::getNewNode($record);
238  }
239 
246  public static function getMountPointPath($uid = -1)
247  {
248  if ($uid === -1) {
249  $uid = (int)$GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'];
250  }
251  if ($uid <= 0) {
252  return '';
253  }
254  if (self::$useNavTitle === null) {
255  self::$useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
256  }
257  $rootline = array_reverse(BackendUtility::BEgetRootLine($uid));
258  array_shift($rootline);
259  $path = array();
260  foreach ($rootline as $rootlineElement) {
261  $record = self::getNodeRecord($rootlineElement['uid']);
262  $text = $record['title'];
263  if (self::$useNavTitle && trim($record['nav_title']) !== '') {
264  $text = $record['nav_title'];
265  }
266  $path[] = htmlspecialchars($text);
267  }
268  return '/' . implode('/', $path);
269  }
270 
278  public static function getNodeRecord($nodeId, $unsetMovePointers = true)
279  {
280  $record = BackendUtility::getRecordWSOL('pages', $nodeId, '*', '', true, $unsetMovePointers);
281  return $record;
282  }
283 
290  public static function getDomainName($uid)
291  {
292  $whereClause = 'pid=' . (int)$uid . BackendUtility::deleteClause('sys_domain') . BackendUtility::BEenableFields('sys_domain');
293  $domain = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('domainName', 'sys_domain', $whereClause, '', 'sorting');
294  return is_array($domain) ? htmlspecialchars($domain['domainName']) : '';
295  }
296 
304  public static function getNewNode($record, $mountPoint = 0)
305  {
306  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
307  if (self::$titleLength === null) {
308  self::$useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
309  self::$addIdAsPrefix = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
310  self::$addDomainName = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showDomainNameWithTitle');
311  self::$backgroundColors = $GLOBALS['BE_USER']->getTSConfigProp('options.pageTree.backgroundColor');
312  self::$titleLength = (int)$GLOBALS['BE_USER']->uc['titleLen'];
313  }
315  $subNode = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class);
316  $subNode->setRecord($record);
317  $subNode->setCls($record['_CSSCLASS']);
318  $subNode->setType('pages');
319  $subNode->setId($record['uid']);
320  $subNode->setMountPoint($mountPoint);
321  $subNode->setWorkspaceId($record['_ORIG_uid'] ?: $record['uid']);
322  $subNode->setBackgroundColor(self::$backgroundColors[$record['uid']]);
323  $field = 'title';
324  $text = $record['title'];
325  if (self::$useNavTitle && trim($record['nav_title']) !== '') {
326  $field = 'nav_title';
327  $text = $record['nav_title'];
328  }
329  if (trim($text) === '') {
330  $visibleText = '[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', true) . ']';
331  } else {
332  $visibleText = $text;
333  }
334  $visibleText = GeneralUtility::fixed_lgd_cs($visibleText, self::$titleLength);
335  $suffix = '';
336  if (self::$addDomainName) {
337  $domain = self::getDomainName($record['uid']);
338  $suffix = $domain !== '' ? ' [' . $domain . ']' : '';
339  }
340  $qtip = str_replace(' - ', '<br />', htmlspecialchars(BackendUtility::titleAttribForPages($record, '', false)));
341  $prefix = '';
342  $lockInfo = BackendUtility::isRecordLocked('pages', $record['uid']);
343  if (is_array($lockInfo)) {
344  $qtip .= '<br />' . htmlspecialchars($lockInfo['msg']);
345  $prefix .= '<span class="typo3-pagetree-status">' . $iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</span>';
346  }
347  // Call stats information hook
348  $stat = '';
349  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
350  $_params = array('pages', $record['uid']);
351  $fakeThis = null;
352  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
353  $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $fakeThis);
354  }
355  }
356  $prefix .= htmlspecialchars(self::$addIdAsPrefix ? '[' . $record['uid'] . '] ' : '');
357  $subNode->setEditableText($text);
358  $subNode->setText(htmlspecialchars($visibleText), $field, $prefix, htmlspecialchars($suffix) . $stat);
359  $subNode->setQTip($qtip);
360  if ((int)$record['uid'] !== 0) {
361  $spriteIconCode = $iconFactory->getIconForRecord('pages', $record, Icon::SIZE_SMALL)->render();
362  } else {
363  $spriteIconCode = $iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render();
364  }
365  $subNode->setSpriteIconCode($spriteIconCode);
366  if (
367  !$subNode->canCreateNewPages()
368  || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
369  ) {
370  $subNode->setIsDropTarget(false);
371  }
372  if (
373  !$subNode->canBeEdited()
374  || !$subNode->canBeRemoved()
375  || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
376  ) {
377  $subNode->setDraggable(false);
378  }
379  return $subNode;
380  }
381 }