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