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