TYPO3 CMS  TYPO3_6-2
DataProvider.php
Go to the documentation of this file.
1 <?php
3 
20 
27 
33  protected $nodeLimit = 0;
34 
40  protected $nodeCounter = 0;
41 
47  protected $showRootlineAboveMounts = FALSE;
48 
54  protected $hiddenRecords = array();
55 
61  protected $processCollectionHookObjects = array();
62 
68  public function __construct($nodeLimit = NULL) {
69  if ($nodeLimit === NULL) {
70  $nodeLimit = $GLOBALS['TYPO3_CONF_VARS']['BE']['pageTree']['preloadLimit'];
71  }
72  $this->nodeLimit = abs((int)$nodeLimit);
73 
74  $this->showRootlineAboveMounts = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showPathAboveMounts');
75 
76  $this->hiddenRecords = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages'));
77  $hookElements = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php']['postProcessCollections'];
78  if (is_array($hookElements)) {
79  foreach ($hookElements as $classRef) {
81  $hookObject = GeneralUtility::getUserObj($classRef);
82  if ($hookObject instanceof \TYPO3\CMS\Backend\Tree\Pagetree\CollectionProcessorInterface) {
83  $this->processCollectionHookObjects[] = $hookObject;
84  }
85  }
86  }
87  }
88 
94  public function getRoot() {
96  $node = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNode');
97  $node->setId('root');
98  $node->setExpanded(TRUE);
99  return $node;
100  }
101 
110  public function getNodes(\TYPO3\CMS\Backend\Tree\TreeNode $node, $mountPoint = 0, $level = 0) {
112  $nodeCollection = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection');
113  if ($level >= 99) {
114  return $nodeCollection;
115  }
116  $isVirtualRootNode = FALSE;
117  $subpages = $this->getSubpages($node->getId());
118  // check if fetching subpages the "root"-page
119  // and in case of a virtual root return the mountpoints as virtual "subpages"
120  if ((int)$node->getId() === 0) {
121  // check no temporary mountpoint is used
122  if (!(int)$GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint']) {
123  $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts());
124  $mountPoints = array_unique($mountPoints);
125  if (!in_array(0, $mountPoints)) {
126  // using a virtual root node
127  // so then return the mount points here as "subpages" of the first node
128  $isVirtualRootNode = TRUE;
129  $subpages = array();
130  foreach ($mountPoints as $webMountPoint) {
131  $subpages[] = array(
132  'uid' => $webMountPoint,
133  'isMountPoint' => TRUE
134  );
135  }
136  }
137  }
138  }
139  if (is_array($subpages) && count($subpages) > 0) {
140  foreach ($subpages as $subpage) {
141  if (in_array($subpage['uid'], $this->hiddenRecords)) {
142  continue;
143  }
144  // must be calculated above getRecordWithWorkspaceOverlay,
145  // because the information is lost otherwise
146  $isMountPoint = $subpage['isMountPoint'] === TRUE;
147  if ($isVirtualRootNode) {
148  $mountPoint = (int)$subpage['uid'];
149  }
150  $subpage = $this->getRecordWithWorkspaceOverlay($subpage['uid'], TRUE);
151  if (!$subpage) {
152  continue;
153  }
154  $subNode = Commands::getNewNode($subpage, $mountPoint);
155  $subNode->setIsMountPoint($isMountPoint);
156  if ($isMountPoint && $this->showRootlineAboveMounts) {
157  $rootline = Commands::getMountPointPath($subpage['uid']);
158  $subNode->setReadableRootline($rootline);
159  }
160  if ($this->nodeCounter < $this->nodeLimit) {
161  $childNodes = $this->getNodes($subNode, $mountPoint, $level + 1);
162  $subNode->setChildNodes($childNodes);
163  $this->nodeCounter += $childNodes->count();
164  } else {
165  $subNode->setLeaf(!$this->hasNodeSubPages($subNode->getId()));
166  }
167  $nodeCollection->append($subNode);
168  }
169  }
170  foreach ($this->processCollectionHookObjects as $hookObject) {
172  $hookObject->postProcessGetNodes($node, $mountPoint, $level, $nodeCollection);
173  }
174  return $nodeCollection;
175  }
176 
184  protected function getRecordWithWorkspaceOverlay($uid, $unsetMovePointers = FALSE) {
185  return BackendUtility::getRecordWSOL('pages', $uid, '*', '', TRUE, $unsetMovePointers);
186  }
187 
196  public function getFilteredNodes(\TYPO3\CMS\Backend\Tree\TreeNode $node, $searchFilter, $mountPoint = 0) {
198  $nodeCollection = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection');
199  $records = $this->getSubpages(-1, $searchFilter);
200  if (!is_array($records) || !count($records)) {
201  return $nodeCollection;
202  } elseif (count($records) > 500) {
203  return $nodeCollection;
204  }
205  // check no temporary mountpoint is used
206  $mountPoints = (int)$GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'];
207  if (!$mountPoints) {
208  $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts());
209  $mountPoints = array_unique($mountPoints);
210  } else {
211  $mountPoints = array($mountPoints);
212  }
213  $isNumericSearchFilter = is_numeric($searchFilter) && $searchFilter > 0;
214  $searchFilterQuoted = preg_quote($searchFilter, '/');
215  $nodeId = (int)$node->getId();
216  $processedRecordIds = array();
217  foreach ($records as $record) {
218  if ((int)$record['t3ver_wsid'] !== (int)$GLOBALS['BE_USER']->workspace && (int)$record['t3ver_wsid'] !== 0) {
219  continue;
220  }
221  $liveVersion = BackendUtility::getLiveVersionOfRecord('pages', $record['uid'], 'uid');
222  if ($liveVersion !== NULL) {
223  $record = $liveVersion;
224  }
225 
226  $record = Commands::getNodeRecord($record['uid'], FALSE);
227  if ((int)$record['pid'] === -1
228  || in_array($record['uid'], $this->hiddenRecords)
229  || in_array($record['uid'], $processedRecordIds)
230  ) {
231  continue;
232  }
233  $processedRecordIds[] = $record['uid'];
234 
235  $rootline = BackendUtility::BEgetRootLine($record['uid'], '', $GLOBALS['BE_USER']->workspace != 0);
236  $rootline = array_reverse($rootline);
237  if (!in_array(0, $mountPoints, TRUE)) {
238  $isInsideMountPoints = FALSE;
239  foreach ($rootline as $rootlineElement) {
240  if (in_array((int)$rootlineElement['uid'], $mountPoints, TRUE)) {
241  $isInsideMountPoints = TRUE;
242  break;
243  }
244  }
245  if (!$isInsideMountPoints) {
246  continue;
247  }
248  }
249  $reference = $nodeCollection;
250  $inFilteredRootline = FALSE;
251  $amountOfRootlineElements = count($rootline);
252  for ($i = 0; $i < $amountOfRootlineElements; ++$i) {
253  $rootlineElement = $rootline[$i];
254  $rootlineElement['uid'] = (int)$rootlineElement['uid'];
255  $isInWebMount = (int)$GLOBALS['BE_USER']->isInWebMount($rootlineElement['uid']);
256  if (!$isInWebMount
257  || ($rootlineElement['uid'] === (int)$mountPoints[0]
258  && $rootlineElement['uid'] !== $isInWebMount)
259  ) {
260  continue;
261  }
262  if ((int)$rootlineElement['pid'] === $nodeId
263  || $rootlineElement['uid'] === $nodeId
264  || ($rootlineElement['uid'] === $isInWebMount
265  && in_array($rootlineElement['uid'], $mountPoints, TRUE))
266  ) {
267  $inFilteredRootline = TRUE;
268  }
269  if (!$inFilteredRootline || $rootlineElement['uid'] === $mountPoint) {
270  continue;
271  }
272  $rootlineElement = Commands::getNodeRecord($rootlineElement['uid'], FALSE);
273  $ident = (int)$rootlineElement['sorting'] . (int)$rootlineElement['uid'];
274  if ($reference && $reference->offsetExists($ident)) {
276  $refNode = $reference->offsetGet($ident);
277  $refNode->setExpanded(TRUE);
278  $refNode->setLeaf(FALSE);
279  $reference = $refNode->getChildNodes();
280  if ($reference == NULL) {
281  $reference = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection');
282  $refNode->setChildNodes($reference);
283  }
284  } else {
285  $refNode = Commands::getNewNode($rootlineElement, $mountPoint);
286  $replacement = '<span class="typo3-pagetree-filteringTree-highlight">$1</span>';
287  if ($isNumericSearchFilter && (int)$rootlineElement['uid'] === (int)$searchFilter) {
288  $text = str_replace('$1', $refNode->getText(), $replacement);
289  } else {
290  $text = preg_replace('/(' . $searchFilterQuoted . ')/i', $replacement, $refNode->getText());
291  }
292  $refNode->setText($text, $refNode->getTextSourceField(), $refNode->getPrefix(), $refNode->getSuffix());
294  $childCollection = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection');
295  if ($i + 1 >= $amountOfRootlineElements) {
296  $childNodes = $this->getNodes($refNode, $mountPoint);
297  foreach ($childNodes as $childNode) {
299  $childRecord = $childNode->getRecord();
300  $childIdent = (int)$childRecord['sorting'] . (int)$childRecord['uid'];
301  $childCollection->offsetSet($childIdent, $childNode);
302  }
303  $refNode->setChildNodes($childNodes);
304  }
305  $refNode->setChildNodes($childCollection);
306  $reference->offsetSet($ident, $refNode);
307  $reference->ksort();
308  $reference = $childCollection;
309  }
310  }
311  }
312  foreach ($this->processCollectionHookObjects as $hookObject) {
314  $hookObject->postProcessFilteredNodes($node, $searchFilter, $mountPoint, $nodeCollection);
315  }
316  return $nodeCollection;
317  }
318 
327  public function getTreeMounts($searchFilter = '') {
329  $nodeCollection = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection');
330  $isTemporaryMountPoint = FALSE;
331  $rootNodeIsVirtual = FALSE;
332  $mountPoints = (int)$GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'];
333  if (!$mountPoints) {
334  $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts());
335  $mountPoints = array_unique($mountPoints);
336  if (!in_array(0, $mountPoints)) {
337  $rootNodeIsVirtual = TRUE;
338  // use a virtual root
339  // the real mountpoints will be fetched in getNodes() then
340  // since those will be the "subpages" of the virtual root
341  $mountPoints = array(0);
342  }
343  } else {
344  $isTemporaryMountPoint = TRUE;
345  $mountPoints = array($mountPoints);
346  }
347  if (!count($mountPoints)) {
348  return $nodeCollection;
349  }
350 
351  foreach ($mountPoints as $mountPoint) {
352  if ($mountPoint === 0) {
353  $sitename = 'TYPO3';
354  if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] !== '') {
355  $sitename = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
356  }
357  $record = array(
358  'uid' => 0,
359  'title' => $sitename
360  );
361  $subNode = Commands::getNewNode($record);
362  $subNode->setLabelIsEditable(FALSE);
363  if ($rootNodeIsVirtual) {
364  $subNode->setType('virtual_root');
365  $subNode->setIsDropTarget(FALSE);
366  } else {
367  $subNode->setType('pages_root');
368  $subNode->setIsDropTarget(TRUE);
369  }
370  } else {
371  if (in_array($mountPoint, $this->hiddenRecords)) {
372  continue;
373  }
374  $record = $this->getRecordWithWorkspaceOverlay($mountPoint);
375  if (!$record) {
376  continue;
377  }
378  $subNode = Commands::getNewNode($record, $mountPoint);
379  if ($this->showRootlineAboveMounts && !$isTemporaryMountPoint) {
380  $rootline = Commands::getMountPointPath($record['uid']);
381  $subNode->setReadableRootline($rootline);
382  }
383  }
384  if (count($mountPoints) <= 1) {
385  $subNode->setExpanded(TRUE);
386  $subNode->setCls('typo3-pagetree-node-notExpandable');
387  }
388  $subNode->setIsMountPoint(TRUE);
389  $subNode->setDraggable(FALSE);
390  if ($searchFilter === '') {
391  $childNodes = $this->getNodes($subNode, $mountPoint);
392  } else {
393  $childNodes = $this->getFilteredNodes($subNode, $searchFilter, $mountPoint);
394  $subNode->setExpanded(TRUE);
395  }
396  $subNode->setChildNodes($childNodes);
397  $nodeCollection->append($subNode);
398  }
399  foreach ($this->processCollectionHookObjects as $hookObject) {
401  $hookObject->postProcessGetTreeMounts($searchFilter, $nodeCollection);
402  }
403  return $nodeCollection;
404  }
405 
413  protected function getWhereClause($id, $searchFilter = '') {
414  $where = $GLOBALS['BE_USER']->getPagePermsClause(1) . BackendUtility::deleteClause('pages') . BackendUtility::versioningPlaceholderClause('pages');
415  if (is_numeric($id) && $id >= 0) {
416  $where .= ' AND pid= ' . $GLOBALS['TYPO3_DB']->fullQuoteStr((int)$id, 'pages');
417  }
418 
419  $excludedDoktypes = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.excludeDoktypes');
420  if (!empty($excludedDoktypes)) {
421  $excludedDoktypes = $GLOBALS['TYPO3_DB']->fullQuoteArray(GeneralUtility::intExplode(',', $excludedDoktypes), 'pages');
422  $where .= ' AND doktype NOT IN (' . implode(',', $excludedDoktypes) . ')';
423  }
424 
425  if ($searchFilter !== '') {
426  if (is_numeric($searchFilter) && $searchFilter > 0) {
427  $searchWhere .= 'uid = ' . (int)$searchFilter . ' OR ';
428  }
429  $searchFilter = $GLOBALS['TYPO3_DB']->fullQuoteStr('%' . $searchFilter . '%', 'pages');
430  $useNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
431  $useAlias = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.searchInAlias');
432 
433  $searchWhereAlias = '';
434  if ($useAlias) {
435  $searchWhereAlias = ' OR alias LIKE ' . $searchFilter;
436  }
437 
438  if ($useNavTitle) {
439  $searchWhere .= '(nav_title LIKE ' . $searchFilter .
440  ' OR (nav_title = "" AND title LIKE ' . $searchFilter . ')' . $searchWhereAlias . ')';
441  } else {
442  $searchWhere .= 'title LIKE ' . $searchFilter . $searchWhereAlias;
443  }
444 
445  $where .= ' AND (' . $searchWhere . ')';
446  }
447  return $where;
448  }
449 
457  protected function getSubpages($id, $searchFilter = '') {
458  $where = $this->getWhereClause($id, $searchFilter);
459  return $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,t3ver_wsid', 'pages', $where, '', 'sorting', '', 'uid');
460  }
461 
468  protected function hasNodeSubPages($id) {
469  $where = $this->getWhereClause($id);
470  $subpage = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid', 'pages', $where, '', 'sorting', '', 'uid');
471  $returnValue = TRUE;
472  if (!$subpage['uid']) {
473  $returnValue = FALSE;
474  }
475  return $returnValue;
476  }
477 
478 }
static getRecordWSOL($table, $uid, $fields=' *', $where='', $useDeleteClause=TRUE, $unsetMovePointers=FALSE)
getNodes(\TYPO3\CMS\Backend\Tree\TreeNode $node)
static BEgetRootLine($uid, $clause='', $workspaceOL=FALSE)
static intExplode($delimiter, $string, $removeEmptyValues=FALSE, $limit=0)
$uid
Definition: server.php:36
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static getNodeRecord($nodeId, $unsetMovePointers=TRUE)
Definition: Commands.php:268
static getLiveVersionOfRecord($table, $uid, $fields=' *')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
getRecordWithWorkspaceOverlay($uid, $unsetMovePointers=FALSE)
static deleteClause($table, $tableAlias='')