-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEpubViewerPlugin.php
199 lines (177 loc) · 6.71 KB
/
EpubViewerPlugin.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
/**
* @file plugins/generic/epubViewer/EpubViewerPlugin.inc.php
*
* Copyright (c) 2010-2021 Lepidus Tecnologia
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class EpubViewerPlugin
*
* @brief This plugin enables embedding of ePUB viewer for epub display
*/
namespace APP\plugins\generic\epubViewer;
use PKP\plugins\Hook;
use PKP\plugins\GenericPlugin;
use APP\core\Application;
use APP\template\TemplateManager;
class EpubViewerPlugin extends GenericPlugin
{
/**
* @copydoc Plugin::register()
*/
public function register($category, $path, $mainContextId = null)
{
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled($mainContextId)) {
Hook::add('ArticleHandler::view::galley', array($this, 'submissionCallback'), HOOK_SEQUENCE_LAST);
Hook::add('IssueHandler::view::galley', array($this, 'issueCallback'), HOOK_SEQUENCE_LAST);
Hook::add('CatalogBookHandler::view', [$this, 'viewCallback'], Hook::SEQUENCE_LATE);
Hook::add('CatalogBookHandler::download', [$this, 'downloadCallback'], Hook::SEQUENCE_LATE);
}
return true;
}
return false;
}
/**
* Install default settings on context creation.
* @return string
*/
public function getContextSpecificPluginSettingsFile()
{
return $this->getPluginPath() . '/settings.xml';
}
/**
* @copydoc Plugin::getDisplayName
*/
public function getDisplayName()
{
return __('plugins.generic.epubViewer.name');
}
/**
* @copydoc Plugin::getDescription
*/
public function getDescription()
{
return __('plugins.generic.epubViewer.description');
}
/**
* Callback that renders the submission galley.
* @param $hookName string
* @param $args array
* @return boolean
*/
public function submissionCallback($hookName, $args)
{
$request =& $args[0];
$application = Application::get();
switch ($application->getName()) {
case 'ojs2':
$issue =& $args[1];
$galley =& $args[2];
$submission =& $args[3];
$submissionNoun = 'article';
break;
default: throw new Exception('Unknown application!');
}
if (!$galley) {
return false;
}
$submissionFile = $galley->getFile();
if ($submissionFile->getData('mimetype') === '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' => $submissionFile,
'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;
}
public function viewCallback($hookName, $args)
{
$submission =& $args[1];
$publicationFormat =& $args[2];
$submissionFile =& $args[3];
if ($submissionFile->getData('mimetype') == 'application/epub+zip') {
foreach ($submission->getData('publications') as $publication) {
if ($publication->getId() === $publicationFormat->getData('publicationId')) {
$filePublication = $publication;
break;
}
}
$request = Application::get()->getRequest();
$router = $request->getRouter();
$dispatcher = $request->getDispatcher();
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign(array(
'pluginUrl' => $request->getBaseUrl() . '/' . $this->getPluginPath(),
'isLatestPublication' => $submission->getData('currentPublicationId') === $publicationFormat->getData('publicationId'),
'filePublication' => $filePublication,
));
$templateMgr->display($this->getTemplateResource('display.tpl'));
return true;
}
return false;
}
public function downloadCallback($hookName, $params)
{
$submission =& $params[1];
$publicationFormat =& $params[2];
$submissionFile =& $params[3];
$inline =& $params[4];
$request = Application::get()->getRequest();
$mimetype = $submissionFile->getData('mimetype');
if ($mimetype == 'application/epub+zip' && $request->getUserVar('inline')) {
$inline = true;
}
return false;
}
/**
* Callback that renders the issue galley.
* @param $hookName string
* @param $args array
* @return boolean
*/
public 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;
}
}
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\epubViewer\EpubViewerPlugin', '\EpubViewerPlugin');
}