forked from defstat/pln
-
Notifications
You must be signed in to change notification settings - Fork 2
/
PLNGatewayPlugin.inc.php
183 lines (157 loc) · 5.12 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* @file plugins/generic/pln/PLNGatewayPlugin.inc.php
*
* Copyright (c) 2013-2017 Simon Fraser University Library
* Copyright (c) 2003-2017 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class PLNGatewayPlugin
* @ingroup plugins_generic_pln
*
* @brief Gateway component of web feed 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
*/
function __construct($parentPluginName) {
parent::__construct();
$this->parentPluginName = $parentPluginName;
}
/**
* Hide this plugin from the management interface (it's subsidiary)
*/
function getHideManagement() {
return true;
}
/**
* @copydoc Plugin::getName
*/
function getName() {
return 'PLNGatewayPlugin';
}
/**
* @copydoc Plugin::getDisplayName
*/
function getDisplayName() {
return __('plugins.generic.plngateway.displayName');
}
/**
* @copydoc Plugin::getDescription
*/
function getDescription() {
return __('plugins.generic.plngateway.description');
}
/**
* Get the PLN plugin
* @return object
*/
function getPLNPlugin() {
$plugin = PluginRegistry::getPlugin('generic', $this->parentPluginName);
return $plugin;
}
/**
* Override the builtin to get the correct plugin path.
*/
function getPluginPath() {
$plugin = $this->getPLNPlugin();
return $plugin->getPluginPath();
}
/**
* Override the builtin to get the correct template path.
* @return string
*/
function getTemplatePath() {
$plugin = $this->getPLNPlugin();
return $plugin->getTemplatePath();
}
/**
* 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
*/
function getEnabled() {
$plugin = $this->getPLNPlugin();
return $plugin->getEnabled(); // Should always be true anyway if this is loaded
}
/**
* Get the management verbs for this plugin (override to none so that the parent
* plugin can handle this)
* @return array
*/
function getManagementVerbs() {
return array();
}
/**
* Handle fetch requests for this plugin.
*/
function fetch($args, $request) {
$plugin = $this->getPLNPlugin();
$templateMgr = TemplateManager::getManager();
$journal = Request::getJournal();
$templateMgr->assign('journal', $journal);
$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');
$curlVersion = 'not installed';
if(function_exists('curl_version')) {
$versionArray = curl_version();
$curlVersion = $versionArray['version'];
}
$prerequisites = array(
'phpVersion' => PHP_VERSION,
'curlVersion' => $curlVersion,
'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());
$publishedArticlesDAO = DAORegistry::getDAO('PublishedArticleDAO');
$range = new DBResultRange(PLN_PLUGIN_PING_ARTICLE_COUNT);
$publishedArticles = $publishedArticlesDAO->getPublishedArticlesByJournalId($journal->getId(), $range, true);
$templateMgr->assign('articles', $publishedArticles);
$templateMgr->assign('pln_network', $plugin->getSetting($journal->getId(), 'pln_network'));
header('Content-Type: text/xml; charset=' . Config::getVar('i18n', 'client_charset'));
echo $templateMgr->fetch($plugin->getTemplateResource('ping.tpl'));
return true;
}
}