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