-
Notifications
You must be signed in to change notification settings - Fork 9
/
PLNGatewayPlugin.inc.php
169 lines (146 loc) · 4.94 KB
/
PLNGatewayPlugin.inc.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
<?php
/**
* @file PLNGatewayPlugin.inc.php
*
* Copyright (c) 2013-2020 Simon Fraser University
* Copyright (c) 2003-2020 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class PLNGatewayPlugin
* @brief Gateway component of web PLN plugin
*/
import('lib.pkp.classes.plugins.GatewayPlugin');
import('lib.pkp.classes.site.VersionCheck');
import('lib.pkp.classes.db.DBResultRange');
import('lib.pkp.classes.core.ArrayItemIterator');
define('PLN_PLUGIN_PING_ARTICLE_COUNT', 12);
// Archive/Tar.php may not be installed, so supress possible error.
@include_once('Archive/Tar.php');
class PLNGatewayPlugin extends GatewayPlugin {
/** @var $parentPluginName string Name of parent plugin */
var $parentPluginName;
/**
* Constructor.
* @param $parentPluginName string
*/
public function __construct($parentPluginName) {
parent::__construct();
$this->parentPluginName = $parentPluginName;
}
/**
* Hide this plugin from the management interface (it's subsidiary)
* @return boolean
*/
public function getHideManagement() {
return true;
}
/**
* @copydoc Plugin::getName
*/
public function getName() {
return 'PLNGatewayPlugin';
}
/**
* @copydoc Plugin::getDisplayName
*/
public function getDisplayName() {
return __('plugins.generic.plngateway.displayName');
}
/**
* @copydoc Plugin::getDescription
*/
public function getDescription() {
return __('plugins.generic.plngateway.description');
}
/**
* Get the PLN plugin
* @return object
*/
public function getPLNPlugin() {
return PluginRegistry::getPlugin('generic', $this->parentPluginName);
}
/**
* Override the builtin to get the correct plugin path.
* @return string
*/
public function getPluginPath() {
$plugin = $this->getPLNPlugin();
return $plugin->getPluginPath();
}
/**
* Override the builtin to get the correct template path.
* @return string
*/
public function getTemplatePath($inCore = false) {
$plugin = $this->getPLNPlugin();
return $plugin->getTemplatePath($inCore);
}
/**
* Get whether or not this plugin is enabled. (Should always return true, as the
* parent plugin will take care of loading this one when needed)
* @return boolean
*/
public function getEnabled() {
$plugin = $this->getPLNPlugin();
return $plugin->getEnabled(); // Should always be true anyway if this is loaded
}
/**
* @copydoc GatewayPlugin::fetch
*/
public function fetch($args, $request) {
$plugin = $this->getPLNPlugin();
$templateMgr = TemplateManager::getManager($request);
$journal = $request->getJournal();
$pluginVersionFile = $this->getPluginPath() . DIRECTORY_SEPARATOR . 'version.xml';
$pluginVersion = VersionCheck::parseVersionXml($pluginVersionFile);
$templateMgr->assign('pluginVersion', $pluginVersion);
$terms = array();
$termsAccepted = $plugin->termsAgreed($journal->getId());
if ($termsAccepted) {
$templateMgr->assign('termsAccepted', 'yes');
$terms = unserialize($plugin->getSetting($journal->getId(), 'terms_of_use'));
$termsAgreement = unserialize($plugin->getSetting($journal->getId(), 'terms_of_use_agreement'));
} else {
$templateMgr->assign('termsAccepted', 'no');
}
$application = PKPApplication::getApplication();
$products = $application->getEnabledProducts('plugins.generic');
$prerequisites = array(
'phpVersion' => PHP_VERSION,
'zipInstalled' => class_exists('ZipArchive') ? 'yes' : 'no',
'tarInstalled' => class_exists('Archive_Tar') ? 'yes' : 'no',
'acron' => isset($products['acron']) ? 'yes' : 'no',
//'tasks' => Config::getVar('general', 'scheduled_tasks', false) ? 'yes' : 'no',
);
$templateMgr->assign('prerequisites', $prerequisites);
$termKeys = array_keys($terms);
$termsDisplay = array();
foreach ($termKeys as $key) {
$termsDisplay[] = array(
'key' => $key,
'term' => $terms[$key]['term'],
'updated' => $terms[$key]['updated'],
'accepted' => $termsAgreement[$key]
);
}
$templateMgr->assign('termsDisplay', new ArrayItemIterator($termsDisplay));
$versionDao = DAORegistry::getDAO('VersionDAO');
$ojsVersion = $versionDao->getCurrentVersion();
$templateMgr->assign('ojsVersion', $ojsVersion->getVersionString());
$submissionDao = DAORegistry::getDAO('SubmissionDAO');
$publications = array();
$submissions = $submissionDao->getByContextId($journal->getId());
while ($submission = $submissions->next()) {
$publication = $submission->getCurrentPublication();
if (!$publication || $publication->getData('status') != STATUS_PUBLISHED) continue;
$publications[] = $publication;
if (count($publications) == PLN_PLUGIN_PING_ARTICLE_COUNT) break;
}
$submissions->close();
$templateMgr->assign('publications', $publications);
$templateMgr->assign('pln_network', $plugin->getSetting($journal->getId(), 'pln_network'));
header('Content-Type: text/xml; charset=' . Config::getVar('i18n', 'client_charset'));
$templateMgr->display($plugin->getTemplateResource('ping.tpl'));
return true;
}
}