TYPO3 CMS  TYPO3_7-6
Commands.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 
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([], $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([], $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([], $data);
118  } else {
119  throw new \RuntimeException(implode(LF, ['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] = [];
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([], $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 = [])
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 = [];
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  $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->setStopPageTree($record['php_tree_stop']);
321  $subNode->setMountPoint($mountPoint);
322  $subNode->setWorkspaceId($record['_ORIG_uid'] ?: $record['uid']);
323  $subNode->setBackgroundColor(self::$backgroundColors[$record['uid']]);
324  $field = 'title';
325  $text = $record['title'];
326  if (self::$useNavTitle && trim($record['nav_title']) !== '') {
327  $field = 'nav_title';
328  $text = $record['nav_title'];
329  }
330  if (trim($text) === '') {
331  $visibleText = '[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', true) . ']';
332  } else {
333  $visibleText = $text;
334  }
335  $visibleText = GeneralUtility::fixed_lgd_cs($visibleText, self::$titleLength);
336  $suffix = '';
337  if (self::$addDomainName) {
338  $domain = self::getDomainName($record['uid']);
339  $suffix = $domain !== '' ? ' [' . $domain . ']' : '';
340  }
341  $qtip = str_replace(' - ', '<br />', htmlspecialchars(BackendUtility::titleAttribForPages($record, '', false)));
342  $prefix = '';
343  $lockInfo = BackendUtility::isRecordLocked('pages', $record['uid']);
344  if (is_array($lockInfo)) {
345  $qtip .= '<br />' . htmlspecialchars($lockInfo['msg']);
346  $prefix .= '<span class="typo3-pagetree-status">' . $iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</span>';
347  }
348  // Call stats information hook
349  $stat = '';
350  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
351  $_params = ['pages', $record['uid']];
352  $fakeThis = null;
353  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
354  $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $fakeThis);
355  }
356  }
357  $prefix .= htmlspecialchars(self::$addIdAsPrefix ? '[' . $record['uid'] . '] ' : '');
358  $subNode->setEditableText($text);
359  $subNode->setText(htmlspecialchars($visibleText), $field, $prefix, htmlspecialchars($suffix) . $stat);
360  $subNode->setQTip($qtip);
361  if ((int)$record['uid'] !== 0) {
362  $spriteIconCode = $iconFactory->getIconForRecord('pages', $record, Icon::SIZE_SMALL)->render();
363  } else {
364  $spriteIconCode = $iconFactory->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render();
365  }
366  $subNode->setSpriteIconCode($spriteIconCode);
367  if (
368  !$subNode->canCreateNewPages()
369  || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
370  ) {
371  $subNode->setIsDropTarget(false);
372  }
373  if (
374  !$subNode->canBeEdited()
375  || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
376  ) {
377  $subNode->setDraggable(false);
378  }
379  return $subNode;
380  }
381 }
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 visiblyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
Definition: Commands.php:60
static restoreNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $targetId)
Definition: Commands.php:97
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']