5 use Laminas\Diactoros\Uri
;
6 use wcf\system\application\ApplicationHandler
;
7 use wcf\system\cache\builder\ACPSearchProviderCacheBuilder
;
8 use wcf\system\event\EventHandler
;
9 use wcf\system\request\RouteHandler
;
10 use wcf\system\session\ACPSessionFactory
;
11 use wcf\system\session\SessionHandler
;
12 use wcf\system\template\ACPTemplateEngine
;
13 use wcf\util\FileUtil
;
14 use wcf\util\HeaderUtil
;
17 * Extends WCF class with functions for the ACP.
20 * @copyright 2001-2019 WoltLab GmbH
21 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
23 class WCFACP
extends WCF
28 protected static bool $inRescueMode;
31 * URL to WCF within rescue mode
33 protected static string $rescueModePageURL;
35 /** @noinspection PhpMissingParentConstructorInspection */
38 * Calls all init functions of the WCF and the WCFACP class.
40 public function __construct()
42 // define tmp directory
43 if (!\
defined('TMP_DIR')) {
44 \
define('TMP_DIR', FileUtil
::getTempFolder());
47 // start initialization
51 $this->initLanguage();
53 $this->initCoreObjects();
55 // prevent application loading during setup
57 $this->initApplications();
60 $this->runBootstrappers();
64 EventHandler
::getInstance()->fireAction($this, 'initialized');
68 * Returns true if ACP is currently in rescue mode.
70 public static function inRescueMode(): bool
72 if (!isset(self
::$inRescueMode)) {
73 self
::$inRescueMode = false;
75 if (\PACKAGE_ID
&& isset($_SERVER['HTTP_HOST'])) {
76 self
::$inRescueMode = true;
78 $activeApplication = ApplicationHandler
::getInstance()->getApplicationByID(\PACKAGE_ID
);
79 if ($activeApplication->domainName
=== $_SERVER['HTTP_HOST']) {
80 self
::$inRescueMode = false;
83 if (!self
::$inRescueMode) {
84 if ($activeApplication->domainPath
!== RouteHandler
::getPath(['acp'])) {
85 self
::$inRescueMode = true;
89 if (self
::$inRescueMode) {
90 self
::$rescueModePageURL = RouteHandler
::getProtocol() . $_SERVER['HTTP_HOST'] . RouteHandler
::getPath(['acp']);
95 return self
::$inRescueMode;
99 * Returns URL for rescue mode page.
101 public static function getRescueModePageURL(): string
103 if (self
::inRescueMode()) {
104 return self
::$rescueModePageURL;
111 * Does the user authentication.
113 protected function initAuth(): void
115 // this is a work-around since neither RequestHandler
116 // nor RouteHandler are populated right now
117 $pathInfo = RouteHandler
::getPathInfo();
119 if (self
::inRescueMode()) {
120 if (!\
preg_match('~^/?rescue-mode/~', $pathInfo)) {
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();
126 $pageURL = self
::$rescueModePageURL;
129 $redirectURI = $pageURL . 'acp/index.php?rescue-mode/';
131 HeaderUtil
::redirect($redirectURI);
141 public static function overrideDebugMode(): void
143 self
::$overrideDebugMode = true;
149 protected function initSession(): void
151 self
::$sessionObj = SessionHandler
::getInstance();
153 $factory = new ACPSessionFactory();
160 protected function initTPL(): void
162 self
::$tplObj = ACPTemplateEngine
::getInstance();
163 self
::getTPL()->setLanguageID(self
::getLanguage()->languageID
);
164 $this->assignDefaultTemplateVariables();
170 protected function assignDefaultTemplateVariables(): void
172 parent
::assignDefaultTemplateVariables();
174 // base tag is determined on runtime
175 $host = RouteHandler
::getHost();
176 $path = RouteHandler
::getPath();
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
185 \asort
($availableAcpSearchProviders);
187 self
::getTPL()->assign([
188 'baseHref' => $host . $path,
189 'availableAcpSearchProviders' => $availableAcpSearchProviders,