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