-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathHypothesisPlugin.php
97 lines (83 loc) · 2.51 KB
/
HypothesisPlugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @file HypothesisPlugin.inc.php
*
* Copyright (c) 2013-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class HypothesisPlugin
* @brief Hypothesis annotation/discussion integration
*/
namespace APP\plugins\generic\hypothesis;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
class HypothesisPlugin extends GenericPlugin {
/**
* @copydoc Plugin::register()
*/
function register($category, $path, $mainContextId = null) {
if (parent::register($category, $path, $mainContextId)) {
Hook::add('ArticleHandler::download',array(&$this, 'callback'));
Hook::add('TemplateManager::display', array(&$this, 'callbackTemplateDisplay'));
return true;
}
return false;
}
/**
* Hook callback function for TemplateManager::display
* @param $hookName string
* @param $args array
* @return boolean
*/
function callback($hookName, $args) {
$galley =& $args[1];
if (!$galley || $galley->getFileType() != 'text/html') return false;
ob_start(function($buffer) {
return str_replace('<head>', '<head><script async defer src="//hypothes.is/embed.js"></script>', $buffer);
});
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';
$displaytpl = 'display.tpl';
// template path contains the plugin path, and ends with the tpl file
if (strpos($template, $plugin) !== false && strpos($template, ':' . $displaytpl) !== 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
*/
function getDisplayName() {
return __('plugins.generic.hypothesis.name');
}
/**
* Get the description of this plugin
* @return string
*/
function getDescription() {
return __('plugins.generic.hypothesis.description');
}
}