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