Project

General

Profile

Bug #84016 » patch_gaya.diff

Rémy DANIEL, 2019-09-10 18:52

View differences:

typo3/sysext/core/Classes/Database/SoftReferenceIndex.php (revision c107879e8e1eb79faf2493084fb9d0429cc92672)
$linkDetails = $linkService->resolve($matches[1]);
if ($linkDetails['type'] === LinkService::TYPE_FILE && preg_match('/file\?uid=(\d+)/', $matches[1], $fileIdMatch)) {
$token = $this->makeTokenID($key);
// PATCH GAYA : ajout de matchString
$elements[$key]['matchString'] = $linkTags[$key];
// FIN PATCH GAYA
$linkTags[$key] = str_replace($matches[1], '{softref:' . $token . '}', $linkTags[$key]);
$elements[$key]['subst'] = [
'type' => 'db',
......
'tokenValue' => 'file:' . ($linkDetails['file'] instanceof File ? $linkDetails['file']->getUid() : $fileIdMatch[1])
];
} elseif ($linkDetails['type'] === LinkService::TYPE_PAGE && preg_match('/page\?uid=(\d+)#?(\d+)?/', $matches[1], $pageAndAnchorMatches)) {
// PATCH GAYA : ajout de matchString et prise en charge des ancres corrigées
$token = $this->makeTokenID($key);
$linkTags[$key] = str_replace($matches[1], '{softref:' . $token . '}', $linkTags[$key]);
$content = '{softref:' . $token . '}';
$elements[$key]['matchString'] = $linkTags[$key];
$elements[$key]['subst'] = [
'type' => 'db',
'recordRef' => 'pages:' . $linkDetails['pageuid'] . (isset($pageAndAnchorMatches[2]) ? '#c' . $pageAndAnchorMatches[2] : ''),
'recordRef' => 'pages:' . $linkDetails['pageuid'],
'tokenID' => $token,
'tokenValue' => $linkDetails['pageuid'] . (isset($pageAndAnchorMatches[2]) ? '#c' . $pageAndAnchorMatches[2] : '')
'tokenValue' => $linkDetails['pageuid']
];
if (isset($pageAndAnchorMatches[2]) && $pageAndAnchorMatches[2] !== '') {
// Anchor is assumed to point to a content elements:
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($pageAndAnchorMatches[2])) {
// Initialize a new entry because we have a new relation:
$newTokenID = $this->makeTokenID('setTypoLinkPartsElement:anchor:' . $key);
$elements[$newTokenID . ':' . $key] = [];
$elements[$newTokenID . ':' . $key]['matchString'] = 'Anchor Content Element: ' . $pageAndAnchorMatches[2];
$content .= '#{softref:' . $newTokenID . '}';
$elements[$newTokenID . ':' . $key]['subst'] = [
'type' => 'db',
'recordRef' => 'tt_content:' . $pageAndAnchorMatches[2],
'tokenID' => $newTokenID,
'tokenValue' => $pageAndAnchorMatches[2]
];
} else {
// Anchor is a hardcoded string
$content .= '#' . $pageAndAnchorMatches[2];
}
}
$linkTags[$key] = str_replace($matches[1], $content, $linkTags[$key]);
// FIN PATCH GAYA
} elseif ($linkDetails['type'] === LinkService::TYPE_URL) {
$token = $this->makeTokenID($key);
// PATCH GAYA : ajout de matchString
$elements[$key]['matchString'] = $linkTags[$key];
// FIN PATCH GAYA
$linkTags[$key] = str_replace($matches[1], '{softref:' . $token . '}', $linkTags[$key]);
$elements[$key]['subst'] = [
'type' => 'external',
......
// keep the legacy code for now
$typolinkValue = preg_replace('/<LINK[[:space:]]+/i', '', substr($foundValue, 0, -1));
$tLP = $this->getTypoLinkParts($typolinkValue);
$linkTags[$k] = '<LINK ' . $this->setTypoLinkPartsElement($tLP, $elements, $typolinkValue, $k) . '>';
// PATCH GAYA
//$linkTags[$k] = '<LINK ' . $this->setTypoLinkPartsElement($tLP, $elements, $typolinkValue, $k) . '>';
$linkTags[$key] = '<LINK ' . $this->setTypoLinkPartsElement($tLP, $elements, $typolinkValue, $key) . '>';
// FIN PATCH GAYA
}
}
}
......
return $finalTagParts;
}
// PATCH GAYA
// Prise en charge des liens t3:// vers les pages
// Sans cela, les softref vers les pages ne sont pas détectées !
$linkService = GeneralUtility::makeInstance(LinkService::class);
$linkDetails = $linkService->resolve($link_param);
if ($linkDetails['type'] === LinkService::TYPE_PAGE) {
$finalTagParts['LINK_TYPE'] = LinkService::TYPE_PAGE;
$finalTagParts['page_id'] = $linkDetails['pageuid'];
if (isset($linkDetails['pagealias'])) {
$finalTagParts['alias'] = $linkDetails['pagealias'];
}
if (isset($linkDetails['pagetype'])) {
$finalTagParts['type'] = $linkDetails['pagetype'];
}
if (isset($linkDetails['fragment'])) {
$finalTagParts['anchor'] = $linkDetails['fragment'];
}
return $finalTagParts;
}
// FIN PATCH GAYA
if ($pU['scheme'] === 't3' && $pU['host'] === LinkService::TYPE_RECORD) {
$finalTagParts['LINK_TYPE'] = LinkService::TYPE_RECORD;
$finalTagParts['url'] = $link_param;
......
];
} else {
// Anchor is a hardcoded string
$content .= '#' . $tLP['type'];
// PATCH GAYA
//$content .= '#' . $tLP['type'];
$content .= '#' . $tLP['anchor'];
// FIN PATCH GAYA
}
}
break;
typo3/sysext/impexp/Classes/Import.php (revision c107879e8e1eb79faf2493084fb9d0429cc92672)
$insertValue = $tokenKey . ':' . $insertValue;
}
}
// PATCH GAYA
if ($tempTable === 'pages') {
$insertValue = $this->fixLegacyLinkFormat($cfg['spKey'], $insertValue);
}
// FIN PATCH GAYA
}
}
// Finally, swap the soft reference token in tokenized content with the insert value:
......
return $tokenizedContent;
}
/**
* PATCH GAYA
* Retransforme les token softref en url de type t3://
*
* @param $spKey
* @param $content
* @return string
* @throws \TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException
*/
private function fixLegacyLinkFormat($spKey, $content) {
switch ($spKey) {
case 'typolink':
case 'typolink_tag':
$tLService = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Service\TypoLinkCodecService::class);
/* @var \TYPO3\CMS\Core\LinkHandling\LinkService $linkService */
$linkService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\LinkHandling\LinkService::class);
$linkElement = explode(',', $content);
foreach ($linkElement as $k => $typolinkValue) {
$tLP = $tLService->decode($typolinkValue);
$linkDetails = $linkService->resolve($tLP['url']);
$linkElement[$k] = $linkService->asString($linkDetails);
}
$content = implode(',', $linkElement);
break;
}
return $content;
}
/**
* Process a soft reference file
*
(4-4/4)