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