From b73a64a1e44f8ee6cb02b8fbda67ac75333fed47 Mon Sep 17 00:00:00 2001 From: Clinton Graham Date: Thu, 5 Mar 2020 12:50:09 -0500 Subject: [PATCH] asmecher/hypothesis#10: Modify delivery of pdfJsViewer template to use hypothes.is version of pdf.js --- .gitmodules | 3 +++ HypothesisPlugin.inc.php | 28 ++++++++++++++++++++++++++++ README | 15 +++------------ pdf.js | 1 + 4 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 .gitmodules create mode 160000 pdf.js diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..1ff4dd4 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "pdf.js"] + path = pdf.js + url = https://github.com/hypothesis/pdf.js-hypothes.is.git diff --git a/HypothesisPlugin.inc.php b/HypothesisPlugin.inc.php index 8f7cc53..d646e43 100644 --- a/HypothesisPlugin.inc.php +++ b/HypothesisPlugin.inc.php @@ -27,6 +27,7 @@ class HypothesisPlugin extends GenericPlugin { function register($category, $path) { if (parent::register($category, $path)) { HookRegistry::register('ArticleHandler::download',array(&$this, 'callback')); + HookRegistry::register('TemplateManager::display', array(&$this, 'callbackTemplateDisplay')); return true; } return false; @@ -49,6 +50,33 @@ function callback($hookName, $args) { return false; } + /** + * Hook callback function for TemplateManager::display + * @param $hookName string + * @param $args array + * @return boolean + */ + function callbackTemplateDisplay($hookName, $args) { + if ($hookName != 'TemplateManager::display') return false; + $templateMgr = $args[0]; + $template = $args[1]; + if ($template == 'plugins-plugins-generic-pdfJsViewer-generic-pdfJsViewer:articleGalley.tpl') { + $templateMgr->registerFilter("output", array($this, 'changePdfjsPath')); + } + return false; + } + + /** + * Output filter to create a new element in a registration form + * @param $output string + * @param $templateMgr TemplateManager + * @return $string + */ + function changePdfjsPath($output, $templateMgr) { + $newOutput = str_replace('pdfJsViewer/pdf.js/web/viewer.html?file=', 'hypothesis/pdf.js/viewer/web/viewer.html?file=', $output); + return $newOutput; + } + /** * Get the display name of this plugin * @return string diff --git a/README b/README index 8b18779..ddbec09 100644 --- a/README +++ b/README @@ -18,7 +18,7 @@ COPYING for the complete terms of this license. System Requirements ------------------- -This plugin has been developed for OJS 3.0.x and may not work with other +This plugin has been developed for OJS 3.1.2 and may not work with other versions. Installation @@ -34,17 +34,8 @@ If you cannot use the Plugin Gallery, you can also install the plugin as follows - Read an HTML article in the public reader interface of OJS and verify that the Hypothes.is tool is embedded. -In order to support Hypothes.is with OJS's PDF.js-based PDF reader, you'll need -to apply a patch to the version of PDF.js that's included in that plugin. The -patch is currently available at: - -https://github.com/hypothesis/pdf.js-hypothes.is/commit/ab3f25 - -To apply it... - - cd plugins/generic/pdfJsViewer/pdf.js - patch -p2 < /path/to/ab3f25.diff - +In order to support Hypothes.is with OJS's PDF.js-based PDF reader, this plugin +hijacks the template display of the pdfJsViewer plugin. Contact/Support --------------- diff --git a/pdf.js b/pdf.js new file mode 160000 index 0000000..6dd681b --- /dev/null +++ b/pdf.js @@ -0,0 +1 @@ +Subproject commit 6dd681bf04fd9b0121c7c03de3b7b9bb3a3a1101