-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPreprintUrlRenamePlugin.php
77 lines (67 loc) · 2.4 KB
/
PreprintUrlRenamePlugin.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
<?php
/**
* @file PreprintUrlRenamePlugin.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PreprintUrlRenamePlugin
* @brief Renames the "preprint" part of OPS URLs to something else.
*/
namespace APP\plugins\generic\preprintUrlRename;
use APP\core\Application;
use PKP\config\Config;
use PKP\core\Registry;
use PKP\facades\Locale;
use PKP\plugins\GenericPlugin;
use PKP\plugins\Hook;
use PKP\core\PKPRequest;
class PreprintUrlRenamePlugin extends GenericPlugin
{
/**
* @copydoc Plugin::register()
*
* @param null|mixed $mainContextId
*/
public function register($category, $path, $mainContextId = null): bool
{
if (parent::register($category, $path, $mainContextId)) {
if ($this->getEnabled($mainContextId)) {
// When OPS generates URLs referring to 'preprint', change it to 'submission'
Hook::add('PKPPageRouter::url', function(string $hookName, PKPRequest &$request, ?string &$newContext, ?string &$page, ?string &$op, ?array &$path, ?array &$params, ?string &$anchor, bool &$escape, ?string &$urlLocaleForPage, ?string &$result) : bool {
if ($page == 'preprint') $page = 'submission';
return Hook::CONTINUE;
});
// When OPS receives requests for 'submission', map it to the preprint handler
Hook::add('LoadHandler', function(string $hookName, array $params) : bool {
$page =& $params[0];
$sourceFile =& $params[2];
if ($page != 'submission') return Hook::CONTINUE;
$page = 'preprint';
$sourceFile = 'pages/preprint/index.php';
return Hook::CONTINUE;
});
}
return true;
}
return false;
}
/**
* @copydoc Plugin::getDisplayName()
*/
public function getDisplayName()
{
return 'Preprint URL rename plugin';
}
/**
* @copydoc Plugin::getDescription()
*/
public function getDescription()
{
return 'Renames the "preprint" part of OPS URLs to something else.';
}
}
if (!PKP_STRICT_MODE) {
class_alias('\APP\plugins\generic\preprintUrlRename\PreprintUrlRenamePlugin', '\PreprintUrlRenamePlugin');
}