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