|
30 | 30 | use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
|
31 | 31 | use TYPO3\CMS\Core\Database\RelationHandler;
|
32 | 32 | use TYPO3\CMS\Core\Exception\SiteNotFoundException;
|
| 33 | +use TYPO3\CMS\Core\Http\Uri; |
33 | 34 | use TYPO3\CMS\Core\Imaging\Icon;
|
34 | 35 | use TYPO3\CMS\Core\Imaging\IconFactory;
|
35 | 36 | use TYPO3\CMS\Core\Imaging\ImageManipulation\CropVariantCollection;
|
|
39 | 40 | use TYPO3\CMS\Core\Resource\ResourceFactory;
|
40 | 41 | use TYPO3\CMS\Core\Routing\InvalidRouteArgumentsException;
|
41 | 42 | use TYPO3\CMS\Core\Routing\RouterInterface;
|
| 43 | +use TYPO3\CMS\Core\Routing\UnableToLinkToPageException; |
42 | 44 | use TYPO3\CMS\Core\Site\SiteFinder;
|
43 | 45 | use TYPO3\CMS\Core\Type\Bitmask\Permission;
|
44 | 46 | use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser;
|
@@ -2306,15 +2308,19 @@ public static function viewOnClick(
|
2306 | 2308 | $additionalGetVars = '',
|
2307 | 2309 | $switchFocus = true
|
2308 | 2310 | ) {
|
2309 |
| - $previewUrl = self::getPreviewUrl( |
2310 |
| - $pageUid, |
2311 |
| - $backPath, |
2312 |
| - $rootLine, |
2313 |
| - $anchorSection, |
2314 |
| - $alternativeUrl, |
2315 |
| - $additionalGetVars, |
2316 |
| - $switchFocus |
2317 |
| - ); |
| 2311 | + try { |
| 2312 | + $previewUrl = self::getPreviewUrl( |
| 2313 | + $pageUid, |
| 2314 | + $backPath, |
| 2315 | + $rootLine, |
| 2316 | + $anchorSection, |
| 2317 | + $alternativeUrl, |
| 2318 | + $additionalGetVars, |
| 2319 | + $switchFocus |
| 2320 | + ); |
| 2321 | + } catch (UnableToLinkToPageException $e) { |
| 2322 | + return ''; |
| 2323 | + } |
2318 | 2324 |
|
2319 | 2325 | $onclickCode = 'var previewWin = window.open(' . GeneralUtility::quoteJSvalue($previewUrl) . ',\'newTYPO3frontendWindow\');'
|
2320 | 2326 | . ($switchFocus ? 'previewWin.focus();' : '') . LF
|
@@ -2380,21 +2386,25 @@ public static function getPreviewUrl(
|
2380 | 2386 | $rootLine = $rootLine ?? BackendUtility::BEgetRootLine($pageUid);
|
2381 | 2387 | try {
|
2382 | 2388 | $site = $siteFinder->getSiteByPageId((int)$pageUid, $rootLine);
|
2383 |
| - // Create a multi-dimensional array out of the additional get vars |
2384 |
| - $additionalQueryParams = []; |
2385 |
| - parse_str($additionalGetVars, $additionalQueryParams); |
2386 |
| - if (isset($additionalQueryParams['L'])) { |
2387 |
| - $additionalQueryParams['_language'] = $additionalQueryParams['_language'] ?? $additionalQueryParams['L']; |
2388 |
| - unset($additionalQueryParams['L']); |
2389 |
| - } |
| 2389 | + } catch (SiteNotFoundException $e) { |
| 2390 | + throw new UnableToLinkToPageException('The page ' . $pageUid . ' had no proper connection to a site, no link could be built.', 1559794919); |
| 2391 | + } |
| 2392 | + // Create a multi-dimensional array out of the additional get vars |
| 2393 | + $additionalQueryParams = []; |
| 2394 | + parse_str($additionalGetVars, $additionalQueryParams); |
| 2395 | + if (isset($additionalQueryParams['L'])) { |
| 2396 | + $additionalQueryParams['_language'] = $additionalQueryParams['_language'] ?? $additionalQueryParams['L']; |
| 2397 | + unset($additionalQueryParams['L']); |
| 2398 | + } |
| 2399 | + try { |
2390 | 2400 | $previewUrl = (string)$site->getRouter()->generateUri(
|
2391 | 2401 | $pageUid,
|
2392 | 2402 | $additionalQueryParams,
|
2393 | 2403 | $anchorSection,
|
2394 | 2404 | RouterInterface::ABSOLUTE_URL
|
2395 | 2405 | );
|
2396 |
| - } catch (SiteNotFoundException | \InvalidArgumentException | InvalidRouteArgumentsException $e) { |
2397 |
| - $previewUrl = self::createPreviewUrl($pageUid, $rootLine, $anchorSection, $additionalGetVars, $viewScript); |
| 2406 | + } catch (\InvalidArgumentException | InvalidRouteArgumentsException $e) { |
| 2407 | + throw new UnableToLinkToPageException('The page ' . $pageUid . ' had no proper connection to a site, no link could be built.', 1559794914); |
2398 | 2408 | }
|
2399 | 2409 | }
|
2400 | 2410 |
|
@@ -2479,96 +2489,38 @@ public static function getLinkToDataHandlerAction($parameters, $redirectUrl = ''
|
2479 | 2489 | return $url;
|
2480 | 2490 | }
|
2481 | 2491 |
|
2482 |
| - /** |
2483 |
| - * Creates the view-on-click preview URL without any alternative URL. |
2484 |
| - * |
2485 |
| - * @param int $pageUid Page UID |
2486 |
| - * @param array $rootLine If rootline is supplied, the function will look for the first found domain record and use that URL instead |
2487 |
| - * @param string $anchorSection Optional anchor to the URL |
2488 |
| - * @param string $additionalGetVars Additional GET variables. |
2489 |
| - * @param string $viewScript The path to the script used to view the page |
2490 |
| - * |
2491 |
| - * @return string The preview URL |
2492 |
| - */ |
2493 |
| - protected static function createPreviewUrl($pageUid, $rootLine, $anchorSection, $additionalGetVars, $viewScript) |
2494 |
| - { |
2495 |
| - // Look if a fixed preview language should be added: |
2496 |
| - $beUser = static::getBackendUserAuthentication(); |
2497 |
| - $viewLanguageOrder = (string)($beUser->getTSConfig()['options.']['view.']['languageOrder'] ?? ''); |
2498 |
| - |
2499 |
| - if (!empty($viewLanguageOrder)) { |
2500 |
| - $suffix = ''; |
2501 |
| - // Find allowed languages (if none, all are allowed!) |
2502 |
| - $allowedLanguages = null; |
2503 |
| - if (!$beUser->isAdmin() && $beUser->groupData['allowed_languages'] !== '') { |
2504 |
| - $allowedLanguages = array_flip(explode(',', $beUser->groupData['allowed_languages'])); |
2505 |
| - } |
2506 |
| - // Traverse the view order, match first occurrence: |
2507 |
| - $languageOrder = GeneralUtility::intExplode(',', $viewLanguageOrder); |
2508 |
| - foreach ($languageOrder as $langUid) { |
2509 |
| - if (is_array($allowedLanguages) && !empty($allowedLanguages)) { |
2510 |
| - // Choose if set. |
2511 |
| - if (isset($allowedLanguages[$langUid])) { |
2512 |
| - $suffix = '&L=' . $langUid; |
2513 |
| - break; |
2514 |
| - } |
2515 |
| - } else { |
2516 |
| - // All allowed since no lang. are listed. |
2517 |
| - $suffix = '&L=' . $langUid; |
2518 |
| - break; |
2519 |
| - } |
2520 |
| - } |
2521 |
| - // Add it |
2522 |
| - $additionalGetVars .= $suffix; |
2523 |
| - } |
2524 |
| - |
2525 |
| - // Check a mount point needs to be previewed |
2526 |
| - $pageRepository = GeneralUtility::makeInstance(PageRepository::class); |
2527 |
| - $mountPointInfo = $pageRepository->getMountPointInfo($pageUid); |
2528 |
| - |
2529 |
| - if ($mountPointInfo && $mountPointInfo['overlay']) { |
2530 |
| - $pageUid = $mountPointInfo['mount_pid']; |
2531 |
| - $additionalGetVars .= '&MP=' . $mountPointInfo['MPvar']; |
2532 |
| - } |
2533 |
| - $viewDomain = self::getViewDomain($pageUid, $rootLine); |
2534 |
| - |
2535 |
| - return $viewDomain . $viewScript . $pageUid . $additionalGetVars . $anchorSection; |
2536 |
| - } |
2537 |
| - |
2538 | 2492 | /**
|
2539 | 2493 | * Builds the frontend view domain for a given page ID with a given root
|
2540 | 2494 | * line.
|
2541 | 2495 | *
|
2542 | 2496 | * @param int $pageId The page ID to use, must be > 0
|
2543 | 2497 | * @param array|null $rootLine The root line structure to use
|
2544 | 2498 | * @return string The full domain including the protocol http:// or https://, but without the trailing '/'
|
| 2499 | + * @deprecated since TYPO3 v10.0, will be removed in TYPO3 v11.0. Use PageRouter instead. |
2545 | 2500 | */
|
2546 | 2501 | public static function getViewDomain($pageId, $rootLine = null)
|
2547 | 2502 | {
|
| 2503 | + trigger_error('BackendUtility::getViewDomain() will be removed in TYPO3 v11.0. Use a Site and its PageRouter to link to a page directly', E_USER_DEPRECATED); |
2548 | 2504 | $domain = rtrim(GeneralUtility::getIndpEnv('TYPO3_SITE_URL'), '/');
|
2549 | 2505 | if (!is_array($rootLine)) {
|
2550 | 2506 | $rootLine = self::BEgetRootLine($pageId);
|
2551 | 2507 | }
|
2552 | 2508 | // Checks alternate domains
|
2553 | 2509 | if (!empty($rootLine)) {
|
2554 |
| - $protocol = GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https' : 'http'; |
2555 |
| - $previewDomainConfig = self::getPagesTSconfig($pageId)['TCEMAIN.']['previewDomain'] ?? ''; |
2556 |
| - $domainName = null; |
2557 |
| - if (!empty($previewDomainConfig)) { |
2558 |
| - if (strpos($previewDomainConfig, '://') !== false) { |
2559 |
| - list($protocol, $domainName) = explode('://', $previewDomainConfig); |
2560 |
| - } else { |
2561 |
| - $domainName = $previewDomainConfig; |
| 2510 | + try { |
| 2511 | + $site = GeneralUtility::makeInstance(SiteFinder::class) |
| 2512 | + ->getSiteByPageId((int)$pageId, $rootLine); |
| 2513 | + $uri = $site->getBase(); |
| 2514 | + } catch (SiteNotFoundException $e) { |
| 2515 | + // Just use the current domain |
| 2516 | + $uri = new Uri($domain); |
| 2517 | + // Append port number if lockSSLPort is not the standard port 443 |
| 2518 | + $portNumber = (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']; |
| 2519 | + if ($portNumber > 0 && $portNumber !== 443 && $portNumber < 65536 && $uri->getScheme() === 'https') { |
| 2520 | + $uri = $uri->withPort((int)$portNumber); |
2562 | 2521 | }
|
2563 | 2522 | }
|
2564 |
| - if ($domainName) { |
2565 |
| - $domain = $protocol . '://' . $domainName; |
2566 |
| - } |
2567 |
| - // Append port number if lockSSLPort is not the standard port 443 |
2568 |
| - $portNumber = (int)$GLOBALS['TYPO3_CONF_VARS']['BE']['lockSSLPort']; |
2569 |
| - if ($portNumber > 0 && $portNumber !== 443 && $portNumber < 65536 && $protocol === 'https') { |
2570 |
| - $domain .= ':' . strval($portNumber); |
2571 |
| - } |
| 2523 | + return (string)$uri; |
2572 | 2524 | }
|
2573 | 2525 | return $domain;
|
2574 | 2526 | }
|
|
0 commit comments