Bug #87919

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

Added by Martin Weymayer over 2 years ago. Updated 6 months ago.

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

0%

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">....

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

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

Actions
#1

Updated by Riccardo De Contardi over 2 years ago

  • Category set to TypoScript
#2

Updated by Patrick no-lastname-given over 2 years ago

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

#3

Updated by Riccardo De Contardi almost 2 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

#4

Updated by Riccardo De Contardi almost 2 years ago

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

Updated by ondro no-lastname-given over 1 year ago

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

#6

Updated by Chris W about 1 year ago

Same in 10.4.5

#7

Updated by Michael Sollmann 9 months ago

Can confirm this for 10.4.12.
Any news?

#8

Updated by Jonas Eberle 7 months 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.

#9

Updated by Patrick no-lastname-given 6 months 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.

#10

Updated by Marc Hirdes 6 months 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.

#11

Updated by Marc Hirdes 6 months 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);
    }
}

Also available in: Atom PDF