Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ public/
vendor/
var/
.phpunit.result.cache
.idea/
16 changes: 15 additions & 1 deletion Classes/Middleware/InternalSsiRedirectMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,21 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
->withQueryParams([])
->withUri($request->getUri()->withPath($originalRequestUri->getPath())->withQuery($originalRequestUri->getQuery()));
$handler->handle($subRequest);
$content = $this->lastRenderedContentRegister->get();
$keyParts = explode('_', (string) $ssiInclude);
if (isset($keyParts[2])) {
$key = $keyParts[2];
// may strip the .html extension
$position = strrpos($key, '.');
if ($position) {
$key = substr($key, 0, $position);
}

$content = $this->lastRenderedContentRegister->get($key);
} elseif (file_exists($absolutePath)) {
$content = file_get_contents($absolutePath);
} else {
$content = '<error>EXT:ssi_include error path:' . $ssiInclude . '</error>';
}
}

return new HtmlResponse($content ?: '<error>EXT:ssi_include error path:' . $absolutePath . '</error>');
Expand Down
17 changes: 12 additions & 5 deletions Classes/Register/LastRenderedContentRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@

class LastRenderedContentRegister implements SingletonInterface
{
private string $lastRenderedContent = '';
/**
* @var array<string, string>
*/
private array $lastRenderedContent = [];

public function set(string $content): void
public function set(string $key, string $content): void
{
$this->lastRenderedContent = $content;
$this->lastRenderedContent[$key] = $content;
}

public function get(): string
public function get(string $key): string
{
return $this->lastRenderedContent;
if (!isset($this->lastRenderedContent[$key])) {
return '';
}

return $this->lastRenderedContent[$key];
}
}
6 changes: 5 additions & 1 deletion Classes/Utility/IsCacheableUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
class IsCacheableUtility
{
public function __construct(private readonly Context $context)
{
}

public function usePageCache(?TypoScriptFrontendController $typoScriptFrontendController = null, bool $usePageCache = true): bool
{
if (!$usePageCache) {
Expand All @@ -26,7 +30,7 @@ public function usePageCache(?TypoScriptFrontendController $typoScriptFrontendCo
return $usePageCache;
}

$context = GeneralUtility::makeInstance(Context::class);
$context = $this->context;
assert($context instanceof Context);
$backendUserContext = $context->getAspect('backend.user');
if ($backendUserContext->isLoggedIn()) {
Expand Down
16 changes: 8 additions & 8 deletions Classes/ViewHelpers/RenderIncludeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException;
use TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
Expand Down Expand Up @@ -85,10 +84,13 @@ public function renderNonStatic(?array $arguments = null, ?Closure $renderChildr
$this->renderingContext = $renderingContext ?? $this->renderingContext;
$renderChildrenClosure ??= $this->buildRenderChildrenClosure();

// generate the cache filename
$name = $this->validateName($this->arguments);

if ($this->isBackendUser()) {
$content = parent::renderStatic($this->arguments, $renderChildrenClosure, $this->renderingContext);
// Put the code to register to use in InternalSsiRedirectMiddleware if the site comes from page cache
$this->lastRenderedContentRegister->set($content);
$this->lastRenderedContentRegister->set($name, $content);
return $content;
}

Expand All @@ -100,9 +102,7 @@ public function renderNonStatic(?array $arguments = null, ?Closure $renderChildr
$groupString = '_' . implode('-', $frontendUser->getGroupIds());
}

// generate the cache filename
$name = $this->validateName($this->arguments);
$filename = $this->getSiteName() . '_' . $this->getLangauge() . '_' . $name . $groupString . '.html';
$filename = $this->getSiteName() . '_' . $this->getLanguage() . '_' . $name . $groupString . '.html';

// If the cache has not the proper entry, generate it
$cache = $this->cacheManager->getCache('aus_ssi_include_cache');
Expand All @@ -116,10 +116,10 @@ public function renderNonStatic(?array $arguments = null, ?Closure $renderChildr

$cacheTags = ['tx_ssiinclude_' . $name, ...$this->arguments['cacheTags']];
$cache->set($filename, $html, $cacheTags, $this->arguments['cacheLifeTime']);
$this->lastRenderedContentRegister->set($html);
$this->lastRenderedContentRegister->set($name, $html);
}

// generate the variables needed for include commments
// generate the variables needed for include comments
$reqUrl = $this->filenameUtility->getReqUrl($filename);
$method = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('ssi_include', 'method');
if ($method === self::METHOD_ESI) {
Expand All @@ -145,7 +145,7 @@ private function validateName(array $arguments): string
/**
* @throws AspectNotFoundException
*/
protected function getLangauge(): int
protected function getLanguage(): int
{
return $this->context->getPropertyFromAspect('language', 'id');
}
Expand Down
Loading