forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PKPApplication.php
777 lines (699 loc) · 27.5 KB
/
PKPApplication.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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
<?php
/**
* @file classes/core/PKPApplication.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2000-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class PKPApplication
*
* @ingroup core
*
* @brief Class describing this application.
*
*/
namespace PKP\core;
use APP\core\Application;
use APP\core\Request;
use DateTime;
use DateTimeZone;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Database\Events\QueryExecuted;
use Illuminate\Database\MySqlConnection;
use Illuminate\Support\Facades\DB;
use PKP\core\PKPSessionGuard;
use PKP\config\Config;
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use PKP\security\Role;
use PKP\site\VersionDAO;
use PKP\submission\RepresentationDAOInterface;
interface iPKPApplicationInfoProvider
{
/**
* Get the top-level context DAO.
*/
public static function getContextDAO();
/**
* Get the representation DAO.
*/
public static function getRepresentationDAO(): RepresentationDAOInterface;
/**
* Get a SubmissionSearchIndex instance.
*/
public static function getSubmissionSearchIndex();
/**
* Get a SubmissionSearchDAO instance.
*/
public static function getSubmissionSearchDAO();
/**
* Get the stages used by the application.
*/
public static function getApplicationStages();
/**
* Get the file directory array map used by the application.
* should return array('context' => ..., 'submission' => ...)
*/
public static function getFileDirectories();
/**
* Returns the context type for this application.
*/
public static function getContextAssocType();
}
abstract class PKPApplication implements iPKPApplicationInfoProvider
{
public const PHP_REQUIRED_VERSION = '8.0.2';
// Constant used to distinguish between editorial and author workflows
public const WORKFLOW_TYPE_EDITORIAL = 'editorial';
public const WORKFLOW_TYPE_AUTHOR = 'author';
public const API_VERSION = 'v1';
public const ROUTE_COMPONENT = 'component';
public const ROUTE_PAGE = 'page';
public const ROUTE_API = 'api';
public const CONTEXT_SITE = 0;
public const CONTEXT_ID_NONE = 0;
public const CONTEXT_ID_ALL = '_';
public const REVIEW_ROUND_NONE = 0;
public const ASSOC_TYPE_PRODUCTION_ASSIGNMENT = 0x0000202;
public const ASSOC_TYPE_SUBMISSION_FILE = 0x0000203;
public const ASSOC_TYPE_REVIEW_RESPONSE = 0x0000204;
public const ASSOC_TYPE_REVIEW_ASSIGNMENT = 0x0000205;
public const ASSOC_TYPE_SUBMISSION_EMAIL_LOG_ENTRY = 0x0000206;
public const ASSOC_TYPE_WORKFLOW_STAGE = 0x0000207;
public const ASSOC_TYPE_NOTE = 0x0000208;
public const ASSOC_TYPE_REPRESENTATION = 0x0000209;
public const ASSOC_TYPE_ANNOUNCEMENT = 0x000020A;
public const ASSOC_TYPE_REVIEW_ROUND = 0x000020B;
public const ASSOC_TYPE_SUBMISSION_FILES = 0x000020F;
public const ASSOC_TYPE_PLUGIN = 0x0000211;
public const ASSOC_TYPE_SECTION = 0x0000212;
public const ASSOC_TYPE_CATEGORY = 0x000020D;
public const ASSOC_TYPE_USER = 0x0001000; // This value used because of bug #6068
public const ASSOC_TYPE_USER_GROUP = 0x0100002;
public const ASSOC_TYPE_CITATION = 0x0100003;
public const ASSOC_TYPE_AUTHOR = 0x0100004;
public const ASSOC_TYPE_EDITOR = 0x0100005;
public const ASSOC_TYPE_USER_ROLES = 0x0100007;
public const ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES = 0x0100008;
public const ASSOC_TYPE_SUBMISSION = 0x0100009;
public const ASSOC_TYPE_QUERY = 0x010000a;
public const ASSOC_TYPE_QUEUED_PAYMENT = 0x010000b;
public const ASSOC_TYPE_PUBLICATION = 0x010000c;
public const ASSOC_TYPE_ACCESSIBLE_FILE_STAGES = 0x010000d;
public const ASSOC_TYPE_NONE = 0x010000e;
public const ASSOC_TYPE_DECISION_TYPE = 0x010000f;
// Constant used in UsageStats for submission files that are not full texts
public const ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER = 0x0000213;
public $enabledProducts = [];
public $allProducts;
/**
* Constructor
*/
public function __construct()
{
if (!defined('PKP_STRICT_MODE')) {
define('PKP_STRICT_MODE', (bool) Config::getVar('general', 'strict'));
class_alias('\PKP\config\Config', '\Config');
class_alias('\PKP\core\Registry', '\Registry');
class_alias('\PKP\core\Core', '\Core');
class_alias('\PKP\cache\CacheManager', '\CacheManager');
class_alias('\PKP\handler\PKPHandler', '\PKPHandler');
class_alias('\PKP\payment\QueuedPayment', '\QueuedPayment'); // QueuedPayment instances may be serialized
}
// If not in strict mode, globally expose constants on this class.
if (!PKP_STRICT_MODE) {
foreach ([
'WORKFLOW_TYPE_EDITORIAL', 'WORKFLOW_TYPE_AUTHOR', 'PHP_REQUIRED_VERSION',
'API_VERSION',
'ROUTE_COMPONENT', 'ROUTE_PAGE', 'ROUTE_API',
'CONTEXT_SITE', 'CONTEXT_ID_NONE', 'CONTEXT_ID_ALL', 'REVIEW_ROUND_NONE',
'ASSOC_TYPE_PRODUCTION_ASSIGNMENT',
'ASSOC_TYPE_SUBMISSION_FILE',
'ASSOC_TYPE_REVIEW_RESPONSE',
'ASSOC_TYPE_REVIEW_ASSIGNMENT',
'ASSOC_TYPE_SUBMISSION_EMAIL_LOG_ENTRY',
'ASSOC_TYPE_WORKFLOW_STAGE',
'ASSOC_TYPE_NOTE',
'ASSOC_TYPE_REPRESENTATION',
'ASSOC_TYPE_ANNOUNCEMENT',
'ASSOC_TYPE_REVIEW_ROUND',
'ASSOC_TYPE_SUBMISSION_FILES',
'ASSOC_TYPE_PLUGIN',
'ASSOC_TYPE_SECTION',
'ASSOC_TYPE_CATEGORY',
'ASSOC_TYPE_USER',
'ASSOC_TYPE_USER_GROUP',
'ASSOC_TYPE_CITATION',
'ASSOC_TYPE_AUTHOR',
'ASSOC_TYPE_EDITOR',
'ASSOC_TYPE_USER_ROLES',
'ASSOC_TYPE_ACCESSIBLE_WORKFLOW_STAGES',
'ASSOC_TYPE_SUBMISSION',
'ASSOC_TYPE_QUERY',
'ASSOC_TYPE_QUEUED_PAYMENT',
'ASSOC_TYPE_PUBLICATION',
'ASSOC_TYPE_ACCESSIBLE_FILE_STAGES',
'ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER',
] as $constantName) {
if (!defined($constantName)) {
define($constantName, constant('self::' . $constantName));
}
}
if (!class_exists('\PKPApplication')) {
class_alias('\PKP\core\PKPApplication', '\PKPApplication');
}
}
ini_set('display_errors', Config::getVar('debug', 'display_errors', ini_get('display_errors')));
if (!static::isInstalled() && !PKPSessionGuard::isSessionDisable()) {
PKPSessionGuard::disableSession();
}
Registry::set('application', $this);
$microTime = Core::microtime();
Registry::set('system.debug.startTime', $microTime);
$this->initializeLaravelContainer();
PKPString::initialize();
// Load default locale files
Locale::registerPath(BASE_SYS_DIR . '/lib/pkp/locale');
if (static::isInstalled() && !static::isUpgrading()) {
$versionDao = DAORegistry::getDAO('VersionDAO'); /** @var VersionDAO $versionDao */
$appVersion = $versionDao->getCurrentVersion()->getVersionString();
Registry::set('appVersion', $appVersion);
}
}
/**
* Initialize Laravel container and register service providers
*/
public function initializeLaravelContainer(): void
{
// Ensure multiple calls to this function don't cause trouble
static $containerInitialized = false;
if ($containerInitialized) {
return;
}
$containerInitialized = true;
// Initialize Laravel's container and set it globally
$laravelContainer = new PKPContainer();
$laravelContainer->registerConfiguredProviders();
$this->initializeTimeZone();
if (Config::getVar('database', 'debug')) {
DB::listen(fn (QueryExecuted $query) => error_log("Database query\n{$query->sql}\n" . json_encode($query->bindings)));
}
}
/**
* Setup the internal time zone for the database and PHP.
*/
protected function initializeTimeZone(): void
{
$timeZone = null;
// Loads the time zone from the configuration file
if ($setting = Config::getVar('general', 'time_zone')) {
try {
$timeZone = (new DateTimeZone($setting))->getName();
} catch (Exception $e) {
$setting = strtolower($setting);
foreach (DateTimeZone::listIdentifiers() as $identifier) {
// Backward compatibility identification
if ($setting == strtolower(preg_replace(['/^\w+\//', '/_/'], ['', ' '], $identifier))) {
$timeZone = $identifier;
break;
}
}
}
}
// Set the default timezone
date_default_timezone_set($timeZone ?: ini_get('date.timezone') ?: 'UTC');
// Synchronize the database time zone
if (Application::isInstalled()) {
// Retrieve the current offset
$offset = (new DateTime())->format('P');
$statement = DB::connection() instanceof MySqlConnection
? "SET time_zone = '{$offset}'"
: "SET TIME ZONE INTERVAL '{$offset}' HOUR TO MINUTE";
DB::statement($statement);
}
}
/**
* Get the current application object
*
* @return Application
*/
public static function get()
{
return Registry::get('application');
}
/**
* Get the unique site ID
*/
public function getUUID(): string
{
$site = $this->getRequest()->getSite();
$uniqueSiteId = $site->getUniqueSiteID();
if (!strlen((string) $uniqueSiteId)) {
$uniqueSiteId = PKPString::generateUUID();
$site->setUniqueSiteID($uniqueSiteId);
/** @var SiteDAO */
$siteDao = DAORegistry::getDAO('SiteDAO');
$siteDao->updateObject($site);
}
return $uniqueSiteId;
}
/**
* Return a HTTP client implementation.
*
* @return Client
*/
public function getHttpClient()
{
$application = Application::get();
$userAgent = $application->getName() . '/';
if (static::isInstalled() && !static::isUpgrading()) {
/** @var \PKP\site\VersionDAO */
$versionDao = DAORegistry::getDAO('VersionDAO');
$currentVersion = $versionDao->getCurrentVersion();
$userAgent .= $currentVersion->getVersionString();
} else {
$userAgent .= '?';
}
return new Client([
'proxy' => [
'http' => Config::getVar('proxy', 'http_proxy', null),
'https' => Config::getVar('proxy', 'https_proxy', null),
],
'headers' => [
'User-Agent' => $userAgent,
],
'allow_redirects' => ['strict' => true],
]);
}
/**
* Get the request implementation singleton
*
* @return Request
*/
public function getRequest()
{
$request = &Registry::get('request', true, null); // Ref req'd
if (is_null($request)) {
// Implicitly set request by ref in the registry
$request = new Request();
}
return $request;
}
/**
* Get the dispatcher implementation singleton
*
* @return Dispatcher
*/
public function getDispatcher()
{
$dispatcher = &Registry::get('dispatcher', true, null); // Ref req'd
if (is_null($dispatcher)) {
// Implicitly set dispatcher by ref in the registry
$dispatcher = new Dispatcher();
// Inject dependency
$dispatcher->setApplication(PKPApplication::get());
// Inject router configuration
$dispatcher->addRouterName('\PKP\core\APIRouter', self::ROUTE_API);
$dispatcher->addRouterName('\PKP\core\PKPComponentRouter', self::ROUTE_COMPONENT);
$dispatcher->addRouterName('\APP\core\PageRouter', self::ROUTE_PAGE);
}
return $dispatcher;
}
/**
* This executes the application by delegating the
* request to the dispatcher.
*/
public function execute()
{
// Dispatch the request to the correct handler
$dispatcher = $this->getDispatcher();
$dispatcher->dispatch($this->getRequest());
}
/**
* Get the symbolic name of this application
*
* @return string
*/
public static function getName()
{
return 'pkp-lib';
}
/**
* Get the locale key for the name of this application.
*
* @return string
*/
abstract public function getNameKey();
/**
* Get the name of the context for this application
*/
abstract public function getContextName(): string;
/**
* Get the URL to the XML descriptor for the current version of this
* application.
*
* @return string
*/
abstract public function getVersionDescriptorUrl();
/**
* This function retrieves all enabled product versions once
* from the database and caches the result for further
* access.
*
* @param string $category
* @param int $mainContextId Optional ID of the top-level context
* (e.g. Journal, Conference, Press) to query for enabled products
*
* @return array
*/
public function getEnabledProducts($category = null, $mainContextId = null)
{
if (is_null($mainContextId)) {
$request = $this->getRequest();
$router = $request->getRouter();
$mainContextId = $router->getContext($request)?->getId() ?? self::CONTEXT_SITE;
}
if (!isset($this->enabledProducts[$mainContextId])) {
$versionDao = DAORegistry::getDAO('VersionDAO'); /** @var \PKP\site\VersionDAO $versionDao */
$this->enabledProducts[$mainContextId] = $versionDao->getCurrentProducts($mainContextId);
}
if (is_null($category)) {
return $this->enabledProducts[$mainContextId];
} elseif (isset($this->enabledProducts[$mainContextId][$category])) {
return $this->enabledProducts[$mainContextId][$category];
} else {
return [];
}
}
/**
* Get the list of plugin categories for this application.
*
* @return array
*/
abstract public function getPluginCategories();
/**
* Return the current version of the application.
*
* @return \PKP\site\Version
*/
public function getCurrentVersion()
{
$currentVersion = $this->getEnabledProducts('core');
assert(count($currentVersion)) == 1;
return $currentVersion[$this->getName()];
}
/**
* Get the map of DAOName => full.class.Path for this application.
*
* @return array
*/
public function getDAOMap()
{
return [
'AnnouncementTypeDAO' => 'PKP\announcement\AnnouncementTypeDAO',
'CitationDAO' => 'PKP\citation\CitationDAO',
'ControlledVocabDAO' => 'PKP\controlledVocab\ControlledVocabDAO',
'ControlledVocabEntryDAO' => 'PKP\controlledVocab\ControlledVocabEntryDAO',
'DataObjectTombstoneDAO' => 'PKP\tombstone\DataObjectTombstoneDAO',
'DataObjectTombstoneSettingsDAO' => 'PKP\tombstone\DataObjectTombstoneSettingsDAO',
'FilterDAO' => 'PKP\filter\FilterDAO',
'FilterGroupDAO' => 'PKP\filter\FilterGroupDAO',
'GenreDAO' => 'PKP\submission\GenreDAO',
'InterestDAO' => 'PKP\user\InterestDAO',
'InterestEntryDAO' => 'PKP\user\InterestEntryDAO',
'LibraryFileDAO' => 'PKP\context\LibraryFileDAO',
'NavigationMenuDAO' => 'PKP\navigationMenu\NavigationMenuDAO',
'NavigationMenuItemDAO' => 'PKP\navigationMenu\NavigationMenuItemDAO',
'NavigationMenuItemAssignmentDAO' => 'PKP\navigationMenu\NavigationMenuItemAssignmentDAO',
'NoteDAO' => 'PKP\note\NoteDAO',
'NotificationDAO' => 'PKP\notification\NotificationDAO',
'NotificationSettingsDAO' => 'PKP\notification\NotificationSettingsDAO',
'NotificationSubscriptionSettingsDAO' => 'PKP\notification\NotificationSubscriptionSettingsDAO',
'PluginGalleryDAO' => 'PKP\plugins\PluginGalleryDAO',
'PluginSettingsDAO' => 'PKP\plugins\PluginSettingsDAO',
'QueuedPaymentDAO' => 'PKP\payment\QueuedPaymentDAO',
'ReviewFilesDAO' => 'PKP\submission\ReviewFilesDAO',
'ReviewFormDAO' => 'PKP\reviewForm\ReviewFormDAO',
'ReviewFormElementDAO' => 'PKP\reviewForm\ReviewFormElementDAO',
'ReviewFormResponseDAO' => 'PKP\reviewForm\ReviewFormResponseDAO',
'ReviewRoundDAO' => 'PKP\submission\reviewRound\ReviewRoundDAO',
'RoleDAO' => 'PKP\security\RoleDAO',
'ScheduledTaskDAO' => 'PKP\scheduledTask\ScheduledTaskDAO',
'SiteDAO' => 'PKP\site\SiteDAO',
'SubEditorsDAO' => 'PKP\context\SubEditorsDAO',
'SubmissionAgencyDAO' => 'PKP\submission\SubmissionAgencyDAO',
'SubmissionAgencyEntryDAO' => 'PKP\submission\SubmissionAgencyEntryDAO',
'SubmissionCommentDAO' => 'PKP\submission\SubmissionCommentDAO',
'SubmissionDisciplineDAO' => 'PKP\submission\SubmissionDisciplineDAO',
'SubmissionDisciplineEntryDAO' => 'PKP\submission\SubmissionDisciplineEntryDAO',
'SubmissionEmailLogDAO' => 'PKP\log\SubmissionEmailLogDAO',
'QueryDAO' => 'PKP\query\QueryDAO',
'SubmissionKeywordDAO' => 'PKP\submission\SubmissionKeywordDAO',
'SubmissionKeywordEntryDAO' => 'PKP\submission\SubmissionKeywordEntryDAO',
'SubmissionSubjectDAO' => 'PKP\submission\SubmissionSubjectDAO',
'SubmissionSubjectEntryDAO' => 'PKP\submission\SubmissionSubjectEntryDAO',
'TemporaryFileDAO' => 'PKP\file\TemporaryFileDAO',
'TemporaryInstitutionsDAO' => 'PKP\statistics\TemporaryInstitutionsDAO',
'VersionDAO' => 'PKP\site\VersionDAO',
'WorkflowStageDAO' => 'PKP\workflow\WorkflowStageDAO',
'XMLDAO' => 'PKP\db\XMLDAO',
];
}
/**
* Return the fully-qualified (e.g. page.name.ClassNameDAO) name of the
* given DAO.
*
* @param string $name
*
* @return string
*/
public function getQualifiedDAOName($name)
{
$map = &Registry::get('daoMap', true, $this->getDAOMap()); // Ref req'd
if (isset($map[$name])) {
return $map[$name];
}
return null;
}
/**
* Get a mapping of license URL to license locale key for common
* creative commons licenses.
*
* @return array
*/
public static function getCCLicenseOptions()
{
return [
'https://creativecommons.org/licenses/by-nc-nd/4.0' => 'submission.license.cc.by-nc-nd4',
'https://creativecommons.org/licenses/by-nc/4.0' => 'submission.license.cc.by-nc4',
'https://creativecommons.org/licenses/by-nc-sa/4.0' => 'submission.license.cc.by-nc-sa4',
'https://creativecommons.org/licenses/by-nd/4.0' => 'submission.license.cc.by-nd4',
'https://creativecommons.org/licenses/by/4.0' => 'submission.license.cc.by4',
'https://creativecommons.org/licenses/by-sa/4.0' => 'submission.license.cc.by-sa4'
];
}
/**
* Get the Creative Commons license badge associated with a given
* license URL.
*
* @param ?string $ccLicenseURL URL to creative commons license
* @param ?string $locale Optional locale to return badge in
*
* @return ?string HTML code for CC license
*/
public function getCCLicenseBadge($ccLicenseURL, $locale = null)
{
if (!$ccLicenseURL) {
return null;
}
$licenseKeyMap = [
'|http[s]?://(www\.)?creativecommons.org/licenses/by-nc-nd/4.0[/]?|' => 'submission.license.cc.by-nc-nd4.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by-nc/4.0[/]?|' => 'submission.license.cc.by-nc4.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by-nc-sa/4.0[/]?|' => 'submission.license.cc.by-nc-sa4.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by-nd/4.0[/]?|' => 'submission.license.cc.by-nd4.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by/4.0[/]?|' => 'submission.license.cc.by4.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by-sa/4.0[/]?|' => 'submission.license.cc.by-sa4.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by-nc-nd/3.0[/]?|' => 'submission.license.cc.by-nc-nd3.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by-nc/3.0[/]?|' => 'submission.license.cc.by-nc3.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by-nc-sa/3.0[/]?|' => 'submission.license.cc.by-nc-sa3.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by-nd/3.0[/]?|' => 'submission.license.cc.by-nd3.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by/3.0[/]?|' => 'submission.license.cc.by3.footer',
'|http[s]?://(www\.)?creativecommons.org/licenses/by-sa/3.0[/]?|' => 'submission.license.cc.by-sa3.footer'
];
$locale ??= Locale::getLocale();
foreach ($licenseKeyMap as $pattern => $key) {
if (preg_match($pattern, $ccLicenseURL)) {
return __($key, [], $locale);
}
}
return null;
}
/**
* Get a mapping of role keys and i18n key names.
*
* @param bool $contextOnly If false, also returns site-level roles (Site admin)
* @param array|null $roleIds Only return role names of these IDs
*
* @return array
*/
public static function getRoleNames($contextOnly = false, $roleIds = null)
{
$siteRoleNames = [Role::ROLE_ID_SITE_ADMIN => 'user.role.siteAdmin'];
$appRoleNames = [
Role::ROLE_ID_MANAGER => 'user.role.manager',
Role::ROLE_ID_SUB_EDITOR => 'user.role.subEditor',
Role::ROLE_ID_ASSISTANT => 'user.role.assistant',
Role::ROLE_ID_AUTHOR => 'user.role.author',
Role::ROLE_ID_REVIEWER => 'user.role.reviewer',
Role::ROLE_ID_READER => 'user.role.reader',
];
$roleNames = $contextOnly ? $appRoleNames : $siteRoleNames + $appRoleNames;
if (!empty($roleIds)) {
$roleNames = array_intersect_key($roleNames, array_flip($roleIds));
}
return $roleNames;
}
/**
* Get a mapping of roles allowed to access particular workflows
*
* @return array
*/
public static function getWorkflowTypeRoles()
{
return [
self::WORKFLOW_TYPE_EDITORIAL => [Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_ASSISTANT],
self::WORKFLOW_TYPE_AUTHOR => [Role::ROLE_ID_SITE_ADMIN, Role::ROLE_ID_MANAGER, Role::ROLE_ID_SUB_EDITOR, Role::ROLE_ID_AUTHOR],
];
}
/**
* Get the name of a workflow stage
*
* @param int $stageId One of the WORKFLOW_STAGE_* constants
*/
public static function getWorkflowStageName(int $stageId): string
{
return match ($stageId) {
WORKFLOW_STAGE_ID_SUBMISSION => 'submission.submission',
WORKFLOW_STAGE_ID_INTERNAL_REVIEW => 'workflow.review.internalReview',
WORKFLOW_STAGE_ID_EXTERNAL_REVIEW => 'workflow.review.externalReview',
WORKFLOW_STAGE_ID_EDITING => 'submission.editorial',
WORKFLOW_STAGE_ID_PRODUCTION => 'submission.production',
default => new Exception('Name requested for an unrecognized stage id.')
};
}
/**
* Get the hex color (#000000) of a workflow stage
*
* @param int $stageId One of the WORKFLOW_STAGE_* constants
*
* @return string
*/
public static function getWorkflowStageColor($stageId)
{
switch ($stageId) {
case WORKFLOW_STAGE_ID_SUBMISSION: return '#d00a0a';
case WORKFLOW_STAGE_ID_INTERNAL_REVIEW: return '#e05c14';
case WORKFLOW_STAGE_ID_EXTERNAL_REVIEW: return '#e08914';
case WORKFLOW_STAGE_ID_EDITING: return '#006798';
case WORKFLOW_STAGE_ID_PRODUCTION: return '#00b28d';
}
throw new Exception('Color requested for an unrecognized stage id.');
}
/**
* Get a human-readable version of the max file upload size
*/
public static function getReadableMaxFileSize(): string
{
return strtoupper(UPLOAD_MAX_FILESIZE) . 'B';
}
/**
* Convert the max upload size to an integer in MBs
*/
public static function getIntMaxFileMBs(): int
{
$size = (int) UPLOAD_MAX_FILESIZE;
$unit = strtolower(substr(UPLOAD_MAX_FILESIZE, -1));
// No suffix fallbacks to "byte"
match (ctype_alpha($unit) ? $unit : 'b') {
'g' => $size <<= 10,
'm' => null,
'k' => $size >>= 10,
'b' => $size >>= 20,
default => error_log(sprintf('Invalid value for the PHP configuration upload_max_filesize "%s"', UPLOAD_MAX_FILESIZE))
};
return floor($size);
}
/**
* Get the supported metadata setting names for this application
*
* @return array
*/
public static function getMetadataFields()
{
return [
'coverage',
'rights',
'source',
'subjects',
'type',
'disciplines',
'keywords',
'agencies',
'citations',
'dataAvailability',
];
}
/**
* Retrieves whether the application is installed
*/
public static function isInstalled(): bool
{
return !!Config::getVar('general', 'installed');
}
/**
* Retrieves whether the application is running an upgrade
*/
public static function isUpgrading(): bool
{
return defined('RUNNING_UPGRADE');
}
/**
* Retrieves whether the application is under maintenance (not installed or being upgraded)
*/
public static function isUnderMaintenance(): bool
{
return !static::isInstalled() || static::isUpgrading();
}
/**
* Signals the application is undergoing an upgrade
*/
public static function upgrade(): void
{
// Constant kept for backwards compatibility
if (!defined('RUNNING_UPGRADE')) {
define('RUNNING_UPGRADE', true);
}
}
/**
* Get the property name for a section id
*
* In OMP, the section is referred to as a series and the
* property name is different.
*/
public static function getSectionIdPropName(): string
{
return 'sectionId';
}
}
define('REALLY_BIG_NUMBER', 10000);
define('UPLOAD_MAX_FILESIZE', trim(ini_get('upload_max_filesize')));
define('WORKFLOW_STAGE_ID_PUBLISHED', 0); // FIXME? See bug #6463.
define('WORKFLOW_STAGE_ID_SUBMISSION', 1);
define('WORKFLOW_STAGE_ID_INTERNAL_REVIEW', 2);
define('WORKFLOW_STAGE_ID_EXTERNAL_REVIEW', 3);
define('WORKFLOW_STAGE_ID_EDITING', 4);
define('WORKFLOW_STAGE_ID_PRODUCTION', 5);
/* TextArea insert tag variable types used to change their display when selected */
define('INSERT_TAG_VARIABLE_TYPE_PLAIN_TEXT', 'PLAIN_TEXT');