-
Notifications
You must be signed in to change notification settings - Fork 0
/
MetadataExportPlugin.inc.php
407 lines (338 loc) · 10.3 KB
/
MetadataExportPlugin.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?php
/**
* @file plugins/generic/metadataExport/MetadataExportPlugin.inc.php
*
* Copyright (c) 2013-2015 Simon Fraser University Library
* Copyright (c) 2003-2015 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class MetadataExportPlugin
* @ingroup plugins_generic_metadataExportPlugin
*
* @brief Metadata Export plugin class
*/
import('lib.pkp.classes.plugins.GenericPlugin');
class MetadataExportPlugin extends GenericPlugin {
/* Constructor */
function MetadataExportPlugin() {
parent::GenericPlugin();
$this->issueDao = DAORegistry::getDAO('IssueDAO');
}
/* @var XMLCustomWriter object */
var $doc;
/* @var issueDAO object */
var $issueDao;
/********************/
/* Metadata fields: */
/********************/
/* @var string Title of the article */
var $title;
/* @var array Authors of the article */
var $creators;
/* @var array Subjects of the article */
var $subjects;
/* @var string Abstracts of the article */
var $abstract;
/* @var string Publisher of the article */
var $publisher;
/* @var array Contributors of the article */
var $contributors;
/* @var string Publishing date of the article */
var $datePublished;
/* @var array Types of the files belonging to the article */
var $types;
/* @var array Formats of the files belonging to the article */
var $formats;
/* @var string Identifier of the article */
var $identifier;
/* @var array Sources of the article */
var $sources;
/* @var string Language of the article */
var $language;
/* @var array Related files of the article */
var $relations;
/* @var array Galley files belonging to the article */
var $galleyURLs;
/* @var array Supplementary files belonging to the article */
var $suppFileURLs;
/* @var string Copyright of the article */
var $copyright;
/**
* @copydoc PKPPlugin::register()
*/
function register($category, $path) {
if (parent::register($category, $path)) {
if ($this->getEnabled()) {
HookRegistry::register('PluginRegistry::loadCategory', array($this, 'callbackLoadCategory'));
HookRegistry::register('LoadHandler', array($this, 'callbackHandleContent'));
}
return true;
}
return false;
}
/**
* Register as a block plugin, even though this is a generic plugin.
* This will allow the plugin to behave as a block plugin
* @param $hookName String
* @param $args Array
* @return Boolean
*/
function callbackLoadCategory($hookName, $args) {
$category = $args[0];
$plugins =& $args[1]; // & operator necessary in this case
switch ($category) {
case 'blocks':
$this->import('MetadataExportBlockPlugin');
$blockPlugin = new MetadataExportBlockPlugin($this->getName());
$plugins[$blockPlugin->getSeq()][$blockPlugin->getPluginPath()] = $blockPlugin;
break;
}
return false;
}
/**
* Handle the request and generate the export file
* @param $hookName String
* @param $args Array
* @return Boolean
*/
function callbackHandleContent($hookName, $args) {
$templateMgr = TemplateManager::getManager();
$page = $args[0];
$op = $args[1];
if ($page == 'metadata') {
define('METADATA_EXPORT_PLUGIN_NAME', $this->getName());
define('HANDLER_CLASS', 'MetadataExportHandler');
$this->import('MetadataExportHandler');
return true;
}
return false;
}
/**
* @copydoc PKPPlugin::getTemplatePath()
*/
function getTemplatePath() {
return parent::getTemplatePath() . 'templates/';
}
/**
* @copydoc PKPPlugin::getName()
*/
function getName() {
return 'MetadataExportPlugin';
}
/**
* @copydoc PKPPlugin::getDisplayName()
*/
function getDisplayName() {
return __('plugins.generic.metadataExport.displayName');
}
/**
* @copydoc PKPPlugin::getDescription()
*/
function getDescription() {
return __('plugins.generic.metadataExport.description');
}
/**
* Get the name of the metadata format.
* Should be overridden by subclasses.
* @return String
*/
function getMetadataExportFormatName() {
assert(false);
}
/**
* Get the file extension of the export file.
* Should be overridden by subclasses.
* @return String
*/
function getFileExtension() {
assert(false);
}
/**
* Get the type of the XML's root node
* Should be overridden by subclasses.
* @return String
*/
function getRootElement() {
assert(false);
}
/**
* Generate the content of the text or XML file
* Should be overridden by subclasses.
* @param $journal Journal Object
* @param $articles Array of Article Objects
* @return Mixed (String or XMLCustomWriter Object)
*/
function getFileContent($journal, $articles) {
assert(false);
}
/**
* Identification as a reviewed article
* @return String
*/
function getType() {
return __('rt.metadata.pkp.peerReviewed');
}
/**
* Abbreviation for the term "issue"
* @return String
*/
function getVolumeAbbreviation() {
return __('issue.vol');
}
/**
* Identifier for publication type
* @return String
*/
function getTypeIdentifier() {
return 'info:eu-repo/semantics/article';
}
/**
* Identifier for publication version
* @return String
*/
function getVersionIdentifier() {
return 'info:eu-repo/semantics/publishedVersion';
}
/**
* Get the Copyright statement
* @param $copyrightHolder String
* @param $copyrightYear Int
* @return String
*/
function getCopyrightStatement($copyrightHolder, $copyrightYear) {
return __('submission.copyrightStatement', array('copyrightHolder' => $copyrightHolder, 'copyrightYear' => $copyrightYear));
}
/**
* Checks if the current download file is an XML file
* @return boolean
*/
function isXML() {
return $this->getFileExtension() == 'xml';
}
/**
* Initialize all metadata for the export file
* @param $journal Journal object
* @param $article Article object
*/
function _initData($journal, $article) {
$locale = $article->getLocale();
$issue = $this->issueDao->getIssueById($article->getIssueId(), $journal->getId());
// title
$this->title = $article->getLocalizedTitle();
// creators
$authors = $article->getAuthors();
for ($i = 0, $num = count($authors); $i < $num; $i++) {
$authorName = $authors[$i]->getFullName(true);
$affiliation = $authors[$i]->getLocalizedAffiliation();
if (!empty($affiliation)) {
$authorName .= '; ' . $affiliation;
}
$this->creators[] = $authorName;
}
// subject
$subjects = $article->getSubject();
$subjectsLocalized = explode(';', $subjects[$locale]);
foreach($subjectsLocalized as $subject) {
$this->subjects[] = trim($subject);
}
//description (=abstract)
$abstract = $article->getAbstract();
$this->abstract = $abstract[$locale];
// publisher
$this->publisher = $journal->getLocalizedTitle();
$publisherInstitution = $journal->getSetting('publisherInstitution');
if (!empty($publisherInstitution)) {
$this->publisher = $publisherInstitution;
}
// contributors
$contributors = $article->getSponsor();
$contributorsLocalized = explode(';', $contributors[$locale]);
foreach($contributorsLocalized as $contributors) {
$this->contributors[] = trim($contributors);
}
// date
$this->datePublished = date('Y-m-d', strtotime($article->getDatePublished()));
// type
$this->types = array($this->getType(), $this->getTypeIdentifier(), $this->getVersionIdentifier());
// formats and relations
$galleyFormats = array();
$suppFileFormats = array();
foreach ($article->getData('galleys') as $galley) {
$galleyFormats[] = $galley->getFileType();
$this->galleyURLs[] = Request::url($journal->getPath(), 'article', 'view', array($article->getId(), $galley->getId()));
}
foreach ($article->getSuppFiles() as $suppFile) {
$suppFileFormats[] = $suppFile->getFileType();
$this->suppFileURLs[] = Request::url($journal->getPath(), 'article', 'downloadSuppFile', array($article->getId(), $suppFile->getId()));
}
$this->formats = array_merge($galleyFormats, $suppFileFormats);
$this->relations = array_merge($this->galleyURLs, $this->suppFileURLs);
//identifier
$this->identifier = Request::url($journal->getPath(), 'article', 'view', array($article->getId()));
// source
foreach($journal->getTitle() as $journalTitle) {
$this->sources[] = $journalTitle . '; ' . $this->getVolumeAbbreviation() . ' ' . $issue->getData('volume');
}
if ($issue->getData('pub-id::doi')) {
$this->sources[] = $issue->getData('pub-id::doi');
}
//language
$this->language = $article->getLanguage();
// copyright
$copyrightHolder = $article->getLocalizedCopyrightHolder();
$copyrightYear = $article->getCopyrightYear();
$licenseUrl = $article->getDefaultLicenseUrl();
$this->copyright = $this->getCopyrightStatement($copyrightHolder, $copyrightYear);
if ($licenseUrl) {
$this->copyright .= ', ' . $licenseUrl;
}
}
/**
* Unset all metadata class variables before they are initialized in _initData()
*/
function _unsetData() {
unset($this->title);
unset($this->creators);
unset($this->subjects);
unset($this->abstract);
unset($this->publisher);
unset($this->contributors);
unset($this->datePublished);
unset($this->types);
unset($this->formats);
unset($this->identifier);
unset($this->sources);
unset($this->language);
unset($this->relations);
unset($this->galleyURLs);
unset($this->suppFileURLs);
unset($this->copyright);
}
/**
* Generate a text file (.bib, .ris etc.)
* @param $journal Journal object
* @param $article Array of Article objects
* @param $name String
*/
function createTextFile($journal, $articles) {
$contents = $this->getFileContent($journal, $articles);
header('content-type: text/plain');
header('content-disposition: attachment; filename=metadata.' . $this->getFileExtension());
echo $contents;
}
/**
* Generate an XML file
* @param $journal Journal 0bject
* @param $articles Array of Article objects
*/
function createXmlFile($journal, $articles) {
AppLocale::requireComponents(array(LOCALE_COMPONENT_APPLICATION_COMMON));
$this->doc = XMLCustomWriter::createDocument();
$contents = $this->getFileContent($journal, $articles);
header('Content-Type: application/xml');
header('Cache-Control: private');
header('Content-Disposition: attachment; filename=metadata.' . $this->getFileExtension());
XMLCustomWriter::printXML($this->doc);
}
}
?>