Skip to content

Commit

Permalink
cleaned up coding, updated composer.json, added check if there is sti…
Browse files Browse the repository at this point in the history
…ll a parameter in url, release of version 2.0.1
  • Loading branch information
Ephraim Härer committed Jun 25, 2020
1 parent 0e27eb2 commit 3f1ec07
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
50 changes: 30 additions & 20 deletions Classes/Signal/PublicFileUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -47,7 +52,7 @@ class PublicFileUri
protected $extKey = 'reint_file_timestamp';

/**
* settings in extension manager
* settings in extension configuration
*
* @var array
*/
Expand All @@ -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)
{
Expand All @@ -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;
}
}
Expand All @@ -107,25 +115,30 @@ 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;
}
}
if ($enable) {
$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'];
}
}
}
}
Expand All @@ -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;
];
}
}
7 changes: 7 additions & 0 deletions Documentation/ChangeLog/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Settings.cfg
Original file line number Diff line number Diff line change
@@ -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

Expand Down
32 changes: 27 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"homepage": "https://www.renolit.com",
"role": "Developer"
}
],
"support": {
"email": "[email protected]",
"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"
Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down

0 comments on commit 3f1ec07

Please sign in to comment.