Commit | Line | Data |
---|---|---|
158bd3ca | 1 | <?php |
a9229942 | 2 | |
158bd3ca | 3 | namespace wcf\system; |
a9229942 | 4 | |
ea7d0f86 | 5 | use Laminas\Diactoros\Uri; |
eacc0f34 | 6 | use wcf\system\application\ApplicationHandler; |
c8f7b2a1 | 7 | use wcf\system\cache\builder\ACPSearchProviderCacheBuilder; |
f0d32df8 | 8 | use wcf\system\event\EventHandler; |
3dcfb497 | 9 | use wcf\system\request\RouteHandler; |
158bd3ca TD |
10 | use wcf\system\session\ACPSessionFactory; |
11 | use wcf\system\session\SessionHandler; | |
12 | use wcf\system\template\ACPTemplateEngine; | |
a17de04e MS |
13 | use wcf\util\FileUtil; |
14 | use wcf\util\HeaderUtil; | |
158bd3ca TD |
15 | |
16 | /** | |
a17de04e | 17 | * Extends WCF class with functions for the ACP. |
a9229942 TD |
18 | * |
19 | * @author Marcel Werk | |
20 | * @copyright 2001-2019 WoltLab GmbH | |
21 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
158bd3ca | 22 | */ |
a9229942 TD |
23 | class WCFACP extends WCF |
24 | { | |
25 | /** | |
26 | * rescue mode | |
a9229942 | 27 | */ |
0378567b | 28 | protected static bool $inRescueMode; |
a9229942 TD |
29 | |
30 | /** | |
31 | * URL to WCF within rescue mode | |
a9229942 | 32 | */ |
0378567b | 33 | protected static string $rescueModePageURL; |
a9229942 TD |
34 | |
35 | /** @noinspection PhpMissingParentConstructorInspection */ | |
36 | ||
37 | /** | |
38 | * Calls all init functions of the WCF and the WCFACP class. | |
39 | */ | |
40 | public function __construct() | |
41 | { | |
a9229942 TD |
42 | // define tmp directory |
43 | if (!\defined('TMP_DIR')) { | |
44 | \define('TMP_DIR', FileUtil::getTempFolder()); | |
45 | } | |
46 | ||
47 | // start initialization | |
48 | $this->initDB(); | |
49 | $this->loadOptions(); | |
a9229942 TD |
50 | $this->initSession(); |
51 | $this->initLanguage(); | |
52 | $this->initTPL(); | |
a9229942 TD |
53 | $this->initCoreObjects(); |
54 | ||
55 | // prevent application loading during setup | |
56 | if (PACKAGE_ID) { | |
57 | $this->initApplications(); | |
58 | } | |
59 | ||
6f77b358 TD |
60 | $this->runBootstrappers(); |
61 | ||
a9229942 TD |
62 | $this->initAuth(); |
63 | ||
64 | EventHandler::getInstance()->fireAction($this, 'initialized'); | |
65 | } | |
66 | ||
a9229942 TD |
67 | /** |
68 | * Returns true if ACP is currently in rescue mode. | |
a9229942 | 69 | */ |
62f1ff72 | 70 | public static function inRescueMode(): bool |
a9229942 | 71 | { |
0378567b | 72 | if (!isset(self::$inRescueMode)) { |
a9229942 TD |
73 | self::$inRescueMode = false; |
74 | ||
2e238f48 | 75 | if (\PACKAGE_ID && isset($_SERVER['HTTP_HOST'])) { |
a9229942 TD |
76 | self::$inRescueMode = true; |
77 | ||
2e238f48 AE |
78 | $activeApplication = ApplicationHandler::getInstance()->getApplicationByID(\PACKAGE_ID); |
79 | if ($activeApplication->domainName === $_SERVER['HTTP_HOST']) { | |
80 | self::$inRescueMode = false; | |
a9229942 TD |
81 | } |
82 | ||
dec40994 | 83 | if (!self::$inRescueMode) { |
2e238f48 | 84 | if ($activeApplication->domainPath !== RouteHandler::getPath(['acp'])) { |
dec40994 MW |
85 | self::$inRescueMode = true; |
86 | } | |
87 | } | |
88 | ||
a9229942 TD |
89 | if (self::$inRescueMode) { |
90 | self::$rescueModePageURL = RouteHandler::getProtocol() . $_SERVER['HTTP_HOST'] . RouteHandler::getPath(['acp']); | |
91 | } | |
92 | } | |
93 | } | |
94 | ||
95 | return self::$inRescueMode; | |
96 | } | |
97 | ||
98 | /** | |
99 | * Returns URL for rescue mode page. | |
a9229942 | 100 | */ |
62f1ff72 | 101 | public static function getRescueModePageURL(): string |
a9229942 TD |
102 | { |
103 | if (self::inRescueMode()) { | |
104 | return self::$rescueModePageURL; | |
105 | } | |
106 | ||
107 | return ''; | |
108 | } | |
109 | ||
110 | /** | |
111 | * Does the user authentication. | |
112 | */ | |
62f1ff72 | 113 | protected function initAuth(): void |
a9229942 TD |
114 | { |
115 | // this is a work-around since neither RequestHandler | |
116 | // nor RouteHandler are populated right now | |
117 | $pathInfo = RouteHandler::getPathInfo(); | |
118 | ||
119 | if (self::inRescueMode()) { | |
120 | if (!\preg_match('~^/?rescue-mode/~', $pathInfo)) { | |
ea7d0f86 MW |
121 | if (\PACKAGE_ID != 1) { |
122 | $uri = new Uri(self::$rescueModePageURL); | |
123 | $uri = $uri->withPath(FileUtil::getRealPath($uri->getPath() . 'acp/' . \RELATIVE_WCF_DIR)); | |
124 | $pageURL = $uri->__toString(); | |
125 | } else { | |
126 | $pageURL = self::$rescueModePageURL; | |
127 | } | |
128 | ||
129 | $redirectURI = $pageURL . 'acp/index.php?rescue-mode/'; | |
a9229942 TD |
130 | |
131 | HeaderUtil::redirect($redirectURI); | |
132 | ||
133 | exit; | |
134 | } | |
a9229942 TD |
135 | } |
136 | } | |
137 | ||
9c97f150 TD |
138 | /** |
139 | * @since 6.0 | |
140 | */ | |
62f1ff72 | 141 | public static function overrideDebugMode(): void |
9c97f150 TD |
142 | { |
143 | self::$overrideDebugMode = true; | |
144 | } | |
145 | ||
a9229942 TD |
146 | /** |
147 | * @inheritDoc | |
148 | */ | |
62f1ff72 | 149 | protected function initSession(): void |
a9229942 TD |
150 | { |
151 | self::$sessionObj = SessionHandler::getInstance(); | |
152 | ||
153 | $factory = new ACPSessionFactory(); | |
154 | $factory->load(); | |
155 | } | |
156 | ||
157 | /** | |
158 | * @inheritDoc | |
159 | */ | |
62f1ff72 | 160 | protected function initTPL(): void |
a9229942 TD |
161 | { |
162 | self::$tplObj = ACPTemplateEngine::getInstance(); | |
163 | self::getTPL()->setLanguageID(self::getLanguage()->languageID); | |
164 | $this->assignDefaultTemplateVariables(); | |
165 | } | |
166 | ||
167 | /** | |
168 | * @inheritDoc | |
169 | */ | |
62f1ff72 | 170 | protected function assignDefaultTemplateVariables(): void |
a9229942 TD |
171 | { |
172 | parent::assignDefaultTemplateVariables(); | |
173 | ||
174 | // base tag is determined on runtime | |
175 | $host = RouteHandler::getHost(); | |
176 | $path = RouteHandler::getPath(); | |
177 | ||
178 | // available acp search providers | |
179 | $availableAcpSearchProviders = []; | |
180 | foreach (ACPSearchProviderCacheBuilder::getInstance()->getData() as $searchProvider) { | |
181 | $availableAcpSearchProviders[$searchProvider->providerName] = self::getLanguage()->get( | |
182 | 'wcf.acp.search.provider.' . $searchProvider->providerName | |
183 | ); | |
184 | } | |
185 | \asort($availableAcpSearchProviders); | |
186 | ||
187 | self::getTPL()->assign([ | |
188 | 'baseHref' => $host . $path, | |
189 | 'availableAcpSearchProviders' => $availableAcpSearchProviders, | |
190 | ]); | |
191 | } | |
158bd3ca | 192 | } |