TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
backend/Classes/Tree/Pagetree/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 
24 
28 class Commands
29 {
33  protected static $useNavTitle = null;
34 
38  protected static $addIdAsPrefix = null;
39 
43  protected static $addDomainName = null;
44 
48  protected static $backgroundColors = null;
49 
53  protected static $titleLength = null;
54 
61  public static function visiblyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
62  {
63  $data['pages'][$node->getWorkspaceId()]['hidden'] = 0;
64  self::processTceCmdAndDataMap([], $data);
65  }
66 
73  public static function disableNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
74  {
75  $data['pages'][$node->getWorkspaceId()]['hidden'] = 1;
76  self::processTceCmdAndDataMap([], $data);
77  }
78 
85  public static function deleteNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
86  {
87  $cmd['pages'][$node->getId()]['delete'] = 1;
88  self::processTceCmdAndDataMap($cmd);
89  }
90 
98  public static function restoreNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $targetId)
99  {
100  $cmd['pages'][$node->getId()]['undelete'] = 1;
101  self::processTceCmdAndDataMap($cmd);
102  if ($node->getId() !== $targetId) {
103  self::moveNode($node, $targetId);
104  }
105  }
106 
114  public static function updateNodeLabel(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $updatedLabel)
115  {
116  if ($GLOBALS['BE_USER']->checkLanguageAccess(0)) {
117  $data['pages'][$node->getWorkspaceId()][$node->getTextSourceField()] = $updatedLabel;
118  self::processTceCmdAndDataMap([], $data);
119  } else {
120  throw new \RuntimeException(implode(LF, ['Editing title of page id \'' . $node->getWorkspaceId() . '\' failed. Editing default language is not allowed.']), 1365513336);
121  }
122  }
123 
133  public static function copyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId)
134  {
135  $cmd['pages'][$sourceNode->getId()]['copy'] = $targetId;
136  $returnValue = self::processTceCmdAndDataMap($cmd);
137  return $returnValue['pages'][$sourceNode->getId()];
138  }
139 
149  public static function moveNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId)
150  {
151  $cmd['pages'][$sourceNode->getId()]['move'] = $targetId;
152  self::processTceCmdAndDataMap($cmd);
153  }
154 
163  public static function createNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $parentNode, $targetId, $pageType)
164  {
165  $placeholder = 'NEW12345';
166  $pid = (int)$parentNode->getWorkspaceId();
167  $targetId = (int)$targetId;
168 
169  // Use page TsConfig as default page initialization
170  $pageTs = BackendUtility::getPagesTSconfig($pid);
171  if (array_key_exists('TCAdefaults.', $pageTs) && array_key_exists('pages.', $pageTs['TCAdefaults.'])) {
172  $data['pages'][$placeholder] = $pageTs['TCAdefaults.']['pages.'];
173  } else {
174  $data['pages'][$placeholder] = [];
175  }
176 
177  $data['pages'][$placeholder]['pid'] = $pid;
178  $data['pages'][$placeholder]['doktype'] = $pageType;
179  $data['pages'][$placeholder]['title'] = htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:tree.defaultPageTitle'));
180  $newPageId = self::processTceCmdAndDataMap([], $data);
181  $node = self::getNode($newPageId[$placeholder]);
182  if ($pid !== $targetId) {
183  self::moveNode($node, $targetId);
184  }
185 
186  return $newPageId[$placeholder];
187  }
188 
205  protected static function processTceCmdAndDataMap(array $cmd, array $data = [])
206  {
208  $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
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 = [];
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 = [];
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  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
293  ->getQueryBuilderForTable('sys_domain');
294  $domain = $queryBuilder
295  ->select('domainName')
296  ->from('sys_domain')
297  ->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)))
298  ->setMaxResults(1)
299  ->orderBy('sorting')
300  ->execute()
301  ->fetch();
302  return is_array($domain) ? htmlspecialchars($domain['domainName']) : '';
303  }
304 
312  public static function getNewNode($record, $mountPoint = 0)
313  {
314  $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
315  if (self::$titleLength === null) {
316  self::$useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
317  self::$addIdAsPrefix = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
318  self::$addDomainName = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showDomainNameWithTitle');
319  self::$backgroundColors = $GLOBALS['BE_USER']->getTSConfigProp('options.pageTree.backgroundColor');
320  self::$titleLength = (int)$GLOBALS['BE_USER']->uc['titleLen'];
321  }
323  $subNode = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode::class);
324  $subNode->setRecord($record);
325  $subNode->setCls($record['_CSSCLASS']);
326  $subNode->setType('pages');
327  $subNode->setId($record['uid']);
328  $subNode->setStopPageTree($record['php_tree_stop']);
329  $subNode->setMountPoint($mountPoint);
330  $subNode->setWorkspaceId($record['_ORIG_uid'] ?: $record['uid']);
331  $subNode->setBackgroundColor(self::$backgroundColors[$record['uid']]);
332  $field = 'title';
333  $text = $record['title'];
334  if (self::$useNavTitle && trim($record['nav_title']) !== '') {
335  $field = 'nav_title';
336  $text = $record['nav_title'];
337  }
338  if (trim($text) === '') {
339  $visibleText = '[' . htmlspecialchars($GLOBALS['LANG']->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.no_title')) . ']';
340  } else {
341  $visibleText = $text;
342  }
343  $visibleText = GeneralUtility::fixed_lgd_cs($visibleText, self::$titleLength);
344  $suffix = '';
345  if (self::$addDomainName) {
346  $domain = self::getDomainName($record['uid']);
347  $suffix = $domain !== '' ? ' [' . $domain . ']' : '';
348  }
349  $qtip = str_replace(' - ', '<br />', htmlspecialchars(BackendUtility::titleAttribForPages($record, '', false)));
350  $prefix = '';
351  $lockInfo = BackendUtility::isRecordLocked('pages', $record['uid']);
352  if (is_array($lockInfo)) {
353  $qtip .= '<br />' . htmlspecialchars($lockInfo['msg']);
354  $prefix .= '<span class="typo3-pagetree-status">' . $iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</span>';
355  }
356  // Call stats information hook
357  $stat = '';
358  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
359  $_params = ['pages', $record['uid']];
360  $fakeThis = null;
361  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
362  $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $fakeThis);
363  }
364  }
365  $prefix .= htmlspecialchars(self::$addIdAsPrefix ? '[' . $record['uid'] . '] ' : '');
366  $subNode->setEditableText($text);
367  $subNode->setText(htmlspecialchars($visibleText), $field, $prefix, htmlspecialchars($suffix) . $stat);
368  $subNode->setQTip($qtip);
369  if ((int)$record['uid'] !== 0) {
370  $spriteIconCode = $iconFactory->getIconForRecord('pages', $record, Icon::SIZE_SMALL)->render();
371  } else {
372  $spriteIconCode = $iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render();
373  }
374  $subNode->setSpriteIconCode($spriteIconCode);
375  if (
376  !$subNode->canCreateNewPages()
377  || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
378  ) {
379  $subNode->setIsDropTarget(false);
380  }
381  if (
382  !$subNode->canBeEdited()
383  || !$subNode->canBeRemoved()
384  || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
385  ) {
386  $subNode->setDraggable(false);
387  }
388  return $subNode;
389  }
390 }
static updateNodeLabel(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $updatedLabel)
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static visiblyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
static deleteNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
static restoreNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $targetId)
static disableNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)