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