TYPO3 CMS  TYPO3_6-2
Commands.php
Go to the documentation of this file.
1 <?php
3 
22 
28 class Commands {
29 
33  static protected $useNavTitle = NULL;
34 
38  static protected $addIdAsPrefix = NULL;
39 
43  static protected $addDomainName = NULL;
44 
48  static protected $backgroundColors = NULL;
49 
53  static protected $titleLength = NULL;
54 
61  static public function visiblyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node) {
62  $data['pages'][$node->getWorkspaceId()]['hidden'] = 0;
63  self::processTceCmdAndDataMap(array(), $data);
64  }
65 
72  static public function disableNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node) {
73  $data['pages'][$node->getWorkspaceId()]['hidden'] = 1;
74  self::processTceCmdAndDataMap(array(), $data);
75  }
76 
83  static public function deleteNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node) {
84  $cmd['pages'][$node->getId()]['delete'] = 1;
85  self::processTceCmdAndDataMap($cmd);
86  }
87 
95  static public function restoreNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $targetId) {
96  $cmd['pages'][$node->getId()]['undelete'] = 1;
97  self::processTceCmdAndDataMap($cmd);
98  if ($node->getId() !== $targetId) {
99  self::moveNode($node, $targetId);
100  }
101  }
102 
110  static public function updateNodeLabel(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node, $updatedLabel) {
111  if ($GLOBALS['BE_USER']->checkLanguageAccess(0)) {
112  $data['pages'][$node->getWorkspaceId()][$node->getTextSourceField()] = $updatedLabel;
113  self::processTceCmdAndDataMap(array(), $data);
114  } else {
115  throw new \RuntimeException(implode(chr(10), array('Editing title of page id \'' . $node->getWorkspaceId() . '\' failed. Editing default language is not allowed.')), 1365513336);
116  }
117  }
118 
128  static public function copyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId) {
129  $cmd['pages'][$sourceNode->getId()]['copy'] = $targetId;
130  $returnValue = self::processTceCmdAndDataMap($cmd);
131  return $returnValue['pages'][$sourceNode->getId()];
132  }
133 
143  static public function moveNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $sourceNode, $targetId) {
144  $cmd['pages'][$sourceNode->getId()]['move'] = $targetId;
145  self::processTceCmdAndDataMap($cmd);
146  }
147 
156  static public function createNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $parentNode, $targetId, $pageType) {
157  $placeholder = 'NEW12345';
158  $pid = (int)$parentNode->getWorkspaceId();
159  $targetId = (int)$targetId;
160 
161  // Use page TsConfig as default page initialization
162  $pageTs = BackendUtility::getPagesTSconfig($pid);
163  if (array_key_exists('TCAdefaults.', $pageTs) && array_key_exists('pages.', $pageTs['TCAdefaults.'])) {
164  $data['pages'][$placeholder] = $pageTs['TCAdefaults.']['pages.'];
165  } else {
166  $data['pages'][$placeholder] = array();
167  }
168 
169  $data['pages'][$placeholder]['pid'] = $pid;
170  $data['pages'][$placeholder]['doktype'] = $pageType;
171  $data['pages'][$placeholder]['title'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:tree.defaultPageTitle', TRUE);
172  $newPageId = self::processTceCmdAndDataMap(array(), $data);
173  $node = self::getNode($newPageId[$placeholder]);
174  if ($pid !== $targetId) {
175  self::moveNode($node, $targetId);
176  }
177 
178  return $newPageId[$placeholder];
179  }
180 
197  static protected function processTceCmdAndDataMap(array $cmd, array $data = array()) {
199  $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
200  $tce->stripslashes_values = 0;
201  $tce->start($data, $cmd);
202  $tce->copyTree = MathUtility::forceIntegerInRange($GLOBALS['BE_USER']->uc['copyLevels'], 0, 100);
203  if (count($cmd)) {
204  $tce->process_cmdmap();
205  $returnValues = $tce->copyMappingArray_merged;
206  } elseif (count($data)) {
207  $tce->process_datamap();
208  $returnValues = $tce->substNEWwithIDs;
209  } else {
210  $returnValues = array();
211  }
212  // check errors
213  if (count($tce->errorLog)) {
214  throw new \RuntimeException(implode(chr(10), $tce->errorLog), 1333754629);
215  }
216  return $returnValues;
217  }
218 
226  static public function getNode($nodeId, $unsetMovePointers = TRUE) {
227  $record = self::getNodeRecord($nodeId, $unsetMovePointers);
228  return self::getNewNode($record);
229  }
230 
237  static public function getMountPointPath($uid = -1) {
238  if ($uid === -1) {
239  $uid = (int)$GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'];
240  }
241  if ($uid <= 0) {
242  return '';
243  }
244  if (self::$useNavTitle === NULL) {
245  self::$useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
246  }
247  $rootline = array_reverse(BackendUtility::BEgetRootLine($uid));
248  array_shift($rootline);
249  $path = array();
250  foreach ($rootline as $rootlineElement) {
251  $record = self::getNodeRecord($rootlineElement['uid']);
252  $text = $record['title'];
253  if (self::$useNavTitle && trim($record['nav_title']) !== '') {
254  $text = $record['nav_title'];
255  }
256  $path[] = htmlspecialchars($text);
257  }
258  return '/' . implode('/', $path);
259  }
260 
268  static public function getNodeRecord($nodeId, $unsetMovePointers = TRUE) {
269  $record = BackendUtility::getRecordWSOL('pages', $nodeId, '*', '', TRUE, $unsetMovePointers);
270  return $record;
271  }
272 
279  static public function getDomainName($uid) {
280  $whereClause = 'pid=' . (int)$uid . BackendUtility::deleteClause('sys_domain') . BackendUtility::BEenableFields('sys_domain');
281  $domain = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('domainName', 'sys_domain', $whereClause, '', 'sorting');
282  return is_array($domain) ? htmlspecialchars($domain['domainName']) : '';
283  }
284 
292  static public function getNewNode($record, $mountPoint = 0) {
293  if (self::$titleLength === NULL) {
294  self::$useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
295  self::$addIdAsPrefix = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPageIdWithTitle');
296  self::$addDomainName = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showDomainNameWithTitle');
297  self::$backgroundColors = $GLOBALS['BE_USER']->getTSConfigProp('options.pageTree.backgroundColor');
298  self::$titleLength = (int)$GLOBALS['BE_USER']->uc['titleLen'];
299  }
301  $subNode = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode');
302  $subNode->setRecord($record);
303  $subNode->setCls($record['_CSSCLASS']);
304  $subNode->setType('pages');
305  $subNode->setId($record['uid']);
306  $subNode->setMountPoint($mountPoint);
307  $subNode->setWorkspaceId($record['_ORIG_uid'] ?: $record['uid']);
308  $subNode->setBackgroundColor(self::$backgroundColors[$record['uid']]);
309  $field = 'title';
310  $text = $record['title'];
311  if (self::$useNavTitle && trim($record['nav_title']) !== '') {
312  $field = 'nav_title';
313  $text = $record['nav_title'];
314  }
315  if (trim($text) === '') {
316  $visibleText = '[' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.no_title', TRUE) . ']';
317  } else {
318  $visibleText = $text;
319  }
320  $visibleText = GeneralUtility::fixed_lgd_cs($visibleText, self::$titleLength);
321  $suffix = '';
322  if (self::$addDomainName) {
323  $domain = self::getDomainName($record['uid']);
324  $suffix = $domain !== '' ? ' [' . $domain . ']' : '';
325  }
326  $qtip = str_replace(' - ', '<br />', htmlspecialchars(BackendUtility::titleAttribForPages($record, '', FALSE)));
327  $prefix = '';
328  $lockInfo = BackendUtility::isRecordLocked('pages', $record['uid']);
329  if (is_array($lockInfo)) {
330  $qtip .= '<br />' . htmlspecialchars($lockInfo['msg']);
331  $prefix .= IconUtility::getSpriteIcon('status-warning-in-use', array(
332  'class' => 'typo3-pagetree-status'
333  ));
334  }
335  // Call stats information hook
336  $stat = '';
337  if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
338  $_params = array('pages', $record['uid']);
339  $fakeThis = NULL;
340  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
341  $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $fakeThis);
342  }
343  }
344  $prefix .= htmlspecialchars(self::$addIdAsPrefix ? '[' . $record['uid'] . '] ' : '');
345  $subNode->setEditableText($text);
346  $subNode->setText(htmlspecialchars($visibleText), $field, $prefix, htmlspecialchars($suffix) . $stat);
347  $subNode->setQTip($qtip);
348  if ((int)$record['uid'] !== 0) {
349  $spriteIconCode = IconUtility::getSpriteIconForRecord('pages', $record);
350  } else {
351  $spriteIconCode = IconUtility::getSpriteIcon('apps-pagetree-root');
352  }
353  $subNode->setSpriteIconCode($spriteIconCode);
354  if (
355  !$subNode->canCreateNewPages()
356  || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
357  ) {
358  $subNode->setIsDropTarget(FALSE);
359  }
360  if (
361  !$subNode->canBeEdited()
362  || !$subNode->canBeRemoved()
363  || VersionState::cast($record['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)
364  ) {
365  $subNode->setDraggable(FALSE);
366  }
367  return $subNode;
368  }
369 
370 }
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 visiblyNode(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode $node)
Definition: Commands.php:61
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'][]