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