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