Project

General

Profile

Actions

Bug #87919

closed

config.absRefPrefix not working for links in HMENU, fluid generated links like <f:link.page ... or <f:link.typolink ...

Added by Martin Weymayer over 5 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
TypoScript
Target version:
-
Start date:
2019-03-15
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Steps to reproduce:
1) install typo3
2) add menu in typoscript like:

lib.menu >
lib.menu = HMENU
lib.menu {
  special = directory
  special.value = 1
  1 = TMENU
   1 {
                expAll =1
                wrap = <ul>|</ul>
                noBlur = 1
                NO = 1
                NO {
                        wrapItemAndSub = <li class="first">|</li> |*| <li>|</li> |*| <li class="last">|</li>
                        stdWrap.htmlSpecialChars = 1

                }
                ACT <.NO
                ACT {
                        wrapItemAndSub = <li class="first active">|</li> |*| <li class="active">|</li> |*| <li class="last active">|</li>
                        stdWrap.htmlSpecialChars = 1
                        ATagParams = class="active" 
                } ....

3) add configuration config.absRefPrefix = https://www.domain.at/

expected result:
Links in menu and fluid generated links should look like <a href="https://www.domain.at/page&quot;&gt;....

actual result:
links look like <a href="/page">....

css files and images are including absolute path domain, but not links from menu and fluid generated

martin


Related issues 1 (1 open0 closed)

Related to TYPO3 Core - Bug #82574: Inconsistent support of config.absRefPrefix in fluid/extbaseNew2017-09-28

Actions
Actions #1

Updated by Riccardo De Contardi over 5 years ago

  • Category set to TypoScript
Actions #2

Updated by Patrick Lenk over 5 years ago

I can confirm this in current 9.5.7. Also ckeditor and contentelement links are not prefixed.

Actions #3

Updated by Riccardo De Contardi about 5 years ago

I confirm for 9.5.11 and latest master,

It seems that config.absRefPrefix is not considered on

1) TypoScript links built with typolink function
2) HMENU TypoScript objects
3) Links in CKEditor
4) Header of content elements (linked)

It is considered on

1) IMAGE TypoScript objects
2) includeJS and includeCSS objects

Actions #4

Updated by Riccardo De Contardi about 5 years ago

  • Related to Bug #82574: Inconsistent support of config.absRefPrefix in fluid/extbase added
Actions #5

Updated by ondro no-lastname-given over 4 years ago

Can confirm in typo3 v9.5.16 too.
Any news about this?

Actions #6

Updated by Chris W over 4 years ago

Same in 10.4.5

Actions #7

Updated by Michael Sollmann almost 4 years ago

Can confirm this for 10.4.12.
Any news?

Actions #8

Updated by Jonas Eberle over 3 years ago

You can use `(NO/ACT/...).stdWrap.typolink.forceAbsoluteUrl`.

I think `config.absRefPrefix` should be deprecated since it doesn't make any sense any more with site config. `typolink.forceAbsoluteUrl` is able to replace it where needed.

Actions #9

Updated by Patrick Lenk over 3 years ago

Jonas Eberle wrote in #note-8:

You can use `(NO/ACT/...).stdWrap.typolink.forceAbsoluteUrl`.

I think `config.absRefPrefix` should be deprecated since it doesn't make any sense any more with site config. `typolink.forceAbsoluteUrl` is able to replace it where needed.

How to enable the absolute url for ckeditor links like <a href="t3://page?uid=123">Link</a> ?
We use page links in the powermail body ckeditor fields. Without the absolute path, the link is not working in a email.

config.absRefPrefix is still not working in TYPO3 10.4.13.

Just found this comment from benni mack: https://forge.typo3.org/issues/93039#note-1

For ckeditor typolinks this config make every link absolute:

lib.parseFunc_RTE.tags.a.typolink {
  forceAbsoluteUrl = 1
  forceAbsoluteUrl.scheme = https
}

In fluid links there is the absolute attribute.

Actions #10

Updated by Marc Hirdes over 3 years ago

We have also this issue. We export the HTML for Newsletter Mails. So it's necessary that all links of the page are absolute.

Actions #11

Updated by Marc Hirdes over 3 years ago

Current Middleware Workaround in TYPO3 v10:


<?php

namespace Clickstorm\CsNewsletterExport\Middleware;

use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\Http\NullResponse;
use TYPO3\CMS\Core\Http\RequestFactory;
use TYPO3\CMS\Core\Http\ResponseFactory;
use TYPO3\CMS\Core\Http\Stream;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
 * prefix all links and src with $GLOBALS['TSFE']->absRefPrefix
 *
 * Class GenerateAbsoluteLinksMiddleware
 * @package Clickstorm\CsNewsletterExport\Middleware
 */
class GenerateAbsoluteLinksMiddleware implements MiddlewareInterface
{
    /** @var ResponseFactory */
    private $responseFactory;
    /** @var RequestFactory */
    private $requestFactory;
    /** @var ClientInterface */
    private $client;

    public function __construct(
        ResponseFactoryInterface $responseFactory,
        RequestFactoryInterface $requestFactory,
        ClientInterface $client
    ) {
        $this->responseFactory = $responseFactory;
        $this->requestFactory = $requestFactory;
        $this->client = $client;
    }

    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {

        $response = $handler->handle($request);
        if (
            !($response instanceof NullResponse)
            && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController
            && $GLOBALS['TSFE']->absRefPrefix 
            && $GLOBALS['TSFE']-> !== '/'
            && $GLOBALS['TSFE']-> !== 'auto'
        ) {
            $body = $response->getBody();
            $body->rewind();
            $contents = $response->getBody()->getContents();
            $content = $this->parseRelativeToAbsoluteUrls($contents);
            $body = new Stream('php://temp', 'rw');
            $body->write($content);
            $response = $response->withBody($body);
        }

        return $response;
    }

    protected function parseRelativeToAbsoluteUrls(string $input = ''): string
    {
        // https://thydzik.com/convert-relative-links-to-absolute-links-with-php-regex/
        $prefix = $GLOBALS['TSFE']->absRefPrefix;

        return preg_replace('/((?:href|src) *= *[\'"])(\/)/i', "$1$prefix", $input);
    }
}

Actions #12

Updated by Jan Kornblum about 3 years ago

I agree since site configuration exists, „absRefPrefix“ is not necessary any longer. But when it gets deprecated or removed, a new configuration option should be introduced to globally enable creation of absolute links, based on site configuration!

Actions #13

Updated by Gerrit Code Review about 2 years ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/76463

Actions #14

Updated by Gerrit Code Review about 2 years ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/76463

Actions #15

Updated by Gerrit Code Review about 2 years ago

Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/76463

Actions #16

Updated by Benni Mack about 2 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #17

Updated by Benni Mack almost 2 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF