From 81e46ab48f7b6d0575f74892d2fa40232d290cb9 Mon Sep 17 00:00:00 2001 From: Jan Stutzmann <31411045+stutzmann72@users.noreply.github.com> Date: Tue, 7 Jan 2025 10:40:37 +0100 Subject: [PATCH] remove 3.3 version files and update code to modify url creation and add json encoding for Issue #26 (#27) Co-authored-by: Peter West --- IiifViewerPlugin.inc.php | 152 --------------------------------- IiifViewerPlugin.php | 38 ++++++--- index.php | 22 ----- locale/de_DE/locale.po | 27 ------ locale/en_US/locale.po | 27 ------ templates/article_image.tpl | 2 +- templates/article_manifest.tpl | 4 +- templates/display.tpl | 2 +- templates/display_manifest.tpl | 4 +- templates/issue_image.tpl | 2 +- templates/issue_manifest.tpl | 4 +- 11 files changed, 35 insertions(+), 249 deletions(-) delete mode 100644 IiifViewerPlugin.inc.php delete mode 100644 index.php delete mode 100644 locale/de_DE/locale.po delete mode 100644 locale/en_US/locale.po diff --git a/IiifViewerPlugin.inc.php b/IiifViewerPlugin.inc.php deleted file mode 100644 index f92797b..0000000 --- a/IiifViewerPlugin.inc.php +++ /dev/null @@ -1,152 +0,0 @@ -getEnabled($mainContextId)) { - $request = Application::get()->getRequest(); - $url = $request->getBaseUrl() . '/' . $this->getPluginPath() . '/styles/iiifviewer.css'; - $templateMgr = TemplateManager::getManager($request); - $templateMgr->addStyleSheet('iiifViewerStyles', $url); - - HookRegistry::register('CatalogBookHandler::view', array($this, 'viewCallback'), HOOK_SEQUENCE_NORMAL); - } - return true; - } - return false; - } - - /** - * Install default settings on press creation. - * @return string - */ - function getContextSpecificPluginSettingsFile() { - return $this->getPluginPath() . '/settings.xml'; - } - - /** - * Get the display name of this plugin. - * @return String - */ - function getDisplayName() { - return __('plugins.generic.iiifViewer.displayName'); - } - - /** - * Get a description of the plugin. - */ - function getDescription() { - return __('plugins.generic.iiifViewer.description'); - } - - /** - * Callback to view the Image content rather than downloading. - * @param $hookName string - * @param $args array - * @return boolean - */ - function viewCallback($hookName, $args) { - $submission =& $args[1]; - $publicationFormat =& $args[2]; - $submissionFile =& $args[3]; - - $mime_type = $submissionFile->getData('mimetype'); - $format = $publicationFormat->getBestId(); - - $contextid = $this->getCurrentContextId(); - - if ($format == 'iiif_manifest' && (($mime_type == 'application/json') || ($mime_type == 'text/plain'))) { - $this->viewImageFile($publicationFormat, $mime_type, $submission, $submissionFile, "display_manifest.tpl" ); - return true; - - } elseif ($mime_type == 'image/jpeg') { - $this->viewImageFile($publicationFormat, $mime_type, $submission, $submissionFile, "display.tpl" ); - return true; - } - - return false; - } - - /** - * function to prepare IIIFViewer data for an image file. - * @param $publicationFormat PublicationFormat - * @param $mime_type string - * @param $submission Submission - * @param $submissionFile SubmissionFile - * @param $submission Submission - * @param $theTemplate string - * @return boolean - */ - function viewImageFile($publicationFormat, $mime_type, $submission, $submissionFile, $theTemplate) { - - foreach ($submission->getData('publications') as $publication) { - if ($publication->getId() === $publicationFormat->getData('publicationId')) { - $filePublication = $publication; - break; - } - } - $fileService = Services::get('file'); - $imgfile = $fileService->get($submissionFile->getData('fileId')); - $imgpath = $imgfile->path; - - $fileId = $submissionFile->getId(); - $fileStage = $submissionFile->getFileStage(); - $subStageId = $submission->getStageId(); - $submissionId = $submission->getId(); - $format = $publicationFormat->getBestId(); - -error_log("iiifviewer::viewImageFile called submissionid[".$submissionId."] fileid[".$fileId."] sub stage [".$subStageId."] filestage[".$fileStage."] mimetype [".$submissionFile->getData('mimetype')."] path[".$this->getPluginPath()."] format[".$format."]\n"); - - $request = Application::get()->getRequest(); - $router = $request->getRouter(); - $contextPath = $router->getRequestedContextPath($request, 1); - - //$apiUrl = $request->getIndexUrl()."/".$contextPath.'/$$$call$$$/api/file/file-api/download-file?submissionFileId='.$fileId."&submissionId=".$submissionId."&stageId=".$subStageId; - - $apiUrl = $request->getIndexUrl().'/'.$contextPath.'/catalog/download/'.$submissionId.'/'.$format.'/'.$fileId.'?inline=1'; - - $templateMgr = TemplateManager::getManager($request); - $templateMgr->assign(array( - 'apiUrl' => $apiUrl, - 'pluginUrl' => $request->getBaseUrl() . '/' . $this->getPluginPath(), - 'isLatestPublication' => $submission->getData('currentPublicationId') === $publicationFormat->getData('publicationId'), - 'filePublication' => $filePublication, - 'subId' => $submissionId, - 'subStageId' => $subStageId, - 'fileId' => $fileId, - )); - - $templateMgr->display($this->getTemplateResource($theTemplate)); - - return true; - } - - /** - * Get the plugin base URL. - * @param $request PKPRequest - * @return string - */ - private function _getPluginUrl($request) { - return $request->getBaseUrl() . '/' . $this->getPluginPath(); - } -} - - diff --git a/IiifViewerPlugin.php b/IiifViewerPlugin.php index d025a46..0e5d167 100644 --- a/IiifViewerPlugin.php +++ b/IiifViewerPlugin.php @@ -44,13 +44,21 @@ public function register($category, $path, $mainContextId = null) { if ($this->getEnabled($mainContextId)) { $request = Application::get()->getRequest(); $url = $request->getBaseUrl() . '/' . $this->getPluginPath() . '/styles/iiifviewer.css'; - $templateMgr = TemplateManager::getManager($request); + + $templateMgr = TemplateManager::getManager($request); $templateMgr->addStyleSheet('iiifViewerStyles', $url); - if (str_starts_with($context, 'ojs')) { - Hook::add('ArticleHandler::view::galley', [$this, 'articleCallback']); - Hook::add('IssueHandler::view::galley', [$this, 'issueCallback']); - } elseif (str_starts_with($context, 'omp')) { - Hook::add('CatalogBookHandler::view', [$this, 'ompViewCallback'], HOOK::SEQUENCE_NORMAL); + + switch (Application::getName()) { + case 'ojs2': + Hook::add('ArticleHandler::view::galley', [$this, 'articleCallback']); + Hook::add('IssueHandler::view::galley', [$this, 'issueCallback']); + break; + case 'omp': + Hook::add('CatalogBookHandler::view', [$this, 'ompViewCallback'], HOOK::SEQUENCE_NORMAL); + break; + case 'ops': + break; + default: throw new \Exception('Unsupported application!'); } } return true; @@ -149,19 +157,21 @@ public function articleCallback($hookName, $args) { $bestId = $submission->getBestId(); $galleyBestId = $galley->getBestGalleyId(); $galleyFile = $galley->getFile(); - $apiUrl = null; + $apiParams['inline'] = 'true'; + $apiPath = []; if ($isLatestPublication) { - $apiUrl = $request->getIndexUrl().'/'.$contextPath.'/article/download/'.$bestId.'/'.$galleyBestId.'/'.$galleyFile->getId().'?inline=1'; + $apiPath = [$bestId, $galleyBestId, $galleyFile->getId()]; } else { - $apiUrl = $request->getIndexUrl().'/'.$contextPath.'/article/download/'.$bestId.'/version/'.$galleyPublication->getId().'/'.$galleyBestId.'/'.$galleyFile->getId().'?inline=1'; + $apiPath = [$bestId, 'version', $galleyPublication->getId(), $galleyBestId, $galleyFile->getId()]; } + $apiUrl = $request->url( null, 'article', 'download', $apiPath, $apiParams ); + $templateMgr = TemplateManager::getManager($request); $templateMgr->assign([ 'apiUrl' => $apiUrl, 'pluginUrl' => $request->getBaseUrl() . '/' . $this->getPluginPath(), 'isLatestPublication' => $isLatestPublication, - ]); $templateMgr->display($this->getTemplateResource($galleyTemplate)); @@ -200,7 +210,9 @@ function issueCallback($hookName, $args) { $galleyBestId = $galley->getBestGalleyId(); $galleyFile = $galley->getFile(); - $apiUrl = $request->getIndexUrl().'/'.$contextPath.'/issue/download/'.$issueBestId.'/'.$galleyBestId.'/'.$galleyFile->getId().'?inline=1'; + $apiPath = [$issueBestId, $galleyBestId, $galleyFile->getId()]; + $apiParams['inline'] = 'true'; + $apiUrl = $request->url(null, 'issue', 'download', $apiPath, $apiParams ); $templateMgr = TemplateManager::getManager($request); $templateMgr->assign([ @@ -246,7 +258,9 @@ private function viewImageFile($publicationFormat, $submission, $submissionFile, $router = $request->getRouter(); $contextPath = $router->getRequestedContextPath($request, 1); - $apiUrl = $request->getIndexUrl().'/'.$contextPath.'/catalog/download/'.$submissionId.'/'.$format.'/'.$fileId.'?inline=1'; + $apiPath = [$submissionId, $format, $fileId]; + $apiParams['inline'] = 'true'; + $apiUrl = $request->url(null, 'catalog', 'download', $apiPath, $apiParams ); $templateMgr = TemplateManager::getManager($request); $templateMgr->assign(array( diff --git a/index.php b/index.php deleted file mode 100644 index be94176..0000000 --- a/index.php +++ /dev/null @@ -1,22 +0,0 @@ - diff --git a/templates/article_manifest.tpl b/templates/article_manifest.tpl index 8b7a147..44f92c6 100644 --- a/templates/article_manifest.tpl +++ b/templates/article_manifest.tpl @@ -22,13 +22,13 @@ var mirador = Mirador.viewer({ "id": "my-mirador", "manifests": { - "{$apiUrl}" :{ + {$apiUrl|json_encode:JSON_UNESCAPED_SLASHES} :{ //"provider": "Basel University" } }, "windows": [ { - "loadedManifest": "{$apiUrl}", + "loadedManifest": {$apiUrl|json_encode:JSON_UNESCAPED_SLASHES}, "canvasIndex": 2, "thumbnailNavigationPosition": 'far-bottom' } diff --git a/templates/display.tpl b/templates/display.tpl index 4f68018..abf3c27 100644 --- a/templates/display.tpl +++ b/templates/display.tpl @@ -46,7 +46,7 @@ sequenceMode: true, tileSources: [{ "type": "image", - "url": "{$apiUrl}" + "url": {$apiUrl|json_encode:JSON_UNESCAPED_SLASHES} }] }); diff --git a/templates/display_manifest.tpl b/templates/display_manifest.tpl index 83ed698..ad6cb1a 100644 --- a/templates/display_manifest.tpl +++ b/templates/display_manifest.tpl @@ -22,13 +22,13 @@ var mirador = Mirador.viewer({ "id": "my-mirador", "manifests": { - "{$apiUrl}" :{ + {$apiUrl|json_encode:JSON_UNESCAPED_SLASHES} :{ //"provider": "Basel University" } }, "windows": [ { - "loadedManifest": "{$apiUrl}", + "loadedManifest": {$apiUrl|json_encode:JSON_UNESCAPED_SLASHES}, "canvasIndex": 2, "thumbnailNavigationPosition": 'far-bottom' } diff --git a/templates/issue_image.tpl b/templates/issue_image.tpl index 6618592..3ae35f6 100644 --- a/templates/issue_image.tpl +++ b/templates/issue_image.tpl @@ -29,7 +29,7 @@ sequenceMode: true, tileSources: [{ "type": "image", - "url": "{$apiUrl}" + "url": {$apiUrl|json_encode:JSON_UNESCAPED_SLASHES} }] }); diff --git a/templates/issue_manifest.tpl b/templates/issue_manifest.tpl index 8b7a147..44f92c6 100644 --- a/templates/issue_manifest.tpl +++ b/templates/issue_manifest.tpl @@ -22,13 +22,13 @@ var mirador = Mirador.viewer({ "id": "my-mirador", "manifests": { - "{$apiUrl}" :{ + {$apiUrl|json_encode:JSON_UNESCAPED_SLASHES} :{ //"provider": "Basel University" } }, "windows": [ { - "loadedManifest": "{$apiUrl}", + "loadedManifest": {$apiUrl|json_encode:JSON_UNESCAPED_SLASHES}, "canvasIndex": 2, "thumbnailNavigationPosition": 'far-bottom' }