-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetadataNormalizerPlugin.php
More file actions
153 lines (133 loc) · 4.75 KB
/
MetadataNormalizerPlugin.php
File metadata and controls
153 lines (133 loc) · 4.75 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
153
<?php
/**
* @file plugins/generic/metadataNormalizer/MetadataNormalizerPlugin.php
*
* Copyright (c) 2014-2025 Simon Fraser University
* Copyright (c) 2003-2025 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file LICENSE.
*
* @class MetadataNormalizerPlugin
* @brief Unified plugin for normalizing submission metadata (keywords, title, abstract)
*
* This plugin automatically cleans and normalizes metadata fields to ensure:
* - Clean indexing for academic databases
* - Consistent formatting across submissions
* - Removal of copy-paste artifacts and formatting issues
* - Improved discoverability and metadata quality
*/
namespace APP\plugins\generic\metadataNormalizer;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use APP\core\Application;
class MetadataNormalizerPlugin extends GenericPlugin
{
/**
* @copydoc Plugin::register()
*/
public function register($category, $path, $mainContextId = null): bool
{
$success = parent::register($category, $path, $mainContextId);
if ($success && $this->getEnabled($mainContextId)) {
// Register template display hook for JavaScript injection
Hook::add('TemplateManager::display', [$this, 'handleTemplateDisplay']);
}
return $success;
}
/**
* Hook callback: Inject JavaScript files on relevant pages
*
* @param string $hookName Hook name
* @param array $args Hook arguments [TemplateManager, template, sendContentType, charset, output]
* @return bool Hook processing status
*/
public function handleTemplateDisplay(string $hookName, array $args): bool
{
$templateMgr = $args[0];
$template = $args[1];
// Only inject scripts on relevant pages
if (!$this->shouldInjectScripts($template)) {
return false;
}
$request = $this->getRequest();
$baseUrl = $request->getBaseUrl();
$pluginPath = $this->getPluginPath();
// Inject shared utilities first
$sharedUrl = $baseUrl . '/' . $pluginPath . '/js/shared.js';
$templateMgr->addJavaScript(
'metadataNormalizer-shared',
$sharedUrl,
[
'contexts' => 'frontend',
'priority' => STYLE_SEQUENCE_NORMAL
]
);
// Inject keywords normalizer
$keywordsUrl = $baseUrl . '/' . $pluginPath . '/js/keywordsNormalizer.js';
$templateMgr->addJavaScript(
'metadataNormalizer-keywords',
$keywordsUrl,
[
'contexts' => 'frontend',
'priority' => STYLE_SEQUENCE_NORMAL
]
);
// Inject title & abstract normalizer
$metadataUrl = $baseUrl . '/' . $pluginPath . '/js/metadataNormalizer.js';
$templateMgr->addJavaScript(
'metadataNormalizer-fields',
$metadataUrl,
[
'contexts' => 'frontend',
'priority' => STYLE_SEQUENCE_NORMAL
]
);
return false; // Don't interrupt other plugins
}
/**
* Determine if scripts should be injected for this template
*
* @param string $template Template path
* @return bool True if scripts should be injected
*/
private function shouldInjectScripts(string $template): bool
{
// Pages where metadata forms appear
$relevantTemplates = [
'submission/form', // Author submission wizard
'workflow', // Editorial workflow
'authorDashboard', // Author dashboard
'controllers/modals/submissionMetadata',// Metadata edit modals
'frontend/pages/submission', // Submission pages
'controllers/tab/settings', // Settings tabs
'controllers/grid/submissions' // Submission grids
];
foreach ($relevantTemplates as $pattern) {
if (str_contains($template, $pattern)) {
return true;
}
}
return false;
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName(): string
{
return __('plugins.generic.metadataNormalizer.displayName');
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription(): string
{
return __('plugins.generic.metadataNormalizer.description');
}
/**
* @copydoc Plugin::getInstallMigration()
*/
public function getInstallMigration()
{
// No database changes required - client-side only
return null;
}
}