‪TYPO3CMS  9.5
DatabaseBrowser.php
Go to the documentation of this file.
1 <?php
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 
25 
31 {
39  protected ‪$expandPage;
40 
43  protected function ‪initialize()
44  {
45  parent::initialize();
46  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/BrowseDatabase');
47  }
48 
51  protected function ‪initVariables()
52  {
53  parent::initVariables();
54  $this->expandPage = GeneralUtility::_GP('expandPage');
55  }
56 
63  public function ‪processSessionData($data)
64  {
65  if ($this->expandPage !== null) {
66  $data['expandPage'] = ‪$this->expandPage;
67  $store = true;
68  } else {
69  $this->expandPage = (int)$data['expandPage'];
70  $store = false;
71  }
72  return [$data, $store];
73  }
74 
78  public function ‪render()
79  {
80  $userTsConfig = $this->‪getBackendUser()->‪getTSConfig();
81 
82  $this->‪setTemporaryDbMounts();
83  list(, , , $allowedTables) = explode('|', $this->bparams);
84 
85  // Making the browsable pagetree:
86  $pageTree = GeneralUtility::makeInstance(ElementBrowserPageTreeView::class);
87  $pageTree->setLinkParameterProvider($this);
88  $pageTree->ext_pArrPages = $allowedTables === 'pages';
89  $pageTree->ext_showNavTitle = (bool)($userTsConfig['options.']['pageTree.']['showNavTitle'] ?? false);
90  $pageTree->ext_showPageId = (bool)($userTsConfig['options.']['pageTree.']['showPageIdWithTitle'] ?? false);
91  $pageTree->ext_showPathAboveMounts = (bool)($userTsConfig['options.']['pageTree.']['showPathAboveMounts'] ?? false);
92  $pageTree->addField('nav_title');
93  $tree = $pageTree->getBrowsableTree();
94 
95  $withTree = true;
96  if ($allowedTables !== '' && $allowedTables !== '*') {
97  $tablesArr = GeneralUtility::trimExplode(',', $allowedTables, true);
98  $onlyRootLevel = true;
99  foreach ($tablesArr as $currentTable) {
100  if (isset(‪$GLOBALS['TCA'][$currentTable])) {
101  if (!isset(‪$GLOBALS['TCA'][$currentTable]['ctrl']['rootLevel']) || (int)‪$GLOBALS['TCA'][$currentTable]['ctrl']['rootLevel'] !== 1) {
102  $onlyRootLevel = false;
103  }
104  }
105  }
106  if ($onlyRootLevel) {
107  $withTree = false;
108  // page to work on is root
109  $this->expandPage = 0;
110  }
111  }
112 
113  $renderedRecordList = $this->‪renderTableRecords($allowedTables);
114 
115  $this->‪initDocumentTemplate();
116  $content = $this->doc->startPage(htmlspecialchars($this->‪getLanguageService()->getLL('recordSelector')));
117 
118  // Putting the parts together, side by side:
119  $markup = [];
120  $markup[] = '<!-- Wrapper table for folder tree / filelist: -->';
121  $markup[] = '<div class="element-browser">';
122  $markup[] = ' <div class="element-browser-panel element-browser-main">';
123  if ($withTree) {
124  $markup[] = ' <div class="element-browser-main-sidebar">';
125  $markup[] = ' <div class="element-browser-body">';
126  $markup[] = ' ' . $this->‪getTemporaryTreeMountCancelNotice();
127  $markup[] = ' ' . $tree;
128  $markup[] = ' </div>';
129  $markup[] = ' </div>';
130  }
131  $markup[] = ' <div class="element-browser-main-content">';
132  $markup[] = ' <div class="element-browser-body">';
133  $markup[] = ' ' . $this->doc->getFlashMessages();
134  $markup[] = ' ' . $renderedRecordList;
135  $markup[] = ' </div>';
136  $markup[] = ' </div>';
137  $markup[] = ' </div>';
138  $markup[] = '</div>';
139  $content .= implode('', $markup);
140 
141  // Ending page, returning content:
142  $content .= $this->doc->endPage();
143  return $this->doc->insertStylesAndJS($content);
144  }
145 
151  protected function ‪getTemporaryTreeMountCancelNotice()
152  {
153  if ((int)$this->‪getBackendUser()->getSessionData('pageTree_temporaryMountPoint') === 0) {
154  return '';
155  }
156  $link = '<p><a href="' . htmlspecialchars(GeneralUtility::linkThisScript(['setTempDBmount' => 0])) . '" class="btn btn-primary">'
157  . htmlspecialchars($this->‪getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.temporaryDBmount')) . '</a></p>';
158 
159  return $link;
160  }
161 
165  protected function ‪setTemporaryDbMounts()
166  {
167  $backendUser = $this->‪getBackendUser();
168 
169  // Clear temporary DB mounts
170  $tmpMount = GeneralUtility::_GET('setTempDBmount');
171  if (isset($tmpMount)) {
172  $backendUser->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
173  }
174 
175  $backendUser->initializeWebmountsForElementBrowser();
176  }
177 
184  protected function ‪renderTableRecords($tables)
185  {
186  $backendUser = $this->‪getBackendUser();
187  if ($this->expandPage === null || $this->expandPage < 0 || !$backendUser->isInWebMount($this->expandPage)) {
188  return '';
189  }
190  // Set array with table names to list:
191  if (trim($tables) === '*') {
192  $tablesArr = array_keys(‪$GLOBALS['TCA']);
193  } else {
194  $tablesArr = GeneralUtility::trimExplode(',', $tables, true);
195  }
196 
197  $out = '';
198  // Create the header, showing the current page for which the listing is.
199  // Includes link to the page itself, if pages are amount allowed tables.
200  $titleLen = (int)$backendUser->uc['titleLen'];
201  $mainPageRecord = ‪BackendUtility::getRecordWSOL('pages', $this->expandPage);
202  if (is_array($mainPageRecord)) {
203  $pText = htmlspecialchars(GeneralUtility::fixed_lgd_cs($mainPageRecord['title'], $titleLen));
204 
205  $out .= '<p>' . $this->iconFactory->getIconForRecord('pages', $mainPageRecord, ‪Icon::SIZE_SMALL)->render() . '&nbsp;';
206  if (in_array('pages', $tablesArr, true)) {
207  $out .= '<span data-uid="' . htmlspecialchars($mainPageRecord['uid']) . '" data-table="pages" data-title="' . htmlspecialchars($mainPageRecord['title']) . '" data-icon="">';
208  $out .= '<a href="#" data-close="0">'
209  . $this->iconFactory->getIcon('actions-add', ‪Icon::SIZE_SMALL)->render()
210  . '</a>'
211  . '<a href="#" data-close="1">'
212  . $pText
213  . '</a>';
214  $out .= '</span>';
215  } else {
216  $out .= $pText;
217  }
218  $out .= '</p>';
219  }
220 
221  $permsClause = $backendUser->getPagePermsClause(‪Permission::PAGE_SHOW);
222  $pageInfo = ‪BackendUtility::readPageAccess($this->expandPage, $permsClause);
223 
225  $dbList = GeneralUtility::makeInstance(ElementBrowserRecordList::class);
226  $dbList->setOverrideUrlParameters($this->‪getUrlParameters([]));
227  $dbList->thisScript = ‪$this->thisScript;
228  $dbList->thumbs = false;
229  $dbList->setIsEditable(false);
230  $dbList->calcPerms = $backendUser->calcPerms($pageInfo);
231  $dbList->noControlPanels = true;
232  $dbList->clickMenuEnabled = false;
233  $dbList->tableList = implode(',', $tablesArr);
234 
235  // a string like "data[pages][79][storage_pid]"
236  list($fieldPointerString) = explode('|', $this->bparams);
237  // parts like: data, pages], 79], storage_pid]
238  $fieldPointerParts = explode('[', $fieldPointerString);
239  $relatingTableName = substr($fieldPointerParts[1], 0, -1);
240  $relatingFieldName = substr($fieldPointerParts[3], 0, -1);
241  if ($relatingTableName && $relatingFieldName) {
242  $dbList->setRelatingTableAndField($relatingTableName, $relatingFieldName);
243  }
244 
245  $dbList->start(
246  $this->expandPage,
247  GeneralUtility::_GP('table'),
248  ‪MathUtility::forceIntegerInRange(GeneralUtility::_GP('pointer'), 0, 100000),
249  GeneralUtility::_GP('search_field'),
250  GeneralUtility::_GP('search_levels'),
251  GeneralUtility::_GP('showLimit')
252  );
253 
254  $dbList->setDispFields();
255  $dbList->generateList();
256 
257  $out .= $dbList->getSearchBox();
258 
259  // Add the HTML for the record list to output variable:
260  $out .= $dbList->HTMLcode;
261 
262  // Add support for fieldselectbox in singleTableMode
263  if ($dbList->table) {
264  $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Recordlist/FieldSelectBox');
265  $out .= $dbList->fieldSelectBox($dbList->table);
266  }
267 
268  return $out;
269  }
270 
274  protected function ‪getBodyTagAttributes()
275  {
276  return [
277  'data-mode' => 'db'
278  ];
279  }
280 
285  public function ‪getUrlParameters(array $values)
286  {
287  $pid = $values['pid'] ?? ‪$this->expandPage;
288  return [
289  'mode' => 'db',
290  'expandPage' => $pid,
291  'bparams' => ‪$this->bparams
292  ];
293  }
294 
299  public function ‪isCurrentlySelectedItem(array $values)
300  {
301  return false;
302  }
303 
309  public function ‪getScriptUrl()
310  {
311  return ‪$this->thisScript;
312  }
313 }
‪TYPO3\CMS\Core\Imaging\Icon\SIZE_SMALL
‪const SIZE_SMALL
Definition: Icon.php:29
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\getUrlParameters
‪string[] getUrlParameters(array $values)
Definition: DatabaseBrowser.php:284
‪TYPO3\CMS\Backend\Tree\View\ElementBrowserPageTreeView
Definition: ElementBrowserPageTreeView.php:29
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\initVariables
‪initVariables()
Definition: DatabaseBrowser.php:50
‪TYPO3\CMS\Backend\RecordList\ElementBrowserRecordList
Definition: ElementBrowserRecordList.php:26
‪TYPO3\CMS\Recordlist\Browser\ElementBrowserInterface
Definition: ElementBrowserInterface.php:18
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\render
‪string render()
Definition: DatabaseBrowser.php:77
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:25
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\$thisScript
‪string $thisScript
Definition: AbstractElementBrowser.php:45
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\getScriptUrl
‪string getScriptUrl()
Definition: DatabaseBrowser.php:308
‪TYPO3\CMS\Core\Utility\MathUtility\forceIntegerInRange
‪static int forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\getBackendUser
‪BackendUserAuthentication getBackendUser()
Definition: AbstractElementBrowser.php:174
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig($objectString=null, $config=null)
Definition: BackendUserAuthentication.php:1232
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\initialize
‪initialize()
Definition: DatabaseBrowser.php:42
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\setTemporaryDbMounts
‪setTemporaryDbMounts()
Definition: DatabaseBrowser.php:164
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:23
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\renderTableRecords
‪string renderTableRecords($tables)
Definition: DatabaseBrowser.php:183
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\$expandPage
‪int null $expandPage
Definition: DatabaseBrowser.php:38
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\isCurrentlySelectedItem
‪bool isCurrentlySelectedItem(array $values)
Definition: DatabaseBrowser.php:298
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\getTemporaryTreeMountCancelNotice
‪string getTemporaryTreeMountCancelNotice()
Definition: DatabaseBrowser.php:150
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser
Definition: AbstractElementBrowser.php:32
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\getBodyTagAttributes
‪string[] getBodyTagAttributes()
Definition: DatabaseBrowser.php:273
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\initDocumentTemplate
‪initDocumentTemplate()
Definition: AbstractElementBrowser.php:121
‪TYPO3\CMS\Core\Type\Bitmask\Permission\PAGE_SHOW
‪const PAGE_SHOW
Definition: Permission.php:32
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\getLanguageService
‪LanguageService getLanguageService()
Definition: AbstractElementBrowser.php:166
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:72
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecordWSOL
‪static array getRecordWSOL( $table, $uid, $fields=' *', $where='', $useDeleteClause=true, $unsetMovePointers=false)
Definition: BackendUtility.php:174
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser
Definition: DatabaseBrowser.php:31
‪TYPO3\CMS\Core\Utility\MathUtility
Definition: MathUtility.php:21
‪TYPO3\CMS\Recordlist\Browser\DatabaseBrowser\processSessionData
‪array[] processSessionData($data)
Definition: DatabaseBrowser.php:62
‪TYPO3\CMS\Recordlist\Browser\AbstractElementBrowser\$bparams
‪string $bparams
Definition: AbstractElementBrowser.php:71
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Recordlist\Browser
Definition: AbstractElementBrowser.php:2
‪TYPO3\CMS\Backend\Utility\BackendUtility\readPageAccess
‪static array bool readPageAccess($id, $perms_clause)
Definition: BackendUtility.php:635