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