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