Skip to content
Snippets Groups Projects
Unverified Commit 6c1d2791 authored by Ole Hartwig's avatar Ole Hartwig
Browse files

feat: add ExifToolService

refs: ITZBUNDPHP-1261
parent 0b554983
No related branches found
No related tags found
No related merge requests found
<?php
declare(strict_types=1);
namespace ITZBund\GsbMetadataCleaner\Service;
use ITZBund\GsbMetadataCleaner\Service\ExifToolService;
use TYPO3\CMS\Core\Resource\Event\BeforeFileAddedEvent;
class BeforeFileAddedEventListener
{
private ExifToolService $exifToolService;
public function __construct(ExifToolService $exifToolService)
{
$this->exifToolService = $exifToolService;
}
public function __invoke(BeforeFileAddedEvent $event): void
{
$this->exifToolService->removeMetadata($event->getSourceFilePath() . $event->getFileName());
}
}
<?php
declare(strict_types=1);
namespace ITZBund\GsbMetadataCleaner\Service;
use TYPO3\CMS\Core\Utility\CommandUtility;
class ExifToolService
{
public function removeMetadata(string $filePath): void
{
$command = sprintf(
'%s -all= -copyright= -tagsFromFile @ -copyright %s',
escapeshellarg($this->getExifToolPath()),
escapeshellarg($filePath)
);
CommandUtility::exec($command);
}
public function getExifData(string $filePath): array
{
$exifData = [];
$exifToolPath = $this->getExifToolPath();
if ($exifToolPath !== '') {
$exifData = $this->getExifDataFromExifTool($exifToolPath, $filePath);
}
return $exifData;
}
protected function getExifToolPath(): string
{
$exifToolPath = '';
$exifToolPathFromSettings = $GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['gsb_metadata_cleaner']['exifToolPath'];
if ($exifToolPathFromSettings !== '') {
$exifToolPath = $exifToolPathFromSettings;
}
return $exifToolPath;
}
protected function getExifDataFromExifTool(string $exifToolPath, string $filePath): array
{
$exifData = [];
$exifToolCommand = $exifToolPath . ' -j -g -n -struct -charset utf8 -fast -m -q -s -t -c "%s" ' . $filePath;
$exifToolOutput = shell_exec($exifToolCommand);
if ($exifToolOutput !== null) {
$exifData = json_decode($exifToolOutput, true);
}
return $exifData;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.