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