forked from pkp/pdfJsViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdfJsViewerPlugin.inc.php
More file actions
132 lines (118 loc) · 3.72 KB
/
Copy pathPdfJsViewerPlugin.inc.php
File metadata and controls
132 lines (118 loc) · 3.72 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
<?php
/**
* @file plugins/generic/pdfJsViewer/PdfJsViewerPlugin.inc.php
*
* Copyright (c) 2013-2018 Simon Fraser University
* Copyright (c) 2003-2018 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class PdfJsViewerPlugin
*
* @brief This plugin enables embedding of the pdf.js viewer for PDF display
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class PdfJsViewerPlugin 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, 'articleCallback'));
HookRegistry::register('IssueHandler::view::galley', array($this, 'issueCallback'));
AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
}
return true;
}
return false;
}
/**
* Install default settings on journal creation.
* @return string
*/
function getContextSpecificPluginSettingsFile() {
return $this->getPluginPath() . '/settings.xml';
}
/**
* @copydoc Plugin::getDisplayName
*/
function getDisplayName() {
return __('plugins.generic.pdfJsViewer.name');
}
/**
* @copydoc Plugin::getDescription
*/
function getDescription() {
return __('plugins.generic.pdfJsViewer.description');
}
/**
* Callback that renders the article galley.
* @param $hookName string
* @param $args array
* @return boolean
*/
function articleCallback($hookName, $args) {
$request =& $args[0];
$issue =& $args[1];
$galley =& $args[2];
$article =& $args[3];
$templateMgr = TemplateManager::getManager($request);
if ($galley && $galley->getFileType() == 'application/pdf') {
$application = Application::getApplication();
$templateMgr->assign(array(
'displayTemplateResource' => $this->getTemplateResource('display.tpl'),
'pluginUrl' => $request->getBaseUrl() . '/' . $this->getPluginPath(),
'galleyFile' => $galley->getFile(),
'issue' => $issue,
'article' => $article,
'galley' => $galley,
'jQueryUrl' => $this->_getJQueryUrl($request),
'currentVersionString' => $application->getCurrentVersion()->getVersionString(false),
));
$templateMgr->display($this->getTemplateResource('articleGalley.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/pdf') {
$application = Application::getApplication();
$templateMgr->assign(array(
'displayTemplateResource' => $this->getTemplateResource('display.tpl'),
'pluginUrl' => $request->getBaseUrl() . '/' . $this->getPluginPath(),
'galleyFile' => $galley->getFile(),
'issue' => $issue,
'galley' => $galley,
'jQueryUrl' => $this->_getJQueryUrl($request),
'currentVersionString' => $application->getCurrentVersion()->getVersionString(false),
));
$templateMgr->display($this->getTemplateResource('issueGalley.tpl'));
return true;
}
return false;
}
/**
* Get the URL for JQuery JS.
* @param $request PKPRequest
* @return string
*/
private function _getJQueryUrl($request) {
$min = Config::getVar('general', 'enable_minified') ? '.min' : '';
if (Config::getVar('general', 'enable_cdn')) {
return '//ajax.googleapis.com/ajax/libs/jquery/' . CDN_JQUERY_VERSION . '/jquery' . $min . '.js';
} else {
return $request->getBaseUrl() . '/lib/pkp/lib/components/jquery/jquery' . $min . '.js';
}
}
}
?>