1<?php 2namespace TYPO3\CMS\Backend\Tree\View; 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 17use TYPO3\CMS\Backend\Utility\BackendUtility; 18use TYPO3\CMS\Core\Exception\SiteNotFoundException; 19use TYPO3\CMS\Core\Site\PseudoSiteFinder; 20use TYPO3\CMS\Core\Site\SiteFinder; 21use TYPO3\CMS\Core\Type\Bitmask\Permission; 22use TYPO3\CMS\Core\Utility\GeneralUtility; 23 24/** 25 * Generate a page-tree, browsable. 26 */ 27class BrowseTreeView extends AbstractTreeView 28{ 29 /** 30 * @var array 31 */ 32 public $fieldArray = [ 33 'uid', 34 'pid', 35 'title', 36 'doktype', 37 'nav_title', 38 'mount_pid', 39 'php_tree_stop', 40 't3ver_id', 41 't3ver_state', 42 'hidden', 43 'starttime', 44 'endtime', 45 'fe_group', 46 'module', 47 'extendToSubpages', 48 'nav_hide', 49 't3ver_wsid', 50 't3ver_move_id', 51 'is_siteroot' 52 ]; 53 54 /** 55 * override to use this treeName 56 * @var string 57 */ 58 public $treeName = 'browsePages'; 59 60 /** 61 * override to use this table 62 * @var string 63 */ 64 public $table = 'pages'; 65 66 /** 67 * override to use this domIdPrefix 68 * @var string 69 */ 70 public $domIdPrefix = 'pages'; 71 72 /** 73 * @var bool 74 */ 75 public $ext_showNavTitle = false; 76 77 /** 78 * Initialize, setting what is necessary for browsing pages. 79 * Using the current user. 80 * 81 * @param string $clause Additional clause for selecting pages. 82 * @param string $orderByFields record ORDER BY field 83 */ 84 public function init($clause = '', $orderByFields = '') 85 { 86 $backendUser = $this->getBackendUser(); 87 // This will hide records from display - it has nothing to do with user rights!! 88 $clauseExcludePidList = ''; 89 $pidList = $backendUser->getTSConfig()['options.']['hideRecords.']['pages'] ?? ''; 90 if (!empty($pidList)) { 91 if ($pidList = implode(',', GeneralUtility::intExplode(',', $pidList))) { 92 $clauseExcludePidList = ' AND pages.uid NOT IN (' . $pidList . ')'; 93 } 94 } 95 // This is very important for making trees of pages: Filtering out deleted pages, pages with no access to and sorting them correctly: 96 parent::init(' AND deleted=0 AND sys_language_uid=0 AND ' . $backendUser->getPagePermsClause(Permission::PAGE_SHOW) . ' ' . $clause . $clauseExcludePidList, 'sorting'); 97 $this->title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; 98 $this->MOUNTS = $backendUser->returnWebmounts(); 99 if ($pidList) { 100 // Remove mountpoint if explicitly set in options.hideRecords.pages (see above) 101 $hideList = explode(',', $pidList); 102 $this->MOUNTS = array_diff($this->MOUNTS, $hideList); 103 } 104 } 105 106 /** 107 * Creates title attribute content for pages. 108 * Uses API function in \TYPO3\CMS\Backend\Utility\BackendUtility which will retrieve lots of useful information for pages. 109 * 110 * @param array $row The table row. 111 * @return string 112 */ 113 public function getTitleAttrib($row) 114 { 115 return BackendUtility::titleAttribForPages($row, '1=1 ' . $this->clause, 0); 116 } 117 118 /** 119 * Wrapping the image tag, $icon, for the row, $row (except for mount points) 120 * 121 * @param string $icon The image tag for the icon 122 * @param array $row The row for the current element 123 * @return string The processed icon input value. 124 * @internal 125 */ 126 public function wrapIcon($icon, $row) 127 { 128 // Wrap icon in click-menu link. 129 $theIcon = ''; 130 if (!$this->ext_IconMode) { 131 $theIcon = BackendUtility::wrapClickMenuOnIcon($icon, $this->treeName, $this->getId($row), 0); 132 } elseif ($this->ext_IconMode === 'titlelink') { 133 $aOnClick = 'return jumpTo(' . GeneralUtility::quoteJSvalue($this->getJumpToParam($row)) . ',this,' 134 . GeneralUtility::quoteJSvalue($this->domIdPrefix . $this->getId($row)) . ',' . $this->bank . ');'; 135 $theIcon = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $icon . '</a>'; 136 } 137 return $theIcon; 138 } 139 140 /** 141 * Returns the title for the input record. If blank, a "no title" label (localized) will be returned. 142 * Do NOT htmlspecialchar the string from this function - has already been done. 143 * 144 * @param array $row The input row array (where the key "title" is used for the title) 145 * @param int $titleLen Title length (30) 146 * @return string The title. 147 */ 148 public function getTitleStr($row, $titleLen = 30) 149 { 150 if ($this->ext_showNavTitle && isset($row['nav_title']) && trim($row['nav_title']) !== '') { 151 $title = parent::getTitleStr(['title' => $row['nav_title']], $titleLen); 152 } else { 153 $title = parent::getTitleStr($row, $titleLen); 154 } 155 if (!empty($row['is_siteroot']) 156 && $this->getBackendUser()->getTSConfig()['options.']['pageTree.']['showDomainNameWithTitle'] ?? false 157 ) { 158 $pageId = (int)$row['uid']; 159 $siteFinder = GeneralUtility::makeInstance(SiteFinder::class); 160 try { 161 $site = $siteFinder->getSiteByRootPageId($pageId); 162 $title .= ' [' . (string)$site->getBase() . ']'; 163 } catch (SiteNotFoundException $e) { 164 // No site found, let's see if it is a legacy-pseudo-site 165 $pseudoSiteFinder = GeneralUtility::makeInstance(PseudoSiteFinder::class); 166 167 try { 168 $site = $pseudoSiteFinder->getSiteByRootPageId($pageId); 169 $title .= ' [' . trim((string)$site->getBase(), '/') . ']'; 170 } catch (SiteNotFoundException $e) { 171 // No pseudo-site found either 172 } 173 } 174 } 175 return $title; 176 } 177} 178