From 3f1ec070e3593500bc35e7049953d5959e908c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ephraim=20H=C3=A4rer?= Date: Thu, 25 Jun 2020 08:46:38 +0200 Subject: [PATCH] cleaned up coding, updated composer.json, added check if there is still a parameter in url, release of version 2.0.1 --- Classes/Signal/PublicFileUri.php | 50 ++++++++++++++++++------------- Documentation/ChangeLog/Index.rst | 7 +++++ Documentation/Settings.cfg | 2 +- composer.json | 32 ++++++++++++++++---- ext_emconf.php | 2 +- 5 files changed, 66 insertions(+), 27 deletions(-) diff --git a/Classes/Signal/PublicFileUri.php b/Classes/Signal/PublicFileUri.php index d176cdf..0ccfbaa 100644 --- a/Classes/Signal/PublicFileUri.php +++ b/Classes/Signal/PublicFileUri.php @@ -27,14 +27,19 @@ * This copyright notice MUST APPEAR in all copies of the script! * ************************************************************* */ +use \TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException; +use \TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException; use \TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use \TYPO3\CMS\Core\Core\Environment; +use \TYPO3\CMS\Core\Resource\Driver\LocalDriver; +use \TYPO3\CMS\Core\Resource\Exception; +use \TYPO3\CMS\Core\Resource\ResourceStorage; use \TYPO3\CMS\Core\Utility\GeneralUtility; use \TYPO3\CMS\Core\Utility\PathUtility; use \TYPO3\CMS\Core\Resource\File; /** - * hooks the public file uri function + * hooks into the public file uri generating */ class PublicFileUri { @@ -47,7 +52,7 @@ class PublicFileUri protected $extKey = 'reint_file_timestamp'; /** - * settings in extension manager + * settings in extension configuration * * @var array */ @@ -56,13 +61,16 @@ class PublicFileUri /** * signal slot for public url generation of a file * - * @param \TYPO3\CMS\Core\Resource\ResourceStorage $t - * @param \TYPO3\CMS\Core\Resource\Driver\LocalDriver $driver + * @param ResourceStorage $t + * @param LocalDriver $driver * @param object $resourceObject e.g. \TYPO3\CMS\Core\Resource\File, \TYPO3\CMS\Core\Resource\Folder, \TYPO3\CMS\Core\Resource\ProcessedFile - * @param boolean $relativeToCurrentScript + * @param bool $relativeToCurrentScript * @param array $urlData * @return void - * @see \TYPO3\CMS\Core\Resource\ResourceStorage and the function getPublicUrl + * @throws ExtensionConfigurationExtensionNotConfiguredException + * @throws ExtensionConfigurationPathDoesNotExistException + * @throws Exception + * @see ResourceStorage and the function getPublicUrl */ public function preGeneratePublicUrl($t, $driver, $resourceObject, $relativeToCurrentScript, $urlData) { @@ -88,10 +96,10 @@ public function preGeneratePublicUrl($t, $driver, $resourceObject, $relativeToCu if ($this->emSettings['disable_fe']) { $enable = false; } else { - // check filetypes field + /* check fileTypes field */ if (!empty($this->emSettings['filetypes_fe'])) { - $filetypes = explode(',', $this->emSettings['filetypes_fe']); - if (!in_array($fileData['extension'], $filetypes, true)) { + $fileTypes = explode(',', $this->emSettings['filetypes_fe']); + if (!in_array($fileData['extension'], $fileTypes, true)) { $enable = false; } } @@ -107,10 +115,10 @@ public function preGeneratePublicUrl($t, $driver, $resourceObject, $relativeToCu if ($this->emSettings['disable_be']) { $enable = false; } else { - /* check filetypes field */ + /* check fileTypes field */ if (!empty($this->emSettings['filetypes_be'])) { - $filetypes = explode(',', $this->emSettings['filetypes_be']); - if (!in_array($fileData['extension'], $filetypes, true)) { + $fileTypes = explode(',', $this->emSettings['filetypes_be']); + if (!in_array($fileData['extension'], $fileTypes, true)) { $enable = false; } } @@ -118,14 +126,19 @@ public function preGeneratePublicUrl($t, $driver, $resourceObject, $relativeToCu $publicUrl = $driver->getPublicUrl($fileData['identifier']); $absolutePathToContainingFolder = PathUtility::dirname(Environment::getPublicPath() . '/' . $publicUrl); $pathPart = PathUtility::getRelativePathTo($absolutePathToContainingFolder); - $filePart = substr(Environment::getPublicPath() . '/' . $publicUrl, strlen($absolutePathToContainingFolder) + 1); + $filePart = substr(Environment::getPublicPath() . '/' . $publicUrl, + strlen($absolutePathToContainingFolder) + 1); $newPublicUrl = $pathPart . $filePart; } } } if (!empty($newPublicUrl) && !empty($fileData['modDate']) && $enable) { - $urlData['publicUrl'] = $newPublicUrl . '?v=' . $fileData['modDate']; + if (strpos($newPublicUrl, '?') === false) { + $urlData['publicUrl'] = $newPublicUrl . '?v=' . $fileData['modDate']; + } else { + $urlData['publicUrl'] = $newPublicUrl . '&v=' . $fileData['modDate']; + } } } } @@ -136,15 +149,12 @@ public function preGeneratePublicUrl($t, $driver, $resourceObject, $relativeToCu * @param File $resourceObject * @return array */ - protected function getFileData($resourceObject) + protected function getFileData($resourceObject): array { - - $fileData = array( + return [ 'identifier' => $resourceObject->getIdentifier(), 'modDate' => $resourceObject->_getPropertyRaw('modification_date'), 'extension' => $resourceObject->getExtension(), - ); - - return $fileData; + ]; } } diff --git a/Documentation/ChangeLog/Index.rst b/Documentation/ChangeLog/Index.rst index 058d382..aa5bb48 100644 --- a/Documentation/ChangeLog/Index.rst +++ b/Documentation/ChangeLog/Index.rst @@ -11,6 +11,13 @@ ChangeLog ========= +- **25.06.2020** -> 2.0.1 + + - cleaned up coding + - added check if public url still contains a parameter in uri + +----------------------------------- + - **24.06.2020** -> 2.0.0 - new version for TYPO3 9.5 and 10.4 diff --git a/Documentation/Settings.cfg b/Documentation/Settings.cfg index 11dedfa..f7d1bed 100644 --- a/Documentation/Settings.cfg +++ b/Documentation/Settings.cfg @@ -1,6 +1,6 @@ [general] project = Timestamp parameter in public file uri -release = 2.0.0 +release = 2.0.1 version = 2.0 copyright = 2020 diff --git a/composer.json b/composer.json index 571f801..365ca6e 100644 --- a/composer.json +++ b/composer.json @@ -1,13 +1,35 @@ { "name": "renolit/reint-file-timestamp", - "type": "typo3-cms-extension", - "version": "2.0.0", "description": "Timestamp parameter in public file uri", - "homepage": "https://github.com/Kephson/reint_file_timestamp", - "license": "GPL-2.0+", + "type": "typo3-cms-extension", "keywords": [ - "TYPO3 CMS" + "TYPO3", + "downloads", + "publicurl", + "url", + "uri", + "file", + "timestamp", + "caching", + "browser", + "Intranet" ], + "homepage": "https://github.com/Kephson/reint_file_timestamp", + "readme": "README.md", + "license": "GPL-2.0-only / GPL-2.0-or-later", + "authors": [ + { + "name": "Ephraim Härer", + "email": "ephraim.haerer@renolit.com", + "homepage": "https://www.renolit.com", + "role": "Developer" + } + ], + "support": { + "email": "ephraim.haerer@renolit.com", + "issues": "https://github.com/Kephson/reint_file_timestamp/issues", + "source": "https://github.com/Kephson/reint_file_timestamp/archive/master.zip" + }, "require": { "typo3/cms-core": "^9.5.17 || ^10.4.3", "php": "^7.1" diff --git a/ext_emconf.php b/ext_emconf.php index 29c1664..f015213 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -10,7 +10,7 @@ $EM_CONF[$_EXTKEY] = [ 'title' => 'Timestamp parameter in public file uri', 'description' => 'Adds a parameter with the timestamp of last change to all public file uri to prevent browser from caching the file after update.', - 'version' => '2.0.0', + 'version' => '2.0.1', 'category' => 'misc', 'constraints' => [ 'depends' => [