Merge branch '6.0'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / bootstrap / com.woltlab.wcf.php
1 <?php
2
3 use wcf\system\acp\dashboard\event\AcpDashboardCollecting;
4 use wcf\system\cronjob\CronjobScheduler;
5 use wcf\system\event\EventHandler;
6 use wcf\system\event\listener\PackageUpdateListChangedLicenseListener;
7 use wcf\system\event\listener\PhraseChangedPreloadListener;
8 use wcf\system\event\listener\PipSyncedPhrasePreloadListener;
9 use wcf\system\event\listener\PreloadPhrasesCollectingListener;
10 use wcf\system\event\listener\UserLoginCancelLostPasswordListener;
11 use wcf\system\event\listener\UsernameValidatingCheckCharactersListener;
12 use wcf\system\language\event\LanguageImported;
13 use wcf\system\language\event\PhraseChanged;
14 use wcf\system\language\LanguageFactory;
15 use wcf\system\language\preload\command\ResetPreloadCache;
16 use wcf\system\language\preload\event\PreloadPhrasesCollecting;
17 use wcf\system\language\preload\PhrasePreloader;
18 use wcf\system\package\event\PackageInstallationPluginSynced;
19 use wcf\system\package\event\PackageListChanged;
20 use wcf\system\package\event\PackageUpdateListChanged;
21 use wcf\system\package\license\LicenseApi;
22 use wcf\system\session\event\PreserveVariablesCollecting;
23 use wcf\system\user\authentication\event\UserLoggedIn;
24 use wcf\system\user\authentication\LoginRedirect;
25 use wcf\system\user\event\UsernameValidating;
26 use wcf\system\WCF;
27 use wcf\system\worker\event\RebuildWorkerCollecting;
28
29 return static function (): void {
30 $eventHandler = EventHandler::getInstance();
31
32 WCF::getTPL()->assign(
33 'executeCronjobs',
34 CronjobScheduler::getInstance()->getNextExec() < TIME_NOW && \defined('OFFLINE') && !OFFLINE
35 );
36
37 $eventHandler->register(UserLoggedIn::class, UserLoginCancelLostPasswordListener::class);
38 $eventHandler->register(PreserveVariablesCollecting::class, static function (PreserveVariablesCollecting $event) {
39 $event->keys[] = LoginRedirect::SESSION_VAR_KEY;
40 });
41
42 $eventHandler->register(UsernameValidating::class, UsernameValidatingCheckCharactersListener::class);
43
44 $eventHandler->register(PackageListChanged::class, static function () {
45 foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
46 $command = new ResetPreloadCache($language);
47 $command();
48 }
49 });
50 $eventHandler->register(LanguageImported::class, static function (LanguageImported $event) {
51 $command = new ResetPreloadCache($event->language);
52 $command();
53 });
54 $eventHandler->register(PhraseChanged::class, PhraseChangedPreloadListener::class);
55 $eventHandler->register(PackageInstallationPluginSynced::class, PipSyncedPhrasePreloadListener::class);
56 WCF::getTPL()->assign('phrasePreloader', new PhrasePreloader());
57 $eventHandler->register(PreloadPhrasesCollecting::class, PreloadPhrasesCollectingListener::class);
58
59 $eventHandler->register(RebuildWorkerCollecting::class, static function (RebuildWorkerCollecting $event) {
60 $event->register(\wcf\system\worker\LikeRebuildDataWorker::class, -100);
61 $event->register(\wcf\system\worker\ArticleRebuildDataWorker::class, 50);
62 $event->register(\wcf\system\worker\PageRebuildDataWorker::class, 50);
63 $event->register(\wcf\system\worker\PollRebuildDataWorker::class, 60);
64 $event->register(\wcf\system\worker\UserActivityPointUpdateEventsWorker::class, 65);
65 $event->register(\wcf\system\worker\UserRebuildDataWorker::class, 70);
66 $event->register(\wcf\system\worker\UserActivityPointItemsRebuildDataWorker::class, 75);
67 $event->register(\wcf\system\worker\CommentRebuildDataWorker::class, 120);
68 $event->register(\wcf\system\worker\CommentResponseRebuildDataWorker::class, 121);
69 $event->register(\wcf\system\worker\AttachmentRebuildDataWorker::class, 450);
70 $event->register(\wcf\system\worker\MediaRebuildDataWorker::class, 450);
71 $event->register(\wcf\system\worker\SitemapRebuildWorker::class, 500);
72 $event->register(\wcf\system\worker\StatDailyRebuildDataWorker::class, 800);
73 });
74
75 $eventHandler->register(PackageUpdateListChanged::class, PackageUpdateListChangedLicenseListener::class);
76
77 $eventHandler->register(AcpDashboardCollecting::class, static function (AcpDashboardCollecting $event) {
78 $event->register(new \wcf\system\acp\dashboard\box\NewsAcpDashboardBox());
79 $event->register(new \wcf\system\acp\dashboard\box\StatusMessageAcpDashboardBox());
80 $event->register(new \wcf\system\acp\dashboard\box\ExpiringLicensesAcpDashboardBox());
81 $event->register(new \wcf\system\acp\dashboard\box\UsersAwaitingApprovalAcpDashboardBox());
82 $event->register(new \wcf\system\acp\dashboard\box\SystemInfoAcpDashboardBox());
83 $event->register(new \wcf\system\acp\dashboard\box\CreditsAcpDashboardBox());
84 });
85
86 try {
87 $licenseApi = new LicenseApi();
88 $licenseData = $licenseApi->readFromFile();
89 if ($licenseData !== null) {
90 $brandingFree = $licenseData->woltlab['com.woltlab.brandingFree'] ?? '0.0';
91 $expiresAt = $licenseData->license['expiryDates']['com.woltlab.brandingFree'] ?? \TIME_NOW;
92 if ($brandingFree !== '0.0' && ($expiresAt === -1 || $expiresAt >= \TIME_NOW)) {
93 define('WOLTLAB_BRANDING', false);
94 }
95
96 // Expire the cached license data after 60 days.
97 if ($licenseData->creationDate->getTimestamp() < \TIME_NOW - 86400 * 60) {
98 $licenseApi->clearLicenseFile();
99 }
100 }
101 } catch (\Throwable) {
102 // Reading the license file must never cause any errors.
103 }
104
105 if (!defined('WOLTLAB_BRANDING')) {
106 define('WOLTLAB_BRANDING', true);
107 }
108 };