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