[TASK] Use strict comparison for strings
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / RecordList / DatabaseRecordList.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\RecordList;
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\Module\BaseScriptClass;
18 use TYPO3\CMS\Backend\RecordList\RecordListGetTableHookInterface;
19 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
20 use TYPO3\CMS\Backend\Template\DocumentTemplate;
21 use TYPO3\CMS\Backend\Template\ModuleTemplate;
22 use TYPO3\CMS\Backend\Utility\BackendUtility;
23 use TYPO3\CMS\Core\Database\ConnectionPool;
24 use TYPO3\CMS\Core\Database\Query\QueryHelper;
25 use TYPO3\CMS\Core\Imaging\Icon;
26 use TYPO3\CMS\Core\Imaging\IconFactory;
27 use TYPO3\CMS\Core\Messaging\FlashMessage;
28 use TYPO3\CMS\Core\Messaging\FlashMessageService;
29 use TYPO3\CMS\Core\Type\Bitmask\Permission;
30 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32 use TYPO3\CMS\Frontend\Page\PageRepository;
33
34 /**
35 * Class for rendering of Web>List module
36 */
37 class DatabaseRecordList extends AbstractDatabaseRecordList
38 {
39 // *********
40 // External:
41 // *********
42
43 /**
44 * Used to indicate which tables (values in the array) that can have a
45 * create-new-record link. If the array is empty, all tables are allowed.
46 *
47 * @var string[]
48 */
49 public $allowedNewTables = [];
50
51 /**
52 * Used to indicate which tables (values in the array) that cannot have a
53 * create-new-record link. If the array is empty, all tables are allowed.
54 *
55 * @var string[]
56 */
57 public $deniedNewTables = [];
58
59 /**
60 * If TRUE, the control panel will contain links to the create-new wizards for
61 * pages and tt_content elements (normally, the link goes to just creatinga new
62 * element without the wizards!).
63 *
64 * @var bool
65 */
66 public $newWizards = false;
67
68 /**
69 * If TRUE, will disable the rendering of clipboard + control panels.
70 *
71 * @var bool
72 */
73 public $dontShowClipControlPanels = false;
74
75 /**
76 * If TRUE, will show the clipboard in the field list.
77 *
78 * @var bool
79 */
80 public $showClipboard = false;
81
82 /**
83 * If TRUE, will DISABLE all control panels in lists. (Takes precedence)
84 *
85 * @var bool
86 */
87 public $noControlPanels = false;
88
89 /**
90 * If TRUE, clickmenus will be rendered
91 *
92 * @var bool
93 */
94 public $clickMenuEnabled = true;
95
96 /**
97 * Count of record rows in view
98 *
99 * @var int
100 */
101 public $totalRowCount;
102
103 /**
104 * Space icon used for alignment
105 *
106 * @var string
107 */
108 public $spaceIcon;
109
110 /**
111 * Disable single table view
112 *
113 * @var bool
114 */
115 public $disableSingleTableView = false;
116
117 // *********
118 // Internal:
119 // *********
120
121 /**
122 * Set to the page record (see writeTop())
123 *
124 * @var string[]
125 */
126 public $pageRow = [];
127
128 /**
129 * Used to accumulate CSV lines for CSV export.
130 *
131 * @var string[]
132 */
133 protected $csvLines = [];
134
135 /**
136 * If set, the listing is returned as CSV instead.
137 *
138 * @var bool
139 */
140 public $csvOutput = false;
141
142 /**
143 * Clipboard object
144 *
145 * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
146 */
147 public $clipObj;
148
149 /**
150 * Tracking names of elements (for clipboard use)
151 *
152 * @var string[]
153 */
154 public $CBnames = [];
155
156 /**
157 * [$tablename][$uid] = number of references to this record
158 *
159 * @var int[][]
160 */
161 protected $referenceCount = [];
162
163 /**
164 * Translations of the current record
165 *
166 * @var string[]
167 */
168 public $translations;
169
170 /**
171 * select fields for the query which fetches the translations of the current
172 * record
173 *
174 * @var string
175 */
176 public $selFieldList;
177
178 /**
179 * @var mixed[]
180 */
181 public $pageinfo;
182
183 /**
184 * Injected by RecordList
185 *
186 * @var string[]
187 */
188 public $MOD_MENU;
189
190 /**
191 * If defined the records are editable
192 *
193 * @var bool
194 */
195 protected $editable = true;
196
197 /**
198 * @var IconFactory
199 */
200 protected $iconFactory;
201
202 /**
203 * Constructor
204 */
205 public function __construct()
206 {
207 parent::__construct();
208 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
209 }
210
211 /**
212 * Create the panel of buttons for submitting the form or otherwise perform
213 * operations.
214 *
215 * @return string[] All available buttons as an assoc. array
216 */
217 public function getButtons()
218 {
219 $module = $this->getModule();
220 $backendUser = $this->getBackendUserAuthentication();
221 $lang = $this->getLanguageService();
222 $buttons = [
223 'csh' => '',
224 'view' => '',
225 'edit' => '',
226 'hide_unhide' => '',
227 'move' => '',
228 'new_record' => '',
229 'paste' => '',
230 'level_up' => '',
231 'cache' => '',
232 'reload' => '',
233 'shortcut' => '',
234 'back' => '',
235 'csv' => '',
236 'export' => ''
237 ];
238 // Get users permissions for this page record:
239 $localCalcPerms = $backendUser->calcPerms($this->pageRow);
240 // CSH
241 if ((string)$this->id === '') {
242 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'list_module_noId');
243 } elseif (!$this->id) {
244 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'list_module_root');
245 } else {
246 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'list_module');
247 }
248 if (isset($this->id)) {
249 // View Exclude doktypes 254,255 Configuration:
250 // mod.web_list.noViewWithDokTypes = 254,255
251 if (isset($module->modTSconfig['properties']['noViewWithDokTypes'])) {
252 $noViewDokTypes = GeneralUtility::trimExplode(',', $module->modTSconfig['properties']['noViewWithDokTypes'], true);
253 } else {
254 //default exclusion: doktype 254 (folder), 255 (recycler)
255 $noViewDokTypes = [
256 PageRepository::DOKTYPE_SYSFOLDER,
257 PageRepository::DOKTYPE_RECYCLER
258 ];
259 }
260 if (!in_array($this->pageRow['doktype'], $noViewDokTypes)) {
261 $onClick = htmlspecialchars(BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)));
262 $buttons['view'] = '<a href="#" onclick="' . $onClick . '" title="'
263 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage')) . '">'
264 . $this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL)->render() . '</a>';
265 }
266 // New record on pages that are not locked by editlock
267 if (!$module->modTSconfig['properties']['noCreateRecordsLink'] && $this->editLockPermissions()) {
268 $onClick = htmlspecialchars('return jumpExt(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', ['id' => $this->id])) . ');');
269 $buttons['new_record'] = '<a href="#" onclick="' . $onClick . '" title="'
270 . htmlspecialchars($lang->getLL('newRecordGeneral')) . '">'
271 . $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL)->render() . '</a>';
272 }
273 // If edit permissions are set, see
274 // \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
275 if ($localCalcPerms & Permission::PAGE_EDIT && !empty($this->id) && $this->editLockPermissions() && $this->getBackendUserAuthentication()->checkLanguageAccess(0)) {
276 // Edit
277 $params = '&edit[pages][' . $this->pageRow['uid'] . ']=edit';
278 $onClick = htmlspecialchars(BackendUtility::editOnClick($params, '', -1));
279 $buttons['edit'] = '<a href="#" onclick="' . $onClick . '" title="' . htmlspecialchars($lang->getLL('editPage')) . '">'
280 . $this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL)->render()
281 . '</a>';
282 }
283 // Paste
284 if (($localCalcPerms & Permission::PAGE_NEW || $localCalcPerms & Permission::CONTENT_EDIT) && $this->editLockPermissions()) {
285 $elFromTable = $this->clipObj->elFromTable('');
286 if (!empty($elFromTable)) {
287 $confirmText = $this->clipObj->confirmMsgText('pages', $this->pageRow, 'into', $elFromTable);
288 $buttons['paste'] = '<a'
289 . ' href="' . htmlspecialchars($this->clipObj->pasteUrl('', $this->id)) . '"'
290 . ' title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
291 . ' class="t3js-modal-trigger"'
292 . ' data-severity="warning"'
293 . ' data-title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
294 . ' data-content="' . htmlspecialchars($confirmText) . '"'
295 . '>'
296 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
297 . '</a>';
298 }
299 }
300 // Cache
301 $buttons['cache'] = '<a href="' . htmlspecialchars(($this->listURL() . '&clear_cache=1')) . '" title="'
302 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clear_cache')) . '">'
303 . $this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL)->render() . '</a>';
304 if ($this->table && (!isset($module->modTSconfig['properties']['noExportRecordsLinks'])
305 || (isset($module->modTSconfig['properties']['noExportRecordsLinks'])
306 && !$module->modTSconfig['properties']['noExportRecordsLinks']))
307 ) {
308 // CSV
309 $buttons['csv'] = '<a href="' . htmlspecialchars(($this->listURL() . '&csv=1')) . '" title="'
310 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.csv')) . '">'
311 . $this->iconFactory->getIcon('actions-document-export-csv', Icon::SIZE_SMALL)->render() . '</a>';
312 // Export
313 if (ExtensionManagementUtility::isLoaded('impexp')) {
314 $url = BackendUtility::getModuleUrl('xMOD_tximpexp', ['tx_impexp[action]' => 'export']);
315 $buttons['export'] = '<a href="' . htmlspecialchars($url . '&tx_impexp[list][]='
316 . rawurlencode($this->table . ':' . $this->id)) . '" title="'
317 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:rm.export')) . '">'
318 . $this->iconFactory->getIcon('actions-document-export-t3d', Icon::SIZE_SMALL)->render() . '</a>';
319 }
320 }
321 // Reload
322 $buttons['reload'] = '<a href="' . htmlspecialchars($this->listURL()) . '" title="'
323 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.reload')) . '">'
324 . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a>';
325 // Shortcut
326 if ($backendUser->mayMakeShortcut()) {
327 $buttons['shortcut'] = $this->getDocumentTemplate()->makeShortcutIcon(
328 'id, M, imagemode, pointer, table, search_field, search_levels, showLimit, sortField, sortRev',
329 implode(',', array_keys($this->MOD_MENU)),
330 'web_list'
331 );
332 }
333 // Back
334 if ($this->returnUrl) {
335 $href = htmlspecialchars(GeneralUtility::linkThisUrl($this->returnUrl, ['id' => $this->id]));
336 $buttons['back'] = '<a href="' . $href . '" class="typo3-goBack" title="'
337 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack')) . '">'
338 . $this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL)->render() . '</a>';
339 }
340 }
341 return $buttons;
342 }
343
344 /**
345 * Create the panel of buttons for submitting the form or otherwise perform
346 * operations.
347 *
348 * @param ModuleTemplate $moduleTemplate
349 */
350 public function getDocHeaderButtons(ModuleTemplate $moduleTemplate)
351 {
352 $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
353 $module = $this->getModule();
354 $backendUser = $this->getBackendUserAuthentication();
355 $lang = $this->getLanguageService();
356 // Get users permissions for this page record:
357 $localCalcPerms = $backendUser->calcPerms($this->pageRow);
358 // CSH
359 if ((string)$this->id === '') {
360 $fieldName = 'list_module_noId';
361 } elseif (!$this->id) {
362 $fieldName = 'list_module_root';
363 } else {
364 $fieldName = 'list_module';
365 }
366 $cshButton = $buttonBar->makeHelpButton()
367 ->setModuleName('xMOD_csh_corebe')
368 ->setFieldName($fieldName);
369 $buttonBar->addButton($cshButton);
370 if (isset($this->id)) {
371 // View Exclude doktypes 254,255 Configuration:
372 // mod.web_list.noViewWithDokTypes = 254,255
373 if (isset($module->modTSconfig['properties']['noViewWithDokTypes'])) {
374 $noViewDokTypes = GeneralUtility::trimExplode(',', $module->modTSconfig['properties']['noViewWithDokTypes'], true);
375 } else {
376 //default exclusion: doktype 254 (folder), 255 (recycler)
377 $noViewDokTypes = [
378 PageRepository::DOKTYPE_SYSFOLDER,
379 PageRepository::DOKTYPE_RECYCLER
380 ];
381 }
382 // New record on pages that are not locked by editlock
383 if (!$module->modTSconfig['properties']['noCreateRecordsLink'] && $this->editLockPermissions()) {
384 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('db_new', ['id' => $this->id])) . ');';
385 $newRecordButton = $buttonBar->makeLinkButton()
386 ->setHref('#')
387 ->setOnClick($onClick)
388 ->setTitle($lang->getLL('newRecordGeneral'))
389 ->setIcon($this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL));
390 $buttonBar->addButton($newRecordButton, ButtonBar::BUTTON_POSITION_LEFT, 10);
391 }
392 if (!in_array($this->pageRow['doktype'], $noViewDokTypes)) {
393 $onClick = BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id));
394 $viewButton = $buttonBar->makeLinkButton()
395 ->setHref('#')
396 ->setOnClick($onClick)
397 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
398 ->setIcon($this->iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL));
399 $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 20);
400 }
401 // If edit permissions are set, see
402 // \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
403 if ($localCalcPerms & Permission::PAGE_EDIT && !empty($this->id) && $this->editLockPermissions()) {
404 // Edit
405 $params = '&edit[pages][' . $this->pageRow['uid'] . ']=edit';
406 $onClick = BackendUtility::editOnClick($params, '', -1);
407 $editButton = $buttonBar->makeLinkButton()
408 ->setHref('#')
409 ->setOnClick($onClick)
410 ->setTitle($lang->getLL('editPage'))
411 ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
412 $buttonBar->addButton($editButton, ButtonBar::BUTTON_POSITION_LEFT, 20);
413 }
414 // Paste
415 if ($this->showClipboard && ($localCalcPerms & Permission::PAGE_NEW || $localCalcPerms & Permission::CONTENT_EDIT) && $this->editLockPermissions()) {
416 $elFromTable = $this->clipObj->elFromTable('');
417 if (!empty($elFromTable)) {
418 $confirmMessage = $this->clipObj->confirmMsgText('pages', $this->pageRow, 'into', $elFromTable);
419 $pasteButton = $buttonBar->makeLinkButton()
420 ->setHref($this->clipObj->pasteUrl('', $this->id))
421 ->setTitle($lang->getLL('clip_paste'))
422 ->setClasses('t3js-modal-trigger')
423 ->setDataAttributes([
424 'severity' => 'warning',
425 'content' => $confirmMessage,
426 'title' => $lang->getLL('clip_paste')
427 ])
428 ->setIcon($this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL));
429 $buttonBar->addButton($pasteButton, ButtonBar::BUTTON_POSITION_LEFT, 40);
430 }
431 }
432 // Cache
433 $clearCacheButton = $buttonBar->makeLinkButton()
434 ->setHref($this->listURL() . '&clear_cache=1')
435 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
436 ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
437 $buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT);
438 if ($this->table && (!isset($module->modTSconfig['properties']['noExportRecordsLinks'])
439 || (isset($module->modTSconfig['properties']['noExportRecordsLinks'])
440 && !$module->modTSconfig['properties']['noExportRecordsLinks']))
441 ) {
442 // CSV
443 $csvButton = $buttonBar->makeLinkButton()
444 ->setHref($this->listURL() . '&csv=1')
445 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.csv'))
446 ->setIcon($this->iconFactory->getIcon('actions-document-export-csv', Icon::SIZE_SMALL));
447 $buttonBar->addButton($csvButton, ButtonBar::BUTTON_POSITION_LEFT, 40);
448 // Export
449 if (ExtensionManagementUtility::isLoaded('impexp')) {
450 $url = BackendUtility::getModuleUrl('xMOD_tximpexp', ['tx_impexp[action]' => 'export']);
451 $exportButton = $buttonBar->makeLinkButton()
452 ->setHref($url . '&tx_impexp[list][]=' . rawurlencode($this->table . ':' . $this->id))
453 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:rm.export'))
454 ->setIcon($this->iconFactory->getIcon('actions-document-export-t3d', Icon::SIZE_SMALL));
455 $buttonBar->addButton($exportButton, ButtonBar::BUTTON_POSITION_LEFT, 40);
456 }
457 }
458 // Reload
459 $reloadButton = $buttonBar->makeLinkButton()
460 ->setHref($this->listURL())
461 ->setTitle($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.reload'))
462 ->setIcon($this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
463 $buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);
464 // Shortcut
465 if ($backendUser->mayMakeShortcut()) {
466 $shortCutButton = $buttonBar->makeShortcutButton()
467 ->setModuleName('web_list')
468 ->setGetVariables([
469 'id',
470 'M',
471 'imagemode',
472 'pointer',
473 'table',
474 'search_field',
475 'search_levels',
476 'showLimit',
477 'sortField',
478 'sortRev'
479 ])
480 ->setSetVariables(array_keys($this->MOD_MENU));
481 $buttonBar->addButton($shortCutButton, ButtonBar::BUTTON_POSITION_RIGHT);
482 }
483 // Back
484 if ($this->returnUrl) {
485 $href = htmlspecialchars(GeneralUtility::linkThisUrl($this->returnUrl, ['id' => $this->id]));
486 $buttons['back'] = '<a href="' . $href . '" class="typo3-goBack" title="'
487 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.goBack')) . '">'
488 . $this->iconFactory->getIcon('actions-view-go-back', Icon::SIZE_SMALL) . '</a>';
489 }
490 }
491 }
492
493 /**
494 * Creates the listing of records from a single table
495 *
496 * @param string $table Table name
497 * @param int $id Page id
498 * @param string $rowList List of fields to show in the listing. Pseudo fields will be added including the record header.
499 * @throws \UnexpectedValueException
500 * @return string HTML table with the listing for the record.
501 */
502 public function getTable($table, $id, $rowList = '')
503 {
504 $rowListArray = GeneralUtility::trimExplode(',', $rowList, true);
505 // if no columns have been specified, show description (if configured)
506 if (!empty($GLOBALS['TCA'][$table]['ctrl']['descriptionColumn']) && empty($rowListArray)) {
507 array_push($rowListArray, $GLOBALS['TCA'][$table]['ctrl']['descriptionColumn']);
508 }
509 $backendUser = $this->getBackendUserAuthentication();
510 $lang = $this->getLanguageService();
511 // Init
512 $addWhere = '';
513 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
514 $titleCol = $GLOBALS['TCA'][$table]['ctrl']['label'];
515 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
516 $l10nEnabled = $GLOBALS['TCA'][$table]['ctrl']['languageField']
517 && $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']
518 && $table !== 'pages_language_overlay';
519 $tableCollapsed = (bool)$this->tablesCollapsed[$table];
520 // prepare space icon
521 $this->spaceIcon = '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
522 // Cleaning rowlist for duplicates and place the $titleCol as the first column always!
523 $this->fieldArray = [];
524 // title Column
525 // Add title column
526 $this->fieldArray[] = $titleCol;
527 // Control-Panel
528 if (!GeneralUtility::inList($rowList, '_CONTROL_')) {
529 $this->fieldArray[] = '_CONTROL_';
530 }
531 // Clipboard
532 if ($this->showClipboard) {
533 $this->fieldArray[] = '_CLIPBOARD_';
534 }
535 // Ref
536 if (!$this->dontShowClipControlPanels) {
537 $this->fieldArray[] = '_REF_';
538 }
539 // Path
540 if ($this->searchLevels) {
541 $this->fieldArray[] = '_PATH_';
542 }
543 // Localization
544 if ($this->localizationView && $l10nEnabled) {
545 $this->fieldArray[] = '_LOCALIZATION_';
546 $this->fieldArray[] = '_LOCALIZATION_b';
547 // Only restrict to the default language if no search request is in place
548 if ($this->searchString === '') {
549 $addWhere = (string)$queryBuilder->expr()->orX(
550 $queryBuilder->expr()->lte($GLOBALS['TCA'][$table]['ctrl']['languageField'], 0),
551 $queryBuilder->expr()->eq($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'], 0)
552 );
553 }
554 }
555 // Cleaning up:
556 $this->fieldArray = array_unique(array_merge($this->fieldArray, $rowListArray));
557 if ($this->noControlPanels) {
558 $tempArray = array_flip($this->fieldArray);
559 unset($tempArray['_CONTROL_']);
560 unset($tempArray['_CLIPBOARD_']);
561 $this->fieldArray = array_keys($tempArray);
562 }
563 // Creating the list of fields to include in the SQL query:
564 $selectFields = $this->fieldArray;
565 $selectFields[] = 'uid';
566 $selectFields[] = 'pid';
567 // adding column for thumbnails
568 if ($thumbsCol) {
569 $selectFields[] = $thumbsCol;
570 }
571 if ($table === 'pages') {
572 $selectFields[] = 'module';
573 $selectFields[] = 'extendToSubpages';
574 $selectFields[] = 'nav_hide';
575 $selectFields[] = 'doktype';
576 $selectFields[] = 'shortcut';
577 $selectFields[] = 'shortcut_mode';
578 $selectFields[] = 'mount_pid';
579 }
580 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
581 $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
582 }
583 foreach (['type', 'typeicon_column', 'editlock'] as $field) {
584 if ($GLOBALS['TCA'][$table]['ctrl'][$field]) {
585 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl'][$field];
586 }
587 }
588 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
589 $selectFields[] = 't3ver_id';
590 $selectFields[] = 't3ver_state';
591 $selectFields[] = 't3ver_wsid';
592 }
593 if ($l10nEnabled) {
594 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
595 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
596 }
597 if ($GLOBALS['TCA'][$table]['ctrl']['label_alt']) {
598 $selectFields = array_merge(
599 $selectFields,
600 GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], true)
601 );
602 }
603 // Unique list!
604 $selectFields = array_unique($selectFields);
605 $fieldListFields = $this->makeFieldList($table, 1);
606 if (empty($fieldListFields) && $GLOBALS['TYPO3_CONF_VARS']['BE']['debug']) {
607 $message = sprintf(htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:missingTcaColumnsMessage')), $table, $table);
608 $messageTitle = htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:missingTcaColumnsMessageTitle'));
609 /** @var FlashMessage $flashMessage */
610 $flashMessage = GeneralUtility::makeInstance(
611 FlashMessage::class,
612 $message,
613 $messageTitle,
614 FlashMessage::WARNING,
615 true
616 );
617 /** @var $flashMessageService FlashMessageService */
618 $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
619 /** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
620 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
621 $defaultFlashMessageQueue->enqueue($flashMessage);
622 }
623 // Making sure that the fields in the field-list ARE in the field-list from TCA!
624 $selectFields = array_intersect($selectFields, $fieldListFields);
625 // Implode it into a list of fields for the SQL-statement.
626 $selFieldList = implode(',', $selectFields);
627 $this->selFieldList = $selFieldList;
628 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'])) {
629 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['getTable'] as $classData) {
630 $hookObject = GeneralUtility::getUserObj($classData);
631 if (!$hookObject instanceof RecordListGetTableHookInterface) {
632 throw new \UnexpectedValueException($classData . ' must implement interface ' . RecordListGetTableHookInterface::class, 1195114460);
633 }
634 $hookObject->getDBlistQuery($table, $id, $addWhere, $selFieldList, $this);
635 }
636 }
637 $additionalConstraints = empty($addWhere) ? [] : [QueryHelper::stripLogicalOperatorPrefix($addWhere)];
638 $selFieldList = GeneralUtility::trimExplode(',', $selFieldList, true);
639
640 // Create the SQL query for selecting the elements in the listing:
641 // do not do paging when outputting as CSV
642 if ($this->csvOutput) {
643 $this->iLimit = 0;
644 }
645 if ($this->firstElementNumber > 2 && $this->iLimit > 0) {
646 // Get the two previous rows for sorting if displaying page > 1
647 $this->firstElementNumber = $this->firstElementNumber - 2;
648 $this->iLimit = $this->iLimit + 2;
649 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
650 $queryBuilder = $this->getQueryBuilder($table, $id, $additionalConstraints);
651 $this->firstElementNumber = $this->firstElementNumber + 2;
652 $this->iLimit = $this->iLimit - 2;
653 } else {
654 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
655 $queryBuilder = $this->getQueryBuilder($table, $id, $additionalConstraints);
656 }
657
658 // Finding the total amount of records on the page
659 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
660 $this->setTotalItems($table, $id, $additionalConstraints);
661
662 // Init:
663 $queryResult = $queryBuilder->execute();
664 $dbCount = 0;
665 $out = '';
666 $tableHeader = '';
667 $listOnlyInSingleTableMode = $this->listOnlyInSingleTableMode && !$this->table;
668 // If the count query returned any number of records, we perform the real query,
669 // selecting records.
670 if ($this->totalItems) {
671 // Fetch records only if not in single table mode
672 if ($listOnlyInSingleTableMode) {
673 $dbCount = $this->totalItems;
674 } else {
675 // Set the showLimit to the number of records when outputting as CSV
676 if ($this->csvOutput) {
677 $this->showLimit = $this->totalItems;
678 $this->iLimit = $this->totalItems;
679 }
680 $dbCount = $queryResult->rowCount();
681 }
682 }
683 // If any records was selected, render the list:
684 if ($dbCount) {
685 $tableTitle = htmlspecialchars($lang->sL($GLOBALS['TCA'][$table]['ctrl']['title']));
686 if ($tableTitle === '') {
687 $tableTitle = $table;
688 }
689 // Header line is drawn
690 $theData = [];
691 if ($this->disableSingleTableView) {
692 $theData[$titleCol] = '<span class="c-table">' . BackendUtility::wrapInHelp($table, '', $tableTitle)
693 . '</span> (<span class="t3js-table-total-items">' . $this->totalItems . '</span>)';
694 } else {
695 $icon = $this->table
696 ? '<span title="' . htmlspecialchars($lang->getLL('contractView')) . '">' . $this->iconFactory->getIcon('actions-view-table-collapse', Icon::SIZE_SMALL)->render() . '</span>'
697 : '<span title="' . htmlspecialchars($lang->getLL('expandView')) . '">' . $this->iconFactory->getIcon('actions-view-table-expand', Icon::SIZE_SMALL)->render() . '</span>';
698 $theData[$titleCol] = $this->linkWrapTable($table, $tableTitle . ' (<span class="t3js-table-total-items">' . $this->totalItems . '</span>) ' . $icon);
699 }
700 if ($listOnlyInSingleTableMode) {
701 $tableHeader .= BackendUtility::wrapInHelp($table, '', $theData[$titleCol]);
702 } else {
703 // Render collapse button if in multi table mode
704 $collapseIcon = '';
705 if (!$this->table) {
706 $href = htmlspecialchars(($this->listURL() . '&collapse[' . $table . ']=' . ($tableCollapsed ? '0' : '1')));
707 $title = $tableCollapsed
708 ? htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.expandTable'))
709 : htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.collapseTable'));
710 $icon = '<span class="collapseIcon">' . $this->iconFactory->getIcon(($tableCollapsed ? 'actions-view-list-expand' : 'actions-view-list-collapse'), Icon::SIZE_SMALL)->render() . '</span>';
711 $collapseIcon = '<a href="' . $href . '" title="' . $title . '" class="pull-right t3js-toggle-recordlist" data-table="' . htmlspecialchars($table) . '" data-toggle="collapse" data-target="#recordlist-' . htmlspecialchars($table) . '">' . $icon . '</a>';
712 }
713 $tableHeader .= $theData[$titleCol] . $collapseIcon;
714 }
715 // Render table rows only if in multi table view or if in single table view
716 $rowOutput = '';
717 if (!$listOnlyInSingleTableMode || $this->table) {
718 // Fixing an order table for sortby tables
719 $this->currentTable = [];
720 $currentIdList = [];
721 $doSort = $GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField;
722 $prevUid = 0;
723 $prevPrevUid = 0;
724 // Get first two rows and initialize prevPrevUid and prevUid if on page > 1
725 if ($this->firstElementNumber > 2 && $this->iLimit > 0) {
726 $row = $queryResult->fetch();
727 $prevPrevUid = -((int)$row['uid']);
728 $row = $queryResult->fetch();
729 $prevUid = $row['uid'];
730 }
731 $accRows = [];
732 // Accumulate rows here
733 while ($row = $queryResult->fetch()) {
734 if (!$this->isRowListingConditionFulfilled($table, $row)) {
735 continue;
736 }
737 // In offline workspace, look for alternative record:
738 BackendUtility::workspaceOL($table, $row, $backendUser->workspace, true);
739 if (is_array($row)) {
740 $accRows[] = $row;
741 $currentIdList[] = $row['uid'];
742 if ($doSort) {
743 if ($prevUid) {
744 $this->currentTable['prev'][$row['uid']] = $prevPrevUid;
745 $this->currentTable['next'][$prevUid] = '-' . $row['uid'];
746 $this->currentTable['prevUid'][$row['uid']] = $prevUid;
747 }
748 $prevPrevUid = isset($this->currentTable['prev'][$row['uid']]) ? -$prevUid : $row['pid'];
749 $prevUid = $row['uid'];
750 }
751 }
752 }
753 $this->totalRowCount = count($accRows);
754 // CSV initiated
755 if ($this->csvOutput) {
756 $this->initCSV();
757 }
758 // Render items:
759 $this->CBnames = [];
760 $this->duplicateStack = [];
761 $this->eCounter = $this->firstElementNumber;
762 $cc = 0;
763 foreach ($accRows as $row) {
764 // Render item row if counter < limit
765 if ($cc < $this->iLimit) {
766 $cc++;
767 $this->translations = false;
768 $rowOutput .= $this->renderListRow($table, $row, $cc, $titleCol, $thumbsCol);
769 // If localization view is enabled and no search happened it means that the selected
770 // records are either default or All language and here we will not select translations
771 // which point to the main record:
772 if ($this->localizationView && $l10nEnabled && $this->searchString === '') {
773 // For each available translation, render the record:
774 if (is_array($this->translations)) {
775 foreach ($this->translations as $lRow) {
776 // $lRow isn't always what we want - if record was moved we've to work with the
777 // placeholder records otherwise the list is messed up a bit
778 if ($row['_MOVE_PLH_uid'] && $row['_MOVE_PLH_pid']) {
779 $where = 't3ver_move_id="' . (int)$lRow['uid'] . '" AND pid="' . $row['_MOVE_PLH_pid']
780 . '" AND t3ver_wsid=' . $row['t3ver_wsid'] . BackendUtility::deleteClause($table);
781 $tmpRow = BackendUtility::getRecordRaw($table, $where, $selFieldList);
782 $lRow = is_array($tmpRow) ? $tmpRow : $lRow;
783 }
784 // In offline workspace, look for alternative record:
785 BackendUtility::workspaceOL($table, $lRow, $backendUser->workspace, true);
786 if (is_array($lRow) && $backendUser->checkLanguageAccess($lRow[$GLOBALS['TCA'][$table]['ctrl']['languageField']])) {
787 $currentIdList[] = $lRow['uid'];
788 $rowOutput .= $this->renderListRow($table, $lRow, $cc, $titleCol, $thumbsCol, 18);
789 }
790 }
791 }
792 }
793 }
794 // Counter of total rows incremented:
795 $this->eCounter++;
796 }
797 // Record navigation is added to the beginning and end of the table if in single
798 // table mode
799 if ($this->table) {
800 $rowOutput = $this->renderListNavigation('top') . $rowOutput . $this->renderListNavigation('bottom');
801 } else {
802 // Show that there are more records than shown
803 if ($this->totalItems > $this->itemsLimitPerTable) {
804 $countOnFirstPage = $this->totalItems > $this->itemsLimitSingleTable ? $this->itemsLimitSingleTable : $this->totalItems;
805 $hasMore = $this->totalItems > $this->itemsLimitSingleTable;
806 $colspan = $this->showIcon ? count($this->fieldArray) + 1 : count($this->fieldArray);
807 $rowOutput .= '<tr><td colspan="' . $colspan . '">
808 <a href="' . htmlspecialchars(($this->listURL() . '&table=' . rawurlencode($table))) . '" class="btn btn-default">'
809 . '<span class="t3-icon fa fa-chevron-down"></span> <i>[1 - ' . $countOnFirstPage . ($hasMore ? '+' : '') . ']</i></a>
810 </td></tr>';
811 }
812 }
813 // The header row for the table is now created:
814 $out .= $this->renderListHeader($table, $currentIdList);
815 }
816
817 $collapseClass = $tableCollapsed && !$this->table ? 'collapse' : 'collapse in';
818 $dataState = $tableCollapsed && !$this->table ? 'collapsed' : 'expanded';
819
820 // The list of records is added after the header:
821 $out .= $rowOutput;
822 // ... and it is all wrapped in a table:
823 $out = '
824
825
826
827 <!--
828 DB listing of elements: "' . htmlspecialchars($table) . '"
829 -->
830 <div class="panel panel-space panel-default recordlist">
831 <div class="panel-heading">
832 ' . $tableHeader . '
833 </div>
834 <div class="' . $collapseClass . '" data-state="' . $dataState . '" id="recordlist-' . htmlspecialchars($table) . '">
835 <div class="table-fit">
836 <table data-table="' . htmlspecialchars($table) . '" class="table table-striped table-hover' . ($listOnlyInSingleTableMode ? ' typo3-dblist-overview' : '') . '">
837 ' . $out . '
838 </table>
839 </div>
840 </div>
841 </div>
842 ';
843 // Output csv if...
844 // This ends the page with exit.
845 if ($this->csvOutput) {
846 $this->outputCSV($table);
847 }
848 }
849 // Return content:
850 return $out;
851 }
852
853 /**
854 * Check if all row listing conditions are fulfilled.
855 *
856 * This function serves as a dummy method to be overriden in extending classes.
857 *
858 * @param string $table Table name
859 * @param string[] $row Record
860 * @return bool True, if all conditions are fulfilled.
861 */
862 protected function isRowListingConditionFulfilled($table, $row)
863 {
864 return true;
865 }
866
867 /**
868 * Rendering a single row for the list
869 *
870 * @param string $table Table name
871 * @param mixed[] $row Current record
872 * @param int $cc Counter, counting for each time an element is rendered (used for alternating colors)
873 * @param string $titleCol Table field (column) where header value is found
874 * @param string $thumbsCol Table field (column) where (possible) thumbnails can be found
875 * @param int $indent Indent from left.
876 * @return string Table row for the element
877 * @access private
878 * @see getTable()
879 */
880 public function renderListRow($table, $row, $cc, $titleCol, $thumbsCol, $indent = 0)
881 {
882 if (!is_array($row)) {
883 return '';
884 }
885 $rowOutput = '';
886 $id_orig = null;
887 // If in search mode, make sure the preview will show the correct page
888 if ((string)$this->searchString !== '') {
889 $id_orig = $this->id;
890 $this->id = $row['pid'];
891 }
892 // Add special classes for first and last row
893 $rowSpecial = '';
894 if ($cc == 1 && $indent == 0) {
895 $rowSpecial .= ' firstcol';
896 }
897 if ($cc == $this->totalRowCount || $cc == $this->iLimit) {
898 $rowSpecial .= ' lastcol';
899 }
900
901 $row_bgColor = ' class="' . $rowSpecial . '"';
902
903 // Overriding with versions background color if any:
904 $row_bgColor = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : $row_bgColor;
905 // Incr. counter.
906 $this->counter++;
907 // The icon with link
908 $toolTip = BackendUtility::getRecordToolTip($row, $table);
909 $additionalStyle = $indent ? ' style="margin-left: ' . $indent . 'px;"' : '';
910 $iconImg = '<span ' . $toolTip . ' ' . $additionalStyle . '>'
911 . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render()
912 . '</span>';
913 $theIcon = $this->clickMenuEnabled ? BackendUtility::wrapClickMenuOnIcon($iconImg, $table, $row['uid']) : $iconImg;
914 // Preparing and getting the data-array
915 $theData = [];
916 $localizationMarkerClass = '';
917 foreach ($this->fieldArray as $fCol) {
918 if ($fCol == $titleCol) {
919 $recTitle = BackendUtility::getRecordTitle($table, $row, false, true);
920 $warning = '';
921 // If the record is edit-locked by another user, we will show a little warning sign:
922 $lockInfo = BackendUtility::isRecordLocked($table, $row['uid']);
923 if ($lockInfo) {
924 $warning = '<span data-toggle="tooltip" data-placement="right" data-title="' . htmlspecialchars($lockInfo['msg']) . '">'
925 . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</span>';
926 }
927 $theData[$fCol] = $theData['__label'] = $warning . $this->linkWrapItems($table, $row['uid'], $recTitle, $row);
928 // Render thumbnails, if:
929 // - a thumbnail column exists
930 // - there is content in it
931 // - the thumbnail column is visible for the current type
932 $type = 0;
933 if (isset($GLOBALS['TCA'][$table]['ctrl']['type'])) {
934 $typeColumn = $GLOBALS['TCA'][$table]['ctrl']['type'];
935 $type = $row[$typeColumn];
936 }
937 // If current type doesn't exist, set it to 0 (or to 1 for historical reasons,
938 // if 0 doesn't exist)
939 if (!isset($GLOBALS['TCA'][$table]['types'][$type])) {
940 $type = isset($GLOBALS['TCA'][$table]['types'][0]) ? 0 : 1;
941 }
942 $visibleColumns = $GLOBALS['TCA'][$table]['types'][$type]['showitem'];
943
944 if ($this->thumbs &&
945 trim($row[$thumbsCol]) &&
946 preg_match('/(^|(.*(;|,)?))' . $thumbsCol . '(((;|,).*)|$)/', $visibleColumns) === 1
947 ) {
948 $thumbCode = '<br />' . $this->thumbCode($row, $table, $thumbsCol);
949 $theData[$fCol] .= $thumbCode;
950 $theData['__label'] .= $thumbCode;
951 }
952 if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
953 && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] != 0
954 && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0
955 ) {
956 // It's a translated record with a language parent
957 $localizationMarkerClass = ' localization';
958 }
959 } elseif ($fCol === 'pid') {
960 $theData[$fCol] = $row[$fCol];
961 } elseif ($fCol === '_PATH_') {
962 $theData[$fCol] = $this->recPath($row['pid']);
963 } elseif ($fCol === '_REF_') {
964 $theData[$fCol] = $this->createReferenceHtml($table, $row['uid']);
965 } elseif ($fCol === '_CONTROL_') {
966 $theData[$fCol] = $this->makeControl($table, $row);
967 } elseif ($fCol === '_CLIPBOARD_') {
968 $theData[$fCol] = $this->makeClip($table, $row);
969 } elseif ($fCol === '_LOCALIZATION_') {
970 list($lC1, $lC2) = $this->makeLocalizationPanel($table, $row);
971 $theData[$fCol] = $lC1;
972 $theData[$fCol . 'b'] = '<div class="btn-group">' . $lC2 . '</div>';
973 } elseif ($fCol === '_LOCALIZATION_b') {
974 // deliberately empty
975 } else {
976 $pageId = $table === 'pages' ? $row['uid'] : $row['pid'];
977 $tmpProc = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 100, $row['uid'], true, $pageId);
978 $theData[$fCol] = $this->linkUrlMail(htmlspecialchars($tmpProc), $row[$fCol]);
979 if ($this->csvOutput) {
980 $row[$fCol] = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 0, $row['uid']);
981 }
982 }
983 }
984 // Reset the ID if it was overwritten
985 if ((string)$this->searchString !== '') {
986 $this->id = $id_orig;
987 }
988 // Add row to CSV list:
989 if ($this->csvOutput) {
990 $this->addToCSV($row);
991 }
992 // Add classes to table cells
993 $this->addElement_tdCssClass[$titleCol] = 'col-title col-responsive' . $localizationMarkerClass;
994 $this->addElement_tdCssClass['__label'] = $this->addElement_tdCssClass[$titleCol];
995 $this->addElement_tdCssClass['_CONTROL_'] = 'col-control';
996 if ($this->getModule()->MOD_SETTINGS['clipBoard']) {
997 $this->addElement_tdCssClass['_CLIPBOARD_'] = 'col-clipboard';
998 }
999 $this->addElement_tdCssClass['_PATH_'] = 'col-path';
1000 $this->addElement_tdCssClass['_LOCALIZATION_'] = 'col-localizationa';
1001 $this->addElement_tdCssClass['_LOCALIZATION_b'] = 'col-localizationb';
1002 // Create element in table cells:
1003 $theData['uid'] = $row['uid'];
1004 if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
1005 && isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'])
1006 && $table !== 'pages_language_overlay'
1007 ) {
1008 $theData['_l10nparent_'] = $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
1009 }
1010 $rowOutput .= $this->addElement(1, $theIcon, $theData, $row_bgColor);
1011 // Finally, return table row element:
1012 return $rowOutput;
1013 }
1014
1015 /**
1016 * Gets the number of records referencing the record with the UID $uid in
1017 * the table $tableName.
1018 *
1019 * @param string $tableName
1020 * @param int $uid
1021 * @return int The number of references to record $uid in table
1022 */
1023 protected function getReferenceCount($tableName, $uid)
1024 {
1025 if (!isset($this->referenceCount[$tableName][$uid])) {
1026 $numberOfReferences = GeneralUtility::makeInstance(ConnectionPool::class)
1027 ->getConnectionForTable('sys_refindex')
1028 ->count(
1029 '*',
1030 'sys_refindex',
1031 [
1032 'ref_table' => $tableName,
1033 'ref_uid' => (int)$uid,
1034 'deleted' => 0
1035 ]
1036 );
1037 $this->referenceCount[$tableName][$uid] = $numberOfReferences;
1038 }
1039 return $this->referenceCount[$tableName][$uid];
1040 }
1041
1042 /**
1043 * Rendering the header row for a table
1044 *
1045 * @param string $table Table name
1046 * @param int[] $currentIdList Array of the currently displayed uids of the table
1047 * @throws \UnexpectedValueException
1048 * @return string Header table row
1049 * @access private
1050 * @see getTable()
1051 */
1052 public function renderListHeader($table, $currentIdList)
1053 {
1054 $lang = $this->getLanguageService();
1055 // Init:
1056 $theData = [];
1057 $icon = '';
1058 // Traverse the fields:
1059 foreach ($this->fieldArray as $fCol) {
1060 // Calculate users permissions to edit records in the table:
1061 $permsEdit = $this->calcPerms & ($table === 'pages' ? 2 : 16) && $this->overlayEditLockPermissions($table);
1062 switch ((string)$fCol) {
1063 case '_PATH_':
1064 // Path
1065 $theData[$fCol] = '<i>[' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels._PATH_')) . ']</i>';
1066 break;
1067 case '_REF_':
1068 // References
1069 $theData[$fCol] = '<i>[' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_file_list.xlf:c__REF_')) . ']</i>';
1070 break;
1071 case '_LOCALIZATION_':
1072 // Path
1073 $theData[$fCol] = '<i>[' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels._LOCALIZATION_')) . ']</i>';
1074 break;
1075 case '_LOCALIZATION_b':
1076 // Path
1077 $theData[$fCol] = htmlspecialchars($lang->getLL('Localize'));
1078 break;
1079 case '_CLIPBOARD_':
1080 if (!$this->getModule()->MOD_SETTINGS['clipBoard']) {
1081 break;
1082 }
1083 // Clipboard:
1084 $cells = [];
1085 // If there are elements on the clipboard for this table, and the parent page is not locked by editlock
1086 // then display the "paste into" icon:
1087 $elFromTable = $this->clipObj->elFromTable($table);
1088 if (!empty($elFromTable) && $this->overlayEditLockPermissions($table)) {
1089 $href = htmlspecialchars($this->clipObj->pasteUrl($table, $this->id));
1090 $confirmMessage = $this->clipObj->confirmMsgText('pages', $this->pageRow, 'into', $elFromTable);
1091 $cells['pasteAfter'] = '<a class="btn btn-default t3js-modal-trigger"'
1092 . ' href="' . $href . '"'
1093 . ' title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
1094 . ' data-title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
1095 . ' data-content="' . htmlspecialchars($confirmMessage) . '"'
1096 . ' data-severity="warning">'
1097 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
1098 . '</a>';
1099 }
1100 // If the numeric clipboard pads are enabled, display the control icons for that:
1101 if ($this->clipObj->current !== 'normal') {
1102 // The "select" link:
1103 $spriteIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render();
1104 $cells['copyMarked'] = $this->linkClipboardHeaderIcon($spriteIcon, $table, 'setCB', '', $lang->getLL('clip_selectMarked'));
1105 // The "edit marked" link:
1106 $editIdList = implode(',', $currentIdList);
1107 $editIdList = '\'+editList(' . GeneralUtility::quoteJSvalue($table) . ',' . GeneralUtility::quoteJSvalue($editIdList) . ')+\'';
1108 $params = 'edit[' . $table . '][' . $editIdList . ']=edit';
1109 $onClick = BackendUtility::editOnClick('', '', -1);
1110 $onClickArray = explode('?', $onClick, 2);
1111 $lastElement = array_pop($onClickArray);
1112 array_push($onClickArray, $params . '&' . $lastElement);
1113 $onClick = implode('?', $onClickArray);
1114 $cells['edit'] = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
1115 . htmlspecialchars($lang->getLL('clip_editMarked')) . '">'
1116 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1117 // The "Delete marked" link:
1118 $cells['delete'] = $this->linkClipboardHeaderIcon(
1119 $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(),
1120 $table,
1121 'delete',
1122 sprintf($lang->getLL('clip_deleteMarkedWarning'), $lang->sL($GLOBALS['TCA'][$table]['ctrl']['title'])),
1123 $lang->getLL('clip_deleteMarked')
1124 );
1125 // The "Select all" link:
1126 $onClick = htmlspecialchars(('checkOffCB(' . GeneralUtility::quoteJSvalue(implode(',', $this->CBnames)) . ', this); return false;'));
1127 $cells['markAll'] = '<a class="btn btn-default" rel="" href="#" onclick="' . $onClick . '" title="'
1128 . htmlspecialchars($lang->getLL('clip_markRecords')) . '">'
1129 . $this->iconFactory->getIcon('actions-document-select', Icon::SIZE_SMALL)->render() . '</a>';
1130 } else {
1131 $cells['empty'] = '';
1132 }
1133 /**
1134 * @hook renderListHeaderActions: Allows to change the clipboard icons of the Web>List table headers
1135 * @usage Above each listed table in Web>List a header row is shown.
1136 * This hook allows to modify the icons responsible for the clipboard functions
1137 * (shown above the clipboard checkboxes when a clipboard other than "Normal" is selected),
1138 * or other "Action" functions which perform operations on the listed records.
1139 */
1140 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1141 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1142 $hookObject = GeneralUtility::getUserObj($classData);
1143 if (!$hookObject instanceof RecordListHookInterface) {
1144 throw new \UnexpectedValueException($classData . ' must implement interface ' . RecordListHookInterface::class, 1195567850);
1145 }
1146 $cells = $hookObject->renderListHeaderActions($table, $currentIdList, $cells, $this);
1147 }
1148 }
1149 $theData[$fCol] = '';
1150 if (isset($cells['edit']) && isset($cells['delete'])) {
1151 $theData[$fCol] .= '<div class="btn-group" role="group">' . $cells['edit'] . $cells['delete'] . '</div>';
1152 unset($cells['edit'], $cells['delete']);
1153 }
1154 $theData[$fCol] .= '<div class="btn-group" role="group">' . implode('', $cells) . '</div>';
1155 break;
1156 case '_CONTROL_':
1157 // Control panel:
1158 if ($this->isEditable($table)) {
1159 // If new records can be created on this page, add links:
1160 $permsAdditional = ($table === 'pages' ? 8 : 16);
1161 if ($this->calcPerms & $permsAdditional && $this->showNewRecLink($table)) {
1162 $spriteIcon = $table === 'pages'
1163 ? $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)
1164 : $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL);
1165 if ($table === 'tt_content' && $this->newWizards) {
1166 // If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead:
1167 $tmpTSc = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod');
1168 $newContentElementWizard = isset($tmpTSc['properties']['newContentElementWizard.']['override'])
1169 ? $tmpTSc['properties']['newContentElementWizard.']['override']
1170 : 'new_content_element';
1171 $newContentWizScriptPath = BackendUtility::getModuleUrl($newContentElementWizard, ['id' => $this->id]);
1172
1173 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($newContentWizScriptPath) . ');';
1174 $icon = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
1175 . htmlspecialchars($lang->getLL('new')) . '">' . $spriteIcon->render() . '</a>';
1176 } elseif ($table === 'pages' && $this->newWizards) {
1177 $parameters = ['id' => $this->id, 'pagesOnly' => 1, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')];
1178 $href = BackendUtility::getModuleUrl('db_new', $parameters);
1179 $icon = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="' . htmlspecialchars($lang->getLL('new')) . '">'
1180 . $spriteIcon->render() . '</a>';
1181 } else {
1182 $params = '&edit[' . $table . '][' . $this->id . ']=new';
1183 if ($table === 'pages_language_overlay') {
1184 $params .= '&overrideVals[pages_language_overlay][doktype]=' . (int)$this->pageRow['doktype'];
1185 }
1186 $icon = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1187 . '" title="' . htmlspecialchars($lang->getLL('new')) . '">' . $spriteIcon->render() . '</a>';
1188 }
1189 }
1190 // If the table can be edited, add link for editing ALL SHOWN fields for all listed records:
1191 if ($permsEdit && $this->table && is_array($currentIdList)) {
1192 $editIdList = implode(',', $currentIdList);
1193 if ($this->clipNumPane()) {
1194 $editIdList = '\'+editList(' . GeneralUtility::quoteJSvalue($table) . ',' . GeneralUtility::quoteJSvalue($editIdList) . ')+\'';
1195 }
1196 $params = 'edit[' . $table . '][' . $editIdList . ']=edit&columnsOnly=' . implode(',', $this->fieldArray);
1197 // we need to build this uri differently, otherwise GeneralUtility::quoteJSvalue messes up the edit list function
1198 $onClick = BackendUtility::editOnClick('', '', -1);
1199 $onClickArray = explode('?', $onClick, 2);
1200 $lastElement = array_pop($onClickArray);
1201 array_push($onClickArray, $params . '&' . $lastElement);
1202 $onClick = implode('?', $onClickArray);
1203 $icon .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick)
1204 . '" title="' . htmlspecialchars($lang->getLL('editShownColumns')) . '">'
1205 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1206 $icon = '<div class="btn-group" role="group">' . $icon . '</div>';
1207 }
1208 // Add an empty entry, so column count fits again after moving this into $icon
1209 $theData[$fCol] = '&nbsp;';
1210 }
1211 break;
1212 default:
1213 // Regular fields header:
1214 $theData[$fCol] = '';
1215
1216 // Check if $fCol is really a field and get the label and remove the colons
1217 // at the end
1218 $sortLabel = BackendUtility::getItemLabel($table, $fCol);
1219 if ($sortLabel !== null) {
1220 $sortLabel = htmlspecialchars($lang->sL($sortLabel));
1221 $sortLabel = rtrim(trim($sortLabel), ':');
1222 } else {
1223 // No TCA field, only output the $fCol variable with square brackets []
1224 $sortLabel = htmlspecialchars($fCol);
1225 $sortLabel = '<i>[' . rtrim(trim($sortLabel), ':') . ']</i>';
1226 }
1227
1228 if ($this->table && is_array($currentIdList)) {
1229 // If the numeric clipboard pads are selected, show duplicate sorting link:
1230 if ($this->clipNumPane()) {
1231 $theData[$fCol] .= '<a class="btn btn-default" href="' . htmlspecialchars($this->listURL('', '-1') . '&duplicateField=' . $fCol)
1232 . '" title="' . htmlspecialchars($lang->getLL('clip_duplicates')) . '">'
1233 . $this->iconFactory->getIcon('actions-document-duplicates-select', Icon::SIZE_SMALL)->render() . '</a>';
1234 }
1235 // If the table can be edited, add link for editing THIS field for all
1236 // listed records:
1237 if ($this->isEditable($table) && $permsEdit && $GLOBALS['TCA'][$table]['columns'][$fCol]) {
1238 $editIdList = implode(',', $currentIdList);
1239 if ($this->clipNumPane()) {
1240 $editIdList = '\'+editList(' . GeneralUtility::quoteJSvalue($table) . ',' . GeneralUtility::quoteJSvalue($editIdList) . ')+\'';
1241 }
1242 $params = 'edit[' . $table . '][' . $editIdList . ']=edit&columnsOnly=' . $fCol;
1243 // we need to build this uri differently, otherwise GeneralUtility::quoteJSvalue messes up the edit list function
1244 $onClick = BackendUtility::editOnClick('', '', -1);
1245 $onClickArray = explode('?', $onClick, 2);
1246 $lastElement = array_pop($onClickArray);
1247 array_push($onClickArray, $params . '&' . $lastElement);
1248 $onClick = implode('?', $onClickArray);
1249 $iTitle = sprintf($lang->getLL('editThisColumn'), $sortLabel);
1250 $theData[$fCol] .= '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick)
1251 . '" title="' . htmlspecialchars($iTitle) . '">'
1252 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1253 }
1254 if (strlen($theData[$fCol]) > 0) {
1255 $theData[$fCol] = '<div class="btn-group" role="group">' . $theData[$fCol] . '</div> ';
1256 }
1257 }
1258 $theData[$fCol] .= $this->addSortLink($sortLabel, $fCol, $table);
1259 }
1260 }
1261 /**
1262 * @hook renderListHeader: Allows to change the contents of columns/cells of the Web>List table headers
1263 * @usage Above each listed table in Web>List a header row is shown.
1264 * Containing the labels of all shown fields and additional icons to create new records for this
1265 * table or perform special clipboard tasks like mark and copy all listed records to clipboard, etc.
1266 */
1267 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1268 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1269 $hookObject = GeneralUtility::getUserObj($classData);
1270 if (!$hookObject instanceof RecordListHookInterface) {
1271 throw new \UnexpectedValueException($classData . ' must implement interface ' . RecordListHookInterface::class, 1195567855);
1272 }
1273 $theData = $hookObject->renderListHeader($table, $currentIdList, $theData, $this);
1274 }
1275 }
1276
1277 // Create and return header table row:
1278 return '<thead>' . $this->addElement(1, $icon, $theData, '', '', '', 'th') . '</thead>';
1279 }
1280
1281 /**
1282 * Get pointer for first element on the page
1283 *
1284 * @param int $page Page number starting with 1
1285 * @return int Pointer to first element on the page (starting with 0)
1286 */
1287 protected function getPointerForPage($page)
1288 {
1289 return ($page - 1) * $this->iLimit;
1290 }
1291
1292 /**
1293 * Creates a page browser for tables with many records
1294 *
1295 * @param string $renderPart Distinguish between 'top' and 'bottom' part of the navigation (above or below the records)
1296 * @return string Navigation HTML
1297 */
1298 protected function renderListNavigation($renderPart = 'top')
1299 {
1300 $totalPages = ceil($this->totalItems / $this->iLimit);
1301 // Show page selector if not all records fit into one page
1302 if ($totalPages <= 1) {
1303 return '';
1304 }
1305 $content = '';
1306 $listURL = $this->listURL('', $this->table);
1307 // 1 = first page
1308 // 0 = first element
1309 $currentPage = floor($this->firstElementNumber / $this->iLimit) + 1;
1310 // Compile first, previous, next, last and refresh buttons
1311 if ($currentPage > 1) {
1312 $labelFirst = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:first'));
1313 $labelPrevious = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:previous'));
1314 $first = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage(1) . '" title="' . $labelFirst . '">'
1315 . $this->iconFactory->getIcon('actions-view-paging-first', Icon::SIZE_SMALL)->render() . '</a></li>';
1316 $previous = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage - 1) . '" title="' . $labelPrevious . '">'
1317 . $this->iconFactory->getIcon('actions-view-paging-previous', Icon::SIZE_SMALL)->render() . '</a></li>';
1318 } else {
1319 $first = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-first', Icon::SIZE_SMALL)->render() . '</span></li>';
1320 $previous = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-previous', Icon::SIZE_SMALL)->render() . '</span></li>';
1321 }
1322 if ($currentPage < $totalPages) {
1323 $labelNext = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:next'));
1324 $labelLast = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:last'));
1325 $next = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage + 1) . '" title="' . $labelNext . '">'
1326 . $this->iconFactory->getIcon('actions-view-paging-next', Icon::SIZE_SMALL)->render() . '</a></li>';
1327 $last = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($totalPages) . '" title="' . $labelLast . '">'
1328 . $this->iconFactory->getIcon('actions-view-paging-last', Icon::SIZE_SMALL)->render() . '</a></li>';
1329 } else {
1330 $next = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-next', Icon::SIZE_SMALL)->render() . '</span></li>';
1331 $last = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-last', Icon::SIZE_SMALL)->render() . '</span></li>';
1332 }
1333 $reload = '<li><a href="#" onclick="document.dblistForm.action=' . GeneralUtility::quoteJSvalue($listURL
1334 . '&pointer=') . '+calculatePointer(document.getElementById(' . GeneralUtility::quoteJSvalue('jumpPage-' . $renderPart)
1335 . ').value); document.dblistForm.submit(); return true;" title="'
1336 . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:reload')) . '">'
1337 . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a></li>';
1338 if ($renderPart === 'top') {
1339 // Add js to traverse a page select input to a pointer value
1340 $content = '
1341 <script type="text/javascript">
1342 /*<![CDATA[*/
1343 function calculatePointer(page) {
1344 if (page > ' . $totalPages . ') {
1345 page = ' . $totalPages . ';
1346 }
1347 if (page < 1) {
1348 page = 1;
1349 }
1350 return (page - 1) * ' . $this->iLimit . ';
1351 }
1352 /*]]>*/
1353 </script>
1354 ';
1355 }
1356 $pageNumberInput = '
1357 <input type="number" min="1" max="' . $totalPages . '" value="' . $currentPage . '" size="3" class="form-control input-sm paginator-input" id="jumpPage-' . $renderPart . '" name="jumpPage-'
1358 . $renderPart . '" onkeyup="if (event.keyCode == 13) { document.dblistForm.action=' . GeneralUtility::quoteJSvalue($listURL
1359 . '&pointer=') . '+calculatePointer(this.value); document.dblistForm.submit(); } return true;" />
1360 ';
1361 $pageIndicatorText = sprintf(
1362 $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:pageIndicator'),
1363 $pageNumberInput,
1364 $totalPages
1365 );
1366 $pageIndicator = '<li><span>' . $pageIndicatorText . '</span></li>';
1367 if ($this->totalItems > $this->firstElementNumber + $this->iLimit) {
1368 $lastElementNumber = $this->firstElementNumber + $this->iLimit;
1369 } else {
1370 $lastElementNumber = $this->totalItems;
1371 }
1372 $rangeIndicator = '<li><span>' . sprintf($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:rangeIndicator'), ($this->firstElementNumber + 1), $lastElementNumber) . '</span></li>';
1373
1374 $titleColumn = $this->fieldArray[0];
1375 $data = [
1376 $titleColumn => $content . '
1377 <nav class="pagination-wrap">
1378 <ul class="pagination pagination-block">
1379 ' . $first . '
1380 ' . $previous . '
1381 ' . $rangeIndicator . '
1382 ' . $pageIndicator . '
1383 ' . $next . '
1384 ' . $last . '
1385 ' . $reload . '
1386 </ul>
1387 </nav>
1388 '
1389 ];
1390 return $this->addElement(1, '', $data);
1391 }
1392
1393 /*********************************
1394 *
1395 * Rendering of various elements
1396 *
1397 *********************************/
1398
1399 /**
1400 * Creates the control panel for a single record in the listing.
1401 *
1402 * @param string $table The table
1403 * @param mixed[] $row The record for which to make the control panel.
1404 * @throws \UnexpectedValueException
1405 * @return string HTML table with the control panel (unless disabled)
1406 */
1407 public function makeControl($table, $row)
1408 {
1409 $module = $this->getModule();
1410 $rowUid = $row['uid'];
1411 if (ExtensionManagementUtility::isLoaded('version') && isset($row['_ORIG_uid'])) {
1412 $rowUid = $row['_ORIG_uid'];
1413 }
1414 $cells = [
1415 'primary' => [],
1416 'secondary' => []
1417 ];
1418 // If the listed table is 'pages' we have to request the permission settings for each page:
1419 $localCalcPerms = 0;
1420 if ($table === 'pages') {
1421 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $row['uid']));
1422 }
1423 $permsEdit = $table === 'pages'
1424 && $this->getBackendUserAuthentication()->checkLanguageAccess(0)
1425 && $localCalcPerms & Permission::PAGE_EDIT
1426 || $table !== 'pages'
1427 && $this->calcPerms & Permission::CONTENT_EDIT
1428 && $this->getBackendUserAuthentication()->recordEditAccessInternals($table, $row);
1429 $permsEdit = $this->overlayEditLockPermissions($table, $row, $permsEdit);
1430 // "Show" link (only pages and tt_content elements)
1431 if ($table === 'pages' || $table === 'tt_content') {
1432 $viewAction = '<a class="btn btn-default" href="#" onclick="'
1433 . htmlspecialchars(
1434 BackendUtility::viewOnClick(
1435 ($table === 'tt_content' ? $this->id : $row['uid']),
1436 '',
1437 '',
1438 ($table === 'tt_content' ? '#' . $row['uid'] : '')
1439 )
1440 ) . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage')) . '">'
1441 . $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>';
1442 $this->addActionToCellGroup($cells, $viewAction, 'view');
1443 }
1444 // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
1445 if ($permsEdit) {
1446 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
1447 $iconIdentifier = 'actions-open';
1448 if ($table === 'pages') {
1449 $iconIdentifier = 'actions-page-open';
1450 }
1451 $overlayIdentifier = !$this->isEditable($table) ? 'overlay-readonly' : null;
1452 $editAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1453 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">' . $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL, $overlayIdentifier)->render() . '</a>';
1454 } else {
1455 $editAction = $this->spaceIcon;
1456 }
1457 $this->addActionToCellGroup($cells, $editAction, 'edit');
1458 // "Info": (All records)
1459 $onClick = 'top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', ' . (int)$row['uid'] . '); return false;';
1460 $viewBigAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('showInfo')) . '">'
1461 . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>';
1462 $this->addActionToCellGroup($cells, $viewBigAction, 'viewBig');
1463 // "Move" wizard link for pages/tt_content elements:
1464 if ($permsEdit && ($table === 'tt_content' || $table === 'pages')) {
1465 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('move_element') . '&table=' . $table . '&uid=' . $row['uid']) . ');';
1466 $linkTitleLL = htmlspecialchars($this->getLanguageService()->getLL('move_' . ($table === 'tt_content' ? 'record' : 'page')));
1467 $icon = ($table === 'pages' ? $this->iconFactory->getIcon('actions-page-move', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL));
1468 $moveAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $linkTitleLL . '">' . $icon->render() . '</a>';
1469 $this->addActionToCellGroup($cells, $moveAction, 'move');
1470 }
1471 // If the table is NOT a read-only table, then show these links:
1472 if ($this->isEditable($table)) {
1473 // "Revert" link (history/undo)
1474 $moduleUrl = BackendUtility::getModuleUrl('record_history', ['element' => $table . ':' . $row['uid']]);
1475 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($moduleUrl) . ',\'#latest\');';
1476 $historyAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
1477 . htmlspecialchars($this->getLanguageService()->getLL('history')) . '">'
1478 . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . '</a>';
1479 $this->addActionToCellGroup($cells, $historyAction, 'history');
1480 // Versioning:
1481 if (ExtensionManagementUtility::isLoaded('version') && !ExtensionManagementUtility::isLoaded('workspaces')) {
1482 $vers = BackendUtility::selectVersionsOfRecord($table, $row['uid'], 'uid', $this->getBackendUserAuthentication()->workspace, false, $row);
1483 // If table can be versionized.
1484 if (is_array($vers)) {
1485 $href = BackendUtility::getModuleUrl('web_txversionM1', [
1486 'table' => $table, 'uid' => $row['uid']
1487 ]);
1488 $versionAction = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="'
1489 . htmlspecialchars($this->getLanguageService()->getLL('displayVersions')) . '">'
1490 . $this->iconFactory->getIcon('actions-version-page-open', Icon::SIZE_SMALL)->render() . '</a>';
1491 $this->addActionToCellGroup($cells, $versionAction, 'version');
1492 }
1493 }
1494 // "Edit Perms" link:
1495 if ($table === 'pages' && $this->getBackendUserAuthentication()->check('modules', 'system_BeuserTxPermission') && ExtensionManagementUtility::isLoaded('beuser')) {
1496 $href = BackendUtility::getModuleUrl('system_BeuserTxPermission') . '&id=' . $row['uid'] . '&returnId=' . $row['uid'] . '&tx_beuser_system_beusertxpermission[action]=edit';
1497 $permsAction = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="'
1498 . htmlspecialchars($this->getLanguageService()->getLL('permissions')) . '">'
1499 . $this->iconFactory->getIcon('status-status-locked', Icon::SIZE_SMALL)->render() . '</a>';
1500 $this->addActionToCellGroup($cells, $permsAction, 'perms');
1501 }
1502 // "New record after" link (ONLY if the records in the table are sorted by a "sortby"-row
1503 // or if default values can depend on previous record):
1504 if (($GLOBALS['TCA'][$table]['ctrl']['sortby'] || $GLOBALS['TCA'][$table]['ctrl']['useColumnsForDefaultValues']) && $permsEdit) {
1505 if ($table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT || $table === 'pages' && $this->calcPerms & Permission::PAGE_NEW) {
1506 if ($this->showNewRecLink($table)) {
1507 $params = '&edit[' . $table . '][' . -($row['_MOVE_PLH'] ? $row['_MOVE_PLH_uid'] : $row['uid']) . ']=new';
1508 $icon = ($table === 'pages' ? $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL));
1509 $titleLabel = 'new';
1510 if ($GLOBALS['TCA'][$table]['ctrl']['sortby']) {
1511 $titleLabel .= ($table === 'pages' ? 'Page' : 'Record');
1512 }
1513 $newAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1514 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL($titleLabel)) . '">'
1515 . $icon->render() . '</a>';
1516 $this->addActionToCellGroup($cells, $newAction, 'new');
1517 }
1518 }
1519 }
1520 // "Up/Down" links
1521 if ($permsEdit && $GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField && !$this->searchLevels) {
1522 if (isset($this->currentTable['prev'][$row['uid']])) {
1523 // Up
1524 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prev'][$row['uid']];
1525 $moveUpAction = '<a class="btn btn-default" href="#" onclick="'
1526 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
1527 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
1528 . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
1529 } else {
1530 $moveUpAction = $this->spaceIcon;
1531 }
1532 $this->addActionToCellGroup($cells, $moveUpAction, 'moveUp');
1533
1534 if ($this->currentTable['next'][$row['uid']]) {
1535 // Down
1536 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['next'][$row['uid']];
1537 $moveDownAction = '<a class="btn btn-default" href="#" onclick="'
1538 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
1539 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
1540 . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
1541 } else {
1542 $moveDownAction = $this->spaceIcon;
1543 }
1544 $this->addActionToCellGroup($cells, $moveDownAction, 'moveDown');
1545 }
1546 // "Hide/Unhide" links:
1547 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
1548
1549 if (
1550 !empty($GLOBALS['TCA'][$table]['columns'][$hiddenField])
1551 && (empty($GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude'])
1552 || $this->getBackendUserAuthentication()->check('non_exclude_fields', $table . ':' . $hiddenField))
1553 ) {
1554 if (!$permsEdit || $this->isRecordCurrentBackendUser($table, $row)) {
1555 $hideAction = $this->spaceIcon;
1556 } else {
1557 $hideTitle = htmlspecialchars($this->getLanguageService()->getLL('hide' . ($table === 'pages' ? 'Page' : '')));
1558 $unhideTitle = htmlspecialchars($this->getLanguageService()->getLL('unHide' . ($table === 'pages' ? 'Page' : '')));
1559 if ($row[$hiddenField]) {
1560 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=0';
1561 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="hidden" href="#"'
1562 . ' data-params="' . htmlspecialchars($params) . '"'
1563 . ' title="' . $unhideTitle . '"'
1564 . ' data-toggle-title="' . $hideTitle . '">'
1565 . $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render() . '</a>';
1566 } else {
1567 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=1';
1568 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="visible" href="#"'
1569 . ' data-params="' . htmlspecialchars($params) . '"'
1570 . ' title="' . $hideTitle . '"'
1571 . ' data-toggle-title="' . $unhideTitle . '">'
1572 . $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render() . '</a>';
1573 }
1574 }
1575 $this->addActionToCellGroup($cells, $hideAction, 'hide');
1576 }
1577 // "Delete" link:
1578 $disableDeleteTS = $this->getBackendUserAuthentication()->getTSConfig('options.disableDelete');
1579 $disableDelete = (bool) trim(isset($disableDeleteTS['properties'][$table]) ? $disableDeleteTS['properties'][$table] : $disableDeleteTS['value']);
1580 if ($permsEdit && !$disableDelete && ($table === 'pages' && $localCalcPerms & Permission::PAGE_DELETE || $table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT)) {
1581 // Check if the record version is in "deleted" state, because that will switch the action to "restore"
1582 if ($this->getBackendUserAuthentication()->workspace > 0 && isset($row['t3ver_state']) && (int)$row['t3ver_state'] === 2) {
1583 $actionName = 'restore';
1584 $refCountMsg = '';
1585 } else {
1586 $actionName = 'delete';
1587 $refCountMsg = BackendUtility::referenceCount(
1588 $table,
1589 $row['uid'],
1590 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.referencesToRecord'),
1591 $this->getReferenceCount($table, $row['uid'])) . BackendUtility::translationCount($table, $row['uid'],
1592 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.translationsOfRecord')
1593 );
1594 }
1595
1596 if ($this->isRecordCurrentBackendUser($table, $row)) {
1597 $deleteAction = $this->spaceIcon;
1598 } else {
1599 $title = BackendUtility::getRecordTitle($table, $row);
1600 $warningText = $this->getLanguageService()->getLL($actionName . 'Warning') . ' "' . $title . '" ' . '[' . $table . ':' . $row['uid'] . ']' . $refCountMsg;
1601
1602 $params = 'cmd[' . $table . '][' . $row['uid'] . '][delete]=1';
1603 $icon = $this->iconFactory->getIcon('actions-edit-' . $actionName, Icon::SIZE_SMALL)->render();
1604 $linkTitle = htmlspecialchars($this->getLanguageService()->getLL($actionName));
1605 $deleteAction = '<a class="btn btn-default t3js-record-delete" href="#" '
1606 . ' data-l10parent="' . htmlspecialchars($row['l10n_parent']) . '"'
1607 . ' data-params="' . htmlspecialchars($params) . '" data-title="' . htmlspecialchars($title) . '"'
1608 . ' data-message="' . htmlspecialchars($warningText) . '" title="' . $linkTitle . '"'
1609 . '>' . $icon . '</a>';
1610 }
1611 } else {
1612 $deleteAction = $this->spaceIcon;
1613 }
1614 $this->addActionToCellGroup($cells, $deleteAction, 'delete');
1615 // "Levels" links: Moving pages into new levels...
1616 if ($permsEdit && $table === 'pages' && !$this->searchLevels) {
1617 // Up (Paste as the page right after the current parent page)
1618 if ($this->calcPerms & Permission::PAGE_NEW) {
1619 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . -$this->id;
1620 $moveLeftAction = '<a class="btn btn-default" href="#" onclick="'
1621 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
1622 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('prevLevel')) . '">'
1623 . $this->iconFactory->getIcon('actions-move-left', Icon::SIZE_SMALL)->render() . '</a>';
1624 $this->addActionToCellGroup($cells, $moveLeftAction, 'moveLeft');
1625 }
1626 // Down (Paste as subpage to the page right above)
1627 if ($this->currentTable['prevUid'][$row['uid']]) {
1628 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $this->currentTable['prevUid'][$row['uid']]));
1629 if ($localCalcPerms & Permission::PAGE_NEW) {
1630 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prevUid'][$row['uid']];
1631 $moveRightAction = '<a class="btn btn-default" href="#" onclick="'
1632 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
1633 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('nextLevel')) . '">'
1634 . $this->iconFactory->getIcon('actions-move-right', Icon::SIZE_SMALL)->render() . '</a>';
1635 } else {
1636 $moveRightAction = $this->spaceIcon;
1637 }
1638 } else {
1639 $moveRightAction = $this->spaceIcon;
1640 }
1641 $this->addActionToCellGroup($cells, $moveRightAction, 'moveRight');
1642 }
1643 }
1644 /**
1645 * @hook recStatInfoHooks: Allows to insert HTML before record icons on various places
1646 */
1647 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1648 $stat = '';
1649 $_params = [$table, $row['uid']];
1650 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1651 $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1652 }
1653 $this->addActionToCellGroup($cells, $stat, 'stat');
1654 }
1655 /**
1656 * @hook makeControl: Allows to change control icons of records in list-module
1657 * @usage This hook method gets passed the current $cells array as third parameter.
1658 * This array contains values for the icons/actions generated for each record in Web>List.
1659 * Each array entry is accessible by an index-key.
1660 * The order of the icons is depending on the order of those array entries.
1661 */
1662 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1663 // for compatibility reason, we move all icons to the rootlevel
1664 // before calling the hooks
1665 foreach ($cells as $section => $actions) {
1666 foreach ($actions as $actionKey => $action) {
1667 $cells[$actionKey] = $action;
1668 }
1669 }
1670 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1671 $hookObject = GeneralUtility::getUserObj($classData);
1672 if (!$hookObject instanceof RecordListHookInterface) {
1673 throw new \UnexpectedValueException($classData . ' must implement interface ' . RecordListHookInterface::class, 1195567840);
1674 }
1675 $cells = $hookObject->makeControl($table, $row, $cells, $this);
1676 }
1677 // now sort icons again into primary and secondary sections
1678 // after all hooks are processed
1679 $hookCells = $cells;
1680 foreach ($hookCells as $key => $value) {
1681 if ($key === 'primary' || $key === 'secondary') {
1682 continue;
1683 }
1684 $this->addActionToCellGroup($cells, $value, $key);
1685 }
1686 }
1687 $output = '<!-- CONTROL PANEL: ' . $table . ':' . $row['uid'] . ' -->';
1688 foreach ($cells as $classification => $actions) {
1689 $visibilityClass = ($classification !== 'primary' && !$module->MOD_SETTINGS['bigControlPanel'] ? 'collapsed' : 'expanded');
1690 if ($visibilityClass === 'collapsed') {
1691 $cellOutput = '';
1692 foreach ($actions as $action) {
1693 $cellOutput .= $action;
1694 }
1695 $output .= ' <div class="btn-group">' .
1696 '<span id="actions_' . $table . '_' . $row['uid'] . '" class="btn-group collapse collapse-horizontal width">' . $cellOutput . '</span>' .
1697 '<a href="#actions_' . $table . '_' . $row['uid'] . '" class="btn btn-default collapsed" data-toggle="collapse" aria-expanded="false"><span class="t3-icon fa fa-ellipsis-h"></span></a>' .
1698 '</div>';
1699 } else {
1700 $output .= ' <div class="btn-group" role="group">' . implode('', $actions) . '</div>';
1701 }
1702 }
1703 return $output;
1704 }
1705
1706 /**
1707 * Creates the clipboard panel for a single record in the listing.
1708 *
1709 * @param string $table The table
1710 * @param mixed[] $row The record for which to make the clipboard panel.
1711 * @throws \UnexpectedValueException
1712 * @return string HTML table with the clipboard panel (unless disabled)
1713 */
1714 public function makeClip($table, $row)
1715 {
1716 // Return blank, if disabled:
1717 if (!$this->getModule()->MOD_SETTINGS['clipBoard']) {
1718 return '';
1719 }
1720 $cells = [];
1721 $cells['pasteAfter'] = ($cells['pasteInto'] = $this->spaceIcon);
1722 //enables to hide the copy, cut and paste icons for localized records - doesn't make much sense to perform these options for them
1723 $isL10nOverlay = $this->localizationView && $table !== 'pages_language_overlay' && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0;
1724 // Return blank, if disabled:
1725 // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
1726 // For the "Normal" pad:
1727 if ($this->clipObj->current === 'normal') {
1728 // Show copy/cut icons:
1729 $isSel = (string)$this->clipObj->isSelected($table, $row['uid']);
1730 if ($isL10nOverlay || !$this->overlayEditLockPermissions($table, $row)) {
1731 $cells['copy'] = $this->spaceIcon;
1732 $cells['cut'] = $this->spaceIcon;
1733 } else {
1734 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL);
1735 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut', Icon::SIZE_SMALL);
1736
1737 if ($isSel === 'copy') {
1738 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy-release', Icon::SIZE_SMALL);
1739 } elseif ($isSel === 'cut') {
1740 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut-release', Icon::SIZE_SMALL);
1741 }
1742
1743 $cells['copy'] = '<a class="btn btn-default" href="#" onclick="'
1744 . htmlspecialchars('return jumpSelf(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $row['uid'], 1, ($isSel === 'copy'), ['returnUrl' => ''])) . ');')
1745 . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy')) . '">'
1746 . $copyIcon->render() . '</a>';
1747
1748 // Check permission to cut page or content
1749 if ($table === 'pages') {
1750 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $row['uid']));
1751 $permsEdit = $localCalcPerms & Permission::PAGE_EDIT;
1752 } else {
1753 $permsEdit = $this->calcPerms & Permission::CONTENT_EDIT;
1754 }
1755 $permsEdit = $this->overlayEditLockPermissions($table, $row, $permsEdit);
1756
1757 // If the listed table is 'pages' we have to request the permission settings for each page:
1758 if ($table === 'pages') {
1759 if ($permsEdit) {
1760 $cells['cut'] = '<a class="btn btn-default" href="#" onclick="'
1761 . htmlspecialchars('return jumpSelf(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel === 'cut'), ['returnUrl' => ''])) . ');')
1762 . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut')) . '">'
1763 . $cutIcon->render() . '</a>';
1764 } else {
1765 $cells['cut'] = $this->spaceIcon;
1766 }
1767 } else {
1768 if ($table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT) {
1769 $cells['cut'] = '<a class="btn btn-default" href="#" onclick="'
1770 . htmlspecialchars('return jumpSelf(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel === 'cut'), ['returnUrl' => ''])) . ');')
1771 . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut')) . '">'
1772 . $cutIcon->render() . '</a>';
1773 } else {
1774 $cells['cut'] = $this->spaceIcon;
1775 }
1776 }
1777 }
1778 } else {
1779 // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
1780 // Setting name of the element in ->CBnames array:
1781 $n = $table . '|' . $row['uid'];
1782 $this->CBnames[] = $n;
1783 // Check if the current element is selected and if so, prepare to set the checkbox as selected:
1784 $checked = $this->clipObj->isSelected($table, $row['uid']) ? 'checked="checked" ' : '';
1785 // If the "duplicateField" value is set then select all elements which are duplicates...
1786 if ($this->duplicateField && isset($row[$this->duplicateField])) {
1787 $checked = '';
1788 if (in_array($row[$this->duplicateField], $this->duplicateStack)) {
1789 $checked = 'checked="checked" ';
1790 }
1791 $this->duplicateStack[] = $row[$this->duplicateField];
1792 }
1793 // Adding the checkbox to the panel:
1794 $cells['select'] = $isL10nOverlay
1795 ? $this->spaceIcon
1796 : '<input type="hidden" name="CBH[' . $n . ']" value="0" /><label class="btn btn-default btn-checkbox"><input type="checkbox"'
1797 . ' name="CBC[' . $n . ']" value="1" ' . $checked . '/><span class="t3-icon fa"></span></label>';
1798 }
1799 // Now, looking for selected elements from the current table:
1800 $elFromTable = $this->clipObj->elFromTable($table);
1801 if (!empty($elFromTable) && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
1802 // IF elements are found, they can be individually ordered and are not locked by editlock, then add a "paste after" icon:
1803 $cells['pasteAfter'] = $isL10nOverlay || !$this->overlayEditLockPermissions($table, $row)
1804 ? $this->spaceIcon
1805 : '<a class="btn btn-default t3js-modal-trigger"'
1806 . ' href="' . htmlspecialchars($this->clipObj->pasteUrl($table, -$row['uid'])) . '"'
1807 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteAfter')) . '"'
1808 . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteAfter')) . '"'
1809 . ' data-content="' . htmlspecialchars($this->clipObj->confirmMsgText($table, $row, 'after', $elFromTable)) . '"'
1810 . ' data-severity="warning">'
1811 . $this->iconFactory->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)->render() . '</a>';
1812 }
1813 // Now, looking for elements in general:
1814 $elFromTable = $this->clipObj->elFromTable('');
1815 if ($table === 'pages' && !empty($elFromTable)) {
1816 $cells['pasteInto'] = '<a class="btn btn-default t3js-modal-trigger"'
1817 . ' href="' . htmlspecialchars($this->clipObj->pasteUrl('', $row['uid'])) . '"'
1818 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
1819 . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
1820 . ' data-content="' . htmlspecialchars($this->clipObj->confirmMsgText($table, $row, 'into', $elFromTable)) . '"'
1821 . ' data-severity="warning">'
1822 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render() . '</a>';
1823 }
1824 /**
1825 * @hook makeClip: Allows to change clip-icons of records in list-module
1826 * @usage This hook method gets passed the current $cells array as third parameter.
1827 * This array contains values for the clipboard icons generated for each record in Web>List.
1828 * Each array entry is accessible by an index-key.
1829 * The order of the icons is depending on the order of those array entries.
1830 */
1831 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1832 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $classData) {
1833 $hookObject = GeneralUtility::getUserObj($classData);
1834 if (!$hookObject instanceof RecordListHookInterface) {
1835 throw new \UnexpectedValueException($classData . ' must implement interface ' . RecordListHookInterface::class, 1195567845);
1836 }
1837 $cells = $hookObject->makeClip($table, $row, $cells, $this);
1838 }
1839 }
1840 // Compile items into a DIV-element:
1841 return '<!-- CLIPBOARD PANEL: ' . $table . ':' . $row['uid'] . ' -->
1842 <div class="btn-group" role="group">' . implode('', $cells) . '</div>';
1843 }
1844
1845 /**
1846 * Creates the HTML for a reference count for the record with the UID $uid
1847 * in the table $tableName.
1848 *
1849 * @param string $tableName
1850 * @param int $uid
1851 * @return string HTML of reference a link, will be empty if there are no
1852 */
1853 protected function createReferenceHtml($tableName, $uid)
1854 {
1855 $referenceCount = GeneralUtility::makeInstance(ConnectionPool::class)
1856 ->getConnectionForTable('sys_refindex')
1857 ->count(
1858 '*',
1859 'sys_refindex',
1860 [
1861 'ref_table' => $tableName,
1862 'ref_uid' => (int)$uid,
1863 'deleted' => 0,
1864 ]
1865 );
1866
1867 return $this->generateReferenceToolTip(
1868 $referenceCount,
1869 GeneralUtility::quoteJSvalue($tableName) . ', ' . GeneralUtility::quoteJSvalue($uid)
1870 );
1871 }
1872
1873 /**
1874 * Creates the localization panel
1875 *
1876 * @param string $table The table
1877 * @param mixed[] $row The record for which to make the localization panel.
1878 * @return string[] Array with key 0/1 with content for column 1 and 2
1879 */
1880 public function makeLocalizationPanel($table, $row)
1881 {
1882 $out = [
1883 0 => '',
1884 1 => ''
1885 ];
1886 // Reset translations
1887 $this->translations = [];
1888
1889 // Language title and icon:
1890 $out[0] = $this->languageFlag($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]);
1891 // Guard clause so we can quickly return if a record is localized to "all languages"
1892 // It should only be possible to localize a record off default (uid 0)
1893 // Reasoning: The Parent is for ALL languages... why overlay with a localization?
1894 if ((int)$row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] === -1) {
1895 return $out;
1896 }
1897
1898 $translations = $this->translateTools->translationInfo($table, $row['uid'], 0, $row, $this->selFieldList);
1899 if (is_array($translations)) {
1900 $this->translations = $translations['translations'];
1901 // Traverse page translations and add icon for each language that does NOT yet exist:
1902 $lNew = '';
1903 foreach ($this->pageOverlays as $lUid_OnPage => $lsysRec) {
1904 if ($this->isEditable($table) && !isset($translations['translations'][$lUid_OnPage]) && $this->getBackendUserAuthentication()->checkLanguageAccess($lUid_OnPage)) {
1905 $url = $this->listURL();
1906 $href = BackendUtility::getLinkToDataHandlerAction(
1907 '&cmd[' . $table . '][' . $row['uid'] . '][localize]=' . $lUid_OnPage,
1908 $url . '&justLocalized=' . rawurlencode($table . ':' . $row['uid'] . ':' . $lUid_OnPage)
1909 );
1910 $language = BackendUtility::getRecord('sys_language', $lUid_OnPage, 'title');
1911 if ($this->languageIconTitles[$lUid_OnPage]['flagIcon']) {
1912 $lC = $this->iconFactory->getIcon($this->languageIconTitles[$lUid_OnPage]['flagIcon'], Icon::SIZE_SMALL)->render();
1913 } else {
1914 $lC = $this->languageIconTitles[$lUid_OnPage]['title'];
1915 }
1916 $lC = '<a href="' . htmlspecialchars($href) . '" title="'
1917 . htmlspecialchars($language['title']) . '" class="btn btn-default">' . $lC . '</a> ';
1918 $lNew .= $lC;
1919 }
1920 }
1921 if ($lNew) {
1922 $out[1] .= $lNew;
1923 }
1924 } elseif ($row['l18n_parent']) {
1925 $out[0] = '&nbsp;&nbsp;&nbsp;&nbsp;' . $out[0];
1926 }
1927 return $out;
1928 }
1929
1930 /**
1931 * Creates a checkbox list for selecting fields to display from a table:
1932 *
1933 * @param string $table Table name
1934 * @param bool $formFields If TRUE, form-fields will be wrapped around the table.
1935 * @return string HTML table with the selector check box (name: displayFields['.$table.'][])
1936 */
1937 public function fieldSelectBox($table, $formFields = true)
1938 {
1939 $lang = $this->getLanguageService();
1940 // Init:
1941 $formElements = ['', ''];
1942 if ($formFields) {
1943 $formElements = ['<form action="' . htmlspecialchars($this->listURL()) . '" method="post" name="fieldSelectBox">', '</form>'];
1944 }
1945 // Load already selected fields, if any:
1946 $setFields = is_array($this->setFields[$table]) ? $this->setFields[$table] : [];
1947 // Request fields from table:
1948 $fields = $this->makeFieldList($table, false, true);
1949 // Add pseudo "control" fields
1950 $fields[] = '_PATH_';
1951 $fields[] = '_REF_';
1952 $fields[] = '_LOCALIZATION_';
1953 $fields[] = '_CONTROL_';
1954 $fields[] = '_CLIPBOARD_';
1955 // Create a checkbox for each field:
1956 $checkboxes = [];
1957 $checkAllChecked = true;
1958 $tsConfig = BackendUtility::getPagesTSconfig($this->id);
1959 $tsConfigOfTable = is_array($tsConfig['TCEFORM.'][$table . '.']) ? $tsConfig['TCEFORM.'][$table . '.'] : null;
1960 foreach ($fields as $fieldName) {
1961 // Hide field if hidden
1962 if ($tsConfigOfTable && is_array($tsConfigOfTable[$fieldName . '.']) && isset($tsConfigOfTable[$fieldName . '.']['disabled']) && (int)$tsConfigOfTable[$fieldName . '.']['disabled'] === 1) {
1963 continue;
1964 }
1965 // Determine, if checkbox should be checked
1966 if (in_array($fieldName, $setFields, true) || $fieldName === $this->fieldArray[0]) {
1967 $checked = ' checked="checked"';
1968 } else {
1969 $checkAllChecked = false;
1970 $checked = '';
1971 }
1972 // Field label
1973 $fieldLabel = is_array($GLOBALS['TCA'][$table]['columns'][$fieldName])
1974 ? rtrim($lang->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label']), ':')
1975 : '';
1976 $checkboxes[] = '<tr><td class="col-checkbox"><input type="checkbox" id="check-' . $fieldName . '" name="displayFields['
1977 . $table . '][]" value="' . $fieldName . '" ' . $checked
1978 . ($fieldName === $this->fieldArray[0] ? ' disabled="disabled"' : '') . '></td><td class="col-title">'
1979 . '<label class="label-block" for="check-' . $fieldName . '">' . htmlspecialchars($fieldLabel) . ' <span class="text-muted text-monospace">[' . htmlspecialchars($fieldName) . ']</span></label></td></tr>';
1980 }
1981 // Table with the field selector::
1982 $content = $formElements[0] . '
1983 <input type="hidden" name="displayFields[' . $table . '][]" value="">
1984 <div class="table-fit table-scrollable">
1985 <table border="0" cellpadding="0" cellspacing="0" class="table table-transparent table-hover">
1986 <thead>
1987 <tr>
1988 <th class="col-checkbox checkbox" colspan="2">
1989 <label><input type="checkbox" class="checkbox checkAll" ' . ($checkAllChecked ? ' checked="checked"' : '') . '>
1990 ' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.toggleall')) . '</label>
1991 </th>
1992 </tr>
1993 </thead>
1994 <tbody>
1995 ' . implode('', $checkboxes) . '
1996 </tbody>
1997 </table>
1998 </div>
1999 <input type="submit" name="search" class="btn btn-default" value="'
2000 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.setFields')) . '"/>
2001 ' . $formElements[1];
2002 return '<div class="fieldSelectBox">' . $content . '</div>';
2003 }
2004
2005 /*********************************
2006 *
2007 * Helper functions
2008 *
2009 *********************************/
2010 /**
2011 * Creates a link around $string. The link contains an onclick action
2012 * which submits the script with some clipboard action.
2013 * Currently, this is used for setting elements / delete elements.
2014 *
2015 * @param string $string The HTML content to link (image/text)
2016 * @param string $table Table name
2017 * @param string $cmd Clipboard command (eg. "setCB" or "delete")
2018 * @param string $warning Warning text, if any ("delete" uses this for confirmation
2019 * @param string $title title attribute for the anchor
2020 * @return string <a> tag wrapped link.
2021 */
2022 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '', $title = '')
2023 {
2024 $jsCode = 'document.dblistForm.cmd.value=' . GeneralUtility::quoteJSvalue($cmd)
2025 . ';document.dblistForm.cmd_table.value='
2026 . GeneralUtility::quoteJSvalue($table)
2027 . ';document.dblistForm.submit();';
2028
2029 $attributes = [];
2030 if ($title !== '') {
2031 $attributes['title'] = $title;
2032 }
2033 if ($warning) {
2034 $attributes['class'] = 'btn btn-default t3js-modal-trigger';
2035 $attributes['data-href'] = 'javascript:' . $jsCode;
2036 $attributes['data-severity'] = 'warning';
2037 $attributes['data-title'] = $title;
2038 $attributes['data-content'] = $warning;
2039 } else {
2040 $attributes['class'] = 'btn btn-default';
2041 $attributes['onclick'] = $jsCode . 'return false;';
2042 }
2043
2044 $attributesString = '';
2045 foreach ($attributes as $key => $value) {
2046 $attributesString .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
2047 }
2048 return '<a href="#" ' . $attributesString . '>' . $string . '</a>';
2049 }
2050
2051 /**
2052 * Returns TRUE if a numeric clipboard pad is selected/active
2053 *
2054 * @return bool
2055 */
2056 public function clipNumPane()
2057 {
2058 return in_array('_CLIPBOARD_', $this->fieldArray) && $this->clipObj->current !== 'normal';
2059 }
2060
2061 /**
2062 * Creates a sort-by link on the input string ($code).
2063 * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
2064 * Also some fields will not be possible to sort (including if single-table-view is disabled).
2065 *
2066 * @param string $code The string to link (text)
2067 * @param string $field The fieldname represented by the title ($code)
2068 * @param string $table Table name
2069 * @return string Linked $code variable
2070 */
2071 public function addSortLink($code, $field, $table)
2072 {
2073 // Certain circumstances just return string right away (no links):
2074 if ($field === '_CONTROL_' || $field === '_LOCALIZATION_' || $field === '_CLIPBOARD_' || $field === '_REF_' || $this->disableSingleTableView) {
2075 return $code;
2076 }
2077 // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
2078 if ($field === '_PATH_') {
2079 $field = 'pid';
2080 }
2081 // Create the sort link:
2082 $sortUrl = $this->listURL('', '-1', 'sortField,sortRev,table,firstElementNumber') . '&table=' . $table
2083 . '&sortField=' . $field . '&sortRev=' . ($this->sortRev || $this->sortField != $field ? 0 : 1);
2084 $sortArrow = $this->sortField === $field
2085 ? $this->iconFactory->getIcon('status-status-sorting-' . ($this->sortRev ? 'desc' : 'asc'), Icon::SIZE_SMALL)->render()
2086 : '';
2087 // Return linked field:
2088 return '<a href="' . htmlspecialchars($sortUrl) . '">' . $code . $sortArrow . '</a>';
2089 }
2090
2091 /**
2092 * Returns the path for a certain pid
2093 * The result is cached internally for the session, thus you can call
2094 * this function as much as you like without performance problems.
2095 *
2096 * @param int $pid The page id for which to get the path
2097 * @return mixed[] The path.
2098 */
2099 public function recPath($pid)
2100 {
2101 if (!isset($this->recPath_cache[$pid])) {
2102 $this->recPath_cache[$pid] = BackendUtility::getRecordPath($pid, $this->perms_clause, 20);
2103 }
2104 return $this->recPath_cache[$pid];
2105 }
2106
2107 /**
2108 * Returns TRUE if a link for creating new records should be displayed for $table
2109 *
2110 * @param string $table Table name
2111 * @return bool Returns TRUE if a link for creating new records should be displayed for $table
2112 * @see \TYPO3\CMS\Backend\Controller\NewRecordController::showNewRecLink
2113 */
2114 public function showNewRecLink($table)
2115 {
2116 // No deny/allow tables are set:
2117 if (empty($this->allowedNewTables) && empty($this->deniedNewTables)) {
2118 return true;
2119 }
2120 return !in_array($table, $this->deniedNewTables)
2121 && (empty($this->allowedNewTables) || in_array($table, $this->allowedNewTables));
2122 }
2123
2124 /**
2125 * Creates the "&returnUrl" parameter for links - this is used when the script links
2126 * to other scripts and passes its own URL with the link so other scripts can return to the listing again.
2127 * Uses REQUEST_URI as value.
2128 *
2129 * @return string
2130 */
2131 public function makeReturnUrl()
2132 {
2133 return '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
2134 }
2135
2136 /************************************
2137 *
2138 * CSV related functions
2139 *
2140 ************************************/
2141 /**
2142 * Initializes internal csvLines array with the header of field names
2143 *
2144 * @return void
2145 */
2146 protected function initCSV()
2147 {
2148 $this->addHeaderRowToCSV();
2149 }
2150
2151 /**
2152 * Add header line with field names as CSV line
2153 *
2154 * @return void
2155 */
2156 protected function addHeaderRowToCSV()
2157 {
2158 // Add header row, control fields will be reduced inside addToCSV()
2159 $this->addToCSV(array_combine($this->fieldArray, $this->fieldArray));
2160 }
2161
2162 /**
2163 * Adds selected columns of one table row as CSV line.
2164 *
2165 * @param mixed[] $row Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
2166 * @return void
2167 */
2168 protected function addToCSV(array $row = [])
2169 {
2170 $rowReducedByControlFields = self::removeControlFieldsFromFieldRow($row);
2171 // Get an field array without control fields but in the expected order
2172 $fieldArray = array_intersect_key(array_flip($this->fieldArray), $rowReducedByControlFields);
2173 // Overwrite fieldArray to keep the order with an array of needed fields
2174 $rowReducedToSelectedColumns = array_replace($fieldArray, array_intersect_key($rowReducedByControlFields, $fieldArray));
2175 $this->setCsvRow($rowReducedToSelectedColumns);
2176 }
2177
2178 /**
2179 * Remove control fields from row for CSV export
2180 *
2181 * @param mixed[] $row fieldNames => fieldValues
2182 * @return mixed[] Input array reduces by control fields
2183 */
2184 protected static function removeControlFieldsFromFieldRow(array $row = [])
2185 {
2186 // Possible control fields in a list row
2187 $controlFields = [
2188 '_PATH_',
2189 '_REF_',
2190 '_CONTROL_',
2191 '_CLIPBOARD_',
2192 '_LOCALIZATION_',
2193 '_LOCALIZATION_b'
2194 ];
2195 return array_diff_key($row, array_flip($controlFields));
2196 }
2197
2198 /**
2199 * Adds input row of values to the internal csvLines array as a CSV formatted line
2200 *
2201 * @param mixed[] $csvRow Array with values to be listed.
2202 * @return void
2203 */
2204 public function setCsvRow($csvRow)
2205 {
2206 $this->csvLines[] = GeneralUtility::csvValues($csvRow);
2207 }
2208
2209 /**
2210 * Compiles the internal csvLines array to a csv-string and outputs it to the browser.
2211 * This function exits!
2212 *
2213 * @param string $prefix Filename prefix:
2214 * @return void EXITS php execution!
2215 */
2216 public function outputCSV($prefix)
2217 {
2218 // Setting filename:
2219 $filename = $prefix . '_' . date('dmy-Hi') . '.csv';
2220 // Creating output header:
2221 header('Content-Type: application/octet-stream');
2222 header('Content-Disposition: attachment; filename=' . $filename);
2223 // Cache-Control header is needed here to solve an issue with browser IE and
2224 // versions lower than 9. See for more information: http://support.microsoft.com/kb/323308
2225 header("Cache-Control: ''");
2226 // Printing the content of the CSV lines:
2227 echo implode(CRLF, $this->csvLines);
2228 // Exits:
2229 die;
2230 }
2231
2232 /**
2233 * add action into correct section
2234 *
2235 * @param array $cells
2236 * @param string $action
2237 * @param string $actionKey
2238 */
2239 public function addActionToCellGroup(&$cells, $action, $actionKey)
2240 {
2241 $cellsMap = [
2242 'primary' => [
2243 'view', 'edit', 'hide', 'delete', 'stat'
2244 ],
2245 'secondary' => [
2246 'viewBig', 'history', 'perms', 'new', 'move', 'moveUp', 'moveDown', 'moveLeft', 'moveRight', 'version'
2247 ]
2248 ];
2249 $classification = in_array($actionKey, $cellsMap['primary']) ? 'primary' : 'secondary';
2250 $cells[$classification][$actionKey] = $action;
2251 unset($cells[$actionKey]);
2252 }
2253
2254 /**
2255 * Check if the record represents the current backend user
2256 *
2257 * @param string $table
2258 * @param array $row
2259 * @return bool
2260 */
2261 protected function isRecordCurrentBackendUser($table, $row)
2262 {
2263 return $table === 'be_users' && (int)$row['uid'] === $this->getBackendUserAuthentication()->user['uid'];
2264 }
2265
2266 /**
2267 * @param bool $isEditable
2268 */
2269 public function setIsEditable($isEditable)
2270 {
2271 $this->editable = $isEditable;
2272 }
2273
2274 /**
2275 * Check if the table is readonly or editable
2276 * @param string $table
2277 * @return bool
2278 */
2279 public function isEditable($table)
2280 {
2281 return $GLOBALS['TCA'][$table]['ctrl']['readOnly'] || $this->editable;
2282 }
2283
2284 /**
2285 * Check if the current record is locked by editlock. Pages are locked if their editlock flag is set,
2286 * records are if they are locked themselves or if the page they are on is locked (a page’s editlock
2287 * is transitive for its content elements).
2288 *
2289 * @param string $table
2290 * @param array $row
2291 * @param bool $editPermission
2292 * @return bool
2293 */
2294 protected function overlayEditLockPermissions($table, $row = [], $editPermission = true)
2295 {
2296 if ($editPermission && !$this->getBackendUserAuthentication()->isAdmin()) {
2297 // If no $row is submitted we only check for general edit lock of current page (except for table "pages")
2298 if (empty($row)) {
2299 return $table === 'pages' ? true : !$this->pageRow['editlock'];
2300 }
2301 if (($table === 'pages' && $row['editlock']) || ($table !== 'pages' && $this->pageRow['editlock'])) {
2302 $editPermission = false;
2303 } elseif (isset($GLOBALS['TCA'][$table]['ctrl']['editlock']) && $row[$GLOBALS['TCA'][$table]['ctrl']['editlock']]) {
2304 $editPermission = false;
2305 }
2306 }
2307 return $editPermission;
2308 }
2309
2310 /**
2311 * Check whether or not the current backend user is an admin or the current page is
2312 * locked by editlock.
2313 *
2314 * @return bool
2315 */
2316 protected function editLockPermissions()
2317 {
2318 return $this->getBackendUserAuthentication()->isAdmin() || !$this->pageRow['editlock'];
2319 }
2320
2321 /**
2322 * @return BaseScriptClass
2323 */
2324 protected function getModule()
2325 {
2326 return $GLOBALS['SOBE'];
2327 }
2328
2329 /**
2330 * @return DocumentTemplate
2331 */
2332 protected function getDocumentTemplate()
2333 {
2334 return $GLOBALS['TBE_TEMPLATE'];
2335 }
2336 }