diff --git a/Classes/Common/AbstractDocument.php b/Classes/Common/AbstractDocument.php index 1f948e7ed..06bd0d4b3 100644 --- a/Classes/Common/AbstractDocument.php +++ b/Classes/Common/AbstractDocument.php @@ -12,6 +12,7 @@ namespace Kitodo\Dlf\Common; +use Kitodo\Dlf\Configuration\UseGroupsConfiguration; use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Log\Logger; @@ -275,12 +276,12 @@ abstract class AbstractDocument protected string $toplevelId = ''; /** - * Holds the configured useGrps as array. + * Holds the configured useGroups as array. * - * @var array * @access protected + * @var \Kitodo\Dlf\Configuration\UseGroupsConfiguration */ - protected array $useGroups = []; + protected UseGroupsConfiguration $useGroupsConfiguration; /** * @access protected @@ -619,20 +620,6 @@ public function getPhysicalPage(string $logicalPage): int return 1; } - /** - * Get the configuration for given use group. - * - * @access protected - * - * @param string $use - * - * @return array|string - */ - protected function getUseGroup(string $use) - { - return array_key_exists($use, $this->getUseGroups()) ? $this->useGroups[$use] : []; - } - /** * This determines a title for the given document * @@ -759,37 +746,6 @@ public function getStructureDepth(string $logId) return $this->getTreeDepth($this->magicGetTableOfContents(), 1, $logId); } - /** - * Get the configuration for use groups. - * - * @access protected - * - * @return array - */ - protected function getUseGroups(): array - { - if (empty($this->useGroups)) { - // Get configured USE attributes. - $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'files'); - - $configKeys = [ - 'fileGrpImages', - 'fileGrpThumbs', - 'fileGrpDownload', - 'fileGrpFulltext', - 'fileGrpAudio', - 'fileGrpScore' - ]; - - foreach ($configKeys as $key) { - if (!empty($extConf[$key])) { - $this->useGroups[$key] = GeneralUtility::trimExplode(',', $extConf[$key]); - } - } - } - return $this->useGroups; - } - /** * Load XML file / IIIF resource from URL * @@ -1140,6 +1096,7 @@ protected function _setCPid(int $value): void protected function __construct(int $pid, string $location, $preloadedDocument, array $settings = []) { $this->pid = $pid; + $this->useGroupsConfiguration = UseGroupsConfiguration::getInstance(); $this->setPreloadedDocument($preloadedDocument); $this->init($location, $settings); $this->establishRecordId($pid); diff --git a/Classes/Common/FullTextReader.php b/Classes/Common/FullTextReader.php index 02a6c7661..e3f060d74 100644 --- a/Classes/Common/FullTextReader.php +++ b/Classes/Common/FullTextReader.php @@ -58,13 +58,13 @@ public function getFromXml(string $id, array $fileLocations, $physicalStructureN { $fullText = ''; - $fileGrpsFulltext = $this->getFullTextFileGroups(); + $useGroupsFulltext = $this->getFullTextUseGroups(); $textFormat = ""; if (!empty($physicalStructureNode)) { - while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { - if (!empty($physicalStructureNode['files'][$fileGrpFulltext])) { + while ($useGroupFulltext = array_shift($useGroupsFulltext)) { + if (!empty($physicalStructureNode['files'][$useGroupFulltext])) { // Get full text file. - $fileContent = GeneralUtility::getUrl($fileLocations[$fileGrpFulltext]); + $fileContent = GeneralUtility::getUrl($fileLocations[$useGroupFulltext]); if ($fileContent !== false) { $textFormat = $this->getTextFormat($fileContent); } else { @@ -128,10 +128,10 @@ private function getRawTextFromClass(string $fileContent, string $textFormat): s * * @return array */ - private function getFullTextFileGroups(): array + private function getFullTextUseGroups(): array { $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf', 'files'); - return GeneralUtility::trimExplode(',', $extConf['fileGrpFulltext']); + return GeneralUtility::trimExplode(',', $extConf['useGroupsFulltext']); } /** diff --git a/Classes/Common/IiifManifest.php b/Classes/Common/IiifManifest.php index 44e245d4b..48db490e1 100644 --- a/Classes/Common/IiifManifest.php +++ b/Classes/Common/IiifManifest.php @@ -223,8 +223,8 @@ protected function magicGetPhysicalStructure(): array $this->setFileUseDownload($iiifId, $this->iiif); $this->setFileUseFulltext($iiifId, $this->iiif); - $fileUseThumbs = $this->getUseGroup('fileGrpThumbs'); - $fileUses = $this->getUseGroup('fileGrpImages'); + $fileUseThumbs = $this->useGroupsConfiguration-> getThumbnail(); + $fileUses = $this->useGroupsConfiguration-> getImage(); if (!empty($this->iiif->getDefaultCanvases())) { // canvases have not order property, but the context defines canveses as @list with a specific order, so we can provide an alternative @@ -697,16 +697,15 @@ public function getFullText(string $id): string // Load physical structure ... $this->magicGetPhysicalStructure(); // ... and extension configuration. - $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey); - $fileGrpsFulltext = $this->getUseGroup('fileGrpFulltext'); + $useGroups = $this->useGroupsConfiguration->getFulltext(); $physicalStructureNode = $this->physicalStructureInfo[$id]; if (!empty($physicalStructureNode)) { - while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { - if (!empty($physicalStructureNode['files'][$fileGrpFulltext])) { + while ($useGroup = array_shift($useGroups)) { + if (!empty($physicalStructureNode['files'][$useGroup])) { $rawText = GeneralUtility::makeInstance(FullTextReader::class, $this->formats)->getFromXml( $id, - [$fileGrpFulltext => $this->getFileLocation($physicalStructureNode['files'][$fileGrpFulltext])], + [$useGroup => $this->getFileLocation($physicalStructureNode['files'][$useGroup])], $physicalStructureNode ); break; @@ -908,12 +907,12 @@ private function getIndexAnnotations(): int */ private function setFileUseDownload(string $iiifId, $iiif): void { - $fileUseDownload = $this->getUseGroup('fileGrpDownload'); + $useGroups = $this->useGroupsConfiguration->getDownload(); - if (!empty($fileUseDownload)) { + if (!empty($useGroups)) { $docPdfRendering = $iiif->getRenderingUrlsForFormat('application/pdf'); if (!empty($docPdfRendering)) { - $this->physicalStructureInfo[$iiifId]['files'][$fileUseDownload[0]] = $docPdfRendering[0]; + $this->physicalStructureInfo[$iiifId]['files'][$useGroups[0]] = $docPdfRendering[0]; } } } @@ -930,16 +929,16 @@ private function setFileUseDownload(string $iiifId, $iiif): void */ private function setFileUseFulltext(string $iiifId, $iiif): void { - $fileUseFulltext = $this->getUseGroup('fileGrpFulltext'); + $useGroups = $this->useGroupsConfiguration->getFulltext(); - if (!empty($fileUseFulltext)) { + if (!empty($useGroups)) { $alto = $iiif->getSeeAlsoUrlsForFormat('application/alto+xml'); if (empty($alto)) { $alto = $iiif->getSeeAlsoUrlsForProfile('http://www.loc.gov/standards/alto/', true); } if (!empty($alto)) { $this->mimeTypes[$alto[0]] = 'application/alto+xml'; - $this->physicalStructureInfo[$iiifId]['files'][$fileUseFulltext[0]] = $alto[0]; + $this->physicalStructureInfo[$iiifId]['files'][$useGroups[0]] = $alto[0]; $this->hasFulltext = true; $this->hasFulltextSet = true; } diff --git a/Classes/Common/Indexer.php b/Classes/Common/Indexer.php index 98d9bc92f..3ab9638e0 100644 --- a/Classes/Common/Indexer.php +++ b/Classes/Common/Indexer.php @@ -439,10 +439,10 @@ protected static function processPhysical(Document $document, int $page, array $ $updateQuery = self::$solr->service->createUpdate(); $solrDoc = self::getSolrDocument($updateQuery, $document, $physicalUnit, $fullText); $solrDoc->setField('page', $page); - $fileGrpsThumb = GeneralUtility::trimExplode(',', $extConf['fileGrpThumbs']); - while ($fileGrpThumb = array_shift($fileGrpsThumb)) { - if (!empty($physicalUnit['files'][$fileGrpThumb])) { - $solrDoc->setField('thumbnail', $doc->getFileLocation($physicalUnit['files'][$fileGrpThumb])); + $useGroupsThumbnail = GeneralUtility::trimExplode(',', $extConf['Thumbnail']); + while ($useGroupThumbnail = array_shift($useGroupsThumbnail)) { + if (!empty($physicalUnit['files'][$useGroupThumbnail])) { + $solrDoc->setField('thumbnail', $doc->getFileLocation($physicalUnit['files'][$useGroupThumbnail])); break; } } diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index 043206ecf..bce66c8bd 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -23,7 +23,6 @@ use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction; use TYPO3\CMS\Core\Log\LogManager; use TYPO3\CMS\Core\Utility\GeneralUtility; -use Ubl\Iiif\Tools\IiifHelper; use Ubl\Iiif\Services\AbstractImageService; /** @@ -480,22 +479,17 @@ private function getPage(array &$details, ?SimpleXMLElement $metsPointers): void */ private function getThumbnail(string $id = '') { - $fileGrpsThumb = $this->getUseGroup('fileGrpThumbs'); - + $useGroups = $this->useGroupsConfiguration->getThumbnail(); $thumbnail = null; if (!empty($this->physicalStructure)) { // There is a physical structure (no anchor or year mets). - while ($fileGrpThumb = array_shift($fileGrpsThumb)) { + while ($useGroup = array_shift($useGroups) && $thumbnail == null) { if (empty($id)) { - $thumbnail = $this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb] ?? null; + $thumbnail = $this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$useGroup] ?? null; } else { $parentId = $this->smLinks['l2p'][$id][0] ?? null; - $thumbnail = $this->physicalStructureInfo[$parentId]['files'][$fileGrpThumb] ?? null; - } - - if (!empty($thumbnail)) { - break; + $thumbnail = $this->physicalStructureInfo[$parentId]['files'][$useGroup] ?? null; } } } @@ -1125,15 +1119,13 @@ public function getFullText(string $id): string $this->ensureHasFulltextIsSet(); if ($this->hasFulltext) { - $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'files'); - $fileGrpsFulltext = GeneralUtility::trimExplode(',', $extConf['fileGrpFulltext']); - + $useGroups = $this->useGroupsConfiguration->getFulltext(); $physicalStructureNode = $this->physicalStructureInfo[$id]; - $fileLocations = []; + if (!empty($physicalStructureNode)) { - while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { - $fileLocations[$fileGrpFulltext] = $this->getFileLocation($physicalStructureNode['files'][$fileGrpFulltext]); + while ($useGroup = array_shift($useGroups)) { + $fileLocations[$useGroup] = $this->getFileLocation($physicalStructureNode['files'][$useGroup]); } } @@ -1206,8 +1198,8 @@ protected function ensureHasFulltextIsSet(): void { // Are there any fulltext files available? if ( - !empty($this->getUseGroup('fileGrpFulltext')) - && array_intersect($this->getUseGroup('fileGrpFulltext'), $this->fileGrps) !== [] + !empty($this->useGroupsConfiguration->getFulltext()) + && array_intersect($this->useGroupsConfiguration->getFulltext(), $this->fileGrps) !== [] ) { $this->hasFulltext = true; } @@ -1351,7 +1343,7 @@ protected function processMdSec(SimpleXMLElement $element): ?array protected function magicGetFileGrps(): array { if (!$this->fileGrpsLoaded) { - foreach (array_values($this->getUseGroups()) as $useGroups) { + foreach (array_values($this->useGroupsConfiguration->get()) as $useGroups) { foreach ($useGroups as $useGroup) { // Perform XPath query for each configured USE attribute $fileGrps = $this->mets->xpath("./mets:fileSec/mets:fileGrp[@USE='$useGroup']"); @@ -1564,7 +1556,7 @@ protected function magicGetThumbnail(): string return $this->thumbnail; } - if (empty($this->getUseGroup('fileGrpThumbs'))) { + if (empty($this->useGroupsConfiguration->getThumbnail())) { $this->logger->warning('No fileGrp for thumbnails specified'); $this->thumbnailLoaded = true; return $this->thumbnail; @@ -1603,17 +1595,17 @@ protected function magicGetThumbnail(): string // Load smLinks. $this->magicGetSmLinks(); // Get thumbnail location. - $fileGrpsThumb = $this->getUseGroup('fileGrpThumbs'); - while ($fileGrpThumb = array_shift($fileGrpsThumb)) { + $useGroups = $this->useGroupsConfiguration->getThumbnail(); + while ($useGroup = array_shift($useGroups)) { if ( $this->magicGetPhysicalStructure() && !empty($this->smLinks['l2p'][$strctId]) - && !empty($this->physicalStructureInfo[$this->smLinks['l2p'][$strctId][0]]['files'][$fileGrpThumb]) + && !empty($this->physicalStructureInfo[$this->smLinks['l2p'][$strctId][0]]['files'][$useGroup]) ) { - $this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->smLinks['l2p'][$strctId][0]]['files'][$fileGrpThumb]); + $this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->smLinks['l2p'][$strctId][0]]['files'][$useGroup]); break; - } elseif (!empty($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb])) { - $this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$fileGrpThumb]); + } elseif (!empty($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$useGroup])) { + $this->thumbnail = $this->getFileLocation($this->physicalStructureInfo[$this->physicalStructure[1]]['files'][$useGroup]); break; } } diff --git a/Classes/Configuration/UseGroupsConfiguration.php b/Classes/Configuration/UseGroupsConfiguration.php new file mode 100644 index 000000000..d31993cc2 --- /dev/null +++ b/Classes/Configuration/UseGroupsConfiguration.php @@ -0,0 +1,179 @@ + + * + * This file is part of the Kitodo and TYPO3 projects. + * + * @license GNU General Public License version 3 or later. + * For the full copyright and license information, please read the + * LICENSE.txt file that was distributed with this source code. + */ + +namespace Kitodo\Dlf\Configuration; + +use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; +use TYPO3\CMS\Core\Utility\GeneralUtility; + +/** + * Undocumented class + */ +class UseGroupsConfiguration +{ + + /** + * @access private + * @var ?UseGroupsConfiguration The instance of singleton. + */ + private static $instance = null; + + /** + * @access private + * @var array The array of configured USE groups. + */ + private array $useGroups = []; + + /** + * Constructor for singleton. + * + * @access private + * + * @return void + */ + private function __construct() + { + // Get configured USE attributes. + $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('dlf', 'files'); + + $configKeys = [ + 'useGroupsImage', + 'useGroupsThumbs', + 'useGroupsDownload', + 'useGroupsFulltext', + 'useGroupsAudio', + 'useGroupsScore' + ]; + + foreach ($configKeys as $key) { + if (!empty($extConf[$key])) { + $this->useGroups[$key] = GeneralUtility::trimExplode(',', $extConf[$key]); + } + } + } + + /** + * Get the instance of singleton. + * + * @access public + * + * @return UseGroupsConfiguration + */ + public static function getInstance(): UseGroupsConfiguration + { + if (self::$instance == null) { + self::$instance = new UseGroupsConfiguration(); + } + + return self::$instance; + } + + /** + * Get the configuration for 'Audio' use groups type. + * + * @access public + * + * @return array + */ + public function getAudio(): array + { + return $this->getByType('Audio'); + } + + /** + * Get the configuration for 'Download' use groups type. + * + * @access public + * + * @return array + */ + public function getDownload(): array + { + return $this->getByType('Download'); + } + + /** + * Get the configuration for 'Fulltext' use groups type. + * + * @access public + * + * @return array + */ + public function getFulltext(): array + { + return $this->getByType('Fulltext'); + } + + /** + * Get the configuration for 'Image' use groups type. + * + * @access public + * + * @return array + */ + public function getImage(): array + { + return $this->getByType('Image'); + } + + /** + * Get the configuration for 'Score' use groups type. + * + * @access public + * + * @return array + */ + public function getScore(): array + { + return $this->getByType('Score'); + } + + /** + * Get the configuration for 'Thumbnail' use groups type. + * + * @access public + * + * @return array + */ + public function getThumbnail(): array + { + return $this->getByType('Thumbnail'); + } + + /** + * Get the configuration for use groups. + * + * @access public + * + * @return array + */ + public function get(): array + { + return $this->useGroups; + } + + /** + * Get the configuration for given use groups type. + * + * @access private + * + * @param string $useType possible values: 'Audio', 'Download', 'Fulltext', 'Image', 'Score', 'Thumbnail' + * + * @return array + */ + //TODO: replace $useType with enum after dropping PHP 7.x support + private function getByType(string $useType): array + { + $useType = 'useGroups' . ucfirst($useType); + return array_key_exists($useType, $this->useGroups) ? $this->useGroups[$useType] : []; + } +} diff --git a/Classes/Controller/AbstractController.php b/Classes/Controller/AbstractController.php index f1f5112f9..e2bb4111b 100644 --- a/Classes/Controller/AbstractController.php +++ b/Classes/Controller/AbstractController.php @@ -13,6 +13,7 @@ use Kitodo\Dlf\Common\AbstractDocument; use Kitodo\Dlf\Common\Helper; +use Kitodo\Dlf\Configuration\UseGroupsConfiguration; use Kitodo\Dlf\Domain\Model\Document; use Kitodo\Dlf\Domain\Repository\DocumentRepository; use Psr\Http\Message\ResponseInterface; @@ -97,6 +98,14 @@ public function injectDocumentRepository(DocumentRepository $documentRepository) */ protected int $pageUid; + /** + * Holds the configured useGroups as array. + * + * @access protected + * @var \Kitodo\Dlf\Configuration\UseGroupsConfiguration + */ + protected UseGroupsConfiguration $useGroupsConfiguration; + /** * Initialize the plugin controller * @@ -203,6 +212,18 @@ protected function configureProxyUrl(string &$url): void ->build(); } + /** + * Checks if doc of its fulltext is missing or is empty (no pages) + * + * @access protected + * + * @return bool + */ + protected function isDocOrFulltextMissingOrEmpty(): bool + { + return $this->isDocMissingOrEmpty() || empty($this->useGroupsConfiguration->getFulltext()); + } + /** * Checks if doc is missing or is empty (no pages) * diff --git a/Classes/Controller/AudioPlayerController.php b/Classes/Controller/AudioPlayerController.php index 7688ce255..0bda30c13 100644 --- a/Classes/Controller/AudioPlayerController.php +++ b/Classes/Controller/AudioPlayerController.php @@ -86,11 +86,11 @@ public function mainAction(): ResponseInterface $this->setDefaultPage(); // Check if there are any audio files available. - $fileGrpsAudio = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpAudio']); - while ($fileGrpAudio = array_shift($fileGrpsAudio)) { + $useGroups = $this->useGroupsConfiguration->getAudio(); + while ($useGroup = array_shift($useGroups)) { $physicalStructureInfo = $this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$this->requestData['page'] ?? 0]]; - if (array_key_exists($fileGrpAudio, $physicalStructureInfo['files'])) { - $fileId = $physicalStructureInfo['files'][$fileGrpAudio]; + if (array_key_exists($useGroup, $physicalStructureInfo['files'])) { + $fileId = $physicalStructureInfo['files'][$useGroup]; if (!empty($fileId)) { // Get audio data. $file = $this->document->getCurrentDocument()->getFileInfo($fileId); diff --git a/Classes/Controller/PageGridController.php b/Classes/Controller/PageGridController.php index ce7488afd..d85eda0b2 100644 --- a/Classes/Controller/PageGridController.php +++ b/Classes/Controller/PageGridController.php @@ -38,7 +38,7 @@ public function mainAction(): ResponseInterface $this->loadDocument(); if ( $this->isDocMissingOrEmpty() - || empty($this->extConf['files']['fileGrpThumbs']) + || empty($this->useGroupsConfiguration->getThumbnail()) ) { // Quit without doing anything if required variables are not set. return $this->htmlResponse(); @@ -92,12 +92,12 @@ protected function getEntry(int $number): array $entry['thumbnail'] = ''; // Get thumbnail or placeholder. - $fileGrpsThumb = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpThumbs']); + $useGroups = $this->useGroupsConfiguration->getThumbnail(); if (is_array($this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$number]]['files'])) { - if (array_intersect($fileGrpsThumb, array_keys($this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$number]]['files'])) !== []) { - while ($fileGrpThumb = array_shift($fileGrpsThumb)) { - if (!empty($this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$number]]['files'][$fileGrpThumb])) { - $entry['thumbnail'] = $this->document->getCurrentDocument()->getFileLocation($this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$number]]['files'][$fileGrpThumb]); + if (array_intersect($useGroups, array_keys($this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$number]]['files'])) !== []) { + while ($useGroup = array_shift($useGroups)) { + if (!empty($this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$number]]['files'][$useGroup])) { + $entry['thumbnail'] = $this->document->getCurrentDocument()->getFileLocation($this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$number]]['files'][$useGroup]); break; } } diff --git a/Classes/Controller/PageViewController.php b/Classes/Controller/PageViewController.php index 1dd6bd808..fdf822256 100644 --- a/Classes/Controller/PageViewController.php +++ b/Classes/Controller/PageViewController.php @@ -383,14 +383,14 @@ protected function getScore(int $page, MetsDocument $specificDoc = null) $doc = $this->document->getCurrentDocument(); } if ($doc instanceof MetsDocument) { - $fileGrpsScores = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpScore']); + $useGroups = $this->useGroupsConfiguration->getScore();; $pageId = $doc->physicalStructure[$page]; $files = $doc->physicalStructureInfo[$pageId]['files'] ?? []; - foreach ($fileGrpsScores as $fileGrpScore) { - if (isset($files[$fileGrpScore])) { - $loc = $files[$fileGrpScore]; + foreach ($useGroups as $useGroup) { + if (isset($files[$useGroup])) { + $loc = $files[$useGroup]; break; } } @@ -419,7 +419,7 @@ protected function getScore(int $page, MetsDocument $specificDoc = null) } if (empty($score)) { - $this->logger->notice('No score file found for page "' . $page . '" in fileGrps "' . ($this->extConf['files']['fileGrpScore'] ?? '') . '"'); + $this->logger->notice('No score file found for page "' . $page . '" in fileGrps "' . ($this->extConf['files']['useGroupScore'] ?? '') . '"'); } return $score; } @@ -437,12 +437,12 @@ protected function getFulltext(int $page): array { $fulltext = []; // Get fulltext link. - $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpFulltext']); - while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { + $useGroups = $this->useGroupsConfiguration->getFulltext(); + while ($useGroup = array_shift($useGroups)) { $physicalStructureInfo = $this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$page]]; $files = $physicalStructureInfo['files']; - if (!empty($files[$fileGrpFulltext])) { - $file = $this->document->getCurrentDocument()->getFileInfo($files[$fileGrpFulltext]); + if (!empty($files[$useGroup])) { + $file = $this->document->getCurrentDocument()->getFileInfo($files[$useGroup]); $fulltext['url'] = $file['location']; if ($this->settings['useInternalProxy']) { $this->configureProxyUrl($fulltext['url']); @@ -450,11 +450,11 @@ protected function getFulltext(int $page): array $fulltext['mimetype'] = $file['mimeType']; break; } else { - $this->logger->notice('No full-text file found for page "' . $page . '" in fileGrp "' . $fileGrpFulltext . '"'); + $this->logger->notice('No full-text file found for page "' . $page . '" in fileGrp "' . $useGroup . '"'); } } if (empty($fulltext)) { - $this->logger->notice('No full-text file found for page "' . $page . '" in fileGrps "' . $this->extConf['files']['fileGrpFulltext'] . '"'); + $this->logger->notice('No full-text file found for page "' . $page . '" in fileGrps "' . ($this->extConf['files']['useGroupFulltext'] ?? '') . '"'); } return $fulltext; } @@ -631,11 +631,11 @@ protected function getImage(int $page, MetsDocument $specificDoc = null): array { $image = []; // Get @USE value of METS fileGrp. - $fileGrpsImages = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpImages']); + $useGroups = $this->useGroupsConfiguration->getImage(); - foreach ($fileGrpsImages as $fileGrpImages) { + foreach ($useGroups as $useGroup) { // Get file info for the specific page and file group - $file = $this->fetchFileInfo($page, $fileGrpImages, $specificDoc); + $file = $this->fetchFileInfo($page, $useGroup, $specificDoc); if ($file && Helper::filterFilesByMimeType($file, ['image', 'application'], ['IIIF', 'IIP', 'ZOOMIFY'], 'mimeType')) { $image['url'] = $file['location']; $image['mimetype'] = $file['mimeType']; @@ -647,12 +647,12 @@ protected function getImage(int $page, MetsDocument $specificDoc = null): array } break; } else { - $this->logger->notice('No image file found for page "' . $page . '" in fileGrp "' . $fileGrpImages . '"'); + $this->logger->notice('No image file found for page "' . $page . '" in fileGrp "' . $useGroup . '"'); } } if (empty($image)) { - $this->logger->warning('No image file found for page "' . $page . '" in fileGrps "' . $this->extConf['files']['fileGrpImages'] . '"'); + $this->logger->warning('No image file found for page "' . $page . '" in fileGrps "' . ($this->extConf['files']['useGroupImage'] ?? '') . '"'); } return $image; diff --git a/Classes/Controller/ToolboxController.php b/Classes/Controller/ToolboxController.php index cb93c6d62..0bf9c8188 100644 --- a/Classes/Controller/ToolboxController.php +++ b/Classes/Controller/ToolboxController.php @@ -142,7 +142,7 @@ private function renderToolByName(string $tool): void public function getImage(int $page): array { // Get @USE value of METS fileGroup. - $image = $this->getFile($page, GeneralUtility::trimExplode(',', $this->settings['fileGrpsImageDownload'])); + $image = $this->getFile($page, $this->useGroupsConfiguration->getImage()); switch ($image['mimetype']) { case 'image/jpeg': $image['mimetypeLabel'] = ' (JPG)'; @@ -194,10 +194,7 @@ private function renderAnnotationTool(): void */ private function renderFulltextDownloadTool(): void { - if ( - $this->isDocMissingOrEmpty() - || empty($this->extConf['files']['fileGrpFulltext']) - ) { + if ($this->isDocOrFulltextMissingOrEmpty()) { // Quit without doing anything if required variables are not set. return; } @@ -218,10 +215,7 @@ private function renderFulltextDownloadTool(): void */ private function renderFulltextTool(): void { - if ( - $this->isDocMissingOrEmpty() - || empty($this->extConf['files']['fileGrpFulltext']) - ) { + if ($this->isDocOrFulltextMissingOrEmpty()) { // Quit without doing anything if required variables are not set. return; } @@ -245,7 +239,7 @@ public function renderScoreTool() { if ( $this->isDocMissingOrEmpty() - || empty($this->extConf['files']['fileGrpScore']) + || empty($this->useGroupsConfiguration->getScore()) ) { // Quit without doing anything if required variables are not set. return; @@ -257,10 +251,10 @@ public function renderScoreTool() $currentPhysPage = $this->document->getCurrentDocument()->physicalStructure[1]; } - $fileGrpsScores = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpScore']); - foreach ($fileGrpsScores as $fileGrpScore) { - if ($this->document->getCurrentDocument()->physicalStructureInfo[$currentPhysPage]['files'][$fileGrpScore]) { - $scoreFile = $this->document->getCurrentDocument()->physicalStructureInfo[$currentPhysPage]['files'][$fileGrpScore]; + $useGroups = $this->useGroupsConfiguration->getScore(); + foreach ($useGroups as $useGroup) { + if ($this->document->getCurrentDocument()->physicalStructureInfo[$currentPhysPage]['files'][$useGroup]) { + $scoreFile = $this->document->getCurrentDocument()->physicalStructureInfo[$currentPhysPage]['files'][$useGroup]; } } if (!empty($scoreFile)) { @@ -283,7 +277,7 @@ private function renderImageDownloadTool(): void { if ( $this->isDocMissingOrEmpty() - || empty($this->settings['fileGrpsImageDownload']) + || empty($this->useGroupsConfiguration->getImage()) ) { // Quit without doing anything if required variables are not set. return; @@ -362,6 +356,7 @@ private function renderImageManipulationTool(): void */ private function renderModelDownloadTool(): void { + // TODO: missing fileGrpsModelDownload, should be added to ext config as useGroupsModelDownload if ( $this->isDocMissingOrEmpty() || empty($this->settings['fileGrpsModelDownload']) @@ -389,7 +384,7 @@ private function renderPdfDownloadTool(): void { if ( $this->isDocMissingOrEmpty() - || empty($this->extConf['files']['fileGrpDownload']) + || empty($this->useGroupsConfiguration->getDownload()) ) { // Quit without doing anything if required variables are not set. return; @@ -416,14 +411,14 @@ private function getPageLink(): array $secondPageLink = ''; $pageLinkArray = []; $pageNumber = $this->requestData['page'] ?? 0; - $fileGrpsDownload = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpDownload']); + $useGroups = $this->useGroupsConfiguration->getDownload(); // Get image link. - while ($fileGrpDownload = array_shift($fileGrpsDownload)) { - $firstFileGroupDownload = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$pageNumber]]['files'][$fileGrpDownload] ?? []; + while ($useGroup = array_shift($useGroups)) { + $firstFileGroupDownload = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$pageNumber]]['files'][$useGroup] ?? []; if (!empty($firstFileGroupDownload)) { $firstPageLink = $this->currentDocument->getFileLocation($firstFileGroupDownload); // Get second page, too, if double page view is activated. - $secondFileGroupDownload = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$pageNumber + 1]]['files'][$fileGrpDownload]; + $secondFileGroupDownload = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$pageNumber + 1]]['files'][$useGroup]; if ( $this->requestData['double'] && $pageNumber < $this->currentDocument->numPages @@ -438,7 +433,7 @@ private function getPageLink(): array empty($firstPageLink) && empty($secondPageLink) ) { - $this->logger->warning('File not found in fileGrps "' . $this->extConf['files']['fileGrpDownload'] . '"'); + $this->logger->warning('File not found in fileGrps "' . $this->extConf['files']['useGroupsDownload'] . '"'); } if (!empty($firstPageLink)) { @@ -460,23 +455,23 @@ private function getPageLink(): array private function getWorkLink(): string { $workLink = ''; - $fileGrpsDownload = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpDownload']); + $useGroups = $this->useGroupsConfiguration->getDownload(); // Get work link. - while ($fileGrpDownload = array_shift($fileGrpsDownload)) { - $fileGroupDownload = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[0]]['files'][$fileGrpDownload] ?? []; + while ($useGroup = array_shift($useGroups)) { + $fileGroupDownload = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[0]]['files'][$useGroup] ?? []; if (!empty($fileGroupDownload)) { $workLink = $this->currentDocument->getFileLocation($fileGroupDownload); break; } else { $details = $this->currentDocument->getLogicalStructure($this->currentDocument->toplevelId); - if (!empty($details['files'][$fileGrpDownload])) { - $workLink = $this->currentDocument->getFileLocation($details['files'][$fileGrpDownload]); + if (!empty($details['files'][$useGroup])) { + $workLink = $this->currentDocument->getFileLocation($details['files'][$useGroup]); break; } } } if (empty($workLink)) { - $this->logger->warning('File not found in fileGrps "' . $this->extConf['files']['fileGrpDownload'] . '"'); + $this->logger->warning('File not found in fileGrps "' . $this->extConf['files']['useGroupsDownload'] . '"'); } return $workLink; } @@ -492,8 +487,7 @@ private function getWorkLink(): string private function renderSearchInDocumentTool(): void { if ( - $this->isDocMissingOrEmpty() - || empty($this->extConf['files']['fileGrpFulltext']) + $this->isDocOrFulltextMissingOrEmpty() || empty($this->settings['solrcore']) ) { // Quit without doing anything if required variables are not set. @@ -588,11 +582,11 @@ private function getEncryptedCoreName(): string */ private function isFullTextEmpty(): bool { - $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpFulltext']); - while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { + $useGroups = $this->useGroupsConfiguration->getFulltext(); + while ($useGroup = array_shift($useGroups)) { if (isset($this->requestData['page'])) { $files = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$this->requestData['page']]]['files']; - if (!empty($files[$fileGrpFulltext])) { + if (!empty($files[$useGroup])) { return false; } } diff --git a/Configuration/FlexForms/Toolbox.xml b/Configuration/FlexForms/Toolbox.xml index 55b71c82a..a11916c73 100644 --- a/Configuration/FlexForms/Toolbox.xml +++ b/Configuration/FlexForms/Toolbox.xml @@ -52,18 +52,6 @@ - - - 1 - - - input - 30 - 30 - DEFAULT,MAX - - - diff --git a/Documentation/Plugins/Index.rst b/Documentation/Plugins/Index.rst index b2b898218..1d24f4495 100644 --- a/Documentation/Plugins/Index.rst +++ b/Documentation/Plugins/Index.rst @@ -974,12 +974,6 @@ Toolbox :ref:`t3tsref:data-type-integer` :Default: - - :Property: - fileGrpsImageDownload - :Data Type: - `t3tsref:data-type-list` - :Default: - MIN,DEFAULT,MAX Fulltext Tool ^^^^^^^^^^^^^ diff --git a/Tests/Functional/FunctionalTestCase.php b/Tests/Functional/FunctionalTestCase.php index 2a818f1b5..26c06b0f4 100644 --- a/Tests/Functional/FunctionalTestCase.php +++ b/Tests/Functional/FunctionalTestCase.php @@ -128,11 +128,11 @@ protected function getDlfConfiguration() 'requiredMetadataFields' => 'document_format' ], 'files' => [ - 'fileGrpImages' => 'DEFAULT,MAX', - 'fileGrpThumbs' => 'THUMBS', - 'fileGrpDownload' => 'DOWNLOAD', - 'fileGrpFulltext' => 'FULLTEXT', - 'fileGrpAudio' => 'AUDIO' + 'useGroupsImage' => 'DEFAULT,MAX', + 'useGroupsThumbnail' => 'THUMBS', + 'useGroupsDownload' => 'DOWNLOAD', + 'useGroupsFulltext' => 'FULLTEXT', + 'useGroupsAudio' => 'AUDIO' ], 'solr' => [ 'host' => getenv('dlfTestingSolrHost'), diff --git a/ext_conf_template.txt b/ext_conf_template.txt index 4813f62e5..18a2fa79f 100644 --- a/ext_conf_template.txt +++ b/ext_conf_template.txt @@ -18,18 +18,18 @@ general.unhideOnIndex = 0 general.useExternalApisForMetadata = 0 # cat=General; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.general.requiredMetadataFields general.requiredMetadataFields = document_format,record_id -# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.fileGrpImages -files.fileGrpImages = DEFAULT,MAX -# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.fileGrpThumbs -files.fileGrpThumbs = THUMBS -# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.fileGrpDownload -files.fileGrpDownload = DOWNLOAD -# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.fileGrpFulltext -files.fileGrpFulltext = FULLTEXT -# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.fileGrpAudio -files.fileGrpAudio = AUDIO -# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.fileGrpScore -files.fileGrpScore = SCORE +# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.useGroupsAudio +files.useGroupsAudio = AUDIO +# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.useGroupsImage +files.useGroupsImage = DEFAULT,MAX +# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.useGroupsThumbnail +files.useGroupsThumbnail = THUMBS +# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.useGroupsDownload +files.useGroupsDownload = DOWNLOAD +# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.useGroupsFulltext +files.useGroupsFulltext = FULLTEXT +# cat=Files; type=string; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.files.useGroupsScore +files.useGroupsScore = SCORE # cat=IIIF; type=boolean; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.iiif.indexAnnotations iiif.indexAnnotations = 0 # cat=IIIF; type=int[1-2000]; label=LLL:EXT:dlf/Resources/Private/Language/locallang_labels.xlf:config.iiif.thumbnailWidth