Skip to content

Commit

Permalink
Merge branch 'release/26.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Apr 12, 2024
2 parents fb9b870 + ce1b799 commit 2a705c4
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 180 deletions.
38 changes: 4 additions & 34 deletions Classes/Domain/Service/BodytextManipulation/LinkHashing.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,18 @@
use Psr\EventDispatcher\EventDispatcherInterface;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\Exception;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotException;
use TYPO3\CMS\Extbase\SignalSlot\Exception\InvalidSlotReturnException;

/**
* Class LinkHashing to rewrite links in newsletter to be able to track link clicks
*/
class LinkHashing
{
/**
* @var Newsletter
*/
protected $newsletter = null;

/**
* @var User
*/
protected $user = null;

/**
* @var LinkRepository
*/
protected $linkRepository = null;

/**
* @var EventDispatcherInterface
*/
private $eventDispatcher;
protected ?Newsletter $newsletter = null;
protected ?User $user = null;
protected ?LinkRepository $linkRepository = null;
private EventDispatcherInterface $eventDispatcher;

/**
* LinkHashing constructor.
* @param Newsletter $newsletter
* @param User $user
*/
public function __construct(Newsletter $newsletter, User $user)
{
$this->newsletter = $newsletter;
Expand All @@ -65,10 +42,7 @@ public function __construct(Newsletter $newsletter, User $user)
* @param string $content
* @return string
* @throws ArgumentMissingException
* @throws Exception
* @throws IllegalObjectTypeException
* @throws InvalidSlotException
* @throws InvalidSlotReturnException
* @throws MisconfigurationException
* @throws SiteNotFoundException
*/
Expand All @@ -90,11 +64,8 @@ public function hashLinks(string $content): string
* @param DOMElement $aTag
* @return void
* @throws IllegalObjectTypeException
* @throws InvalidSlotException
* @throws InvalidSlotReturnException
* @throws MisconfigurationException
* @throws ArgumentMissingException
* @throws Exception
* @throws SiteNotFoundException
*/
protected function hashLink(DOMElement $aTag): void
Expand Down Expand Up @@ -122,7 +93,6 @@ protected function hashLink(DOMElement $aTag): void
* @param string $href
* @return string
* @throws MisconfigurationException
* @throws SiteNotFoundException
*/
protected function convertToAbsoluteHref(string $href): string
{
Expand Down
69 changes: 27 additions & 42 deletions Classes/Domain/Service/PreviewUrlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,24 @@
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException;

/**
* Class PreviewUrlService
*/
class PreviewUrlService
{
/**
* @var string
*/
protected $origin = '';

/**
* @var string
*/
protected $layout = '';

/**
* @var PageRepository
*/
protected $pageRepository;
protected string $origin = '';
protected string $layout = '';
protected ?PageRepository $pageRepository = null;
protected ?NewsletterParsing $parseService = null;
protected ?UserFactory $userFactory = null;
protected ?SiteService $siteService = null;

/**
* @var NewsletterParsing
*/
protected $parseService;

/**
* @var UserFactory
*/
protected $userFactory;

/**
* Constructor
*/
public function __construct()
{
$this->pageRepository = GeneralUtility::makeInstance(PageRepository::class);
$this->parseService = GeneralUtility::makeInstance(NewsletterParsing::class);
$this->userFactory = GeneralUtility::makeInstance(UserFactory::class);
$this->siteService = GeneralUtility::makeInstance(SiteService::class);
}

/**
Expand All @@ -76,7 +54,6 @@ public function get(string $origin, string $layout): array
* @param string $origin
* @param string $layout
* @return array
* @throws ExceptionDbalDriver
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
* @throws MisconfigurationException
Expand All @@ -98,11 +75,6 @@ protected function getUrlForMultiLanguageModeInstallation(string $origin, string
return $urls;
}

/**
* @param string $origin
* @param string $layout
* @return array
*/
protected function getUrlInDefaultInstallation(string $origin, string $layout): array
{
return [
Expand All @@ -113,18 +85,31 @@ protected function getUrlInDefaultInstallation(string $origin, string $layout):
];
}

/**
* @param string $origin
* @param string $layout
* @param int $language
* @return string
*/
protected function getUrl(string $origin, string $layout, int $language = 0): string
{
if (MathUtility::canBeInterpretedAsInteger($origin)) {
return $this->getUrlFromPageIdentifier((int)$origin, $layout, $language);
}

$url = '//' . GeneralUtility::getIndpEnv('HTTP_HOST') . '?type=1560777975';
$url .= '&tx_luxletter_preview[origin]=' . htmlspecialchars($origin);
$url .= '&tx_luxletter_preview[layout]=' . htmlspecialchars($layout);
$url .= '&tx_luxletter_preview[language]=' . $language;
return $url;
}

protected function getUrlFromPageIdentifier(int $origin, string $layout, int $language): string
{
return $this->siteService->getPageUrlFromParameter(
$origin,
[
'type' => 1560777975,
'tx_luxletter_preview' => [
'origin' => $origin,
'layout' => $layout,
'language' => $language,
],
]
);
}
}
12 changes: 5 additions & 7 deletions Classes/Domain/Service/SiteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ public function getPageUrlFromParameter(int $pageIdentifier, array $arguments =
public function getFrontendUrlFromParameter(array $arguments, Site $site): string
{
$this->checkForValidSite($site);
$siteService = GeneralUtility::makeInstance(SiteService::class);
$url = $siteService->getDomainFromSite($site);
$url = $this->getDomainFromSite($site);
$url .= '?' . http_build_query($arguments);
return $url;
}
Expand Down Expand Up @@ -141,15 +140,14 @@ protected function checkForValidSite(Site $site): void
}

/**
* Get current base domain with a trailing slash
* Get current base domain with a trailing slash and support also path postfix for default language
*
* @param Site $site
* @return string
* @return string e.g. "https://domain.org/" or "https://domain.org/en/"
*/
protected function getCurrentBaseDomain(Site $site): string
{
$base = (string)$site->getBase();
$base .= (substr($base, -1) === '/' ? '' : '/');
return $base;
$uri = $site->getRouter()->generateUri($site->getRootPageId());
return $uri->__tostring();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lib {

// Use absolute URL for all kind of links within fluidStyledMailContent
// (absRefPrefix is also used for absolute images paths - see ext_localconf.php)
// Todo: Remove this and part in ext_localconf.php and replace with `fluidStyledMailContent.config.forceAbsoluteUrls = 1` when TYPO3 11 support is dropped
// Todo: Remove this part when TYPO3 11 support is dropped (fluidStyledMailContent.config.forceAbsoluteUrls=1 is used in TYPO3 12)
parseFunc {
tags {
a.typolink.forceAbsoluteUrl = 1
Expand Down Expand Up @@ -62,6 +62,7 @@ fluidStyledMailContent {
admPanel = 0
debug = 0
linkVars =
forceAbsoluteUrls = 1
}

# Add some css for frontend view
Expand Down
Loading

0 comments on commit 2a705c4

Please sign in to comment.