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