Project

General

Profile

Actions

Bug #86494

closed

RteHtmlParser :: TS_links_rte seems not to resolve links to internal files

Added by Dieter Porth over 5 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
RTE (rtehtmlarea + ckeditor)
Target version:
-
Start date:
2018-10-01
Due date:
% Done:

0%

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

Description

Internal links to files are in the internal method
TYPO3 \ CMS \ Core \ Html \ RteHtmlParser :: TS_links_rte
not dissolved.

Story:
In a Command Controller, a RTE field is parsed. The field can contain all forms of RTE links. The field contains the body text of an email. I use TYPO3 7.6.31.

My Current Workaround:
To display the internal links, the system variable HTTP_HOST must be set in the command line in addition to the TYPO3_CONTEXT. Also, I have to initialize manually the $ GLOBALS ['TSFE'] in the commandController, because the Instance of RteHtmlParser was not enough.

Problem
The links to internal files won't be resolved correctly in
TYPO3 \ CMS \ Core \ Html \ RteHtmlParser :: TS_links_rte

Rhe genration of links to internal files fails, because the method TS_links_rte contains only the lines 696-698

if ($linkHandlerKeyword === 'file' && !StringUtility::beginsWith($link_param, 'file://')) {
    $href = $siteUrl . '?' . $linkHandlerKeyword . ':' . rawurlencode($linkHandlerValue);
} else {

As a workaround I have to parse the already parsed text.


/**
 * @param int $fileId
 * @throws \InvalidArgumentException
 * @throws FileDoesNotExistException
 * @return string
 */
protected function detectPathToInternalFile ($fileId=0) {
    $path = '';
    if ($fileId >0) {
        /** @var ResourceFactory $resourceFactory */
        $resourceFactory = ResourceFactory::getInstance();
        /** @var File $file */
        $file = $resourceFactory->getFileObject($fileId);
        $fileStoragePath = $file->getIdentifier();
        /** @var  $myStorage */
        $urlStoragePath = $file->getStorage()->getConfiguration()['basePath'];

        $path = $urlStoragePath.$fileStoragePath;
        $path = str_replace('//','/',$path);
    }

    return $path;
}

/**
 * @param string $messageText
 * @return string
 * @throws \InvalidArgumentException
 * @throws FileDoesNotExistException
 */
protected function workaroundGenerateLinksToFilesForRte($messageText = '') {
    $parts = explode('?file:',$messageText);
    $result = $messageText;
    if (($countParts = count($parts)) >1) {
        for($i=1;$i <$countParts;$i++ ) {
            $fileId = (int) $parts[$i];
            $fileRelPath = $this->detectPathToInternalFile($fileId);
            if (($fileRelPath !== '') &&
                (strpos($parts[$i],((string)$fileId))===0)
            ) {
                $parts[$i]= $fileRelPath . substr($parts[$i],strlen((string)$fileId));
            }

        }
        $result = implode('',$parts);
    }
    return $result;
}

Actions

Also available in: Atom PDF