Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pdfjsviewer template override master #12

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "pdf.js"]
path = pdf.js
url = https://github.com/hypothesis/pdf.js-hypothes.is.git
31 changes: 31 additions & 0 deletions HypothesisPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class HypothesisPlugin extends GenericPlugin {
function register($category, $path, $mainContextId = null) {
if (parent::register($category, $path, $mainContextId)) {
HookRegistry::register('ArticleHandler::download',array(&$this, 'callback'));
HookRegistry::register('TemplateManager::display', array(&$this, 'callbackTemplateDisplay'));
return true;
}
return false;
Expand All @@ -43,6 +44,36 @@ 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];
$plugin = 'plugins-generic-pdfJsViewer';
$tpl = 'submissionGalley.tpl';
// template path contains the plugin path, and ends with the tpl file
if (strpos($template, $plugin) !== false && strpos($template, ':'.$tpl, -1 - strlen($tpl)) !== false) {
$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
Expand Down
9 changes: 3 additions & 6 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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.2 and may not work with other
versions.

Installation
Expand All @@ -34,11 +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 make a change to the PDF.js Viewer plugin. To do this, replace the pdf.js
implementation in plugins/generic/pdfJsViewer/pdf.js with the one from this
repository: https://github.com/hypothesis/pdf.js-hypothes.is

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
---------------
Expand Down
1 change: 1 addition & 0 deletions pdf.js
Submodule pdf.js added at 6dd681