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