[TASK] Deprecate PageRenderer->loadJQuery()
[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()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
821 $dbList = GeneralUtility::makeInstance(PageLayoutView::class);
822 $dbList->thumbs = $this->imagemode;
823 $dbList->no_noWrap = 1;
824 $dbList->descrTable = $this->descrTable;
825 $this->pointer = MathUtility::forceIntegerInRange($this->pointer, 0, 100000);
826 $dbList->script = (string)$uriBuilder->buildUriFromRoute($this->moduleName);
827 $dbList->showIcon = 0;
828 $dbList->setLMargin = 0;
829 $dbList->doEdit = $this->EDIT_CONTENT;
830 $dbList->ext_CALC_PERMS = $this->CALC_PERMS;
831 $dbList->agePrefixes = $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears');
832 $dbList->id = $this->id;
833 $dbList->nextThree = MathUtility::forceIntegerInRange($this->modTSconfig['properties']['editFieldsAtATime'], 0, 10);
834 $dbList->option_newWizard = empty($this->modTSconfig['properties']['disableNewContentElementWizard']);
835 $dbList->defLangBinding = !empty($this->modTSconfig['properties']['defLangBinding']);
836 if (!$dbList->nextThree) {
837 $dbList->nextThree = 1;
838 }
839 // Create menu for selecting a table to jump to (this is, if more than just pages/tt_content elements are found on the page!)
840 // also fills $dbList->activeTables
841 $dbList->getTableMenu($this->id);
842 // Initialize other variables:
843 $tableOutput = [];
844 $tableJSOutput = [];
845 $CMcounter = 0;
846 // Traverse the list of table names which has records on this page (that array is populated
847 // by the $dblist object during the function getTableMenu()):
848 foreach ($dbList->activeTables as $table => $value) {
849 $h_func = '';
850 $h_func_b = '';
851 if (!isset($dbList->externalTables[$table])) {
852 // Boolean: Display up/down arrows and edit icons for tt_content records
853 $dbList->tt_contentConfig['showCommands'] = 1;
854 // Boolean: Display info-marks or not
855 $dbList->tt_contentConfig['showInfo'] = 1;
856 // Setting up the tt_content columns to show:
857 if (is_array($GLOBALS['TCA']['tt_content']['columns']['colPos']['config']['items'])) {
858 $colList = [];
859 $tcaItems = GeneralUtility::callUserFunction(BackendLayoutView::class . '->getColPosListItemsParsed', $this->id, $this);
860 foreach ($tcaItems as $temp) {
861 $colList[] = $temp[1];
862 }
863 } else {
864 // ... should be impossible that colPos has no array. But this is the fallback should it make any sense:
865 $colList = ['1', '0', '2', '3'];
866 }
867 if ($this->colPosList !== '') {
868 $colList = array_intersect(GeneralUtility::intExplode(',', $this->colPosList), $colList);
869 }
870 // The order of the rows: Default is left(1), Normal(0), right(2), margin(3)
871 $dbList->tt_contentConfig['cols'] = implode(',', $colList);
872 $dbList->tt_contentConfig['activeCols'] = $this->activeColPosList;
873 $dbList->tt_contentConfig['showHidden'] = $this->MOD_SETTINGS['tt_content_showHidden'];
874 $dbList->tt_contentConfig['sys_language_uid'] = (int)$this->current_sys_language;
875 // If the function menu is set to "Language":
876 if ($this->MOD_SETTINGS['function'] == 2) {
877 $dbList->tt_contentConfig['languageMode'] = 1;
878 $dbList->tt_contentConfig['languageCols'] = $this->MOD_MENU['language'];
879 $dbList->tt_contentConfig['languageColsPointer'] = $this->current_sys_language;
880 }
881 // Toggle hidden ContentElements
882 $numberOfHiddenElements = $this->getNumberOfHiddenElements($dbList->tt_contentConfig);
883 if ($numberOfHiddenElements > 0) {
884 $h_func_b = '
885 <div class="checkbox">
886 <label for="checkTt_content_showHidden">
887 <input type="checkbox" id="checkTt_content_showHidden" class="checkbox" name="SET[tt_content_showHidden]" value="1" ' . ($this->MOD_SETTINGS['tt_content_showHidden'] ? 'checked="checked"' : '') . ' />
888 ' . htmlspecialchars($this->getLanguageService()->getLL('hiddenCE')) . ' (<span class="t3js-hidden-counter">' . $numberOfHiddenElements . '</span>)
889 </label>
890 </div>';
891 }
892 } else {
893 if (isset($this->MOD_SETTINGS) && isset($this->MOD_MENU)) {
894 $h_func = BackendUtility::getFuncMenu($this->id, 'SET[' . $table . ']', $this->MOD_SETTINGS[$table], $this->MOD_MENU[$table], '', '');
895 }
896 }
897 // Start the dblist object:
898 $dbList->itemsLimitSingleTable = 1000;
899 $dbList->start($this->id, $table, $this->pointer, $this->search_field, $this->search_levels, $this->showLimit);
900 $dbList->counter = $CMcounter;
901 $dbList->ext_function = $this->MOD_SETTINGS['function'];
902 // Generate the list of elements here:
903 $dbList->generateList();
904 // Adding the list content to the tableOutput variable:
905 $tableOutput[$table] = $h_func . $dbList->HTMLcode . $h_func_b;
906 // ... and any accumulated JavaScript goes the same way!
907 $tableJSOutput[$table] = $dbList->JScode;
908 // Increase global counter:
909 $CMcounter += $dbList->counter;
910 // Reset variables after operation:
911 $dbList->HTMLcode = '';
912 $dbList->JScode = '';
913 }
914 // END: traverse tables
915 // For Context Sensitive Menus:
916 // Init the content
917 $content = '';
918 // Additional header content
919 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawHeaderHook'] ?? [] as $hook) {
920 $params = [];
921 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
922 }
923 // Add the content for each table we have rendered (traversing $tableOutput variable)
924 foreach ($tableOutput as $table => $output) {
925 $content .= $output;
926 }
927 // Making search form:
928 if (!$this->modTSconfig['properties']['disableSearchBox'] && ($dbList->counter > 0 || $this->currentPageHasSubPages())) {
929 $this->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ToggleSearchToolbox');
930 $toggleSearchFormButton = $this->buttonBar->makeLinkButton()
931 ->setClasses('t3js-toggle-search-toolbox')
932 ->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.title.searchIcon'))
933 ->setIcon($this->iconFactory->getIcon('actions-search', Icon::SIZE_SMALL))
934 ->setHref('#');
935 $this->buttonBar->addButton($toggleSearchFormButton, ButtonBar::BUTTON_POSITION_LEFT, 4);
936 $this->searchContent = $dbList->getSearchBox();
937 }
938 // Additional footer content
939 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/db_layout.php']['drawFooterHook'] ?? [] as $hook) {
940 $params = [];
941 $content .= GeneralUtility::callUserFunction($hook, $params, $this);
942 }
943 return $content;
944 }
945
946 /**
947 * @return ModuleTemplate
948 */
949 protected function getModuleTemplate(): ModuleTemplate
950 {
951 return $this->moduleTemplate;
952 }
953
954 /***************************
955 *
956 * Sub-content functions, rendering specific parts of the module content.
957 *
958 ***************************/
959 /**
960 * This creates the buttons for the modules
961 * @param ServerRequestInterface $request
962 */
963 protected function makeButtons(ServerRequestInterface $request): void
964 {
965 if ($this->MOD_SETTINGS['function'] == 1 || $this->MOD_SETTINGS['function'] == 2) {
966 // Add CSH (Context Sensitive Help) icon to tool bar
967 $contextSensitiveHelpButton = $this->buttonBar->makeHelpButton()
968 ->setModuleName($this->descrTable)
969 ->setFieldName('columns_' . $this->MOD_SETTINGS['function']);
970 $this->buttonBar->addButton($contextSensitiveHelpButton);
971 }
972 $lang = $this->getLanguageService();
973 // View page
974 if (!VersionState::cast($this->pageinfo['t3ver_state'])->equals(VersionState::DELETE_PLACEHOLDER)) {
975 $viewButton = $this->buttonBar->makeLinkButton()
976 ->setOnClick(BackendUtility::viewOnClick($this->pageinfo['uid'], '', BackendUtility::BEgetRootLine($this->pageinfo['uid'])))
977 ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.showPage'))
978 ->setIcon($this->iconFactory->getIcon('actions-view-page', Icon::SIZE_SMALL))
979 ->setHref('#');
980
981 $this->buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
982 }
983 // Shortcut
984 $shortcutButton = $this->buttonBar->makeShortcutButton()
985 ->setModuleName($this->moduleName)
986 ->setGetVariables([
987 'id',
988 'route',
989 'edit_record',
990 'pointer',
991 'new_unique_uid',
992 'search_field',
993 'search_levels',
994 'showLimit'
995 ])
996 ->setSetVariables(array_keys($this->MOD_MENU));
997 $this->buttonBar->addButton($shortcutButton);
998
999 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
1000 // Cache
1001 if (empty($this->modTSconfig['properties']['disableAdvanced'])) {
1002 $clearCacheButton = $this->buttonBar->makeLinkButton()
1003 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName, ['id' => $this->pageinfo['uid'], 'clear_cache' => '1']))
1004 ->setTitle($lang->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.clear_cache'))
1005 ->setIcon($this->iconFactory->getIcon('actions-system-cache-clear', Icon::SIZE_SMALL));
1006 $this->buttonBar->addButton($clearCacheButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
1007 }
1008 if (empty($this->modTSconfig['properties']['disableIconToolbar'])) {
1009 // Edit page properties and page language overlay icons
1010 if ($this->isPageEditable() && $this->getBackendUser()->checkLanguageAccess(0)) {
1011 /** @var \TYPO3\CMS\Core\Http\NormalizedParams */
1012 $normalizedParams = $request->getAttribute('normalizedParams');
1013 // Edit localized pages only when one specific language is selected
1014 if ($this->MOD_SETTINGS['function'] == 1 && $this->current_sys_language > 0) {
1015 $localizationParentField = $GLOBALS['TCA']['pages']['ctrl']['transOrigPointerField'];
1016 $languageField = $GLOBALS['TCA']['pages']['ctrl']['languageField'];
1017 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
1018 ->getQueryBuilderForTable('pages');
1019 $queryBuilder->getRestrictions()
1020 ->removeAll()
1021 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1022 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1023 $overlayRecord = $queryBuilder
1024 ->select('uid')
1025 ->from('pages')
1026 ->where(
1027 $queryBuilder->expr()->eq(
1028 $localizationParentField,
1029 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
1030 ),
1031 $queryBuilder->expr()->eq(
1032 $languageField,
1033 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1034 )
1035 )
1036 ->setMaxResults(1)
1037 ->execute()
1038 ->fetch();
1039 // Edit button
1040 $urlParameters = [
1041 'edit' => [
1042 'pages' => [
1043 $overlayRecord['uid'] => 'edit'
1044 ]
1045 ],
1046 'returnUrl' => $normalizedParams->getRequestUri(),
1047 ];
1048
1049 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
1050 $editLanguageButton = $this->buttonBar->makeLinkButton()
1051 ->setHref($url)
1052 ->setTitle($lang->getLL('editPageLanguageOverlayProperties'))
1053 ->setIcon($this->iconFactory->getIcon('mimetypes-x-content-page-language-overlay', Icon::SIZE_SMALL));
1054 $this->buttonBar->addButton($editLanguageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1055 }
1056 $urlParameters = [
1057 'edit' => [
1058 'pages' => [
1059 $this->id => 'edit'
1060 ]
1061 ],
1062 'returnUrl' => $normalizedParams->getRequestUri(),
1063 ];
1064 $url = (string)$uriBuilder->buildUriFromRoute('record_edit', $urlParameters);
1065 $editPageButton = $this->buttonBar->makeLinkButton()
1066 ->setHref($url)
1067 ->setTitle($lang->getLL('editPageProperties'))
1068 ->setIcon($this->iconFactory->getIcon('actions-page-open', Icon::SIZE_SMALL));
1069 $this->buttonBar->addButton($editPageButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
1070 }
1071 }
1072 }
1073
1074 /*******************************
1075 *
1076 * Other functions
1077 *
1078 ******************************/
1079 /**
1080 * Returns the number of hidden elements (including those hidden by start/end times)
1081 * on the current page (for the current sys_language)
1082 *
1083 * @param array $contentConfig
1084 * @return int
1085 */
1086 protected function getNumberOfHiddenElements(array $contentConfig = []): int
1087 {
1088 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
1089 $queryBuilder->getRestrictions()
1090 ->removeAll()
1091 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1092 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1093
1094 $queryBuilder
1095 ->count('uid')
1096 ->from('tt_content')
1097 ->where(
1098 $queryBuilder->expr()->eq(
1099 'pid',
1100 $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)
1101 )
1102 );
1103
1104 if (!empty($contentConfig['languageCols']) && is_array($contentConfig['languageCols'])) {
1105 // Multi-language view is active
1106 if ($this->current_sys_language > 0) {
1107 $queryBuilder->andWhere(
1108 $queryBuilder->expr()->in(
1109 'sys_language_uid',
1110 [0, $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)]
1111 )
1112 );
1113 }
1114 } else {
1115 $queryBuilder->andWhere(
1116 $queryBuilder->expr()->eq(
1117 'sys_language_uid',
1118 $queryBuilder->createNamedParameter($this->current_sys_language, \PDO::PARAM_INT)
1119 )
1120 );
1121 }
1122
1123 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['disabled'])) {
1124 $andWhere[] = $queryBuilder->expr()->neq(
1125 'hidden',
1126 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1127 );
1128 }
1129
1130 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['starttime'])) {
1131 $andWhere[] = $queryBuilder->expr()->andX(
1132 $queryBuilder->expr()->neq(
1133 'starttime',
1134 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1135 ),
1136 $queryBuilder->expr()->gt(
1137 'starttime',
1138 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1139 )
1140 );
1141 }
1142
1143 if (!empty($GLOBALS['TCA']['tt_content']['ctrl']['enablecolumns']['endtime'])) {
1144 $andWhere[] = $queryBuilder->expr()->andX(
1145 $queryBuilder->expr()->neq(
1146 'endtime',
1147 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
1148 ),
1149 $queryBuilder->expr()->lte(
1150 'endtime',
1151 $queryBuilder->createNamedParameter($GLOBALS['SIM_ACCESS_TIME'], \PDO::PARAM_INT)
1152 )
1153 );
1154 }
1155
1156 if (!empty($andWhere)) {
1157 $queryBuilder->andWhere(
1158 $queryBuilder->expr()->orX(...$andWhere)
1159 );
1160 }
1161
1162 $count = $queryBuilder
1163 ->execute()
1164 ->fetchColumn(0);
1165
1166 return (int)$count;
1167 }
1168
1169 /**
1170 * Returns URL to the current script.
1171 * In particular the "popView" and "new_unique_uid" Get vars are unset.
1172 *
1173 * @param array $params Parameters array, merged with global GET vars.
1174 * @return string URL
1175 */
1176 protected function local_linkThisScript($params): string
1177 {
1178 $params['popView'] = '';
1179 $params['new_unique_uid'] = '';
1180 return GeneralUtility::linkThisScript($params);
1181 }
1182
1183 /**
1184 * Check if page can be edited by current user
1185 *
1186 * @return bool
1187 */
1188 protected function isPageEditable(): bool
1189 {
1190 if ($this->getBackendUser()->isAdmin()) {
1191 return true;
1192 }
1193 return !$this->pageinfo['editlock'] && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::PAGE_EDIT);
1194 }
1195
1196 /**
1197 * Check if page can be edited by current user
1198 *
1199 * @return bool
1200 */
1201 protected function pageIsNotLockedForEditors(): bool
1202 {
1203 return $this->isPageEditable();
1204 }
1205
1206 /**
1207 * Check if content can be edited by current user
1208 *
1209 * @return bool
1210 */
1211 protected function isContentEditable(): bool
1212 {
1213 if ($this->getBackendUser()->isAdmin()) {
1214 return true;
1215 }
1216 return !$this->pageinfo['editlock'] && $this->getBackendUser()->doesUserHaveAccess($this->pageinfo, Permission::CONTENT_EDIT);
1217 }
1218
1219 /**
1220 * Check if content can be edited by current user
1221 *
1222 * @return bool
1223 */
1224 protected function contentIsNotLockedForEditors(): bool
1225 {
1226 return $this->isContentEditable();
1227 }
1228
1229 /**
1230 * Returns LanguageService
1231 *
1232 * @return \TYPO3\CMS\Core\Localization\LanguageService
1233 */
1234 protected function getLanguageService(): LanguageService
1235 {
1236 return $GLOBALS['LANG'];
1237 }
1238
1239 /**
1240 * Returns the current BE user.
1241 *
1242 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
1243 */
1244 protected function getBackendUser(): BackendUserAuthentication
1245 {
1246 return $GLOBALS['BE_USER'];
1247 }
1248
1249 /**
1250 * Returns current PageRenderer
1251 *
1252 * @return PageRenderer
1253 */
1254 protected function getPageRenderer(): PageRenderer
1255 {
1256 return GeneralUtility::makeInstance(PageRenderer::class);
1257 }
1258
1259 /**
1260 * Make the LanguageMenu
1261 */
1262 protected function makeLanguageMenu(): void
1263 {
1264 if (count($this->MOD_MENU['language']) > 1) {
1265 $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
1266 $languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
1267 $languageMenu->setIdentifier('languageMenu');
1268 foreach ($this->MOD_MENU['language'] as $key => $language) {
1269 $menuItem = $languageMenu
1270 ->makeMenuItem()
1271 ->setTitle($language)
1272 ->setHref((string)$uriBuilder->buildUriFromRoute($this->moduleName) . '&id=' . $this->id . '&SET[language]=' . $key);
1273 if ((int)$this->current_sys_language === $key) {
1274 $menuItem->setActive(true);
1275 }
1276 $languageMenu->addMenuItem($menuItem);
1277 }
1278 $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($languageMenu);
1279 }
1280 }
1281
1282 /**
1283 * Checks whether the current page has sub pages
1284 *
1285 * @return bool
1286 */
1287 protected function currentPageHasSubPages(): bool
1288 {
1289 /** @var QueryBuilder $queryBuilder */
1290 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
1291 $queryBuilder->getRestrictions()
1292 ->removeAll()
1293 ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
1294 ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
1295
1296 // get workspace id
1297 $workspaceId = (int)$this->getBackendUser()->workspace;
1298 $comparisonExpression = $workspaceId === 0 ? 'neq' : 'eq';
1299
1300 $count = $queryBuilder
1301 ->count('uid')
1302 ->from('pages')
1303 ->where(
1304 $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($this->id, \PDO::PARAM_INT)),
1305 $queryBuilder->expr()->eq(
1306 't3ver_wsid',
1307 $queryBuilder->createNamedParameter($workspaceId, \PDO::PARAM_INT)
1308 ),
1309 $queryBuilder->expr()->{$comparisonExpression}(
1310 'pid',
1311 $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
1312 )
1313 )
1314 ->execute()
1315 ->fetchColumn(0);
1316
1317 return (bool)$count;
1318 }
1319 }