Skip to content

Commit

Permalink
Merge branch 'master' into Pres_01-2023_Solr-Verbesserungen_soft_comm…
Browse files Browse the repository at this point in the history
…its_rebase
  • Loading branch information
sebastian-meyer authored Jul 29, 2024
2 parents 0f435f2 + 244c2ca commit 95ff044
Show file tree
Hide file tree
Showing 28 changed files with 325 additions and 179 deletions.
4 changes: 2 additions & 2 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,13 @@ private function getDocumentByUid(int $documentId)
/**
* Get document by URL.
*
* @access private
* @access protected
*
* @param string $documentId The document's URL
*
* @return AbstractDocument
*/
private function getDocumentByUrl(string $documentId)
protected function getDocumentByUrl(string $documentId)
{
$doc = AbstractDocument::getInstance($documentId, $this->settings, true);

Expand Down
97 changes: 97 additions & 0 deletions Classes/Controller/Embedded3dViewerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* (c) Kitodo. Key to digital objects e.V. <[email protected]>
*
* 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\Controller;

use Kitodo\Dlf\Common\AbstractDocument;

/**
* Plugin 'Embedded3dViewer' for the 'dlf' extension
*
* @package TYPO3
* @subpackage dlf
*
* @access public
*/
class Embedded3dViewerController extends AbstractController
{

const MIDDLEWARE_DLF_EMBEDDED_3D_VIEWER_PREFIX = '/?middleware=dlf/embedded3dviewer';

/**
* @access public
*
* @return void
*/
public function mainAction(): void
{
if (!empty($this->requestData['model']) || !empty($this->settings['model'])) {
$this->view->assign('embedded3dViewerUrl', $this->buildEmbedded3dViewerUrl());
return;
}

if (!empty($this->settings['document'])) {
$this->assignModelFromDocument($this->getDocumentByUrl($this->settings['document']));
} else {
$this->loadDocument();
if (!$this->isDocMissingOrEmpty()) {
$this->assignModelFromDocument($this->document->getCurrentDocument());
}
}

}

/**
* Builds the embedded 3D viewer url.
*
* @param string $model The model url
* @return string The embedded 3D viewer url
*/
public function buildEmbedded3dViewerUrl(string $model = ''): string
{
$viewer = "";
$embedded3dViewerUrl = self::MIDDLEWARE_DLF_EMBEDDED_3D_VIEWER_PREFIX;

if (!empty($this->requestData['model'])) {
$model = $this->requestData['model'];
} elseif (!empty($this->settings['model'])) {
$model = $this->settings['model'];
}

if (!empty($model)) {
$embedded3dViewerUrl .= '&model=' . $model;
}

if (!empty($this->requestData['viewer'])) {
$viewer = $this->requestData['viewer'];
} elseif (!empty($this->settings['viewer'])) {
$viewer = $this->settings['viewer'];
}

if (!empty($viewer)) {
$embedded3dViewerUrl .= '&viewer=' . $viewer;
}
return $embedded3dViewerUrl;
}

/**
* Assign the model from document to view.
*
* @param AbstractDocument $document The document containing the model
*/
public function assignModelFromDocument(AbstractDocument $document): void
{
if ($document->getToplevelMetadata()['type'][0] === 'object') {
$model = trim($document->getFileLocation($document->physicalStructureInfo[$document->physicalStructure[1]]['files']['DEFAULT']));
$this->view->assign('embedded3dViewerUrl', $this->buildEmbedded3dViewerUrl($model));
}
}
}
79 changes: 0 additions & 79 deletions Classes/Controller/View3DController.php

This file was deleted.

34 changes: 26 additions & 8 deletions Classes/ExpressionLanguage/DocumentTypeFunctionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,27 @@ function($arguments, $cPid)
return $type;
}

// object type if model parameter is not empty so we assume that it is a 3d object
if (!empty($queryParams['tx_dlf']['model'])) {
return 'object';
}

// Load document with current plugin parameters.
$this->loadDocument($queryParams['tx_dlf'], $cPid);
if (!isset($this->document) || $this->document->getCurrentDocument() === null) {
return $type;
}

// Set PID for metadata definitions.
$this->document->getCurrentDocument()->cPid = $cPid;

$metadata = $this->document->getCurrentDocument()->getToplevelMetadata($cPid);
if (!empty($metadata['type'][0])) {
// Calendar plugin does not support IIIF (yet). Abort for all newspaper related types.
if (
$this->document->getCurrentDocument() instanceof IiifManifest
&& array_search($metadata['type'][0], ['newspaper', 'ephemera', 'year', 'issue']) !== false
) {
return $type;
}

if (!empty($metadata['type'][0])
&& !$this->isIiifManifestWithNewspaperRelatedType($metadata['type'][0])) {
$type = $metadata['type'][0];
}

return $type;
});
}
Expand Down Expand Up @@ -211,4 +213,20 @@ protected function loadDocument(array $requestData, int $pid): void
$this->logger->error('Empty UID or invalid PID "' . $pid . '" for document loading');
}
}

/**
* Check if is IIIF Manifest with newspaper related type.
*
* Calendar plugin does not support IIIF (yet). Abort for all newspaper related types.
*
* @access private
*
* @param string $type The metadata type
* @return bool
*/
private function isIiifManifestWithNewspaperRelatedType(string $type): bool
{
return ($this->document->getCurrentDocument() instanceof IiifManifest
&& in_array($type, ['newspaper', 'ephemera', 'year', 'issue']));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @subpackage dlf
* @access public
*/
class Embedded3DViewer implements MiddlewareInterface
class Embedded3dViewer implements MiddlewareInterface
{
use LoggerAwareTrait;

Expand All @@ -58,7 +58,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
// parameters are sent by POST --> use getParsedBody() instead of getQueryParams()
$parameters = $request->getQueryParams();
// Return if not this middleware
if (!isset($parameters['middleware']) || ($parameters['middleware'] != 'dlf/embedded3DViewer')) {
if (!isset($parameters['middleware']) || ($parameters['middleware'] != 'dlf/embedded3dviewer')) {
return $response;
}

Expand Down Expand Up @@ -202,8 +202,8 @@ public function renderDefaultViewer($model): HtmlResponse
{
/** @var ResourceFactory $resourceFactory */
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
$html = $resourceFactory->retrieveFileOrFolderObject('EXT:dlf/Resources/Private/Templates/View3D/Standalone.html')->getContents();
$file = $resourceFactory->retrieveFileOrFolderObject('EXT:dlf/Resources/Public/JavaScript/3DViewer/model-viewer-3.5.0.min.js');
$html = $resourceFactory->retrieveFileOrFolderObject('EXT:dlf/Resources/Private/Templates/Embedded3dViewer/Standalone.html')->getContents();
$file = $resourceFactory->retrieveFileOrFolderObject('EXT:dlf/Resources/Public/JavaScript/Embedded3dViewer/model-viewer-3.5.0.min.js');
$html = str_replace('{{modelViewerJS}}', $file->getPublicUrl(), $html);
$html = str_replace("{{modelUrl}}", $model, $html);
return new HtmlResponse($html);
Expand Down
57 changes: 57 additions & 0 deletions Configuration/FlexForms/Embedded3dViewer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<!--
* (c) Kitodo. Key to digital objects e.V. <[email protected]>
*
* 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.
-->
<T3DataStructure>
<meta>
<langDisable>1</langDisable>
</meta>
<sheets>
<sDEF>
<ROOT>
<TCEforms>
<sheetTitle>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:flexform.sheet_general</sheetTitle>
</TCEforms>
<type>array</type>
<el>
<settings.document>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.embedded3dviewer.flexform.document</label>
<config>
<type>input</type>
<eval>trim</eval>
</config>
</TCEforms>
</settings.document>
<settings.model>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.embedded3dviewer.flexform.model</label>
<config>
<type>input</type>
<eval>trim</eval>
</config>
</TCEforms>
</settings.model>
<settings.viewer>
<TCEforms>
<exclude>1</exclude>
<label>LLL:EXT:dlf/Resources/Private/Language/locallang_be.xlf:plugins.embedded3dviewer.flexform.viewer</label>
<config>
<type>input</type>
<eval>trim</eval>
</config>
</TCEforms>
</settings.viewer>
</el>
</ROOT>
</sDEF>
</sheets>
</T3DataStructure>
37 changes: 0 additions & 37 deletions Configuration/FlexForms/View3D.xml

This file was deleted.

2 changes: 1 addition & 1 deletion Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
]
],
'dlf/embedded3DViewer' => [
'target' => \Kitodo\Dlf\Middleware\Embedded3DViewer::class,
'target' => \Kitodo\Dlf\Middleware\Embedded3dViewer::class,
'after' => [
'typo3/cms-frontend/prepare-tsfe-rendering'
]
Expand Down
Loading

0 comments on commit 95ff044

Please sign in to comment.