-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathJatsTemplatePlugin.php
executable file
·96 lines (82 loc) · 2.46 KB
/
JatsTemplatePlugin.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
<?php
/**
* @file JatsTemplatePlugin.inc.php
*
* Copyright (c) 2003-2022 Simon Fraser University
* Copyright (c) 2003-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @brief JATS template plugin
*/
namespace APP\plugins\generic\jatsTemplate;
use APP\core\Application;
use APP\plugins\generic\jatsTemplate\classes\Article;
use APP\template\TemplateManager;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
class JatsTemplatePlugin extends GenericPlugin
{
/**
* @copydoc Plugin::register()
*/
public function register($category, $path, $mainContextId = null)
{
$success = parent::register($category, $path, $mainContextId);
$this->addLocaleData();
if ($success && $this->getEnabled()) {
Hook::add('OAIMetadataFormat_JATS::findJats', [$this, 'callbackFindJats']);
Hook::add('LoadHandler', [$this, 'callbackHandleContent']);
}
return $success;
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName()
{
return __('plugins.generic.jatsTemplate.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription()
{
return __('plugins.generic.jatsTemplate.description');
}
/**
* Prepare JATS template document
* @param $hookName string
* @param $args array
*/
public function callbackFindJats($hookName, $args)
{
$plugin =& $args[0];
$record =& $args[1];
$candidateFiles =& $args[2];
$doc =& $args[3];
if (!$doc && empty($candidateFiles)) {
$request = Application::get()->getRequest();
$doc = new Article();
$doc->convertOAIToXml($record, $request);
}
return false;
}
/**
* Declare the handler function to process the actual page PATH
* @param $hookName string The name of the invoked hook
* @param $args array Hook parameters
* @return boolean Hook handling status
*/
public function callbackHandleContent($hookName, $args)
{
$request = Application::get()->getRequest();
$templateMgr = TemplateManager::getManager($request);
$page =& $args[0];
$op =& $args[1];
if ($page == 'jatsTemplate' && $op == 'download') {
$args[3] = new JatsTemplateDownloadHandler($this);
return true;
}
return false;
}
}