-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEpubJsViewerPlugin.inc.php
More file actions
157 lines (135 loc) · 4.92 KB
/
EpubJsViewerPlugin.inc.php
File metadata and controls
157 lines (135 loc) · 4.92 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* version.xml
*
* Copyright (c) 2020 Dimitris Sioulas
* Copyright (c) 2020 National Documentation Center
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* Plugin version information.
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class EpubJsViewerPlugin extends GenericPlugin {
/**
* @copydoc Plugin::register()
*/
function register($category, $path, $mainContextId = null) {
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled($mainContextId)) {
HookRegistry::register('ArticleHandler::view::galley', array($this, 'submissionCallback'), HOOK_SEQUENCE_LAST);
HookRegistry::register('IssueHandler::view::galley', array($this, 'issueCallback'), HOOK_SEQUENCE_LAST);
AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
}
return true;
}
return false;
}
/**
* Install default settings on context creation.
* @return string
*/
function getContextSpecificPluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}
/**
* @copydoc Plugin::getDisplayName
*/
function getDisplayName() {
return __('plugins.generic.epubJsViewer.name');
}
/**
* @copydoc Plugin::getDescription
*/
function getDescription() {
return __('plugins.generic.epubJsViewer.description');
}
function displaySubmissionFile($publishedMonograph, $publicationFormat, $submissionFile) {
$request = $this->getRequest();
$context = $request->getContext();
$router = $request->getRouter();
$dispatcher = $request->getDispatcher();
$templateMgr = TemplateManager::getManager($request);
$pubId = null;
$pubIdPlugins = PluginRegistry::loadCategory('pubIds', true);
foreach ($pubIdPlugins as $pubIdPlugin) {
if ($pubIdPlugin->getPubIdType() == 'doi'){
$pubId = $publishedMonograph->getStoredPubId($pubIdPlugin->getPubIdType());
}
}
$templateMgr->assign(array(
'pluginTemplatePath' => $this->getTemplatePath(),
'pluginUrl' => $request->getBaseUrl() . DIRECTORY_SEPARATOR . $this->getPluginPath(),
'downloadUrl' => $dispatcher->url($request, ROUTE_PAGE, null, null, 'download', array($publishedMonograph->getId(), $submissionFile->getAssocId(), $submissionFile->getFileIdAndRevision()), array('inline' => true)),
'annotationsEnabled' => $this->getSetting($context->getId(),'annotationsEnabled'),
'doi' => $pubId
));
return parent::displaySubmissionFile($publishedMonograph, $publicationFormat, $submissionFile);
}
/**
* Callback that renders the submission galley.
* @param $hookName string
* @param $args array
* @return boolean
*/
function submissionCallback($hookName, $args) {
$request =& $args[0];
$application = Application::get();
$issue =& $args[1];
$galley =& $args[2];
$submission =& $args[3];
$submissionNoun = 'article';
if ($galley && $galley->getFileType() == 'application/epub+zip') {
$galleyPublication = null;
foreach ($submission->getData('publications') as $publication) {
if ($publication->getId() === $galley->getData('publicationId')) {
$galleyPublication = $publication;
break;
}
}
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign(array(
'displayTemplateResource' => $this->getTemplateResource('display.tpl'),
'pluginUrl' => $request->getBaseUrl() . '/' . $this->getPluginPath(),
'galleyFile' => $galley->getFile(),
'issue' => $issue,
'submission' => $submission,
'submissionNoun' => $submissionNoun,
'bestId' => $submission->getBestId(),
'galley' => $galley,
'currentVersionString' => $application->getCurrentVersion()->getVersionString(false),
'isLatestPublication' => $submission->getData('currentPublicationId') === $galley->getData('publicationId'),
'galleyPublication' => $galleyPublication,
));
$templateMgr->display($this->getTemplateResource('submissionGalley.tpl'));
return true;
}
return false;
}
/**
* Callback that renders the issue galley.
* @param $hookName string
* @param $args array
* @return boolean
*/
function issueCallback($hookName, $args) {
$request =& $args[0];
$issue =& $args[1];
$galley =& $args[2];
$templateMgr = TemplateManager::getManager($request);
if ($galley && $galley->getFileType() == 'application/epub+zip') {
$application = Application::get();
$templateMgr->assign(array(
'displayTemplateResource' => $this->getTemplateResource('display.tpl'),
'pluginUrl' => $request->getBaseUrl() . '/' . $this->getPluginPath(),
'galleyFile' => $galley->getFile(),
'issue' => $issue,
'galley' => $galley,
'currentVersionString' => $application->getCurrentVersion()->getVersionString(false),
'isLatestPublication' => true,
));
$templateMgr->display($this->getTemplateResource('issueGalley.tpl'));
return true;
}
return false;
}
}