-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepecPlugin.php
More file actions
152 lines (127 loc) · 4.5 KB
/
RepecPlugin.php
File metadata and controls
152 lines (127 loc) · 4.5 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
<?php
/**
* @file plugins/generic/repec/RepecPlugin.php
*
* @class RepecPlugin
* @ingroup plugins_generic_repec
*
* @brief Publishes OJS journal metadata as RePEc/ReDIF templates.
*/
namespace APP\plugins\generic\repec;
use APP\core\Application;
use APP\plugins\generic\repec\classes\RepecLegacyHandleMap;
use APP\plugins\generic\repec\classes\RepecSettingsForm;
use APP\plugins\generic\repec\pages\RepecHandler;
use APP\template\TemplateManager;
use PKP\config\Config;
use PKP\core\JSONMessage;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
class RepecPlugin extends GenericPlugin
{
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);
if (!$success) {
return false;
}
$this->addLocaleData();
if (!Application::isInstalled() || Application::isUnderMaintenance() || defined('RUNNING_UPGRADE')) {
return true;
}
Hook::add('LoadHandler', [$this, 'setupRepecHandler']);
return true;
}
public function getDisplayName()
{
return __('plugins.generic.repec.displayName');
}
public function getName()
{
return 'repecplugin';
}
public function getDescription()
{
return __('plugins.generic.repec.description');
}
public function isSitePlugin()
{
return !Application::get()->getRequest()->getContext();
}
public function getActions($request, $verb)
{
$router = $request->getRouter();
$context = $request->getContext();
$contextId = $context ? $context->getId() : 0;
return array_merge(
$this->getEnabled($contextId) ? array(
new LinkAction(
'settings',
new AjaxModal(
$router->url($request, null, null, 'manage', null, array(
'verb' => 'settings',
'plugin' => $this->getName(),
'category' => 'generic',
)),
$this->getDisplayName()
),
__('manager.plugins.settings'),
null
),
) : array(),
parent::getActions($request, $verb)
);
}
public function manage($args, $request)
{
switch ($request->getUserVar('verb')) {
case 'settings':
$context = $request->getContext();
$contextId = $context ? $context->getId() : 0;
$templateMgr = TemplateManager::getManager($request);
$templateMgr->registerPlugin('function', 'plugin_url', array($this, 'smartyPluginUrl'));
$form = new RepecSettingsForm($this, $contextId);
if ($request->getUserVar('save')) {
$form->readInputData();
if ($form->validate()) {
$form->execute();
return new JSONMessage(true);
}
} else {
$form->initData();
}
return new JSONMessage(true, $form->fetch($request));
case 'downloadLegacyHandles':
$context = $request->getContext();
if (!$context) {
return parent::manage($args, $request);
}
$parser = new RepecLegacyHandleMap();
$contents = $parser->encode($parser->decode($this->getSetting($context->getId(), 'legacyHandles')));
header('Content-Type: application/json; charset=UTF-8');
header('Content-Disposition: attachment; filename="repec-legacy-handles-' . $context->getPath() . '.json"');
echo $contents;
exit();
}
return parent::manage($args, $request);
}
public function setupRepecHandler($hookName, $params)
{
$page = &$params[0];
$op = &$params[1];
$handler = &$params[3];
$localePattern = '/^[a-z]{2}(?:_[A-Z]{2})?$/';
if ($page !== 'repec' && !($op === 'repec' && preg_match($localePattern, (string) $page))) {
return false;
}
$page = 'repec';
$op = 'index';
$handler = new RepecHandler();
return true;
}
}
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\repec\RepecPlugin', '\RepecPlugin');
}