Open Journal Systems  3.3.0
HypothesisPlugin.inc.php
1 <?php
2 
15 import('lib.pkp.classes.plugins.GenericPlugin');
16 
21  function register($category, $path, $mainContextId = null) {
22  if (parent::register($category, $path, $mainContextId)) {
23  HookRegistry::register('ArticleHandler::download',array(&$this, 'callback'));
24  HookRegistry::register('TemplateManager::display', array(&$this, 'callbackTemplateDisplay'));
25  return true;
26  }
27  return false;
28  }
29 
36  function callback($hookName, $args) {
37  $galley =& $args[1];
38  if (!$galley || $galley->getFileType() != 'text/html') return false;
39 
40  ob_start(function($buffer) {
41  return str_replace('<head>', '<head><script async defer src="//hypothes.is/embed.js"></script>', $buffer);
42  });
43 
44  return false;
45  }
46 
53  function callbackTemplateDisplay($hookName, $args) {
54  if ($hookName != 'TemplateManager::display') return false;
55  $templateMgr = $args[0];
56  $template = $args[1];
57  $plugin = 'plugins-generic-pdfJsViewer';
58  $tpl = 'submissionGalley.tpl';
59  // template path contains the plugin path, and ends with the tpl file
60  if (strpos($template, $plugin) !== false && strpos($template, ':'.$tpl, -1 - strlen($tpl)) !== false) {
61  $templateMgr->registerFilter("output", array($this, 'changePdfjsPath'));
62  }
63  return false;
64  }
65 
72  function changePdfjsPath($output, $templateMgr) {
73  $newOutput = str_replace('pdfJsViewer/pdf.js/web/viewer.html?file=', 'hypothesis/pdf.js/viewer/web/viewer.html?file=', $output);
74  return $newOutput;
75  }
76 
81  function getDisplayName() {
82  return __('plugins.generic.hypothesis.name');
83  }
84 
89  function getDescription() {
90  return __('plugins.generic.hypothesis.description');
91  }
92 }
93 
HypothesisPlugin\getDisplayName
getDisplayName()
Definition: HypothesisPlugin.inc.php:81
HypothesisPlugin\callback
callback($hookName, $args)
Definition: HypothesisPlugin.inc.php:36
HypothesisPlugin
Hypothesis annotation/discussion integration.
Definition: HypothesisPlugin.inc.php:17
HypothesisPlugin\changePdfjsPath
changePdfjsPath($output, $templateMgr)
Definition: HypothesisPlugin.inc.php:72
HypothesisPlugin\getDescription
getDescription()
Definition: HypothesisPlugin.inc.php:89
HypothesisPlugin\callbackTemplateDisplay
callbackTemplateDisplay($hookName, $args)
Definition: HypothesisPlugin.inc.php:53
HookRegistry\register
static register($hookName, $callback, $hookSequence=HOOK_SEQUENCE_NORMAL)
Definition: HookRegistry.inc.php:70
GenericPlugin
Abstract class for generic plugins.
Definition: GenericPlugin.inc.php:18