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