/**
  * Gets node children
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $node
  * @param int $level
  * @return NULL|\TYPO3\CMS\Backend\Tree\TreeNodeCollection
  */
 protected function getChildrenOf(\TYPO3\CMS\Backend\Tree\TreeNode $node, $level)
 {
     $nodeData = NULL;
     if ($node->getId() !== 0) {
         $nodeData = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $this->tableName, 'uid=' . $node->getId());
     }
     if ($nodeData == NULL) {
         $nodeData = array('uid' => 0, $this->getLookupField() => '');
     }
     $storage = NULL;
     $children = $this->getRelatedRecords($nodeData);
     if (!empty($children)) {
         /** @var $storage \TYPO3\CMS\Backend\Tree\TreeNodeCollection */
         $storage = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\TreeNodeCollection::class);
         foreach ($children as $child) {
             $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\TreeNode::class);
             $node->setId($child);
             if ($level < $this->levelMaximum) {
                 $children = $this->getChildrenOf($node, $level + 1);
                 if ($children !== NULL) {
                     $node->setChildNodes($children);
                 }
             }
             $storage->append($node);
         }
     }
     return $storage;
 }
示例#2
0
 /**
  * Sets the CSS Class on all pages which have versioned records
  * in the current workspace
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $node
  * @return void
  */
 protected function highlightVersionizedElements(\TYPO3\CMS\Backend\Tree\TreeNode $node)
 {
     if (!$node->getCls() && $this->getWorkspaceService()->hasPageRecordVersions($GLOBALS['BE_USER']->workspace, $node->getId())) {
         $node->setCls('ver-versions');
     }
 }
示例#3
0
 /**
  * Compares a node if it's identical to another node by the id property.
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $other
  * @return bool
  */
 public function equals(\TYPO3\CMS\Backend\Tree\TreeNode $other)
 {
     return $this->id == $other->getId();
 }
示例#4
0
 /**
  * Returns a node collection of filtered nodes
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $node
  * @param string $searchFilter
  * @param int $mountPoint
  * @return \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection the filtered nodes
  */
 public function getFilteredNodes(\TYPO3\CMS\Backend\Tree\TreeNode $node, $searchFilter, $mountPoint = 0)
 {
     /** @var $nodeCollection \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */
     $nodeCollection = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection::class);
     $records = $this->getSubpages(-1, $searchFilter);
     if (!is_array($records) || empty($records)) {
         return $nodeCollection;
     } elseif (count($records) > 500) {
         return $nodeCollection;
     }
     // check no temporary mountpoint is used
     $mountPoints = (int) $GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint'];
     if (!$mountPoints) {
         $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts());
         $mountPoints = array_unique($mountPoints);
     } else {
         $mountPoints = [$mountPoints];
     }
     $isNumericSearchFilter = is_numeric($searchFilter) && $searchFilter > 0;
     $searchFilterQuoted = preg_quote($searchFilter, '/');
     $nodeId = (int) $node->getId();
     $processedRecordIds = [];
     foreach ($records as $record) {
         if ((int) $record['t3ver_wsid'] !== (int) $GLOBALS['BE_USER']->workspace && (int) $record['t3ver_wsid'] !== 0) {
             continue;
         }
         $liveVersion = BackendUtility::getLiveVersionOfRecord('pages', $record['uid'], 'uid');
         if ($liveVersion !== null) {
             $record = $liveVersion;
         }
         $record = Commands::getNodeRecord($record['uid'], false);
         if ((int) $record['pid'] === -1 || in_array($record['uid'], $this->hiddenRecords) || in_array($record['uid'], $processedRecordIds)) {
             continue;
         }
         $processedRecordIds[] = $record['uid'];
         $rootline = BackendUtility::BEgetRootLine($record['uid'], '', $GLOBALS['BE_USER']->workspace != 0);
         $rootline = array_reverse($rootline);
         if (!in_array(0, $mountPoints, true)) {
             $isInsideMountPoints = false;
             foreach ($rootline as $rootlineElement) {
                 if (in_array((int) $rootlineElement['uid'], $mountPoints, true)) {
                     $isInsideMountPoints = true;
                     break;
                 }
             }
             if (!$isInsideMountPoints) {
                 continue;
             }
         }
         $reference = $nodeCollection;
         $inFilteredRootline = false;
         $amountOfRootlineElements = count($rootline);
         for ($i = 0; $i < $amountOfRootlineElements; ++$i) {
             $rootlineElement = $rootline[$i];
             $rootlineElement['uid'] = (int) $rootlineElement['uid'];
             $isInWebMount = (int) $GLOBALS['BE_USER']->isInWebMount($rootlineElement['uid']);
             if (!$isInWebMount || $rootlineElement['uid'] === (int) $mountPoints[0] && $rootlineElement['uid'] !== $isInWebMount) {
                 continue;
             }
             if ((int) $rootlineElement['pid'] === $nodeId || $rootlineElement['uid'] === $nodeId || $rootlineElement['uid'] === $isInWebMount && in_array($rootlineElement['uid'], $mountPoints, true)) {
                 $inFilteredRootline = true;
             }
             if (!$inFilteredRootline || $rootlineElement['uid'] === $mountPoint) {
                 continue;
             }
             $rootlineElement = Commands::getNodeRecord($rootlineElement['uid'], false);
             $ident = (int) $rootlineElement['sorting'] . (int) $rootlineElement['uid'];
             if ($reference && $reference->offsetExists($ident)) {
                 /** @var $refNode \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
                 $refNode = $reference->offsetGet($ident);
                 $refNode->setExpanded(true);
                 $refNode->setLeaf(false);
                 $reference = $refNode->getChildNodes();
                 if ($reference == null) {
                     $reference = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection::class);
                     $refNode->setChildNodes($reference);
                 }
             } else {
                 $refNode = Commands::getNewNode($rootlineElement, $mountPoint);
                 $replacement = '<span class="typo3-pagetree-filteringTree-highlight">$1</span>';
                 if ($isNumericSearchFilter && (int) $rootlineElement['uid'] === (int) $searchFilter) {
                     $text = str_replace('$1', $refNode->getText(), $replacement);
                 } else {
                     $text = preg_replace('/(' . $searchFilterQuoted . ')/iu', $replacement, $refNode->getText());
                 }
                 $refNode->setText($text, $refNode->getTextSourceField(), $refNode->getPrefix(), $refNode->getSuffix());
                 /** @var $childCollection \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */
                 $childCollection = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection::class);
                 if ($i + 1 >= $amountOfRootlineElements) {
                     $childNodes = $this->getNodes($refNode, $mountPoint);
                     foreach ($childNodes as $childNode) {
                         /** @var $childNode \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
                         $childRecord = $childNode->getRecord();
                         $childIdent = (int) $childRecord['sorting'] . (int) $childRecord['uid'];
                         $childCollection->offsetSet($childIdent, $childNode);
                     }
                     $refNode->setChildNodes($childNodes);
                 }
                 $refNode->setChildNodes($childCollection);
                 $reference->offsetSet($ident, $refNode);
                 $reference->ksort();
                 $reference = $childCollection;
             }
         }
     }
     foreach ($this->processCollectionHookObjects as $hookObject) {
         /** @var $hookObject \TYPO3\CMS\Backend\Tree\Pagetree\CollectionProcessorInterface */
         $hookObject->postProcessFilteredNodes($node, $searchFilter, $mountPoint, $nodeCollection);
     }
     return $nodeCollection;
 }
示例#5
0
 /**
  * Gets the expanded state of a given node
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $node
  * @return bool
  */
 protected function isExpanded(\TYPO3\CMS\Backend\Tree\TreeNode $node)
 {
     return $this->getExpandAll() || \TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->expandedList, $node->getId());
 }
示例#6
0
 /**
  * Check if given category is allowed by the access rights
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $child
  * @return bool
  */
 protected function isCategoryAllowed($child)
 {
     $mounts = $this->backendUserAuthentication->getCategoryMountPoints();
     if (empty($mounts)) {
         return TRUE;
     }
     return in_array($child->getId(), $mounts);
 }
 /**
  * Sets the CSS Class on all pages which have versioned records
  * in the current workspace
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $node
  * @return void
  */
 protected function highlightVersionizedElements(\TYPO3\CMS\Backend\Tree\TreeNode $node)
 {
     if (!$node->getCls() && count(\TYPO3\CMS\Backend\Utility\BackendUtility::countVersionsOfRecordsOnPage($GLOBALS['BE_USER']->workspace, $node->getId(), TRUE))) {
         $node->setCls('ver-versions');
     }
 }
 /**
  * Check if given category is allowed by the access rights
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $child
  * @return bool
  */
 protected function isCategoryAllowed($child)
 {
     $mounts = Tx_News_Utility_CategoryProvider::getUserMounts();
     if (empty($mounts)) {
         return TRUE;
     }
     return t3lib_div::inList($mounts, $child->getId());
 }
示例#9
0
 /**
  * Gets node children
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $node
  * @param int $level
  * @return NULL|\TYPO3\CMS\Backend\Tree\TreeNodeCollection
  */
 protected function getChildrenOf(\TYPO3\CMS\Backend\Tree\TreeNode $node, $level)
 {
     $nodeData = null;
     if ($node->getId() !== 0) {
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->getTableName());
         $queryBuilder->getRestrictions()->removeAll();
         $nodeData = $queryBuilder->select('*')->from($this->getTableName())->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($node->getId(), \PDO::PARAM_INT)))->setMaxResults(1)->execute()->fetch();
     }
     if (empty($nodeData)) {
         $nodeData = ['uid' => 0, $this->getLookupField() => ''];
     }
     $storage = null;
     $children = $this->getRelatedRecords($nodeData);
     if (!empty($children)) {
         /** @var $storage \TYPO3\CMS\Backend\Tree\TreeNodeCollection */
         $storage = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\TreeNodeCollection::class);
         foreach ($children as $child) {
             $node = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\TreeNode::class);
             $node->setId($child);
             if ($level < $this->levelMaximum) {
                 $children = $this->getChildrenOf($node, $level + 1);
                 if ($children !== null) {
                     $node->setChildNodes($children);
                 }
             }
             $storage->append($node);
         }
     }
     return $storage;
 }
示例#10
0
 /**
  * Returns a node collection of filtered nodes
  *
  * @param \TYPO3\CMS\Backend\Tree\TreeNode $node
  * @param string $searchFilter
  * @param integer $mountPoint
  * @return \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection the filtered nodes
  */
 public function getFilteredNodes(\TYPO3\CMS\Backend\Tree\TreeNode $node, $searchFilter, $mountPoint = 0)
 {
     /** @var $nodeCollection \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */
     $nodeCollection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection');
     $records = $this->getSubpages(-1, $searchFilter);
     if (!is_array($records) || !count($records)) {
         return $nodeCollection;
     } elseif (count($records) > 500) {
         return $nodeCollection;
     }
     // check no temporary mountpoint is used
     $mountPoints = intval($GLOBALS['BE_USER']->uc['pageTree_temporaryMountPoint']);
     if (!$mountPoints) {
         $mountPoints = array_map('intval', $GLOBALS['BE_USER']->returnWebmounts());
         $mountPoints = array_unique($mountPoints);
     } else {
         $mountPoints = array($mountPoints);
     }
     $isNumericSearchFilter = is_numeric($searchFilter) && $searchFilter > 0;
     $nodeId = intval($node->getId());
     foreach ($records as $record) {
         $record = \TYPO3\CMS\Backend\Tree\Pagetree\Commands::getNodeRecord($record['uid']);
         if (intval($record['pid']) === -1 || in_array($record['uid'], $this->hiddenRecords)) {
             continue;
         }
         $rootline = \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($record['uid'], '', $GLOBALS['BE_USER']->workspace != 0);
         $rootline = array_reverse($rootline);
         if ($nodeId === 0) {
             array_shift($rootline);
         }
         if ($mountPoints != array(0)) {
             $isInsideMountPoints = FALSE;
             foreach ($rootline as $rootlineElement) {
                 if (in_array(intval($rootlineElement['uid']), $mountPoints, TRUE)) {
                     $isInsideMountPoints = TRUE;
                     break;
                 }
             }
             if (!$isInsideMountPoints) {
                 continue;
             }
         }
         $reference = $nodeCollection;
         $inFilteredRootline = FALSE;
         $amountOfRootlineElements = count($rootline);
         for ($i = 0; $i < $amountOfRootlineElements; ++$i) {
             $rootlineElement = $rootline[$i];
             if (intval($rootlineElement['pid']) === $nodeId || intval($rootlineElement['uid']) === $nodeId) {
                 $inFilteredRootline = TRUE;
             }
             if (!$inFilteredRootline) {
                 continue;
             }
             $rootlineElement = \TYPO3\CMS\Backend\Tree\Pagetree\Commands::getNodeRecord($rootlineElement['uid']);
             $ident = intval($rootlineElement['sorting']) . intval($rootlineElement['uid']);
             if ($reference && $reference->offsetExists($ident)) {
                 /** @var $refNode \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
                 $refNode = $reference->offsetGet($ident);
                 $refNode->setExpanded(TRUE);
                 $refNode->setLeaf(FALSE);
                 $reference = $refNode->getChildNodes();
                 if ($reference == NULL) {
                     $reference = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection');
                     $refNode->setChildNodes($reference);
                 }
             } else {
                 $refNode = \TYPO3\CMS\Backend\Tree\Pagetree\Commands::getNewNode($rootlineElement, $mountPoint);
                 $replacement = '<span class="typo3-pagetree-filteringTree-highlight">$1</span>';
                 if ($isNumericSearchFilter && intval($rootlineElement['uid']) === intval($searchFilter)) {
                     $text = str_replace('$1', $refNode->getText(), $replacement);
                 } else {
                     $text = preg_replace('/(' . $searchFilter . ')/i', $replacement, $refNode->getText());
                 }
                 $refNode->setText($text, $refNode->getTextSourceField(), $refNode->getPrefix(), $refNode->getSuffix());
                 /** @var $childCollection \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNodeCollection */
                 $childCollection = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\Pagetree\\PagetreeNodeCollection');
                 if ($i + 1 >= $amountOfRootlineElements) {
                     $childNodes = $this->getNodes($refNode, $mountPoint);
                     foreach ($childNodes as $childNode) {
                         /** @var $childNode \TYPO3\CMS\Backend\Tree\Pagetree\PagetreeNode */
                         $childRecord = $childNode->getRecord();
                         $childIdent = intval($childRecord['sorting']) . intval($childRecord['uid']);
                         $childCollection->offsetSet($childIdent, $childNode);
                     }
                     $refNode->setChildNodes($childNodes);
                 }
                 $refNode->setChildNodes($childCollection);
                 $reference->offsetSet($ident, $refNode);
                 $reference->ksort();
                 $reference = $childCollection;
             }
         }
     }
     foreach ($this->processCollectionHookObjects as $hookObject) {
         /** @var $hookObject t3lib_tree_pagetree_interfaces_collectionprocessor */
         $hookObject->postProcessFilteredNodes($node, $searchFilter, $mountPoint, $nodeCollection);
     }
     return $nodeCollection;
 }