5ce1b74531a335229fc7d6c6eb499cd4132ff935
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / PageLayoutController.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Controller;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
20 use TYPO3\CMS\Backend\Module\ModuleLoader;
21 use TYPO3\CMS\Backend\Routing\UriBuilder;
22 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
23 use TYPO3\CMS\Backend\Template\ModuleTemplate;
24 use TYPO3\CMS\Backend\Utility\BackendUtility;
25 use TYPO3\CMS\Backend\View\BackendLayoutView;
26 use TYPO3\CMS\Backend\View\PageLayoutView;
27 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
28 use TYPO3\CMS\Core\Compatibility\PublicMethodDeprecationTrait;
29 use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
30 use TYPO3\CMS\Core\Database\ConnectionPool;
31 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
32 use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
33 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
34 use TYPO3\CMS\Core\DataHandling\DataHandler;
35 use TYPO3\CMS\Core\Http\HtmlResponse;
36 use TYPO3\CMS\Core\Imaging\Icon;
37 use TYPO3\CMS\Core\Imaging\IconFactory;
38 use TYPO3\CMS\Core\Localization\LanguageService;
39 use TYPO3\CMS\Core\Page\PageRenderer;
40 use TYPO3\CMS\Core\Site\Entity\SiteInterface;
41 use TYPO3\CMS\Core\Type\Bitmask\Permission;
42 use TYPO3\CMS\Core\Utility\GeneralUtility;
43 use TYPO3\CMS\Core\Utility\MathUtility;
44 use TYPO3\CMS\Core\Versioning\VersionState;
45 use TYPO3\CMS\Fluid\View\StandaloneView;
46 use TYPO3\CMS\Fluid\ViewHelpers\Be\InfoboxViewHelper;
47 use TYPO3\CMS\Frontend\Page\PageRepository;
48
49 /**
50 * Script Class for Web > Layout module
51 */
52 class PageLayoutController
53 {
54 use PublicMethodDeprecationTrait;
55 use PublicPropertyDeprecationTrait;
56
57 /**
58 * @var array
59 */
60 private $deprecatedPublicMethods = [
61 'init' => 'Using PageLayoutController::init() is deprecated and will not be possible anymore in TYPO3 v10.',
62 'main' => 'Using PageLayoutController::main() is deprecated and will not be possible anymore in TYPO3 v10.',
63 'menuConfig' => 'Using PageLayoutController::menuConfig() is deprecated and will not be possible anymore in TYPO3 v10.',
64 'renderContent' => 'Using PageLayoutController::renderContent() is deprecated and will not be possible anymore in TYPO3 v10.',
65 'clearCache' => 'Using PageLayoutController::clearCache() is deprecated and will not be possible anymore in TYPO3 v10.',
66 'getModuleTemplate' => 'Using PageLayoutController::getModuleTemplate() is deprecated and will not be possible anymore in TYPO3 v10.',
67 'getLocalizedPageTitle' => 'Using PageLayoutController::getLocalizedPageTitle() is deprecated and will not be possible anymore in TYPO3 v10.',
68 'getNumberOfHiddenElements' => 'Using PageLayoutController::getNumberOfHiddenElements() is deprecated and will not be possible anymore in TYPO3 v10.',
69 'local_linkThisScript' => 'Using PageLayoutController::local_linkThisScript() is deprecated and will not be possible anymore in TYPO3 v10.',
70 'pageIsNotLockedForEditors' => 'Using PageLayoutController::pageIsNotLockedForEditors() is deprecated and will not be possible anymore in TYPO3 v10.',
71 'contentIsNotLockedForEditors' => 'Using PageLayoutController::contentIsNotLockedForEditors() is deprecated and will not be possible anymore in TYPO3 v10.',
72 ];
73
74 /**
75 * @var array
76 */
77 private $deprecatedPublicProperties = [
78 'pointer' => 'Using PageLayoutController::$pointer is deprecated and will not be possible anymore in TYPO3 v10.',
79 'imagemode' => 'Using PageLayoutController::$imagemode is deprecated and will not be possible anymore in TYPO3 v10.',
80 'search_field' => 'Using PageLayoutController::$search_field is deprecated and will not be possible anymore in TYPO3 v10.',
81 'search_levels' => 'Using PageLayoutController::$search_levels is deprecated and will not be possible anymore in TYPO3 v10.',
82 'showLimit' => 'Using PageLayoutController::$showLimit is deprecated and will not be possible anymore in TYPO3 v10.',
83 'returnUrl' => 'Using PageLayoutController::$returnUrl is deprecated and will not be possible anymore in TYPO3 v10.',
84 'clear_cache' => 'Using PageLayoutController::$clear_cache is deprecated and will not be possible anymore in TYPO3 v10.',
85 'popView' => 'Using PageLayoutController::$popView is deprecated and will not be possible anymore in TYPO3 v10.',
86 'perms_clause' => 'Using PageLayoutController::$perms_clause is deprecated and will not be possible anymore in TYPO3 v10.',
87 'modTSconfig' => 'Using PageLayoutController::$modTSconfig is deprecated and will not be possible anymore in TYPO3 v10.',
88 'modSharedTSconfig' => 'Using PageLayoutController::$modSharedTSconfig is deprecated and will not be possible anymore in TYPO3 v10.',
89 'descrTable' => 'Using PageLayoutController::$descrTable is deprecated and will not be possible anymore in TYPO3 v10.',
90 'colPosList' => 'Using PageLayoutController::$colPosList is deprecated and will not be possible anymore in TYPO3 v10.',
91 'EDIT_CONTENT' => 'Using PageLayoutController::$EDIT_CONTENT is deprecated and will not be possible anymore in TYPO3 v10.',
92 'CALC_PERMS' => 'Using PageLayoutController::$CALC_PERMS is deprecated and will not be possible anymore in TYPO3 v10.',
93 'current_sys_language' => 'Using PageLayoutController::$current_sys_language is deprecated and will not be possible anymore in TYPO3 v10.',
94 'MCONF' => 'Using PageLayoutController::$MCONF is deprecated and will not be possible anymore in TYPO3 v10.',
95 'MOD_MENU' => 'Using PageLayoutController::$MOD_MENU is deprecated and will not be possible anymore in TYPO3 v10.',
96 'content' => 'Using PageLayoutController::$content is deprecated and will not be possible anymore in TYPO3 v10.',
97 'activeColPosList' => 'Using PageLayoutController::$activeColPosList is deprecated and will not be possible anymore in TYPO3 v10.',
98 ];
99
100 /**
101 * Page Id for which to make the listing
102 *
103 * @var int
104 * @internal
105 */
106 public $id;
107
108 /**
109 * Pointer - for browsing list of records.
110 *
111 * @var int
112 */
113 protected $pointer;
114
115 /**
116 * Thumbnails or not
117 *
118 * @var string
119 */
120 protected $imagemode;
121
122 /**
123 * Search-fields
124 *
125 * @var string
126 */
127 protected $search_field;
128
129 /**
130 * Search-levels
131 *
132 * @var int
133 */
134 protected $search_levels;
135
136 /**
137 * Show-limit
138 *
139 * @var int
140 */
141 protected $showLimit;
142
143 /**
144 * Return URL
145 *
146 * @var string
147 */
148 protected $returnUrl;
149
150 /**
151 * Clear-cache flag - if set, clears page cache for current id.
152 *
153 * @var bool
154 */
155 protected $clear_cache;
156
157 /**
158 * PopView id - for opening a window with the page
159 *
160 * @var bool
161 */
162 protected $popView;
163
164 /**
165 * Page select perms clause
166 *
167 * @var string
168 */
169 protected $perms_clause;
170
171 /**
172 * Module TSconfig
173 *
174 * @var array
175 */
176 protected $modTSconfig = [];
177
178 /**
179 * Module shared TSconfig
180 *
181 * @var array
182 */
183 protected $modSharedTSconfig = [];
184
185 /**
186 * Current ids page record
187 *
188 * @var array
189 * @internal
190 */
191 public $pageinfo;
192
193 /**
194 * "Pseudo" Description -table name
195 *
196 * @var string
197 */
198 protected $descrTable;
199
200 /**
201 * List of column-integers to edit. Is set from TSconfig, default is "1,0,2,3"
202 *
203 * @var string
204 */
205 protected $colPosList;
206
207 /**
208 * Flag: If content can be edited or not.
209 *
210 * @var bool
211 */
212 protected $EDIT_CONTENT;
213
214 /**
215 * Users permissions integer for this page.
216 *
217 * @var int
218 */
219 protected $CALC_PERMS;
220
221 /**
222 * Currently selected language for editing content elements
223 *
224 * @var int
225 */
226 protected $current_sys_language;
227
228 /**
229 * Module configuration
230 *
231 * @var array
232 */
233 protected $MCONF = [];
234
235 /**
236 * Menu configuration
237 *
238 * @var array
239 */
240 protected $MOD_MENU = [];
241
242 /**
243 * Module settings (session variable)
244 *
245 * @var array
246 * @internal
247 */
248 public $MOD_SETTINGS = [];
249
250 /**
251 * Module output accumulation
252 *
253 * @var string
254 */
255 protected $content;
256
257 /**
258 * List of column-integers accessible to the current BE user.
259 * Is set from TSconfig, default is $colPosList
260 *
261 * @var string
262 */
263 protected $activeColPosList;
264
265 /**
266 * @var string
267 */
268 protected $editSelect;
269
270 /**
271 * Caches the available languages in a colPos
272 *
273 * @var array
274 */
275 protected $languagesInColumnCache = [];
276
277 /**
278 * @var IconFactory
279 */
280 protected $iconFactory;
281
282 /**
283 * The name of the module
284 *
285 * @var string
286 */
287 protected $moduleName = 'web_layout';
288
289 /**
290 * @var ModuleTemplate
291 */
292 protected $moduleTemplate;
293
294 /**
295 * @var ButtonBar
296 */
297 protected $buttonBar;
298
299 /**
300 * @var string
301 */
302 protected $searchContent;
303
304 /**
305 * Injects the request object for the current request or subrequest
306 * As this controller goes only through the main() method, it is rather simple for now
307 *
308 * @param ServerRequestInterface $request the current request
309 * @return ResponseInterface the response with the content
310 */
311 public function mainAction(ServerRequestInterface $request): ResponseInterface
312 {
313 $GLOBALS['SOBE'] = $this;
314 $this->init($request);
315 $this->clearCache();
316 $this->main($request);
317 return new HtmlResponse($this->moduleTemplate->renderContent());
318 }
319
320 /**
321 * Initializing the module
322 * @param ServerRequestInterface $request
323 */
324 protected function init(ServerRequestInterface $request = null): void
325 {
326 $request = $request ?: $GLOBALS['TYPO3_REQUEST'];
327 // Set the GPvars from outside
328 $parsedBody = $request->getParsedBody();
329 $queryParams = $request->getQueryParams();
330
331 $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
332 $this->iconFactory = $this->moduleTemplate->getIconFactory();
333 $this->buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
334 $this->getLanguageService()->includeLLFile('EXT:backend/Resources/Private/Language/locallang_layout.xlf');
335 // Setting module configuration / page select clause
336 $this->MCONF['name'] = $this->moduleName;
337 $this->perms_clause = $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW);
338 // Get session data
339 $sessionData = $this->getBackendUser()->getSessionData(__CLASS__);
340 $this->search_field = !empty($sessionData['search_field']) ? $sessionData['search_field'] : '';
341
342 $this->id = (int)($parsedBody['id'] ?? $queryParams['id'] ?? 0);
343 $this->pointer = $parsedBody['pointer'] ?? $queryParams['pointer'] ?? null;
344 $this->imagemode = $parsedBody['imagemode'] ?? $queryParams['imagemode'] ?? null;
345 $this->clear_cache = $parsedBody['clear_cache'] ?? $queryParams['clear_cache'] ?? null;
346 $this->popView = $parsedBody['popView'] ?? $queryParams['popView'] ?? null;
347 $this->search_field = $parsedBody['search_field'] ?? $queryParams['search_field'] ?? null;
348 $this->search_levels = $parsedBody['search_levels'] ?? $queryParams['search_levels'] ?? null;
349 $this->showLimit = $parsedBody['showLimit'] ?? $queryParams['showLimit'] ?? null;
350 $returnUrl = $parsedBody['returnUrl'] ?? $queryParams['returnUrl'] ?? null;
351 $this->returnUrl = GeneralUtility::sanitizeLocalUrl($returnUrl);
352
353 $sessionData['search_field'] = $this->search_field;
354 // Store session data
355 $this->getBackendUser()->setAndSaveSessionData(__CLASS__, $sessionData);
356 // Load page info array:
357 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
358 // Initialize menu
359 $this->menuConfig($request);
360 // Setting sys language from session var:
361 $this->current_sys_language = (int)$this->MOD_SETTINGS['language'];
362 // CSH / Descriptions:
363 $this->descrTable = '_MOD_' . $this->moduleName;
364 }
365
366 /**
367 * Initialize menu array
368 * @param ServerRequestInterface $request
369 */
370 protected function menuConfig(ServerRequestInterface $request = null): void
371 {
372 $request = $request ?: $GLOBALS['TYPO3_REQUEST'];
373 // Set the GPvars from outside
374 $parsedBody = $request->getParsedBody();
375 $queryParams = $request->getQueryParams();
376
377 /** @var SiteInterface $currentSite */
378 $currentSite = $request->getAttribute('site');
379 $availableLanguages = $currentSite->getAvailableLanguages($this->getBackendUser(), false, $this->id);
380
381 $lang = $this->getLanguageService();
382 // MENU-ITEMS:
383 $this->MOD_MENU = [
384 'tt_content_showHidden' => '',
385 'function' => [
386 1 => $lang->getLL('m_function_1'),
387 2 => $lang->getLL('m_function_2')
388 ],
389 'language' => [
390 0 => $lang->getLL('m_default')
391 ]
392 ];
393 // initialize page/be_user TSconfig settings
394 $pageTsConfig = BackendUtility::getPagesTSconfig($this->id);
395 $this->modSharedTSconfig['properties'] = $pageTsConfig['mod.']['SHARED.'] ?? [];
396 $this->modTSconfig['properties'] = $pageTsConfig['mod.']['web_layout.'] ?? [];
397
398 // First, select all localized page records on the current page.
399 // Each represents a possibility for a language on the page. Add these to language selector.
400 if ($this->id) {
401 // Compile language data for pid != 0 only. The language drop-down is not shown on pid 0
402 // since pid 0 can't be localized.
403 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
404 $queryBuilder->getRestrictions()->removeAll()
405 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
406 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
407 $statement = $queryBuilder->select('uid', $GLOBALS['TCA']['pages']['ctrl']['languageField'])
408 ->from('pages')
409 ->where(
410 $queryBuilder->expr()->eq(
411 $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
412 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
413 )
414 )->execute();
415 while ($pageTranslation = $statement->fetch()) {
416 $languageId = $pageTranslation[$GLOBALS['TCA']['pages']['ctrl']['languageField']];
417 if (isset($availableLanguages[$languageId])) {
418 $this->MOD_MENU['language'][$languageId] = $availableLanguages[$languageId]->getTitle();
419 }
420 }
421 // Override the label
422 if (isset($availableLanguages[0])) {
423 $this->MOD_MENU['language'][0] = $availableLanguages[0]->getTitle();
424 }
425 }
426 // Initialize the available actions
427 $actions = $this->initActions();
428 // Clean up settings
429 $this->MOD_SETTINGS = BackendUtility::getModuleData($this->MOD_MENU, $parsedBody['SET'] ?? $queryParams['SET'] ?? [], $this->moduleName);
430 // For all elements to be shown in draft workspaces & to also show hidden elements by default if user hasn't disabled the option
431 if ($this->getBackendUser()->workspace != 0
432 || !isset($this->MOD_SETTINGS['tt_content_showHidden'])
433 || $this->MOD_SETTINGS['tt_content_showHidden'] !== '0'
434 ) {
435 $this->MOD_SETTINGS['tt_content_showHidden'] = 1;
436 }
437 // Make action menu from available actions
438 $this->makeActionMenu($actions);
439 }
440
441 /**
442 * Initializes the available actions this module provides
443 *
444 * @return array the available actions
445 */
446 protected function initActions(): array
447 {
448 $actions = [
449 1 => $this->getLanguageService()->getLL('m_function_1'),
450 2 => $this->getLanguageService()->getLL('m_function_2')
451 ];
452 // Find if there are ANY languages at all (and if not, remove the language option from function menu).
453 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_language');
454 if ($this->getBackendUser()->isAdmin()) {
455 $queryBuilder->getRestrictions()->removeAll();
456 }
457
458 $count = $queryBuilder
459 ->count('uid')
460 ->from('sys_language')
461 ->execute()
462 ->fetchColumn(0);
463
464 if (!$count) {
465 unset($actions['2']);
466 }
467 // Page / user TSconfig blinding of menu-items
468 $blindActions = $this->modTSconfig['properties']['menu.']['functions.'] ?? [];
469 foreach ($blindActions as $key => $value) {
470 if (!$value && array_key_exists($key, $actions)) {
471 unset($actions[$key]);
472 }
473 }
474
475 return $actions;
476 }
477
478 /**
479 * This creates the dropdown menu with the different actions this module is able to provide.
480 * For now they are Columns, Quick Edit and Languages.
481 *
482 * @param array $actions array with the available actions
483 */
484 protected function makeActionMenu(array $actions): void
485 {
486 $actionMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
487 $actionMenu->setIdentifier('actionMenu');
488 $actionMenu->setLabel('');
489
490 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
491
492 $defaultKey = null;
493 $foundDefaultKey = false;
494 foreach ($actions as $key => $action) {
495 $menuItem = $actionMenu
496 ->makeMenuItem()
497 ->setTitle($action)
498 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[function]=' . $key);
499
500 if (!$foundDefaultKey) {
501 $defaultKey = $key;
502 $foundDefaultKey = true;
503 }
504 if ((int)$this->MOD_SETTINGS['function'] === $key) {
505 $menuItem->setActive(true);
506 $defaultKey = null;
507 }
508 $actionMenu->addMenuItem($menuItem);
509 }
510 if (isset($defaultKey)) {
511 $this->MOD_SETTINGS['function'] = $defaultKey;
512 }
513 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($actionMenu);
514 }
515
516 /**
517 * Clears page cache for the current id, $this->id
518 */
519 protected function clearCache(): void
520 {
521 if ($this->clear_cache && !empty($this->pageinfo)) {
522 $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
523 $dataHandler->start([], []);
524 $dataHandler->clear_cacheCmd($this->id);
525 }
526 }
527
528 /**
529 * Generate the flashmessages for current pid
530 *
531 * @return string HTML content with flashmessages
532 */
533 protected function getHeaderFlashMessagesForCurrentPid(): string
534 {
535 $content = '';
536 $lang = $this->getLanguageService();
537
538 $view = GeneralUtility::makeInstance(StandaloneView::class);
539 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
540
541 // If page is a folder
542 if ($this->pageinfo['doktype'] == PageRepository::DOKTYPE_SYSFOLDER) {
543 $moduleLoader = GeneralUtility::makeInstance(ModuleLoader::class);
544 $moduleLoader->load($GLOBALS['TBE_MODULES']);
545 $modules = $moduleLoader->modules;
546 if (is_array($modules['web']['sub']['list'])) {
547 $title = $lang->getLL('goToListModule');
548 $message = '<p>' . $lang->getLL('goToListModuleMessage') . '</p>';
549 $message .= '<a class="btn btn-info" href="javascript:top.goToModule(\'web_list\',1);">' . $lang->getLL('goToListModule') . '</a>';
550 $view->assignMultiple([
551 'title' => $title,
552 'message' => $message,
553 'state' => InfoboxViewHelper::STATE_INFO
554 ]);
555 $content .= $view->render();
556 }
557 } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_SHORTCUT) {
558 $shortcutMode = (int)$this->pageinfo['shortcut_mode'];
559 $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
560 $targetPage = [];
561
562 if ($this->pageinfo['shortcut'] || $shortcutMode) {
563 switch ($shortcutMode) {
564 case PageRepository::SHORTCUT_MODE_NONE:
565 $targetPage = $pageRepository->getPage($this->pageinfo['shortcut']);
566 break;
567 case PageRepository::SHORTCUT_MODE_FIRST_SUBPAGE:
568 $targetPage = reset($pageRepository->getMenu($this->pageinfo['shortcut'] ?: $this->pageinfo['uid']));
569 break;
570 case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
571 $targetPage = $pageRepository->getPage($this->pageinfo['pid']);
572 break;
573 }
574
575 $message = '';
576 if ($shortcutMode === PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
577 $message .= sprintf($lang->getLL('pageIsRandomInternalLinkMessage'));
578 } else {
579 $linkToPid = $this->local_linkThisScript(['id' => $targetPage['uid']]);
580 $path = BackendUtility::getRecordPath($targetPage['uid'], $this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW), 1000);
581 $linkedPath = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($path) . '</a>';
582 $message .= sprintf($lang->getLL('pageIsInternalLinkMessage'), $linkedPath);
583 }
584
585 $message .= ' (' . htmlspecialchars($lang->sL(BackendUtility::getLabelFromItemlist('pages', 'shortcut_mode', $shortcutMode))) . ')';
586
587 $view->assignMultiple([
588 'title' => $this->pageinfo['title'],
589 'message' => $message,
590 'state' => InfoboxViewHelper::STATE_INFO
591 ]);
592 $content .= $view->render();
593 } else {
594 if (empty($targetPage) && $shortcutMode !== PageRepository::SHORTCUT_MODE_RANDOM_SUBPAGE) {
595 $view->assignMultiple([
596 'title' => $this->pageinfo['title'],
597 'message' => $lang->getLL('pageIsMisconfiguredInternalLinkMessage'),
598 'state' => InfoboxViewHelper::STATE_ERROR
599 ]);
600 $content .= $view->render();
601 }
602 }
603 } elseif ($this->pageinfo['doktype'] === PageRepository::DOKTYPE_LINK) {
604 if (empty($this->pageinfo['url'])) {
605 $view->assignMultiple([
606 'title' => $this->pageinfo['title'],
607 'message' => $lang->getLL('pageIsMisconfiguredExternalLinkMessage'),
608 'state' => InfoboxViewHelper::STATE_ERROR
609 ]);
610 $content .= $view->render();
611 } else {
612 $externalUrl = htmlspecialchars(GeneralUtility::makeInstance(PageRepository::class)->getExtURL($this->pageinfo));
613 if ($externalUrl !== false) {
614 $externalUrlHtml = '<a href="' . $externalUrl . '" target="_blank" rel="noopener">' . $externalUrl . '</a>';
615 $view->assignMultiple([
616 'title' => $this->pageinfo['title'],
617 'message' => sprintf($lang->getLL('pageIsExternalLinkMessage'), $externalUrlHtml),
618 'state' => InfoboxViewHelper::STATE_INFO
619 ]);
620 $content .= $view->render();
621 }
622 }
623 }
624 // If content from different pid is displayed
625 if ($this->pageinfo['content_from_pid']) {
626 $contentPage = BackendUtility::getRecord('pages', (int)$this->pageinfo['content_from_pid']);
627 $linkToPid = $this->local_linkThisScript(['id' => $this->pageinfo['content_from_pid']]);
628 $title = BackendUtility::getRecordTitle('pages', $contentPage);
629 $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$this->pageinfo['content_from_pid'] . ')</a>';
630 $message = sprintf($lang->getLL('content_from_pid_title'), $link);
631 $view->assignMultiple([
632 'title' => $title,
633 'message' => $message,
634 'state' => InfoboxViewHelper::STATE_INFO
635 ]);
636 $content .= $view->render();
637 } else {
638 $links = $this->getPageLinksWhereContentIsAlsoShownOn($this->pageinfo['uid']);
639 if (!empty($links)) {
640 $message = sprintf($lang->getLL('content_on_pid_title'), $links);
641 $view->assignMultiple([
642 'title' => '',
643 'message' => $message,
644 'state' => InfoboxViewHelper::STATE_INFO
645 ]);
646 $content .= $view->render();
647 }
648 }
649 return $content;
650 }
651
652 /**
653 * Get all pages with links where the content of a page $pageId is also shown on
654 *
655 * @param int $pageId
656 * @return string
657 */
658 protected function getPageLinksWhereContentIsAlsoShownOn($pageId): string
659 {
660 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
661 $queryBuilder->getRestrictions()->removeAll();
662 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
663 $queryBuilder
664 ->select('*')
665 ->from('pages')
666 ->where($queryBuilder->expr()->eq('content_from_pid', $queryBuilder->createNamedParameter($pageId, \PDO::PARAM_INT)));
667
668 $links = [];
669 $rows = $queryBuilder->execute()->fetchAll();
670 if (!empty($rows)) {
671 foreach ($rows as $row) {
672 $linkToPid = $this->local_linkThisScript(['id' => $row['uid']]);
673 $title = BackendUtility::getRecordTitle('pages', $row);
674 $link = '<a href="' . htmlspecialchars($linkToPid) . '">' . htmlspecialchars($title) . ' (PID ' . (int)$row['uid'] . ')</a>';
675 $links[] = $link;
676 }
677 }
678 return implode(', ', $links);
679 }
680
681 /**
682 * @return string $title
683 */
684 protected function getLocalizedPageTitle(): string
685 {
686 if ($this->current_sys_language > 0) {
687 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
688 ->getQueryBuilderForTable('pages');
689 $queryBuilder->getRestrictions()
690 ->removeAll()
691 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
692 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
693 $localizedPage = $queryBuilder
694 ->select('*')
695 ->from('pages')
696 ->where(
697 $queryBuilder->expr()->eq(
698 $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'],
699 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
700 ),
701 $queryBuilder->expr()->eq(
702 $GLOBALS['TCA']['pages']['ctrl']['languageField'],
703 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
704 )
705 )
706 ->setMaxResults(1)
707 ->execute()
708 ->fetch();
709 BackendUtility::workspaceOL('pages', $localizedPage);
710 return $localizedPage['title'];
711 }
712 return $this->pageinfo['title'];
713 }
714
715 /**
716 * Main function.
717 * Creates some general objects and calls other functions for the main rendering of module content.
718 *
719 * @param ServerRequestInterface $request
720 */
721 protected function main(ServerRequestInterface $request = null): void
722 {
723 $request = $request ?: $GLOBALS['TYPO3_REQUEST'];
724 $lang = $this->getLanguageService();
725 // Access check...
726 // The page will show only if there is a valid page and if this page may be viewed by the user
727 $access = is_array($this->pageinfo);
728 // Content
729 $content = '';
730 if ($this->id && $access) {
731 // Initialize permission settings:
732 $this->CALC_PERMS = $this->getBackendUser()->calcPerms($this->pageinfo);
733 $this->EDIT_CONTENT = $this->isContentEditable();
734
735 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
736
737 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
738
739 $this->moduleTemplate->addJavaScriptCode('mainJsFunctions', '
740 if (top.fsMod) {
741 top.fsMod.recentIds["web"] = ' . (int)$this->id . ';
742 top.fsMod.navFrameHighlightedID["web"] = top.fsMod.currentBank + "_" + ' . (int)$this->id . ';
743 }
744 ' . ($this->popView ? BackendUtility::viewOnClick($this->id, '', BackendUtility::BEgetRootLine($this->id)) : '') . '
745 function deleteRecord(table,id,url) { //
746 window.location.href = ' . GeneralUtility::quoteJSvalue((string)$uriBuilder->buildUriFromRoute('tce_db') . '&cmd[')
747 . ' + table + "][" + id + "][delete]=1&redirect=" + encodeURIComponent(url);
748 return false;
749 }
750 ');
751
752 // Find backend layout / columns
753 $backendLayout = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getSelectedBackendLayout', $this->id, $this);
754 if (!empty($backendLayout['__colPosList'])) {
755 $this->colPosList = implode(',', $backendLayout['__colPosList']);
756 }
757 // Removing duplicates, if any
758 $this->colPosList = array_unique(GeneralUtility::intExplode(',', $this->colPosList));
759 // Accessible columns
760 if (isset($this->modSharedTSconfig['properties']['colPos_list']) && trim($this->modSharedTSconfig['properties']['colPos_list']) !== '') {
761 $this->activeColPosList = array_unique(GeneralUtility::intExplode(',', trim($this->modSharedTSconfig['properties']['colPos_list'])));
762 // Match with the list which is present in the colPosList for the current page
763 if (!empty($this->colPosList) && !empty($this->activeColPosList)) {
764 $this->activeColPosList = array_unique(array_intersect(
765 $this->activeColPosList,
766 $this->colPosList
767 ));
768 }
769 } else {
770 $this->activeColPosList = $this->colPosList;
771 }
772 $this->activeColPosList = implode(',', $this->activeColPosList);
773 $this->colPosList = implode(',', $this->colPosList);
774
775 $content .= $this->getHeaderFlashMessagesForCurrentPid();
776
777 // Render the primary module content:
778 if ($this->MOD_SETTINGS['function'] == 1 || $this->MOD_SETTINGS['function'] == 2) {
779 $content .= '<form action="' . htmlspecialchars((string)$uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->id, 'imagemode' => $this->imagemode])) . '" id="PageLayoutController" method="post">';
780 // Page title
781 $content .= '<h1 class="t3js-title-inlineedit">' . htmlspecialchars($this->getLocalizedPageTitle()) . '</h1>';
782 // All other listings
783 $content .= $this->renderContent();
784 }
785 $content .= '</form>';
786 $content .= $this->searchContent;
787 // Setting up the buttons for the docheader
788 $this->makeButtons($request);
789
790 // Create LanguageMenu
791 $this->makeLanguageMenu();
792 } else {
793 $this->moduleTemplate->addJavaScriptCode(
794 'mainJsFunctions',
795 'if (top.fsMod) top.fsMod.recentIds["web"] = ' . (int)$this->id . ';'
796 );
797 $content .= '<h1>' . htmlspecialchars($GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']) . '</h1>';
798 $view = GeneralUtility::makeInstance(StandaloneView::class);
799 $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:backend/Resources/Private/Templates/InfoBox.html'));
800 $view->assignMultiple([
801 'title' => $lang->getLL('clickAPage_header'),
802 'message' => $lang->getLL('clickAPage_content'),
803 'state' => InfoboxViewHelper::STATE_INFO
804 ]);
805 $content .= $view->render();
806 }
807 // Set content
808 $this->moduleTemplate->setContent($content);
809 }
810
811 /**
812 * Rendering content
813 *
814 * @return string
815 */
816 protected function renderContent(): string
817 {
818 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
819
820 $this->moduleTemplate->getPageRenderer()->loadJquery();
821 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
822 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
823 $dbList->thumbs = $this->imagemode;
824 $dbList->no_noWrap = 1;
825 $dbList->descrTable = $this->descrTable;
826 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
827 $dbList->script = (string)$uriBuilder->buildUriFromRoute($this->moduleName);
828 $dbList->showIcon = 0;
829 $dbList->setLMargin = 0;
830 $dbList->doEdit = $this->EDIT_CONTENT;
831 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
832 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears');
833 $dbList->id = $this->id;
834 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
835 $dbList->option_newWizard = empty($this->modTSconfig['properties']['disableNewContentElementWizard']);
836 $dbList->defLangBinding = !empty($this->modTSconfig['properties']['defLangBinding']);
837 if (!$dbList->nextThree) {
838 $dbList->nextThree = 1;
839 }
840 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
841 // also fills $dbList->activeTables
842 $dbList->getTableMenu($this->id);
843 // Initialize other variables:
844 $tableOutput = [];
845 $tableJSOutput = [];
846 $CMcounter = 0;
847 // Traverse the list of table names which has records on this page (that array is populated
848 // by the $dblist object during the function getTableMenu()):
849 foreach ($dbList->activeTables as $table => $value) {
850 $h_func = '';
851 $h_func_b = '';
852 if (!isset($dbList->externalTables[$table])) {
853 // Boolean: Display up/down arrows and edit icons for tt_content records
854 $dbList->tt_contentConfig['showCommands'] = 1;
855 // Boolean: Display info-marks or not
856 $dbList->tt_contentConfig['showInfo'] = 1;
857 // Setting up the tt_content columns to show:
858 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
859 $colList = [];
860 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
861 foreach ($tcaItems as $temp) {
862 $colList[] = $temp[1];
863 }
864 } else {
865 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
866 $colList = ['1', '0', '2', '3'];
867 }
868 if ($this->colPosList !== '') {
869 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
870 }
871 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
872 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
873 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
874 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
875 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
876 // If the function menu is set to "Language":
877 if ($this->MOD_SETTINGS['function'] == 2) {
878 $dbList->tt_contentConfig['languageMode'] = 1;
879 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
880 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
881 }
882 // Toggle hidden ContentElements
883 $numberOfHiddenElements = $this->getNumberOfHiddenElements($dbList->tt_contentConfig);
884 if ($numberOfHiddenElements > 0) {
885 $h_func_b = '
886 <div class="checkbox">
887 <label for="checkTt_content_showHidden">
888 <input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
889 ' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
890 </label>
891 </div>';
892 }
893 } else {
894 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
895 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
896 }
897 }
898 // Start the dblist object:
899 $dbList->itemsLimitSingleTable = 1000;
900 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
901 $dbList->counter = $CMcounter;
902 $dbList->ext_function = $this->MOD_SETTINGS['function'];
903 // Generate the list of elements here:
904 $dbList->generateList();
905 // Adding the list content to the tableOutput variable:
906 $tableOutput[$table] = $h_func . $dbList->HTMLcode . $h_func_b;
907 // ... and any accumulated JavaScript goes the same way!
908 $tableJSOutput[$table] = $dbList->JScode;
909 // Increase global counter:
910 $CMcounter += $dbList->counter;
911 // Reset variables after operation:
912 $dbList->HTMLcode = '';
913 $dbList->JScode = '';
914 }
915 // END: traverse tables
916 // For Context Sensitive Menus:
917 // Init the content
918 $content = '';
919 // Additional header content
920 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] ?? [] as $hook) {
921 $params = [];
922 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
923 }
924 // Add the content for each table we have rendered (traversing $tableOutput variable)
925 foreach ($tableOutput as $table => $output) {
926 $content .= $output;
927 }
928 // Making search form:
929 if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dbList->counter > 0 || $this->currentPageHasSubPages())) {
930 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
931 $toggleSearchFormButton = $this->buttonBar->makeLinkButton()
932 ->setClasses('t3js-toggle-search-toolbox')
933 ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.title.searchIcon'))
934 ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL))
935 ->setHref('#');
936 $this->buttonBar->addButton($toggleSearchFormButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
937 $this->searchContent = $dbList->getSearchBox();
938 }
939 // Additional footer content
940 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'] ?? [] as $hook) {
941 $params = [];
942 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
943 }
944 return $content;
945 }
946
947 /**
948 * @return ModuleTemplate
949 */
950 protected function getModuleTemplate(): ModuleTemplate
951 {
952 return $this->moduleTemplate;
953 }
954
955 /***************************
956 *
957 * Sub-content functions, rendering specific parts of the module content.
958 *
959 ***************************/
960 /**
961 * This creates the buttons for the modules
962 * @param ServerRequestInterface $request
963 */
964 protected function makeButtons(ServerRequestInterface $request): void
965 {
966 if ($this->MOD_SETTINGS['function'] == 1 || $this->MOD_SETTINGS['function'] == 2) {
967 // Add CSH (Context Sensitive Help) icon to tool bar
968 $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
969 ->setModuleName($this->descrTable)
970 ->setFieldName('columns_' . $this->MOD_SETTINGS['function']);
971 $this->buttonBar->addButton($contextSensitiveHelpButton);
972 }
973 $lang = $this->getLanguageService();
974 // View page
975 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
976 $viewButton = $this->buttonBar->makeLinkButton()
977 ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
978 ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
979 ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
980 ->setHref('#');
981
982 $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
983 }
984 // Shortcut
985 $shortcutButton = $this->buttonBar->makeShortcutButton()
986 ->setModuleName($this->moduleName)
987 ->setGetVariables([
988 'id',
989 'route',
990 'edit_record',
991 'pointer',
992 'new_unique_uid',
993 'search_field',
994 'search_levels',
995 'showLimit'
996 ])
997 ->setSetVariables(array_keys($this->MOD_MENU));
998 $this->buttonBar->addButton($shortcutButton);
999
1000 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
1001 // Cache
1002 if (empty($this->modTSconfig['properties']['disableAdvanced'])) {
1003 $clearCacheButton = $this->buttonBar->makeLinkButton()
1004 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->pageinfo['uid'], 'clear_cache' => '1']))
1005 ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
1006 ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
1007 $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
1008 }
1009 if (empty($this->modTSconfig['properties']['disableIconToolbar'])) {
1010 // Edit page properties and page language overlay icons
1011 if ($this->isPageEditable() && $this->getBackendUser()->checkLanguageAccess(0)) {
1012 /** @var \TYPO3\CMS\Core\Http\NormalizedParams */
1013 $normalizedParams = $request->getAttribute('normalizedParams');
1014 // Edit localized pages only when one specific language is selected
1015 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1016 $localizationParentField = $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'];
1017 $languageField = $GLOBALS['TCA']['pages']['ctrl']['languageField'];
1018 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1019 ->getQueryBuilderForTable('pages');
1020 $queryBuilder->getRestrictions()
1021 ->removeAll()
1022 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1023 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1024 $overlayRecord = $queryBuilder
1025 ->select('uid')
1026 ->from('pages')
1027 ->where(
1028 $queryBuilder->expr()->eq(
1029 $localizationParentField,
1030 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
1031 ),
1032 $queryBuilder->expr()->eq(
1033 $languageField,
1034 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1035 )
1036 )
1037 ->setMaxResults(1)
1038 ->execute()
1039 ->fetch();
1040 // Edit button
1041 $urlParameters = [
1042 'edit' => [
1043 'pages' => [
1044 $overlayRecord['uid'] => 'edit'
1045 ]
1046 ],
1047 'returnUrl' => $normalizedParams->getRequestUri(),
1048 ];
1049
1050 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
1051 $editLanguageButton = $this->buttonBar->makeLinkButton()
1052 ->setHref($url)
1053 ->setTitle($lang->getLL('editPageLanguageOverlayProperties'))
1054 ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
1055 $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1056 }
1057 $urlParameters = [
1058 'edit' => [
1059 'pages' => [
1060 $this->id => 'edit'
1061 ]
1062 ],
1063 'returnUrl' => $normalizedParams->getRequestUri(),
1064 ];
1065 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
1066 $editPageButton = $this->buttonBar->makeLinkButton()
1067 ->setHref($url)
1068 ->setTitle($lang->getLL('editPageProperties'))
1069 ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
1070 $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1071 }
1072 }
1073 }
1074
1075 /*******************************
1076 *
1077 * Other functions
1078 *
1079 ******************************/
1080 /**
1081 * Returns the number of hidden elements (including those hidden by start/end times)
1082 * on the current page (for the current sys_language)
1083 *
1084 * @param array $contentConfig
1085 * @return int
1086 */
1087 protected function getNumberOfHiddenElements(array $contentConfig = []): int
1088 {
1089 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
1090 $queryBuilder->getRestrictions()
1091 ->removeAll()
1092 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1093 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1094
1095 $queryBuilder
1096 ->count('uid')
1097 ->from('tt_content')
1098 ->where(
1099 $queryBuilder->expr()->eq(
1100 'pid',
1101 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
1102 )
1103 );
1104
1105 if (!empty($contentConfig['languageCols']) && is_array($contentConfig['languageCols'])) {
1106 // Multi-language view is active
1107 if ($this->current_sys_language > 0) {
1108 $queryBuilder->andWhere(
1109 $queryBuilder->expr()->in(
1110 'sys_language_uid',
1111 [0, $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)]
1112 )
1113 );
1114 }
1115 } else {
1116 $queryBuilder->andWhere(
1117 $queryBuilder->expr()->eq(
1118 'sys_language_uid',
1119 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1120 )
1121 );
1122 }
1123
1124 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) {
1125 $andWhere[] = $queryBuilder->expr()->neq(
1126 'hidden',
1127 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1128 );
1129 }
1130
1131 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) {
1132 $andWhere[] = $queryBuilder->expr()->andX(
1133 $queryBuilder->expr()->neq(
1134 'starttime',
1135 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1136 ),
1137 $queryBuilder->expr()->gt(
1138 'starttime',
1139 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1140 )
1141 );
1142 }
1143
1144 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) {
1145 $andWhere[] = $queryBuilder->expr()->andX(
1146 $queryBuilder->expr()->neq(
1147 'endtime',
1148 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1149 ),
1150 $queryBuilder->expr()->lte(
1151 'endtime',
1152 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1153 )
1154 );
1155 }
1156
1157 if (!empty($andWhere)) {
1158 $queryBuilder->andWhere(
1159 $queryBuilder->expr()->orX(...$andWhere)
1160 );
1161 }
1162
1163 $count = $queryBuilder
1164 ->execute()
1165 ->fetchColumn(0);
1166
1167 return (int)$count;
1168 }
1169
1170 /**
1171 * Returns URL to the current script.
1172 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1173 *
1174 * @param array $params Parameters array, merged with global GET vars.
1175 * @return string URL
1176 */
1177 protected function local_linkThisScript($params): string
1178 {
1179 $params['popView'] = '';
1180 $params['new_unique_uid'] = '';
1181 return GeneralUtility::linkThisScript($params);
1182 }
1183
1184 /**
1185 * Check if page can be edited by current user
1186 *
1187 * @return bool
1188 */
1189 protected function isPageEditable(): bool
1190 {
1191 if ($this->getBackendUser()->isAdmin()) {
1192 return true;
1193 }
1194 return !$this->pageinfo['editlock'] && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::PAGE_EDIT);
1195 }
1196
1197 /**
1198 * Check if page can be edited by current user
1199 *
1200 * @return bool
1201 */
1202 protected function pageIsNotLockedForEditors(): bool
1203 {
1204 return $this->isPageEditable();
1205 }
1206
1207 /**
1208 * Check if content can be edited by current user
1209 *
1210 * @return bool
1211 */
1212 protected function isContentEditable(): bool
1213 {
1214 if ($this->getBackendUser()->isAdmin()) {
1215 return true;
1216 }
1217 return !$this->pageinfo['editlock'] && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT);
1218 }
1219
1220 /**
1221 * Check if content can be edited by current user
1222 *
1223 * @return bool
1224 */
1225 protected function contentIsNotLockedForEditors(): bool
1226 {
1227 return $this->isContentEditable();
1228 }
1229
1230 /**
1231 * Returns LanguageService
1232 *
1233 * @return \TYPO3\CMS\Core\Localization\LanguageService
1234 */
1235 protected function getLanguageService(): LanguageService
1236 {
1237 return $GLOBALS['LANG'];
1238 }
1239
1240 /**
1241 * Returns the current BE user.
1242 *
1243 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1244 */
1245 protected function getBackendUser(): BackendUserAuthentication
1246 {
1247 return $GLOBALS['BE_USER'];
1248 }
1249
1250 /**
1251 * Returns current PageRenderer
1252 *
1253 * @return PageRenderer
1254 */
1255 protected function getPageRenderer(): PageRenderer
1256 {
1257 return GeneralUtility::makeInstance(PageRenderer::class);
1258 }
1259
1260 /**
1261 * Make the LanguageMenu
1262 */
1263 protected function makeLanguageMenu(): void
1264 {
1265 if (count($this->MOD_MENU['language']) > 1) {
1266 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
1267 $languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
1268 $languageMenu->setIdentifier('languageMenu');
1269 foreach ($this->MOD_MENU['language'] as $key => $language) {
1270 $menuItem = $languageMenu
1271 ->makeMenuItem()
1272 ->setTitle($language)
1273 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key);
1274 if ((int)$this->current_sys_language === $key) {
1275 $menuItem->setActive(true);
1276 }
1277 $languageMenu->addMenuItem($menuItem);
1278 }
1279 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($languageMenu);
1280 }
1281 }
1282
1283 /**
1284 * Checks whether the current page has sub pages
1285 *
1286 * @return bool
1287 */
1288 protected function currentPageHasSubPages(): bool
1289 {
1290 /** @var QueryBuilder $queryBuilder */
1291 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1292 $queryBuilder->getRestrictions()
1293 ->removeAll()
1294 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1295 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1296
1297 // get workspace id
1298 $workspaceId = (int)$this->getBackendUser()->workspace;
1299 $comparisonExpression = $workspaceId === 0 ? 'neq' : 'eq';
1300
1301 $count = $queryBuilder
1302 ->count('uid')
1303 ->from('pages')
1304 ->where(
1305 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
1306 $queryBuilder->expr()->eq(
1307 't3ver_wsid',
1308 $queryBuilder->createNamedParameter($workspaceId, \PDO::PARAM_INT)
1309 ),
1310 $queryBuilder->expr()->{$comparisonExpression}(
1311 'pid',
1312 $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
1313 )
1314 )
1315 ->execute()
1316 ->fetchColumn(0);
1317
1318 return (bool)$count;
1319 }
1320 }