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