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