3394c2b6aa452bf138145fffbbd1d726572e2693
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / View / PageLayoutView.php
1 <?php
2 namespace TYPO3\CMS\Backend\View;
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\Controller\Page\LocalizationController;
18 use TYPO3\CMS\Backend\Controller\PageLayoutController;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
21 use TYPO3\CMS\Core\Database\DatabaseConnection;
22 use TYPO3\CMS\Core\Imaging\Icon;
23 use TYPO3\CMS\Core\Imaging\IconFactory;
24 use TYPO3\CMS\Core\Messaging\FlashMessage;
25 use TYPO3\CMS\Core\Messaging\FlashMessageService;
26 use TYPO3\CMS\Core\Page\PageRenderer;
27 use TYPO3\CMS\Core\Type\Bitmask\Permission;
28 use TYPO3\CMS\Core\Utility\GeneralUtility;
29 use TYPO3\CMS\Core\Utility\StringUtility;
30 use TYPO3\CMS\Core\Versioning\VersionState;
31 use TYPO3\CMS\Extbase\Service\FlexFormService;
32 use TYPO3\CMS\Fluid\View\StandaloneView;
33
34 /**
35 * Child class for the Web > Page module
36 */
37 class PageLayoutView extends \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList
38 {
39 /**
40 * If TRUE, users/groups are shown in the page info box.
41 *
42 * @var int
43 */
44 public $pI_showUser = 0;
45
46 /**
47 * The number of successive records to edit when showing content elements.
48 *
49 * @var int
50 */
51 public $nextThree = 3;
52
53 /**
54 * If TRUE, disables the edit-column icon for tt_content elements
55 *
56 * @var int
57 */
58 public $pages_noEditColumns = 0;
59
60 /**
61 * If TRUE, new-wizards are linked to rather than the regular new-element list.
62 *
63 * @var int
64 */
65 public $option_newWizard = 1;
66
67 /**
68 * If set to "1", will link a big button to content element wizard.
69 *
70 * @var int
71 */
72 public $ext_function = 0;
73
74 /**
75 * If TRUE, elements will have edit icons (probably this is whether the user has permission to edit the page content). Set externally.
76 *
77 * @var int
78 */
79 public $doEdit = 1;
80
81 /**
82 * Age prefixes for displaying times. May be set externally to localized values.
83 *
84 * @var string
85 */
86 public $agePrefixes = ' min| hrs| days| yrs| min| hour| day| year';
87
88 /**
89 * Array of tables to be listed by the Web > Page module in addition to the default tables.
90 *
91 * @var array
92 */
93 public $externalTables = [];
94
95 /**
96 * "Pseudo" Description -table name
97 *
98 * @var string
99 */
100 public $descrTable;
101
102 /**
103 * If set TRUE, the language mode of tt_content elements will be rendered with hard binding between
104 * default language content elements and their translations!
105 *
106 * @var bool
107 */
108 public $defLangBinding = false;
109
110 /**
111 * External, static: Configuration of tt_content element display:
112 *
113 * @var array
114 */
115 public $tt_contentConfig = [
116 // Boolean: Display info-marks or not
117 'showInfo' => 1,
118 // Boolean: Display up/down arrows and edit icons for tt_content records
119 'showCommands' => 1,
120 'languageCols' => 0,
121 'languageMode' => 0,
122 'languageColsPointer' => 0,
123 'showHidden' => 1,
124 // Displays hidden records as well
125 'sys_language_uid' => 0,
126 // Which language
127 'cols' => '1,0,2,3',
128 'activeCols' => '1,0,2,3'
129 // Which columns can be accessed by current BE user
130 ];
131
132 /**
133 * Contains icon/title of pages which are listed in the tables menu (see getTableMenu() function )
134 *
135 * @var array
136 */
137 public $activeTables = [];
138
139 /**
140 * @var array
141 */
142 public $tt_contentData = [
143 'nextThree' => [],
144 'prev' => [],
145 'next' => []
146 ];
147
148 /**
149 * Used to store labels for CTypes for tt_content elements
150 *
151 * @var array
152 */
153 public $CType_labels = [];
154
155 /**
156 * Used to store labels for the various fields in tt_content elements
157 *
158 * @var array
159 */
160 public $itemLabels = [];
161
162 /**
163 * @var \TYPO3\CMS\Backend\Clipboard\Clipboard
164 */
165 protected $clipboard;
166
167 /**
168 * @var array
169 */
170 protected $plusPages = [];
171
172 /**
173 * User permissions
174 *
175 * @var int
176 */
177 public $ext_CALC_PERMS;
178
179 /**
180 * Current ids page record
181 *
182 * @var array
183 */
184 protected $pageinfo;
185
186 /**
187 * Caches the available languages in a colPos
188 *
189 * @var array
190 */
191 protected $languagesInColumnCache = [];
192
193 /**
194 * Caches the amount of content elements as a matrix
195 *
196 * @var array
197 * @internal
198 */
199 protected $contentElementCache = [];
200
201 /**
202 * @var IconFactory
203 */
204 protected $iconFactory;
205
206 /**
207 * Stores whether a certain language has translations in it
208 *
209 * @var array
210 */
211 protected $languageHasTranslationsCache = [];
212
213 /**
214 * @var LocalizationController
215 */
216 protected $localizationController;
217
218 /**
219 * Construct to initialize class variables.
220 */
221 public function __construct()
222 {
223 parent::__construct();
224 $this->localizationController = GeneralUtility::makeInstance(LocalizationController::class);
225 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
226 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
227 $pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
228 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
229 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Localization');
230 }
231
232 /*****************************************
233 *
234 * Renderings
235 *
236 *****************************************/
237 /**
238 * Adds the code of a single table
239 *
240 * @param string $table Table name
241 * @param int $id Current page id
242 * @param string $fields
243 * @return string HTML for listing.
244 */
245 public function getTable($table, $id, $fields = '')
246 {
247 if (isset($this->externalTables[$table])) {
248 return $this->getExternalTables($id, $table);
249 } else {
250 // Branch out based on table name:
251 switch ($table) {
252 case 'pages':
253 return $this->getTable_pages($id);
254 break;
255 case 'tt_content':
256 return $this->getTable_tt_content($id);
257 break;
258 default:
259 return '';
260 }
261 }
262 }
263
264 /**
265 * Renders an external table from page id
266 *
267 * @param int $id Page id
268 * @param string $table Name of the table
269 * @return string HTML for the listing
270 */
271 public function getExternalTables($id, $table)
272 {
273 $this->pageinfo = BackendUtility::readPageAccess($id, '');
274 $type = $this->getPageLayoutController()->MOD_SETTINGS[$table];
275 if (!isset($type)) {
276 $type = 0;
277 }
278 // eg. "name;title;email;company,image"
279 $fList = $this->externalTables[$table][$type]['fList'];
280 // The columns are separeted by comma ','.
281 // Values separated by semicolon ';' are shown in the same column.
282 $icon = $this->externalTables[$table][$type]['icon'];
283 $addWhere = $this->externalTables[$table][$type]['addWhere'];
284 // Create listing
285 $out = $this->makeOrdinaryList($table, $id, $fList, $icon, $addWhere);
286 return $out;
287 }
288
289 /**
290 * Renders records from the pages table from page id
291 * (Used to get information about the page tree content by "Web>Info"!)
292 *
293 * @param int $id Page id
294 * @return string HTML for the listing
295 */
296 public function getTable_pages($id)
297 {
298 // Initializing:
299 $out = '';
300 // Select clause for pages:
301 $delClause = BackendUtility::deleteClause('pages') . ' AND ' . $this->getBackendUser()->getPagePermsClause(1);
302 // Select current page:
303 if (!$id) {
304 // The root has a pseudo record in pageinfo...
305 $row = $this->getPageLayoutController()->pageinfo;
306 } else {
307 $result = $this->getDatabase()->exec_SELECTquery('*', 'pages', 'uid=' . (int)$id . $delClause);
308 $row = $this->getDatabase()->sql_fetch_assoc($result);
309 BackendUtility::workspaceOL('pages', $row);
310 }
311 // If there was found a page:
312 if (is_array($row)) {
313 // Select which fields to show:
314 $pKey = $this->getPageLayoutController()->MOD_SETTINGS['pages'];
315 switch ($pKey) {
316 case 1:
317 $this->fieldArray = ['title', 'uid'] + array_keys($this->cleanTableNames());
318 break;
319 case 2:
320 $this->fieldArray = [
321 'title',
322 'uid',
323 'lastUpdated',
324 'newUntil',
325 'no_cache',
326 'cache_timeout',
327 'php_tree_stop',
328 'TSconfig',
329 'is_siteroot',
330 'fe_login_mode'
331 ];
332 break;
333 default:
334 $this->fieldArray = [
335 'title',
336 'uid',
337 'alias',
338 'starttime',
339 'endtime',
340 'fe_group',
341 'target',
342 'url',
343 'shortcut',
344 'shortcut_mode'
345 ];
346 }
347 // Getting select-depth:
348 $depth = (int)$this->getPageLayoutController()->MOD_SETTINGS['pages_levels'];
349 // Overriding a few things:
350 $this->no_noWrap = 0;
351 // Items
352 $this->eCounter = $this->firstElementNumber;
353 // Creating elements:
354 list($flag, $code) = $this->fwd_rwd_nav();
355 $out .= $code;
356 $editUids = [];
357 if ($flag) {
358 // Getting children:
359 $theRows = [];
360 $theRows = $this->pages_getTree($theRows, $row['uid'], $delClause . BackendUtility::versioningPlaceholderClause('pages'), '', $depth);
361 if ($this->getBackendUser()->doesUserHaveAccess($row, 2) && $row['uid'] > 0) {
362 $editUids[] = $row['uid'];
363 }
364 $out .= $this->pages_drawItem($row, $this->fieldArray);
365 // Traverse all pages selected:
366 foreach ($theRows as $sRow) {
367 if ($this->getBackendUser()->doesUserHaveAccess($sRow, 2)) {
368 $editUids[] = $sRow['uid'];
369 }
370 $out .= $this->pages_drawItem($sRow, $this->fieldArray);
371 }
372 $this->eCounter++;
373 }
374 // Header line is drawn
375 $theData = [];
376 $editIdList = implode(',', $editUids);
377 // Traverse fields (as set above) in order to create header values:
378 foreach ($this->fieldArray as $field) {
379 if ($editIdList && isset($GLOBALS['TCA']['pages']['columns'][$field]) && $field != 'uid' && !$this->pages_noEditColumns) {
380 $iTitle = sprintf(
381 $this->getLanguageService()->getLL('editThisColumn'),
382 rtrim(trim($this->getLanguageService()->sL(BackendUtility::getItemLabel('pages', $field))), ':')
383 );
384 $urlParameters = [
385 'edit' => [
386 'pages' => [
387 $editIdList => 'edit'
388 ]
389 ],
390 'columnsOnly' => $field,
391 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
392 ];
393 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
394 $eI = '<a href="' . htmlspecialchars($url)
395 . '" title="' . htmlspecialchars($iTitle) . '">'
396 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
397 } else {
398 $eI = '';
399 }
400 switch ($field) {
401 case 'title':
402 $theData[$field] = '&nbsp;<strong>'
403 . $this->getLanguageService()->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'])
404 . '</strong>' . $eI;
405 break;
406 case 'uid':
407 $theData[$field] = '&nbsp;<strong>ID:</strong>';
408 break;
409 default:
410 if (substr($field, 0, 6) == 'table_') {
411 $f2 = substr($field, 6);
412 if ($GLOBALS['TCA'][$f2]) {
413 $theData[$field] = '&nbsp;' . '<span title="' . $this->getLanguageService()->sL($GLOBALS['TCA'][$f2]['ctrl']['title'], true) . '">' . $this->iconFactory->getIconForRecord($f2, [], Icon::SIZE_SMALL)->render() . '</span>';
414 }
415 } else {
416 $theData[$field] = '&nbsp;&nbsp;<strong>'
417 . $this->getLanguageService()->sL($GLOBALS['TCA']['pages']['columns'][$field]['label'], true)
418 . '</strong>' . $eI;
419 }
420 }
421 }
422 // CSH:
423 $out = BackendUtility::cshItem($this->descrTable, ('func_' . $pKey), null, '<span class="btn btn-default btn-sm">|</span>') . '
424 <div class="table-fit">
425 <table class="table table-striped table-hover typo3-page-pages">' .
426 '<thead>' .
427 $this->addElement(1, '', $theData) .
428 '</thead>' .
429 '<tbody>' .
430 $out .
431 '</tbody>' .
432 '</table>
433 </div>';
434 }
435 return $out;
436 }
437
438 /**
439 * Renders Content Elements from the tt_content table from page id
440 *
441 * @param int $id Page id
442 * @return string HTML for the listing
443 */
444 public function getTable_tt_content($id)
445 {
446 $backendUser = $this->getBackendUser();
447 $this->pageinfo = BackendUtility::readPageAccess($this->id, '');
448 $this->initializeLanguages();
449 $this->initializeClipboard();
450 $pageTitleParamForAltDoc = '&recTitle=' . rawurlencode(BackendUtility::getRecordTitle('pages', BackendUtility::getRecordWSOL('pages', $id), true));
451 /** @var $pageRenderer PageRenderer */
452 $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
453 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LayoutModule/DragDrop');
454 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
455 $userCanEditPage = $this->ext_CALC_PERMS & Permission::PAGE_EDIT && !empty($this->id) && ($backendUser->isAdmin() || (int)$this->pageinfo['editlock'] === 0);
456 if ($this->tt_contentConfig['languageColsPointer'] > 0) {
457 $userCanEditPage = $this->getBackendUser()->check('tables_modify', 'pages_language_overlay');
458 }
459 if ($userCanEditPage) {
460 $languageOverlayId = 0;
461 $pageOverlayRecord = BackendUtility::getRecordsByField(
462 'pages_language_overlay',
463 'pid',
464 (int)$this->id,
465 'AND sys_language_uid=' . (int)$this->tt_contentConfig['sys_language_uid']
466 );
467 if (!empty($pageOverlayRecord[0]['uid'])) {
468 $languageOverlayId = $pageOverlayRecord[0]['uid'];
469 }
470 $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/PageActions', 'function(PageActions) {
471 PageActions.setPageId(' . (int)$this->id . ');
472 PageActions.setLanguageOverlayId(' . $languageOverlayId . ');
473 PageActions.initializePageTitleRenaming();
474 }');
475 }
476 // Get labels for CTypes and tt_content element fields in general:
477 $this->CType_labels = [];
478 foreach ($GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] as $val) {
479 $this->CType_labels[$val[1]] = $this->getLanguageService()->sL($val[0]);
480 }
481 $this->itemLabels = [];
482 foreach ($GLOBALS['TCA']['tt_content']['columns'] as $name => $val) {
483 $this->itemLabels[$name] = $this->getLanguageService()->sL($val['label']);
484 }
485 $languageColumn = [];
486 $out = '';
487
488 // Setting language list:
489 $langList = $this->tt_contentConfig['sys_language_uid'];
490 if ($this->tt_contentConfig['languageMode']) {
491 if ($this->tt_contentConfig['languageColsPointer']) {
492 $langList = '0,' . $this->tt_contentConfig['languageColsPointer'];
493 } else {
494 $langList = implode(',', array_keys($this->tt_contentConfig['languageCols']));
495 }
496 $languageColumn = [];
497 }
498 $langListArr = GeneralUtility::intExplode(',', $langList);
499 $defLanguageCount = [];
500 $defLangBinding = [];
501 // For each languages... :
502 // If not languageMode, then we'll only be through this once.
503 foreach ($langListArr as $lP) {
504 $lP = (int)$lP;
505
506 if (!isset($this->contentElementCache[$lP])) {
507 $this->contentElementCache[$lP] = [];
508 }
509
510 if (count($langListArr) === 1 || $lP === 0) {
511 $showLanguage = ' AND sys_language_uid IN (' . $lP . ',-1)';
512 } else {
513 $showLanguage = ' AND sys_language_uid=' . $lP;
514 }
515 $cList = explode(',', $this->tt_contentConfig['cols']);
516 $content = [];
517 $head = [];
518
519 // Select content records per column
520 $contentRecordsPerColumn = $this->getContentRecordsPerColumn('table', $id, array_values($cList), $showLanguage);
521 // For each column, render the content into a variable:
522 foreach ($cList as $key) {
523 if (!isset($this->contentElementCache[$lP][$key])) {
524 $this->contentElementCache[$lP][$key] = [];
525 }
526
527 if (!$lP) {
528 $defLanguageCount[$key] = [];
529 }
530 // Start wrapping div
531 $content[$key] .= '<div data-colpos="' . $key . '" data-language-uid="' . $lP . '" class="t3js-sortable t3js-sortable-lang t3js-sortable-lang-' . $lP . ' t3-page-ce-wrapper';
532 if (empty($contentRecordsPerColumn[$key])) {
533 $content[$key] .= ' t3-page-ce-empty';
534 }
535 $content[$key] .= '">';
536 // Add new content at the top most position
537 $link = '';
538 if ($this->getPageLayoutController()->contentIsNotLockedForEditors()
539 && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
540 ) {
541 if ($this->option_newWizard) {
542 $urlParameters = [
543 'id' => $id,
544 'sys_language_uid' => $lP,
545 'colPos' => $key,
546 'uid_pid' => $id,
547 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
548 ];
549 $tsConfig = BackendUtility::getModTSconfig($id, 'mod');
550 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
551 ? $tsConfig['properties']['newContentElementWizard.']['override']
552 : 'new_content_element';
553 $url = BackendUtility::getModuleUrl($moduleName, $urlParameters);
554 } else {
555 $urlParameters = [
556 'edit' => [
557 'tt_content' => [
558 $id => 'new'
559 ]
560 ],
561 'defVals' => [
562 'tt_content' => [
563 'colPos' => $key,
564 'sys_language_uid' => $lP
565 ]
566 ],
567 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
568 ];
569 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
570 }
571
572 $link = '<a href="' . htmlspecialchars($url) . '" title="'
573 . $this->getLanguageService()->getLL('newContentElement', true) . '" class="btn btn-default btn-sm">'
574 . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render()
575 . ' '
576 . $this->getLanguageService()->getLL('content', true) . '</a>';
577 }
578 if ($this->getBackendUser()->checkLanguageAccess($lP)) {
579 $content[$key] .= '
580 <div class="t3-page-ce t3js-page-ce" data-page="' . (int)$id . '" id="' . StringUtility::getUniqueId() . '">
581 <div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $key . '-' . 'page-' . $id . '-' . StringUtility::getUniqueId() . '">'
582 . $link
583 . '</div>
584 <div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div>
585 </div>
586 ';
587 }
588 $editUidList = '';
589 if (!isset($contentRecordsPerColumn[$key]) || !is_array($contentRecordsPerColumn[$key])) {
590 $message = GeneralUtility::makeInstance(
591 FlashMessage::class,
592 $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:error.invalidBackendLayout'),
593 '',
594 FlashMessage::WARNING
595 );
596 $service = GeneralUtility::makeInstance(FlashMessageService::class);
597 $queue = $service->getMessageQueueByIdentifier();
598 $queue->addMessage($message);
599 } else {
600 $rowArr = $contentRecordsPerColumn[$key];
601 $this->generateTtContentDataArray($rowArr);
602
603 foreach ((array)$rowArr as $rKey => $row) {
604 $this->contentElementCache[$lP][$key][$row['uid']] = $row;
605 if ($this->tt_contentConfig['languageMode']) {
606 $languageColumn[$key][$lP] = $head[$key] . $content[$key];
607 if (!$this->defLangBinding) {
608 $languageColumn[$key][$lP] .= $this->newLanguageButton(
609 $this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP),
610 $lP,
611 $key
612 );
613 }
614 }
615 if (is_array($row) && !VersionState::cast($row['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
616 $singleElementHTML = '';
617 if (!$lP && ($this->defLangBinding || $row['sys_language_uid'] != -1)) {
618 $defLanguageCount[$key][] = (isset($row['_ORIG_uid']) ? $row['_ORIG_uid'] : $row['uid']);
619 }
620 $editUidList .= $row['uid'] . ',';
621 $disableMoveAndNewButtons = $this->defLangBinding && $lP > 0;
622 if (!$this->tt_contentConfig['languageMode']) {
623 $singleElementHTML .= '<div class="t3-page-ce-dragitem" id="' . StringUtility::getUniqueId() . '">';
624 }
625 $singleElementHTML .= $this->tt_content_drawHeader(
626 $row,
627 $this->tt_contentConfig['showInfo'] ? 15 : 5,
628 $disableMoveAndNewButtons,
629 true,
630 $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
631 );
632 $innerContent = '<div ' . ($row['_ORIG_uid'] ? ' class="ver-element"' : '') . '>'
633 . $this->tt_content_drawItem($row) . '</div>';
634 $singleElementHTML .= '<div class="t3-page-ce-body-inner">' . $innerContent . '</div>'
635 . $this->tt_content_drawFooter($row);
636 $isDisabled = $this->isDisabled('tt_content', $row);
637 $statusHidden = $isDisabled ? ' t3-page-ce-hidden t3js-hidden-record' : '';
638 $displayNone = !$this->tt_contentConfig['showHidden'] && $isDisabled ? ' style="display: none;"' : '';
639 $highlightHeader = false;
640 if ($this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid']) && (int)$row['l18n_parent'] === 0) {
641 $highlightHeader = true;
642 }
643 $singleElementHTML = '<div class="t3-page-ce ' . ($highlightHeader ? 't3-page-ce-danger' : '') . ' t3js-page-ce t3js-page-ce-sortable ' . $statusHidden . '" id="element-tt_content-'
644 . $row['uid'] . '" data-table="tt_content" data-uid="' . $row['uid'] . '"' . $displayNone . '>' . $singleElementHTML . '</div>';
645
646 if ($this->tt_contentConfig['languageMode']) {
647 $singleElementHTML .= '<div class="t3-page-ce t3js-page-ce">';
648 }
649 $singleElementHTML .= '<div class="t3js-page-new-ce t3-page-ce-wrapper-new-ce" id="colpos-' . $key . '-' . 'page-' . $id .
650 '-' . StringUtility::getUniqueId() . '">';
651 // Add icon "new content element below"
652 if (!$disableMoveAndNewButtons
653 && $this->getPageLayoutController()->contentIsNotLockedForEditors()
654 && $this->getBackendUser()->checkLanguageAccess($lP)
655 && (!$this->checkIfTranslationsExistInLanguage($contentRecordsPerColumn, $lP))
656 ) {
657 // New content element:
658 if ($this->option_newWizard) {
659 $urlParameters = [
660 'id' => $row['pid'],
661 'sys_language_uid' => $row['sys_language_uid'],
662 'colPos' => $row['colPos'],
663 'uid_pid' => -$row['uid'],
664 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
665 ];
666 $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod');
667 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
668 ? $tsConfig['properties']['newContentElementWizard.']['override']
669 : 'new_content_element';
670 $url = BackendUtility::getModuleUrl($moduleName, $urlParameters);
671 } else {
672 $urlParameters = [
673 'edit' => [
674 'tt_content' => [
675 -$row['uid'] => 'new'
676 ]
677 ],
678 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
679 ];
680 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
681 }
682 $singleElementHTML .= '
683 <a href="' . htmlspecialchars($url) . '" title="'
684 . $this->getLanguageService()->getLL('newContentElement', true) . '" class="btn btn-default btn-sm">'
685 . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render()
686 . ' '
687 . $this->getLanguageService()->getLL('content', true) . '</a>
688 ';
689 }
690 $singleElementHTML .= '</div></div><div class="t3-page-ce-dropzone-available t3js-page-ce-dropzone-available"></div></div>';
691 if ($this->defLangBinding && $this->tt_contentConfig['languageMode']) {
692 $defLangBinding[$key][$lP][$row[$lP ? 'l18n_parent' : 'uid']] = $singleElementHTML;
693 } else {
694 $content[$key] .= $singleElementHTML;
695 }
696 } else {
697 unset($rowArr[$rKey]);
698 }
699 }
700 $content[$key] .= '</div>';
701 $colTitle = BackendUtility::getProcessedValue('tt_content', 'colPos', $key);
702 $tcaItems = GeneralUtility::callUserFunction(\TYPO3\CMS\Backend\View\BackendLayoutView::class . '->getColPosListItemsParsed', $id, $this);
703 foreach ($tcaItems as $item) {
704 if ($item[1] == $key) {
705 $colTitle = $this->getLanguageService()->sL($item[0]);
706 }
707 }
708
709 $pasteP = ['colPos' => $key, 'sys_language_uid' => $lP];
710 $editParam = $this->doEdit && !empty($rowArr)
711 ? '&edit[tt_content][' . $editUidList . ']=edit' . $pageTitleParamForAltDoc
712 : '';
713 $head[$key] .= $this->tt_content_drawColHeader($colTitle, $editParam, '', $pasteP);
714 }
715 }
716 // For each column, fit the rendered content into a table cell:
717 $out = '';
718 if ($this->tt_contentConfig['languageMode']) {
719 // in language mode process the content elements, but only fill $languageColumn. output will be generated later
720 $sortedLanguageColumn = [];
721 foreach ($cList as $key) {
722 $languageColumn[$key][$lP] = $head[$key] . $content[$key];
723 if (!$this->defLangBinding) {
724 $languageColumn[$key][$lP] .= $this->newLanguageButton(
725 $this->getNonTranslatedTTcontentUids($defLanguageCount[$key], $id, $lP),
726 $lP,
727 $key
728 );
729 }
730 // We sort $languageColumn again according to $cList as it may contain data already from above.
731 $sortedLanguageColumn[$key] = $languageColumn[$key];
732 }
733 $languageColumn = $sortedLanguageColumn;
734 } else {
735 $backendLayout = $this->getBackendLayoutView()->getSelectedBackendLayout($this->id);
736 // GRID VIEW:
737 $grid = '<div class="t3-grid-container"><table border="0" cellspacing="0" cellpadding="0" width="100%" class="t3-page-columns t3-grid-table t3js-page-columns">';
738 // Add colgroups
739 $colCount = (int)$backendLayout['__config']['backend_layout.']['colCount'];
740 $rowCount = (int)$backendLayout['__config']['backend_layout.']['rowCount'];
741 $grid .= '<colgroup>';
742 for ($i = 0; $i < $colCount; $i++) {
743 $grid .= '<col />';
744 }
745 $grid .= '</colgroup>';
746 // Cycle through rows
747 for ($row = 1; $row <= $rowCount; $row++) {
748 $rowConfig = $backendLayout['__config']['backend_layout.']['rows.'][$row . '.'];
749 if (!isset($rowConfig)) {
750 continue;
751 }
752 $grid .= '<tr>';
753 for ($col = 1; $col <= $colCount; $col++) {
754 $columnConfig = $rowConfig['columns.'][$col . '.'];
755 if (!isset($columnConfig)) {
756 continue;
757 }
758 // Which tt_content colPos should be displayed inside this cell
759 $columnKey = (int)$columnConfig['colPos'];
760 // Render the grid cell
761 $colSpan = (int)$columnConfig['colspan'];
762 $rowSpan = (int)$columnConfig['rowspan'];
763 $grid .= '<td valign="top"' .
764 ($colSpan > 0 ? ' colspan="' . $colSpan . '"' : '') .
765 ($rowSpan > 0 ? ' rowspan="' . $rowSpan . '"' : '') .
766 ' data-colpos="' . (int)$columnConfig['colPos'] . '" data-language-uid="' . $lP . '" class="t3js-page-lang-column-' . $lP . ' t3js-page-column t3-grid-cell t3-page-column t3-page-column-' . $columnKey .
767 ((!isset($columnConfig['colPos']) || $columnConfig['colPos'] === '') ? ' t3-grid-cell-unassigned' : '') .
768 ((isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && !$head[$columnKey]) || !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos']) ? ' t3-grid-cell-restricted' : '') .
769 ($colSpan > 0 ? ' t3-gridCell-width' . $colSpan : '') .
770 ($rowSpan > 0 ? ' t3-gridCell-height' . $rowSpan : '') . '">';
771
772 // Draw the pre-generated header with edit and new buttons if a colPos is assigned.
773 // If not, a new header without any buttons will be generated.
774 if (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== '' && $head[$columnKey]
775 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
776 ) {
777 $grid .= $head[$columnKey] . $content[$columnKey];
778 } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
779 && GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
780 ) {
781 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('noAccess'), '', '');
782 } elseif (isset($columnConfig['colPos']) && $columnConfig['colPos'] !== ''
783 && !GeneralUtility::inList($this->tt_contentConfig['activeCols'], $columnConfig['colPos'])
784 ) {
785 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name']) .
786 ' (' . $this->getLanguageService()->getLL('noAccess') . ')', '', '');
787 } elseif (isset($columnConfig['name']) && $columnConfig['name'] !== '') {
788 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->sL($columnConfig['name'])
789 . ' (' . $this->getLanguageService()->getLL('notAssigned') . ')', '', '');
790 } else {
791 $grid .= $this->tt_content_drawColHeader($this->getLanguageService()->getLL('notAssigned'), '', '');
792 }
793
794 $grid .= '</td>';
795 }
796 $grid .= '</tr>';
797 }
798 $out .= $grid . '</table></div>';
799 }
800 // CSH:
801 $out .= BackendUtility::cshItem($this->descrTable, 'columns_multi', null, '<span class="btn btn-default btn-sm">|</span>');
802 }
803 // If language mode, then make another presentation:
804 // Notice that THIS presentation will override the value of $out!
805 // But it needs the code above to execute since $languageColumn is filled with content we need!
806 if ($this->tt_contentConfig['languageMode']) {
807 // Get language selector:
808 $languageSelector = $this->languageSelector($id);
809 // Reset out - we will make new content here:
810 $out = '';
811 // Traverse languages found on the page and build up the table displaying them side by side:
812 $cCont = [];
813 $sCont = [];
814 foreach ($langListArr as $lP) {
815 // Header:
816 $lP = (int)$lP;
817 $cCont[$lP] = '
818 <td valign="top" class="t3-page-column" data-language-uid="' . $lP . '">
819 <h2>' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '</h2>
820 </td>';
821
822 // "View page" icon is added:
823 $viewLink = '';
824 if (!VersionState::cast($this->getPageLayoutController()->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
825 $onClick = BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id), '', '', ('&L=' . $lP));
826 $viewLink = '<a href="#" class="btn btn-default btn-sm" onclick="' . htmlspecialchars($onClick) . '" title="' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true) . '">' . $this->iconFactory->getIcon('actions-view', Icon::SIZE_SMALL)->render() . '</a>';
827 }
828 // Language overlay page header:
829 if ($lP) {
830 list($lpRecord) = BackendUtility::getRecordsByField('pages_language_overlay', 'pid', $id, 'AND sys_language_uid=' . $lP);
831 BackendUtility::workspaceOL('pages_language_overlay', $lpRecord);
832 $params = '&edit[pages_language_overlay][' . $lpRecord['uid'] . ']=edit&overrideVals[pages_language_overlay][sys_language_uid]=' . $lP;
833 $recordIcon = BackendUtility::wrapClickMenuOnIcon(
834 $this->iconFactory->getIconForRecord('pages_language_overlay', $lpRecord, Icon::SIZE_SMALL)->render(),
835 'pages_language_overlay',
836 $lpRecord['uid']
837 );
838 $urlParameters = [
839 'edit' => [
840 'pages_language_overlay' => [
841 $lpRecord['uid'] => 'edit'
842 ]
843 ],
844 'overrideVals' => [
845 'pages_language_overlay' => [
846 'sys_language_uid' => $lP
847 ]
848 ],
849 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
850 ];
851 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
852 $editLink = ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
853 ? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
854 . ' title="' . $this->getLanguageService()->getLL('edit', true) . '">'
855 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
856 : ''
857 );
858
859 $lPLabel =
860 '<div class="btn-group">'
861 . $viewLink
862 . $editLink
863 . '</div>'
864 . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($lpRecord['title'], 20));
865 } else {
866 $editLink = '';
867 $recordIcon = '';
868 if ($this->getBackendUser()->checkLanguageAccess(0)) {
869 $recordIcon = BackendUtility::wrapClickMenuOnIcon(
870 $this->iconFactory->getIconForRecord('pages', $this->pageRecord,
871 Icon::SIZE_SMALL)->render(),
872 'pages',
873 $this->id
874 );
875 $urlParameters = [
876 'edit' => [
877 'pages' => [
878 $this->id => 'edit'
879 ]
880 ],
881 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
882 ];
883 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
884 $editLink = ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')
885 ? '<a href="' . htmlspecialchars($url) . '" class="btn btn-default btn-sm"'
886 . ' title="' . $this->getLanguageService()->getLL('edit', true) . '">'
887 . $this->iconFactory->getIcon('actions-open', Icon::SIZE_SMALL)->render() . '</a>'
888 : ''
889 );
890 }
891
892 $lPLabel =
893 '<div class="btn-group">'
894 . $viewLink
895 . $editLink
896 . '</div>'
897 . ' ' . $recordIcon . ' ' . htmlspecialchars(GeneralUtility::fixed_lgd_cs($this->pageRecord['title'], 20));
898 }
899 $sCont[$lP] = '
900 <td nowrap="nowrap" class="t3-page-column t3-page-lang-label">' . $lPLabel . '</td>';
901 }
902 // Add headers:
903 $out .= '<tr>' . implode($cCont) . '</tr>';
904 $out .= '<tr>' . implode($sCont) . '</tr>';
905 unset($cCont, $sCont);
906
907 // Traverse previously built content for the columns:
908 foreach ($languageColumn as $cKey => $cCont) {
909 $out .= '<tr>';
910 foreach ($cCont as $languageId => $columnContent) {
911 $out .= '<td valign="top" class="t3-grid-cell t3-page-column t3js-page-column t3js-page-lang-column t3js-page-lang-column-' . $languageId . '">' . $columnContent . '</td>';
912 }
913 $out .= '</tr>';
914 if ($this->defLangBinding) {
915 // "defLangBinding" mode
916 foreach ($defLanguageCount[$cKey] as $defUid) {
917 $cCont = [];
918 foreach ($langListArr as $lP) {
919 $cCont[] = $defLangBinding[$cKey][$lP][$defUid] . $this->newLanguageButton(
920 $this->getNonTranslatedTTcontentUids([$defUid], $id, $lP),
921 $lP,
922 $cKey
923 );
924 }
925 $out .= '
926 <tr>
927 <td valign="top" class="t3-grid-cell">' . implode(('</td>' . '
928 <td valign="top" class="t3-grid-cell">'), $cCont) . '</td>
929 </tr>';
930 }
931 }
932 }
933 // Finally, wrap it all in a table and add the language selector on top of it:
934 $out = $languageSelector . '
935 <div class="t3-grid-container">
936 <table cellpadding="0" cellspacing="0" class="t3-page-columns t3-grid-table t3js-page-columns">
937 ' . $out . '
938 </table>
939 </div>';
940 // CSH:
941 $out .= BackendUtility::cshItem($this->descrTable, 'language_list', null, '<span class="btn btn-default btn-sm">|</span>');
942 }
943
944 return $out;
945 }
946
947 /**********************************
948 *
949 * Generic listing of items
950 *
951 **********************************/
952 /**
953 * Creates a standard list of elements from a table.
954 *
955 * @param string $table Table name
956 * @param int $id Page id.
957 * @param string $fList Comma list of fields to display
958 * @param bool $icon If TRUE, icon is shown
959 * @param string $addWhere Additional WHERE-clauses.
960 * @return string HTML table
961 */
962 public function makeOrdinaryList($table, $id, $fList, $icon = false, $addWhere = '')
963 {
964 // Initialize
965 $queryParts = $this->makeQueryArray($table, $id, $addWhere);
966 $this->setTotalItems($queryParts);
967 $dbCount = 0;
968 $result = false;
969 // Make query for records if there were any records found in the count operation
970 if ($this->totalItems) {
971 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
972 // Will return FALSE, if $result is invalid
973 $dbCount = $this->getDatabase()->sql_num_rows($result);
974 }
975 // If records were found, render the list
976 if (!$dbCount) {
977 return '';
978 }
979 // Set fields
980 $out = '';
981 $this->fieldArray = GeneralUtility::trimExplode(',', '__cmds__,' . $fList . ',__editIconLink__', true);
982 $theData = [];
983 $theData = $this->headerFields($this->fieldArray, $table, $theData);
984 // Title row
985 $localizedTableTitle = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['ctrl']['title'], true);
986 $out .= '<tr class="t3-row-header">' . '<th class="col-icon"></th>'
987 . '<th colspan="' . (count($theData) - 2) . '"><span class="c-table">'
988 . $localizedTableTitle . '</span> (' . $dbCount . ')</td>' . '<td class="col-icon"></td>'
989 . '</tr>';
990 // Column's titles
991 if ($this->doEdit) {
992 $urlParameters = [
993 'edit' => [
994 $table => [
995 $this->id => 'new'
996 ]
997 ],
998 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
999 ];
1000 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1001 $theData['__cmds__'] = '<a href="' . htmlspecialchars($url) . '" '
1002 . 'title="' . $this->getLanguageService()->getLL('new', true) . '">'
1003 . $this->iconFactory->getIcon('actions-document-new', Icon::SIZE_SMALL)->render() . '</a>';
1004 }
1005 $out .= $this->addElement(1, '', $theData, ' class="c-headLine"', 15, '', 'th');
1006 // Render Items
1007 $this->eCounter = $this->firstElementNumber;
1008 while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
1009 BackendUtility::workspaceOL($table, $row);
1010 if (is_array($row)) {
1011 list($flag, $code) = $this->fwd_rwd_nav();
1012 $out .= $code;
1013 if ($flag) {
1014 $Nrow = [];
1015 // Setting icons links
1016 if ($icon) {
1017 $Nrow['__cmds__'] = $this->getIcon($table, $row);
1018 }
1019 // Get values:
1020 $Nrow = $this->dataFields($this->fieldArray, $table, $row, $Nrow);
1021 // Attach edit icon
1022 if ($this->doEdit && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1023 $urlParameters = [
1024 'edit' => [
1025 $table => [
1026 $row['uid'] => 'edit'
1027 ]
1028 ],
1029 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1030 ];
1031 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1032 $Nrow['__editIconLink__'] = '<a href="' . htmlspecialchars($url)
1033 . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">'
1034 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1035 } else {
1036 $Nrow['__editIconLink__'] = $this->noEditIcon();
1037 }
1038 $out .= $this->addElement(1, '', $Nrow);
1039 }
1040 $this->eCounter++;
1041 }
1042 }
1043 $this->getDatabase()->sql_free_result($result);
1044 // Wrap it all in a table:
1045 $out = '
1046 <!--
1047 Standard list of table "' . $table . '"
1048 -->
1049 <div class="table-fit"><table class="table table-striped">
1050 ' . $out . '
1051 </table></div>';
1052 return $out;
1053 }
1054
1055 /**
1056 * Adds content to all data fields in $out array
1057 *
1058 * Each field name in $fieldArr has a special feature which is that the field name can be specified as more field names.
1059 * Eg. "field1,field2;field3".
1060 * Field 2 and 3 will be shown in the same cell of the table separated by <br /> while field1 will have its own cell.
1061 *
1062 * @param array $fieldArr Array of fields to display
1063 * @param string $table Table name
1064 * @param array $row Record array
1065 * @param array $out Array to which the data is added
1066 * @return array $out array returned after processing.
1067 * @see makeOrdinaryList()
1068 */
1069 public function dataFields($fieldArr, $table, $row, $out = [])
1070 {
1071 // Check table validity
1072 if (!isset($GLOBALS['TCA'][$table])) {
1073 return $out;
1074 }
1075
1076 $thumbsCol = $GLOBALS['TCA'][$table]['ctrl']['thumbnail'];
1077 // Traverse fields
1078 foreach ($fieldArr as $fieldName) {
1079 if ($GLOBALS['TCA'][$table]['columns'][$fieldName]) {
1080 // Each field has its own cell (if configured in TCA)
1081 // If the column is a thumbnail column:
1082 if ($fieldName == $thumbsCol) {
1083 $out[$fieldName] = $this->thumbCode($row, $table, $fieldName);
1084 } else {
1085 // ... otherwise just render the output:
1086 $out[$fieldName] = nl2br(htmlspecialchars(trim(GeneralUtility::fixed_lgd_cs(
1087 BackendUtility::getProcessedValue($table, $fieldName, $row[$fieldName], 0, 0, 0, $row['uid']),
1088 250
1089 ))));
1090 }
1091 } else {
1092 // Each field is separated by <br /> and shown in the same cell (If not a TCA field, then explode
1093 // the field name with ";" and check each value there as a TCA configured field)
1094 $theFields = explode(';', $fieldName);
1095 // Traverse fields, separated by ";" (displayed in a single cell).
1096 foreach ($theFields as $fName2) {
1097 if ($GLOBALS['TCA'][$table]['columns'][$fName2]) {
1098 $out[$fieldName] .= '<strong>' . $this->getLanguageService()->sL(
1099 $GLOBALS['TCA'][$table]['columns'][$fName2]['label'],
1100 true
1101 ) . '</strong>' . '&nbsp;&nbsp;' . htmlspecialchars(GeneralUtility::fixed_lgd_cs(
1102 BackendUtility::getProcessedValue($table, $fName2, $row[$fName2], 0, 0, 0, $row['uid']),
1103 25
1104 )) . '<br />';
1105 }
1106 }
1107 }
1108 // If no value, add a nbsp.
1109 if (!$out[$fieldName]) {
1110 $out[$fieldName] = '&nbsp;';
1111 }
1112 // Wrap in dimmed-span tags if record is "disabled"
1113 if ($this->isDisabled($table, $row)) {
1114 $out[$fieldName] = '<span class="text-muted">' . $out[$fieldName] . '</span>';
1115 }
1116 }
1117 return $out;
1118 }
1119
1120 /**
1121 * Header fields made for the listing of records
1122 *
1123 * @param array $fieldArr Field names
1124 * @param string $table The table name
1125 * @param array $out Array to which the headers are added.
1126 * @return array $out returned after addition of the header fields.
1127 * @see makeOrdinaryList()
1128 */
1129 public function headerFields($fieldArr, $table, $out = [])
1130 {
1131 foreach ($fieldArr as $fieldName) {
1132 $ll = $this->getLanguageService()->sL($GLOBALS['TCA'][$table]['columns'][$fieldName]['label'], true);
1133 $out[$fieldName] = $ll ? $ll : '&nbsp;';
1134 }
1135 return $out;
1136 }
1137
1138 /**
1139 * Gets content records per column.
1140 * This is required for correct workspace overlays.
1141 *
1142 * @param string $table UNUSED (will always be queried from tt_content)
1143 * @param int $id Page Id to be used (not used at all, but part of the API, see $this->pidSelect)
1144 * @param array $columns colPos values to be considered to be shown
1145 * @param string $additionalWhereClause Additional where clause for database select
1146 * @return array Associative array for each column (colPos)
1147 */
1148 protected function getContentRecordsPerColumn($table, $id, array $columns, $additionalWhereClause = '')
1149 {
1150 $columns = array_map('intval', $columns);
1151 $contentRecordsPerColumn = array_fill_keys($columns, []);
1152
1153 $queryParts = $this->makeQueryArray('tt_content', $id, 'AND colPos IN (' . implode(',', $columns) . ')' . $additionalWhereClause);
1154 $result = $this->getDatabase()->exec_SELECT_queryArray($queryParts);
1155 // Traverse any selected elements and render their display code:
1156 $rowArr = $this->getResult($result);
1157
1158 foreach ($rowArr as $record) {
1159 $columnValue = $record['colPos'];
1160 $contentRecordsPerColumn[$columnValue][] = $record;
1161 }
1162
1163 return $contentRecordsPerColumn;
1164 }
1165
1166 /**********************************
1167 *
1168 * Additional functions; Pages
1169 *
1170 **********************************/
1171 /**
1172 * Adds pages-rows to an array, selecting recursively in the page tree.
1173 *
1174 * @param array $theRows Array which will accumulate page rows
1175 * @param int $pid Pid to select from
1176 * @param string $qWhere Query-where clause
1177 * @param string $treeIcons Prefixed icon code.
1178 * @param int $depth Depth (decreasing)
1179 * @return array $theRows, but with added rows.
1180 */
1181 public function pages_getTree($theRows, $pid, $qWhere, $treeIcons, $depth)
1182 {
1183 $depth--;
1184 if ($depth >= 0) {
1185 $res = $this->getDatabase()->exec_SELECTquery('*', 'pages', 'pid=' . (int)$pid . $qWhere, '', 'sorting');
1186 $c = 0;
1187 $rc = $this->getDatabase()->sql_num_rows($res);
1188 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1189 BackendUtility::workspaceOL('pages', $row);
1190 if (is_array($row)) {
1191 $c++;
1192 $row['treeIcons'] = $treeIcons . '<span class="treeline-icon treeline-icon-join' . ($rc === $c ? 'bottom' : '') . '"></span>';
1193 $theRows[] = $row;
1194 // Get the branch
1195 $spaceOutIcons = '<span class="treeline-icon treeline-icon-' . ($rc === $c ? 'clear' : 'line') . '"></span>';
1196 $theRows = $this->pages_getTree($theRows, $row['uid'], $qWhere, $treeIcons . $spaceOutIcons, $row['php_tree_stop'] ? 0 : $depth);
1197 }
1198 }
1199 } else {
1200 $count = $this->getDatabase()->exec_SELECTcountRows('uid', 'pages', 'pid=' . (int)$pid . $qWhere);
1201 if ($count) {
1202 $this->plusPages[$pid] = $count;
1203 }
1204 }
1205 return $theRows;
1206 }
1207
1208 /**
1209 * Adds a list item for the pages-rendering
1210 *
1211 * @param array $row Record array
1212 * @param array $fieldArr Field list
1213 * @return string HTML for the item
1214 */
1215 public function pages_drawItem($row, $fieldArr)
1216 {
1217 // Initialization
1218 $theIcon = $this->getIcon('pages', $row);
1219 // Preparing and getting the data-array
1220 $theData = [];
1221 foreach ($fieldArr as $field) {
1222 switch ($field) {
1223 case 'title':
1224 $red = $this->plusPages[$row['uid']] ? '<span class="text-danger"><strong>+</strong></span>' : '';
1225 $pTitle = htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field], 20));
1226 if ($red) {
1227 $pTitle = '<a href="'
1228 . htmlspecialchars($this->script . ((strpos($this->script, '?') !== false) ? '&' : '?')
1229 . 'id=' . $row['uid']) . '">' . $pTitle . '</a>';
1230 }
1231 $theData[$field] = $row['treeIcons'] . $theIcon . $red . $pTitle . '&nbsp;&nbsp;';
1232 break;
1233 case 'php_tree_stop':
1234 // Intended fall through
1235 case 'TSconfig':
1236 $theData[$field] = $row[$field] ? '&nbsp;<strong>x</strong>' : '&nbsp;';
1237 break;
1238 case 'uid':
1239 if ($this->getBackendUser()->doesUserHaveAccess($row, 2) && $row['uid'] > 0) {
1240 $urlParameters = [
1241 'edit' => [
1242 'pages' => [
1243 $row['uid'] => 'edit'
1244 ]
1245 ],
1246 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1247 ];
1248 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1249 $eI = '<a href="' . htmlspecialchars($url)
1250 . '" title="' . $this->getLanguageService()->getLL('editThisPage', true) . '">'
1251 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1252 } else {
1253 $eI = '';
1254 }
1255 $theData[$field] = '<span align="right">' . $row['uid'] . $eI . '</span>';
1256 break;
1257 case 'shortcut':
1258 case 'shortcut_mode':
1259 if ((int)$row['doktype'] === \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_SHORTCUT) {
1260 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1261 }
1262 break;
1263 default:
1264 if (substr($field, 0, 6) == 'table_') {
1265 $f2 = substr($field, 6);
1266 if ($GLOBALS['TCA'][$f2]) {
1267 $c = $this->numberOfRecords($f2, $row['uid']);
1268 $theData[$field] = '&nbsp;&nbsp;' . ($c ? $c : '');
1269 }
1270 } else {
1271 $theData[$field] = $this->getPagesTableFieldValue($field, $row);
1272 }
1273 }
1274 }
1275 $this->addElement_tdParams['title'] = $row['_CSSCLASS'] ? ' class="' . $row['_CSSCLASS'] . '"' : '';
1276 return $this->addElement(1, '', $theData);
1277 }
1278
1279 /**
1280 * Returns the HTML code for rendering a field in the pages table.
1281 * The row value is processed to a human readable form and the result is parsed through htmlspecialchars().
1282 *
1283 * @param string $field The name of the field of which the value should be rendered.
1284 * @param array $row The pages table row as an associative array.
1285 * @return string The rendered table field value.
1286 */
1287 protected function getPagesTableFieldValue($field, array $row)
1288 {
1289 return '&nbsp;&nbsp;' . htmlspecialchars(BackendUtility::getProcessedValue('pages', $field, $row[$field]));
1290 }
1291
1292 /**********************************
1293 *
1294 * Additional functions; Content Elements
1295 *
1296 **********************************/
1297 /**
1298 * Draw header for a content element column:
1299 *
1300 * @param string $colName Column name
1301 * @param string $editParams Edit params (Syntax: &edit[...] for FormEngine)
1302 * @param string $newParams New element params (Syntax: &edit[...] for FormEngine) OBSOLETE
1303 * @param array|NULL $pasteParams Paste element params (i.e. array(colPos => 1, sys_language_uid => 2))
1304 * @return string HTML table
1305 */
1306 public function tt_content_drawColHeader($colName, $editParams, $newParams, array $pasteParams = null)
1307 {
1308 $iconsArr = [];
1309 // Create command links:
1310 if ($this->tt_contentConfig['showCommands']) {
1311 // Edit whole of column:
1312 if ($editParams && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT) && $this->getBackendUser()->checkLanguageAccess(0)) {
1313 $iconsArr['edit'] = '<a href="#" onclick="'
1314 . htmlspecialchars(BackendUtility::editOnClick($editParams)) . '" title="'
1315 . $this->getLanguageService()->getLL('editColumn', true) . '">'
1316 . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1317 }
1318 if ($pasteParams) {
1319 $elFromTable = $this->clipboard->elFromTable('tt_content');
1320 if (!empty($elFromTable) && $this->getPageLayoutController()->pageIsNotLockedForEditors()) {
1321 $iconsArr['paste'] =
1322 '<a href="' . htmlspecialchars($this->clipboard->pasteUrl('tt_content', $this->id, true, $pasteParams)) . '"'
1323 . ' class="t3js-modal-trigger"'
1324 . ' data-severity="warning"'
1325 . ' data-title="' . $this->getLanguageService()->getLL('pasteIntoColumn', true) . '"'
1326 . ' data-content="' . htmlspecialchars($this->clipboard->confirmMsgText('pages', $this->pageRecord, 'into', $elFromTable, $colName)) . '"'
1327 . ' title="' . $this->getLanguageService()->getLL('pasteIntoColumn', true) . '">'
1328 . $this->iconFactory->getIcon('actions-document-paste-into', Icon::SIZE_SMALL)->render()
1329 . '</a>';
1330 }
1331 }
1332 }
1333 $icons = '';
1334 if (!empty($iconsArr)) {
1335 $icons = '<div class="t3-page-column-header-icons">' . implode('', $iconsArr) . '</div>';
1336 }
1337 // Create header row:
1338 $out = '<div class="t3-page-column-header">
1339 ' . $icons . '
1340 <div class="t3-page-column-header-label">' . htmlspecialchars($colName) . '</div>
1341 </div>';
1342 return $out;
1343 }
1344
1345 /**
1346 * Draw the footer for a single tt_content element
1347 *
1348 * @param array $row Record array
1349 * @return string HTML of the footer
1350 * @throws \UnexpectedValueException
1351 */
1352 protected function tt_content_drawFooter(array $row)
1353 {
1354 $content = '';
1355 // Get processed values:
1356 $info = [];
1357 $this->getProcessedValue('tt_content', 'starttime,endtime,fe_group,spaceBefore,spaceAfter', $row, $info);
1358
1359 // Content element annotation
1360 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn'])) {
1361 $info[] = htmlspecialchars($row[$GLOBALS['TCA']['tt_content']['ctrl']['descriptionColumn']]);
1362 }
1363
1364 // Call drawFooter hooks
1365 $drawFooterHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawFooter'];
1366 if (is_array($drawFooterHooks)) {
1367 foreach ($drawFooterHooks as $hookClass) {
1368 $hookObject = GeneralUtility::getUserObj($hookClass);
1369 if (!$hookObject instanceof PageLayoutViewDrawFooterHookInterface) {
1370 throw new \UnexpectedValueException($hookClass . ' must implement interface ' . PageLayoutViewDrawFooterHookInterface::class, 1404378171);
1371 }
1372 $hookObject->preProcess($this, $info, $row);
1373 }
1374 }
1375
1376 // Display info from records fields:
1377 if (!empty($info)) {
1378 $content = '<div class="t3-page-ce-info">
1379 ' . implode('<br>', $info) . '
1380 </div>';
1381 }
1382 // Wrap it
1383 if (!empty($content)) {
1384 $content = '<div class="t3-page-ce-footer">' . $content . '</div>';
1385 }
1386 return $content;
1387 }
1388
1389 /**
1390 * Draw the header for a single tt_content element
1391 *
1392 * @param array $row Record array
1393 * @param int $space Amount of pixel space above the header. UNUSED
1394 * @param bool $disableMoveAndNewButtons If set the buttons for creating new elements and moving up and down are not shown.
1395 * @param bool $langMode If set, we are in language mode and flags will be shown for languages
1396 * @param bool $dragDropEnabled If set the move button must be hidden
1397 * @return string HTML table with the record header.
1398 */
1399 public function tt_content_drawHeader($row, $space = 0, $disableMoveAndNewButtons = false, $langMode = false, $dragDropEnabled = false)
1400 {
1401 $out = '';
1402 // If show info is set...;
1403 if ($this->tt_contentConfig['showInfo'] && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1404 // Render control panel for the element:
1405 if ($this->tt_contentConfig['showCommands'] && $this->doEdit) {
1406 // Edit content element:
1407 $urlParameters = [
1408 'edit' => [
1409 'tt_content' => [
1410 $this->tt_contentData['nextThree'][$row['uid']] => 'edit'
1411 ]
1412 ],
1413 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI') . '#element-tt_content-' . $row['uid'],
1414 ];
1415 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters) . '#element-tt_content-' . $row['uid'];
1416
1417 $out .= '<a class="btn btn-default" href="' . htmlspecialchars($url)
1418 . '" title="' . htmlspecialchars($this->nextThree > 1
1419 ? sprintf($this->getLanguageService()->getLL('nextThree'), $this->nextThree)
1420 : $this->getLanguageService()->getLL('edit'))
1421 . '">' . $this->iconFactory->getIcon('actions-document-open', Icon::SIZE_SMALL)->render() . '</a>';
1422 // Hide element:
1423 $hiddenField = $GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'];
1424 if ($hiddenField && $GLOBALS['TCA']['tt_content']['columns'][$hiddenField]
1425 && (!$GLOBALS['TCA']['tt_content']['columns'][$hiddenField]['exclude']
1426 || $this->getBackendUser()->check('non_exclude_fields', 'tt_content:' . $hiddenField))
1427 ) {
1428 if ($row[$hiddenField]) {
1429 $value = 0;
1430 $label = 'unHide';
1431 } else {
1432 $value = 1;
1433 $label = 'hide';
1434 }
1435 $params = '&data[tt_content][' . ($row['_ORIG_uid'] ? $row['_ORIG_uid'] : $row['uid'])
1436 . '][' . $hiddenField . ']=' . $value;
1437 $out .= '<a class="btn btn-default" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1438 . '" title="' . $this->getLanguageService()->getLL($label, true) . '">'
1439 . $this->iconFactory->getIcon('actions-edit-' . strtolower($label), Icon::SIZE_SMALL)->render() . '</a>';
1440 }
1441 // Delete
1442 $disableDeleteTS = $this->getBackendUser()->getTSConfig('options.disableDelete');
1443 $disableDelete = (bool) trim(isset($disableDeleteTS['properties']['tt_content']) ? $disableDeleteTS['properties']['tt_content'] : $disableDeleteTS['value']);
1444 if (!$disableDelete) {
1445 $params = '&cmd[tt_content][' . $row['uid'] . '][delete]=1';
1446 $confirm = $this->getLanguageService()->getLL('deleteWarning')
1447 . BackendUtility::translationCount('tt_content', $row['uid'], (' '
1448 . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.translationsOfRecord')));
1449 $out .= '<a class="btn btn-default t3js-modal-trigger" href="' . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params)) . '"'
1450 . ' data-severity="warning"'
1451 . ' data-title="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_alt_doc.xlf:label.confirm.delete_record.title')) . '"'
1452 . ' data-content="' . htmlspecialchars($confirm) . '" '
1453 . ' data-button-close-text="' . htmlspecialchars($this->getLanguageService()->sL('LLL:EXT:lang/locallang_common.xlf:cancel')) . '"'
1454 . ' title="' . $this->getLanguageService()->getLL('deleteItem', true) . '">'
1455 . $this->iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render() . '</a>';
1456 if ($out && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)) {
1457 $out = '<div class="btn-group btn-group-sm" role="group">' . $out . '</div>';
1458 } else {
1459 $out = '';
1460 }
1461 }
1462 if (!$disableMoveAndNewButtons) {
1463 $moveButtonContent = '';
1464 $displayMoveButtons = false;
1465 // Move element up:
1466 if ($this->tt_contentData['prev'][$row['uid']]) {
1467 $params = '&cmd[tt_content][' . $row['uid'] . '][move]=' . $this->tt_contentData['prev'][$row['uid']];
1468 $moveButtonContent .= '<a class="btn btn-default" href="'
1469 . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1470 . '" title="' . $this->getLanguageService()->getLL('moveUp', true) . '">'
1471 . $this->iconFactory->getIcon('actions-move-up', Icon::SIZE_SMALL)->render() . '</a>';
1472 if (!$dragDropEnabled) {
1473 $displayMoveButtons = true;
1474 }
1475 } else {
1476 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1477 }
1478 // Move element down:
1479 if ($this->tt_contentData['next'][$row['uid']]) {
1480 $params = '&cmd[tt_content][' . $row['uid'] . '][move]= ' . $this->tt_contentData['next'][$row['uid']];
1481 $moveButtonContent .= '<a class="btn btn-default" href="'
1482 . htmlspecialchars(BackendUtility::getLinkToDataHandlerAction($params))
1483 . '" title="' . $this->getLanguageService()->getLL('moveDown', true) . '">'
1484 . $this->iconFactory->getIcon('actions-move-down', Icon::SIZE_SMALL)->render() . '</a>';
1485 if (!$dragDropEnabled) {
1486 $displayMoveButtons = true;
1487 }
1488 } else {
1489 $moveButtonContent .= '<span class="btn btn-default disabled">' . $this->iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
1490 }
1491 if ($displayMoveButtons) {
1492 $out .= '<div class="btn-group btn-group-sm" role="group">' . $moveButtonContent . '</div>';
1493 }
1494 }
1495 }
1496 }
1497 $allowDragAndDrop = $this->isDragAndDropAllowed($row);
1498 $additionalIcons = [];
1499 if ($row['sys_language_uid'] > 0 && $this->checkIfTranslationsExistInLanguage([], (int)$row['sys_language_uid'])) {
1500 $disabledClickMenuItems = 'new,move';
1501 $allowDragAndDrop = false;
1502 }
1503 $additionalIcons[] = $this->getIcon('tt_content', $row, $disabledClickMenuItems) . ' ';
1504 $additionalIcons[] = $langMode ? $this->languageFlag($row['sys_language_uid'], false) : '';
1505 // Get record locking status:
1506 if ($lockInfo = BackendUtility::isRecordLocked('tt_content', $row['uid'])) {
1507 $additionalIcons[] = '<a href="#" onclick="alert(' . GeneralUtility::quoteJSvalue($lockInfo['msg'])
1508 . ');return false;" title="' . htmlspecialchars($lockInfo['msg']) . '">'
1509 . $this->iconFactory->getIcon('status-warning-in-use', Icon::SIZE_SMALL)->render() . '</a>';
1510 }
1511 // Call stats information hook
1512 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'])) {
1513 $_params = ['tt_content', $row['uid'], &$row];
1514 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['recStatInfoHooks'] as $_funcRef) {
1515 $additionalIcons[] = GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1516 }
1517 }
1518 // Wrap the whole header
1519 // NOTE: end-tag for <div class="t3-page-ce-body"> is in getTable_tt_content()
1520 return '<div class="t3-page-ce-header ' . ($allowDragAndDrop ? 't3-page-ce-header-draggable t3js-page-ce-draghandle' : '') . '">
1521 <div class="t3-page-ce-header-icons-left">' . implode('', $additionalIcons) . '</div>
1522 <div class="t3-page-ce-header-icons-right">' . ($out ? '<div class="btn-toolbar">' . $out . '</div>' : '') . '</div>
1523 </div>
1524 <div class="t3-page-ce-body">';
1525 }
1526
1527 /**
1528 * Determine whether Drag & Drop should be allowed
1529 *
1530 * @param array $row
1531 * @return bool
1532 */
1533 protected function isDragAndDropAllowed(array $row)
1534 {
1535 if ($this->getBackendUser()->user['admin']
1536 || ((int)$row['editlock'] === 0 && (int)$this->pageinfo['editlock'] === 0)
1537 && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT)
1538 && $this->getBackendUser()->checkAuthMode('tt_content', 'CType', $row['CType'], $GLOBALS['TYPO3_CONF_VARS']['BE']['explicitADmode'])
1539 ) {
1540 return true;
1541 }
1542 return false;
1543 }
1544
1545 /**
1546 * Draws the preview content for a content element
1547 *
1548 * @param array $row Content element
1549 * @return string HTML
1550 * @throws \UnexpectedValueException
1551 */
1552 public function tt_content_drawItem($row)
1553 {
1554 $out = '';
1555 $outHeader = '';
1556 // Make header:
1557
1558 if ($row['header']) {
1559 $infoArr = [];
1560 $this->getProcessedValue('tt_content', 'header_position,header_layout,header_link', $row, $infoArr);
1561 $hiddenHeaderNote = '';
1562 // If header layout is set to 'hidden', display an accordant note:
1563 if ($row['header_layout'] == 100) {
1564 $hiddenHeaderNote = ' <em>[' . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.hidden', true) . ']</em>';
1565 }
1566 $outHeader = $row['date']
1567 ? htmlspecialchars($this->itemLabels['date'] . ' ' . BackendUtility::date($row['date'])) . '<br />'
1568 : '';
1569 $outHeader .= '<strong>' . $this->linkEditContent($this->renderText($row['header']), $row)
1570 . $hiddenHeaderNote . '</strong><br />';
1571 }
1572 // Make content:
1573 $infoArr = [];
1574 $drawItem = true;
1575 // Hook: Render an own preview of a record
1576 $drawItemHooks = &$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'];
1577 if (is_array($drawItemHooks)) {
1578 foreach ($drawItemHooks as $hookClass) {
1579 $hookObject = GeneralUtility::getUserObj($hookClass);
1580 if (!$hookObject instanceof PageLayoutViewDrawItemHookInterface) {
1581 throw new \UnexpectedValueException($hookClass . ' must implement interface ' . PageLayoutViewDrawItemHookInterface::class, 1218547409);
1582 }
1583 $hookObject->preProcess($this, $drawItem, $outHeader, $out, $row);
1584 }
1585 }
1586
1587 // If the previous hook did not render something,
1588 // then check if a Fluid-based preview template was defined for this CType
1589 // and render it via Fluid. Possible option:
1590 // mod.web_layout.tt_content.preview.media = EXT:site_mysite/Resources/Private/Templates/Preview/Media.html
1591 if ($drawItem) {
1592 $tsConfig = BackendUtility::getModTSconfig($row['pid'], 'mod.web_layout.tt_content.preview');
1593 if (!empty($tsConfig['properties'][$row['CType']])) {
1594 $fluidTemplateFile = $tsConfig['properties'][$row['CType']];
1595 $fluidTemplateFile = GeneralUtility::getFileAbsFileName($fluidTemplateFile);
1596 if ($fluidTemplateFile) {
1597 try {
1598 /** @var StandaloneView $view */
1599 $view = GeneralUtility::makeInstance(StandaloneView::class);
1600 $view->setTemplatePathAndFilename($fluidTemplateFile);
1601 $view->assignMultiple($row);
1602 if (!empty($row['pi_flexform'])) {
1603 /** @var FlexFormService $flexFormService */
1604 $flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
1605 $view->assign('pi_flexform_transformed', $flexFormService->convertFlexFormContentToArray($row['pi_flexform']));
1606 }
1607 $out = $view->render();
1608 $drawItem = false;
1609 } catch (\Exception $e) {
1610 // Catch any exception to avoid breaking the view
1611 }
1612 }
1613 }
1614 }
1615
1616 // Draw preview of the item depending on its CType (if not disabled by previous hook):
1617 if ($drawItem) {
1618 switch ($row['CType']) {
1619 case 'header':
1620 if ($row['subheader']) {
1621 $out .= $this->linkEditContent($this->renderText($row['subheader']), $row) . '<br />';
1622 }
1623 break;
1624 case 'bullets':
1625 case 'table':
1626 if ($row['bodytext']) {
1627 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1628 }
1629 break;
1630 case 'uploads':
1631 if ($row['media']) {
1632 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'media'), $row) . '<br />';
1633 }
1634 break;
1635 case 'menu':
1636 $contentType = $this->CType_labels[$row['CType']];
1637 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
1638 // Add Menu Type
1639 $menuTypeLabel = $this->getLanguageService()->sL(
1640 BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'menu_type', $row['menu_type'])
1641 );
1642 $menuTypeLabel = $menuTypeLabel ?: 'invalid menu type';
1643 $out .= $this->linkEditContent($menuTypeLabel, $row);
1644 if ($row['menu_type'] !== '2' && ($row['pages'] || $row['selected_categories'])) {
1645 // Show pages if menu type is not "Sitemap"
1646 $out .= ':' . $this->linkEditContent($this->generateListForCTypeMenu($row), $row) . '<br />';
1647 }
1648 break;
1649 case 'shortcut':
1650 if (!empty($row['records'])) {
1651 $shortcutContent = [];
1652 $recordList = explode(',', $row['records']);
1653 foreach ($recordList as $recordIdentifier) {
1654 $split = BackendUtility::splitTable_Uid($recordIdentifier);
1655 $tableName = empty($split[0]) ? 'tt_content' : $split[0];
1656 $shortcutRecord = BackendUtility::getRecord($tableName, $split[1]);
1657 if (is_array($shortcutRecord)) {
1658 $icon = $this->iconFactory->getIconForRecord($tableName, $shortcutRecord, Icon::SIZE_SMALL)->render();
1659 $icon = BackendUtility::wrapClickMenuOnIcon(
1660 $icon,
1661 $tableName,
1662 $shortcutRecord['uid'],
1663 1,
1664 '',
1665 '+copy,info,edit,view'
1666 );
1667 $shortcutContent[] = $icon
1668 . htmlspecialchars(BackendUtility::getRecordTitle($tableName, $shortcutRecord));
1669 }
1670 }
1671 $out .= implode('<br />', $shortcutContent) . '<br />';
1672 }
1673 break;
1674 case 'list':
1675 $hookArr = [];
1676 $hookOut = '';
1677 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']])) {
1678 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info'][$row['list_type']];
1679 } elseif (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'])) {
1680 $hookArr = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['list_type_Info']['_DEFAULT'];
1681 }
1682 if (!empty($hookArr)) {
1683 $_params = ['pObj' => &$this, 'row' => $row, 'infoArr' => $infoArr];
1684 foreach ($hookArr as $_funcRef) {
1685 $hookOut .= GeneralUtility::callUserFunction($_funcRef, $_params, $this);
1686 }
1687 }
1688 if ((string)$hookOut !== '') {
1689 $out .= $hookOut;
1690 } elseif (!empty($row['list_type'])) {
1691 $label = BackendUtility::getLabelFromItemListMerged($row['pid'], 'tt_content', 'list_type', $row['list_type']);
1692 if (!empty($label)) {
1693 $out .= $this->linkEditContent('<strong>' . $this->getLanguageService()->sL($label, true) . '</strong>', $row) . '<br />';
1694 } else {
1695 $message = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'), $row['list_type']);
1696 $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>';
1697 }
1698 } elseif (!empty($row['select_key'])) {
1699 $out .= $this->getLanguageService()->sL(BackendUtility::getItemLabel('tt_content', 'select_key'), true)
1700 . ' ' . htmlspecialchars($row['select_key']) . '<br />';
1701 } else {
1702 $out .= '<strong>' . $this->getLanguageService()->getLL('noPluginSelected') . '</strong>';
1703 }
1704 $out .= $this->getLanguageService()->sL(
1705 BackendUtility::getLabelFromItemlist('tt_content', 'pages', $row['pages']),
1706 true
1707 ) . '<br />';
1708 break;
1709 default:
1710 $contentType = $this->CType_labels[$row['CType']];
1711
1712 if (isset($contentType)) {
1713 $out .= $this->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
1714 if ($row['bodytext']) {
1715 $out .= $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
1716 }
1717 if ($row['image']) {
1718 $out .= $this->linkEditContent($this->getThumbCodeUnlinked($row, 'tt_content', 'image'), $row) . '<br />';
1719 }
1720 } else {
1721 $message = sprintf(
1722 $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.noMatchingValue'),
1723 $row['CType']
1724 );
1725 $out .= '<span class="label label-warning">' . htmlspecialchars($message) . '</span>';
1726 }
1727 }
1728 }
1729 // Wrap span-tags:
1730 $out = '
1731 <span class="exampleContent">' . $out . '</span>';
1732 // Add header:
1733 $out = $outHeader . $out;
1734 // Return values:
1735 if ($this->isDisabled('tt_content', $row)) {
1736 return '<span class="text-muted">' . $out . '</span>';
1737 } else {
1738 return $out;
1739 }
1740 }
1741
1742 /**
1743 * Generates a list of selected pages or categories for the CType menu
1744 *
1745 * @param array $row row from pages
1746 * @return string
1747 */
1748 protected function generateListForCTypeMenu(array $row)
1749 {
1750 $table = 'pages';
1751 $field = 'pages';
1752 // get categories instead of pages
1753 if (strpos($row['menu_type'], 'categorized_') !== false) {
1754 $table = 'sys_category';
1755 $field = 'selected_categories';
1756 }
1757 if (trim($row[$field]) === '') {
1758 return '';
1759 }
1760 $content = '';
1761 $uidList = explode(',', $row[$field]);
1762 foreach ($uidList as $uid) {
1763 $uid = (int)$uid;
1764 $record = BackendUtility::getRecord($table, $uid, 'title');
1765 $content .= '<br>' . $record['title'] . ' (' . $uid . ')';
1766 }
1767 return $content;
1768 }
1769
1770 /**
1771 * Filters out all tt_content uids which are already translated so only non-translated uids is left.
1772 * Selects across columns, but within in the same PID. Columns are expect to be the same
1773 * for translations and original but this may be a conceptual error (?)
1774 *
1775 * @param array $defLanguageCount Numeric array with uids of tt_content elements in the default language
1776 * @param int $id Page pid
1777 * @param int $lP Sys language UID
1778 * @return array Modified $defLanguageCount
1779 */
1780 public function getNonTranslatedTTcontentUids($defLanguageCount, $id, $lP)
1781 {
1782 if ($lP && !empty($defLanguageCount)) {
1783 // Select all translations here:
1784 $where = 'sys_language_uid=' . intval($lP) . ' AND l18n_parent IN ('
1785 . implode(',', $defLanguageCount) . ')'
1786 . BackendUtility::deleteClause('tt_content');
1787 $rowArr = $this->getDatabase()->exec_SELECTgetRows('*', 'tt_content', $where);
1788
1789 // Flip uids:
1790 $defLanguageCount = array_flip($defLanguageCount);
1791 // Traverse any selected elements and unset original UID if any:
1792 foreach ($rowArr as $row) {
1793 BackendUtility::workspaceOL('tt_content', $row);
1794 unset($defLanguageCount[$row['l18n_parent']]);
1795 }
1796 // Flip again:
1797 $defLanguageCount = array_keys($defLanguageCount);
1798 }
1799 return $defLanguageCount;
1800 }
1801
1802 /**
1803 * Creates button which is used to create copies of records..
1804 *
1805 * @param array $defLanguageCount Numeric array with uids of tt_content elements in the default language
1806 * @param int $lP Sys language UID
1807 * @param int $colPos Column position
1808 * @return string "Copy languages" button, if available.
1809 */
1810 public function newLanguageButton($defLanguageCount, $lP, $colPos = 0)
1811 {
1812 $lP = (int)$lP;
1813 if (!$this->doEdit || !$lP) {
1814 return '';
1815 }
1816 $theNewButton = '';
1817
1818 $allowCopy = true;
1819 $allowTranslate = true;
1820 if (!empty($this->languageHasTranslationsCache[$lP])) {
1821 if (isset($this->languageHasTranslationsCache[$lP]['hasStandAloneContent'])) {
1822 $allowTranslate = false;
1823 }
1824 if (isset($this->languageHasTranslationsCache[$lP]['hasTranslations'])) {
1825 $allowCopy = false;
1826 }
1827 }
1828
1829 if (isset($this->contentElementCache[$lP][$colPos]) && is_array($this->contentElementCache[$lP][$colPos])) {
1830 foreach ($this->contentElementCache[$lP][$colPos] as $record) {
1831 $key = array_search($record['t3_origuid'], $defLanguageCount);
1832 if ($key !== false) {
1833 unset($defLanguageCount[$key]);
1834 }
1835 }
1836 }
1837
1838 if (!empty($defLanguageCount)) {
1839 $theNewButton =
1840 '<input'
1841 . ' class="btn btn-default t3js-localize"'
1842 . ' type="button"'
1843 . ' disabled'
1844 . ' value="' . htmlspecialchars($this->getLanguageService()->getLL('newPageContent_translate', true)) . '"'
1845 . ' data-has-elements="' . (int)!empty($this->contentElementCache[$lP][$colPos]) . '"'
1846 . ' data-allow-copy="' . (int)$allowCopy . '"'
1847 . ' data-allow-translate="' . (int)$allowTranslate . '"'
1848 . ' data-table="tt_content"'
1849 . ' data-page-id="' . (int)GeneralUtility::_GP('id') . '"'
1850 . ' data-language-id="' . $lP . '"'
1851 . ' data-language-name="' . htmlspecialchars($this->tt_contentConfig['languageCols'][$lP]) . '"'
1852 . ' data-colpos-id="' . $colPos . '"'
1853 . ' data-colpos-name="' . BackendUtility::getProcessedValue('tt_content', 'colPos', $colPos) . '"'
1854 . '/>';
1855 }
1856
1857 return '<div class="t3-page-lang-copyce">' . $theNewButton . '</div>';
1858 }
1859
1860 /**
1861 * Creates onclick-attribute content for a new content element
1862 *
1863 * @param int $id Page id where to create the element.
1864 * @param int $colPos Preset: Column position value
1865 * @param int $sys_language Preset: Sys langauge value
1866 * @return string String for onclick attribute.
1867 * @see getTable_tt_content()
1868 */
1869 public function newContentElementOnClick($id, $colPos, $sys_language)
1870 {
1871 if ($this->option_newWizard) {
1872 $tsConfig = BackendUtility::getModTSconfig($id, 'mod');
1873 $moduleName = isset($tsConfig['properties']['newContentElementWizard.']['override'])
1874 ? $tsConfig['properties']['newContentElementWizard.']['override']
1875 : 'new_content_element';
1876 $onClick = 'window.location.href=' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl($moduleName) . '&id=' . $id . '&colPos=' . $colPos
1877 . '&sys_language_uid=' . $sys_language . '&uid_pid=' . $id
1878 . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'))) . ';';
1879 } else {
1880 $onClick = BackendUtility::editOnClick('&edit[tt_content][' . $id . ']=new&defVals[tt_content][colPos]='
1881 . $colPos . '&defVals[tt_content][sys_language_uid]=' . $sys_language);
1882 }
1883 return $onClick;
1884 }
1885
1886 /**
1887 * Will create a link on the input string and possibly a big button after the string which links to editing in the RTE.
1888 * Used for content element content displayed so the user can click the content / "Edit in Rich Text Editor" button
1889 *
1890 * @param string $str String to link. Must be prepared for HTML output.
1891 * @param array $row The row.
1892 * @return string If the whole thing was editable ($this->doEdit) $str is return with link around. Otherwise just $str.
1893 * @see getTable_tt_content()
1894 */
1895 public function linkEditContent($str, $row)
1896 {
1897 if ($this->doEdit && $this->getBackendUser()->recordEditAccessInternals('tt_content', $row)) {
1898 $urlParameters = [
1899 'edit' => [
1900 'tt_content' => [
1901 $row['uid'] => 'edit'
1902 ]
1903 ],
1904 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1905 ];
1906 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
1907 // Return link
1908 return '<a href="' . htmlspecialchars($url) . '" title="' . $this->getLanguageService()->getLL('edit', true) . '">' . $str . '</a>';
1909 } else {
1910 return $str;
1911 }
1912 }
1913
1914 /**
1915 * Make selector box for creating new translation in a language
1916 * Displays only languages which are not yet present for the current page and
1917 * that are not disabled with page TS.
1918 *
1919 * @param int $id Page id for which to create a new language (pages_language_overlay record)
1920 * @return string <select> HTML element (if there were items for the box anyways...)
1921 * @see getTable_tt_content()
1922 */
1923 public function languageSelector($id)
1924 {
1925 if ($this->getBackendUser()->check('tables_modify', 'pages_language_overlay')) {
1926 // First, select all
1927 $res = $this->getPageLayoutController()->exec_languageQuery(0);
1928 $langSelItems = [];
1929 $langSelItems[0] = '
1930 <option value="0"></option>';
1931 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1932 if ($this->getBackendUser()->checkLanguageAccess($row['uid'])) {
1933 $langSelItems[$row['uid']] = '
1934 <option value="' . $row['uid'] . '">' . htmlspecialchars($row['title']) . '</option>';
1935 }
1936 }
1937 // Then, subtract the languages which are already on the page:
1938 $res = $this->getPageLayoutController()->exec_languageQuery($id);
1939 while ($row = $this->getDatabase()->sql_fetch_assoc($res)) {
1940 unset($langSelItems[$row['uid']]);
1941 }
1942 // Remove disallowed languages
1943 if (count($langSelItems) > 1
1944 && !$this->getBackendUser()->user['admin']
1945 && $this->getBackendUser()->groupData['allowed_languages'] !== ''
1946 ) {
1947 $allowed_languages = array_flip(explode(',', $this->getBackendUser()->groupData['allowed_languages']));
1948 if (!empty($allowed_languages)) {
1949 foreach ($langSelItems as $key => $value) {
1950 if (!isset($allowed_languages[$key]) && $key != 0) {
1951 unset($langSelItems[$key]);
1952 }
1953 }
1954 }
1955 }
1956 // Remove disabled languages
1957 $modSharedTSconfig = BackendUtility::getModTSconfig($id, 'mod.SHARED');
1958 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages'])
1959 ? GeneralUtility::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], true)
1960 : [];
1961 if (!empty($langSelItems) && !empty($disableLanguages)) {
1962 foreach ($disableLanguages as $language) {
1963 if ($language != 0 && isset($langSelItems[$language])) {
1964 unset($langSelItems[$language]);
1965 }
1966 }
1967 }
1968 // If any languages are left, make selector:
1969 if (count($langSelItems) > 1) {
1970 $url = BackendUtility::getModuleUrl('record_edit', [
1971 'edit[pages_language_overlay][' . $id . ']' => 'new',
1972 'overrideVals[pages_language_overlay][doktype]' => (int)$this->pageRecord['doktype'],
1973 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')
1974 ]);
1975 $onChangeContent = 'window.location.href=' . GeneralUtility::quoteJSvalue($url . '&overrideVals[pages_language_overlay][sys_language_uid]=') . '+this.options[this.selectedIndex].value';
1976 return '<div class="form-inline form-inline-spaced">'
1977 . '<div class="form-group">'
1978 . '<label for="createNewLanguage">'
1979 . $this->getLanguageService()->getLL('new_language', true)
1980 . '</label>'
1981 . '<select class="form-control input-sm" name="createNewLanguage" onchange="' . htmlspecialchars($onChangeContent) . '">'
1982 . implode('', $langSelItems)
1983 . '</select></div></div>';
1984 }
1985 }
1986 return '';
1987 }
1988
1989 /**
1990 * Traverse the result pointer given, adding each record to array and setting some internal values at the same time.
1991 *
1992 * @param bool|\mysqli_result|object $result MySQLi result object / DBAL object
1993 * @param string $table Table name defaulting to tt_content
1994 * @return array The selected rows returned in this array.
1995 */
1996 public function getResult($result, $table = 'tt_content')
1997 {
1998 $output = [];
1999 // Traverse the result:
2000 while ($row = $this->getDatabase()->sql_fetch_assoc($result)) {
2001 BackendUtility::workspaceOL($table, $row, -99, true);
2002 if ($row) {
2003 // Add the row to the array:
2004 $output[] = $row;
2005 }
2006 }
2007 $this->generateTtContentDataArray($output);
2008 // Return selected records
2009 return $output;
2010 }
2011
2012 /********************************
2013 *
2014 * Various helper functions
2015 *
2016 ********************************/
2017
2018 /**
2019 * Initializes the clipboard for generating paste links
2020 *
2021 * @return void
2022 *
2023 * @see \TYPO3\CMS\Recordlist\RecordList::main()
2024 * @see \TYPO3\CMS\Backend\Controller\ClickMenuController::main()
2025 * @see \TYPO3\CMS\Filelist\Controller\FileListController::main()
2026 */
2027 protected function initializeClipboard()
2028 {
2029 // Start clipboard
2030 $this->clipboard = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Clipboard\Clipboard::class);
2031
2032 // Initialize - reads the clipboard content from the user session
2033 $this->clipboard->initializeClipboard();
2034
2035 // This locks the clipboard to the Normal for this request.
2036 $this->clipboard->lockToNormal();
2037
2038 // Clean up pad
2039 $this->clipboard->cleanCurrent();
2040
2041 // Save the clipboard content
2042 $this->clipboard->endClipboard();
2043 }
2044
2045 /**
2046 * Generates the data for previous and next elements which is needed for movements.
2047 *
2048 * @param array $rowArray
2049 * @return void
2050 */
2051 protected function generateTtContentDataArray(array $rowArray)
2052 {
2053 if (empty($this->tt_contentData)) {
2054 $this->tt_contentData = [
2055 'nextThree' => [],
2056 'next' => [],
2057 'prev' => [],
2058 ];
2059 }
2060 foreach ($rowArray as $key => $value) {
2061 // Create the list of the next three ids (for editing links...)
2062 for ($i = 0; $i < $this->nextThree; $i++) {
2063 if (isset($rowArray[$key - $i])
2064 && !GeneralUtility::inList($this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']], $value['uid'])
2065 ) {
2066 $this->tt_contentData['nextThree'][$rowArray[$key - $i]['uid']] .= $value['uid'] . ',';
2067 }
2068 }
2069
2070 // Create information for next and previous content elements
2071 if (isset($rowArray[$key - 1])) {
2072 if (isset($rowArray[$key - 2])) {
2073 $this->tt_contentData['prev'][$value['uid']] = -$rowArray[$key - 2]['uid'];
2074 } else {
2075 $this->tt_contentData['prev'][$value['uid']] = $value['pid'];
2076 }
2077 $this->tt_contentData['next'][$rowArray[$key - 1]['uid']] = -$value['uid'];
2078 }
2079 }
2080 }
2081
2082 /**
2083 * Counts and returns the number of records on the page with $pid
2084 *
2085 * @param string $table Table name
2086 * @param int $pid Page id
2087 * @return int Number of records.
2088 */
2089 public function numberOfRecords($table, $pid)
2090 {
2091 $count = 0;
2092 if ($GLOBALS['TCA'][$table]) {
2093 $where = 'pid=' . (int)$pid . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table);
2094 $count = $this->getDatabase()->exec_SELECTcountRows('uid', $table, $where);
2095 }
2096 return (int)$count;
2097 }
2098
2099 /**
2100 * Processing of larger amounts of text (usually from RTE/bodytext fields) with word wrapping etc.
2101 *
2102 * @param string $input Input string
2103 * @return string Output string
2104 */
2105 public function renderText($input)
2106 {
2107 $input = strip_tags($input);
2108 $input = GeneralUtility::fixed_lgd_cs($input, 1500);
2109 return nl2br(htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8', false));
2110 }
2111
2112 /**
2113 * Creates the icon image tag for record from table and wraps it in a link which will trigger the click menu.
2114 *
2115 * @param string $table Table name
2116 * @param array $row Record array
2117 * @param string $enabledClickMenuItems Passthrough to wrapClickMenuOnIcon
2118 * @return string HTML for the icon
2119 */
2120 public function getIcon($table, $row, $enabledClickMenuItems = '')
2121 {
2122 // Initialization
2123 $toolTip = BackendUtility::getRecordToolTip($row, 'tt_content');
2124 $icon = '<span ' . $toolTip . '>' . $this->iconFactory->getIconForRecord($table, $row, Icon::SIZE_SMALL)->render() . '</span>';
2125 $this->counter++;
2126 // The icon with link
2127 if ($this->getBackendUser()->recordEditAccessInternals($table, $row)) {
2128 $icon = BackendUtility::wrapClickMenuOnIcon($icon, $table, $row['uid'], true, '', $enabledClickMenuItems);
2129 }
2130 return $icon;
2131 }
2132
2133 /**
2134 * Creates processed values for all field names in $fieldList based on values from $row array.
2135 * The result is 'returned' through $info which is passed as a reference
2136 *
2137 * @param string $table Table name
2138 * @param string $fieldList Comma separated list of fields.
2139 * @param array $row Record from which to take values for processing.
2140 * @param array $info Array to which the processed values are added.
2141 * @return void
2142 */
2143 public function getProcessedValue($table, $fieldList, array $row, array &$info)
2144 {
2145 // Splitting values from $fieldList
2146 $fieldArr = explode(',', $fieldList);
2147 // Traverse fields from $fieldList
2148 foreach ($fieldArr as $field) {
2149 if ($row[$field]) {
2150 $info[] = '<strong>' . htmlspecialchars($this->itemLabels[$field]) . '</strong> '
2151 . htmlspecialchars(BackendUtility::getProcessedValue($table, $field, $row[$field]));
2152 }
2153 }
2154 }
2155
2156 /**
2157 * Returns TRUE, if the record given as parameters is NOT visible based on hidden/starttime/endtime (if available)
2158 *
2159 * @param string $table Tablename of table to test
2160 * @param array $row Record row.
2161 * @return bool Returns TRUE, if disabled.
2162 */
2163 public function isDisabled($table, $row)
2164 {
2165 $enableCols = $GLOBALS['TCA'][$table]['ctrl']['enablecolumns'];
2166 return $enableCols['disabled'] && $row[$enableCols['disabled']]
2167 || $enableCols['starttime'] && $row[$enableCols['starttime']] > $GLOBALS['EXEC_TIME']
2168 || $enableCols['endtime'] && $row[$enableCols['endtime']] && $row[$enableCols['endtime']] < $GLOBALS['EXEC_TIME'];
2169 }
2170
2171 /**
2172 * Returns icon for "no-edit" of a record.
2173 * Basically, the point is to signal that this record could have had an edit link if
2174 * the circumstances were right. A placeholder for the regular edit icon...
2175 *
2176 * @param string $label Label key from LOCAL_LANG
2177 * @return string IMG tag for icon.
2178 */
2179 public function noEditIcon($label = 'noEditItems')
2180 {
2181 $title = $this->getLanguageService()->getLL($label, true);
2182 return '<span title="' . $title . '">' . $this->iconFactory->getIcon('status-status-edit-read-only', Icon::SIZE_SMALL)->render() . '</span>';
2183 }
2184
2185 /**
2186 * Function, which fills in the internal array, $this->allowedTableNames with all tables to
2187 * which the user has access. Also a set of standard tables (pages, static_template, sys_filemounts, etc...)
2188 * are filtered out. So what is left is basically all tables which makes sense to list content from.
2189 *
2190 * @return array
2191 */
2192 protected function cleanTableNames()
2193 {
2194 // Get all table names:
2195 $tableNames = array_flip(array_keys($GLOBALS['TCA']));
2196 // Unset common names:
2197 unset($tableNames['pages']);
2198 unset($tableNames['static_template']);
2199 unset($tableNames['sys_filemounts']);
2200 unset($tableNames['sys_action']);
2201 unset($tableNames['sys_workflows']);
2202 unset($tableNames['be_users']);
2203 unset($tableNames['be_groups']);
2204 $allowedTableNames = [];
2205 // Traverse table names and set them in allowedTableNames array IF they can be read-accessed by the user.
2206 if (is_array($tableNames)) {
2207 foreach ($tableNames as $k => $v) {
2208 if (!$GLOBALS['TCA'][$k]['ctrl']['hideTable'] && $this->getBackendUser()->check('tables_select', $k)) {
2209 $allowedTableNames['table_' . $k] = $k;
2210 }
2211 }
2212 }
2213 return $allowedTableNames;
2214 }
2215
2216 /*****************************************
2217 *
2218 * External renderings
2219 *
2220 *****************************************/
2221
2222 /**
2223 * Creates a menu of the tables that can be listed by this function
2224 * Only tables which has records on the page will be included.
2225 * Notice: The function also fills in the internal variable $this->activeTables with icon/titles.
2226 *
2227 * @param int $id Page id from which we are listing records (the function will look up if there are records on the page)
2228 * @return string HTML output.
2229 */
2230 public function getTableMenu($id)
2231 {
2232 // Initialize:
2233 $this->activeTables = [];
2234 $theTables = ['tt_content'];
2235 // External tables:
2236 if (is_array($this->externalTables)) {
2237 $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
2238 }
2239 $out = '';
2240 // Traverse tables to check:
2241 foreach ($theTables as $tName) {
2242 // Check access and whether the proper extensions are loaded:
2243 if ($this->getBackendUser()->check('tables_select', $tName)
2244 && (isset($this->externalTables[$tName])
2245 || $tName === 'fe_users' || $tName === 'tt_content'
2246 || \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($tName)
2247 )
2248 ) {
2249 // Make query to count records from page:
2250 $c = $this->getDatabase()->exec_SELECTcountRows('uid', $tName, 'pid=' . (int)$id
2251 . BackendUtility::deleteClause($tName) . BackendUtility::versioningPlaceholderClause($tName));
2252 // If records were found (or if "tt_content" is the table...):
2253 if ($c || $tName === 'tt_content') {
2254 // Add row to menu:
2255 $out .= '
2256 <td><a href="#' . $tName . '" title="' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true) . '"></a>'
2257 . $this->iconFactory->getIconForRecord($tName, [], Icon::SIZE_SMALL)->render()
2258 . '</td>';
2259 // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
2260 $title = $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true)
2261 . ': ' . $c . ' ' . $this->getLanguageService()->getLL('records', true);
2262 $this->activeTables[$tName] = '<span title="' . $title . '">'
2263 . $this->iconFactory->getIconForRecord($tName, [], Icon::SIZE_SMALL)->render()
2264 . '</span>'
2265 . '&nbsp;' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true);
2266 }
2267 }
2268 }
2269 // Wrap cells in table tags:
2270 $out = '
2271 <!--
2272 Menu of tables on the page (table menu)
2273 -->
2274 <table border="0" cellpadding="0" cellspacing="0" id="typo3-page-tblMenu">
2275 <tr>' . $out . '
2276 </tr>
2277 </table>';
2278 // Return the content:
2279 return $out;
2280 }
2281
2282 /**
2283 * Create thumbnail code for record/field but not linked
2284 *
2285 * @param mixed[] $row Record array
2286 * @param string $table Table (record is from)
2287 * @param string $field Field name for which thumbnail are to be rendered.
2288 * @return string HTML for thumbnails, if any.
2289 */
2290 public function getThumbCodeUnlinked($row, $table, $field)
2291 {
2292 return BackendUtility::thumbCode($row, $table, $field, '', '', null, 0, '', '', false);
2293 }
2294
2295 /**
2296 * Checks whether translated Content Elements exist in the desired language
2297 * If so, deny creating new ones via the UI
2298 *
2299 * @param array $contentElements
2300 * @param int $language
2301 * @return bool
2302 */
2303 protected function checkIfTranslationsExistInLanguage(array $contentElements, $language)
2304 {
2305 // If in default language, you may always create new entries
2306 // Also, you may override this strict behavior via user TS Config
2307 // If you do so, you're on your own and cannot rely on any support by the TYPO3 core
2308 // We jump out here since we don't need to do the expensive loop operations
2309 $allowInconsistentLanguageHandling = BackendUtility::getModTSconfig($this->id, 'mod.web_layout.allowInconsistentLanguageHandling');
2310 if ($language === 0 || $allowInconsistentLanguageHandling['value'] === '1') {
2311 return false;
2312 }
2313 /**
2314 * Build up caches
2315 */
2316 if (!isset($this->languageHasTranslationsCache[$language])) {
2317 foreach ($contentElements as $columns) {
2318 foreach ($columns as $contentElement) {
2319 if ((int)$contentElement['l18n_parent'] === 0) {
2320 $this->languageHasTranslationsCache[$language]['hasStandAloneContent'] = true;
2321 }
2322 if ((int)$contentElement['l18n_parent'] > 0) {
2323 $this->languageHasTranslationsCache[$language]['hasTranslations'] = true;
2324 }
2325 }
2326 }
2327 // Check whether we have a mix of both
2328 if ($this->languageHasTranslationsCache[$language]['hasStandAloneContent']
2329 && $this->languageHasTranslationsCache[$language]['hasTranslations']
2330 ) {
2331 $message = GeneralUtility::makeInstance(
2332 FlashMessage::class,
2333 sprintf($this->getLanguageService()->getLL('staleTranslationWarning'), $this->languageIconTitles[$language]['title']),
2334 sprintf($this->getLanguageService()->getLL('staleTranslationWarningTitle'), $this->languageIconTitles[$language]['title']),
2335 FlashMessage::WARNING
2336 );
2337 $service = GeneralUtility::makeInstance(FlashMessageService::class);
2338 $queue = $service->getMessageQueueByIdentifier();
2339 $queue->addMessage($message);
2340 }
2341 }
2342 if ($this->languageHasTranslationsCache[$language]['hasTranslations']) {
2343 return true;
2344 }
2345 return false;
2346 }
2347
2348 /**
2349 * @return BackendLayoutView
2350 */
2351 protected function getBackendLayoutView()
2352 {
2353 return GeneralUtility::makeInstance(BackendLayoutView::class);
2354 }
2355
2356 /**
2357 * @return BackendUserAuthentication
2358 */
2359 protected function getBackendUser()
2360 {
2361 return $GLOBALS['BE_USER'];
2362 }
2363
2364 /**
2365 * @return DatabaseConnection
2366 */
2367 protected function getDatabase()
2368 {
2369 return $GLOBALS['TYPO3_DB'];
2370 }
2371
2372 /**
2373 * @return PageLayoutController
2374 */
2375 protected function getPageLayoutController()
2376 {
2377 return $GLOBALS['SOBE'];
2378 }
2379 }