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