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