17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
93 <title>###TITLE###</title>
94 <meta name=
"robots" content=
"noindex,follow" />
105 protected $imageTag =
'<img src="###publicUrl###" alt="###alt###" title="###title###" width="###width###" height="###height###" />';
115 $fileUid = $this->request->getQueryParams()[
'file'] ??
null;
116 $parametersArray = $this->request->getQueryParams()[
'parameters'] ??
null;
119 if (!$fileUid || !isset($parametersArray) || !is_array($parametersArray)) {
120 throw new \InvalidArgumentException(
'No valid fileUid given', 1476048455);
124 $parametersEncoded = implode(
'', $parametersArray);
127 $hmacParameter = $this->request->getQueryParams()[
'md5'] ??
null;
128 $hmac = GeneralUtility::hmac(implode(
'|', [$fileUid, $parametersEncoded]));
129 if (!is_string($hmacParameter) || !hash_equals($hmac, $hmacParameter)) {
130 throw new \InvalidArgumentException(
'hash does not match', 1476048456);
135 $parameters = json_decode(base64_decode($parametersEncoded),
true) ?? [];
136 foreach ($parameters as $parameterName => $parameterValue) {
137 if (in_array($parameterName, static::ALLOWED_PARAMETER_NAMES,
true)) {
138 $this->{$parameterName} = $parameterValue;
147 if ($this->file !==
null && !$this->
isFileValid($this->file)) {
148 throw new Exception(
'File processing for local storage is denied', 1594043425);
151 $this->frame = $this->request->getQueryParams()[
'frame'] ??
null;
158 public function main()
162 '###publicUrl###' => htmlspecialchars($processedImage->getPublicUrl()),
163 '###alt###' => htmlspecialchars($this->file->getProperty(
'alternative') ?: $this->title),
164 '###title###' => htmlspecialchars($this->file->getProperty(
'title') ?: $this->title),
165 '###width###' => $processedImage->getProperty(
'width'),
166 '###height###' => $processedImage->getProperty(
'height')
168 $this->imageTag = str_replace(array_keys($imageTagMarkers), array_values($imageTagMarkers), $this->imageTag);
170 '###TITLE###' => $this->file->getProperty(
'title') ?:
$this->title,
175 $this->content = str_replace(array_keys($markerArray), array_values($markerArray), $this->content);
185 if (strstr($this->width . $this->height,
'm')) {
193 $processingConfiguration = [
216 $response->getBody()->write($this->content);
218 }
catch (\InvalidArgumentException $e) {
222 return (
new Response)->withStatus(404);
228 return $file->getStorage()->getDriverType() !==
'Local'
229 || GeneralUtility::verifyFilenameAgainstDenyPattern(basename(
$file->getIdentifier()));