From 5c4c90334505c5b0e44c9a72714cd3e1e01a3b77 Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Mon, 21 Oct 2024 18:14:36 +0200 Subject: [PATCH] [MAINTENANCE] Cleanup and improvements regarding TYPO3 12 update (#1362) Co-authored-by: Sebastian Meyer --- .gitignore | 2 + Build/Documentation/.gitignore | 2 - Build/Documentation/conf.py | 35 ------------ Build/Documentation/dbdocs/Generator.php | 1 - Build/Documentation/sphinx.sh | 55 ------------------- Classes/Common/MetsDocument.php | 7 +-- Classes/Controller/AbstractController.php | 13 +++-- Classes/Controller/AudioPlayerController.php | 20 ++++--- Classes/Controller/MetadataController.php | 12 ++-- Classes/Controller/PageViewController.php | 28 +++++----- .../Controller/TableOfContentsController.php | 6 +- Classes/Controller/ToolboxController.php | 15 +++-- .../Private/Partials/Lists/Pagination.html | 10 ++-- Resources/Private/Templates/Feeds/Main.xml | 2 +- 14 files changed, 64 insertions(+), 144 deletions(-) delete mode 100644 Build/Documentation/.gitignore delete mode 100644 Build/Documentation/conf.py delete mode 100755 Build/Documentation/sphinx.sh diff --git a/.gitignore b/.gitignore index 9153c9038f..11b74dabf6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ /var/ /vendor/ .DS_Store +_build +venv diff --git a/Build/Documentation/.gitignore b/Build/Documentation/.gitignore deleted file mode 100644 index 703312362f..0000000000 --- a/Build/Documentation/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -_build -venv diff --git a/Build/Documentation/conf.py b/Build/Documentation/conf.py deleted file mode 100644 index 1a0a918f87..0000000000 --- a/Build/Documentation/conf.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -Basic Sphinx configuration for TYPO3 theme. Uses configuration from Settings.cfg. -""" - -import ConfigParser - -settings = globals() -settings['general'] = settings - -config = ConfigParser.RawConfigParser() -config.read('../../Documentation/Settings.cfg') - -for section in config.sections(): - target = settings.setdefault(section, {}) - - for (name, value) in config.items(section): - if section == 'intersphinx_mapping': - target[name] = (value, None) - else: - target[name] = value - -extensions = [ - 'sphinx_typo3_theme', - 'sphinx.ext.intersphinx', - 'sphinxcontrib.t3fieldlisttable' -] - -html_theme = 'sphinx_typo3_theme' - -# The TYPO3 convention is to capitalize the index filename, which would require -# us to visit http://127.0.0.1:8000/Index.html. We thus add an `index.html` that -# redirects to `Index.html`. -master_doc = 'Index' -html_extra_path = ['index.html'] -exclude_patterns = [] diff --git a/Build/Documentation/dbdocs/Generator.php b/Build/Documentation/dbdocs/Generator.php index c5a18888ce..b42a016be9 100644 --- a/Build/Documentation/dbdocs/Generator.php +++ b/Build/Documentation/dbdocs/Generator.php @@ -21,7 +21,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; -use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper; /** diff --git a/Build/Documentation/sphinx.sh b/Build/Documentation/sphinx.sh deleted file mode 100755 index c8d216f876..0000000000 --- a/Build/Documentation/sphinx.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -BASE_DIR=$(dirname "$0") -VENV_DIR="$BASE_DIR/venv" -DOCS_DIR="$BASE_DIR/../../Documentation" - -function usage() -{ - cat << EOF -Usage: sphinx.sh [options] - -Commands: - i, install Install Sphinx in a virtualenv - s, serve Serve documentation. Options are forwarded to sphinx-autobuild. - -H Server host - -p Server port - -a Write all files (from sphinx-build) - -E Don't use a saved environment (from sphinx-build) -EOF - - exit -} - -function use_sphinx() -{ - source "$VENV_DIR/bin/activate" -} - -COMMAND=$1 -shift - -case $COMMAND in - i|install) - if [ ! -e "$VENV_DIR" ]; then - # t3fieldlisttable doesn't seem to work with Python 3 - virtualenv -p python2 "$VENV_DIR" - fi - - use_sphinx - - pip install sphinx-autobuild - pip install t3fieldlisttable - pip install sphinx_typo3_theme - - ;; - - s|serve) - use_sphinx - sphinx-autobuild -c "$BASE_DIR" "$@" "$DOCS_DIR" "$BASE_DIR/_build" - ;; - - *) - usage - ;; -esac diff --git a/Classes/Common/MetsDocument.php b/Classes/Common/MetsDocument.php index 01d1799301..a4d95c6116 100644 --- a/Classes/Common/MetsDocument.php +++ b/Classes/Common/MetsDocument.php @@ -845,9 +845,8 @@ private function setDefaultMetadataValue(array $resArray, array &$metadata): voi private function setSortableMetadataValue(array $resArray, DOMXPath $domXPath, DOMElement $domNode, array &$metadata): void { $indexName = $resArray['index_name']; - $currentMetadata = $metadata[$indexName][0]; - if (!empty($metadata[$indexName]) && $resArray['is_sortable']) { + $currentMetadata = $metadata[$indexName][0]; if ($resArray['format'] > 0 && !empty($resArray['xpath_sorting'])) { $values = $domXPath->evaluate($resArray['xpath_sorting'], $domNode); if ($values instanceof DOMNodeList && $values->length > 0) { @@ -1338,7 +1337,7 @@ protected function magicGetFileGrps(): array // Get configured USE attributes. $extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey, 'files'); $useGrps = GeneralUtility::trimExplode(',', $extConf['fileGrpImages']); - + $configKeys = [ 'fileGrpThumbs', 'fileGrpDownload', @@ -1346,7 +1345,7 @@ protected function magicGetFileGrps(): array 'fileGrpAudio', 'fileGrpScore' ]; - + foreach ($configKeys as $key) { if (!empty($extConf[$key])) { $useGrps = array_merge($useGrps, GeneralUtility::trimExplode(',', $extConf[$key])); diff --git a/Classes/Controller/AbstractController.php b/Classes/Controller/AbstractController.php index 9851ec207e..809157e04f 100644 --- a/Classes/Controller/AbstractController.php +++ b/Classes/Controller/AbstractController.php @@ -371,9 +371,12 @@ protected function setDefaultPage(): void // Set default values if not set. // $this->requestData['page'] may be integer or string (physical structure @ID) if ( - (int) $this->requestData['page'] > 0 - || empty($this->requestData['page']) - || is_array($this->requestData['docPage']) + isset($this->requestData['page']) + && ( + (int) $this->requestData['page'] > 0 + || empty($this->requestData['page']) + || is_array($this->requestData['docPage']) + ) ) { if (isset($this->settings['multiViewType']) && $this->document->getCurrentDocument()->tableOfContents[0]['type'] === $this->settings['multiViewType']) { $i = 0; @@ -471,7 +474,7 @@ protected function buildSimplePagination(PaginationInterface $pagination, Pagina // array with label as screen/pagination page number // and startRecordNumber for correct structure of the link //{page.label} @@ -581,7 +584,7 @@ protected function getDocumentByUrl(string $documentId) } else { $this->documentArray[] = $doc; } - if ($this->requestData['multipleSource'] && is_array($this->requestData['multipleSource'])) { + if (isset($this->requestData['multipleSource']) && is_array($this->requestData['multipleSource'])) { $i = 0; foreach ($this->requestData['multipleSource'] as $location) { $document = AbstractDocument::getInstance($location, $this->settings, true); diff --git a/Classes/Controller/AudioPlayerController.php b/Classes/Controller/AudioPlayerController.php index d78e86572c..7688ce255a 100644 --- a/Classes/Controller/AudioPlayerController.php +++ b/Classes/Controller/AudioPlayerController.php @@ -88,15 +88,17 @@ public function mainAction(): ResponseInterface // Check if there are any audio files available. $fileGrpsAudio = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpAudio']); while ($fileGrpAudio = array_shift($fileGrpsAudio)) { - $physicalStructureInfo = $this->document->getCurrentDocument()->physicalStructureInfo[$this->document->getCurrentDocument()->physicalStructure[$this->requestData['page']]]; - $fileId = $physicalStructureInfo['files'][$fileGrpAudio]; - if (!empty($fileId)) { - // Get audio data. - $file = $this->document->getCurrentDocument()->getFileInfo($fileId); - $this->audio['url'] = $file['location']; - $this->audio['label'] = $physicalStructureInfo['label']; - $this->audio['mimetype'] = $file['mimeType']; - break; + $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 (!empty($fileId)) { + // Get audio data. + $file = $this->document->getCurrentDocument()->getFileInfo($fileId); + $this->audio['url'] = $file['location']; + $this->audio['label'] = $physicalStructureInfo['label']; + $this->audio['mimetype'] = $file['mimeType']; + break; + } } } diff --git a/Classes/Controller/MetadataController.php b/Classes/Controller/MetadataController.php index 6b8abc90e0..d5354fb809 100644 --- a/Classes/Controller/MetadataController.php +++ b/Classes/Controller/MetadataController.php @@ -478,11 +478,13 @@ private function getMetadata(): array if ($this->settings['rootline'] < 2) { // Get current structure's @ID. $ids = []; - $page = $this->currentDocument->physicalStructure[$this->requestData['page']]; - if (!empty($page) && !empty($this->currentDocument->smLinks['p2l'][$page])) { - foreach ($this->currentDocument->smLinks['p2l'][$page] as $logId) { - $count = $this->currentDocument->getStructureDepth($logId); - $ids[$count][] = $logId; + if (isset($this->requestData['page'])) { + $page = $this->currentDocument->physicalStructure[$this->requestData['page']]; + if (!empty($page) && !empty($this->currentDocument->smLinks['p2l'][$page])) { + foreach ($this->currentDocument->smLinks['p2l'][$page] as $logId) { + $count = $this->currentDocument->getStructureDepth($logId); + $ids[$count][] = $logId; + } } } ksort($ids); diff --git a/Classes/Controller/PageViewController.php b/Classes/Controller/PageViewController.php index b6f27563b4..1dd6bd808b 100644 --- a/Classes/Controller/PageViewController.php +++ b/Classes/Controller/PageViewController.php @@ -122,18 +122,20 @@ public function mainAction(): ResponseInterface $this->setPage(); + $page = $this->requestData['page'] ?? 0; + // Get image data. - $this->images[0] = $this->getImage($this->requestData['page']); - $this->fulltexts[0] = $this->getFulltext($this->requestData['page']); - $this->annotationContainers[0] = $this->getAnnotationContainers($this->requestData['page']); - if ($this->requestData['double'] && $this->requestData['page'] < $this->document->getCurrentDocument()->numPages) { - $this->images[1] = $this->getImage($this->requestData['page'] + 1); - $this->fulltexts[1] = $this->getFulltext($this->requestData['page'] + 1); - $this->annotationContainers[1] = $this->getAnnotationContainers($this->requestData['page'] + 1); + $this->images[0] = $this->getImage($page); + $this->fulltexts[0] = $this->getFulltext($page); + $this->annotationContainers[0] = $this->getAnnotationContainers($page); + if ($this->requestData['double'] && $page < $this->document->getCurrentDocument()->numPages) { + $this->images[1] = $this->getImage($page + 1); + $this->fulltexts[1] = $this->getFulltext($page + 1); + $this->annotationContainers[1] = $this->getAnnotationContainers($page + 1); } - $this->scores = $this->getScore($this->requestData['page']); - $this->measures = $this->getMeasures($this->requestData['page']); + $this->scores = $this->getScore($page); + $this->measures = $this->getMeasures($page); // Get the controls for the map. $this->controls = explode(',', $this->settings['features']); @@ -154,7 +156,7 @@ public function mainAction(): ResponseInterface $this->view->assign('images', $this->images); $this->view->assign('docId', $this->requestData['id']); - $this->view->assign('page', $this->requestData['page']); + $this->view->assign('page', $page); return $this->htmlResponse(); } @@ -280,7 +282,7 @@ public function addDocumentAction(FormAddDocument $formAddDocument): ResponseInt { if (GeneralUtility::isValidUrl($formAddDocument->getLocation())) { $nextMultipleSourceKey = 0; - if ($this->requestData['multipleSource']) { + if (isset($this->requestData['multipleSource']) && is_array($this->requestData['multipleSource'])) { $nextMultipleSourceKey = max(array_keys($this->requestData['multipleSource'])) + 1; } $params = array_merge( @@ -527,7 +529,7 @@ protected function addViewerJS(): void });'; } else { $currentMeasureId = ''; - $docPage = $this->requestData['page']; + $docPage = $this->requestData['page'] ?? 0; $docMeasures = $this->getMeasures($docPage); if ($this->requestData['measure'] ?? false) { @@ -537,7 +539,7 @@ protected function addViewerJS(): void $viewer = [ 'controls' => $this->controls, 'div' => $this->settings['elementId'], - 'progressElementId' => $this->settings['progressElementId'], + 'progressElementId' => $this->settings['progressElementId'] ?? 'tx-dlf-page-progress', 'images' => $this->images, 'fulltexts' => $this->fulltexts, 'score' => $this->scores, diff --git a/Classes/Controller/TableOfContentsController.php b/Classes/Controller/TableOfContentsController.php index 8747672d27..bb8658f425 100644 --- a/Classes/Controller/TableOfContentsController.php +++ b/Classes/Controller/TableOfContentsController.php @@ -263,12 +263,12 @@ private function resolveMenuEntry(array $entry): array */ private function getAllLogicalUnits(): void { - $page = $this->requestData['page']; $physicalStructure = $this->document->getCurrentDocument()->physicalStructure; - if ( - !empty($page) + if (isset($this->requestData['page']) && + !empty($this->requestData['page']) && !empty($physicalStructure) ) { + $page = $this->requestData['page']; $structureMapLinks = $this->document->getCurrentDocument()->smLinks; $this->activeEntries = array_merge( (array) $structureMapLinks['p2l'][$physicalStructure[0]], diff --git a/Classes/Controller/ToolboxController.php b/Classes/Controller/ToolboxController.php index 630a934c24..832b0ab289 100644 --- a/Classes/Controller/ToolboxController.php +++ b/Classes/Controller/ToolboxController.php @@ -290,16 +290,17 @@ private function renderImageDownloadTool(): void } $this->setPage(); + $page = $this->requestData['page'] ?? 0; $imageArray = []; // Get left or single page download. - $image = $this->getImage($this->requestData['page']); + $image = $this->getImage($page); if (Helper::filterFilesByMimeType($image, ['image'])) { $imageArray[0] = $image; } if ($this->requestData['double'] == 1) { - $image = $this->getImage($this->requestData['page'] + 1); + $image = $this->getImage($page + 1); if (Helper::filterFilesByMimeType($image, ['image'])) { $imageArray[1] = $image; } @@ -412,7 +413,7 @@ private function getPageLink(): array $firstPageLink = ''; $secondPageLink = ''; $pageLinkArray = []; - $pageNumber = $this->requestData['page']; + $pageNumber = $this->requestData['page'] ?? 0; $fileGrpsDownload = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpDownload']); // Get image link. while ($fileGrpDownload = array_shift($fileGrpsDownload)) { @@ -587,9 +588,11 @@ private function isFullTextEmpty(): bool { $fileGrpsFulltext = GeneralUtility::trimExplode(',', $this->extConf['files']['fileGrpFulltext']); while ($fileGrpFulltext = array_shift($fileGrpsFulltext)) { - $files = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$this->requestData['page']]]['files']; - if (!empty($files[$fileGrpFulltext])) { - return false; + if (isset($this->requestData['page'])) { + $files = $this->currentDocument->physicalStructureInfo[$this->currentDocument->physicalStructure[$this->requestData['page']]]['files']; + if (!empty($files[$fileGrpFulltext])) { + return false; + } } } return true; diff --git a/Resources/Private/Partials/Lists/Pagination.html b/Resources/Private/Partials/Lists/Pagination.html index c9e48afd58..312b2a2541 100644 --- a/Resources/Private/Partials/Lists/Pagination.html +++ b/Resources/Private/Partials/Lists/Pagination.html @@ -3,10 +3,10 @@
  • - 1 + 1
  • @@ -43,7 +43,7 @@
  • - {page.label} + {page.label}
  • @@ -53,10 +53,10 @@
  • - {pagination.lastPageNumber} + {pagination.lastPageNumber}
  • diff --git a/Resources/Private/Templates/Feeds/Main.xml b/Resources/Private/Templates/Feeds/Main.xml index aa3c3e291a..789876ede5 100644 --- a/Resources/Private/Templates/Feeds/Main.xml +++ b/Resources/Private/Templates/Feeds/Main.xml @@ -8,7 +8,7 @@ {settings.title} {settings.description} - + {feedMeta.copyright}