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