patch_gaya.diff

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

Download (9.41 KB)

View differences:

typo3/sysext/core/Classes/Database/SoftReferenceIndex.php (revision c107879e8e1eb79faf2493084fb9d0429cc92672)
269 269
                        $linkDetails = $linkService->resolve($matches[1]);
270 270
                        if ($linkDetails['type'] === LinkService::TYPE_FILE && preg_match('/file\?uid=(\d+)/', $matches[1], $fileIdMatch)) {
271 271
                            $token = $this->makeTokenID($key);
272
                            // PATCH GAYA : ajout de matchString
273
                            $elements[$key]['matchString'] = $linkTags[$key];
274
                            // FIN PATCH GAYA
272 275
                            $linkTags[$key] = str_replace($matches[1], '{softref:' . $token . '}', $linkTags[$key]);
273 276
                            $elements[$key]['subst'] = [
274 277
                                'type' => 'db',
......
277 280
                                'tokenValue' => 'file:' . ($linkDetails['file'] instanceof File ? $linkDetails['file']->getUid() : $fileIdMatch[1])
278 281
                            ];
279 282
                        } elseif ($linkDetails['type'] === LinkService::TYPE_PAGE && preg_match('/page\?uid=(\d+)#?(\d+)?/', $matches[1], $pageAndAnchorMatches)) {
283
                            // PATCH GAYA : ajout de matchString et prise en charge des ancres corrigées
280 284
                            $token = $this->makeTokenID($key);
281
                            $linkTags[$key] = str_replace($matches[1], '{softref:' . $token . '}', $linkTags[$key]);
285
                            $content = '{softref:' . $token . '}';
286
                            $elements[$key]['matchString'] = $linkTags[$key];
282 287
                            $elements[$key]['subst'] = [
283 288
                                'type' => 'db',
284
                                'recordRef' => 'pages:' . $linkDetails['pageuid'] . (isset($pageAndAnchorMatches[2]) ? '#c' . $pageAndAnchorMatches[2] : ''),
289
                                'recordRef' => 'pages:' . $linkDetails['pageuid'],
285 290
                                'tokenID' => $token,
286
                                'tokenValue' => $linkDetails['pageuid'] . (isset($pageAndAnchorMatches[2]) ? '#c' . $pageAndAnchorMatches[2] : '')
291
                                'tokenValue' => $linkDetails['pageuid']
287 292
                            ];
293
                            if (isset($pageAndAnchorMatches[2]) && $pageAndAnchorMatches[2] !== '') {
294
                                // Anchor is assumed to point to a content elements:
295
                                if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($pageAndAnchorMatches[2])) {
296
                                    // Initialize a new entry because we have a new relation:
297
                                    $newTokenID = $this->makeTokenID('setTypoLinkPartsElement:anchor:' . $key);
298
                                    $elements[$newTokenID . ':' . $key] = [];
299
                                    $elements[$newTokenID . ':' . $key]['matchString'] = 'Anchor Content Element: ' . $pageAndAnchorMatches[2];
300
                                    $content .= '#{softref:' . $newTokenID . '}';
301
                                    $elements[$newTokenID . ':' . $key]['subst'] = [
302
                                        'type' => 'db',
303
                                        'recordRef' => 'tt_content:' . $pageAndAnchorMatches[2],
304
                                        'tokenID' => $newTokenID,
305
                                        'tokenValue' => $pageAndAnchorMatches[2]
306
                                    ];
307
                                } else {
308
                                    // Anchor is a hardcoded string
309
                                    $content .= '#' . $pageAndAnchorMatches[2];
310
                                }
311
                            }
312
                            $linkTags[$key] = str_replace($matches[1], $content, $linkTags[$key]);
313
                            // FIN PATCH GAYA
288 314
                        } elseif ($linkDetails['type'] === LinkService::TYPE_URL) {
289 315
                            $token = $this->makeTokenID($key);
316
                            // PATCH GAYA : ajout de matchString
317
                            $elements[$key]['matchString'] = $linkTags[$key];
318
                            // FIN PATCH GAYA
290 319
                            $linkTags[$key] = str_replace($matches[1], '{softref:' . $token . '}', $linkTags[$key]);
291 320
                            $elements[$key]['subst'] = [
292 321
                                'type' => 'external',
......
301 330
                    // keep the legacy code for now
302 331
                    $typolinkValue = preg_replace('/<LINK[[:space:]]+/i', '', substr($foundValue, 0, -1));
303 332
                    $tLP = $this->getTypoLinkParts($typolinkValue);
304
                    $linkTags[$k] = '<LINK ' . $this->setTypoLinkPartsElement($tLP, $elements, $typolinkValue, $k) . '>';
333
                    // PATCH GAYA
334
                    //$linkTags[$k] = '<LINK ' . $this->setTypoLinkPartsElement($tLP, $elements, $typolinkValue, $k) . '>';
335
                    $linkTags[$key] = '<LINK ' . $this->setTypoLinkPartsElement($tLP, $elements, $typolinkValue, $key) . '>';
336
                    // FIN PATCH GAYA
305 337
                }
306 338
            }
307 339
        }
......
461 493
            return $finalTagParts;
462 494
        }
495
        // PATCH GAYA
496
        // Prise en charge des liens t3:// vers les pages
497
        // Sans cela, les softref vers les pages ne sont pas détectées !
498
        $linkService = GeneralUtility::makeInstance(LinkService::class);
499
        $linkDetails = $linkService->resolve($link_param);
500
        if ($linkDetails['type'] === LinkService::TYPE_PAGE) {
501
            $finalTagParts['LINK_TYPE'] = LinkService::TYPE_PAGE;
502
            $finalTagParts['page_id'] = $linkDetails['pageuid'];
503
            if (isset($linkDetails['pagealias'])) {
504
                $finalTagParts['alias'] = $linkDetails['pagealias'];
505
            }
506
            if (isset($linkDetails['pagetype'])) {
507
                $finalTagParts['type'] = $linkDetails['pagetype'];
508
            }
509
            if (isset($linkDetails['fragment'])) {
510
                $finalTagParts['anchor'] = $linkDetails['fragment'];
511
            }
512
            return $finalTagParts;
513
        }
514
        // FIN PATCH GAYA
515

  
463 516
        if ($pU['scheme'] === 't3' && $pU['host'] === LinkService::TYPE_RECORD) {
464 517
            $finalTagParts['LINK_TYPE'] = LinkService::TYPE_RECORD;
465 518
            $finalTagParts['url'] = $link_param;
......
627 680
                        ];
628 681
                    } else {
629 682
                        // Anchor is a hardcoded string
630
                        $content .= '#' . $tLP['type'];
683
                        // PATCH GAYA
684
                        //$content .= '#' . $tLP['type'];
685
                        $content .= '#' . $tLP['anchor'];
686
                        // FIN PATCH GAYA
631 687
                    }
632 688
                }
633 689
                break;
typo3/sysext/impexp/Classes/Import.php (revision c107879e8e1eb79faf2493084fb9d0429cc92672)
1421 1421
                                    $insertValue = $tokenKey . ':' . $insertValue;
1422 1422
                                }
1423 1423
                            }
1424
                            // PATCH GAYA
1425
                            if ($tempTable === 'pages') {
1426
                                $insertValue = $this->fixLegacyLinkFormat($cfg['spKey'], $insertValue);
1427
                            }
1428
                            // FIN PATCH GAYA
1424 1429
                    }
1425 1430
            }
1426 1431
            // Finally, swap the soft reference token in tokenized content with the insert value:
......
1429 1434
        return $tokenizedContent;
1430 1435
    }
1436
    /**
1437
     * PATCH GAYA
1438
     * Retransforme les token softref en url de type t3://
1439
     *
1440
     * @param $spKey
1441
     * @param $content
1442
     * @return string
1443
     * @throws \TYPO3\CMS\Core\LinkHandling\Exception\UnknownLinkHandlerException
1444
     */
1445
    private function fixLegacyLinkFormat($spKey, $content) {
1446
        switch ($spKey) {
1447
            case 'typolink':
1448
            case 'typolink_tag':
1449
                $tLService = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Service\TypoLinkCodecService::class);
1450
                /* @var \TYPO3\CMS\Core\LinkHandling\LinkService $linkService */
1451
                $linkService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\LinkHandling\LinkService::class);
1452
                $linkElement = explode(',', $content);
1453
                foreach ($linkElement as $k => $typolinkValue) {
1454
                    $tLP = $tLService->decode($typolinkValue);
1455
                    $linkDetails = $linkService->resolve($tLP['url']);
1456
                    $linkElement[$k] = $linkService->asString($linkDetails);
1457
                }
1458
                $content = implode(',', $linkElement);
1459
                break;
1460
        }
1461

  
1462
        return $content;
1463
    }
1464

  
1431 1465
    /**
1432 1466
     * Process a soft reference file
1433 1467
     *