[BUGFIX] Correct type of argument passed to BackendUtility::viewOnClick
[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-add', 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-view-page', 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 $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($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:missingTcaColumnsMessage'), $table, $table);
610 $messageTitle = $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 $className) {
632 $hookObject = GeneralUtility::makeInstance($className);
633 if (!$hookObject instanceof RecordListGetTableHookInterface) {
634 throw new \UnexpectedValueException($className . ' 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 -= 2;
650 $this->iLimit += 2;
651 // (API function from TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList)
652 $queryBuilder = $this->getQueryBuilder($table, $id, $additionalConstraints);
653 $this->firstElementNumber += 2;
654 $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 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
782 ->getQueryBuilderForTable($table);
783 $queryBuilder->getRestrictions()
784 ->removeAll()
785 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
786 $predicates = [
787 $queryBuilder->expr()->eq(
788 't3ver_move_id',
789 $queryBuilder->createNamedParameter((int)$lRow['uid'], \PDO::PARAM_INT)
790 ),
791 $queryBuilder->expr()->eq(
792 'pid',
793 $queryBuilder->createNamedParameter((int)$row['_MOVE_PLH_pid'], \PDO::PARAM_INT)
794 ),
795 $queryBuilder->expr()->eq(
796 't3ver_wsid',
797 $queryBuilder->createNamedParameter((int)$row['t3ver_wsid'], \PDO::PARAM_INT)
798 ),
799 ];
800
801 $tmpRow = $queryBuilder
802 ->select(...$selFieldList)
803 ->from($table)
804 ->andWhere(...$predicates)
805 ->execute()
806 ->fetch();
807
808 $lRow = is_array($tmpRow) ? $tmpRow : $lRow;
809 }
810 // In offline workspace, look for alternative record:
811 BackendUtility::workspaceOL($table, $lRow, $backendUser->workspace, true);
812 if (is_array($lRow) && $backendUser->checkLanguageAccess($lRow[$GLOBALS['TCA'][$table]['ctrl']['languageField']])) {
813 $currentIdList[] = $lRow['uid'];
814 $rowOutput .= $this->renderListRow($table, $lRow, $cc, $titleCol, $thumbsCol, 18);
815 }
816 }
817 }
818 }
819 }
820 // Counter of total rows incremented:
821 $this->eCounter++;
822 }
823 // Record navigation is added to the beginning and end of the table if in single
824 // table mode
825 if ($this->table) {
826 $rowOutput = $this->renderListNavigation('top') . $rowOutput . $this->renderListNavigation('bottom');
827 } else {
828 // Show that there are more records than shown
829 if ($this->totalItems > $this->itemsLimitPerTable) {
830 $countOnFirstPage = $this->totalItems > $this->itemsLimitSingleTable ? $this->itemsLimitSingleTable : $this->totalItems;
831 $hasMore = $this->totalItems > $this->itemsLimitSingleTable;
832 $colspan = $this->showIcon ? count($this->fieldArray) + 1 : count($this->fieldArray);
833 $rowOutput .= '<tr><td colspan="' . $colspan . '">
834 <a href="' . htmlspecialchars(($this->listURL() . '&table=' . rawurlencode($table))) . '" class="btn btn-default">'
835 . '<span class="t3-icon fa fa-chevron-down"></span> <i>[1 - ' . $countOnFirstPage . ($hasMore ? '+' : '') . ']</i></a>
836 </td></tr>';
837 }
838 }
839 // The header row for the table is now created:
840 $out .= $this->renderListHeader($table, $currentIdList);
841 }
842
843 $collapseClass = $tableCollapsed && !$this->table ? 'collapse' : 'collapse in';
844 $dataState = $tableCollapsed && !$this->table ? 'collapsed' : 'expanded';
845
846 // The list of records is added after the header:
847 $out .= $rowOutput;
848 // ... and it is all wrapped in a table:
849 $out = '
850
851
852
853 <!--
854 DB listing of elements: "' . htmlspecialchars($table) . '"
855 -->
856 <div class="panel panel-space panel-default recordlist">
857 <div class="panel-heading">
858 ' . $tableHeader . '
859 </div>
860 <div class="' . $collapseClass . '" data-state="' . $dataState . '" id="recordlist-' . htmlspecialchars($table) . '">
861 <div class="table-fit">
862 <table data-table="' . htmlspecialchars($table) . '" class="table table-striped table-hover' . ($listOnlyInSingleTableMode ? ' typo3-dblist-overview' : '') . '">
863 ' . $out . '
864 </table>
865 </div>
866 </div>
867 </div>
868 ';
869 // Output csv if...
870 // This ends the page with exit.
871 if ($this->csvOutput) {
872 $this->outputCSV($table);
873 }
874 }
875 // Return content:
876 return $out;
877 }
878
879 /**
880 * Check if all row listing conditions are fulfilled.
881 *
882 * This function serves as a dummy method to be overridden in extending classes.
883 *
884 * @param string $table Table name
885 * @param string[] $row Record
886 * @return bool True, if all conditions are fulfilled.
887 */
888 protected function isRowListingConditionFulfilled($table, $row)
889 {
890 return true;
891 }
892
893 /**
894 * Rendering a single row for the list
895 *
896 * @param string $table Table name
897 * @param mixed[] $row Current record
898 * @param int $cc Counter, counting for each time an element is rendered (used for alternating colors)
899 * @param string $titleCol Table field (column) where header value is found
900 * @param string $thumbsCol Table field (column) where (possible) thumbnails can be found
901 * @param int $indent Indent from left.
902 * @return string Table row for the element
903 * @access private
904 * @see getTable()
905 */
906 public function renderListRow($table, $row, $cc, $titleCol, $thumbsCol, $indent = 0)
907 {
908 if (!is_array($row)) {
909 return '';
910 }
911 $rowOutput = '';
912 $id_orig = null;
913 // If in search mode, make sure the preview will show the correct page
914 if ((string)$this->searchString !== '') {
915 $id_orig = $this->id;
916 $this->id = $row['pid'];
917 }
918
919 $tagAttributes = [
920 'class' => ['t3js-entity'],
921 'data-table' => $table,
922 ];
923
924 // Add special classes for first and last row
925 if ($cc == 1 && $indent == 0) {
926 $tagAttributes['class'][] = 'firstcol';
927 }
928 if ($cc == $this->totalRowCount || $cc == $this->iLimit) {
929 $tagAttributes['class'][] = 'lastcol';
930 }
931 // Overriding with versions background color if any:
932 if (!empty($row['_CSSCLASS'])) {
933 $tagAttributes['class'] = [$row['_CSSCLASS']];
934 }
935 // Incr. counter.
936 $this->counter++;
937 // The icon with link
938 $toolTip = BackendUtility::getRecordToolTip($row, $table);
939 $additionalStyle = $indent ? ' style="margin-left: ' . $indent . 'px;"' : '';
940 $iconImg = '<span ' . $toolTip . ' ' . $additionalStyle . '>'
941 . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render()
942 . '</span>';
943 $theIcon = $this->clickMenuEnabled ? BackendUtility::wrapClickMenuOnIcon($iconImg, $table, $row['uid']) : $iconImg;
944 // Preparing and getting the data-array
945 $theData = [];
946 $localizationMarkerClass = '';
947 foreach ($this->fieldArray as $fCol) {
948 if ($fCol == $titleCol) {
949 $recTitle = BackendUtility::getRecordTitle($table, $row, false, true);
950 $warning = '';
951 // If the record is edit-locked by another user, we will show a little warning sign:
952 $lockInfo = BackendUtility::isRecordLocked($table, $row['uid']);
953 if ($lockInfo) {
954 $warning = '<span data-toggle="tooltip" data-placement="right" data-title="' . htmlspecialchars($lockInfo['msg']) . '">'
955 . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</span>';
956 }
957 $theData[$fCol] = $theData['__label'] = $warning . $this->linkWrapItems($table, $row['uid'], $recTitle, $row);
958 // Render thumbnails, if:
959 // - a thumbnail column exists
960 // - there is content in it
961 // - the thumbnail column is visible for the current type
962 $type = 0;
963 if (isset($GLOBALS['TCA'][$table]['ctrl']['type'])) {
964 $typeColumn = $GLOBALS['TCA'][$table]['ctrl']['type'];
965 $type = $row[$typeColumn];
966 }
967 // If current type doesn't exist, set it to 0 (or to 1 for historical reasons,
968 // if 0 doesn't exist)
969 if (!isset($GLOBALS['TCA'][$table]['types'][$type])) {
970 $type = isset($GLOBALS['TCA'][$table]['types'][0]) ? 0 : 1;
971 }
972 $visibleColumns = $GLOBALS['TCA'][$table]['types'][$type]['showitem'];
973
974 if ($this->thumbs &&
975 trim($row[$thumbsCol]) &&
976 preg_match('/(^|(.*(;|,)?))' . $thumbsCol . '(((;|,).*)|$)/', $visibleColumns) === 1
977 ) {
978 $thumbCode = '<br />' . $this->thumbCode($row, $table, $thumbsCol);
979 $theData[$fCol] .= $thumbCode;
980 $theData['__label'] .= $thumbCode;
981 }
982 if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
983 && $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] != 0
984 && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0
985 ) {
986 // It's a translated record with a language parent
987 $localizationMarkerClass = ' localization';
988 }
989 } elseif ($fCol === 'pid') {
990 $theData[$fCol] = $row[$fCol];
991 } elseif ($fCol === '_PATH_') {
992 $theData[$fCol] = $this->recPath($row['pid']);
993 } elseif ($fCol === '_REF_') {
994 $theData[$fCol] = $this->createReferenceHtml($table, $row['uid']);
995 } elseif ($fCol === '_CONTROL_') {
996 $theData[$fCol] = $this->makeControl($table, $row);
997 } elseif ($fCol === '_CLIPBOARD_') {
998 $theData[$fCol] = $this->makeClip($table, $row);
999 } elseif ($fCol === '_LOCALIZATION_') {
1000 list($lC1, $lC2) = $this->makeLocalizationPanel($table, $row);
1001 $theData[$fCol] = $lC1;
1002 $theData[$fCol . 'b'] = '<div class="btn-group">' . $lC2 . '</div>';
1003 } elseif ($fCol === '_LOCALIZATION_b') {
1004 // deliberately empty
1005 } else {
1006 $pageId = $table === 'pages' ? $row['uid'] : $row['pid'];
1007 $tmpProc = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 100, $row['uid'], true, $pageId);
1008 $theData[$fCol] = $this->linkUrlMail(htmlspecialchars($tmpProc), $row[$fCol]);
1009 if ($this->csvOutput) {
1010 $row[$fCol] = BackendUtility::getProcessedValueExtra($table, $fCol, $row[$fCol], 0, $row['uid']);
1011 }
1012 }
1013 }
1014 // Reset the ID if it was overwritten
1015 if ((string)$this->searchString !== '') {
1016 $this->id = $id_orig;
1017 }
1018 // Add row to CSV list:
1019 if ($this->csvOutput) {
1020 $this->addToCSV($row);
1021 }
1022 // Add classes to table cells
1023 $this->addElement_tdCssClass[$titleCol] = 'col-title col-responsive' . $localizationMarkerClass;
1024 $this->addElement_tdCssClass['__label'] = $this->addElement_tdCssClass[$titleCol];
1025 $this->addElement_tdCssClass['_CONTROL_'] = 'col-control';
1026 if ($this->getModule()->MOD_SETTINGS['clipBoard']) {
1027 $this->addElement_tdCssClass['_CLIPBOARD_'] = 'col-clipboard';
1028 }
1029 $this->addElement_tdCssClass['_PATH_'] = 'col-path';
1030 $this->addElement_tdCssClass['_LOCALIZATION_'] = 'col-localizationa';
1031 $this->addElement_tdCssClass['_LOCALIZATION_b'] = 'col-localizationb';
1032 // Create element in table cells:
1033 $theData['uid'] = $row['uid'];
1034 if (isset($GLOBALS['TCA'][$table]['ctrl']['languageField'])
1035 && isset($GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'])
1036 && $table !== 'pages_language_overlay'
1037 ) {
1038 $theData['_l10nparent_'] = $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
1039 }
1040
1041 $tagAttributes = array_map(
1042 function ($attributeValue) {
1043 if (is_array($attributeValue)) {
1044 return implode(' ', $attributeValue);
1045 }
1046 return $attributeValue;
1047 },
1048 $tagAttributes
1049 );
1050
1051 $rowOutput .= $this->addElement(1, $theIcon, $theData, GeneralUtility::implodeAttributes($tagAttributes, true));
1052 // Finally, return table row element:
1053 return $rowOutput;
1054 }
1055
1056 /**
1057 * Gets the number of records referencing the record with the UID $uid in
1058 * the table $tableName.
1059 *
1060 * @param string $tableName
1061 * @param int $uid
1062 * @return int The number of references to record $uid in table
1063 */
1064 protected function getReferenceCount($tableName, $uid)
1065 {
1066 if (!isset($this->referenceCount[$tableName][$uid])) {
1067 $numberOfReferences = GeneralUtility::makeInstance(ConnectionPool::class)
1068 ->getConnectionForTable('sys_refindex')
1069 ->count(
1070 '*',
1071 'sys_refindex',
1072 [
1073 'ref_table' => $tableName,
1074 'ref_uid' => (int)$uid,
1075 'deleted' => 0
1076 ]
1077 );
1078 $this->referenceCount[$tableName][$uid] = $numberOfReferences;
1079 }
1080 return $this->referenceCount[$tableName][$uid];
1081 }
1082
1083 /**
1084 * Rendering the header row for a table
1085 *
1086 * @param string $table Table name
1087 * @param int[] $currentIdList Array of the currently displayed uids of the table
1088 * @throws \UnexpectedValueException
1089 * @return string Header table row
1090 * @access private
1091 * @see getTable()
1092 */
1093 public function renderListHeader($table, $currentIdList)
1094 {
1095 $lang = $this->getLanguageService();
1096 // Init:
1097 $theData = [];
1098 $icon = '';
1099 // Traverse the fields:
1100 foreach ($this->fieldArray as $fCol) {
1101 // Calculate users permissions to edit records in the table:
1102 $permsEdit = $this->calcPerms & ($table === 'pages' ? 2 : 16) && $this->overlayEditLockPermissions($table);
1103 switch ((string)$fCol) {
1104 case '_PATH_':
1105 // Path
1106 $theData[$fCol] = '<i>[' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels._PATH_')) . ']</i>';
1107 break;
1108 case '_REF_':
1109 // References
1110 $theData[$fCol] = '<i>[' . htmlspecialchars($lang->sL('LLL:EXT:filelist/Resources/Private/Language/locallang_mod_file_list.xlf:c__REF_')) . ']</i>';
1111 break;
1112 case '_LOCALIZATION_':
1113 // Path
1114 $theData[$fCol] = '<i>[' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels._LOCALIZATION_')) . ']</i>';
1115 break;
1116 case '_LOCALIZATION_b':
1117 // Path
1118 $theData[$fCol] = htmlspecialchars($lang->getLL('Localize'));
1119 break;
1120 case '_CLIPBOARD_':
1121 if (!$this->getModule()->MOD_SETTINGS['clipBoard']) {
1122 break;
1123 }
1124 // Clipboard:
1125 $cells = [];
1126 // If there are elements on the clipboard for this table, and the parent page is not locked by editlock
1127 // then display the "paste into" icon:
1128 $elFromTable = $this->clipObj->elFromTable($table);
1129 if (!empty($elFromTable) && $this->overlayEditLockPermissions($table)) {
1130 $href = htmlspecialchars($this->clipObj->pasteUrl($table, $this->id));
1131 $confirmMessage = $this->clipObj->confirmMsgText('pages', $this->pageRow, 'into', $elFromTable);
1132 $cells['pasteAfter'] = '<a class="btn btn-default t3js-modal-trigger"'
1133 . ' href="' . $href . '"'
1134 . ' title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
1135 . ' data-title="' . htmlspecialchars($lang->getLL('clip_paste')) . '"'
1136 . ' data-content="' . htmlspecialchars($confirmMessage) . '"'
1137 . ' data-severity="warning">'
1138 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
1139 . '</a>';
1140 }
1141 // If the numeric clipboard pads are enabled, display the control icons for that:
1142 if ($this->clipObj->current !== 'normal') {
1143 // The "select" link:
1144 $spriteIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL)->render();
1145 $cells['copyMarked'] = $this->linkClipboardHeaderIcon($spriteIcon, $table, 'setCB', '', $lang->getLL('clip_selectMarked'));
1146 // The "edit marked" link:
1147 $editUri = BackendUtility::getModuleUrl('record_edit')
1148 . '&edit[' . $table . '][{entityIdentifiers:editList}]=edit'
1149 . '&returnUrl={T3_THIS_LOCATION}';
1150 $cells['edit'] = '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
1151 . ' data-uri="' . htmlspecialchars($editUri) . '"'
1152 . ' title="' . htmlspecialchars($lang->getLL('clip_editMarked')) . '">'
1153 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1154 // The "Delete marked" link:
1155 $cells['delete'] = $this->linkClipboardHeaderIcon(
1156 $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render(),
1157 $table,
1158 'delete',
1159 sprintf($lang->getLL('clip_deleteMarkedWarning'), $lang->sL($GLOBALS['TCA'][$table]['ctrl']['title'])),
1160 $lang->getLL('clip_deleteMarked')
1161 );
1162 // The "Select all" link:
1163 $onClick = htmlspecialchars(('checkOffCB(' . GeneralUtility::quoteJSvalue(implode(',', $this->CBnames)) . ', this); return false;'));
1164 $cells['markAll'] = '<a class="btn btn-default" rel="" href="#" onclick="' . $onClick . '" title="'
1165 . htmlspecialchars($lang->getLL('clip_markRecords')) . '">'
1166 . $this->iconFactory->getIcon('actions-document-select', Icon::SIZE_SMALL)->render() . '</a>';
1167 } else {
1168 $cells['empty'] = '';
1169 }
1170 /**
1171 * @hook renderListHeaderActions: Allows to change the clipboard icons of the Web>List table headers
1172 * @usage Above each listed table in Web>List a header row is shown.
1173 * This hook allows to modify the icons responsible for the clipboard functions
1174 * (shown above the clipboard checkboxes when a clipboard other than "Normal" is selected),
1175 * or other "Action" functions which perform operations on the listed records.
1176 */
1177 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1178 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $className) {
1179 $hookObject = GeneralUtility::makeInstance($className);
1180 if (!$hookObject instanceof RecordListHookInterface) {
1181 throw new \UnexpectedValueException($className . ' must implement interface ' . RecordListHookInterface::class, 1195567850);
1182 }
1183 $cells = $hookObject->renderListHeaderActions($table, $currentIdList, $cells, $this);
1184 }
1185 }
1186 $theData[$fCol] = '';
1187 if (isset($cells['edit']) && isset($cells['delete'])) {
1188 $theData[$fCol] .= '<div class="btn-group" role="group">' . $cells['edit'] . $cells['delete'] . '</div>';
1189 unset($cells['edit'], $cells['delete']);
1190 }
1191 $theData[$fCol] .= '<div class="btn-group" role="group">' . implode('', $cells) . '</div>';
1192 break;
1193 case '_CONTROL_':
1194 // Control panel:
1195 if ($this->isEditable($table)) {
1196 // If new records can be created on this page, add links:
1197 $permsAdditional = ($table === 'pages' ? 8 : 16);
1198 if ($this->calcPerms & $permsAdditional && $this->showNewRecLink($table)) {
1199 $spriteIcon = $table === 'pages'
1200 ? $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL)
1201 : $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL);
1202 if ($table === 'tt_content' && $this->newWizards) {
1203 // If mod.newContentElementWizard.override is set, use that extension's create new content wizard instead:
1204 $tmpTSc = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod');
1205 $newContentElementWizard = isset($tmpTSc['properties']['newContentElementWizard.']['override'])
1206 ? $tmpTSc['properties']['newContentElementWizard.']['override']
1207 : 'new_content_element';
1208 $newContentWizScriptPath = BackendUtility::getModuleUrl($newContentElementWizard, ['id' => $this->id]);
1209
1210 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($newContentWizScriptPath) . ');';
1211 $icon = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
1212 . htmlspecialchars($lang->getLL('new')) . '">' . $spriteIcon->render() . '</a>';
1213 } elseif ($table === 'pages' && $this->newWizards) {
1214 $parameters = ['id' => $this->id, 'pagesOnly' => 1, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')];
1215 $href = BackendUtility::getModuleUrl('db_new', $parameters);
1216 $icon = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="' . htmlspecialchars($lang->getLL('new')) . '">'
1217 . $spriteIcon->render() . '</a>';
1218 } else {
1219 $params = '&edit[' . $table . '][' . $this->id . ']=new';
1220 if ($table === 'pages_language_overlay') {
1221 $params .= '&overrideVals[pages_language_overlay][doktype]=' . (int)$this->pageRow['doktype'];
1222 }
1223 $icon = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1224 . '" title="' . htmlspecialchars($lang->getLL('new')) . '">' . $spriteIcon->render() . '</a>';
1225 }
1226 }
1227 // If the table can be edited, add link for editing ALL SHOWN fields for all listed records:
1228 if ($permsEdit && $this->table && is_array($currentIdList)) {
1229 $entityIdentifiers = 'entityIdentifiers';
1230 if ($this->clipNumPane()) {
1231 $entityIdentifiers .= ':editList';
1232 }
1233 $editUri = BackendUtility::getModuleUrl('record_edit')
1234 . '&edit[' . $table . '][{' . $entityIdentifiers . '}]=edit'
1235 . '&columnsOnly=' . implode(',', $this->fieldArray)
1236 . '&returnUrl={T3_THIS_LOCATION}';
1237 $icon .= '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
1238 . ' data-uri="' . htmlspecialchars($editUri) . '"'
1239 . ' title="' . htmlspecialchars($lang->getLL('editShownColumns')) . '">'
1240 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1241 $icon = '<div class="btn-group" role="group">' . $icon . '</div>';
1242 }
1243 // Add an empty entry, so column count fits again after moving this into $icon
1244 $theData[$fCol] = '&nbsp;';
1245 }
1246 break;
1247 default:
1248 // Regular fields header:
1249 $theData[$fCol] = '';
1250
1251 // Check if $fCol is really a field and get the label and remove the colons
1252 // at the end
1253 $sortLabel = BackendUtility::getItemLabel($table, $fCol);
1254 if ($sortLabel !== null) {
1255 $sortLabel = htmlspecialchars($lang->sL($sortLabel));
1256 $sortLabel = rtrim(trim($sortLabel), ':');
1257 } else {
1258 // No TCA field, only output the $fCol variable with square brackets []
1259 $sortLabel = htmlspecialchars($fCol);
1260 $sortLabel = '<i>[' . rtrim(trim($sortLabel), ':') . ']</i>';
1261 }
1262
1263 if ($this->table && is_array($currentIdList)) {
1264 // If the numeric clipboard pads are selected, show duplicate sorting link:
1265 if ($this->clipNumPane()) {
1266 $theData[$fCol] .= '<a class="btn btn-default" href="' . htmlspecialchars($this->listURL('', '-1') . '&duplicateField=' . $fCol)
1267 . '" title="' . htmlspecialchars($lang->getLL('clip_duplicates')) . '">'
1268 . $this->iconFactory->getIcon('actions-document-duplicates-select', Icon::SIZE_SMALL)->render() . '</a>';
1269 }
1270 // If the table can be edited, add link for editing THIS field for all
1271 // listed records:
1272 if ($this->isEditable($table) && $permsEdit && $GLOBALS['TCA'][$table]['columns'][$fCol]) {
1273 $entityIdentifiers = 'entityIdentifiers';
1274 if ($this->clipNumPane()) {
1275 $entityIdentifiers .= ':editList';
1276 }
1277 $editUri = BackendUtility::getModuleUrl('record_edit')
1278 . '&edit[' . $table . '][{' . $entityIdentifiers . '}]=edit'
1279 . '&columnsOnly=' . $fCol
1280 . '&returnUrl={T3_THIS_LOCATION}';
1281 $iTitle = sprintf($lang->getLL('editThisColumn'), $sortLabel);
1282 $theData[$fCol] .= '<a class="btn btn-default t3js-record-edit-multiple" href="#"'
1283 . ' data-uri="' . htmlspecialchars($editUri) . '"'
1284 . ' title="' . htmlspecialchars($iTitle) . '">'
1285 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1286 }
1287 if (strlen($theData[$fCol]) > 0) {
1288 $theData[$fCol] = '<div class="btn-group" role="group">' . $theData[$fCol] . '</div> ';
1289 }
1290 }
1291 $theData[$fCol] .= $this->addSortLink($sortLabel, $fCol, $table);
1292 }
1293 }
1294 /**
1295 * @hook renderListHeader: Allows to change the contents of columns/cells of the Web>List table headers
1296 * @usage Above each listed table in Web>List a header row is shown.
1297 * Containing the labels of all shown fields and additional icons to create new records for this
1298 * table or perform special clipboard tasks like mark and copy all listed records to clipboard, etc.
1299 */
1300 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1301 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $className) {
1302 $hookObject = GeneralUtility::makeInstance($className);
1303 if (!$hookObject instanceof RecordListHookInterface) {
1304 throw new \UnexpectedValueException($className . ' must implement interface ' . RecordListHookInterface::class, 1195567855);
1305 }
1306 $theData = $hookObject->renderListHeader($table, $currentIdList, $theData, $this);
1307 }
1308 }
1309
1310 // Create and return header table row:
1311 return '<thead>' . $this->addElement(1, $icon, $theData, '', '', '', 'th') . '</thead>';
1312 }
1313
1314 /**
1315 * Get pointer for first element on the page
1316 *
1317 * @param int $page Page number starting with 1
1318 * @return int Pointer to first element on the page (starting with 0)
1319 */
1320 protected function getPointerForPage($page)
1321 {
1322 return ($page - 1) * $this->iLimit;
1323 }
1324
1325 /**
1326 * Creates a page browser for tables with many records
1327 *
1328 * @param string $renderPart Distinguish between 'top' and 'bottom' part of the navigation (above or below the records)
1329 * @return string Navigation HTML
1330 */
1331 protected function renderListNavigation($renderPart = 'top')
1332 {
1333 $totalPages = ceil($this->totalItems / $this->iLimit);
1334 // Show page selector if not all records fit into one page
1335 if ($totalPages <= 1) {
1336 return '';
1337 }
1338 $content = '';
1339 $listURL = $this->listURL('', $this->table);
1340 // 1 = first page
1341 // 0 = first element
1342 $currentPage = floor($this->firstElementNumber / $this->iLimit) + 1;
1343 // Compile first, previous, next, last and refresh buttons
1344 if ($currentPage > 1) {
1345 $labelFirst = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:first'));
1346 $labelPrevious = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:previous'));
1347 $first = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage(1) . '" title="' . $labelFirst . '">'
1348 . $this->iconFactory->getIcon('actions-view-paging-first', Icon::SIZE_SMALL)->render() . '</a></li>';
1349 $previous = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage - 1) . '" title="' . $labelPrevious . '">'
1350 . $this->iconFactory->getIcon('actions-view-paging-previous', Icon::SIZE_SMALL)->render() . '</a></li>';
1351 } else {
1352 $first = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-first', Icon::SIZE_SMALL)->render() . '</span></li>';
1353 $previous = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-previous', Icon::SIZE_SMALL)->render() . '</span></li>';
1354 }
1355 if ($currentPage < $totalPages) {
1356 $labelNext = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:next'));
1357 $labelLast = htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:last'));
1358 $next = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($currentPage + 1) . '" title="' . $labelNext . '">'
1359 . $this->iconFactory->getIcon('actions-view-paging-next', Icon::SIZE_SMALL)->render() . '</a></li>';
1360 $last = '<li><a href="' . $listURL . '&pointer=' . $this->getPointerForPage($totalPages) . '" title="' . $labelLast . '">'
1361 . $this->iconFactory->getIcon('actions-view-paging-last', Icon::SIZE_SMALL)->render() . '</a></li>';
1362 } else {
1363 $next = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-next', Icon::SIZE_SMALL)->render() . '</span></li>';
1364 $last = '<li class="disabled"><span>' . $this->iconFactory->getIcon('actions-view-paging-last', Icon::SIZE_SMALL)->render() . '</span></li>';
1365 }
1366 $reload = '<li><a href="#" onclick="document.dblistForm.action=' . GeneralUtility::quoteJSvalue($listURL
1367 . '&pointer=') . '+calculatePointer(document.getElementById(' . GeneralUtility::quoteJSvalue('jumpPage-' . $renderPart)
1368 . ').value); document.dblistForm.submit(); return true;" title="'
1369 . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_common.xlf:reload')) . '">'
1370 . $this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render() . '</a></li>';
1371 if ($renderPart === 'top') {
1372 // Add js to traverse a page select input to a pointer value
1373 $content = '
1374 <script type="text/javascript">
1375 /*<![CDATA[*/
1376 function calculatePointer(page) {
1377 if (page > ' . $totalPages . ') {
1378 page = ' . $totalPages . ';
1379 }
1380 if (page < 1) {
1381 page = 1;
1382 }
1383 return (page - 1) * ' . $this->iLimit . ';
1384 }
1385 /*]]>*/
1386 </script>
1387 ';
1388 }
1389 $pageNumberInput = '
1390 <input type="number" min="1" max="' . $totalPages . '" value="' . $currentPage . '" size="3" class="form-control input-sm paginator-input" id="jumpPage-' . $renderPart . '" name="jumpPage-'
1391 . $renderPart . '" onkeyup="if (event.keyCode == 13) { document.dblistForm.action=' . GeneralUtility::quoteJSvalue($listURL
1392 . '&pointer=') . '+calculatePointer(this.value); document.dblistForm.submit(); } return true;" />
1393 ';
1394 $pageIndicatorText = sprintf(
1395 $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_mod_web_list.xlf:pageIndicator'),
1396 $pageNumberInput,
1397 $totalPages
1398 );
1399 $pageIndicator = '<li><span>' . $pageIndicatorText . '</span></li>';
1400 if ($this->totalItems > $this->firstElementNumber + $this->iLimit) {
1401 $lastElementNumber = $this->firstElementNumber + $this->iLimit;
1402 } else {
1403 $lastElementNumber = $this->totalItems;
1404 }
1405 $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>';
1406
1407 $titleColumn = $this->fieldArray[0];
1408 $data = [
1409 $titleColumn => $content . '
1410 <nav class="pagination-wrap">
1411 <ul class="pagination pagination-block">
1412 ' . $first . '
1413 ' . $previous . '
1414 ' . $rangeIndicator . '
1415 ' . $pageIndicator . '
1416 ' . $next . '
1417 ' . $last . '
1418 ' . $reload . '
1419 </ul>
1420 </nav>
1421 '
1422 ];
1423 return $this->addElement(1, '', $data);
1424 }
1425
1426 /*********************************
1427 *
1428 * Rendering of various elements
1429 *
1430 *********************************/
1431
1432 /**
1433 * Creates the control panel for a single record in the listing.
1434 *
1435 * @param string $table The table
1436 * @param mixed[] $row The record for which to make the control panel.
1437 * @throws \UnexpectedValueException
1438 * @return string HTML table with the control panel (unless disabled)
1439 */
1440 public function makeControl($table, $row)
1441 {
1442 $module = $this->getModule();
1443 $rowUid = $row['uid'];
1444 if (ExtensionManagementUtility::isLoaded('version') && isset($row['_ORIG_uid'])) {
1445 $rowUid = $row['_ORIG_uid'];
1446 }
1447 $cells = [
1448 'primary' => [],
1449 'secondary' => []
1450 ];
1451 // If the listed table is 'pages' we have to request the permission settings for each page:
1452 $localCalcPerms = 0;
1453 if ($table === 'pages') {
1454 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $row['uid']));
1455 }
1456 $permsEdit = $table === 'pages'
1457 && $this->getBackendUserAuthentication()->checkLanguageAccess(0)
1458 && $localCalcPerms & Permission::PAGE_EDIT
1459 || $table !== 'pages'
1460 && $this->calcPerms & Permission::CONTENT_EDIT
1461 && $this->getBackendUserAuthentication()->recordEditAccessInternals($table, $row);
1462 $permsEdit = $this->overlayEditLockPermissions($table, $row, $permsEdit);
1463 // "Show" link (only pages and tt_content elements)
1464 if ($table === 'pages' || $table === 'tt_content') {
1465 $viewAction = '<a class="btn btn-default" href="#" onclick="'
1466 . htmlspecialchars(
1467 BackendUtility::viewOnClick(
1468 ($table === 'tt_content' ? $this->id : $row['uid']),
1469 '',
1470 null,
1471 ($table === 'tt_content' ? '#c' . $row['uid'] : '')
1472 )
1473 ) . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.showPage')) . '">';
1474 if ($table === 'pages') {
1475 $viewAction .= $this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL)->render();
1476 } else {
1477 $viewAction .= $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render();
1478 }
1479 $viewAction .= '</a>';
1480 $this->addActionToCellGroup($cells, $viewAction, 'view');
1481 }
1482 // "Edit" link: ( Only if permissions to edit the page-record of the content of the parent page ($this->id)
1483 if ($permsEdit) {
1484 $params = '&edit[' . $table . '][' . $row['uid'] . ']=edit';
1485 $iconIdentifier = 'actions-open';
1486 if ($table === 'pages') {
1487 $iconIdentifier = 'actions-page-open';
1488 }
1489 $overlayIdentifier = !$this->isEditable($table) ? 'overlay-readonly' : null;
1490 $editAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1491 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('edit')) . '">' . $this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL, $overlayIdentifier)->render() . '</a>';
1492 } else {
1493 $editAction = $this->spaceIcon;
1494 }
1495 $this->addActionToCellGroup($cells, $editAction, 'edit');
1496 // "Info": (All records)
1497 $onClick = 'top.launchView(' . GeneralUtility::quoteJSvalue($table) . ', ' . (int)$row['uid'] . '); return false;';
1498 $viewBigAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('showInfo')) . '">'
1499 . $this->iconFactory->getIcon('actions-document-info', Icon::SIZE_SMALL)->render() . '</a>';
1500 $this->addActionToCellGroup($cells, $viewBigAction, 'viewBig');
1501 // "Move" wizard link for pages/tt_content elements:
1502 if ($permsEdit && ($table === 'tt_content' || $table === 'pages')) {
1503 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('move_element') . '&table=' . $table . '&uid=' . $row['uid']) . ');';
1504 $linkTitleLL = htmlspecialchars($this->getLanguageService()->getLL('move_' . ($table === 'tt_content' ? 'record' : 'page')));
1505 $icon = ($table === 'pages' ? $this->iconFactory->getIcon('actions-page-move', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-document-move', Icon::SIZE_SMALL));
1506 $moveAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="' . $linkTitleLL . '">' . $icon->render() . '</a>';
1507 $this->addActionToCellGroup($cells, $moveAction, 'move');
1508 }
1509 // If the table is NOT a read-only table, then show these links:
1510 if ($this->isEditable($table)) {
1511 // "Revert" link (history/undo)
1512 $moduleUrl = BackendUtility::getModuleUrl('record_history', ['element' => $table . ':' . $row['uid']]);
1513 $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($moduleUrl) . ',\'#latest\');';
1514 $historyAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
1515 . htmlspecialchars($this->getLanguageService()->getLL('history')) . '">'
1516 . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . '</a>';
1517 $this->addActionToCellGroup($cells, $historyAction, 'history');
1518 // Versioning:
1519 if (ExtensionManagementUtility::isLoaded('version') && !ExtensionManagementUtility::isLoaded('workspaces')) {
1520 $vers = BackendUtility::selectVersionsOfRecord($table, $row['uid'], 'uid', $this->getBackendUserAuthentication()->workspace, false, $row);
1521 // If table can be versionized.
1522 if (is_array($vers)) {
1523 $href = BackendUtility::getModuleUrl('web_txversionM1', [
1524 'table' => $table, 'uid' => $row['uid']
1525 ]);
1526 $versionAction = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="'
1527 . htmlspecialchars($this->getLanguageService()->getLL('displayVersions')) . '">'
1528 . $this->iconFactory->getIcon('actions-version-page-open', Icon::SIZE_SMALL)->render() . '</a>';
1529 $this->addActionToCellGroup($cells, $versionAction, 'version');
1530 }
1531 }
1532 // "Edit Perms" link:
1533 if ($table === 'pages' && $this->getBackendUserAuthentication()->check('modules', 'system_BeuserTxPermission') && ExtensionManagementUtility::isLoaded('beuser')) {
1534 $href = BackendUtility::getModuleUrl('system_BeuserTxPermission') . '&id=' . $row['uid'] . '&returnId=' . $row['uid'] . '&tx_beuser_system_beusertxpermission[action]=edit';
1535 $permsAction = '<a class="btn btn-default" href="' . htmlspecialchars($href) . '" title="'
1536 . htmlspecialchars($this->getLanguageService()->getLL('permissions')) . '">'
1537 . $this->iconFactory->getIcon('actions-lock', Icon::SIZE_SMALL)->render() . '</a>';
1538 $this->addActionToCellGroup($cells, $permsAction, 'perms');
1539 }
1540 // "New record after" link (ONLY if the records in the table are sorted by a "sortby"-row
1541 // or if default values can depend on previous record):
1542 if (($GLOBALS['TCA'][$table]['ctrl']['sortby'] || $GLOBALS['TCA'][$table]['ctrl']['useColumnsForDefaultValues']) && $permsEdit) {
1543 if ($table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT || $table === 'pages' && $this->calcPerms & Permission::PAGE_NEW) {
1544 if ($this->showNewRecLink($table)) {
1545 $params = '&edit[' . $table . '][' . -($row['_MOVE_PLH'] ? $row['_MOVE_PLH_uid'] : $row['uid']) . ']=new';
1546 $icon = ($table === 'pages' ? $this->iconFactory->getIcon('actions-page-new', Icon::SIZE_SMALL) : $this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL));
1547 $titleLabel = 'new';
1548 if ($GLOBALS['TCA'][$table]['ctrl']['sortby']) {
1549 $titleLabel .= ($table === 'pages' ? 'Page' : 'Record');
1550 }
1551 $newAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars(BackendUtility::editOnClick($params, '', -1))
1552 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL($titleLabel)) . '">'
1553 . $icon->render() . '</a>';
1554 $this->addActionToCellGroup($cells, $newAction, 'new');
1555 }
1556 }
1557 }
1558 // "Up/Down" links
1559 if ($permsEdit && $GLOBALS['TCA'][$table]['ctrl']['sortby'] && !$this->sortField && !$this->searchLevels) {
1560 if (isset($this->currentTable['prev'][$row['uid']])) {
1561 // Up
1562 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prev'][$row['uid']];
1563 $moveUpAction = '<a class="btn btn-default" href="#" onclick="'
1564 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
1565 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveUp')) . '">'
1566 . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
1567 } else {
1568 $moveUpAction = $this->spaceIcon;
1569 }
1570 $this->addActionToCellGroup($cells, $moveUpAction, 'moveUp');
1571
1572 if ($this->currentTable['next'][$row['uid']]) {
1573 // Down
1574 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['next'][$row['uid']];
1575 $moveDownAction = '<a class="btn btn-default" href="#" onclick="'
1576 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
1577 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('moveDown')) . '">'
1578 . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
1579 } else {
1580 $moveDownAction = $this->spaceIcon;
1581 }
1582 $this->addActionToCellGroup($cells, $moveDownAction, 'moveDown');
1583 }
1584 // "Hide/Unhide" links:
1585 $hiddenField = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
1586
1587 if (
1588 !empty($GLOBALS['TCA'][$table]['columns'][$hiddenField])
1589 && (empty($GLOBALS['TCA'][$table]['columns'][$hiddenField]['exclude'])
1590 || $this->getBackendUserAuthentication()->check('non_exclude_fields', $table . ':' . $hiddenField))
1591 ) {
1592 if (!$permsEdit || $this->isRecordCurrentBackendUser($table, $row)) {
1593 $hideAction = $this->spaceIcon;
1594 } else {
1595 $hideTitle = htmlspecialchars($this->getLanguageService()->getLL('hide' . ($table === 'pages' ? 'Page' : '')));
1596 $unhideTitle = htmlspecialchars($this->getLanguageService()->getLL('unHide' . ($table === 'pages' ? 'Page' : '')));
1597 if ($row[$hiddenField]) {
1598 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=0';
1599 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="hidden" href="#"'
1600 . ' data-params="' . htmlspecialchars($params) . '"'
1601 . ' title="' . $unhideTitle . '"'
1602 . ' data-toggle-title="' . $hideTitle . '">'
1603 . $this->iconFactory->getIcon('actions-edit-unhide', Icon::SIZE_SMALL)->render() . '</a>';
1604 } else {
1605 $params = 'data[' . $table . '][' . $rowUid . '][' . $hiddenField . ']=1';
1606 $hideAction = '<a class="btn btn-default t3js-record-hide" data-state="visible" href="#"'
1607 . ' data-params="' . htmlspecialchars($params) . '"'
1608 . ' title="' . $hideTitle . '"'
1609 . ' data-toggle-title="' . $unhideTitle . '">'
1610 . $this->iconFactory->getIcon('actions-edit-hide', Icon::SIZE_SMALL)->render() . '</a>';
1611 }
1612 }
1613 $this->addActionToCellGroup($cells, $hideAction, 'hide');
1614 }
1615 // "Delete" link:
1616 $disableDeleteTS = $this->getBackendUserAuthentication()->getTSConfig('options.disableDelete');
1617 $disableDelete = (bool) trim(isset($disableDeleteTS['properties'][$table]) ? $disableDeleteTS['properties'][$table] : $disableDeleteTS['value']);
1618 if ($permsEdit && !$disableDelete && ($table === 'pages' && $localCalcPerms & Permission::PAGE_DELETE || $table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT)) {
1619 // Check if the record version is in "deleted" state, because that will switch the action to "restore"
1620 if ($this->getBackendUserAuthentication()->workspace > 0 && isset($row['t3ver_state']) && (int)$row['t3ver_state'] === 2) {
1621 $actionName = 'restore';
1622 $refCountMsg = '';
1623 } else {
1624 $actionName = 'delete';
1625 $refCountMsg = BackendUtility::referenceCount(
1626 $table,
1627 $row['uid'],
1628 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.referencesToRecord'),
1629 $this->getReferenceCount($table, $row['uid'])) . BackendUtility::translationCount($table, $row['uid'],
1630 ' ' . $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.translationsOfRecord')
1631 );
1632 }
1633
1634 if ($this->isRecordCurrentBackendUser($table, $row)) {
1635 $deleteAction = $this->spaceIcon;
1636 } else {
1637 $title = BackendUtility::getRecordTitle($table, $row);
1638 $warningText = $this->getLanguageService()->getLL($actionName . 'Warning') . ' "' . $title . '" ' . '[' . $table . ':' . $row['uid'] . ']' . $refCountMsg;
1639
1640 $params = 'cmd[' . $table . '][' . $row['uid'] . '][delete]=1';
1641 $icon = $this->iconFactory->getIcon('actions-edit-' . $actionName, Icon::SIZE_SMALL)->render();
1642 $linkTitle = htmlspecialchars($this->getLanguageService()->getLL($actionName));
1643 $deleteAction = '<a class="btn btn-default t3js-record-delete" href="#" '
1644 . ' data-l10parent="' . htmlspecialchars($row['l10n_parent']) . '"'
1645 . ' data-params="' . htmlspecialchars($params) . '" data-title="' . htmlspecialchars($title) . '"'
1646 . ' data-message="' . htmlspecialchars($warningText) . '" title="' . $linkTitle . '"'
1647 . '>' . $icon . '</a>';
1648 }
1649 } else {
1650 $deleteAction = $this->spaceIcon;
1651 }
1652 $this->addActionToCellGroup($cells, $deleteAction, 'delete');
1653 // "Levels" links: Moving pages into new levels...
1654 if ($permsEdit && $table === 'pages' && !$this->searchLevels) {
1655 // Up (Paste as the page right after the current parent page)
1656 if ($this->calcPerms & Permission::PAGE_NEW) {
1657 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . -$this->id;
1658 $moveLeftAction = '<a class="btn btn-default" href="#" onclick="'
1659 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
1660 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('prevLevel')) . '">'
1661 . $this->iconFactory->getIcon('actions-move-left', Icon::SIZE_SMALL)->render() . '</a>';
1662 $this->addActionToCellGroup($cells, $moveLeftAction, 'moveLeft');
1663 }
1664 // Down (Paste as subpage to the page right above)
1665 if ($this->currentTable['prevUid'][$row['uid']]) {
1666 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $this->currentTable['prevUid'][$row['uid']]));
1667 if ($localCalcPerms & Permission::PAGE_NEW) {
1668 $params = '&cmd[' . $table . '][' . $row['uid'] . '][move]=' . $this->currentTable['prevUid'][$row['uid']];
1669 $moveRightAction = '<a class="btn btn-default" href="#" onclick="'
1670 . htmlspecialchars('return jumpToUrl(' . BackendUtility::getLinkToDataHandlerAction($params, -1) . ');')
1671 . '" title="' . htmlspecialchars($this->getLanguageService()->getLL('nextLevel')) . '">'
1672 . $this->iconFactory->getIcon('actions-move-right', Icon::SIZE_SMALL)->render() . '</a>';
1673 } else {
1674 $moveRightAction = $this->spaceIcon;
1675 }
1676 } else {
1677 $moveRightAction = $this->spaceIcon;
1678 }
1679 $this->addActionToCellGroup($cells, $moveRightAction, 'moveRight');
1680 }
1681 }
1682 /**
1683 * @hook recStatInfoHooks: Allows to insert HTML before record icons on various places
1684 */
1685 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1686 $stat = '';
1687 $_params = [$table, $row['uid']];
1688 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1689 $stat .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1690 }
1691 $this->addActionToCellGroup($cells, $stat, 'stat');
1692 }
1693 /**
1694 * @hook makeControl: Allows to change control icons of records in list-module
1695 * @usage This hook method gets passed the current $cells array as third parameter.
1696 * This array contains values for the icons/actions generated for each record in Web>List.
1697 * Each array entry is accessible by an index-key.
1698 * The order of the icons is depending on the order of those array entries.
1699 */
1700 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1701 // for compatibility reason, we move all icons to the rootlevel
1702 // before calling the hooks
1703 foreach ($cells as $section => $actions) {
1704 foreach ($actions as $actionKey => $action) {
1705 $cells[$actionKey] = $action;
1706 }
1707 }
1708 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $className) {
1709 $hookObject = GeneralUtility::makeInstance($className);
1710 if (!$hookObject instanceof RecordListHookInterface) {
1711 throw new \UnexpectedValueException($className . ' must implement interface ' . RecordListHookInterface::class, 1195567840);
1712 }
1713 $cells = $hookObject->makeControl($table, $row, $cells, $this);
1714 }
1715 // now sort icons again into primary and secondary sections
1716 // after all hooks are processed
1717 $hookCells = $cells;
1718 foreach ($hookCells as $key => $value) {
1719 if ($key === 'primary' || $key === 'secondary') {
1720 continue;
1721 }
1722 $this->addActionToCellGroup($cells, $value, $key);
1723 }
1724 }
1725 $output = '<!-- CONTROL PANEL: ' . $table . ':' . $row['uid'] . ' -->';
1726 foreach ($cells as $classification => $actions) {
1727 $visibilityClass = ($classification !== 'primary' && !$module->MOD_SETTINGS['bigControlPanel'] ? 'collapsed' : 'expanded');
1728 if ($visibilityClass === 'collapsed') {
1729 $cellOutput = '';
1730 foreach ($actions as $action) {
1731 $cellOutput .= $action;
1732 }
1733 $output .= ' <div class="btn-group">' .
1734 '<span id="actions_' . $table . '_' . $row['uid'] . '" class="btn-group collapse collapse-horizontal width">' . $cellOutput . '</span>' .
1735 '<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>' .
1736 '</div>';
1737 } else {
1738 $output .= ' <div class="btn-group" role="group">' . implode('', $actions) . '</div>';
1739 }
1740 }
1741 return $output;
1742 }
1743
1744 /**
1745 * Creates the clipboard panel for a single record in the listing.
1746 *
1747 * @param string $table The table
1748 * @param mixed[] $row The record for which to make the clipboard panel.
1749 * @throws \UnexpectedValueException
1750 * @return string HTML table with the clipboard panel (unless disabled)
1751 */
1752 public function makeClip($table, $row)
1753 {
1754 // Return blank, if disabled:
1755 if (!$this->getModule()->MOD_SETTINGS['clipBoard']) {
1756 return '';
1757 }
1758 $cells = [];
1759 $cells['pasteAfter'] = ($cells['pasteInto'] = $this->spaceIcon);
1760 //enables to hide the copy, cut and paste icons for localized records - doesn't make much sense to perform these options for them
1761 $isL10nOverlay = $this->localizationView && $table !== 'pages_language_overlay' && $row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0;
1762 // Return blank, if disabled:
1763 // Whether a numeric clipboard pad is active or the normal pad we will see different content of the panel:
1764 // For the "Normal" pad:
1765 if ($this->clipObj->current === 'normal') {
1766 // Show copy/cut icons:
1767 $isSel = (string)$this->clipObj->isSelected($table, $row['uid']);
1768 if ($isL10nOverlay || !$this->overlayEditLockPermissions($table, $row)) {
1769 $cells['copy'] = $this->spaceIcon;
1770 $cells['cut'] = $this->spaceIcon;
1771 } else {
1772 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy', Icon::SIZE_SMALL);
1773 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut', Icon::SIZE_SMALL);
1774
1775 if ($isSel === 'copy') {
1776 $copyIcon = $this->iconFactory->getIcon('actions-edit-copy-release', Icon::SIZE_SMALL);
1777 } elseif ($isSel === 'cut') {
1778 $cutIcon = $this->iconFactory->getIcon('actions-edit-cut-release', Icon::SIZE_SMALL);
1779 }
1780
1781 $cells['copy'] = '<a class="btn btn-default" href="#" onclick="'
1782 . htmlspecialchars('return jumpSelf(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $row['uid'], 1, ($isSel === 'copy'), ['returnUrl' => ''])) . ');')
1783 . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.copy')) . '">'
1784 . $copyIcon->render() . '</a>';
1785
1786 // Check permission to cut page or content
1787 if ($table === 'pages') {
1788 $localCalcPerms = $this->getBackendUserAuthentication()->calcPerms(BackendUtility::getRecord('pages', $row['uid']));
1789 $permsEdit = $localCalcPerms & Permission::PAGE_EDIT;
1790 } else {
1791 $permsEdit = $this->calcPerms & Permission::CONTENT_EDIT;
1792 }
1793 $permsEdit = $this->overlayEditLockPermissions($table, $row, $permsEdit);
1794
1795 // If the listed table is 'pages' we have to request the permission settings for each page:
1796 if ($table === 'pages') {
1797 if ($permsEdit) {
1798 $cells['cut'] = '<a class="btn btn-default" href="#" onclick="'
1799 . htmlspecialchars('return jumpSelf(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel === 'cut'), ['returnUrl' => ''])) . ');')
1800 . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut')) . '">'
1801 . $cutIcon->render() . '</a>';
1802 } else {
1803 $cells['cut'] = $this->spaceIcon;
1804 }
1805 } else {
1806 if ($table !== 'pages' && $this->calcPerms & Permission::CONTENT_EDIT) {
1807 $cells['cut'] = '<a class="btn btn-default" href="#" onclick="'
1808 . htmlspecialchars('return jumpSelf(' . GeneralUtility::quoteJSvalue($this->clipObj->selUrlDB($table, $row['uid'], 0, ($isSel === 'cut'), ['returnUrl' => ''])) . ');')
1809 . '" title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:cm.cut')) . '">'
1810 . $cutIcon->render() . '</a>';
1811 } else {
1812 $cells['cut'] = $this->spaceIcon;
1813 }
1814 }
1815 }
1816 } else {
1817 // For the numeric clipboard pads (showing checkboxes where one can select elements on/off)
1818 // Setting name of the element in ->CBnames array:
1819 $n = $table . '|' . $row['uid'];
1820 $this->CBnames[] = $n;
1821 // Check if the current element is selected and if so, prepare to set the checkbox as selected:
1822 $checked = $this->clipObj->isSelected($table, $row['uid']) ? 'checked="checked" ' : '';
1823 // If the "duplicateField" value is set then select all elements which are duplicates...
1824 if ($this->duplicateField && isset($row[$this->duplicateField])) {
1825 $checked = '';
1826 if (in_array($row[$this->duplicateField], $this->duplicateStack)) {
1827 $checked = 'checked="checked" ';
1828 }
1829 $this->duplicateStack[] = $row[$this->duplicateField];
1830 }
1831 // Adding the checkbox to the panel:
1832 $cells['select'] = $isL10nOverlay
1833 ? $this->spaceIcon
1834 : '<input type="hidden" name="CBH[' . $n . ']" value="0" /><label class="btn btn-default btn-checkbox"><input type="checkbox"'
1835 . ' name="CBC[' . $n . ']" value="1" ' . $checked . '/><span class="t3-icon fa"></span></label>';
1836 }
1837 // Now, looking for selected elements from the current table:
1838 $elFromTable = $this->clipObj->elFromTable($table);
1839 if (!empty($elFromTable) && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
1840 // IF elements are found, they can be individually ordered and are not locked by editlock, then add a "paste after" icon:
1841 $cells['pasteAfter'] = $isL10nOverlay || !$this->overlayEditLockPermissions($table, $row)
1842 ? $this->spaceIcon
1843 : '<a class="btn btn-default t3js-modal-trigger"'
1844 . ' href="' . htmlspecialchars($this->clipObj->pasteUrl($table, -$row['uid'])) . '"'
1845 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteAfter')) . '"'
1846 . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteAfter')) . '"'
1847 . ' data-content="' . htmlspecialchars($this->clipObj->confirmMsgText($table, $row, 'after', $elFromTable)) . '"'
1848 . ' data-severity="warning">'
1849 . $this->iconFactory->getIcon('actions-document-paste-after', Icon::SIZE_SMALL)->render() . '</a>';
1850 }
1851 // Now, looking for elements in general:
1852 $elFromTable = $this->clipObj->elFromTable('');
1853 if ($table === 'pages' && !empty($elFromTable)) {
1854 $cells['pasteInto'] = '<a class="btn btn-default t3js-modal-trigger"'
1855 . ' href="' . htmlspecialchars($this->clipObj->pasteUrl('', $row['uid'])) . '"'
1856 . ' title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
1857 . ' data-title="' . htmlspecialchars($this->getLanguageService()->getLL('clip_pasteInto')) . '"'
1858 . ' data-content="' . htmlspecialchars($this->clipObj->confirmMsgText($table, $row, 'into', $elFromTable)) . '"'
1859 . ' data-severity="warning">'
1860 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render() . '</a>';
1861 }
1862 /**
1863 * @hook makeClip: Allows to change clip-icons of records in list-module
1864 * @usage This hook method gets passed the current $cells array as third parameter.
1865 * This array contains values for the clipboard icons generated for each record in Web>List.
1866 * Each array entry is accessible by an index-key.
1867 * The order of the icons is depending on the order of those array entries.
1868 */
1869 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'])) {
1870 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.db_list_extra.inc']['actions'] as $className) {
1871 $hookObject = GeneralUtility::makeInstance($className);
1872 if (!$hookObject instanceof RecordListHookInterface) {
1873 throw new \UnexpectedValueException($className . ' must implement interface ' . RecordListHookInterface::class, 1195567845);
1874 }
1875 $cells = $hookObject->makeClip($table, $row, $cells, $this);
1876 }
1877 }
1878 // Compile items into a DIV-element:
1879 return '<!-- CLIPBOARD PANEL: ' . $table . ':' . $row['uid'] . ' -->
1880 <div class="btn-group" role="group">' . implode('', $cells) . '</div>';
1881 }
1882
1883 /**
1884 * Creates the HTML for a reference count for the record with the UID $uid
1885 * in the table $tableName.
1886 *
1887 * @param string $tableName
1888 * @param int $uid
1889 * @return string HTML of reference a link, will be empty if there are no
1890 */
1891 protected function createReferenceHtml($tableName, $uid)
1892 {
1893 $referenceCount = GeneralUtility::makeInstance(ConnectionPool::class)
1894 ->getConnectionForTable('sys_refindex')
1895 ->count(
1896 '*',
1897 'sys_refindex',
1898 [
1899 'ref_table' => $tableName,
1900 'ref_uid' => (int)$uid,
1901 'deleted' => 0,
1902 ]
1903 );
1904
1905 return $this->generateReferenceToolTip(
1906 $referenceCount,
1907 GeneralUtility::quoteJSvalue($tableName) . ', ' . GeneralUtility::quoteJSvalue($uid)
1908 );
1909 }
1910
1911 /**
1912 * Creates the localization panel
1913 *
1914 * @param string $table The table
1915 * @param mixed[] $row The record for which to make the localization panel.
1916 * @return string[] Array with key 0/1 with content for column 1 and 2
1917 */
1918 public function makeLocalizationPanel($table, $row)
1919 {
1920 $out = [
1921 0 => '',
1922 1 => ''
1923 ];
1924 // Reset translations
1925 $this->translations = [];
1926
1927 // Language title and icon:
1928 $out[0] = $this->languageFlag($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']]);
1929 // Guard clause so we can quickly return if a record is localized to "all languages"
1930 // It should only be possible to localize a record off default (uid 0)
1931 // Reasoning: The Parent is for ALL languages... why overlay with a localization?
1932 if ((int)$row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] === -1) {
1933 return $out;
1934 }
1935
1936 $translations = $this->translateTools->translationInfo($table, $row['uid'], 0, $row, $this->selFieldList);
1937 if (is_array($translations)) {
1938 $this->translations = $translations['translations'];
1939 // Traverse page translations and add icon for each language that does NOT yet exist:
1940 $lNew = '';
1941 foreach ($this->pageOverlays as $lUid_OnPage => $lsysRec) {
1942 if ($this->isEditable($table) && !isset($translations['translations'][$lUid_OnPage]) && $this->getBackendUserAuthentication()->checkLanguageAccess($lUid_OnPage)) {
1943 $url = $this->listURL();
1944 $href = BackendUtility::getLinkToDataHandlerAction(
1945 '&cmd[' . $table . '][' . $row['uid'] . '][localize]=' . $lUid_OnPage,
1946 $url . '&justLocalized=' . rawurlencode($table . ':' . $row['uid'] . ':' . $lUid_OnPage)
1947 );
1948 $language = BackendUtility::getRecord('sys_language', $lUid_OnPage, 'title');
1949 if ($this->languageIconTitles[$lUid_OnPage]['flagIcon']) {
1950 $lC = $this->iconFactory->getIcon($this->languageIconTitles[$lUid_OnPage]['flagIcon'], Icon::SIZE_SMALL)->render();
1951 } else {
1952 $lC = $this->languageIconTitles[$lUid_OnPage]['title'];
1953 }
1954 $lC = '<a href="' . htmlspecialchars($href) . '" title="'
1955 . htmlspecialchars($language['title']) . '" class="btn btn-default">' . $lC . '</a> ';
1956 $lNew .= $lC;
1957 }
1958 }
1959 if ($lNew) {
1960 $out[1] .= $lNew;
1961 }
1962 } elseif ($row['l18n_parent']) {
1963 $out[0] = '&nbsp;&nbsp;&nbsp;&nbsp;' . $out[0];
1964 }
1965 return $out;
1966 }
1967
1968 /**
1969 * Creates a checkbox list for selecting fields to display from a table:
1970 *
1971 * @param string $table Table name
1972 * @param bool $formFields If TRUE, form-fields will be wrapped around the table.
1973 * @return string HTML table with the selector check box (name: displayFields['.$table.'][])
1974 */
1975 public function fieldSelectBox($table, $formFields = true)
1976 {
1977 $lang = $this->getLanguageService();
1978 // Init:
1979 $formElements = ['', ''];
1980 if ($formFields) {
1981 $formElements = ['<form action="' . htmlspecialchars($this->listURL()) . '" method="post" name="fieldSelectBox">', '</form>'];
1982 }
1983 // Load already selected fields, if any:
1984 $setFields = is_array($this->setFields[$table]) ? $this->setFields[$table] : [];
1985 // Request fields from table:
1986 $fields = $this->makeFieldList($table, false, true);
1987 // Add pseudo "control" fields
1988 $fields[] = '_PATH_';
1989 $fields[] = '_REF_';
1990 $fields[] = '_LOCALIZATION_';
1991 $fields[] = '_CONTROL_';
1992 $fields[] = '_CLIPBOARD_';
1993 // Create a checkbox for each field:
1994 $checkboxes = [];
1995 $checkAllChecked = true;
1996 $tsConfig = BackendUtility::getPagesTSconfig($this->id);
1997 $tsConfigOfTable = is_array($tsConfig['TCEFORM.'][$table . '.']) ? $tsConfig['TCEFORM.'][$table . '.'] : null;
1998 foreach ($fields as $fieldName) {
1999 // Hide field if hidden
2000 if ($tsConfigOfTable && is_array($tsConfigOfTable[$fieldName . '.']) && isset($tsConfigOfTable[$fieldName . '.']['disabled']) && (int)$tsConfigOfTable[$fieldName . '.']['disabled'] === 1) {
2001 continue;
2002 }
2003 // Determine, if checkbox should be checked
2004 if (in_array($fieldName, $setFields, true) || $fieldName === $this->fieldArray[0]) {
2005 $checked = ' checked="checked"';
2006 } else {
2007 $checkAllChecked = false;
2008 $checked = '';
2009 }
2010 // Field label
2011 $fieldLabel = is_array($GLOBALS['TCA'][$table]['columns'][$fieldName])
2012 ? rtrim($lang->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label']), ':')
2013 : '';
2014 $checkboxes[] = '<tr><td class="col-checkbox"><input type="checkbox" id="check-' . $fieldName . '" name="displayFields['
2015 . $table . '][]" value="' . $fieldName . '" ' . $checked
2016 . ($fieldName === $this->fieldArray[0] ? ' disabled="disabled"' : '') . '></td><td class="col-title">'
2017 . '<label class="label-block" for="check-' . $fieldName . '">' . htmlspecialchars($fieldLabel) . ' <span class="text-muted text-monospace">[' . htmlspecialchars($fieldName) . ']</span></label></td></tr>';
2018 }
2019 // Table with the field selector::
2020 $content = $formElements[0] . '
2021 <input type="hidden" name="displayFields[' . $table . '][]" value="">
2022 <div class="table-fit table-scrollable">
2023 <table border="0" cellpadding="0" cellspacing="0" class="table table-transparent table-hover">
2024 <thead>
2025 <tr>
2026 <th class="col-checkbox checkbox" colspan="2">
2027 <label><input type="checkbox" class="checkbox checkAll" ' . ($checkAllChecked ? ' checked="checked"' : '') . '>
2028 ' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.toggleall')) . '</label>
2029 </th>
2030 </tr>
2031 </thead>
2032 <tbody>
2033 ' . implode('', $checkboxes) . '
2034 </tbody>
2035 </table>
2036 </div>
2037 <input type="submit" name="search" class="btn btn-default" value="'
2038 . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.setFields')) . '"/>
2039 ' . $formElements[1];
2040 return '<div class="fieldSelectBox">' . $content . '</div>';
2041 }
2042
2043 /*********************************
2044 *
2045 * Helper functions
2046 *
2047 *********************************/
2048 /**
2049 * Creates a link around $string. The link contains an onclick action
2050 * which submits the script with some clipboard action.
2051 * Currently, this is used for setting elements / delete elements.
2052 *
2053 * @param string $string The HTML content to link (image/text)
2054 * @param string $table Table name
2055 * @param string $cmd Clipboard command (eg. "setCB" or "delete")
2056 * @param string $warning Warning text, if any ("delete" uses this for confirmation
2057 * @param string $title title attribute for the anchor
2058 * @return string <a> tag wrapped link.
2059 */
2060 public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '', $title = '')
2061 {
2062 $jsCode = 'document.dblistForm.cmd.value=' . GeneralUtility::quoteJSvalue($cmd)
2063 . ';document.dblistForm.cmd_table.value='
2064 . GeneralUtility::quoteJSvalue($table)
2065 . ';document.dblistForm.submit();';
2066
2067 $attributes = [];
2068 if ($title !== '') {
2069 $attributes['title'] = $title;
2070 }
2071 if ($warning) {
2072 $attributes['class'] = 'btn btn-default t3js-modal-trigger';
2073 $attributes['data-href'] = 'javascript:' . $jsCode;
2074 $attributes['data-severity'] = 'warning';
2075 $attributes['data-title'] = $title;
2076 $attributes['data-content'] = $warning;
2077 } else {
2078 $attributes['class'] = 'btn btn-default';
2079 $attributes['onclick'] = $jsCode . 'return false;';
2080 }
2081
2082 $attributesString = '';
2083 foreach ($attributes as $key => $value) {
2084 $attributesString .= ' ' . $key . '="' . htmlspecialchars($value) . '"';
2085 }
2086 return '<a href="#" ' . $attributesString . '>' . $string . '</a>';
2087 }
2088
2089 /**
2090 * Returns TRUE if a numeric clipboard pad is selected/active
2091 *
2092 * @return bool
2093 */
2094 public function clipNumPane()
2095 {
2096 return in_array('_CLIPBOARD_', $this->fieldArray) && $this->clipObj->current !== 'normal';
2097 }
2098
2099 /**
2100 * Creates a sort-by link on the input string ($code).
2101 * It will automatically detect if sorting should be ascending or descending depending on $this->sortRev.
2102 * Also some fields will not be possible to sort (including if single-table-view is disabled).
2103 *
2104 * @param string $code The string to link (text)
2105 * @param string $field The fieldname represented by the title ($code)
2106 * @param string $table Table name
2107 * @return string Linked $code variable
2108 */
2109 public function addSortLink($code, $field, $table)
2110 {
2111 // Certain circumstances just return string right away (no links):
2112 if ($field === '_CONTROL_' || $field === '_LOCALIZATION_' || $field === '_CLIPBOARD_' || $field === '_REF_' || $this->disableSingleTableView) {
2113 return $code;
2114 }
2115 // If "_PATH_" (showing record path) is selected, force sorting by pid field (will at least group the records!)
2116 if ($field === '_PATH_') {
2117 $field = 'pid';
2118 }
2119 // Create the sort link:
2120 $sortUrl = $this->listURL('', '-1', 'sortField,sortRev,table,firstElementNumber') . '&table=' . $table
2121 . '&sortField=' . $field . '&sortRev=' . ($this->sortRev || $this->sortField != $field ? 0 : 1);
2122 $sortArrow = $this->sortField === $field
2123 ? $this->iconFactory->getIcon('status-status-sorting-' . ($this->sortRev ? 'desc' : 'asc'), Icon::SIZE_SMALL)->render()
2124 : '';
2125 // Return linked field:
2126 return '<a href="' . htmlspecialchars($sortUrl) . '">' . $code . $sortArrow . '</a>';
2127 }
2128
2129 /**
2130 * Returns the path for a certain pid
2131 * The result is cached internally for the session, thus you can call
2132 * this function as much as you like without performance problems.
2133 *
2134 * @param int $pid The page id for which to get the path
2135 * @return mixed[] The path.
2136 */
2137 public function recPath($pid)
2138 {
2139 if (!isset($this->recPath_cache[$pid])) {
2140 $this->recPath_cache[$pid] = BackendUtility::getRecordPath($pid, $this->perms_clause, 20);
2141 }
2142 return $this->recPath_cache[$pid];
2143 }
2144
2145 /**
2146 * Returns TRUE if a link for creating new records should be displayed for $table
2147 *
2148 * @param string $table Table name
2149 * @return bool Returns TRUE if a link for creating new records should be displayed for $table
2150 * @see \TYPO3\CMS\Backend\Controller\NewRecordController::showNewRecLink
2151 */
2152 public function showNewRecLink($table)
2153 {
2154 // No deny/allow tables are set:
2155 if (empty($this->allowedNewTables) && empty($this->deniedNewTables)) {
2156 return true;
2157 }
2158 return !in_array($table, $this->deniedNewTables)
2159 && (empty($this->allowedNewTables) || in_array($table, $this->allowedNewTables));
2160 }
2161
2162 /**
2163 * Creates the "&returnUrl" parameter for links - this is used when the script links
2164 * to other scripts and passes its own URL with the link so other scripts can return to the listing again.
2165 * Uses REQUEST_URI as value.
2166 *
2167 * @return string
2168 */
2169 public function makeReturnUrl()
2170 {
2171 return '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
2172 }
2173
2174 /************************************
2175 *
2176 * CSV related functions
2177 *
2178 ************************************/
2179 /**
2180 * Initializes internal csvLines array with the header of field names
2181 */
2182 protected function initCSV()
2183 {
2184 $this->addHeaderRowToCSV();
2185 }
2186
2187 /**
2188 * Add header line with field names as CSV line
2189 */
2190 protected function addHeaderRowToCSV()
2191 {
2192 // Add header row, control fields will be reduced inside addToCSV()
2193 $this->addToCSV(array_combine($this->fieldArray, $this->fieldArray));
2194 }
2195
2196 /**
2197 * Adds selected columns of one table row as CSV line.
2198 *
2199 * @param mixed[] $row Record array, from which the values of fields found in $this->fieldArray will be listed in the CSV output.
2200 */
2201 protected function addToCSV(array $row = [])
2202 {
2203 $rowReducedByControlFields = self::removeControlFieldsFromFieldRow($row);
2204 // Get an field array without control fields but in the expected order
2205 $fieldArray = array_intersect_key(array_flip($this->fieldArray), $rowReducedByControlFields);
2206 // Overwrite fieldArray to keep the order with an array of needed fields
2207 $rowReducedToSelectedColumns = array_replace($fieldArray, array_intersect_key($rowReducedByControlFields, $fieldArray));
2208 $this->setCsvRow($rowReducedToSelectedColumns);
2209 }
2210
2211 /**
2212 * Remove control fields from row for CSV export
2213 *
2214 * @param mixed[] $row fieldNames => fieldValues
2215 * @return mixed[] Input array reduces by control fields
2216 */
2217 protected static function removeControlFieldsFromFieldRow(array $row = [])
2218 {
2219 // Possible control fields in a list row
2220 $controlFields = [
2221 '_PATH_',
2222 '_REF_',
2223 '_CONTROL_',
2224 '_CLIPBOARD_',
2225 '_LOCALIZATION_',
2226 '_LOCALIZATION_b'
2227 ];
2228 return array_diff_key($row, array_flip($controlFields));
2229 }
2230
2231 /**
2232 * Adds input row of values to the internal csvLines array as a CSV formatted line
2233 *
2234 * @param mixed[] $csvRow Array with values to be listed.
2235 */
2236 public function setCsvRow($csvRow)
2237 {
2238 $this->csvLines[] = CsvUtility::csvValues($csvRow);
2239 }
2240
2241 /**
2242 * Compiles the internal csvLines array to a csv-string and outputs it to the browser.
2243 * This function exits!
2244 *
2245 * @param string $prefix Filename prefix:
2246 */
2247 public function outputCSV($prefix)
2248 {
2249 // Setting filename:
2250 $filename = $prefix . '_' . date('dmy-Hi') . '.csv';
2251 // Creating output header:
2252 header('Content-Type: application/octet-stream');
2253 header('Content-Disposition: attachment; filename=' . $filename);
2254 // Cache-Control header is needed here to solve an issue with browser IE and
2255 // versions lower than 9. See for more information: http://support.microsoft.com/kb/323308
2256 header("Cache-Control: ''");
2257 // Printing the content of the CSV lines:
2258 echo implode(CRLF, $this->csvLines);
2259 // Exits:
2260 die;
2261 }
2262
2263 /**
2264 * add action into correct section
2265 *
2266 * @param array $cells
2267 * @param string $action
2268 * @param string $actionKey
2269 */
2270 public function addActionToCellGroup(&$cells, $action, $actionKey)
2271 {
2272 $cellsMap = [
2273 'primary' => [
2274 'view', 'edit', 'hide', 'delete', 'stat'
2275 ],
2276 'secondary' => [
2277 'viewBig', 'history', 'perms', 'new', 'move', 'moveUp', 'moveDown', 'moveLeft', 'moveRight', 'version'
2278 ]
2279 ];
2280 $classification = in_array($actionKey, $cellsMap['primary']) ? 'primary' : 'secondary';
2281 $cells[$classification][$actionKey] = $action;
2282 unset($cells[$actionKey]);
2283 }
2284
2285 /**
2286 * Check if the record represents the current backend user
2287 *
2288 * @param string $table
2289 * @param array $row
2290 * @return bool
2291 */
2292 protected function isRecordCurrentBackendUser($table, $row)
2293 {
2294 return $table === 'be_users' && (int)$row['uid'] === $this->getBackendUserAuthentication()->user['uid'];
2295 }
2296
2297 /**
2298 * @param bool $isEditable
2299 */
2300 public function setIsEditable($isEditable)
2301 {
2302 $this->editable = $isEditable;
2303 }
2304
2305 /**
2306 * Check if the table is readonly or editable
2307 * @param string $table
2308 * @return bool
2309 */
2310 public function isEditable($table)
2311 {
2312 return $GLOBALS['TCA'][$table]['ctrl']['readOnly'] || $this->editable;
2313 }
2314
2315 /**
2316 * Check if the current record is locked by editlock. Pages are locked if their editlock flag is set,
2317 * records are if they are locked themselves or if the page they are on is locked (a page’s editlock
2318 * is transitive for its content elements).
2319 *
2320 * @param string $table
2321 * @param array $row
2322 * @param bool $editPermission
2323 * @return bool
2324 */
2325 protected function overlayEditLockPermissions($table, $row = [], $editPermission = true)
2326 {
2327 if ($editPermission && !$this->getBackendUserAuthentication()->isAdmin()) {
2328 // If no $row is submitted we only check for general edit lock of current page (except for table "pages")
2329 if (empty($row)) {
2330 return $table === 'pages' ? true : !$this->pageRow['editlock'];
2331 }
2332 if (($table === 'pages' && $row['editlock']) || ($table !== 'pages' && $this->pageRow['editlock'])) {
2333 $editPermission = false;
2334 } elseif (isset($GLOBALS['TCA'][$table]['ctrl']['editlock']) && $row[$GLOBALS['TCA'][$table]['ctrl']['editlock']]) {
2335 $editPermission = false;
2336 }
2337 }
2338 return $editPermission;
2339 }
2340
2341 /**
2342 * Check whether or not the current backend user is an admin or the current page is
2343 * locked by editlock.
2344 *
2345 * @return bool
2346 */
2347 protected function editLockPermissions()
2348 {
2349 return $this->getBackendUserAuthentication()->isAdmin() || !$this->pageRow['editlock'];
2350 }
2351
2352 /**
2353 * @return BaseScriptClass
2354 */
2355 protected function getModule()
2356 {
2357 return $GLOBALS['SOBE'];
2358 }
2359
2360 /**
2361 * @return DocumentTemplate
2362 */
2363 protected function getDocumentTemplate()
2364 {
2365 return $GLOBALS['TBE_TEMPLATE'];
2366 }
2367 }